-
-
Save tkf/112651 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: "insert-formula", | |
takes: {"expression in LaTeX": noun_arb_text}, | |
homepage: "http://arataka.wordpress.com", | |
author: {name: "Takafumi Arakaki", homepage: "http://arataka.wordpress.com"}, | |
license: "MPL", | |
preview: function( pblock, what ) { | |
var base = "https://secure.s21g.com/formula/formulae/preview_with_auth"; | |
var img_url = [base, '?expression=', encodeURIComponent(what.text)].join(''); | |
jQuery.get(img_url, null, function(){ | |
pblock.innerHTML = [ | |
'<div style="height:200px"><img src="', img_url, | |
'" style="display:block;background:#FFF;-moz-border-radius:5px;border:5px solid #FFF" />', | |
'powered by <a href="http://formula.s21g.com/" style="text-decoration:underline">formula.s21g.com</a></div>'].join(''); | |
}); | |
}, | |
execute: function( what, mods ) { | |
jQuery.ajax({ | |
url: ['https://secure.s21g.com/formula/formulae/create_with_auth?formula[expression]=', | |
encodeURIComponent(what.text), '&base=http%3A%2F%2Fformula.s21g.com%2F'].join(''), | |
cache: false, | |
success: function(html){ | |
var ehtml = jQuery(html).find("#embed_html").val(); | |
var fsrc = jQuery(ehtml).find("img").attr("src"); | |
//var furl = jQuery(ehtml).parent().find("a").attr("href"); | |
var furl = "http://formula.s21g.com" + jQuery(html).find("#formula .formula a").attr("href"); | |
var doc = context.focusedWindow.document; | |
var focused = context.focusedElement; | |
if (doc.designMode == "on") | |
//rich text case | |
doc.execCommand("insertHTML", false, "<img src='" + fsrc + "'/>"); | |
else if (focused != null && ((focused.type == "textarea") || (focused.type == "text"))) | |
// simple text | |
CmdUtils.setSelection(furl); | |
else | |
displayMessage("Sorry, this function can be used in an editable box only"); | |
} | |
}); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment