Mercurial > my-ubiquity-commands
view wowhead/results.js @ 26:f3cd3dc2f451
compatibility change for latest jetpack version
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 12 May 2009 23:00:29 -0700 |
parents | 7ac908bdb3d3 |
children |
line wrap: on
line source
var typeRegexp = /.*\(([A-Za-z]+)\).*/; function showResults(data) { var query = data[0]; var names = data[1]; if (!query) { $("#results").html("Searches Wowhead."); return; } if (!names.length) { $("#results").html("No results found."); return; } 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 match = name.match(typeRegexp); if (!match) { list.append($("<li></li>").text(name)); continue; } var type = match[1].toLowerCase(); if (type == "spell" && item_meta[3]) name = name.replace("(Spell)", "(" + item_meta[3] + ")"); var id = item_meta[1]; var css = "list-style: none;"; if (typeof(item_meta[2]) == "string") { var iconName = item_meta[2].toLowerCase(); css = ('list-style-image: url(' + 'http://static.wowhead.com/images/icons/small/' + iconName + '.jpg);'); } var linkClass = ''; if (item_meta[3] && typeof(item_meta[3]) == "number") linkClass = 'q' + item_meta[3]; var link = $('<a class="' + linkClass + '" ' + 'href="http://www.wowhead.com/?' + type + '=' + id + '"></a>'); link.text(name); list.append(link); link.wrap('<li style="' + css + '"></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); });