now history is saved in localStorage + added basic history UI -- ctrl+shift+left/right...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-11-25 06:57:40 +04:00
parent 41ac21f088
commit c9d0a17f43
4 changed files with 30 additions and 6 deletions

View File

@ -1619,13 +1619,28 @@ function preCacheAllRibbons(){
function setupBaseURLHistory(){ function setupBaseURLHistory(){
$('.viewer') $('.viewer')
.on('baseURLChanged', function(evt, old_url, new_url){ .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){ if(BASE_URL_HISTORY.indexOf(old_url) < 0){
BASE_URL_HISTORY.splice(0, 0, old_url) 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... // truncate the history if needed...
if(BASE_URL_HISTORY.length > BASE_URL_LIMIT){ if(BASE_URL_HISTORY.length > BASE_URL_LIMIT){
BASE_URL_HISTORY.splice(BASE_URL_LIMIT, BASE_URL_HISTORY.length) 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) return BASE_URL_HISTORY.indexOf(BASE_URL)
} }
function getURLHistoryNext(){ function getURLHistoryNext(){
var res = BASE_URL_HISTORY[ getURLHistoryPosition() + 1] var res = BASE_URL_HISTORY[ getURLHistoryPosition() - 1]
return res == null ? BASE_URL : res return res == null ? BASE_URL : res
} }
function getURLHistoryPrev(){ function getURLHistoryPrev(){
var res = BASE_URL_HISTORY[ getURLHistoryPosition() - 1 ] var res = BASE_URL_HISTORY[ getURLHistoryPosition() + 1 ]
return res == null ? BASE_URL : res return res == null ? BASE_URL : res
} }

View File

@ -150,6 +150,8 @@ $(function(){
if((DATA_ATTR + '_BASE_URL') in localStorage if((DATA_ATTR + '_BASE_URL') in localStorage
&& !/^\.[\/\\]*/.test(localStorage[DATA_ATTR + '_BASE_URL'])){ && !/^\.[\/\\]*/.test(localStorage[DATA_ATTR + '_BASE_URL'])){
loadLocalStorageBaseURLHistory(DATA_ATTR)
BASE_URL = localStorage[DATA_ATTR + '_BASE_URL'] BASE_URL = localStorage[DATA_ATTR + '_BASE_URL']
var loading = statusNotify(loadDir(BASE_URL)) var loading = statusNotify(loadDir(BASE_URL))

View File

@ -385,6 +385,9 @@ var KEYBOARD_CONFIG = {
centerRibbons() centerRibbons()
}), }),
ctrl: 'prev-screen', ctrl: 'prev-screen',
// XXX button not final...
'ctrl+shift': doc('Previous URL in history', loadURLHistoryPrev ),
}, },
Right: { Right: {
default: doc('Next image', default: doc('Next image',
@ -396,6 +399,9 @@ var KEYBOARD_CONFIG = {
centerRibbons() centerRibbons()
}), }),
ctrl: 'next-screen', ctrl: 'next-screen',
// XXX button not final...
'ctrl+shift': doc('Next URL in history', loadURLHistoryNext ),
}, },
'prev-screen': doc('Previous screen', 'prev-screen': doc('Previous screen',
function(){ function(){

View File

@ -26,6 +26,7 @@ function saveLocalStorageBaseURL(attr){
function loadLocalStorageBaseURLHistory(attr){ function loadLocalStorageBaseURLHistory(attr){
attr = attr == null ? DATA_ATTR : attr attr = attr == null ? DATA_ATTR : attr
BASE_URL_HISTORY = JSON.parse(localStorage[attr + '_BASE_URL_HISTORY']) BASE_URL_HISTORY = JSON.parse(localStorage[attr + '_BASE_URL_HISTORY'])
return BASE_URL_HISTORY
} }
function saveLocalStorageBaseURLHistory(attr){ function saveLocalStorageBaseURLHistory(attr){
attr = attr == null ? DATA_ATTR : attr attr = attr == null ? DATA_ATTR : attr