Skip to content

Instantly share code, notes, and snippets.

@asafd1
Created May 2, 2010 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asafd1/386919 to your computer and use it in GitHub Desktop.
Save asafd1/386919 to your computer and use it in GitHub Desktop.
call JS from preview html example
CmdUtils.CreateCommand({
names: ["666"],
domain: "seret.co.il",
arguments: [
{role: "object", label: 'what', nountype: noun_arb_text}
],
description: "seret.co.il חפש סרט באתר",
icon: "http://www.seret.co.il/favicon.ico",
homepage: "http://sites.google.com/site/ubiquityisrael",
author: { name: "Asaf David", email: "asafd1@gmail.com"},
license: "GPL",
execute: function( args ){
args.object.text = "site:" + this.domain + " " + args.object.text;
CmdUtils.executeCommand("Google", args)
return true;
},
preview: function(pblock, args) {
var txt = jQuery.trim( args.object.text );
var jsonURL = "http://ajax.googleapis.com/ajax/services/search/web?q=site:" + this.domain +" " + txt + "&v=1.0&rsz=large&callback=?";
pblock.innerHTML = "Searching for " + txt + ' on <a title="' + this.domain + '" target="_blank" href="' +this.domain+ '/">' + this.domain + '...</a>';
jQuery.getJSON(jsonURL,
function (data) {
if (data.responseData.results &&
data.responseData.results.length > 0) {
var results = data.responseData.results;
var text = "";
for (var i=0; i < results.length; i++) {
text += '<h3>' + (i+1) + '. ' + '<a href="' + results[i].unescapedUrl + '">' + results[i].titleNoFormatting + '</a></h3>';
text += results[i].content + '<br>';
text += '<a class="hand" onclick="insertURL(results[i]);">Insert URL in page</a><br>';
}
pblock.innerHTML = text;
}
}
)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment