3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('event-touch', function(Y) {
10 * Adds touch event facade normalization properties (touches, changedTouches, targetTouches etc.) to the DOM event facade
16 ROTATION = "rotation",
17 IDENTIFIER = "identifier";
20 * Adds touch event facade normalization properties to the DOM event facade
25 * @param ev {Event} the DOM event
26 * @param currentTarget {HTMLElement} the element the listener was attached to
27 * @param wrapper {Event.Custom} the custom event wrapper for this DOM event
29 Y.DOMEventFacade.prototype._touch = function(e, currentTarget, wrapper) {
31 var i,l, etCached, et,touchCache;
33 Y.log("Calling facade._touch() with e = " + e);
36 Y.log("Found e.touches. Replicating on facade");
39 * Array of individual touch events for touch points that are still in
40 * contact with the touch surface.
43 * @type {DOMEventFacade[]}
48 for (i = 0, l = e.touches.length; i < l; ++i) {
50 touchCache[Y.stamp(et)] = this.touches[i] = new Y.DOMEventFacade(et, currentTarget, wrapper);
54 if (e.targetTouches) {
55 Y.log("Found e.targetTouches. Replicating on facade");
58 * Array of individual touch events still in contact with the touch
59 * surface and whose `touchstart` event occurred inside the same taregt
60 * element as the current target element.
62 * @property targetTouches
63 * @type {DOMEventFacade[]}
65 this.targetTouches = [];
67 for (i = 0, l = e.targetTouches.length; i < l; ++i) {
68 et = e.targetTouches[i];
69 etCached = touchCache && touchCache[Y.stamp(et, true)];
71 this.targetTouches[i] = etCached || new Y.DOMEventFacade(et, currentTarget, wrapper);
73 if (etCached) { Y.log("Found native event in touches. Using same facade in targetTouches"); }
77 if (e.changedTouches) {
78 Y.log("Found e.changedTouches. Replicating on facade");
81 An array of event-specific touch events.
83 For `touchstart`, the touch points that became active with the current
86 For `touchmove`, the touch points that have changed since the last
89 For `touchend`, the touch points that have been removed from the touch
92 @property changedTouches
93 @type {DOMEventFacade[]}
95 this.changedTouches = [];
97 for (i = 0, l = e.changedTouches.length; i < l; ++i) {
98 et = e.changedTouches[i];
99 etCached = touchCache && touchCache[Y.stamp(et, true)];
101 this.changedTouches[i] = etCached || new Y.DOMEventFacade(et, currentTarget, wrapper);
103 if (etCached) { Y.log("Found native event in touches. Using same facade in changedTouches"); }
108 this[SCALE] = e[SCALE];
112 this[ROTATION] = e[ROTATION];
115 if (IDENTIFIER in e) {
116 this[IDENTIFIER] = e[IDENTIFIER];
120 if (Y.Node.DOM_EVENTS) {
121 Y.mix(Y.Node.DOM_EVENTS, {
133 }, '3.5.1' ,{requires:['node-base']});