Mercurial > my-ubiquity-commands
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 |
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 | 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 | 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 | 14 var meta = data[7]; |
15 var list = $("<ul></ul>"); | |
16 for (var i = 0; i < names.length; i++) { | |
17 var name = names[i]; | |
18 var item_meta = meta[i]; | |
3 | 19 var match = name.match(typeRegexp); |
20 if (!match) { | |
21 list.append($("<li></li>").text(name)); | |
22 continue; | |
23 } | |
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 | 27 var id = item_meta[1]; |
3 | 28 var css = "list-style: none;"; |
29 if (typeof(item_meta[2]) == "string") { | |
30 var iconName = item_meta[2].toLowerCase(); | |
31 css = ('list-style-image: url(' + | |
32 'http://static.wowhead.com/images/icons/small/' + | |
33 iconName + '.jpg);'); | |
34 } | |
35 var linkClass = ''; | |
36 if (item_meta[3] && typeof(item_meta[3]) == "number") | |
37 linkClass = 'q' + item_meta[3]; | |
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 | 41 link.text(name); |
42 list.append(link); | |
3 | 43 link.wrap('<li style="' + css + '"></li>'); |
0 | 44 } |
45 $("#results").html(list); | |
46 } | |
47 | |
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]]]; | |
49 | |
50 //$(window).ready(function() { showResults(SAMPLE_RESULTS); }); |