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

Unified Diff: client/dart.js

Issue 10388005: Allow developers to try out dart2js in their web apps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698