-
-
Save misuba/111791 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
CmdUtils.CreateCommand({ | |
name: "lazy-link", | |
takes: {text: noun_arb_text}, | |
description: "Links some text to its top hit in Google.", | |
_firsthit: null, | |
_linkFor: function(recordObj) { | |
return "<a href='" + recordObj.unescapedUrl + "'>" + recordObj.titleNoFormatting + "</a>"; | |
}, | |
preview: function(pblock, directObject) { | |
var searchTerm = directObject.text; | |
CmdUtils.previewGet("http://ajax.googleapis.com/ajax/services/search/web", | |
{ v: "1.0", q: directObject.text }, | |
function(data) { | |
this._firsthit = data.responseData.results[0]; | |
pblock.innerHTML = "Links some text to its top hit in Google, which seems to be:<p>" + | |
this._linkFor(this._firsthit) + "<br />" + this._firsthit.content; | |
}, | |
"json" | |
); | |
}, | |
execute: function(inputObject) { | |
//var url = "http://ajax.googleapis.com/ajax/services/search/web"; | |
//var params = { v: "1.0", q: inputObject.text }; | |
//jQuery.get(url, params, function(data) { | |
CmdUtils.setSelection(this._linkFor(this._firsthit)); | |
//}, "text"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment