73
edits
(Made the sample code modern (and actually work).) |
|||
| Line 860: | Line 860: | ||
<pre> | <pre> | ||
var noun_type_freebase_topic = { | var noun_type_freebase_topic = { | ||
name: "Freebase topic", | |||
label: "topic", | |||
suggest: function | suggest: function freebase_topic_suggest(text, html, callback) { | ||
return [ | |||
CmdUtils.makeSugg(text), | |||
$.ajax({ | |||
url: "http://www.freebase.com/api/service/search", | |||
dataType: "json", | |||
data: {prefix: text, limit: 5}, | |||
success: function suggestTopics(response) { | |||
if (response.status === "200 OK") | |||
callback([CmdUtils.makeSugg(result.name, result.name, result) | |||
for each (result in response.result)]); | |||
} | }, | ||
} | })]; | ||
} | } | ||
} | }; | ||
CmdUtils.CreateCommand( { | CmdUtils.CreateCommand({ | ||
names: ["lookup on freebase"], | names: ["lookup on freebase"], | ||
arguments: | arguments: {object: noun_type_freebase_topic}, | ||
preview: function preview(pblock, args) { | |||
pblock.innerHTML = _(("Go to the Freebase topic page for " + | |||
preview: function preview( pblock, | "{if text}${text}{else}any topic{/if}."), | ||
args.object); | |||
pblock.innerHTML = _("Go to the Freebase topic page for ${text}.", | |||
}, | }, | ||
execute: function goToFreebase( | execute: function goToFreebase({object: {text, data}}) { | ||
Utils.openUrlInBrowser( | |||
text | |||
? (data | |||
? "http://www.freebase.com/view" + data.id | |||
: ("http://www.freebase.com/search?query=" + | |||
encodeURIComponent(text))) | |||
: "http://www.freebase.com/"); | |||
} | } | ||
} ); | }); | ||
</pre> | </pre> | ||
edits