diff --git a/ui/data.js b/ui/data.js index d591f184..7ed67a25 100755 --- a/ui/data.js +++ b/ui/data.js @@ -1619,13 +1619,28 @@ function preCacheAllRibbons(){ function setupBaseURLHistory(){ $('.viewer') .on('baseURLChanged', function(evt, old_url, new_url){ + var updated = false + + // store the old and new urls in history unless they already + // exist... if(BASE_URL_HISTORY.indexOf(old_url) < 0){ BASE_URL_HISTORY.splice(0, 0, old_url) + updated = true + } + if(BASE_URL_HISTORY.indexOf(new_url) < 0){ + BASE_URL_HISTORY.splice(0, 0, new_url) + updated = true + } - // truncate the history if needed... - if(BASE_URL_HISTORY.length > BASE_URL_LIMIT){ - BASE_URL_HISTORY.splice(BASE_URL_LIMIT, BASE_URL_HISTORY.length) - } + // truncate the history if needed... + if(BASE_URL_HISTORY.length > BASE_URL_LIMIT){ + BASE_URL_HISTORY.splice(BASE_URL_LIMIT, BASE_URL_HISTORY.length) + updated = true + } + + // XXX is this the right place for this??? + if(updated){ + saveLocalStorageBaseURLHistory() } }) } @@ -1634,11 +1649,11 @@ function getURLHistoryPosition(){ return BASE_URL_HISTORY.indexOf(BASE_URL) } function getURLHistoryNext(){ - var res = BASE_URL_HISTORY[ getURLHistoryPosition() + 1] + var res = BASE_URL_HISTORY[ getURLHistoryPosition() - 1] return res == null ? BASE_URL : res } function getURLHistoryPrev(){ - var res = BASE_URL_HISTORY[ getURLHistoryPosition() - 1 ] + var res = BASE_URL_HISTORY[ getURLHistoryPosition() + 1 ] return res == null ? BASE_URL : res } diff --git a/ui/index.html b/ui/index.html index 30ab05b3..ecdea0f2 100755 --- a/ui/index.html +++ b/ui/index.html @@ -150,6 +150,8 @@ $(function(){ if((DATA_ATTR + '_BASE_URL') in localStorage && !/^\.[\/\\]*/.test(localStorage[DATA_ATTR + '_BASE_URL'])){ + loadLocalStorageBaseURLHistory(DATA_ATTR) + BASE_URL = localStorage[DATA_ATTR + '_BASE_URL'] var loading = statusNotify(loadDir(BASE_URL)) diff --git a/ui/keybindings.js b/ui/keybindings.js index 1e44e0a8..d261f2a9 100755 --- a/ui/keybindings.js +++ b/ui/keybindings.js @@ -385,6 +385,9 @@ var KEYBOARD_CONFIG = { centerRibbons() }), ctrl: 'prev-screen', + + // XXX button not final... + 'ctrl+shift': doc('Previous URL in history', loadURLHistoryPrev ), }, Right: { default: doc('Next image', @@ -396,6 +399,9 @@ var KEYBOARD_CONFIG = { centerRibbons() }), ctrl: 'next-screen', + + // XXX button not final... + 'ctrl+shift': doc('Next URL in history', loadURLHistoryNext ), }, 'prev-screen': doc('Previous screen', function(){ diff --git a/ui/localstorage.js b/ui/localstorage.js index ce3174a7..a5f7c54d 100755 --- a/ui/localstorage.js +++ b/ui/localstorage.js @@ -26,6 +26,7 @@ function saveLocalStorageBaseURL(attr){ function loadLocalStorageBaseURLHistory(attr){ attr = attr == null ? DATA_ATTR : attr BASE_URL_HISTORY = JSON.parse(localStorage[attr + '_BASE_URL_HISTORY']) + return BASE_URL_HISTORY } function saveLocalStorageBaseURLHistory(attr){ attr = attr == null ? DATA_ATTR : attr