OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 @JS("") |
| 6 library json_helper; |
| 7 |
| 8 import 'package:js/js.dart'; |
| 9 |
| 10 // This is a minimal and intentionally hacky raw DOM API built with typed JS |
| 11 // interop. |
| 12 @JS() |
| 13 class EventTarget { |
| 14 external void addEventListener(String type, Function listener, [bool use
Capture]); |
| 15 external void removeEventListener(String type, Function listener, [bool
useCapture]); |
| 16 external void dispatchEvent(Event event); |
| 17 |
| 18 // The dart:html and simple_dom versions of addEventListener are general
ly |
| 19 // compatible except for behavior capturing this and throwing when passe
d |
| 20 // event listeners that have not had allowInterop called. |
| 21 external void JS$addEventListener(String type, Function listener, [bool
useCapture]); |
| 22 external void JS$removeEventListener(String type, Function listener, [bo
ol useCapture]); |
| 23 } |
| 24 |
| 25 // Example showing addEventListener as a top level memthod |
| 26 @JS("document.addEventListener") |
| 27 external void documentAddEventListener(String type, Function listener, [bool use
Capture]); |
| 28 |
| 29 @JS() |
| 30 @anonymous |
| 31 class EventInit { |
| 32 external factory EventInit({bool bubbles, bool cancelable}); |
| 33 external bool get bubbles; |
| 34 external bool get cancelable; |
| 35 } |
| 36 |
| 37 @JS() |
| 38 class Event { |
| 39 external Event(String type, [EventInit eventInit]); |
| 40 /// This is also defined in dart:html but that is fine as the |
| 41 /// is consistent. |
| 42 external String get type; |
| 43 |
| 44 external String get exampleEventExpando; |
| 45 external set exampleEventExpando(String v); |
| 46 } |
| 47 |
| 48 @JS() |
| 49 class Window extends EventTarget { |
| 50 external Node get document; |
| 51 } |
| 52 |
| 53 @JS() |
| 54 class Node extends EventTarget { |
| 55 external String get textContent; |
| 56 |
| 57 external get exampleNodeExpando; |
| 58 external set exampleNodeExpando(v); |
| 59 } |
| 60 |
| 61 @JS() |
| 62 class Document extends Node { |
| 63 external Node getElementById(String id); |
| 64 } |
| 65 |
| 66 @JS() |
| 67 external Window get window; |
| 68 |
| 69 @JS() |
| 70 external Document get document; |
OLD | NEW |