react 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/README.md +15 -228
  2. package/ReactJSErrors.js +40 -0
  3. package/addons.js +4 -0
  4. package/lib/$.js +46 -0
  5. package/lib/CSSCore.js +114 -0
  6. package/lib/CSSProperty.js +90 -0
  7. package/lib/CSSPropertyOperations.js +97 -0
  8. package/lib/CallbackRegistry.js +91 -0
  9. package/lib/ChangeEventPlugin.js +365 -0
  10. package/lib/CompositionEventPlugin.js +212 -0
  11. package/lib/DOMChildrenOperations.js +135 -0
  12. package/lib/DOMProperty.js +266 -0
  13. package/lib/DOMPropertyOperations.js +168 -0
  14. package/lib/Danger.js +186 -0
  15. package/lib/DefaultDOMPropertyConfig.js +187 -0
  16. package/lib/DefaultEventPluginOrder.js +44 -0
  17. package/lib/EnterLeaveEventPlugin.js +112 -0
  18. package/lib/EventConstants.js +73 -0
  19. package/lib/EventListener.js +61 -0
  20. package/lib/EventPluginHub.js +190 -0
  21. package/lib/EventPluginRegistry.js +237 -0
  22. package/lib/EventPluginUtils.js +185 -0
  23. package/lib/EventPropagators.js +179 -0
  24. package/lib/ExecutionEnvironment.js +41 -0
  25. package/lib/LinkedStateMixin.js +46 -0
  26. package/lib/LinkedValueMixin.js +68 -0
  27. package/lib/MobileSafariClickEventPlugin.js +63 -0
  28. package/lib/PooledClass.js +113 -0
  29. package/lib/React.js +71 -0
  30. package/lib/ReactChildren.js +132 -0
  31. package/lib/ReactComponent.js +515 -0
  32. package/lib/ReactComponentBrowserEnvironment.js +140 -0
  33. package/lib/ReactComponentEnvironment.js +24 -0
  34. package/lib/ReactCompositeComponent.js +1020 -0
  35. package/lib/ReactCurrentOwner.js +39 -0
  36. package/lib/ReactDOM.js +194 -0
  37. package/lib/ReactDOMButton.js +64 -0
  38. package/lib/ReactDOMComponent.js +374 -0
  39. package/lib/ReactDOMForm.js +52 -0
  40. package/lib/ReactDOMIDOperations.js +173 -0
  41. package/lib/ReactDOMInput.js +169 -0
  42. package/lib/ReactDOMOption.js +50 -0
  43. package/lib/ReactDOMSelect.js +160 -0
  44. package/lib/ReactDOMSelection.js +189 -0
  45. package/lib/ReactDOMTextarea.js +136 -0
  46. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  47. package/lib/ReactDefaultInjection.js +91 -0
  48. package/lib/ReactDefaultPerf.js +407 -0
  49. package/lib/ReactErrorUtils.js +46 -0
  50. package/lib/ReactEventEmitter.js +341 -0
  51. package/lib/ReactEventEmitterMixin.js +89 -0
  52. package/lib/ReactEventTopLevelCallback.js +89 -0
  53. package/lib/ReactInputSelection.js +140 -0
  54. package/lib/ReactInstanceHandles.js +322 -0
  55. package/lib/ReactLink.js +54 -0
  56. package/lib/ReactMarkupChecksum.js +53 -0
  57. package/lib/ReactMount.js +617 -0
  58. package/lib/ReactMountReady.js +95 -0
  59. package/lib/ReactMultiChild.js +441 -0
  60. package/lib/ReactMultiChildUpdateTypes.js +36 -0
  61. package/lib/ReactOwner.js +146 -0
  62. package/lib/ReactPerf.js +88 -0
  63. package/lib/ReactPropTransferer.js +128 -0
  64. package/lib/ReactPropTypes.js +158 -0
  65. package/lib/ReactReconcileTransaction.js +161 -0
  66. package/lib/ReactServerRendering.js +62 -0
  67. package/lib/ReactStateSetters.js +111 -0
  68. package/lib/ReactTextComponent.js +94 -0
  69. package/lib/ReactTransitionEvents.js +97 -0
  70. package/lib/ReactTransitionGroup.js +112 -0
  71. package/lib/ReactTransitionKeySet.js +111 -0
  72. package/lib/ReactTransitionableChild.js +152 -0
  73. package/lib/ReactUpdates.js +145 -0
  74. package/lib/ReactWithAddons.js +41 -0
  75. package/lib/SelectEventPlugin.js +217 -0
  76. package/lib/SimpleEventPlugin.js +365 -0
  77. package/lib/SyntheticClipboardEvent.js +45 -0
  78. package/lib/SyntheticCompositionEvent.js +51 -0
  79. package/lib/SyntheticEvent.js +163 -0
  80. package/lib/SyntheticFocusEvent.js +44 -0
  81. package/lib/SyntheticKeyboardEvent.js +56 -0
  82. package/lib/SyntheticMouseEvent.js +85 -0
  83. package/lib/SyntheticTouchEvent.js +50 -0
  84. package/lib/SyntheticUIEvent.js +45 -0
  85. package/lib/SyntheticWheelEvent.js +63 -0
  86. package/lib/Transaction.js +251 -0
  87. package/lib/ViewportMetrics.js +37 -0
  88. package/lib/accumulate.js +54 -0
  89. package/lib/adler32.js +39 -0
  90. package/lib/containsNode.js +49 -0
  91. package/lib/copyProperties.js +54 -0
  92. package/lib/createArrayFrom.js +94 -0
  93. package/lib/createNodesFromMarkup.js +93 -0
  94. package/lib/createObjectFrom.js +61 -0
  95. package/lib/cx.js +44 -0
  96. package/lib/dangerousStyleValue.js +57 -0
  97. package/lib/emptyFunction.js +43 -0
  98. package/lib/escapeTextForBrowser.js +47 -0
  99. package/lib/ex.js +49 -0
  100. package/lib/filterAttributes.js +45 -0
  101. package/lib/flattenChildren.js +54 -0
  102. package/lib/forEachAccumulated.js +36 -0
  103. package/lib/ge.js +76 -0
  104. package/lib/getActiveElement.js +33 -0
  105. package/lib/getEventTarget.js +36 -0
  106. package/lib/getMarkupWrap.js +108 -0
  107. package/lib/getNodeForCharacterOffset.js +80 -0
  108. package/lib/getReactRootElementInContainer.js +40 -0
  109. package/lib/getTextContentAccessor.js +40 -0
  110. package/lib/getUnboundedScrollPosition.js +45 -0
  111. package/lib/hyphenate.js +35 -0
  112. package/lib/invariant.js +54 -0
  113. package/lib/isEventSupported.js +74 -0
  114. package/lib/isNode.js +33 -0
  115. package/lib/isTextInputElement.js +49 -0
  116. package/lib/isTextNode.js +30 -0
  117. package/lib/joinClasses.js +44 -0
  118. package/lib/keyMirror.js +58 -0
  119. package/lib/keyOf.js +41 -0
  120. package/lib/memoizeStringOnly.js +39 -0
  121. package/lib/merge.js +37 -0
  122. package/lib/mergeHelpers.js +137 -0
  123. package/lib/mergeInto.js +45 -0
  124. package/lib/mixInto.js +34 -0
  125. package/lib/mutateHTMLNodeWithMarkup.js +100 -0
  126. package/lib/objMap.js +47 -0
  127. package/lib/objMapKeyVal.js +47 -0
  128. package/lib/performanceNow.js +42 -0
  129. package/lib/shallowEqual.js +49 -0
  130. package/lib/traverseAllChildren.js +127 -0
  131. package/package.json +33 -31
  132. package/react.js +4 -0
  133. package/.npmignore +0 -7
  134. package/.travis.yml +0 -7
  135. package/Jakefile.js +0 -39
  136. package/LICENSE +0 -19
  137. package/browser-test/dist.html +0 -90
  138. package/browser-test/index.html +0 -86
  139. package/browser-test/min.html +0 -90
  140. package/dist/react.js +0 -3141
  141. package/dist/react.min.js +0 -22
  142. package/doc/advanced.md +0 -175
  143. package/doc/color-def.graffle +0 -938
  144. package/doc/color-def.png +0 -0
  145. package/doc/simple.dot +0 -25
  146. package/doc/simple.png +0 -0
  147. package/examples/longer-example.js +0 -41
  148. package/examples/simple.js +0 -45
  149. package/examples/using-ast-directly.js +0 -30
  150. package/examples/using-events1.js +0 -79
  151. package/examples/using-log-events.js +0 -43
  152. package/lib/base-task.js +0 -120
  153. package/lib/cb-task.js +0 -84
  154. package/lib/core.js +0 -138
  155. package/lib/dsl.js +0 -138
  156. package/lib/error.js +0 -55
  157. package/lib/event-collector.js +0 -81
  158. package/lib/event-manager.js +0 -89
  159. package/lib/eventemitter.js +0 -20
  160. package/lib/finalcb-first-task.js +0 -68
  161. package/lib/finalcb-task.js +0 -65
  162. package/lib/id.js +0 -22
  163. package/lib/input-parser.js +0 -56
  164. package/lib/log-events.js +0 -101
  165. package/lib/parse.js +0 -41
  166. package/lib/promise-resolve.js +0 -50
  167. package/lib/promise-task.js +0 -93
  168. package/lib/react.js +0 -59
  169. package/lib/ret-task.js +0 -71
  170. package/lib/sprintf.js +0 -18
  171. package/lib/status.js +0 -14
  172. package/lib/task.js +0 -251
  173. package/lib/track-tasks.js +0 -74
  174. package/lib/validate.js +0 -159
  175. package/lib/vcon.js +0 -113
  176. package/lib/when-task.js +0 -84
  177. package/src/dist.build.requirejs +0 -20
  178. package/test/ast.mocha.js +0 -136
  179. package/test/cb-task.mocha.js +0 -220
  180. package/test/core-deferred.mocha.js +0 -143
  181. package/test/core-when.mocha.js +0 -96
  182. package/test/core.mocha.js +0 -589
  183. package/test/dsl.mocha.js +0 -352
  184. package/test/event-manager.mocha.js +0 -119
  185. package/test/exec-options.mocha.js +0 -48
  186. package/test/finalcb-task.mocha.js +0 -58
  187. package/test/input-parser.mocha.js +0 -86
  188. package/test/log-events.mocha.js +0 -88
  189. package/test/mocha.opts +0 -2
  190. package/test/module-use.mocha.js +0 -164
  191. package/test/promise-auto-resolve.mocha.js +0 -68
  192. package/test/ret-task.mocha.js +0 -220
  193. package/test/task.mocha.js +0 -42
  194. package/test/validate-cb-task.mocha.js +0 -100
  195. package/test/validate-ret-task.mocha.js +0 -110
  196. package/test/validate.mocha.js +0 -324
  197. package/test/vcon.mocha.js +0 -193
  198. package/vendor/chai/chai.js +0 -4251
  199. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  200. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  201. package/vendor/node/util.js +0 -531
  202. package/vendor/requirejs/require.js +0 -2045
  203. package/vendor/requirejs/require.min.js +0 -36
