Merge branch 'MDL-32509' of git://github.com/danpoltawski/moodle
[moodle.git] / lib / yui / 3.5.0 / build / event-touch / event-touch-debug.js
blobe0f9d07a4ede160dcdb76de07b68282d92a35441
1 /*
2 YUI 3.5.0 (build 5089)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('event-touch', function(Y) {
9 /**
10  * Adds touch event facade normalization properties (touches, changedTouches, targetTouches etc.) to the DOM event facade
11  *
12  * @module event-touch
13  */
15 var SCALE = "scale",
16     ROTATION = "rotation",
17     IDENTIFIER = "identifier";
19 /**
20  * Adds touch event facade normalization properties to the DOM event facade
21  *
22  * @method _touch
23  * @for DOMEventFacade
24  * @private
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
28  */
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);
35     if (e.touches) {
36         Y.log("Found e.touches. Replicating on facade");
38         /**
39          * Array of individual touch events for touch points that are still in
40          * contact with the touch surface.
41          *
42          * @property touches
43          * @type {DOMEventFacade[]}
44          */
45         this.touches = [];
46         touchCache = {};
48         for (i = 0, l = e.touches.length; i < l; ++i) {
49             et = e.touches[i];
50             touchCache[Y.stamp(et)] = this.touches[i] = new Y.DOMEventFacade(et, currentTarget, wrapper);
51         }
52     }
54     if (e.targetTouches) {
55         Y.log("Found e.targetTouches. Replicating on facade");
57         /**
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.
61          *
62          * @property targetTouches
63          * @type {DOMEventFacade[]}
64          */
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);
72             
73             if (etCached) { Y.log("Found native event in touches. Using same facade in targetTouches"); }
74         }
75     }
77     if (e.changedTouches) {
78         Y.log("Found e.changedTouches. Replicating on facade");        
80         /**
81         An array of event-specific touch events.
83         For `touchstart`, the touch points that became active with the current
84         event.
86         For `touchmove`, the touch points that have changed since the last
87         event.
88         
89         For `touchend`, the touch points that have been removed from the touch
90         surface.
92         @property changedTouches
93         @type {DOMEventFacade[]}
94         **/
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);
102             
103             if (etCached) { Y.log("Found native event in touches. Using same facade in changedTouches"); }
104         }
105     }
107     if (SCALE in e) {
108         this[SCALE] = e[SCALE];
109     }
111     if (ROTATION in e) {
112         this[ROTATION] = e[ROTATION];
113     }
115     if (IDENTIFIER in e) {
116         this[IDENTIFIER] = e[IDENTIFIER];
117     }
120 if (Y.Node.DOM_EVENTS) {
121     Y.mix(Y.Node.DOM_EVENTS, {
122         touchstart:1,
123         touchmove:1,
124         touchend:1,
125         touchcancel:1,
126         gesturestart:1,
127         gesturechange:1,
128         gestureend:1
129     });
133 }, '3.5.0' ,{requires:['node-base']});