-
-
Save asafd1/386919 to your computer and use it in GitHub Desktop.
call JS from preview html example
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({ | |
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: "[email protected]"}, | |
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