diff --git a/lib/jli.js b/lib/jli.js index 8c16bca..0b7b17d 100755 --- a/lib/jli.js +++ b/lib/jli.js @@ -483,10 +483,23 @@ function makeKeyboardHandler(keybindings, unhandled){ +// click threshold in pixels, if the distance between start and end is +// less than this, the whole event is considered a click and not a +// drag/swipe... var CLICK_THRESHOLD = 10 +// if the amount of time to wait beween start and end is greater than this +// the event is considered a long click. +// NOTE: this will not auto-fire the event, the user MUST release first. var LONG_CLICK_THRESHOLD = 400 +// NOTE: this is reset by the timeout explicitly set in the handler... +// NOTE: this is the timeout between two consecutive clicks and not the total. +// NOTE: if multiple clicks are enabled this will introduce a lag after +// each click (while we wait for the next), so keep this as small +// as possible. var MULTI_CLICK_TIMEOUT = 200 +var MULTITOUCH_RELEASE_THRESHOLD = 100 + // XXX add a resonable cancel scheme... // ... something similar to touch threshold but bigger... // XXX handle multiple touches... @@ -497,6 +510,7 @@ var MULTI_CLICK_TIMEOUT = 200 // XXX BUG: on landing a second finger while scrolling the things goes // haywhire... // XXX BUG: after long click the mouse is tracked and the view is scrolled... +// XXX split this into a seporate lib... function makeScrollHandler(root, config){ root = $(root) @@ -663,7 +677,9 @@ function makeScrollHandler(root, config){ speed: dx/dt, distance: start_x-x, duration: t-start_t, - touches: touches + // current touches... + touches: touches, + clicks: null, }) === false || touches == 0){ // cleanup and stop... @@ -719,6 +735,7 @@ function makeScrollHandler(root, config){ clickThreshold: null, longClickThreshold: null, multiClickTimeout: null, + multitouchTimeout: null, }, // NOTE: this is updated live but not used by the system in any way... state: 'stopped', @@ -779,12 +796,20 @@ function makeScrollHandler(root, config){ // This will provide support for the folowing events on the scroll root // element: // - scrollCancelled -// - longClick // - shortClick +// - doubleClick +// - multiClick +// this will store the number of clicks in data.clicks +// - longClick // - swipeLeft // - swipeRight // - screenReleased // +// NOTE: data.touches passed to the event is the number of touches +// released within the multitouchTimeout. +// this differs from what postScrollCallback actually gets in the +// same field when it recieves the object. +// // XXX add up/down swipes // XXX add double clicks // XXX add generic snap @@ -794,10 +819,13 @@ function postScrollCallback(data){ var root = scroller.root var clickThreshold = scroller.options.clickThreshold || CLICK_THRESHOLD var longClickThreshold = scroller.options.longClickThreshold || LONG_CLICK_THRESHOLD + var multitouchTimeout = scroller.options.multitouchTimeout || MULTITOUCH_RELEASE_THRESHOLD var enableMultiClicks = scroller.options.enableMultiClicks var multiClickTimeout = scroller.options.multiClickTimeout || MULTI_CLICK_TIMEOUT + var now = Date.now(); + // cancel event... if(scroller.state == 'canceling'){ return root.trigger('scrollCancelled', data) @@ -805,8 +833,26 @@ function postScrollCallback(data){ // ignore situations when the user is still touching... // ...like when he/she lifted one finger of several... + // XXX needs testing... if(data.touches > 0){ + var then = scroller._last_touch_release + if(then == null || now - then < multitouchTimeout){ + if(scroller._touches == null){ + scroller._touches = 1 + } else { + scroller._touches += 1 + } + } else { + scroller._touches = null + } + // wait for the next touch release... + scroller._last_touch_release = now return + // calculate how many touches did participate... + } else { + data.touches = scroller._touches + 1 + scroller._last_touch_release = null + scroller._touches = null } // clicks, double clicks and long clicks... @@ -818,6 +864,7 @@ function postScrollCallback(data){ return root.trigger('shortClick', data) } else { + // count the clicks so far... if(scroller._clicks == null){ scroller._clicks = 1 } else {