@@ -0,0 +1,341 @@
1
+ /**
2
+ * Copyright 2013 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule ReactEventEmitter
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var EventConstants = require("./EventConstants");
23
+ var EventListener = require("./EventListener");
24
+ var EventPluginHub = require("./EventPluginHub");
25
+ var ExecutionEnvironment = require("./ExecutionEnvironment");
26
+ var ReactEventEmitterMixin = require("./ReactEventEmitterMixin");
27
+ var ViewportMetrics = require("./ViewportMetrics");
28
+
29
+ var invariant = require("./invariant");
30
+ var isEventSupported = require("./isEventSupported");
31
+ var merge = require("./merge");
32
+
33
+ /**
34
+ * Summary of `ReactEventEmitter` event handling:
35
+ *
36
+ * - Top-level delegation is used to trap native browser events. We normalize
37
+ * and de-duplicate events to account for browser quirks.
38
+ *
39
+ * - Forward these native events (with the associated top-level type used to
40
+ * trap it) to `EventPluginHub`, which in turn will ask plugins if they want
41
+ * to extract any synthetic events.
42
+ *
43
+ * - The `EventPluginHub` will then process each event by annotating them with
44
+ * "dispatches", a sequence of listeners and IDs that care about that event.
45
+ *
46
+ * - The `EventPluginHub` then dispatches the events.
47
+ *
48
+ * Overview of React and the event system:
49
+ *
50
+ * .
51
+ * +------------+ .
52
+ * | DOM | .
53
+ * +------------+ . +-----------+
54
+ * + . +--------+|SimpleEvent|
55
+ * | . | |Plugin |
56
+ * +-----|------+ . v +-----------+
57
+ * | | | . +--------------+ +------------+
58
+ * | +-----------.--->|EventPluginHub| | Event |
59
+ * | | . | | +-----------+ | Propagators|
60
+ * | ReactEvent | . | | |TapEvent | |------------|
61
+ * | Emitter | . | |<---+|Plugin | |other plugin|
62
+ * | | . | | +-----------+ | utilities |
63
+ * | +-----------.---------+ | +------------+
64
+ * | | | . +----|---------+
65
+ * +-----|------+ . | ^ +-----------+
66
+ * | . | | |Enter/Leave|
67
+ * + . | +-------+|Plugin |
68
+ * +-------------+ . v +-----------+
69
+ * | application | . +----------+
70
+ * |-------------| . | callback |
71
+ * | | . | registry |
72
+ * | | . +----------+
73
+ * +-------------+ .
74
+ * .
75
+ * React Core . General Purpose Event Plugin System
76
+ */
77
+
78
+ /**
79
+ * Traps top-level events by using event bubbling.
80
+ *
81
+ * @param {string} topLevelType Record from `EventConstants`.
82
+ * @param {string} handlerBaseName Event name (e.g. "click").
83
+ * @param {DOMEventTarget} element Element on which to attach listener.
84
+ * @internal
85
+ */
86
+ function trapBubbledEvent(topLevelType, handlerBaseName, element) {
87
+ EventListener.listen(
88
+ element,
89
+ handlerBaseName,
90
+ ReactEventEmitter.TopLevelCallbackCreator.createTopLevelCallback(
91
+ topLevelType
92
+ )
93
+ );
94
+ }
95
+
96
+ /**
97
+ * Traps a top-level event by using event capturing.
98
+ *
99
+ * @param {string} topLevelType Record from `EventConstants`.
100
+ * @param {string} handlerBaseName Event name (e.g. "click").
101
+ * @param {DOMEventTarget} element Element on which to attach listener.
102
+ * @internal
103
+ */
104
+ function trapCapturedEvent(topLevelType, handlerBaseName, element) {
105
+ EventListener.capture(
106
+ element,
107
+ handlerBaseName,
108
+ ReactEventEmitter.TopLevelCallbackCreator.createTopLevelCallback(
109
+ topLevelType
110
+ )
111
+ );
112
+ }
113
+
114
+ /**
115
+ * Listens to window scroll and resize events. We cache scroll values so that
116
+ * application code can access them without triggering reflows.
117
+ *
118
+ * NOTE: Scroll events do not bubble.
119
+ *
120
+ * @private
121
+ * @see http://www.quirksmode.org/dom/events/scroll.html
122
+ */
123
+ function registerScrollValueMonitoring() {
124
+ var refresh = ViewportMetrics.refreshScrollValues;
125
+ EventListener.listen(window, 'scroll', refresh);
126
+ EventListener.listen(window, 'resize', refresh);
127
+ }
128
+
129
+ /**
130
+ * `ReactEventEmitter` is used to attach top-level event listeners. For example:
131
+ *
132
+ * ReactEventEmitter.putListener('myID', 'onClick', myFunction);
133
+ *
134
+ * This would allocate a "registration" of `('onClick', myFunction)` on 'myID'.
135
+ *
136
+ * @internal
137
+ */
138
+ var ReactEventEmitter = merge(ReactEventEmitterMixin, {
139
+
140
+ /**
141
+ * React references `ReactEventTopLevelCallback` using this property in order
142
+ * to allow dependency injection.
143
+ */
144
+ TopLevelCallbackCreator: null,
145
+
146
+ /**
147
+ * Ensures that top-level event delegation listeners are installed.
148
+ *
149
+ * There are issues with listening to both touch events and mouse events on
150
+ * the top-level, so we make the caller choose which one to listen to. (If
151
+ * there's a touch top-level listeners, anchors don't receive clicks for some
152
+ * reason, and only in some cases).
153
+ *
154
+ * @param {boolean} touchNotMouse Listen to touch events instead of mouse.
155
+ * @param {DOMDocument} contentDocument DOM document to listen on
156
+ */
157
+ ensureListening: function(touchNotMouse, contentDocument) {
158
+ ("production" !== process.env.NODE_ENV ? invariant(
159
+ ExecutionEnvironment.canUseDOM,
160
+ 'ensureListening(...): Cannot toggle event listening in a Worker ' +
161
+ 'thread. This is likely a bug in the framework. Please report ' +
162
+ 'immediately.'
163
+ ) : invariant(ExecutionEnvironment.canUseDOM));
164
+ ("production" !== process.env.NODE_ENV ? invariant(
165
+ ReactEventEmitter.TopLevelCallbackCreator,
166
+ 'ensureListening(...): Cannot be called without a top level callback ' +
167
+ 'creator being injected.'
168
+ ) : invariant(ReactEventEmitter.TopLevelCallbackCreator));
169
+ // Call out to base implementation.
170
+ ReactEventEmitterMixin.ensureListening.call(
171
+ ReactEventEmitter,
172
+ {
173
+ touchNotMouse: touchNotMouse,
174
+ contentDocument: contentDocument
175
+ }
176
+ );
177
+ },
178
+
179
+ /**
180
+ * Sets whether or not any created callbacks should be enabled.
181
+ *
182
+ * @param {boolean} enabled True if callbacks should be enabled.
183
+ */
184
+ setEnabled: function(enabled) {
185
+ ("production" !== process.env.NODE_ENV ? invariant(
186
+ ExecutionEnvironment.canUseDOM,
187
+ 'setEnabled(...): Cannot toggle event listening in a Worker thread. ' +
188
+ 'This is likely a bug in the framework. Please report immediately.'
189
+ ) : invariant(ExecutionEnvironment.canUseDOM));
190
+ if (ReactEventEmitter.TopLevelCallbackCreator) {
191
+ ReactEventEmitter.TopLevelCallbackCreator.setEnabled(enabled);
192
+ }
193
+ },
194
+
195
+ /**
196
+ * @return {boolean} True if callbacks are enabled.
197
+ */
198
+ isEnabled: function() {
199
+ return !!(
200
+ ReactEventEmitter.TopLevelCallbackCreator &&
201
+ ReactEventEmitter.TopLevelCallbackCreator.isEnabled()
202
+ );
203
+ },
204
+
205
+ /**
206
+ * We listen for bubbled touch events on the document object.
207
+ *
208
+ * Firefox v8.01 (and possibly others) exhibited strange behavior when
209
+ * mounting `onmousemove` events at some node that was not the document
210
+ * element. The symptoms were that if your mouse is not moving over something
211
+ * contained within that mount point (for example on the background) the
212
+ * top-level listeners for `onmousemove` won't be called. However, if you
213
+ * register the `mousemove` on the document object, then it will of course
214
+ * catch all `mousemove`s. This along with iOS quirks, justifies restricting
215
+ * top-level listeners to the document object only, at least for these
216
+ * movement types of events and possibly all events.
217
+ *
218
+ * @see http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
219
+ *
220
+ * Also, `keyup`/`keypress`/`keydown` do not bubble to the window on IE, but
221
+ * they bubble to document.
222
+ *
223
+ * @param {boolean} touchNotMouse Listen to touch events instead of mouse.
224
+ * @param {DOMDocument} contentDocument Document which owns the container
225
+ * @private
226
+ * @see http://www.quirksmode.org/dom/events/keys.html.
227
+ */
228
+ listenAtTopLevel: function(touchNotMouse, contentDocument) {
229
+ ("production" !== process.env.NODE_ENV ? invariant(
230
+ !contentDocument._isListening,
231
+ 'listenAtTopLevel(...): Cannot setup top-level listener more than once.'
232
+ ) : invariant(!contentDocument._isListening));
233
+ var topLevelTypes = EventConstants.topLevelTypes;
234
+ var mountAt = contentDocument;
235
+
236
+ registerScrollValueMonitoring();
237
+ trapBubbledEvent(topLevelTypes.topMouseOver, 'mouseover', mountAt);
238
+ trapBubbledEvent(topLevelTypes.topMouseDown, 'mousedown', mountAt);
239
+ trapBubbledEvent(topLevelTypes.topMouseUp, 'mouseup', mountAt);
240
+ trapBubbledEvent(topLevelTypes.topMouseMove, 'mousemove', mountAt);
241
+ trapBubbledEvent(topLevelTypes.topMouseOut, 'mouseout', mountAt);
242
+ trapBubbledEvent(topLevelTypes.topClick, 'click', mountAt);
243
+ trapBubbledEvent(topLevelTypes.topDoubleClick, 'dblclick', mountAt);
244
+ trapBubbledEvent(topLevelTypes.topContextMenu, 'contextmenu', mountAt);
245
+ if (touchNotMouse) {
246
+ trapBubbledEvent(topLevelTypes.topTouchStart, 'touchstart', mountAt);
247
+ trapBubbledEvent(topLevelTypes.topTouchEnd, 'touchend', mountAt);
248
+ trapBubbledEvent(topLevelTypes.topTouchMove, 'touchmove', mountAt);
249
+ trapBubbledEvent(topLevelTypes.topTouchCancel, 'touchcancel', mountAt);
250
+ }
251
+ trapBubbledEvent(topLevelTypes.topKeyUp, 'keyup', mountAt);
252
+ trapBubbledEvent(topLevelTypes.topKeyPress, 'keypress', mountAt);
253
+ trapBubbledEvent(topLevelTypes.topKeyDown, 'keydown', mountAt);
254
+ trapBubbledEvent(topLevelTypes.topInput, 'input', mountAt);
255
+ trapBubbledEvent(topLevelTypes.topChange, 'change', mountAt);
256
+ trapBubbledEvent(
257
+ topLevelTypes.topSelectionChange,
258
+ 'selectionchange',
259
+ mountAt
260
+ );
261
+
262
+ trapBubbledEvent(
263
+ topLevelTypes.topCompositionEnd,
264
+ 'compositionend',
265
+ mountAt
266
+ );
267
+ trapBubbledEvent(
268
+ topLevelTypes.topCompositionStart,
269
+ 'compositionstart',
270
+ mountAt
271
+ );
272
+ trapBubbledEvent(
273
+ topLevelTypes.topCompositionUpdate,
274
+ 'compositionupdate',
275
+ mountAt
276
+ );
277
+
278
+ if (isEventSupported('drag')) {
279
+ trapBubbledEvent(topLevelTypes.topDrag, 'drag', mountAt);
280
+ trapBubbledEvent(topLevelTypes.topDragEnd, 'dragend', mountAt);
281
+ trapBubbledEvent(topLevelTypes.topDragEnter, 'dragenter', mountAt);
282
+ trapBubbledEvent(topLevelTypes.topDragExit, 'dragexit', mountAt);
283
+ trapBubbledEvent(topLevelTypes.topDragLeave, 'dragleave', mountAt);
284
+ trapBubbledEvent(topLevelTypes.topDragOver, 'dragover', mountAt);
285
+ trapBubbledEvent(topLevelTypes.topDragStart, 'dragstart', mountAt);
286
+ trapBubbledEvent(topLevelTypes.topDrop, 'drop', mountAt);
287
+ }
288
+
289
+ if (isEventSupported('wheel')) {
290
+ trapBubbledEvent(topLevelTypes.topWheel, 'wheel', mountAt);
291
+ } else if (isEventSupported('mousewheel')) {
292
+ trapBubbledEvent(topLevelTypes.topWheel, 'mousewheel', mountAt);
293
+ } else {
294
+ // Firefox needs to capture a different mouse scroll event.
295
+ // @see http://www.quirksmode.org/dom/events/tests/scroll.html
296
+ trapBubbledEvent(topLevelTypes.topWheel, 'DOMMouseScroll', mountAt);
297
+ }
298
+
299
+ // IE<9 does not support capturing so just trap the bubbled event there.
300
+ if (isEventSupported('scroll', true)) {
301
+ trapCapturedEvent(topLevelTypes.topScroll, 'scroll', mountAt);
302
+ } else {
303
+ trapBubbledEvent(topLevelTypes.topScroll, 'scroll', window);
304
+ }
305
+
306
+ if (isEventSupported('focus', true)) {
307
+ trapCapturedEvent(topLevelTypes.topFocus, 'focus', mountAt);
308
+ trapCapturedEvent(topLevelTypes.topBlur, 'blur', mountAt);
309
+ } else if (isEventSupported('focusin')) {
310
+ // IE has `focusin` and `focusout` events which bubble.
311
+ // @see
312
+ // http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html
313
+ trapBubbledEvent(topLevelTypes.topFocus, 'focusin', mountAt);
314
+ trapBubbledEvent(topLevelTypes.topBlur, 'focusout', mountAt);
315
+ }
316
+
317
+ if (isEventSupported('copy')) {
318
+ trapBubbledEvent(topLevelTypes.topCopy, 'copy', mountAt);
319
+ trapBubbledEvent(topLevelTypes.topCut, 'cut', mountAt);
320
+ trapBubbledEvent(topLevelTypes.topPaste, 'paste', mountAt);
321
+ }
322
+ },
323
+
324
+ registrationNames: EventPluginHub.registrationNames,
325
+
326
+ putListener: EventPluginHub.putListener,
327
+
328
+ getListener: EventPluginHub.getListener,
329
+
330
+ deleteListener: EventPluginHub.deleteListener,
331
+
332
+ deleteAllListeners: EventPluginHub.deleteAllListeners,
333
+
334
+ trapBubbledEvent: trapBubbledEvent,
335
+
336
+ trapCapturedEvent: trapCapturedEvent
337
+
338
+ });
339
+
340
+
341
+ module.exports = ReactEventEmitter;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Copyright 2013 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule ReactEventEmitterMixin
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var EventPluginHub = require("./EventPluginHub");
22
+ var ReactUpdates = require("./ReactUpdates");
23
+
24
+ function runEventQueueInBatch(events) {
25
+ EventPluginHub.enqueueEvents(events);
26
+ EventPluginHub.processEventQueue();
27
+ }
28
+
29
+ var ReactEventEmitterMixin = {
30
+ /**
31
+ * Whether or not `ensureListening` has been invoked.
32
+ * @type {boolean}
33
+ * @private
34
+ */
35
+ _isListening: false,
36
+
37
+ /**
38
+ * Function, must be implemented. Listens to events on the top level of the
39
+ * application.
40
+ *
41
+ * @abstract
42
+ *
43
+ * listenAtTopLevel: null,
44
+ */
45
+
46
+ /**
47
+ * Ensures that top-level event delegation listeners are installed.
48
+ *
49
+ * There are issues with listening to both touch events and mouse events on
50
+ * the top-level, so we make the caller choose which one to listen to. (If
51
+ * there's a touch top-level listeners, anchors don't receive clicks for some
52
+ * reason, and only in some cases).
53
+ *
54
+ * @param {*} config Configuration passed through to `listenAtTopLevel`.
55
+ */
56
+ ensureListening: function(config) {
57
+ if (!config.contentDocument._reactIsListening) {
58
+ this.listenAtTopLevel(config.touchNotMouse, config.contentDocument);
59
+ config.contentDocument._reactIsListening = true;
60
+ }
61
+ },
62
+
63
+ /**
64
+ * Streams a fired top-level event to `EventPluginHub` where plugins have the
65
+ * opportunity to create `ReactEvent`s to be dispatched.
66
+ *
67
+ * @param {string} topLevelType Record from `EventConstants`.
68
+ * @param {object} topLevelTarget The listening component root node.
69
+ * @param {string} topLevelTargetID ID of `topLevelTarget`.
70
+ * @param {object} nativeEvent Native environment event.
71
+ */
72
+ handleTopLevel: function(
73
+ topLevelType,
74
+ topLevelTarget,
75
+ topLevelTargetID,
76
+ nativeEvent) {
77
+ var events = EventPluginHub.extractEvents(
78
+ topLevelType,
79
+ topLevelTarget,
80
+ topLevelTargetID,
81
+ nativeEvent
82
+ );
83
+
84
+ // Event queue being processed in the same cycle allows `preventDefault`.
85
+ ReactUpdates.batchedUpdates(runEventQueueInBatch, events);
86
+ }
87
+ };
88
+
89
+ module.exports = ReactEventEmitterMixin;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Copyright 2013 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule ReactEventTopLevelCallback
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var ReactEventEmitter = require("./ReactEventEmitter");
23
+ var ReactMount = require("./ReactMount");
24
+
25
+ var getEventTarget = require("./getEventTarget");
26
+
27
+ /**
28
+ * @type {boolean}
29
+ * @private
30
+ */
31
+ var _topLevelListenersEnabled = true;
32
+
33
+ /**
34
+ * Top-level callback creator used to implement event handling using delegation.
35
+ * This is used via dependency injection.
36
+ */
37
+ var ReactEventTopLevelCallback = {
38
+
39
+ /**
40
+ * Sets whether or not any created callbacks should be enabled.
41
+ *
42
+ * @param {boolean} enabled True if callbacks should be enabled.
43
+ */
44
+ setEnabled: function(enabled) {
45
+ _topLevelListenersEnabled = !!enabled;
46
+ },
47
+
48
+ /**
49
+ * @return {boolean} True if callbacks are enabled.
50
+ */
51
+ isEnabled: function() {
52
+ return _topLevelListenersEnabled;
53
+ },
54
+
55
+ /**
56
+ * Creates a callback for the supplied `topLevelType` that could be added as
57
+ * a listener to the document. The callback computes a `topLevelTarget` which
58
+ * should be the root node of a mounted React component where the listener
59
+ * is attached.
60
+ *
61
+ * @param {string} topLevelType Record from `EventConstants`.
62
+ * @return {function} Callback for handling top-level events.
63
+ */
64
+ createTopLevelCallback: function(topLevelType) {
65
+ return function(nativeEvent) {
66
+ if (!_topLevelListenersEnabled) {
67
+ return;
68
+ }
69
+ // TODO: Remove when synthetic events are ready, this is for IE<9.
70
+ if (nativeEvent.srcElement &&
71
+ nativeEvent.srcElement !== nativeEvent.target) {
72
+ nativeEvent.target = nativeEvent.srcElement;
73
+ }
74
+ var topLevelTarget = ReactMount.getFirstReactDOM(
75
+ getEventTarget(nativeEvent)
76
+ ) || window;
77
+ var topLevelTargetID = ReactMount.getID(topLevelTarget) || '';
78
+ ReactEventEmitter.handleTopLevel(
79
+ topLevelType,
80
+ topLevelTarget,
81
+ topLevelTargetID,
82
+ nativeEvent
83
+ );
84
+ };
85
+ }
86
+
87
+ };
88
+
89
+ module.exports = ReactEventTopLevelCallback;