| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 support for Dart scripts on the page as this script. | 5 // Bootstrap support for Dart scripts on the page as this script. |
| 6 | |
| 7 if (navigator.webkitStartDart) { | 6 if (navigator.webkitStartDart) { |
| 8 navigator.webkitStartDart(); | 7 navigator.webkitStartDart(); |
| 9 } else { | 8 } else { |
| 9 // TODO: |
| 10 // - Support in-browser compilation. |
| 11 // - Handle inline Dart scripts. |
| 10 window.addEventListener("DOMContentLoaded", function (e) { | 12 window.addEventListener("DOMContentLoaded", function (e) { |
| 11 // Fall back to compiled JS. | 13 // Fall back to compiled JS. Run through all the scripts and |
| 12 var scripts = document.getElementsByTagName("script"); | 14 // replace them if they have a type that indicate that they source |
| 13 var length = scripts.length; | 15 // in Dart code. |
| 14 for (var i = 0; i < length; ++i) { | 16 // |
| 15 if (scripts[i].type == "application/dart") { | 17 // <script type="application/dart" src="<file>.dart"></script> |
| 16 // Remap foo.dart to foo.js. | 18 // |
| 17 // TODO: | 19 // If the script tag has a 'data-compiler' attribute set to |
| 18 // - Support in-browser compilation. | 20 // dart2js then we use the dart2js generated file rather than the |
| 19 // - Handle inline Dart scripts. | 21 // one produced by frog: |
| 20 if (scripts[i].src && scripts[i].src != '') { | 22 // |
| 21 var script = document.createElement('script'); | 23 // <script ... data-compiler="dart2js"></script> |
| 24 // |
| 25 var scripts = document.getElementsByTagName("script"); |
| 26 var length = scripts.length; |
| 27 for (var i = 0; i < length; ++i) { |
| 28 if (scripts[i].type == "application/dart") { |
| 29 // Remap foo.dart to foo.js or foo.js_ depending |
| 30 // on the chosen compiler (frog or dart2js). |
| 31 if (scripts[i].src && scripts[i].src != '') { |
| 32 var script = document.createElement('script'); |
| 33 var compiler = scripts[i].getAttribute('data-compiler'); |
| 34 if (compiler == "dart2js") { |
| 35 script.src = scripts[i].src + '.js_'; |
| 36 } else { |
| 22 script.src = scripts[i].src + '.js'; | 37 script.src = scripts[i].src + '.js'; |
| 23 var parent = scripts[i].parentNode; | |
| 24 parent.replaceChild(script, scripts[i]); | |
| 25 } | 38 } |
| 39 var parent = scripts[i].parentNode; |
| 40 parent.replaceChild(script, scripts[i]); |
| 26 } | 41 } |
| 27 } | 42 } |
| 28 }, false); | 43 } |
| 44 }, false); |
| 29 } | 45 } |
| OLD | NEW |