Created
September 12, 2008 20:20
-
-
Save kfitzpatrick/10509 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fancast search ubiquity verb | |
if(typeof(KFDotNet) == 'undefined') { | |
KFDotNet = {}; | |
} | |
jQuery.extend(KFDotNet, { | |
fancast_util: { | |
generate_query: function(searchText){ | |
var location = "http://cimjoyent.ath.cx/~kfitzpat/fancastSearchProxy/searchProxy.php?q="+escape(searchText); | |
return location; | |
} | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "fancast", | |
homepage: "http://gist.github.com/10509", | |
author: { name: "Kevin Fitzpatrick", email: "kevin.m.a.fitzpatrick@gmail.com"}, | |
description: "Searches Fancast.com for the movie, TV show or person you enter.", | |
icon: "http://www.fancast.com/favicon.ico", | |
takes: {"entity": noun_arb_text}, | |
preview: function(pblock, input) { | |
var searchText = input.text; | |
searchUrl = KFDotNet.fancast_util.generate_query(searchText) | |
if(input.text == '') { | |
pblock.innerHTML = "Type something to Search Fancast.com."; | |
} else { | |
var preview = "<p>Search for \"" + searchText + "\"</p>"; | |
pblock.innerHTML = preview; | |
jQuery.ajax( | |
{ | |
type:"GET", | |
url: searchUrl, | |
success: function(results){ | |
var filteredResults = jQuery(results).find("entities > *").not("[role]").not("[rel='search']"); | |
var template = "<ol style=\"margin: 0;\">" + | |
"{for item in items}"+ | |
"{if item_index < 10}"+ | |
"<li class=\"gresult\">"+ | |
"<a "+ | |
"href=\"${item.getElementsByTagName('fancastUrl')[0].textContent}\">"+ | |
"${item.getAttribute('name')}"+ | |
" ("+ | |
"{if item.nodeName == 'tvSeries'}"+ | |
"TV Series"+ | |
"{elseif item.nodeName == 'movie'}"+ | |
"Movie"+ | |
"{elseif item.nodeName == 'contributor'}"+ | |
"Person"+ | |
"{/if}"+ | |
")"+ | |
"</a>"+ | |
"</li>"+ | |
"{/if}"+ | |
"{/for}"+ | |
"</ol>"; | |
var rendered = CmdUtils.renderTemplate(template, {items: filteredResults}); | |
pblock.innerHTML += rendered; | |
} | |
} | |
); | |
} | |
}, | |
execute: function (input) { | |
var url = "http://www.fancast.com/search/?s=" + escape(input.text); | |
Utils.openUrlInBrowser(url); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment