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

Unified Diff: third_party/pkg/js/example/twitter/twitter.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/js/example/twitter/twitter.dart
diff --git a/third_party/pkg/js/example/twitter/twitter.dart b/third_party/pkg/js/example/twitter/twitter.dart
new file mode 100644
index 0000000000000000000000000000000000000000..859cd0f4088e71e6fb1cf0ed09dd4e9dc227f22c
--- /dev/null
+++ b/third_party/pkg/js/example/twitter/twitter.dart
@@ -0,0 +1,52 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// A JS interop sample showing JSONP access to Twitter from Dart.
+
+import 'dart:html';
+import 'package:js/js.dart' as js;
+
+void main() {
+ // Create a JavaScript function called display that forwards to the Dart
+ // function.
+ js.context.display = display;
+
+ // Inject a JSONP request to Twitter invoking the JavaScript display
+ // function.
+ document.body.nodes.add(new ScriptElement()..src =
+ "https://search.twitter.com/search.json?q=dartlang&rpp=20&callback=display");
+}
+
+// Convert URLs in the text to links.
+String linkify(String text) {
+ List words = text.split(' ');
+ var buffer = new StringBuffer();
+ for (var word in words) {
+ if (!buffer.isEmpty) buffer.write(' ');
+ if (word.startsWith('http://') || word.startsWith('https://')) {
+ buffer.write('<a href="$word">$word</a>');
+ } else {
+ buffer.write(word);
+ }
+ }
+ return buffer.toString();
+}
+
+// Display the JSON data on the web page.
+// Note callbacks are automatically executed within a scope.
+void display(var data) {
+ // The data and results objects are proxies to JavaScript object.
+ var results = data.results;
+ int length = results.length;
+
+ for (int i = 0; i < length; ++i) {
+ var result = results[i];
+ String user = result.from_user_name;
+ String text = linkify(result.text);
+
+ var div = new DivElement()
+ ..innerHtml = '<div>From: $user</div><div>$text</div><p>';
+ document.body.nodes.add(div);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698