Vés al contingut

Usuari:Anskar/scripts/operadors.js

De la Viquipèdia, l'enciclopèdia lliure

Nota: Després de desar, heu de netejar la memòria cau del navegador per veure els canvis. En la majoria de navegadors amb Windows o Linux, premeu Ctrl+F5 o bé premeu Shift i cliqueu el botó "Actualitza" (Ctrl i "Actualitza" amb Internet Explorer). Vegeu més informació i instruccions per a cada navegador a Viquipèdia:Neteja de la memòria cau.

//<pre><nowiki>
//Personalizada por Axxgreazz, para el [[w:es:User:Axxgreazz/Monobook-Suite]]
//http://es.wikipedia.org/wiki/Usuario:Axxgreazz/Monobook-Suite

/*****************Texto seleccionado******************************/

function inclou_operador (inici, fi)
{
   var txtàrea = document.editform.wpTextbox1;
   // IE
   if(document.selection  && !is_gecko) 
   {    var laSelecció = document.selection.createRange().text;
        if(!laSelecció) { laSelecció="";}
        txtàrea.focus();
        if(laSelecció.charAt(laSelecció.length - 1) == " ")
        {// exclude ending space char
                laSelecció = laSelecció.substring(0, laSelecció.length - 1);
		document.selection.createRange().text = inici + laSelecció + fi + " ";
        } 
        else {	document.selection.createRange().text = inici + laSelecció + fi;
             }
   } 
   //Mozilla
   else if(txtàrea.selectionStart || txtàrea.selectionStart == '0') 
     {
 		var PosInicial = txtàrea.selectionStart;
		var PosFinal = txtàrea.selectionEnd;
		var scrollTop=txtàrea.scrollTop;
		var TextMeu = (txtàrea.value).substring(PosInicial, PosFinal);
		if(!TextMeu) { TextMeu="";}
		if(TextMeu.charAt(TextMeu.length - 1) == " "){ // exclude ending space char, if any
			subst = inici + TextMeu.substring(0, (TextMeu.length - 1)) + fi + " ";
		} else {
			subst = inici + TextMeu + fi;
		}
		txtàrea.value = txtàrea.value.substring(0, PosInicial) + subst +
		  txtàrea.value.substring(PosFinal, txtàrea.value.length);
		txtàrea.focus();

		var cPos=PosInicial+subst.length;
		txtàrea.selectionStart=cPos;
		txtàrea.selectionEnd=cPos;
		txtàrea.scrollTop=scrollTop;
      } //altres navegadors
        else {
		var copy_alertText=alertText;
		var re1=new RegExp("\\$1","g");
		var re2=new RegExp("\\$2","g");
		copy_alertText=copy_alertText.replace(re1,"xyz");
		copy_alertText=copy_alertText.replace(re2,fn("xyz"));
		var text;
		if (sampleText) {
			text=prompt(copy_alertText);
		} else {
			text="";
		}
		if(!text) { text="xyz";}
		text=inici + text + fi;
		document.infoform.infobox.value=text;
		// in Safari this causes scrolling
		if(!is_safari) {
			txtàrea.focus();
		}
		noOverwrite=true;
	}

   if (txtàrea.createTextRange) 
     { txtàrea.caretPos = document.selection.createRange().duplicate();}
}

function text_seleccionat ()
{
   var txtàrea = document.editform.wpTextbox1;
   // IE
   if(document.selection  && !is_gecko) 
   {    var laSelecció = document.selection.createRange().text;
        if(laSelecció.length == 0)
        {  return false;}
        else 
        {  return true;}
   } 
   //Mozilla
   else 
       if(txtàrea.selectionStart || txtàrea.selectionStart == '0') 
       {
           if (txtàrea.selectionStart==txtàrea.selectionEnd)
           {  return false;}
           else 
           {  return true;}
       } 
       else
           {
               var copy_alertText=alertText;
               var re1=new RegExp("\\$1","g");
               var re2=new RegExp("\\$2","g");
               if (re1==re2)
               {  return false;}
               else 
               {  return true;}
	   }	
}

function text_seleccionat2 ()
{
   var txtàrea = document.editform.wpTextbox1;
   // IE
   if(document.selection  && !is_gecko) 
   {    var laSelecció = document.selection.createRange().text;
        return laSelecció;
   } 
   //Mozilla
   else 
       if(txtàrea.selectionStart || txtàrea.selectionStart == '0') 
       {  var PosInicial = txtàrea.selectionStart;
          var PosFinal = txtàrea.selectionEnd;
	  var scrollTop=txtàrea.scrollTop;
	  var TextMeu = (txtàrea.value).substring(PosInicial, PosFinal);
          if(!TextMeu) { TextMeu="";}
          if(TextMeu.charAt(TextMeu.length - 1) == " ")
          {  return TextMeu.substring(0, (TextMeu.length - 1));}
          else 
          {  return TextMeu;}
       } 
       else
           {
               var copy_alertText=alertText;
		var re1=new RegExp("\\$1","g");
		var re2=new RegExp("\\$2","g");
		copy_alertText=copy_alertText.replace(re1,"xyz");
		copy_alertText=copy_alertText.replace(re2,fn("xyz"));
		var text;
		if (sampleText) {
			text=prompt(copy_alertText);
		} else {
			text="";
		}
                return text;
	   }	
}

function insertTags2 (tagOpen, tagClose, sampleText) {
	if (document.editform)
		var txtarea = document.editform.wpTextbox1;
	else {
		// some alternate form? take the first one we can find
		var areas = document.getElementsByTagName('textarea');
		var txtarea = areas[0];
	}

	// IE
	if (document.selection  && !is_gecko) {
		var theSelection = document.selection.createRange().text;
		if (!theSelection)
			theSelection=sampleText;
		txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") { // exclude ending space char, if any
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
		var replaced = false;
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		if (endPos-startPos)
			replaced = true;
		var scrollTop = txtarea.scrollTop;
		var myText = (txtarea.value).substring(startPos, endPos);
		if (!myText)
			myText=sampleText;
		if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
		} else {
			subst = tagOpen + myText + tagClose;
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst +
			txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();
/*
		//set new selection
		if (replaced) {
			var cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
			txtarea.selectionStart = cPos;
			txtarea.selectionEnd = cPos;
		} else {
			txtarea.selectionStart = startPos+tagOpen.length;
			txtarea.selectionEnd = startPos+tagOpen.length+myText.length;
		}
		txtarea.scrollTop = scrollTop;
*/
	// All other browsers get no toolbar.
	// There was previously support for a crippled "help"
	// bar, but that caused more problems than it solved.
	}
	// reposition cursor if possible
	if (txtarea.createTextRange)
		txtarea.caretPos = document.selection.createRange().duplicate();
}

//</nowiki></pre>