Created
May 29, 2009 21:44
-
-
Save satyr/120223 to your computer and use it in GitHub Desktop.
[Ubiquity] Wolfram|Alpha in preview
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
const WA = 'http://www.wolframalpha.com/'; | |
CmdUtils.CreateCommand({ | |
name: 'wolframalpha', | |
description: ( | |
<a href={WA} style={<![CDATA[ | |
background: | |
url('http://www.wolframalpha.com/images/basicSprite.png') | |
white no-repeat scroll 1px -145px; | |
display:inline-block; vertical-align:middle; | |
width:352px; height:42px; z-index:-1; | |
]]>}> </a>.toXMLString()), | |
author: 'satyr', license: 'MIT', | |
argument: noun_arb_text, | |
icon: WA +'favicon_calculate.ico', | |
execute: function wa_execute({object: {text}}){ | |
Utils.openUrlInBrowser(this._url(text)); | |
}, | |
preview: function wa_preview(pb, {object: {text}}){ | |
pb.innerHTML = this.description; | |
if(!text) return; | |
var me = this; | |
var ifr = pb.ownerDocument.createElement('iframe'); | |
ifr.setAttribute( | |
'style', 'display:none; border:none; overflow:hidden; width:100%'); | |
var logo = pb.firstChild; | |
logo.style.opacity = 0.4; | |
ifr.src = this._url(text); | |
Utils.listenOnce(pb.insertBefore(ifr, logo), 'load', function onload(){ | |
var tid, doc = ifr.contentDocument; | |
$(doc.body).append(me._css); | |
logo.style.opacity = 1; | |
ifr.style.display = 'block'; | |
function fixHeight(){ ifr.height = doc.body.clientHeight } | |
doc.addEventListener('DOMSubtreeModified', function onDOMSM(e){ | |
Utils.clearTimeout(tid); | |
tid = Utils.setTimeout(fixHeight, 99); | |
}, true); | |
}, true); | |
}, | |
_url: function wa__url(i) WA +'input/?i='+ encodeURIComponent(i), | |
_css: '<style>'+ <![CDATA[ | |
header, footer, aside, #calculate, #feedback, #popanchor {display:none;} | |
body, #content {display:inline-block; width:100%; padding:0;} | |
#results {margin:0;} | |
]]>.toString().replace(/;/g, '!important;') +'</style>', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment