2012-01-22 23:34:35 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Bootstrap support for Dart scripts on the page as this script.
|
2012-02-02 10:09:09 +00:00
|
|
|
if (navigator.webkitStartDart) {
|
2012-05-17 17:15:38 +00:00
|
|
|
if (!navigator.webkitStartDart()) {
|
2012-05-17 14:20:26 +00:00
|
|
|
document.body.innerHTML = 'This build has expired. Please download a new Dartium at http://www.dartlang.org/dartium/index.html';
|
|
|
|
}
|
2012-02-03 12:17:28 +00:00
|
|
|
} else {
|
2012-05-08 15:30:53 +00:00
|
|
|
// TODO:
|
|
|
|
// - Support in-browser compilation.
|
|
|
|
// - Handle inline Dart scripts.
|
2012-01-22 23:34:35 +00:00
|
|
|
window.addEventListener("DOMContentLoaded", function (e) {
|
2012-05-08 15:30:53 +00:00
|
|
|
// 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
|
2012-05-23 13:09:38 +00:00
|
|
|
// frog then we use the frog generated file rather than the
|
|
|
|
// one produced by dart2js:
|
2012-05-08 15:30:53 +00:00
|
|
|
//
|
2012-05-23 13:09:38 +00:00
|
|
|
// <script ... data-compiler="frog"></script>
|
2012-05-08 15:30:53 +00:00
|
|
|
//
|
|
|
|
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');
|
2012-05-23 13:09:38 +00:00
|
|
|
if (compiler == "frog") {
|
2012-05-08 15:30:53 +00:00
|
|
|
script.src = scripts[i].src + '.js_';
|
|
|
|
} else {
|
2012-01-22 23:34:35 +00:00
|
|
|
script.src = scripts[i].src + '.js';
|
|
|
|
}
|
2012-05-08 15:30:53 +00:00
|
|
|
var parent = scripts[i].parentNode;
|
|
|
|
parent.replaceChild(script, scripts[i]);
|
2012-01-22 23:34:35 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-08 15:30:53 +00:00
|
|
|
}
|
|
|
|
}, false);
|
2012-01-22 23:34:35 +00:00
|
|
|
}
|