code cleanup and minor bugs squashed...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-01-22 19:19:43 +04:00
parent 4895fed07b
commit 99989e6a6c

View File

@ -378,7 +378,6 @@ function setCurrentPage(n, W){
var W = W == null ? cur.width() : W var W = W == null ? cur.width() : W
mag.css({left: -n*W}) mag.css({left: -n*W})
window.location.hash = n
// XXX should this be here??? // XXX should this be here???
saveState() saveState()
@ -448,19 +447,50 @@ function prevArticle(){
// XXX /*********************************************************************/
function loadState(){ // XXX make these magazine-specific...
setCurrentPage(parseInt($.jStorage.get('current_page'), 0)) // URL state managers...
function loadURLState(){
if(window.location.hash == ''){
return 0
}
var n = parseInt(window.location.hash.split('#')[1])
if(n != null){
return n
} else {
alert('textual anchors not yet supported...')
return
}
}
function saveURLState(){
window.location.hash = getPageNumber()
} }
// XXX // local storage state managers...
function saveState(){ function loadStorageState(){
// XXX make this magazine-specific... return parseInt($.jStorage.get('current_page'), 0)
}
function saveStorageState(){
$.jStorage.set('current_page', getPageNumber()) $.jStorage.set('current_page', getPageNumber())
} }
// generic state managers...
function loadState(){
var n = loadURLState()
if(n != null){
setCurrentPage(n)
} else {
setCurrentPage(loadStorageState())
}
}
function saveState(){
saveURLState()
saveStorageState()
}
/*********************************************************************/
// XXX create magazine... // XXX create magazine...
function createMagazine(){ function createMagazine(){
} }
@ -485,13 +515,7 @@ $(document).ready(function(){
fitNPages(PAGES_VISIBLE) fitNPages(PAGES_VISIBLE)
}) })
.bind('hashchange', function(){ .bind('hashchange', function(){
// XXX this is the same as the init code below... setCurrentPage(loadURLState())
var n = parseInt(window.location.hash.split('#')[1])
if(n != null){
setCurrentPage(n)
} else {
alert('textual anchors not yet supported...')
}
}) })
$('.viewer') $('.viewer')
@ -519,16 +543,7 @@ $(document).ready(function(){
$('.button.next-article').swipe({click: nextArticle}) $('.button.next-article').swipe({click: nextArticle})
$('.button.prev-article').swipe({click: prevArticle}) $('.button.prev-article').swipe({click: prevArticle})
if(window.location.hash == ''){ loadState()
loadState()
} else {
var n = parseInt(window.location.hash.split('#')[1])
if(n != null){
setCurrentPage(n)
} else {
alert('textual anchors not yet supported...')
}
}
togglePageView('on') togglePageView('on')
@ -540,7 +555,6 @@ $(document).ready(function(){
}) })
</script> </script>
</head> </head>
<body> <body>