-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathplugin.js
More file actions
69 lines (66 loc) · 2.58 KB
/
Copy pathplugin.js
File metadata and controls
69 lines (66 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(function(tinymce){
tinymce.create('tinymce.plugins.Formula', {
init: function(editor, url) {
var options = editor.getParam('formula') || {};
var path = options.path || url;
editor.addButton('formula', {
image: path + '/img/formula.png',
tooltip: 'Insert Formula',
onclick: showFormulaDialog.bind(this, editor, path),
onPostRender: function() {
var _this = this; // reference to the button itself
editor.on('NodeChange', function(e) {
_this.active(e.element.className.indexOf('fm-editor-equation')>-1 && e.element.nodeName.toLowerCase() == "img");
})
}
});
}
});
tinymce.PluginManager.requireLangPack('formula','en,es,fr_FR');
tinymce.PluginManager.add('formula', tinymce.plugins.Formula);
function showFormulaDialog(editor, url) {
editor.windowManager.open({
title: "Formula",
width : 900,
height : 610,
html: buildIFrame(editor, url),
buttons: [
{
text: 'Cancel',
onclick: function() {
this.parent().parent().close();
}
},
{
text: 'Insert Formula',
subtype: 'primary',
onclick: function(e) {
var me = this;
if(window.frames['tinymceFormula'] && window.frames['tinymceFormula'].getData) {
window.frames['tinymceFormula'].getData(function(src, mlang, equation) {
if(src) {
editor.insertContent('<img class="fm-editor-equation" src="' + src + '" data-mlang="' + mlang + '" data-equation="' + encodeURIComponent(equation) + '"/>');
}
me.parent().parent().close();
});
} else {
me.parent().parent().close();
}
}
}
]
});
}
function buildIFrame(editor, url){
var currentNode = editor.selection.getNode();
var lang = editor.getParam('language') || 'en';
var mlangParam = '';
var equationParam = '';
if (currentNode.nodeName.toLowerCase() == 'img' && currentNode.className.indexOf('fm-editor-equation')>-1) {
if (currentNode.getAttribute('data-mlang')) mlangParam = "&mlang=" + currentNode.getAttribute('data-mlang');
if (currentNode.getAttribute('data-equation')) equationParam = '&equation=' + currentNode.getAttribute('data-equation');
}
var html = '<iframe name="tinymceFormula" id="tinymceFormula" src="'+ url + '/index.html'+ '?lang='+ lang + mlangParam + equationParam + '" scrolling="no" frameborder="0"></iframe>';
return html;
}
})(window.tinymce);