kfitzpatrick (owner)

Revisions

gist: 10509 Download_button fork
public
Public Clone URL: git://gist.github.com/10509.git
fancast.ubiq.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 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);
}
});