2018-06-24 16:07:22 +03:00
|
|
|
|
/* ===========================================================
|
|
|
|
|
* trumbowyg.mathMl.js v1.0
|
|
|
|
|
* MathML plugin for Trumbowyg
|
2020-05-12 21:47:37 +03:00
|
|
|
|
* http://alex-d.github.com/Trumbowyg
|
2018-06-24 16:07:22 +03:00
|
|
|
|
* ===========================================================
|
|
|
|
|
* Author : loclamor
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* globals MathJax */
|
|
|
|
|
(function($) {
|
|
|
|
|
'use strict';
|
|
|
|
|
$.extend(true, $.trumbowyg, {
|
|
|
|
|
langs: {
|
2020-05-12 21:47:37 +03:00
|
|
|
|
// jshint camelcase:false
|
2018-06-24 16:07:22 +03:00
|
|
|
|
en: {
|
|
|
|
|
mathml: 'Insert Formulas',
|
|
|
|
|
formulas: 'Formulas',
|
|
|
|
|
inline: 'Inline'
|
|
|
|
|
},
|
2020-05-12 21:47:37 +03:00
|
|
|
|
da: {
|
|
|
|
|
mathml: 'Indsæt formler',
|
|
|
|
|
formulas: 'Formler',
|
|
|
|
|
inline: 'Inline'
|
|
|
|
|
},
|
2018-06-24 16:07:22 +03:00
|
|
|
|
fr: {
|
|
|
|
|
mathml: 'Inserer une formule',
|
|
|
|
|
formulas: 'Formule',
|
|
|
|
|
inline: 'En ligne'
|
|
|
|
|
},
|
|
|
|
|
tr: {
|
|
|
|
|
mathml: 'Formül Ekle',
|
|
|
|
|
formulas: 'Formüller',
|
|
|
|
|
inline: 'Satır içi'
|
2020-05-12 21:47:37 +03:00
|
|
|
|
},
|
|
|
|
|
zh_tw: {
|
|
|
|
|
mathml: '插入方程式',
|
|
|
|
|
formulas: '方程式',
|
|
|
|
|
inline: '內嵌'
|
|
|
|
|
},
|
|
|
|
|
pt_br: {
|
|
|
|
|
mathml: 'Inserir fórmulas',
|
|
|
|
|
formulas: 'Fórmulas',
|
|
|
|
|
inline: 'Em linha'
|
|
|
|
|
},
|
|
|
|
|
ko: {
|
|
|
|
|
mathml: '수식 넣기',
|
|
|
|
|
formulas: '수식',
|
|
|
|
|
inline: '글 안에 넣기'
|
|
|
|
|
},
|
2018-06-24 16:07:22 +03:00
|
|
|
|
},
|
2020-05-12 21:47:37 +03:00
|
|
|
|
// jshint camelcase:true
|
|
|
|
|
|
2018-06-24 16:07:22 +03:00
|
|
|
|
plugins: {
|
|
|
|
|
mathml: {
|
|
|
|
|
init: function(trumbowyg) {
|
|
|
|
|
var btnDef = {
|
|
|
|
|
fn: function() {
|
|
|
|
|
trumbowyg.saveRange();
|
|
|
|
|
var mathMLoptions = {
|
|
|
|
|
formulas: {
|
|
|
|
|
label: trumbowyg.lang.formulas,
|
|
|
|
|
required: true,
|
|
|
|
|
value: ''
|
|
|
|
|
},
|
|
|
|
|
inline: {
|
|
|
|
|
label: trumbowyg.lang.inline,
|
|
|
|
|
attributes: {
|
|
|
|
|
checked: true
|
|
|
|
|
},
|
|
|
|
|
type: 'checkbox',
|
|
|
|
|
required: false,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var mathmlCallback = function(v) {
|
2020-05-12 21:47:37 +03:00
|
|
|
|
var delimiter = v.inline ? '$' : '$$';
|
2018-06-24 16:07:22 +03:00
|
|
|
|
if (trumbowyg.currentMathNode) {
|
2020-05-12 21:47:37 +03:00
|
|
|
|
$(trumbowyg.currentMathNode)
|
|
|
|
|
.html(delimiter + ' ' + v.formulas + ' ' + delimiter)
|
|
|
|
|
.attr('formulas', v.formulas)
|
|
|
|
|
.attr('inline', (v.inline ? 'true' : 'false'));
|
2018-06-24 16:07:22 +03:00
|
|
|
|
} else {
|
2020-05-12 21:47:37 +03:00
|
|
|
|
var html = '<span class="mathMlContainer" contenteditable="false" formulas="' + v.formulas + '" inline="' + (v.inline ? 'true' : 'false') + '" >' + delimiter + ' ' + v.formulas + ' ' + delimiter + '</span>';
|
2018-06-24 16:07:22 +03:00
|
|
|
|
var node = $(html)[0];
|
2020-05-12 21:47:37 +03:00
|
|
|
|
node.onclick = function() {
|
2018-06-24 16:07:22 +03:00
|
|
|
|
trumbowyg.currentMathNode = this;
|
|
|
|
|
mathMLoptions.formulas.value = $(this).attr('formulas');
|
2020-05-12 21:47:37 +03:00
|
|
|
|
|
|
|
|
|
if ($(this).attr('inline') === 'true') {
|
2018-06-24 16:07:22 +03:00
|
|
|
|
mathMLoptions.inline.attributes.checked = true;
|
|
|
|
|
} else {
|
|
|
|
|
delete mathMLoptions.inline.attributes.checked;
|
|
|
|
|
}
|
2020-05-12 21:47:37 +03:00
|
|
|
|
|
2018-06-24 16:07:22 +03:00
|
|
|
|
trumbowyg.openModalInsert(trumbowyg.lang.mathml, mathMLoptions, mathmlCallback);
|
|
|
|
|
};
|
2020-05-12 21:47:37 +03:00
|
|
|
|
|
2018-06-24 16:07:22 +03:00
|
|
|
|
trumbowyg.range.deleteContents();
|
|
|
|
|
trumbowyg.range.insertNode(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trumbowyg.currentMathNode = false;
|
|
|
|
|
MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mathMLoptions.formulas.value = trumbowyg.getRangeText();
|
|
|
|
|
mathMLoptions.inline.attributes.checked = true;
|
|
|
|
|
trumbowyg.openModalInsert(trumbowyg.lang.mathml, mathMLoptions, mathmlCallback);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
trumbowyg.addBtnDef('mathml', btnDef);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})(jQuery);
|