mirror of
https://github.com/flynx/PortableMag.git
synced 2025-12-23 20:11:46 +00:00
added multitouch (needs testing)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d63a9b46bd
commit
cd9ca4995a
51
lib/jli.js
51
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
|
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
|
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 MULTI_CLICK_TIMEOUT = 200
|
||||||
|
|
||||||
|
var MULTITOUCH_RELEASE_THRESHOLD = 100
|
||||||
|
|
||||||
// XXX add a resonable cancel scheme...
|
// XXX add a resonable cancel scheme...
|
||||||
// ... something similar to touch threshold but bigger...
|
// ... something similar to touch threshold but bigger...
|
||||||
// XXX handle multiple touches...
|
// 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
|
// XXX BUG: on landing a second finger while scrolling the things goes
|
||||||
// haywhire...
|
// haywhire...
|
||||||
// XXX BUG: after long click the mouse is tracked and the view is scrolled...
|
// 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){
|
function makeScrollHandler(root, config){
|
||||||
root = $(root)
|
root = $(root)
|
||||||
|
|
||||||
@ -663,7 +677,9 @@ function makeScrollHandler(root, config){
|
|||||||
speed: dx/dt,
|
speed: dx/dt,
|
||||||
distance: start_x-x,
|
distance: start_x-x,
|
||||||
duration: t-start_t,
|
duration: t-start_t,
|
||||||
touches: touches
|
// current touches...
|
||||||
|
touches: touches,
|
||||||
|
clicks: null,
|
||||||
}) === false
|
}) === false
|
||||||
|| touches == 0){
|
|| touches == 0){
|
||||||
// cleanup and stop...
|
// cleanup and stop...
|
||||||
@ -719,6 +735,7 @@ function makeScrollHandler(root, config){
|
|||||||
clickThreshold: null,
|
clickThreshold: null,
|
||||||
longClickThreshold: null,
|
longClickThreshold: null,
|
||||||
multiClickTimeout: null,
|
multiClickTimeout: null,
|
||||||
|
multitouchTimeout: null,
|
||||||
},
|
},
|
||||||
// NOTE: this is updated live but not used by the system in any way...
|
// NOTE: this is updated live but not used by the system in any way...
|
||||||
state: 'stopped',
|
state: 'stopped',
|
||||||
@ -779,12 +796,20 @@ function makeScrollHandler(root, config){
|
|||||||
// This will provide support for the folowing events on the scroll root
|
// This will provide support for the folowing events on the scroll root
|
||||||
// element:
|
// element:
|
||||||
// - scrollCancelled
|
// - scrollCancelled
|
||||||
// - longClick
|
|
||||||
// - shortClick
|
// - shortClick
|
||||||
|
// - doubleClick
|
||||||
|
// - multiClick
|
||||||
|
// this will store the number of clicks in data.clicks
|
||||||
|
// - longClick
|
||||||
// - swipeLeft
|
// - swipeLeft
|
||||||
// - swipeRight
|
// - swipeRight
|
||||||
// - screenReleased
|
// - 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 up/down swipes
|
||||||
// XXX add double clicks
|
// XXX add double clicks
|
||||||
// XXX add generic snap
|
// XXX add generic snap
|
||||||
@ -794,10 +819,13 @@ function postScrollCallback(data){
|
|||||||
var root = scroller.root
|
var root = scroller.root
|
||||||
var clickThreshold = scroller.options.clickThreshold || CLICK_THRESHOLD
|
var clickThreshold = scroller.options.clickThreshold || CLICK_THRESHOLD
|
||||||
var longClickThreshold = scroller.options.longClickThreshold || LONG_CLICK_THRESHOLD
|
var longClickThreshold = scroller.options.longClickThreshold || LONG_CLICK_THRESHOLD
|
||||||
|
var multitouchTimeout = scroller.options.multitouchTimeout || MULTITOUCH_RELEASE_THRESHOLD
|
||||||
|
|
||||||
var enableMultiClicks = scroller.options.enableMultiClicks
|
var enableMultiClicks = scroller.options.enableMultiClicks
|
||||||
var multiClickTimeout = scroller.options.multiClickTimeout || MULTI_CLICK_TIMEOUT
|
var multiClickTimeout = scroller.options.multiClickTimeout || MULTI_CLICK_TIMEOUT
|
||||||
|
|
||||||
|
var now = Date.now();
|
||||||
|
|
||||||
// cancel event...
|
// cancel event...
|
||||||
if(scroller.state == 'canceling'){
|
if(scroller.state == 'canceling'){
|
||||||
return root.trigger('scrollCancelled', data)
|
return root.trigger('scrollCancelled', data)
|
||||||
@ -805,8 +833,26 @@ function postScrollCallback(data){
|
|||||||
|
|
||||||
// ignore situations when the user is still touching...
|
// ignore situations when the user is still touching...
|
||||||
// ...like when he/she lifted one finger of several...
|
// ...like when he/she lifted one finger of several...
|
||||||
|
// XXX needs testing...
|
||||||
if(data.touches > 0){
|
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
|
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...
|
// clicks, double clicks and long clicks...
|
||||||
@ -818,6 +864,7 @@ function postScrollCallback(data){
|
|||||||
return root.trigger('shortClick', data)
|
return root.trigger('shortClick', data)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// count the clicks so far...
|
||||||
if(scroller._clicks == null){
|
if(scroller._clicks == null){
|
||||||
scroller._clicks = 1
|
scroller._clicks = 1
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user