| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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 @HtmlImport('polymer.html') | |
| 5 library polymer_interop.polymer_interop; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:html'; | |
| 9 import 'dart:js' as js; | |
| 10 import 'package:web_components/web_components.dart'; | |
| 11 export 'src/polymer_proxy_mixin.dart'; | |
| 12 | |
| 13 final js.JsObject _polymer = js.context['Polymer']; | |
| 14 | |
| 15 /// Wrapper which provides access to many polymer js apis. | |
| 16 class PolymerJs { | |
| 17 static js.JsFunction get constructor => _polymer as js.JsFunction; | |
| 18 | |
| 19 static void resolveElementPaths(Node node) { | |
| 20 if (!checkExists()) return; | |
| 21 _polymer['urlResolver'].callMethod('resolveDom', [node]); | |
| 22 } | |
| 23 | |
| 24 static void flush() { | |
| 25 if (!checkExists()) return; | |
| 26 _polymer.callMethod('flush'); | |
| 27 } | |
| 28 | |
| 29 static List<Element> get waitingFor { | |
| 30 if (!checkExists()) return null; | |
| 31 return _polymer.callMethod('waitingFor', [null]); | |
| 32 } | |
| 33 | |
| 34 static void forceReady([int timeout]) { | |
| 35 if (!checkExists()) return null; | |
| 36 _polymer.callMethod('forceReady', [null, timeout]); | |
| 37 } | |
| 38 | |
| 39 static Future importElements(Node elementOrFragment) { | |
| 40 if (!checkExists()) return null; | |
| 41 var completer = new Completer(); | |
| 42 _polymer.callMethod( | |
| 43 'importElements', [elementOrFragment, () => completer.complete()]); | |
| 44 return completer.future; | |
| 45 } | |
| 46 | |
| 47 static Future import(List urls) { | |
| 48 if (!checkExists()) return null; | |
| 49 var completer = new Completer(); | |
| 50 _polymer.callMethod('import', [urls, () => completer.complete()]); | |
| 51 return completer.future; | |
| 52 } | |
| 53 | |
| 54 static void whenPolymerReady(f()) { | |
| 55 if (!checkExists()) return null; | |
| 56 _polymer.callMethod( | |
| 57 'whenPolymerReady', [Zone.current.bindCallback(() => f())]); | |
| 58 } | |
| 59 | |
| 60 static void endOfMicrotask(f()) { | |
| 61 if (!checkExists()) return null; | |
| 62 _polymer.callMethod('endOfMicrotask', [() => f()]); | |
| 63 } | |
| 64 | |
| 65 static bool outputPolymerError = false; | |
| 66 static bool checkExists() { | |
| 67 if (_polymer != null) return true; | |
| 68 if (!outputPolymerError) { | |
| 69 outputPolymerError = true; | |
| 70 window.console.error('Unable to find Polymer. Please make sure you are ' | |
| 71 'waiting on initWebComponents() or initPolymer() before attempting ' | |
| 72 'to use Polymer.'); | |
| 73 } | |
| 74 return false; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 final js.JsObject _polymerGestures = js.context['PolymerGestures']; | |
| 79 | |
| 80 class PolymerGesturesJs { | |
| 81 static void addEventListener(Node node, String type, callback) { | |
| 82 if (!checkExists()) return null; | |
| 83 _polymerGestures.callMethod('addEventListener', [node, type, callback]); | |
| 84 } | |
| 85 | |
| 86 static void removeEventListener(Node node, String type, callback) { | |
| 87 if (!checkExists()) return null; | |
| 88 _polymerGestures.callMethod('removeEventListener', [node, type, callback]); | |
| 89 } | |
| 90 | |
| 91 static bool outputPolymerGesturesError = false; | |
| 92 static bool checkExists() { | |
| 93 if (_polymerGestures != null) return true; | |
| 94 if (!outputPolymerGesturesError) { | |
| 95 outputPolymerGesturesError = true; | |
| 96 window.console.error('Unable to find PolymerGestures. Please make sure ' | |
| 97 'you are waiting on initWebComponents() or initPolymer() before ' | |
| 98 'attempting to use PolymerGestures.'); | |
| 99 } | |
| 100 return false; | |
| 101 } | |
| 102 } | |
| OLD | NEW |