event-gestures.js revision 35a16952b0308d5bf01f468c2e748bd2895a4bdf
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * Adds support for a "flick" event, which is fired at the end of a touch or mouse based flick gesture, and provides
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * velocity of the flick, along with distance and time information.
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * @module event-gestures
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * @submodule event-flick
6ec4e1827eab6a424d672ef0e5a17b065e52db20vboxsync// TODO: Better way to sniff 'n' switch touch support?
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * Sets up a "flick" event, that is fired whenever the user initiates a flick gesture on the node
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * where the listener is attached. The subscriber can specify a minimum distance or velocity for
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * which the event is to be fired.
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * @event flick
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * @param type {string} "flick"
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * @param fn {function} The method the event invokes.
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * @param cfg {Object} Optional. An object which specifies the minimum distance and/or velocity
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * of the flick gesture for which the event is to be fired.
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * @return {EventHandle} the detach handle
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync // The initialization implementation. Called for the first subscription per node.
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync // The destroy implementation. Called for the last detach per node.
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync var startHandle = node.getData(_FLICK_START_HANDLE),
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync // How to process the additional spec args
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync var params = (args[3]) ? args.splice(3, 1)[0] : {};
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync // Internal DOM listener to identify the start of the gesture
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync doc = (node.get(NODE_TYPE) === 9) ? node : node.get(OWNER_DOCUMENT);
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync endHandle = doc.on(EVENT[END], Y.bind(this._onEnd, this), null, node, subscriber, ce);
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync // Internal DOM listener to identify the end of the gesture. Fires the
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync // synthetic flick event.
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync if (e.changedTouches.length === 1 && e.touches.length === 0) {
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync axis = params.axis || (Math.abs(xyDistance[0]) >= Math.abs(xyDistance[1])) ? 'x' : 'y';
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync if (isFinite(velocity) && velocity >= params.minVelocity && absDistance >= params.minDistance) {
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync}, '@VERSION@' ,{requires:['node-base','event-touch','event-synthetic']});
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync// TODO: Better way to sniff 'n' switch touch support?
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync // TODO: Should this be in SynthEvent as the default?
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync return subscriber._extra.root || (node.get(NODE_TYPE) === 9) ? node : node.get(OWNER_DOCUMENT);
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync node.setData(_MOVE_START_HANDLE, node.on(EVENT[START],
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync var startHandle = node.getData(_MOVE_START_HANDLE);
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync e.currentTarget = e.currentTarget || origE.currentTarget;
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync var move = subscriber._extra.standAlone || node.getData(_MOVE_START),
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync e.currentTarget = e.currentTarget || origE.currentTarget;
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync var moveEnd = subscriber._extra.standAlone || node.getData(_MOVE) || node.getData(_MOVE_START),
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync e.currentTarget = e.currentTarget || origE.currentTarget;
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync}, '@VERSION@' ,{requires:['node-base','event-touch','event-synthetic']});
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsyncYUI.add('event-gestures', function(Y){}, '@VERSION@' ,{use:['event-flick', 'event-move']});