/**
* ASCIIMath Plugin for TinyMCE editor
* port of ASCIIMath plugin for HTMLArea written by
* David Lippman & Peter Jipsen
*
* @author David Lippman
* @copyright Copyright © 2008 David Lippman.
*
* Plugin format based on code that is:
* @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
*/
(function() {
// Load plugin specific language pack
tinymce.PluginManager.requireLangPack('asciimath');
tinymce.create('tinymce.plugins.AsciimathPlugin', {
/**
* Initializes the plugin, this will be executed after the plugin has been created.
* This call is done before the editor instance has finished it's initialization so use the onInit event
* of the editor instance to intercept that event.
*
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
* @param {string} url Absolute URL to where the plugin is located.
*/
init : function(ed, url) {
var t = this;
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceAsciimath');
ed.addCommand('mceAsciimath', function(val) {
el = ed.selection.getNode();
if (t.lastAMnode==null) {
existing = ed.selection.getContent();
if (existing.indexOf('class=AM')==-1) { //existing does not contain an AM node, so turn it into one
//strip out all existing html tags.
existing = existing.replace(/<([^>]*)>/g,"");
existing = existing.replace(/&(.*?);/g,"$1");
if (val) {
existing = val;
}
entity = '`'+existing+'` ';
if (tinymce.isIE) ed.focus();
ed.selection.setContent(entity);
ed.selection.select(ed.dom.get('removeme'));
ed.dom.remove('removeme');
ed.selection.collapse(true);
ed.nodeChanged();
}
} else if (val) {
ed.selection.setContent(val);
}
});
ed.addCommand('mceAsciimathDlg', function() {
if (typeof AMTcgiloc == 'undefined') {
AMTcgiloc = "";
}
ed.windowManager.open({
file : url + '/amcharmap.htm',
width : 630 + parseInt(ed.getLang('asciimathdlg.delta_width', 0)),
height : 390 + parseInt(ed.getLang('asciimathdlg.delta_height', 0)),
inline : 1
}, {
plugin_url : url, // Plugin absolute URL
AMTcgiloc : AMTcgiloc
});
});
ed.onKeyPress.add(function(ed, ev) {
var key = String.fromCharCode(ev.charCode || ev.keyCode);
if (key=='`') {
if (t.lastAMnode == null) {
existing = ed.selection.getContent();
if (existing.indexOf('class=AM')==-1) { //existing does not contain an AM node, so turn it into one
//strip out all existing html tags.
existing = existing.replace(/<([^>]*)>/g,"");
entity = '`'+existing+'` ';
if (tinymce.isIE) ed.focus();
ed.selection.setContent(entity);
ed.selection.select(ed.dom.get('removeme'));
ed.dom.remove('removeme');
ed.nodeChanged();
}
}
if (ev.stopPropagation) {
ev.stopPropagation();
ev.preventDefault();
} else {
ev.cancelBubble = true;
ev.returnValue = false;
}
}
});
// Register asciimath button
ed.addButton('asciimath', {
title : 'asciimath.desc',
cmd : 'mceAsciimath',
image : url + '/img/ed_mathformula2.gif'
});
ed.addButton('asciimathcharmap', {
title : 'asciimathcharmap.desc',
cmd : 'mceAsciimathDlg',
image : url + '/img/ed_mathformula.gif'
});
/*
ed.onInit.add(function(ed) {
AMtags = ed.dom.select('span.AM');
for (var i=0; i";
addhtml +="";
ed.dom.doc.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd",addhtml);
}
});
ed.onPreProcess.add(function(ed,o) {
if (o.get) {
AMtags = ed.dom.select('span.AM', o.node);
for (var i=0; i]*?)\s.*>.*/g,"$2");
myAM = myAM.replace(/.+(alt|title)=(.*?)>.*/g,"$2");
//myAM = myAM.replace(/>/g,">");
//myAM = myAM.replace(/</g,"<");
myAM = myAM.replace(/>/g,">");
myAM = myAM.replace(/