re-did the swipe-handler...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-02-19 00:55:49 +04:00
parent 88d0494f17
commit c28a3bb116
2 changed files with 63 additions and 51 deletions

View File

@ -59,7 +59,7 @@ $(document).ready(function(){
// user interactions... // user interactions...
.swipe({ .swipe({
swipeStatus: swipeHandler, swipeStatus: makeSwipeHandler(),
// XXX these get called instead of pinches... // XXX these get called instead of pinches...
swipeUp: function(event, direction, distance, duration, fingerCount){ swipeUp: function(event, direction, distance, duration, fingerCount){

View File

@ -361,61 +361,73 @@ function viewResizeHandler(){
// each call while dragging... // each call while dragging...
// XXX for some reason with finger count of 3 and greater, touchSwipe // XXX for some reason with finger count of 3 and greater, touchSwipe
// dies on android... // dies on android...
function swipeHandler(evt, phase, direction, distance, duration, fingers){ function makeSwipeHandler(){
var pages = $('.page') var pages
var cur = $('.current.page') var cur
var n = pages.index(cur) var n
var scale = getPageScale() var scale
var mag = $('.magazine') var mag
var pos = $('.navigator .bar .indicator') var pos
var viewer
// XXX make this drag pages that are larger than view before dragging outside... return function(evt, phase, direction, distance, duration, fingers){
if(phase=='move'
// see if wee need to drag the page and allways drag the ribbon...
&& (DRAG_FULL_PAGE || !_PAGE_VIEW)
&& (direction=='left' || direction=='right')){
if(direction == 'left'){
shiftMagazineTo(-cur.position()['left']/scale - distance/scale)
} else if(direction == 'right') {
shiftMagazineTo(-cur.position()['left']/scale + distance/scale)
}
$('.viewer').trigger('magazineDragging') if(phase == 'start'){
// NOTE: this is used with the "unanimated" trick, we will make
// dragging real-time...
togglePageDragging('on')
} else if(phase == 'start'){ // setup the data for the drag...
// NOTE: this is used with the "unanimated" trick, we will make pages = $('.page')
// dragging real-time... cur = $('.current.page')
togglePageDragging('on') n = pages.index(cur)
scale = getPageScale()
mag = $('.magazine')
pos = $('.navigator .bar .indicator')
viewer = $('.viewer')
} else if(phase == 'cancel'){ // XXX make this drag pages that are larger than view before dragging outside...
togglePageDragging('off') } else if(phase=='move'
setCurrentPage() // see if wee need to drag the page and allways drag the ribbon...
&& (DRAG_FULL_PAGE || !_PAGE_VIEW)
} else if(phase =='end' ){ && (direction=='left' || direction=='right')){
togglePageDragging('off') if(direction == 'left'){
// see which page is closer to the middle of the screen and set it... shiftMagazineTo(-cur.position().left/scale - distance/scale)
// do this based on how much we dragged... } else if(direction == 'right') {
var p = Math.ceil((distance/scale)/cur.width()) shiftMagazineTo(-cur.position().left/scale + distance/scale)
// prev page...
if(direction == 'right'){
// 2 fingers moves to closest article...
if(fingers == 2){
prevArticle()
// 3+ fingers moves to bookmark...
} else if(fingers >= 3){
prevBookmark()
} else {
setCurrentPage(Math.max(n-p, 0))
} }
// next page... viewer.trigger('magazineDragging')
} else if(direction == 'left'){
if(fingers == 2){ } else if(phase == 'cancel'){
nextArticle() togglePageDragging('off')
} else if(fingers >= 3){ setCurrentPage()
nextBookmark()
} else { } else if(phase =='end' ){
setCurrentPage(Math.min(n+p, pages.length-1)) togglePageDragging('off')
// see which page is closer to the middle of the screen and set it...
// do this based on how much we dragged...
var p = Math.ceil((distance/scale)/cur.width())
// prev page...
if(direction == 'right'){
// 2 fingers moves to closest article...
if(fingers == 2){
prevArticle()
// 3+ fingers moves to bookmark...
} else if(fingers >= 3){
prevBookmark()
} else {
setCurrentPage(Math.max(n-p, 0))
}
// next page...
} else if(direction == 'left'){
if(fingers == 2){
nextArticle()
} else if(fingers >= 3){
nextBookmark()
} else {
setCurrentPage(Math.min(n+p, pages.length-1))
}
} }
} }
} }