diff options
Diffstat (limited to 'node_modules/montage-user/core/event/event-manager.js')
-rwxr-xr-x | node_modules/montage-user/core/event/event-manager.js | 2080 |
1 files changed, 2080 insertions, 0 deletions
diff --git a/node_modules/montage-user/core/event/event-manager.js b/node_modules/montage-user/core/event/event-manager.js new file mode 100755 index 00000000..4adc3926 --- /dev/null +++ b/node_modules/montage-user/core/event/event-manager.js | |||
@@ -0,0 +1,2080 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | * | ||
8 | * @author: Lea Verou | ||
9 | * @license: Licensed under The MIT License. See license.txt and http://www.opensource.org/licenses/mit-license.php. | ||
10 | * @website: http://leaverou.github.com/chainvas/ | ||
11 | */ | ||
12 | |||
13 | /** | ||
14 | @module montage/core/event/event-manager | ||
15 | @requires montage/core/core | ||
16 | @requires montage/core/event/mutable-event | ||
17 | @requires montage/core/event/action-event-listener | ||
18 | */ | ||
19 | |||
20 | var Montage = require("montage").Montage, | ||
21 | MutableEvent = require("core/event/mutable-event").MutableEvent, | ||
22 | ActionEventListener = require("core/event/action-event-listener").ActionEventListener, | ||
23 | Serializer = require("core/serializer").Serializer, | ||
24 | Deserializer = require("core/deserializer").Deserializer, | ||
25 | defaultEventManager; | ||
26 | |||
27 | // XXX Does not presently function server-side | ||
28 | if (typeof window !== "undefined") { // client-side | ||
29 | |||
30 | /* This is to handle browsers that have TouchEvents but don't have the global constructor function Touch */ | ||
31 | //if(TouchEvent && typeof window.Touch === "undefined") { | ||
32 | // HACK: The commented expression fails because Chrome on the desktop also has TouchEvent and in the code we're either registering touch events OR mouse events on most components. | ||
33 | if (typeof window.Touch === "undefined" && /Xoom|TouchPad/.test(navigator.userAgent)) { | ||
34 | window.Touch = function() { | ||
35 | }; | ||
36 | (function() { | ||
37 | var onFirstTouchstart; | ||
38 | |||
39 | document.addEventListener("touchstart", onFirstTouchstart = function (event) { | ||
40 | window.Touch = event.touches[0].constructor; | ||
41 | if (document.nativeRemoveEventListener) { | ||
42 | document.nativeRemoveEventListener("touchstart", onFirstTouchstart, true); | ||
43 | } else { | ||
44 | document.removeEventListener("touchstart", onFirstTouchstart, true); | ||
45 | } | ||
46 | if (defaultEventManager && defaultEventManager.isStoringPointerEvents) { | ||
47 | defaultEventManager.isStoringPointerEvents = false; | ||
48 | defaultEventManager.isStoringPointerEvents = true; | ||
49 | } | ||
50 | }, true); | ||
51 | })(); | ||
52 | } | ||
53 | |||
54 | /** | ||
55 | @external Element | ||
56 | */ | ||
57 | |||
58 | /** | ||
59 | HTML element event handler UUID | ||
60 | @member external:Element#eventHandlerUUID | ||
61 | */ | ||
62 | Montage.defineProperty(Element.prototype, "eventHandlerUUID", /** @lends module:montage/core/event/event-manager.defineProperty */ { | ||
63 | value: undefined, | ||
64 | enumerable: false | ||
65 | }); | ||
66 | |||
67 | |||
68 | /** | ||
69 | The controller (Montage component) for the element. | ||
70 | @member external:Element#controller | ||
71 | */ | ||
72 | Montage.defineProperty(Element.prototype, "controller", { | ||
73 | get: function() { | ||
74 | return defaultEventManager._elementEventHandlerByUUID[this.eventHandlerUUID]; | ||
75 | }, | ||
76 | enumerable: false | ||
77 | }); | ||
78 | |||
79 | |||
80 | /** | ||
81 | @function external:Object#dispatchEvent | ||
82 | */ | ||
83 | Montage.defineProperty(Object.prototype, "dispatchEvent", { | ||
84 | value: function(event) { | ||
85 | var targettedEvent = MutableEvent.fromEvent(event); | ||
86 | targettedEvent.target = this; | ||
87 | defaultEventManager.handleEvent(targettedEvent); | ||
88 | }, | ||
89 | enumerable: false | ||
90 | }); | ||
91 | |||
92 | var EventListenerDescriptor = Montage.create(Montage, { | ||
93 | type: { | ||
94 | serializable: true, | ||
95 | value: null | ||
96 | }, | ||
97 | |||
98 | listener: { | ||
99 | serializable: "reference", | ||
100 | value: null | ||
101 | }, | ||
102 | |||
103 | capture: { | ||
104 | serializable: true, | ||
105 | value: null | ||
106 | } | ||
107 | }); | ||
108 | |||
109 | Serializer.defineSerializationUnit("listeners", function(object) { | ||
110 | var eventManager = defaultEventManager, | ||
111 | uuid = object.uuid, | ||
112 | eventListenerDescriptors = [], | ||
113 | descriptors, | ||
114 | descriptor, | ||
115 | listenerDescriptor, | ||
116 | listener; | ||
117 | |||
118 | for (var type in eventManager.registeredEventListeners) { | ||
119 | descriptors = eventManager.registeredEventListeners[type]; | ||
120 | descriptor = descriptors && descriptors[uuid]; | ||
121 | if (descriptor) { | ||
122 | for (var listenerUuid in descriptor.listeners) { | ||
123 | listener = descriptor.listeners[listenerUuid]; | ||
124 | |||
125 | eventListenerDescriptor = EventListenerDescriptor.create(); | ||
126 | eventListenerDescriptor.type = type; | ||
127 | eventListenerDescriptor.listener = listener.listener; | ||
128 | eventListenerDescriptor.capture = listener.capture; | ||
129 | |||
130 | eventListenerDescriptors.push(eventListenerDescriptor); | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | |||
135 | if (eventListenerDescriptors.length > 0) { | ||
136 | return eventListenerDescriptors; | ||
137 | } | ||
138 | }); | ||
139 | |||
140 | Deserializer.defineDeserializationUnit("listeners", function(object, listeners) { | ||
141 | for (var i = 0, listener; (listener = listeners[i]); i++) { | ||
142 | object.addEventListener(listener.type, listener.listener, listener.capture); | ||
143 | } | ||
144 | }); | ||
145 | |||
146 | var CAPTURING_PHASE = 1, | ||
147 | AT_TARGET = 2, | ||
148 | BUBBLING_PHASE = 3; | ||
149 | |||
150 | /** | ||
151 | @class module:montage/core/event/event-manager.EventManager | ||
152 | */ | ||
153 | var EventManager = exports.EventManager = Montage.create(Montage,/** @lends module:montage/core/event/event-manager.EventManager# */ { | ||
154 | |||
155 | // Utility | ||
156 | eventDefinitions: { | ||
157 | value: { | ||
158 | "mousedown": { | ||
159 | bubbles: true, | ||
160 | type: "MouseEvents" | ||
161 | }, | ||
162 | "mouseup": { | ||
163 | bubbles: true, | ||
164 | type: "MouseEvents" | ||
165 | }, | ||
166 | "mousemove": { | ||
167 | bubbles: true, | ||
168 | type: "MouseEvents" | ||
169 | }, | ||
170 | "click": { | ||
171 | bubbles: true, | ||
172 | type: "MouseEvents" | ||
173 | }, | ||
174 | "dblclick": { | ||
175 | bubbles: true, | ||
176 | type: "MouseEvents" | ||
177 | }, | ||
178 | "mouseover": { | ||
179 | bubbles: true, | ||
180 | type: "MouseEvents" | ||
181 | }, | ||
182 | "mouseout": { | ||
183 | bubbles: true, | ||
184 | type: "MouseEvents" | ||
185 | }, | ||
186 | |||
187 | "contextmenu": { | ||
188 | bubbles: true | ||
189 | }, | ||
190 | |||
191 | "touchstart": { | ||
192 | bubbles: true, | ||
193 | type: "TouchEvents" | ||
194 | }, | ||
195 | "touchend": { | ||
196 | bubbles: true, | ||
197 | type: "TouchEvents" | ||
198 | }, | ||
199 | "touchmove": { | ||
200 | bubbles: true, | ||
201 | type: "TouchEvents" | ||
202 | }, | ||
203 | "touchcancel": { | ||
204 | bubbles: true, | ||
205 | type: "TouchEvents" | ||
206 | }, | ||
207 | |||
208 | "copy": { | ||
209 | bubbles: true | ||
210 | }, | ||
211 | "cut": { | ||
212 | bubbles: true | ||
213 | }, | ||
214 | "paste": { | ||
215 | bubbles: true | ||
216 | }, | ||
217 | |||
218 | "keyup": { | ||
219 | bubbles: true, | ||
220 | type: "KeyEvents" | ||
221 | }, | ||