event-gestures-debug.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
});
/**
* Adds lower level support for "gesturemovestart", "gesturemove" and "gesturemoveend" events, which can be used to create drag/drop
* interactions which work across touch and mouse input devices. They correspond to "touchstart", "touchmove" and "touchend" on a touch input
* device, and "mousedown", "mousemove", "mouseup" on a mouse based input device.
*
* @module event-gestures
* @submodule event-move
*/
start: "touchstart",
move: "touchmove",
end: "touchend"
} : {
start: "mousedown",
move: "mousemove",
end: "mouseup"
},
START = "start",
MOVE = "move",
END = "end",
_MOVE_START_HANDLE = "_msh",
_MOVE_HANDLE = "_mh",
_MOVE_END_HANDLE = "_meh",
_DEL_MOVE_START_HANDLE = "_dmsh",
_DEL_MOVE_HANDLE = "_dmh",
_DEL_MOVE_END_HANDLE = "_dmeh",
_MOVE_START = "_ms",
_MOVE = "_m",
MIN_TIME = "minTime",
MIN_DISTANCE = "minDistance",
PREVENT_DEFAULT = "preventDefault",
BUTTON = "button",
OWNER_DOCUMENT = "ownerDocument",
CURRENT_TARGET = "currentTarget",
TARGET = "target",
NODE_TYPE = "nodeType",
if (!(PREVENT_DEFAULT in config)) {
}
return config;
},
},
touchFacade[BUTTON] = (params && params[BUTTON]) || 1; // default to left (left as per vendors, not W3C which is 0)
},
_prevent = function(e, preventDefault) {
if (preventDefault) {
// preventDefault is a boolean or a function
e.preventDefault();
}
}
},
/**
* Sets up a "gesturemovestart" event, that is fired on touch devices in response to a single finger "touchstart",
* and on mouse based devices in response to a "mousedown". The subscriber can specify the minimum time
* and distance thresholds which should be crossed before the "gesturemovestart" is fired and for the mouse,
* which button should initiate a "gesturemovestart". This event can also be listened for using node.delegate().
*
* <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/delegate,
* you need to provide a null value for the configuration object, e.g: <code>node.on("gesturemovestart", fn, null, context, arg1, arg2, arg3)</code></p>
*
* @event gesturemovestart
* @for YUI
* @param type {string} "gesturemovestart"
* @param fn {function} The method the event invokes. It receives the event facade of the underlying DOM event (mousedown or touchstart.touches[0]) which contains position co-ordinates.
* @param cfg {Object} Optional. An object which specifies:
*
* <dl>
* <dt>minDistance (defaults to 0)</dt>
* <dd>The minimum distance threshold which should be crossed before the gesturemovestart is fired</dd>
* <dt>minTime (defaults to 0)</dt>
* <dd>The minimum time threshold for which the finger/mouse should be help down before the gesturemovestart is fired</dd>
* <dt>button (no default)</dt>
* <dd>In the case of a mouse input device, if the event should only be fired for a specific mouse button.</dd>
* <dt>preventDefault (defaults to false)</dt>
* <dd>Can be set to true/false to prevent default behavior as soon as the touchstart or mousedown is received (that is before minTime or minDistance thresholds are crossed, and so before the gesturemovestart listener is notified) so that things like text selection and context popups (on touch devices) 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 (for example, DragDrop can determine if the target is a valid handle or not before preventing default).</dd>
* </dl>
*
* @return {EventHandle} the detach handle
*/
this._onStart,
this,
node,
ce);
},
var se = this;
function(e) {
},
filter);
},
if (handle) {
subscriber[_DEL_MOVE_START_HANDLE] = null;
}
},
if (startHandle) {
subscriber[_MOVE_START_HANDLE] = null;
}
},
}
if (!(MIN_DISTANCE in params)) {
}
return params;
},
if (delegate) {
node = e[CURRENT_TARGET];
}
fireStart = true,
if (e.touches) {
} else {
fireStart = false;
}
} else {
}
Y.log("gesturemovestart: params = button:" + button + ", minTime = " + minTime + ", minDistance = " + minDistance, "event-gestures");
if (fireStart) {
_prevent(e, preventDefault);
} else {
if (minTime > 0) {
}, this));
}
if (minDistance > 0) {
Y.log("gesturemovestart: minDistance specified. Setup native mouse/touchmove listener to measure distance.", "event-gestures");
if (Math.abs(em.pageX - startXY[0]) > minDistance || Math.abs(em.pageY - startXY[1]) > minDistance) {
}
}, this));
}
}
}
},
}
}
}
},
if (params) {
}
e.type = GESTURE_MOVE_START;
},
MIN_TIME : 0,
MIN_DISTANCE : 0,
PREVENT_DEFAULT : false
});
/**
* Sets up a "gesturemove" event, that is fired on touch devices in response to a single finger "touchmove",
* and on mouse based devices in response to a "mousemove".
*
* <p>By default this event is only fired when the same node
* has received a "gesturemovestart" event. The subscriber can set standAlone to true, in the configuration properties,
* if they want to listen for this event without an initial "gesturemovestart".</p>
*
* <p>By default this event sets up it's internal "touchmove" and "mousemove" DOM listeners on the document element. The subscriber
* can set the root configuration property, to specify which node to attach DOM listeners to, if different from the document.</p>
*
* <p>This event can also be listened for using node.delegate().</p>
*
* <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/delegate,
* you need to provide a null value for the configuration object, e.g: <code>node.on("gesturemove", fn, null, context, arg1, arg2, arg3)</code></p>
*
* @event gesturemove
* @for YUI
* @param type {string} "gesturemove"
* @param fn {function} The method the event invokes. It receives the event facade of the underlying DOM event (mousemove or touchmove.touches[0]) which contains position co-ordinates.
* @param cfg {Object} Optional. An object which specifies:
* <dl>
* <dt>standAlone (defaults to false)</dt>
* <dd>true, if the subscriber should be notified even if a "gesturemovestart" has not occured on the same node.</dd>
* <dt>root (defaults to document)</dt>
* <dd>The node to which the internal DOM listeners should be attached.</dd>
* <dt>preventDefault (defaults to false)</dt>
* <dd>Can be set to true/false to prevent default behavior as soon as the touchmove or mousemove is received. As with gesturemovestart, can also be set to function which returns true/false based on the event facade passed to it.</dd>
* </dl>
*
* @return {EventHandle} the detach handle
*/
this._onMove,
this,
node,
ce);
},
var se = this;
function(e) {
},
filter);
},
if (moveHandle) {
moveHandle.detach();
subscriber[_MOVE_HANDLE] = null;
}
},
if (handle) {
subscriber[_DEL_MOVE_HANDLE] = null;
}
},
},
if (delegate) {
node = e[CURRENT_TARGET];
}
if (fireMove) {
if (e.touches) {
} else {
fireMove = false;
}
}
if (fireMove) {
_prevent(e, preventDefault);
e.type = GESTURE_MOVE;
}
}
},
PREVENT_DEFAULT : false
});
/**
* Sets up a "gesturemoveend" event, that is fired on touch devices in response to a single finger "touchend",
* and on mouse based devices in response to a "mouseup".
*
* <p>By default this event is only fired when the same node
* has received a "gesturemove" or "gesturemovestart" event. The subscriber can set standAlone to true, in the configuration properties,
* if they want to listen for this event without a preceding "gesturemovestart" or "gesturemove".</p>
*
* <p>By default this event sets up it's internal "touchend" and "mouseup" DOM listeners on the document element. The subscriber
* can set the root configuration property, to specify which node to attach DOM listeners to, if different from the document.</p>
*
* <p>This event can also be listened for using node.delegate().</p>
*
* <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/delegate,
* you need to provide a null value for the configuration object, e.g: <code>node.on("gesturemoveend", fn, null, context, arg1, arg2, arg3)</code></p>
*
*
* @event gesturemoveend
* @for YUI
* @param type {string} "gesturemoveend"
* @param fn {function} The method the event invokes. It receives the event facade of the underlying DOM event (mouseup or touchend.changedTouches[0]).
* @param cfg {Object} Optional. An object which specifies:
* <dl>
* <dt>standAlone (defaults to false)</dt>
* <dd>true, if the subscriber should be notified even if a "gesturemovestart" or "gesturemove" has not occured on the same node.</dd>
* <dt>root (defaults to document)</dt>
* <dd>The node to which the internal DOM listeners should be attached.</dd>
* <dt>preventDefault (defaults to false)</dt>
* <dd>Can be set to true/false to prevent default behavior as soon as the touchend or mouseup is received. As with gesturemovestart, can also be set to function which returns true/false based on the event facade passed to it.</dd>
* </dl>
*
* @return {EventHandle} the detach handle
*/
this._onEnd,
this,
node,
ce);
},
var se = this;
function(e) {
},
filter);
},
if (handle) {
subscriber[_DEL_MOVE_END_HANDLE] = null;
}
},
if (endHandle) {
subscriber[_MOVE_END_HANDLE] = null;
}
},
},
if (delegate) {
node = e[CURRENT_TARGET];
}
if (fireMoveEnd) {
if (e.changedTouches) {
} else {
fireMoveEnd = false;
}
}
if (fireMoveEnd) {
_prevent(e, preventDefault);
e.type = GESTURE_MOVE_END;
}
}
},
PREVENT_DEFAULT : false
});