משתמש:קיפודנחש/common.js/hebeng.js

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) + 1)
mw.loader.using('jquery.textSelection' ).done( function() {
    function doit() {
		var selection = $("#wpTextbox1").textSelection('getSelection');
		var hes = ["qwertyuiop[asdfghjkl;'zxcvbnm,./", "/'קראטוןםפ]שדגכעיחלךף,זסבהנמצתץ."];
		var alt = '';
		var isEng = /[a-z]/.test(selection);
		for (var i = 0; i < selection.length; i++) {
			var c = selection[i];
			if (isEng && hes[0].indexOf(c) + 1)
				c = hes[1][hes[0].indexOf(c)];
			else if (!isEng && hes[1].indexOf(c) + 1)
				c = hes[0][hes[1].indexOf(c)];
			alt += c;
		}
		$("#wpTextbox1").textSelection('encapsulateSelection', {replace: true, peri: alt});
	}

	function addToWikiEditor() {	
		var buttonImage = '//upload.wikimedia.org/wikipedia/he/math/2/7/7/2778f20ac96041b97ed7050a7b3ff756.png';
		if (typeof $.wikiEditor != 'undefined')
			$('#wpTextbox1').wikiEditor('addToToolbar', {
				'section': 'advanced',
				'group': 'more',
				tools: {
					'hebeng': {
						label: 'שיכול מקלדת',
						type: 'button',
						icon: buttonImage,
						action: {type: 'callback', execute: doit}
					}
				}
			});
	}
    $(document).keydown(function(e) {if (e.altKey && e.shiftKey && e.keyCode == 85) { e.preventDefault(); doit();}});//alt-shift-u
	if ($('#wikiEditor-ui-toolbar').length === 1) addToWikiEditor(); //in case it loaded after toolbar initaliztion
	else $( '#wpTextbox1' ).on( 'wikiEditor-toolbar-doneInitialSections', addToWikiEditor);
});