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

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: 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 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. Run through all the scripts and
12 var scripts = document.getElementsByTagName("script"); 14 // replace them if they have a type that indicate that they source
13 var length = scripts.length; 15 // in Dart code.
14 for (var i = 0; i < length; ++i) { 16 //
15 if (scripts[i].type == "application/dart") { 17 // <script type="application/dart" src="<file>.dart"></script>
16 // Remap foo.dart to foo.js. 18 //
17 // TODO: 19 // If the script tag has a 'data-compiler' attribute set to
18 // - Support in-browser compilation. 20 // dart2js then we use the dart2js generated file rather than the
19 // - Handle inline Dart scripts. 21 // one produced by frog:
20 if (scripts[i].src && scripts[i].src != '') { 22 //
21 var script = document.createElement('script'); 23 // <script ... data-compiler="dart2js"></script>
24 //
25 var scripts = document.getElementsByTagName("script");
26 var length = scripts.length;
27 for (var i = 0; i < length; ++i) {
28 if (scripts[i].type == "application/dart") {
29 // Remap foo.dart to foo.js or foo.js_ depending
30 // on the chosen compiler (frog or dart2js).
31 if (scripts[i].src && scripts[i].src != '') {
32 var script = document.createElement('script');
33 var compiler = scripts[i].getAttribute('data-compiler');
34 if (compiler == "dart2js") {
35 script.src = scripts[i].src + '.js_';
36 } else {
22 script.src = scripts[i].src + '.js'; 37 script.src = scripts[i].src + '.js';
23 var parent = scripts[i].parentNode;
24 parent.replaceChild(script, scripts[i]);
25 } 38 }
39 var parent = scripts[i].parentNode;
40 parent.replaceChild(script, scripts[i]);
26 } 41 }
27 } 42 }
28 }, false); 43 }
44 }, false);
29 } 45 }
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