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