Index: client/dart.js |
diff --git a/client/dart.js b/client/dart.js |
index d740c1fcd6940f2589a14ae38f86a267b056049c..bad712cd7309b41a86d6630c5b0dd818f79f2626 100644 |
--- a/client/dart.js |
+++ b/client/dart.js |
@@ -3,27 +3,49 @@ |
// BSD-style license that can be found in the LICENSE file. |
// Bootstrap support for Dart scripts on the page as this script. |
- |
if (navigator.webkitStartDart) { |
navigator.webkitStartDart(); |
} else { |
+ // TODO: |
+ // - Support in-browser compilation. |
+ // - Handle inline Dart scripts. |
window.addEventListener("DOMContentLoaded", function (e) { |
- // Fall back to compiled JS. |
- var scripts = document.getElementsByTagName("script"); |
- var length = scripts.length; |
- for (var i = 0; i < length; ++i) { |
- if (scripts[i].type == "application/dart") { |
- // Remap foo.dart to foo.js. |
- // TODO: |
- // - Support in-browser compilation. |
- // - Handle inline Dart scripts. |
- if (scripts[i].src && scripts[i].src != '') { |
- var script = document.createElement('script'); |
+ // Fall back to compiled JS. We try to figure out which |
+ // Dart-to-JavaScript compiler to use by looking for |
+ // meta information in the current document. |
+ // |
+ // <meta name="dart/use-dart2js"> |
+ // |
+ // If we don't find such a tag, we default to frog. |
+ var metas = document.getElementsByTagName("meta"); |
+ var length = metas.length; |
+ var compiler = "frog"; |
asandholm
2012/05/07 13:13:00
You could consider using var jssuffix = ".js" or j
|
+ for (var i = 0; i < length; i++) { |
+ if (metas[i].name == "dart/use-dart2js") { |
+ compiler = "dart2js"; |
+ break; |
+ } |
+ } |
+ |
+ // Run through all the scripts and replace them if they have a |
+ // type that indicate that they source in Dart code. |
+ var scripts = document.getElementsByTagName("script"); |
+ var length = scripts.length; |
+ for (var i = 0; i < length; ++i) { |
+ if (scripts[i].type == "application/dart") { |
+ // Remap foo.dart to foo.js or foo.js_ depending |
+ // on the chosen compiler (frog or dart2js). |
+ if (scripts[i].src && scripts[i].src != '') { |
+ var script = document.createElement('script'); |
+ if (compiler == "dart2js") { |
+ script.src = scripts[i].src + '.js_'; |
+ } else { |
script.src = scripts[i].src + '.js'; |
- var parent = scripts[i].parentNode; |
- parent.replaceChild(script, scripts[i]); |
} |
+ var parent = scripts[i].parentNode; |
+ parent.replaceChild(script, scripts[i]); |
} |
} |
- }, false); |
+ } |
+ }, false); |
} |