Wikisource:La fabbrica dei giocattoli/Toy bibbia.js

/*

== bibbia3 ==
*/
 
function bibbia3(){
       var editbox = document.getElementsByName('wpTextbox1')[0];
       var testo=editbox.value;
       // Cattura elementi BibLink da OCR grezzo
       patt2=/(\w+)\s*\.\s*(\d+)\s*\.\s*(\d+)/;
       while (patt2.test(testo)) {
           elemento=patt2.exec(testo)[0]; // elemento Biblink
           newElemento=elemento.replace(patt2,"{{BibLink|$1|$2|$3}}");
           testo=testo.replace(elemento,newElemento);
       }
       // normalizzazione del contenuto dei template BibLink (sostituzione punti con |)
       var lista=produciLista(testo,"{{BibLink|","}}",1);
       var patt1=/(\{\{BibLink\|\d*\s*\w+)[\.\| ]*(\d+)[\.\| ]*(\d+)[\.\| ]*(.*\}\})/;
       for (i=0; i<lista.length;i+=1) {
            elemento1=lista[i];
            elemento2=lista[i].replace(patt1,"$1|$2|$3|$4").replace("|}}","}}"); 
            testo=testo.replace(elemento1,elemento2);
            }
       // Cattura di eventuali numeri d'ordine del libro (1,2,3)
       patt3=/([123]\ )(\{\{BibLink\|)(\w+)/;
       while (patt3.test(testo)) {
          elemento=patt3.exec(testo)[0];
          newElemento=elemento.replace(patt3, "$2$1$3");
          testo=testo.replace(elemento, newElemento);
       }
       editbox.value = testo;
       return;
}
 
/*
 
== bibbia4 ==
*/
function bibbia4(){
       var editbox = document.getElementsByName('wpTextbox1')[0];
       var testo=editbox.value;
       var note=produciLista(testo,"\n{{BibLink|","\n",1);
 
       for (i=0; i<lista.length;i+=1) {
            riga=lista[i].trim()
            testo=testo.replace(lista[i],"\n<ref>"+riga+"</ref>\n");
            }
       editbox.value = testo;
       return;
}
/* cerca le evenienze {{BibLink|xxx|999|999}}; 77. 88. e le trasforma in {{BibLink|xxx|999|999}}; {{BibLink|xxx|77|88|77. 88}}.;
   cerca le evenienze {{BibLink|xxx|999|999}}, 77 e le trasforma in {{BibLink|xxx|999|999}}, {{BibLink|xxx|999|77|77}}.
ìP*/
/*
 
== bibbia5 ==
*/
function bibbia5(){
       var editbox = document.getElementsByName('wpTextbox1')[0];
       var testo=editbox.value;
       //  pattern di un elemento tipo 2 CORRETTO
       patt=/(\{\{BibLink\|\d?\ ?\w*\|).{1,10}(\}\});\s*(\d+)\.\s*(\d+)\./; 
       ps=/\{\{.+\}\}/;
       while (patt.test(testo))
          {
          elemento=patt.exec(testo)[0]; // elemento Biblink; capitolo. versetto 
          newElemento=elemento.replace(patt,elemento.match(ps)[0]+"; $1$3|$4|$3. $4$2");
          testo=testo.replace(elemento,newElemento);
          }
       // elemento Biblink, versetto (lista o intervallo)
       patt=/(\{\{BibLink\|\d?\ ?\w*\|\d+\|)(\d+)(\}\})\s*(-)\s*(\d+)/;
       while (patt.test(testo))
          {
          elemento=patt.exec(testo)[0];       
          newElemento=elemento.replace(patt,elemento.match(ps)[0]+"$4$1$5|$5$3");
          testo=testo.replace(elemento,newElemento);
          }
       patt=/(\{\{BibLink\|\d?\ ?\w*\|\d+\|)(\d+)(\}\})\s*(,)\s*(\d+)/;
       while (patt.test(testo))
          {
          elemento=patt.exec(testo)[0];       
          newElemento=elemento.replace(patt,elemento.match(ps)[0]+"$4 $1$5|$5$3");
          testo=testo.replace(elemento,newElemento);
          }
       editbox.value=testo;
}
// AltraColonna
function altraColonna() {
var t=selection();
if (t[1]!="") {alert("Il tool va lanciato senza selezionare alcun testo,\nma solo posizionando il cursore nel punto di inserimento di AltraColonna"); return;}
t[0]=t[0].replace(/\{\{altracolonna\}\}/i,"");
t[2]=t[2].replace(/\{\{altracolonna\}\}/i,"");
// caso AltraColonna in riga vuota
if (t[0].charAt(t[0].length-1)=="\n" && t[2].charAt(0)=="\n") {scriviBox(t[0]+"{{AltraColonna}}"+t[2]); return;}
// caso AltraColonna a fine parola
if (t[2].charAt(0)==" ") {t[0]+=" ";t[2]=t[2].substring(1);}
if (t[0].charAt(t[0].length-1)==" ") {scriviBox(t[0]+"{{AltraColonna}}"+t[2]); return;}
 
// caso AltraColonna a metà parola
if (/[A-z]$/.test(t[0]) && /^[A-z]/.test(t[2])) {
inizioParola=t[0].lastIndexOf(" ")+1; inizioP=t[0].substring(inizioParola);
fineParola=t[2].indexOf(" ");fineP=t[2].substring(0,fineParola);
t[0]=t[0].substring(0,inizioParola)+ "{{Pt|#|}}".replace("#",inizioP+"-");
t[2]="{{Pt|#|§}}".replace("#",fineP).replace("§",inizioP+fineP)+t[2].substring(fineParola);
scriviBox(t[0]+"{{AltraColonna}}"+t[2]); return;
   } 
}

function bibbia6() {
var t=selection();
t[1]="{{Centrato|{{smaller|''"+t[1]+"''}}}}";
scriviBox(t.join(""));
}
function verificaNote () {
   serie="a,b,c,d,e,f,g,h,i,k,l,m,n,o,p,q,r,s,t,u,v,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh,ii,ll,mm".split(",");
   var editbox = document.getElementsByName('wpTextbox1')[0];
   var testo=editbox.value;
   n=testo.count("<sup>");
   alert("Ultima nota: "+serie[n-1]);
}
/****************/
/* Tastini personali */
/* Bl */
if ( typeof $j != 'undefined' && typeof $.fn.wikiEditor != 'undefined' ) {$( function() {
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'advanced',
      'group': 'format',
      'tools': {'BibLink': {
          label: 'BibLink',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/1/1c/Comillas_angulares.png',
          action: {type: 'encapsulate',
            options: { pre: "{{BibLink|",  post: "}}"
}}}}});});}

 
/* punto nota */
if ( typeof $j != 'undefined' && typeof $.fn.wikiEditor != 'undefined' ) {$( function() {
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'advanced',
      'group': 'format',
      'tools': {'punto nota': {
          label: '',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/c/c4/Button_ref.png',
          action: {type: 'encapsulate',
            options: { pre: "<sup>nota</sup>",  post: ""
}}}}});});}
/*
  • /