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 (function() { | |
5 // Bootstrap support for Dart scripts on the page as this script. | 6 // Bootstrap support for Dart scripts on the page as this script. |
6 if (navigator.webkitStartDart) { | 7 if (navigator.webkitStartDart) { |
7 if (!navigator.webkitStartDart()) { | 8 if (!navigator.webkitStartDart()) { |
8 document.body.innerHTML = 'This build has expired. Please download a new Da rtium at http://www.dartlang.org/dartium/index.html'; | 9 document.body.innerHTML = 'This build has expired. Please download a new Da rtium at http://www.dartlang.org/dartium/index.html'; |
9 } | 10 } |
10 } else { | 11 } else { |
11 // TODO: | 12 // TODO: |
12 // - Support in-browser compilation. | 13 // - Support in-browser compilation. |
13 // - Handle inline Dart scripts. | 14 // - Handle inline Dart scripts. |
14 window.addEventListener("DOMContentLoaded", function (e) { | 15 |
15 // Fall back to compiled JS. Run through all the scripts and | 16 // Fall back to compiled JS. Run through all the scripts and |
16 // replace them if they have a type that indicate that they source | 17 // replace them if they have a type that indicate that they source |
17 // in Dart code. | 18 // in Dart code. |
18 // | 19 // |
19 // <script type="application/dart" src="..."></script> | 20 // <script type="application/dart" src="..."></script> |
20 // | 21 // |
21 var scripts = document.getElementsByTagName("script"); | 22 var scripts = document.getElementsByTagName("script"); |
22 var length = scripts.length; | 23 var length = scripts.length; |
23 for (var i = 0; i < length; ++i) { | 24 for (var i = 0; i < length; ++i) { |
24 if (scripts[i].type == "application/dart") { | 25 if (scripts[i].type == "application/dart") { |
25 // Remap foo.dart to foo.dart.js. | 26 // Remap foo.dart to foo.dart.js. |
26 if (scripts[i].src && scripts[i].src != '') { | 27 if (scripts[i].src && scripts[i].src != '') { |
27 var script = document.createElement('script'); | 28 var script = document.createElement('script'); |
28 script.src = scripts[i].src.replace(/\.dart(?=\?|$)/, '.dart.js'); | 29 script.src = scripts[i].src.replace(/\.dart(?=\?|$)/, '.dart.js'); |
29 var parent = scripts[i].parentNode; | 30 var parent = scripts[i].parentNode; |
blois
2013/08/15 21:38:48
This parent variable was leaking to the window, ov
| |
30 // TODO(vsm): Find a solution for issue 8455 that works with more | 31 // TODO(vsm): Find a solution for issue 8455 that works with more |
31 // than one script. | 32 // than one script. |
32 document.currentScript = script; | 33 document.currentScript = script; |
33 parent.replaceChild(script, scripts[i]); | 34 parent.replaceChild(script, scripts[i]); |
34 } | |
35 } | 35 } |
36 } | 36 } |
37 }, false); | 37 } |
38 } | 38 } |
39 })(); | |
OLD | NEW |