OLD | NEW |
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 // A JS interop sample showing JSONP access to Twitter from Dart. | 5 // A JS interop sample showing JSONP access to Twitter from Dart. |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'dart:json'; | |
9 import 'package:js/js.dart' as js; | 8 import 'package:js/js.dart' as js; |
10 | 9 |
11 void main() { | 10 void main() { |
12 // Create a JavaScript function called display that forwards to the Dart | 11 // Create a JavaScript function called display that forwards to the Dart |
13 // function. | 12 // function. |
14 js.context.display = new js.Callback.once(display); | 13 js.context.display = new js.Callback.once(display); |
15 | 14 |
16 // Inject a JSONP request to Twitter invoking the JavaScript display | 15 // Inject a JSONP request to Twitter invoking the JavaScript display |
17 // function. | 16 // function. |
18 document.body.nodes.add(new ScriptElement()..src = | 17 document.body.nodes.add(new ScriptElement()..src = |
(...skipping 25 matching lines...) Expand all Loading... |
44 for (int i = 0; i < length; ++i) { | 43 for (int i = 0; i < length; ++i) { |
45 var result = results[i]; | 44 var result = results[i]; |
46 String user = result.from_user_name; | 45 String user = result.from_user_name; |
47 String text = linkify(result.text); | 46 String text = linkify(result.text); |
48 | 47 |
49 var div = new DivElement() | 48 var div = new DivElement() |
50 ..innerHtml = '<div>From: $user</div><div>$text</div><p>'; | 49 ..innerHtml = '<div>From: $user</div><div>$text</div><p>'; |
51 document.body.nodes.add(div); | 50 document.body.nodes.add(div); |
52 } | 51 } |
53 } | 52 } |
OLD | NEW |