OLD | NEW |
| (Empty) |
1 Dart JavaScript Interop | |
2 =================== | |
3 | |
4 The js.dart library allows Dart code running in the browser to | |
5 manipulate JavaScript running in the same page. It is intended to | |
6 allow Dart code to easily interact with third-party JavaScript libraries. | |
7 | |
8 Warning | |
9 ------- | |
10 | |
11 The use of this library may result in a sizable increase in code size | |
12 when compiled to JavaScript, because names cannot be minified. If the | |
13 size of the generated JavaScript is a concern, use the [dart:js][dartjs] | |
14 library. | |
15 | |
16 Documentation | |
17 ------------- | |
18 | |
19 See [API documentation][docs]. You should also watch this [video tutorial][video
]. | |
20 | |
21 Samples | |
22 ------- | |
23 | |
24 See [samples][samples] that demonstrate interaction with JavaScript | |
25 code. These include interoperation with the Google Maps JavaScript | |
26 library, the Google Visualization JavaScript library, and Twitter's | |
27 query API via JSONP. | |
28 | |
29 Usage | |
30 ----- | |
31 | |
32 The [Dart Editor][editor] now includes pub support. To try out this | |
33 library in the editor: | |
34 | |
35 1. [Update to the latest editor][editor]. | |
36 | |
37 2. From the "File" menu, open a "New Application" (and make sure "Add | |
38 Pub support" is checked). | |
39 | |
40 3. Add the following to your pubspec.yaml: | |
41 | |
42 dependencies: | |
43 js: any | |
44 | |
45 | |
46 4. Under the "Tools" menu, run "Pub Install". | |
47 | |
48 5. Try the following test Dart file: | |
49 | |
50 import 'package:js/js.dart' as js; | |
51 | |
52 void main() { | |
53 js.context.alert('Hello from Dart via JS'); | |
54 } | |
55 | |
56 6. Add the script to your HTML page: | |
57 | |
58 <script src="packages/browser/dart.js"></script> | |
59 <script src="packages/browser/interop.js"></script> | |
60 | |
61 Running Tests | |
62 ------------- | |
63 | |
64 First, use the [Pub Package Manager][pub] to install dependencies: | |
65 | |
66 pub install | |
67 | |
68 To run browser tests on [Dartium], simply open **test/browser_tests.html** | |
69 in Dartium. | |
70 | |
71 To run browser tests using JavaScript in any modern browser, first use the | |
72 following command to compile to JavaScript: | |
73 | |
74 dart2js -otest/browser_tests.dart.js test/browser_tests.dart | |
75 | |
76 and then open **test/browser_tests.html** in any browser. | |
77 | |
78 [d]: http://www.dartlang.org | |
79 [mb]: http://www.dartlang.org/support/faq.html#what-browsers-supported | |
80 [pub]: http://www.dartlang.org/docs/pub-package-manager/ | |
81 [Dartium]: http://www.dartlang.org/tools/dartium/ | |
82 [docs]: http://dart-lang.github.com/js-interop | |
83 [samples]: http://dart-lang.github.com/js-interop/example | |
84 [editor]: http://www.dartlang.org/docs/editor/getting-started/ | |
85 [video]: http://www.youtube.com/watch?v=QFuCFUd2Zsw | |
86 [dartjs]: http://api.dartlang.org/docs/channels/stable/latest/dart_js.html | |
OLD | NEW |