| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of html; | 5 part of html; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Adapter for exposing DOM events as Dart streams. | 8 * Adapter for exposing DOM events as Dart streams. |
| 9 */ | 9 */ |
| 10 class _EventStream<T extends Event> extends Stream<T> { | 10 class _EventStream<T extends Event> extends Stream<T> { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 abstract class ElementStream<T extends Event> implements Stream<T> { | 34 abstract class ElementStream<T extends Event> implements Stream<T> { |
| 35 /** | 35 /** |
| 36 * Return a stream that only fires when the particular event fires for | 36 * Return a stream that only fires when the particular event fires for |
| 37 * elements matching the specified CSS selector. | 37 * elements matching the specified CSS selector. |
| 38 * | 38 * |
| 39 * This is the Dart equivalent to jQuery's | 39 * This is the Dart equivalent to jQuery's |
| 40 * [delegate](http://api.jquery.com/delegate/). | 40 * [delegate](http://api.jquery.com/delegate/). |
| 41 */ | 41 */ |
| 42 Stream<T> matches(String selector); | 42 Stream<T> matches(String selector); |
| 43 | 43 |
| 44 /** |
| 45 * Adds a capturing subscription to this stream. |
| 46 * |
| 47 * If the target of the event is a descendant of the element from which this |
| 48 * stream derives then [onData] is called before the event propagates down to |
| 49 * the target. This is the opposite of bubbling behavior, where the event |
| 50 * is first processed for the event target and then bubbles upward. |
| 51 * |
| 52 * ## Other Resources |
| 53 * |
| 54 * * [Event Capture] |
| 55 * (http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-capture) |
| 56 * from the W3C DOM Events specification. |
| 57 */ |
| 44 StreamSubscription<T> capture(void onData(T event)); | 58 StreamSubscription<T> capture(void onData(T event)); |
| 45 } | 59 } |
| 46 | 60 |
| 47 /** | 61 /** |
| 48 * Adapter for exposing DOM Element events as streams, while also allowing | 62 * Adapter for exposing DOM Element events as streams, while also allowing |
| 49 * event delegation. | 63 * event delegation. |
| 50 */ | 64 */ |
| 51 class _ElementEventStreamImpl<T extends Event> extends _EventStream<T> | 65 class _ElementEventStreamImpl<T extends Event> extends _EventStream<T> |
| 52 implements ElementStream<T> { | 66 implements ElementStream<T> { |
| 53 _ElementEventStreamImpl(target, eventType, useCapture) : | 67 _ElementEventStreamImpl(target, eventType, useCapture) : |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 /** | 325 /** |
| 312 * Gets a [Stream] for this event type, on the specified target. | 326 * Gets a [Stream] for this event type, on the specified target. |
| 313 * | 327 * |
| 314 * This will always return a broadcast stream so multiple listeners can be | 328 * This will always return a broadcast stream so multiple listeners can be |
| 315 * used simultaneously. | 329 * used simultaneously. |
| 316 * | 330 * |
| 317 * This may be used to capture DOM events: | 331 * This may be used to capture DOM events: |
| 318 * | 332 * |
| 319 * Element.keyDownEvent.forTarget(element, useCapture: true).listen(...); | 333 * Element.keyDownEvent.forTarget(element, useCapture: true).listen(...); |
| 320 * | 334 * |
| 335 * // Alternate method: |
| 336 * Element.keyDownEvent.forTarget(element).capture(...); |
| 337 * |
| 321 * Or for listening to an event which will bubble through the DOM tree: | 338 * Or for listening to an event which will bubble through the DOM tree: |
| 322 * | 339 * |
| 323 * MediaElement.pauseEvent.forTarget(document.body).listen(...); | 340 * MediaElement.pauseEvent.forTarget(document.body).listen(...); |
| 324 * | 341 * |
| 325 * See also: | 342 * See also: |
| 326 * | 343 * |
| 327 * [addEventListener](http://docs.webplatform.org/wiki/dom/methods/addEventLis
tener) | 344 * [addEventListener](http://docs.webplatform.org/wiki/dom/methods/addEventLis
tener) |
| 328 */ | 345 */ |
| 329 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) => | 346 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) => |
| 330 new _EventStream(e, _eventType, useCapture); | 347 new _EventStream(e, _eventType, useCapture); |
| 331 | 348 |
| 332 /** | 349 /** |
| 333 * Gets an [ElementEventStream] for this event type, on the specified element. | 350 * Gets an [ElementEventStream] for this event type, on the specified element. |
| 334 * | 351 * |
| 335 * This will always return a broadcast stream so multiple listeners can be | 352 * This will always return a broadcast stream so multiple listeners can be |
| 336 * used simultaneously. | 353 * used simultaneously. |
| 337 * | 354 * |
| 338 * This may be used to capture DOM events: | 355 * This may be used to capture DOM events: |
| 339 * | 356 * |
| 340 * Element.keyDownEvent.forElement(element, useCapture: true).listen(...); | 357 * Element.keyDownEvent.forElement(element, useCapture: true).listen(...); |
| 341 * | 358 * |
| 359 * // Alternate method: |
| 360 * Element.keyDownEvent.forElement(element).capture(...); |
| 361 * |
| 362 * Or for listening to an event which will bubble through the DOM tree: |
| 363 * |
| 364 * MediaElement.pauseEvent.forElement(document.body).listen(...); |
| 365 * |
| 342 * See also: | 366 * See also: |
| 343 * | 367 * |
| 344 * [addEventListener](http://docs.webplatform.org/wiki/dom/methods/addEventLis
tener) | 368 * [addEventListener](http://docs.webplatform.org/wiki/dom/methods/addEventLis
tener) |
| 345 */ | 369 */ |
| 346 ElementStream<T> forElement(Element e, {bool useCapture: false}) { | 370 ElementStream<T> forElement(Element e, {bool useCapture: false}) { |
| 347 return new _ElementEventStreamImpl(e, _eventType, useCapture); | 371 return new _ElementEventStreamImpl(e, _eventType, useCapture); |
| 348 } | 372 } |
| 349 | 373 |
| 350 /** | 374 /** |
| 351 * Gets an [ElementEventStream] for this event type, on the list of elements. | 375 * Gets an [ElementEventStream] for this event type, on the list of elements. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 421 |
| 398 ElementStream<T> _forElementList(ElementList e, | 422 ElementStream<T> _forElementList(ElementList e, |
| 399 {bool useCapture: false}) { | 423 {bool useCapture: false}) { |
| 400 return new _ElementListEventStreamImpl(e, _eventTypeGetter(e), useCapture); | 424 return new _ElementListEventStreamImpl(e, _eventTypeGetter(e), useCapture); |
| 401 } | 425 } |
| 402 | 426 |
| 403 String getEventType(EventTarget target) { | 427 String getEventType(EventTarget target) { |
| 404 return _eventTypeGetter(target); | 428 return _eventTypeGetter(target); |
| 405 } | 429 } |
| 406 } | 430 } |
| OLD | NEW |