| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * Polyfill script for custom elements. To use this script, your app must | 6 * Polyfill script for custom elements. To use this script, your app must |
| 7 * create a CustomElementsManager with the appropriate lookup function before | 7 * create a CustomElementsManager with the appropriate lookup function before |
| 8 * doing any DOM queries or modifications. | 8 * doing any DOM queries or modifications. |
| 9 * Currently, all custom elements must be registered with the polyfill. To | 9 * Currently, all custom elements must be registered with the polyfill. To |
| 10 * register custom elements, provide the appropriate lookup function to your | 10 * register custom elements, provide the appropriate lookup function to your |
| 11 * CustomElementsManager. | 11 * CustomElementsManager. |
| 12 * | 12 * |
| 13 * This script only works at present in dart2js, but it should work in dartium | 13 * This script only works at present in dart2js, but it should work in dartium |
| 14 * soon (pending MutationObservers). The script does an XMLHTTP request, so | 14 * soon (pending MutationObservers). The script does an HTTP request, so |
| 15 * to test using locally defined custom elements you must run chrome with the | 15 * to test using locally defined custom elements you must run chrome with the |
| 16 * flag -allow-file-access-from-files. | 16 * flag -allow-file-access-from-files. |
| 17 */ | 17 */ |
| 18 | 18 |
| 19 #library('webcomponents'); | 19 #library('webcomponents'); |
| 20 | 20 |
| 21 #import('dart:html'); | 21 #import('dart:html'); |
| 22 | 22 |
| 23 #source('list_map.dart'); | 23 #source('list_map.dart'); |
| 24 | 24 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 void _loadComponents() { | 88 void _loadComponents() { |
| 89 queryAll('link[rel=components]').forEach((link) => _load(link.href)); | 89 queryAll('link[rel=components]').forEach((link) => _load(link.href)); |
| 90 _expandDeclarations(); | 90 _expandDeclarations(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * Load the document at the given url and parse it to extract | 94 * Load the document at the given url and parse it to extract |
| 95 * custom element declarations. | 95 * custom element declarations. |
| 96 */ | 96 */ |
| 97 void _load(String url) { | 97 void _load(String url) { |
| 98 var request = new XMLHttpRequest(); | 98 var request = new HttpRequest(); |
| 99 // We use a blocking request here because no Dart is allowed to run | 99 // We use a blocking request here because no Dart is allowed to run |
| 100 // until DOM content is loaded. | 100 // until DOM content is loaded. |
| 101 // TODO(samhop): give a decent timeout message if custom elements fail to | 101 // TODO(samhop): give a decent timeout message if custom elements fail to |
| 102 // load | 102 // load |
| 103 request.open('GET', url, async: false); | 103 request.open('GET', url, async: false); |
| 104 request.on.readyStateChange.add((Event e) { | 104 request.on.readyStateChange.add((Event e) { |
| 105 if (request.readyState == REQUEST_DONE) { | 105 if (request.readyState == REQUEST_DONE) { |
| 106 if (request.status >= 200 && request.status < 300 | 106 if (request.status >= 200 && request.status < 300 |
| 107 || request.status == 304 || request.status == 0) { | 107 || request.status == 304 || request.status == 0) { |
| 108 var declarations = _parse(request.response); | 108 var declarations = _parse(request.response); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 338 } |
| 339 }); | 339 }); |
| 340 attributeObserver.observe(e, attributes: true, attributeOldValue: true); | 340 attributeObserver.observe(e, attributes: true, attributeOldValue: true); |
| 341 | 341 |
| 342 // Listen for all insertions and deletions on the DOM so that we can | 342 // Listen for all insertions and deletions on the DOM so that we can |
| 343 // catch custom elements being inserted and call the appropriate callbacks. | 343 // catch custom elements being inserted and call the appropriate callbacks. |
| 344 manager.initializeInsertedRemovedCallbacks(shadowRoot); | 344 manager.initializeInsertedRemovedCallbacks(shadowRoot); |
| 345 return newCustomElement; | 345 return newCustomElement; |
| 346 } | 346 } |
| 347 } | 347 } |
| OLD | NEW |