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 |
| 5 /// Provides support for associating a Dart type for Javascript Custom Elements. |
| 6 /// This will not work unless `dart_support.js` is loaded. |
| 7 library web_components.interop; |
| 8 |
| 9 import 'dart:async' show Stream, StreamController; |
| 10 import 'dart:html' show document, Element; |
| 11 import 'dart:js' show JsObject, JsFunction; |
| 12 |
| 13 final _doc = new JsObject.fromBrowserObject(document); |
| 14 |
| 15 /// Returns whether [registerDartType] is supported, which requires to have |
| 16 /// `dart_support.js` already loaded in the page. |
| 17 bool get isSupported => _doc.hasProperty('_registerDartTypeUpgrader'); |
| 18 |
| 19 /// Watches when Javascript custom elements named [tagName] are created and |
| 20 /// associates the created element with the given [dartType]. Only one Dart type |
| 21 /// can be registered for a given tag name. |
| 22 void registerDartType(String tagName, Type dartType, {String extendsTag}) { |
| 23 if (!isSupported) { |
| 24 throw new UnsupportedError("Couldn't find " |
| 25 "`document._registerDartTypeUpgrader`. Please make sure that " |
| 26 "`packages/web_components/dart_support.js` is loaded and available " |
| 27 "before calling this function."); |
| 28 } |
| 29 |
| 30 var upgrader = document.createElementUpgrader( |
| 31 dartType, extendsTag: extendsTag); |
| 32 _doc.callMethod('_registerDartTypeUpgrader', [tagName, upgrader.upgrade]); |
| 33 } |
OLD | NEW |