MediaWiki:Gadget-Click.js

Da Wikisource.

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
// a global variable is initialized
var activeArea = "";
 


 
// gets selecion from activeArea as a three-string list (pre,selecion,post):
 
function selezione() {
	var s = [];
	var txt = activeArea.value;
	s[0] = txt.substring(0, activeArea.selectionStart);
	s[1] = txt.substring(activeArea.selectionStart, activeArea.selectionEnd);
	s[2] = txt.substring(activeArea.selectionEnd);
	return s;
}
 
// puts the content of a three-string list as activeArea value:
 
function putSelezione(s) {
	activeArea.value = s.join("");
	activeArea.selectionStart = s[0].length;
	activeArea.selectionEnd = s[0].length + s[1].length;
}


function rotateChar() {
if (typeof(options)=="undefined") options=["aæäàâ","eêë","oœôö","uûü","nñ"];
s=selezione();
cc=s[2].substring(0,1); 
for (i=0;i<options.length;i+=1) {
   if (options[i].indexOf(cc)>-1) {
       ccp=options[i].indexOf(cc);        
       ccp+=1; 
       if (ccp==options[i].length) ccp=0;
       cc=options[i].substring(ccp,ccp+1);
       s[2]=cc+s[2].substring(1);
       putSelezione(s);
       return false;
       }
   }
}

// active area element is saved at .focusin event, so that the last input or textarea is saved:
$(document).ready(function () {
	$("textarea, input[type='text']").focus(function () {
		activeArea = this;
	}).click(function(e) {
 
  if(e.ctrlKey) {
    rotateChar();
  }
  if(e.shiftKey) {
    //alert("Event doesn't be implemented by now")
    splitRiga();
  }
  if(e.altKey) {
    alert("Event doesn't be implemented by now")
  } 
});;}
);