minor refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-01-26 23:48:57 +04:00
parent 0a6f2ffdb0
commit 4f4538fbb3
2 changed files with 19 additions and 26 deletions

View File

@ -40,21 +40,7 @@ $(document).ready(function(){
} }
//$('.splash').fadeOut() //$('.splash').fadeOut()
}) })
.bind('hashchange', function(e){ .bind('hashchange', hashChangeHandler)
e.preventDefault()
var r = loadURLState()
// if we are dealing with history actions the browser will
// do the work for us...
if(r == 'back'){
window.history.go(-2)
return
} else if(r == 'forward'){
window.history.go(2)
return
} else {
setCurrentPage(r)
}
})
$('.viewer') $('.viewer')
.swipe({ .swipe({

View File

@ -66,6 +66,22 @@ function getPageNumber(page){
/************************************************** event handlers ***/ /************************************************** event handlers ***/
function hashChangeHandler(e){
e.preventDefault()
var r = loadURLState()
// if we are dealing with history actions the browser will
// do the work for us...
// XXX revise...
if(r == 'back'){
window.history.go(-2)
} else if(r == 'forward'){
window.history.go(2)
} else {
setCurrentPage(r)
}
}
// swipe state handler // swipe state handler
// this handles single and double finger swipes and dragging // this handles single and double finger swipes and dragging
function swipeHandler(evt, phase, direction, distance, duration, fingers){ function swipeHandler(evt, phase, direction, distance, duration, fingers){
@ -298,20 +314,11 @@ function loadURLState(){
return $('.page').length-1 return $('.page').length-1
// history... // history...
// NOTE: these are handled by hashChangeHandler()
// XXX revise...
} else if(anchor == 'back') { } else if(anchor == 'back') {
//window.history.back()
//setTimeout(function(win){ return function(){ win.history.back() } }(window), 100)
// NOTE: if we do not do this we'll endup in an infinite history loop...
//window.location.hash = ''
//return getPageNumber()
return anchor return anchor
} else if(anchor == 'forward') { } else if(anchor == 'forward') {
//window.history.forward()
//setTimeout(function(win){ return function(){ win.history.forward() } }(window), 100)
// NOTE: if we do not do this we'll endup in an infinite history loop...
//window.location.hash = ''
//return getPageNumber()
return anchor return anchor
// relative URLs... // relative URLs...