| 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 polymer; | 5 part of polymer; |
| 6 | 6 |
| 7 /// Annotation used to automatically register polymer elements. | 7 /// Annotation used to automatically register polymer elements. |
| 8 class CustomTag { | 8 class CustomTag { |
| 9 final String tagName; | 9 final String tagName; |
| 10 const CustomTag(this.tagName); | 10 const CustomTag(this.tagName); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 | 80 |
| 81 /// To ensure Dart can interoperate with polymer-element registered by | 81 /// To ensure Dart can interoperate with polymer-element registered by |
| 82 /// polymer.js, we need to be able to execute Dart code if we are registering | 82 /// polymer.js, we need to be able to execute Dart code if we are registering |
| 83 /// a Dart class for that element. We trigger Dart logic by patching | 83 /// a Dart class for that element. We trigger Dart logic by patching |
| 84 /// polymer-element's register function and: | 84 /// polymer-element's register function and: |
| 85 /// | 85 /// |
| 86 /// * if it has a Dart class, run PolymerDeclaration's register. | 86 /// * if it has a Dart class, run PolymerDeclaration's register. |
| 87 /// * otherwise it is a JS prototype, run polymer-element's normal register. | 87 /// * otherwise it is a JS prototype, run polymer-element's normal register. |
| 88 void _hookJsPolymer() { | 88 void _hookJsPolymer() { |
| 89 // Note: platform.js is not used directly here, but we check that it is loaded |
| 90 // to provide a good error message in Dartium if people forgot to include it. |
| 91 // Otherwise, polymer.js below will fail with a hard to understand error |
| 92 // message. |
| 93 var platform = js.context['Platform']; |
| 94 if (platform == null) { |
| 95 throw new StateError('platform.js, dart_support.js must be loaded at' |
| 96 ' the top of your application, before any other scripts or HTML' |
| 97 ' imports that use polymer. Putting these two script tags at the top of' |
| 98 ' your <head> element should address this issue:' |
| 99 ' <script src="packages/web_components/platform.js"></script> and ' |
| 100 ' <script src="packages/web_components/dart_support.js"></script>.'); |
| 101 } |
| 89 var polymerJs = js.context['Polymer']; | 102 var polymerJs = js.context['Polymer']; |
| 90 if (polymerJs == null) { | 103 if (polymerJs == null) { |
| 91 throw new StateError('polymer.js must be loaded before polymer.dart, please' | 104 throw new StateError('polymer.js must be loaded before polymer.dart, please' |
| 92 ' add <link rel="import" href="packages/polymer/polymer.html"> to your' | 105 ' add <link rel="import" href="packages/polymer/polymer.html"> to your' |
| 93 ' <head> before any Dart scripts. Alternatively you can get a different' | 106 ' <head> before any Dart scripts. Alternatively you can get a different' |
| 94 ' version of polymer.js by following the instructions at' | 107 ' version of polymer.js by following the instructions at' |
| 95 ' http://www.polymer-project.org; if you do that be sure to include' | 108 ' http://www.polymer-project.org.'); |
| 96 ' the platform polyfills.'); | |
| 97 } | 109 } |
| 98 | 110 |
| 99 // TODO(jmesserly): dart:js appears to not callback in the correct zone: | 111 // TODO(jmesserly): dart:js appears to not callback in the correct zone: |
| 100 // https://code.google.com/p/dart/issues/detail?id=17301 | 112 // https://code.google.com/p/dart/issues/detail?id=17301 |
| 101 var zone = Zone.current; | 113 var zone = Zone.current; |
| 102 | 114 |
| 103 polymerJs.callMethod('whenPolymerReady', | 115 polymerJs.callMethod('whenPolymerReady', |
| 104 [zone.bindCallback(() => Polymer._onReady.complete())]); | 116 [zone.bindCallback(() => Polymer._onReady.complete())]); |
| 105 | 117 |
| 106 JsFunction originalRegister = _polymerElementProto['register']; | 118 JsFunction originalRegister = _polymerElementProto['register']; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 127 } | 139 } |
| 128 | 140 |
| 129 // Note: we cache this so we can use it later to look up 'init'. | 141 // Note: we cache this so we can use it later to look up 'init'. |
| 130 // See registerSync. | 142 // See registerSync. |
| 131 JsObject _polymerElementProto = () { | 143 JsObject _polymerElementProto = () { |
| 132 var polyElem = document.createElement('polymer-element'); | 144 var polyElem = document.createElement('polymer-element'); |
| 133 var proto = new JsObject.fromBrowserObject(polyElem)['__proto__']; | 145 var proto = new JsObject.fromBrowserObject(polyElem)['__proto__']; |
| 134 if (proto is Node) proto = new JsObject.fromBrowserObject(proto); | 146 if (proto is Node) proto = new JsObject.fromBrowserObject(proto); |
| 135 return proto; | 147 return proto; |
| 136 }(); | 148 }(); |
| OLD | NEW |