MediaWiki:Gadget-EoMagicalConversion.js/dev

From Wikimedia Commons, the free media repository
Jump to: navigation, search

/* Esperanto conversion script to emulate mediawiki's esperanto x-coding. http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/languages/classes/LanguageEo.php?view=co&content-type=text%2Fplain

To do:

  • remove loop detectors (if safe)
  • test test
  • /

var $boxes;

if(wgAction == 'edit' || wgAction == 'submit' || wgCanonicalSpecialPageName == 'Upload') $j(document).ready(esperantoHandlers);

function esperantoHandlers() {


$boxes = $j('#wpTextbox1, #wpUploadDescription');

//Immidiately $boxes.each(function (){ var text = $j(this).val(); text = text.replace(/Cx/g, 'C!x') .replace(/cx/g, 'c!x') .replace(/Gx/g, 'G!x') .replace(/gx/g, 'g!x') .replace(/Hx/g, 'H!x') .replace(/hx/g, 'h!x') .replace(/Jx/g, 'J!x') .replace(/jx/g, 'j!x') .replace(/Sx/g, 'S!x') .replace(/sx/g, 's!x') .replace(/Ux/g, 'U!x') .replace(/ux/g, 'u!x'); $j(this).val(text); });

//On Change $boxes.change(function (){ var text = $j(this).val(); text = text.replace(/Cx/g, 'Ĉ') .replace(/cx/g, 'ĉ') .replace(/Gx/g, 'Ĝ') .replace(/gx/g, 'ĝ') .replace(/Hx/g, 'Ĥ') .replace(/hx/g, 'ĥ') .replace(/Jx/g, 'Ĵ') .replace(/jx/g, 'ĵ') .replace(/Sx/g, 'Ŝ') .replace(/sx/g, 'ŝ') .replace(/Ux/g, 'Ŭ') .replace(/ux/g, 'ŭ'); $j(this).val(text); });

//On Submit $j('#wpSave , #wpPreview, #wpDiff, #wpUpload').click(function (){ alert('Clicked'); $boxes.unbind('change'); $boxes.each(function (){ var text = $j(this).val(); text = text.replace(/C!x/g, 'Cx') .replace(/c!x/g, 'cx') .replace(/G!x/g, 'Gx') .replace(/g!x/g, 'gx') .replace(/H!x/g, 'Hx') .replace(/h!x/g, 'hx') .replace(/J!x/g,'Jx') .replace(/j!x/g,'jx') .replace(/S!x/g,'Sx') .replace(/s!x/g,'sx') .replace(/U!x/g,'Ux') .replace(/u!x/g,'ux'); $j(this).val(text); });


}); }