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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Bootstrap support for Dart scripts on the page as this script. 5 // Bootstrap support for Dart scripts on the page as this script.
6
7 if (navigator.webkitStartDart) { 6 if (navigator.webkitStartDart) {
8 navigator.webkitStartDart(); 7 navigator.webkitStartDart();
9 } else { 8 } else {
9 // TODO:
10 // - Support in-browser compilation.
11 // - Handle inline Dart scripts.
10 window.addEventListener("DOMContentLoaded", function (e) { 12 window.addEventListener("DOMContentLoaded", function (e) {
11 // Fall back to compiled JS. 13 // Fall back to compiled JS. We try to figure out which
12 var scripts = document.getElementsByTagName("script"); 14 // Dart-to-JavaScript compiler to use by looking for
13 var length = scripts.length; 15 // meta information in the current document.
14 for (var i = 0; i < length; ++i) { 16 //
15 if (scripts[i].type == "application/dart") { 17 // <meta name="dart/use-dart2js">
16 // Remap foo.dart to foo.js. 18 //
17 // TODO: 19 // If we don't find such a tag, we default to frog.
18 // - Support in-browser compilation. 20 var metas = document.getElementsByTagName("meta");
19 // - Handle inline Dart scripts. 21 var length = metas.length;
20 if (scripts[i].src && scripts[i].src != '') { 22 var compiler = "frog";
asandholm 2012/05/07 13:13:00 You could consider using var jssuffix = ".js" or j
21 var script = document.createElement('script'); 23 for (var i = 0; i < length; i++) {
24 if (metas[i].name == "dart/use-dart2js") {
25 compiler = "dart2js";
26 break;
27 }
28 }
29
30 // Run through all the scripts and replace them if they have a
31 // type that indicate that they source in Dart code.
32 var scripts = document.getElementsByTagName("script");
33 var length = scripts.length;
34 for (var i = 0; i < length; ++i) {
35 if (scripts[i].type == "application/dart") {
36 // Remap foo.dart to foo.js or foo.js_ depending
37 // on the chosen compiler (frog or dart2js).
38 if (scripts[i].src && scripts[i].src != '') {
39 var script = document.createElement('script');
40 if (compiler == "dart2js") {
41 script.src = scripts[i].src + '.js_';
42 } else {
22 script.src = scripts[i].src + '.js'; 43 script.src = scripts[i].src + '.js';
23 var parent = scripts[i].parentNode;
24 parent.replaceChild(script, scripts[i]);
25 } 44 }
45 var parent = scripts[i].parentNode;
46 parent.replaceChild(script, scripts[i]);
26 } 47 }
27 } 48 }
28 }, false); 49 }
50 }, false);
29 } 51 }
OLDNEW
« 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