Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: pkg/polymer/lib/boot.js

Issue 227743009: [polymer] fix imports in Dartium if no script is on the main page (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/polymer/lib/polymer.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 /// Bootstrap to initialize polymer applications. This library is will be 5 /// Bootstrap to initialize polymer applications. This library is will be
6 /// replaced by boot.dart in the near future (see dartbug.com/18007). 6 /// replaced by boot.dart in the near future (see dartbug.com/18007).
7 /// 7 ///
8 /// This script contains logic to bootstrap polymer apps during development. It 8 /// This script contains logic to bootstrap polymer apps during development. It
9 /// internally discovers special Dart script tags through HTML imports, and 9 /// internally discovers special Dart script tags through HTML imports, and
10 /// constructs a new entrypoint for the application that is then launched in an 10 /// constructs a new entrypoint for the application that is then launched in an
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 state.scripts.push(getScriptUrl(node)); 117 state.scripts.push(getScriptUrl(node));
118 } 118 }
119 if (node.type == 'application/dart') { 119 if (node.type == 'application/dart') {
120 state.badTags.push(node); 120 state.badTags.push(node);
121 } 121 }
122 } 122 }
123 } 123 }
124 return state; 124 return state;
125 } 125 }
126 126
127 // Waits for all imports to be loaded, then calls [callback]. 127 // TODO(jmesserly): we're using this function because DOMContentLoaded can
128 function onImportsReady(callback) { 128 // be fired too soon: https://www.w3.org/Bugs/Public/show_bug.cgi?id=23526
129 // Note: we only need to check the main document because an import is loaded 129 HTMLImports.whenImportsReady(function() {
130 // only when all it's transitive imports are loaded too.
131 var links = document.querySelectorAll('link[rel="import"]');
132 var total = links.length;
133 var loaded = 0;
134 function incrementLoaded() {
135 loaded++;
136 if (loaded == total) {
137 window.addEventListener('DOMContentLoaded', callback);
138 }
139 }
140
141 for (var i = 0; i < total; i++) {
142 var node = links[i];
143 if (node.import) {
144 incrementLoaded();
145 } else {
146 node.addEventListener('load', incrementLoaded);
147 }
148 }
149 }
150
151 onImportsReady(function () {
152 // Append a new script tag that initializes everything. 130 // Append a new script tag that initializes everything.
153 var newScript = document.createElement('script'); 131 var newScript = document.createElement('script');
154 newScript.type = "application/dart"; 132 newScript.type = "application/dart";
155 133
156 var results = discoverScripts(document); 134 var results = discoverScripts(document);
157 if (results.badTags.length > 0) { 135 if (results.badTags.length > 0) {
158 console.warn('Dartium currently only allows a single Dart script tag ' 136 console.warn('Dartium currently only allows a single Dart script tag '
159 + 'per application, and in the future it will run them in ' 137 + 'per application, and in the future it will run them in '
160 + 'separtate isolates. To prepare for this all the following ' 138 + 'separtate isolates. To prepare for this all the following '
161 + 'script tags need to be updated to use the mime-type ' 139 + 'script tags need to be updated to use the mime-type '
162 + '"application/dart;component=1" instead of "application/dart":'); 140 + '"application/dart;component=1" instead of "application/dart":');
163 for (var i = 0; i < results.badTags.length; i++) { 141 for (var i = 0; i < results.badTags.length; i++) {
164 console.warn(results.badTags[i]); 142 console.warn(results.badTags[i]);
165 } 143 }
166 } 144 }
167 newScript.textContent = createMain(results.scripts); 145 newScript.textContent = createMain(results.scripts);
168 document.body.appendChild(newScript); 146 document.body.appendChild(newScript);
169 }); 147 });
170 })(); 148 })();
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer/lib/polymer.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698