OLD | NEW |
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 /// Experimental bootstrap to initialize polymer applications. This library is | 5 /// Experimental bootstrap to initialize polymer applications. This library is |
6 /// not used by default, and may be replaced by Dart code in the near future. | 6 /// not used by default, and may be replaced by Dart code in the near future. |
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 Dart script tags through HTML imports, and constructs | 9 /// internally discovers Dart script tags through HTML imports, and constructs |
10 /// a new entrypoint for the application that is then launched in an isolate. | 10 /// a new entrypoint for the application that is then launched in an isolate. |
(...skipping 15 matching lines...) Expand all Loading... |
26 /// script tags in the main page, so you may need to move some code into an HTML | 26 /// script tags in the main page, so you may need to move some code into an HTML |
27 /// import. For example, If you need to run some initialization code before any | 27 /// import. For example, If you need to run some initialization code before any |
28 /// other code is executed, include an HTML import to an html file with a | 28 /// other code is executed, include an HTML import to an html file with a |
29 /// "application/dart" script tag that contains an initializer | 29 /// "application/dart" script tag that contains an initializer |
30 /// method with the body of your old main, and make sure this tag is placed | 30 /// method with the body of your old main, and make sure this tag is placed |
31 /// above other html-imports that load the rest of the application. | 31 /// above other html-imports that load the rest of the application. |
32 /// Initialization methods are executed in the order in which they are | 32 /// Initialization methods are executed in the order in which they are |
33 /// discovered in the HTML document. | 33 /// discovered in the HTML document. |
34 (function() { | 34 (function() { |
35 // Only run in Dartium. | 35 // Only run in Dartium. |
36 if (!navigator.dartEnabled && | 36 if (navigator.userAgent.indexOf('(Dart)') === -1) return; |
37 // TODO(sigmund): remove userAgent check once 1.6 rolls as stable. | |
38 // See: dartbug.com/18463 | |
39 (navigator.userAgent.indexOf('(Dart)') === -1)) { | |
40 return; | |
41 } | |
42 | 37 |
43 // Extract a Dart import URL from a script tag, which is the 'src' attribute | 38 // Extract a Dart import URL from a script tag, which is the 'src' attribute |
44 // of the script tag, or a data-url with the script contents for inlined code. | 39 // of the script tag, or a data-url with the script contents for inlined code. |
45 function getScriptUrl(script) { | 40 function getScriptUrl(script) { |
46 var url = script.src; | 41 var url = script.src; |
47 if (url) { | 42 if (url) { |
48 // Normalize package: urls | 43 // Normalize package: urls |
49 var index = url.indexOf('packages/'); | 44 var index = url.indexOf('packages/'); |
50 if (index == 0 || (index > 0 && url[index - 1] == '/')) { | 45 if (index == 0 || (index > 0 && url[index - 1] == '/')) { |
51 url = "package:" + url.slice(index + 9); | 46 url = "package:" + url.slice(index + 9); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 + 'doesn\'t have a main, but a top-level method marked with ' | 119 + 'doesn\'t have a main, but a top-level method marked with ' |
125 + '@initMethod instead'); | 120 + '@initMethod instead'); |
126 for (var i = 0; i < results.badTags.length; i++) { | 121 for (var i = 0; i < results.badTags.length; i++) { |
127 console.warn(results.badTags[i]); | 122 console.warn(results.badTags[i]); |
128 } | 123 } |
129 } | 124 } |
130 newScript.textContent = createMain(results.scripts); | 125 newScript.textContent = createMain(results.scripts); |
131 document.body.appendChild(newScript); | 126 document.body.appendChild(newScript); |
132 }); | 127 }); |
133 })(); | 128 })(); |
OLD | NEW |