changeset 0:a2715827c482

Origination.
author Atul Varma <varmaa@toolness.com>
date Thu, 19 Mar 2009 23:30:41 -0700
parents
children b498a74c7410
files wowhead/results.html wowhead/results.js wowhead/wowhead.html wowhead/wowhead.js
diffstat 4 files changed, 78 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wowhead/results.html	Thu Mar 19 23:30:41 2009 -0700
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+  <title>Preview Content</title>
+</head>
+<body class="ubiquity-preview-content" style="margin: 0; padding: 0;">
+<div id="results"></div>
+</body>
+<script src="resource://ubiquity/scripts/jquery.js"></script>
+<script src="http://www.wowhead.com/widgets/power.js"></script>
+<script src="results.js"></script>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wowhead/results.js	Thu Mar 19 23:30:41 2009 -0700
@@ -0,0 +1,21 @@
+function showResults(data) {
+  var names = data[1];
+  var meta = data[7];
+  var list = $("<ul></ul>");
+  for (var i = 0; i < names.length; i++) {
+    var name = names[i];
+    var item_meta = meta[i];
+    var id = item_meta[1];
+    var quality = item_meta[3];
+    var link = $('<a class="q' + quality + '" ' +
+                 'href="http://www.wowhead.com/?item=' + id + '"></a>');
+    link.text(name);
+    list.append(link);
+    link.wrap("<li></li>");
+  }
+  $("#results").html(list);
+}
+
+SAMPLE_RESULTS = ["sword", ["Bastard Sword (Item)", "Chromatic Sword (Item)", "Commoner's Sword (Item)", "Crude Bastard Sword (Item)", "Feeble Sword (Item)", "Long Bastard Sword (Item)", "Shadowhide Two-handed Sword (Item)", "Sword of Decay (Item)", "Sword of the Night Sky (Item)", "Well-used Sword (Item)"], [], [], [], [], [], [[3, 1194, "INV_Sword_06", 1], [3, 1604, "INV_Sword_22", 2], [3, 1511, "INV_Sword_04", 0], [3, 1412, "INV_Sword_06", 0], [3, 1413, "INV_Sword_04", 0], [3, 1830, "INV_Sword_06", 0], [3, 1460, "INV_Sword_46", 2], [3, 1727, "INV_Sword_26", 3], [3, 2035, "INV_Sword_20", 2], [3, 1008, "INV_Sword_04", 1]]];
+
+//$(window).ready(function() { showResults(SAMPLE_RESULTS); });
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wowhead/wowhead.html	Thu Mar 19 23:30:41 2009 -0700
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+  <link rel="commands" href="wowhead.js"/>
+  <title>Wowhead Ubiquity Command</title>
+</head>
+<body>
+Hi there.
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wowhead/wowhead.js	Thu Mar 19 23:30:41 2009 -0700
@@ -0,0 +1,31 @@
+/* This is a template command. */
+CmdUtils.CreateCommand({
+  name: "wowhead",
+  icon: "http://www.wowhead.com/favicon.png",
+  homepage: "http://www.wowhead.com/",
+  author: {name: "Your Name", email: "you@example.com"},
+  license: "GPL",
+  description: "A short description of your command",
+  help: "How to use your command",
+  takes: {"input": /.*/},
+  previewUrl: Utils.url({uri: "results.html", base: feed.id}),
+  preview: function(pblock, input) {
+    var url = ("http://www.wowhead.com/?search=" + encodeURI(input.text) +
+               "&opensearch");
+    CmdUtils.previewAjax(pblock, {
+      url: url,
+      dataType: "text",
+      error: function() {
+        pblock.innerHTML = "Sorry, an error occurred.";
+      },
+      success: function(data) {
+        var scriptTag = pblock.ownerDocument.createElement("script");
+        scriptTag.textContent = "showResults(" + data + ");";
+        pblock.appendChild(scriptTag);
+      }
+    });
+  },
+  execute: function(input) {
+    displayMessage("You selected: " + input.text);
+  }
+});