annotate wowhead/results.js @ 3:7ac908bdb3d3

Fixed more bugs in wowhead.
author Atul Varma <varmaa@toolness.com>
date Fri, 20 Mar 2009 00:32:33 -0700
parents abd59cfa1e70
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
1 var typeRegexp = /.*\(([A-Za-z]+)\).*/;
1
b498a74c7410 More item types in wowhead can be searched.
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
2
0
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
3 function showResults(data) {
2
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
4 var query = data[0];
0
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
5 var names = data[1];
2
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
6 if (!query) {
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
7 $("#results").html("Searches Wowhead.");
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
8 return;
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
9 }
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
10 if (!names.length) {
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
11 $("#results").html("No results found.");
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
12 return;
abd59cfa1e70 Wowhead has better type detection, now tells you if no results were found.
Atul Varma <varmaa@toolness.com>
parents: 1
diff changeset
13 }
0
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
14 var meta = data[7];
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
15 var list = $("<ul></ul>");
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
16 for (var i = 0; i < names.length; i++) {
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
17 var name = names[i];
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
18 var item_meta = meta[i];
3
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
19 var match = name.match(typeRegexp);
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
20 if (!match) {
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
21 list.append($("<li></li>").text(name));
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
22 continue;
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
23 }
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
24 var type = match[1].toLowerCase();
1
b498a74c7410 More item types in wowhead can be searched.
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
25 if (type == "spell" && item_meta[3])
b498a74c7410 More item types in wowhead can be searched.
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
26 name = name.replace("(Spell)", "(" + item_meta[3] + ")");
0
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
27 var id = item_meta[1];
3
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
28 var css = "list-style: none;";
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
29 if (typeof(item_meta[2]) == "string") {
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
30 var iconName = item_meta[2].toLowerCase();
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
31 css = ('list-style-image: url(' +
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
32 'http://static.wowhead.com/images/icons/small/' +
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
33 iconName + '.jpg);');
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
34 }
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
35 var linkClass = '';
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
36 if (item_meta[3] && typeof(item_meta[3]) == "number")
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
37 linkClass = 'q' + item_meta[3];
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
38 var link = $('<a class="' + linkClass + '" ' +
1
b498a74c7410 More item types in wowhead can be searched.
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
39 'href="http://www.wowhead.com/?' +
b498a74c7410 More item types in wowhead can be searched.
Atul Varma <varmaa@toolness.com>
parents: 0
diff changeset
40 type + '=' + id + '"></a>');
0
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
41 link.text(name);
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
42 list.append(link);
3
7ac908bdb3d3 Fixed more bugs in wowhead.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
43 link.wrap('<li style="' + css + '"></li>');
0
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
44 }
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
45 $("#results").html(list);
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
46 }
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
47
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
48 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]]];
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
49
a2715827c482 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
50 //$(window).ready(function() { showResults(SAMPLE_RESULTS); });