User:ערן/mathjaxdialog.js: Difference between revisions
Appearance
< User:ערן
Content deleted Content added
Maintenance: mw:RL/MGU - Updated deprecated module name |
Amorymeltzer (talk | contribs) m Remove legacy globals per phab:T72470 (via WP:JWB) |
||
Line 2: | Line 2: | ||
if ($.inArray(wgAction,['edit','submit'])!=-1) mw.loader.using(['ext.wikiEditor'],function(){ |
if ($.inArray(mw.config.get('wgAction'),['edit','submit'])!=-1) mw.loader.using(['ext.wikiEditor'],function(){ |
||
function mathDialog(){ |
function mathDialog(){ |
||
mw.loader.using(['jquery.ui','ext.math.mathjax.enabler'],function(){ |
mw.loader.using(['jquery.ui','ext.math.mathjax.enabler'],function(){ |
Latest revision as of 13:59, 4 February 2021
/* Math editor based on mathJax */
if ($.inArray(mw.config.get('wgAction'),['edit','submit'])!=-1) mw.loader.using(['ext.wikiEditor'],function(){
function mathDialog(){
mw.loader.using(['jquery.ui','ext.math.mathjax.enabler'],function(){
var mathEditor=$('<div>');
var mathInput=$('<input>',{dir:'ltr'}).appendTo(mathEditor);
var mathPreview=$('<div>').appendTo(mathEditor);
mathEditor.dialog({title: 'Equation editor', buttons: {
'Insert': function(){
$("#wpTextbox1").textSelection('encapsulateSelection', {replace: true, peri: '<math>'+mathInput.val()+'</math>'});
$(this).dialog('close');
},
'Help':function(){window.open(mw.util.getUrl('Help:Math'))},
'Cancel': function(){ $(this).dialog('close');}
} });
mathInput.keyup(function(){
mathPreview.html('<span dir="ltr" class="tex">$ '+$(this).val()+' $</span>');
MathJax.Hub.Queue( ["Typeset", MathJax.Hub, mathPreview.get(0)])
});
var selection = $("#wpTextbox1").textSelection( 'getSelection' );
//insert the selected text into the equation editor
var mathRgx=/<math>(.*)<\/math>/;
if(selection && mathRgx.test(selection)){
mathInput.val(mathRgx.exec(selection)[1]);
mathInput.keyup();
}
});
}
$(function(){
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'advanced',
'group': 'insert',
'tools': {
'formula': {
label: 'Math (LaTeX)',
type: 'button',
icon: '/upwiki/wikipedia/commons/thumb/3/3e/Nuvola_apps_edu_mathematics_blue-p.svg/22px-Nuvola_apps_edu_mathematics_blue-p.svg.png',
action: {type: 'callback', execute: mathDialog }
}
}
} );
})
})