MediaWiki:Gadget-BiDiEditing.js: Difference between revisions
Content deleted Content added
m 1 revision from meta:MediaWiki:Gadget-BiDiEditing.js |
Jack Phoenix (talk | contribs) stylized, JSHinted, swapped deprecated addOnloadHook to the jQuery event loading mechanism ($) |
||
Line 1: | Line 1: | ||
function bidiSwitchSetup() { |
function bidiSwitchSetup() { |
||
var editform = document.getElementById( |
var editform = document.getElementById( 'editform' ); |
||
if (editform == null) { |
if ( editform === null ) { |
||
return; |
return; |
||
} |
} |
||
bidiAddButton(editform, |
bidiAddButton( editform, 'Default', function( style ) { |
||
style.direction = |
style.direction = 'inherit'; |
||
style.unicodeBidi = |
style.unicodeBidi = 'inherit'; |
||
}); |
} ); |
||
bidiAddButton(editform, |
bidiAddButton( editform, 'dir=ltr', function( style ) { |
||
style.direction = |
style.direction = 'ltr'; |
||
}); |
} ); |
||
bidiAddButton(editform, |
bidiAddButton( editform, 'dir=rtl', function( style ) { |
||
style.direction = |
style.direction = 'rtl'; |
||
}); |
} ); |
||
bidiAddButton(editform, |
bidiAddButton( editform, 'bidi=normal', function( style ) { |
||
style.unicodeBidi = |
style.unicodeBidi = 'normal'; |
||
}); |
} ); |
||
bidiAddButton(editform, |
bidiAddButton( editform, 'bidi=override', function( style ) { |
||
style.unicodeBidi = |
style.unicodeBidi = 'bidi-override'; |
||
}); |
} ); |
||
} |
} |
||
function bidiAddButton(before, label, action) { |
function bidiAddButton( before, label, action ) { |
||
var button = document.createElement( |
var button = document.createElement( 'input' ); |
||
button.type = |
button.type = 'button'; |
||
button.value = label; |
button.value = label; |
||
button.onclick = function(event) { |
button.onclick = function( event ) { |
||
var box = document.getElementById( |
var box = document.getElementById( 'wpTextbox1' ); |
||
if (box == null) { |
if ( box === null ) { |
||
alert( |
alert( 'Broken! Edit box missing.' ); |
||
} else { |
} else { |
||
//var style = document.getOverrideStyle(box, null); |
//var style = document.getOverrideStyle(box, null); |
||
var style = box.style; |
var style = box.style; |
||
action(style); |
action( style ); |
||
} |
} |
||
} |
}; |
||
before.parentNode.insertBefore(button, before); |
before.parentNode.insertBefore( button, before ); |
||
} |
} |
||
$( bidiSwitchSetup ); |
Latest revision as of 12:23, 10 August 2015
function bidiSwitchSetup() {
var editform = document.getElementById( 'editform' );
if ( editform === null ) {
return;
}
bidiAddButton( editform, 'Default', function( style ) {
style.direction = 'inherit';
style.unicodeBidi = 'inherit';
} );
bidiAddButton( editform, 'dir=ltr', function( style ) {
style.direction = 'ltr';
} );
bidiAddButton( editform, 'dir=rtl', function( style ) {
style.direction = 'rtl';
} );
bidiAddButton( editform, 'bidi=normal', function( style ) {
style.unicodeBidi = 'normal';
} );
bidiAddButton( editform, 'bidi=override', function( style ) {
style.unicodeBidi = 'bidi-override';
} );
}
function bidiAddButton( before, label, action ) {
var button = document.createElement( 'input' );
button.type = 'button';
button.value = label;
button.onclick = function( event ) {
var box = document.getElementById( 'wpTextbox1' );
if ( box === null ) {
alert( 'Broken! Edit box missing.' );
} else {
//var style = document.getOverrideStyle(box, null);
var style = box.style;
action( style );
}
};
before.parentNode.insertBefore( button, before );
}
$( bidiSwitchSetup );