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

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: Use data-compiler attribute. 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..d0899d1fa6ced6f5140c18f9b6f0e965e458f724 100644
--- a/client/dart.js
+++ b/client/dart.js
@@ -3,27 +3,43 @@
// 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. Run through all the scripts and
+ // replace them if they have a type that indicate that they source
+ // in Dart code.
+ //
+ // <script type="application/dart" src="<file>.dart"></script>
+ //
+ // If the script tag has a 'data-compiler' attribute set to
+ // dart2js then we use the dart2js generated file rather than the
+ // one produced by frog:
+ //
+ // <script ... data-compiler="dart2js"></script>
+ //
+ 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');
+ var compiler = scripts[i].getAttribute('data-compiler');
+ 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