From bf8a47ed8bb3c838cea806ce14ee2ad47272673f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 20 Feb 2013 23:29:22 +0400 Subject: [PATCH] some refactoring and tuneup... Signed-off-by: Alex A. Naanou --- lib/jli.js | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/jli.js b/lib/jli.js index 7818a75..33fac77 100755 --- a/lib/jli.js +++ b/lib/jli.js @@ -10,6 +10,7 @@ //var DEBUG = DEBUG != null ? DEBUG : true + /*********************************************************************/ // this will create a function that will cycle through a class_list on elem @@ -482,6 +483,9 @@ function makeKeyboardHandler(keybindings, unhandled){ +var CLICK_THRESHOLD = 10 +var LONG_CLICK_THRESHOLD = 400 + // XXX add a resonable cancel scheme... // ... something similar to touch threshold but bigger... // XXX handle multiple touches... @@ -696,7 +700,10 @@ function makeScrollHandler(root, config){ eventBounds: 5, // NOTE: if this returns false explicitly, this will stop scrolling. - callback: postScrollCallback + callback: postScrollCallback, + // These are used by the default callback... + clickThreshold: null, + longClickThreshold: null, }, // NOTE: this is updated live but not used by the system in any way... state: 'stopped', @@ -748,17 +755,25 @@ function makeScrollHandler(root, config){ return scroller } -var CLICK_THRESHOLD = 10 -var LONG_CLICK_THRESHOLD = 400 - - -// this is the default callback... +// default callback... +// This will provide support for the folowing events on the scroll root +// element: +// - scrollCancelled +// - longClick +// - shortClick +// - swipeLeft +// - swipeRight +// - screenReleased +// // XXX add up/down swipes // XXX add double clicks // XXX add generic snap // XXX add generic innertial scroll function postScrollCallback(data){ var root = data.scroller.root + var clickThreshold = data.scroller.options.clickThreshold || CLICK_THRESHOLD + var longClickThreshold = data.scroller.options.longClickThreshold || LONG_CLICK_THRESHOLD + // cancel event... if(data.scroller.state == 'canceling'){ return root.trigger('scrollCancelled', data) @@ -771,8 +786,8 @@ function postScrollCallback(data){ } // clicks and long clicks... - if(Math.abs(data.distance) < CLICK_THRESHOLD){ - if(data.duration > LONG_CLICK_THRESHOLD){ + if(Math.abs(data.distance) < clickThreshold){ + if(data.duration > longClickThreshold){ return root.trigger('longClick', data) } return root.trigger('shortClick', data) @@ -780,10 +795,11 @@ function postScrollCallback(data){ // left/right swipes... // XXX add up/down support... - if(data.distance <= -CLICK_THRESHOLD){ + // XXX check if these are bound... + if(data.distance <= -clickThreshold){ return root.trigger('swipeLeft', data) } - if(data.distance >= CLICK_THRESHOLD){ + if(data.distance >= clickThreshold){ return root.trigger('swipeRight', data) }