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