| 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 // This script dynamically prepares a set of files to run polymer.dart. It uses | 5 // This script dynamically prepares a set of files to run polymer.dart. It uses |
| 6 // the html_import polyfill to search for all imported files, then | 6 // the html_import polyfill to search for all imported files, then |
| 7 // it inlines all <polymer-element> definitions on the top-level page (needed by | 7 // it inlines all <polymer-element> definitions on the top-level page (needed by |
| 8 // registerPolymerElement), and it removes script tags that appear inside | 8 // registerPolymerElement), and it removes script tags that appear inside |
| 9 // those tags. It finally rewrites the main entrypoint to call an initialization | 9 // those tags. It finally rewrites the main entrypoint to call an initialization |
| 10 // function on each of the declared <polymer-elements>. | 10 // function on each of the declared <polymer-elements>. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // (changing to text/javascript hides the warning, but seems wrong). | 75 // (changing to text/javascript hides the warning, but seems wrong). |
| 76 return "data:application/dart;base64," + window.btoa(script.textContent); | 76 return "data:application/dart;base64," + window.btoa(script.textContent); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Moves <polymer-elements> from imported documents into the top-level page. | 80 // Moves <polymer-elements> from imported documents into the top-level page. |
| 81 function inlinePolymerElements(content, ref, seen) { | 81 function inlinePolymerElements(content, ref, seen) { |
| 82 if (!seen) seen = {}; | 82 if (!seen) seen = {}; |
| 83 var links = content.querySelectorAll('link[rel="import"]'); | 83 var links = content.querySelectorAll('link[rel="import"]'); |
| 84 for (var i = 0; i < links.length; i++) { | 84 for (var i = 0; i < links.length; i++) { |
| 85 var link = links[i].import; | 85 var link = links[i]; |
| 86 // TODO(jmesserly): figure out why ".import" fails in content_shell but |
| 87 // works in Dartium. |
| 88 if (link.import && link.import.href) link = link.import; |
| 89 |
| 86 if (seen[link.href]) continue; | 90 if (seen[link.href]) continue; |
| 87 seen[link.href] = link; | 91 seen[link.href] = link; |
| 88 inlinePolymerElements(link.content, ref, seen); | 92 inlinePolymerElements(link.content, ref, seen); |
| 89 } | 93 } |
| 90 | 94 |
| 91 if (content != document) { // no need to do anything for the top-level page | 95 if (content != document) { // no need to do anything for the top-level page |
| 92 var elements = content.querySelectorAll('polymer-element'); | 96 var elements = content.querySelectorAll('polymer-element'); |
| 93 for (var i = 0; i < elements.length; i++) { | 97 for (var i = 0; i < elements.length; i++) { |
| 94 document.body.insertBefore(elements[i], ref); | 98 document.body.insertBefore(elements[i], ref); |
| 95 } | 99 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 alreadyRan = true; | 153 alreadyRan = true; |
| 150 var ref = document.body.children[0]; | 154 var ref = document.body.children[0]; |
| 151 inlinePolymerElements(document, ref); | 155 inlinePolymerElements(document, ref); |
| 152 mergeScripts(); | 156 mergeScripts(); |
| 153 if (!navigator.webkitStartDart()) { | 157 if (!navigator.webkitStartDart()) { |
| 154 document.body.innerHTML = 'This build has expired. Please download a ' + | 158 document.body.innerHTML = 'This build has expired. Please download a ' + |
| 155 'new Dartium at http://www.dartlang.org/dartium/index.html'; | 159 'new Dartium at http://www.dartlang.org/dartium/index.html'; |
| 156 } | 160 } |
| 157 }); | 161 }); |
| 158 })(); | 162 })(); |
| OLD | NEW |