mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:37:53 +00:00
Allow developers to try out dart2js in their web apps.
We look for a dart-compiler attribute on the script tag and if it is set to dart2js we use the dart2js generated file. R=sandholm@google.com BUG= TEST= Review URL: https://chromiumcodereview.appspot.com//10388005 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@7418 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
3ee233c155
commit
f379a1d8a3
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue