2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('event-touch', function (Y, NAME) {
11 Adds touch event facade normalization properties (touches, changedTouches, targetTouches etc.) to the DOM event facade. Adds
12 touch events to the DOM events whitelist.
15 YUI().use('event-touch', function (Y) {
16 Y.one('#myDiv').on('touchstart', function(e) {
21 @submodule event-touch
24 ROTATION = "rotation",
25 IDENTIFIER = "identifier",
30 * Adds touch event facade normalization properties to the DOM event facade
35 * @param ev {Event} the DOM event
36 * @param currentTarget {HTMLElement} the element the listener was attached to
37 * @param wrapper {Event.Custom} the custom event wrapper for this DOM event
39 Y.DOMEventFacade.prototype._touch = function(e, currentTarget, wrapper) {
41 var i,l, etCached, et,touchCache;
43 Y.log("Calling facade._touch() with e = " + e, "info", "event-touch");
46 Y.log("Found e.touches. Replicating on facade");
49 * Array of individual touch events for touch points that are still in
50 * contact with the touch surface.
53 * @type {DOMEventFacade[]}
58 for (i = 0, l = e.touches.length; i < l; ++i) {
60 touchCache[Y.stamp(et)] = this.touches[i] = new Y.DOMEventFacade(et, currentTarget, wrapper);
64 if (e.targetTouches) {
65 Y.log("Found e.targetTouches. Replicating on facade", "info", "event-touch");
68 * Array of individual touch events still in contact with the touch
69 * surface and whose `touchstart` event occurred inside the same taregt
70 * element as the current target element.
72 * @property targetTouches
73 * @type {DOMEventFacade[]}
75 this.targetTouches = [];
77 for (i = 0, l = e.targetTouches.length; i < l; ++i) {
78 et = e.targetTouches[i];
79 etCached = touchCache && touchCache[Y.stamp(et, true)];
81 this.targetTouches[i] = etCached || new Y.DOMEventFacade(et, currentTarget, wrapper);
83 if (etCached) { Y.log("Found native event in touches. Using same facade in targetTouches", "info", "event-touch"); }
87 if (e.changedTouches) {
88 Y.log("Found e.changedTouches. Replicating on facade", "info", "event-touch");
91 An array of event-specific touch events.
93 For `touchstart`, the touch points that became active with the current
96 For `touchmove`, the touch points that have changed since the last
99 For `touchend`, the touch points that have been removed from the touch
102 @property changedTouches
103 @type {DOMEventFacade[]}
105 this.changedTouches = [];
107 for (i = 0, l = e.changedTouches.length; i < l; ++i) {
108 et = e.changedTouches[i];
109 etCached = touchCache && touchCache[Y.stamp(et, true)];
111 this.changedTouches[i] = etCached || new Y.DOMEventFacade(et, currentTarget, wrapper);
113 if (etCached) { Y.log("Found native event in touches. Using same facade in changedTouches", "info", "event-touch"); }
118 this[SCALE] = e[SCALE];
122 this[ROTATION] = e[ROTATION];
125 if (IDENTIFIER in e) {
126 this[IDENTIFIER] = e[IDENTIFIER];
130 //Adding MSPointer events to whitelisted DOM Events. MSPointer event payloads
131 //have the same properties as mouse events.
132 if (Y.Node.DOM_EVENTS) {
133 Y.mix(Y.Node.DOM_EVENTS, {
147 //Add properties to Y.EVENT.GESTURE_MAP based on feature detection.
148 if ((win && ("ontouchstart" in win)) && !(Y.UA.chrome && Y.UA.chrome < 6)) {
149 GESTURE_MAP.start = ["touchstart", "mousedown"];
150 GESTURE_MAP.end = ["touchend", "mouseup"];
151 GESTURE_MAP.move = ["touchmove", "mousemove"];
152 GESTURE_MAP.cancel = ["touchcancel", "mousecancel"];
157 else if (win && ("msPointerEnabled" in win.navigator)) {
158 GESTURE_MAP.start = "MSPointerDown";
159 GESTURE_MAP.end = "MSPointerUp";
160 GESTURE_MAP.move = "MSPointerMove";
161 GESTURE_MAP.cancel = "MSPointerCancel";
165 GESTURE_MAP.start = "mousedown";
166 GESTURE_MAP.end = "mouseup";
167 GESTURE_MAP.move = "mousemove";
168 GESTURE_MAP.cancel = "mousecancel";
172 * A object literal with keys "start", "end", and "move". The value for each key is a
173 * string representing the event for that environment. For touch environments, the respective
174 * values are "touchstart", "touchend" and "touchmove". Mouse and MSPointer environments are also
175 * supported via feature detection.
177 * @property _GESTURE_MAP
181 Y.Event._GESTURE_MAP = GESTURE_MAP;
184 }, '3.13.0', {"requires": ["node-base"]});