some refactoring and tuneup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-02-20 23:29:22 +04:00
parent 1c9119767c
commit bf8a47ed8b

View File

@ -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)
}