Flick.js revision 16f6ce56ed5f7889fc7449bba668a85f8a39bd84
/**
* The gestures module provides gesture events such as "flick", which normalize user interactions
* across touch and mouse or pointer based input devices. This layer can be used by application developers
* to build input device agnostic components which behave the same in response to either touch or mouse based
* interaction.
*
* <p>Documentation for events added by this module can be found in the event document for the <a href="YUI.html#events">YUI</event> global.</p>
*
* @module event-gestures
*/
/**
* Adds support for a "flick" event, which is fired at the end of a touch or mouse based flick gesture, and provides
* velocity of the flick, along with distance and time information.
*
* @module event-gestures
* @submodule event-flick
*/
start: "touchstart",
end: "touchend"
} : {
start: "mousedown",
end: "mouseup"
},
START = "start",
END = "end",
OWNER_DOCUMENT = "ownerDocument",
MIN_VELOCITY = "minVelocity",
MIN_DISTANCE = "minDistance",
PREVENT_DEFAULT = "preventDefault",
_FLICK_START = "_fs",
_FLICK_START_HANDLE = "_fsh",
_FLICK_END_HANDLE = "_feh",
NODE_TYPE = "nodeType";
/**
* Sets up a "flick" event, that is fired whenever the user initiates a flick gesture on the node
* where the listener is attached. The subscriber can specify a minimum distance or velocity for
* which the event is to be fired. The subscriber can also specify if there is a particular axis which
* they are interested in - "x" or "y". If no axis is specified, the axis along which there was most distance
* covered is used.
*
* <p>It is recommended that you use Y.bind to set up context and additional arguments for your event handler,
* however if you want to pass the context and arguments as additional signature arguments to "on",
* you need to provide a null value for the configuration object, e.g: <code>node.on("flick", fn, null, context, arg1, arg2, arg3)</code></p>
*
* @event flick
* @for YUI
* @param type {string} "flick"
* @param fn {function} The method the event invokes. It receives an event facade with an e.flick object containing the flick related properties: e.flick.time, e.flick.distance, e.flick.velocity and e.flick.axis, e.flick.start.
* @param cfg {Object} Optional. An object which specifies any of the following:
* <dl>
* <dt>minDistance (in pixels, defaults to 10)</dt>
* <dd>The minimum distance between start and end points, which would qualify the gesture as a flick.</dd>
* <dd>The minimum velocity which would qualify the gesture as a flick.</dd>
* <dt>preventDefault (defaults to true)</dt>
* <dd>Can be set to true/false to prevent default behavior as soon as the touchstart/touchend or mousedown/mouseup is received so that things like scrolling or text selection can be
* prevented. This property can also be set to a function, which returns true or false, based on the event facade passed to it.</dd>
* </dl>
* @return {EventHandle} the detach handle
*/
this._onStart,
this,
node,
ce);
},
if (startHandle) {
subscriber[_FLICK_START_HANDLE] = null;
}
if (endHandle) {
subscriber[_FLICK_END_HANDLE] = null;
}
},
processArgs: function(args) {
if (!(MIN_VELOCITY in params)) {
}
if (!(MIN_DISTANCE in params)) {
}
if (!(PREVENT_DEFAULT in params)) {
}
Y.log("flick, processArgs : minDistance =" + params.minDistance + ", minVelocity =" + params.minVelocity + ", preventDefault = " + params.preventDefault);
return params;
},
var start = true, // always true for mouse
doc,
origE = e;
if (e.touches) {
e = e.touches[0];
}
if (start) {
if (preventDefault) {
// preventDefault is a boolean or function
}
}
e.flick = {
};
subscriber[_FLICK_START] = e;
if (!endHandle) {
}
}
},
endEvent = e,
time,
axis;
if (valid) {
if (e.changedTouches) {
} else {
valid = false;
}
}
if (valid) {
if (preventDefault) {
// preventDefault is a boolean or function
}
}
xyDistance = [
];
if (isFinite(velocity) && (Math.abs(distance) >= params[MIN_DISTANCE]) && (Math.abs(velocity) >= params[MIN_VELOCITY])) {
e.type = "flick";
e.flick = {
};
}
subscriber[_FLICK_START] = null;
}
}
},
MIN_VELOCITY : 0,
MIN_DISTANCE : 0,
PREVENT_DEFAULT : true
});