MediaWiki:Gadget-indentaVersi.js
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.
function scriviBox(testo, area, ss, se) {
if (area === undefined || area === "") {
if (mw.config.get('wgCanonicalNamespace') == "Page") {
area = 1;
} else {
area = 0;
}
}
$('textarea')[area].value = testo;
if (ss !== undefined && se !== undefined) {
$('textarea')[area].selectionStart = ss;
$('textarea')[area].selectionEnd = se;
}
}
function versoSpezzato() {
var t=selection();
var spazi=["{"+"{Spazi|","}}"];
if (t[0].indexOf("\n")==-1) {
t[1]=t[0]+t[1];
t[0]="";
}
else {
pn=t[0].lastIndexOf("\n");
t[1]=t[0].substring(pn+1)+t[1];
t[0]=t[0].substring(0,pn+1);
}
var t1=t[1].split("\n");
spazi[0]+=Math.ceil($.trim(t1[0]).length*1.90);
spazi=spazi.join("");
var bianchi=/[^ ]/.exec(t1[t1.length-1]).index;
t1[t1.length-1]=t1[t1.length-1].slice(0,bianchi)+spazi+t1[t1.length-1].slice(bianchi);
t[1]=t1.join("\n");
scriviBox(t.join(""),"",t[0].length,t[0].length+t[1].length);
}
function indentSelection() {
t=selection();
if (t[0].indexOf("\n")==-1) {
t[1]=t[0]+t[1];
t[0]="";
}
else {
pn=t[0].lastIndexOf("\n");
t[1]=t[0].substring(pn+1)+t[1];
t[0]=t[0].substring(0,pn+1);
}
var t1=t[1].split("\n");
for (var i=0; i<t1.length; i+=1) {
t1[i]=" "+t1[i];}
t[1]=t1.join("\n");
scriviBox(t.join(""),"",t[0].length,t[0].length+t[1].length);
$('#wpTextbox1').focus();
}
function deIndentSelection() {
t=selection();
if (t[0].indexOf("\n")==-1) {
t[1]=t[0]+t[1];
t[0]="";
}
else {
pn=t[0].lastIndexOf("\n");
t[1]=t[0].substring(pn+1)+t[1];
t[0]=t[0].substring(0,pn+1);
}
var t1=t[1].split("\n");
for (var i=0; i<t1.length; i+=1) {
for (j=0; j<5; j+=1) {
if (t1[i].substring(0,1)==" ") t1[i]=t1[i].substring(1);
else break;
}
}
t[1]=t1.join("\n");
scriviBox(t.join(""),"",t[0].length,t[0].length+t[1].length);
$('#wpTextbox1').focus();
}
/* indentaVersi() */
if ( typeof $ != 'undefined' && typeof $.fn.wikiEditor != 'undefined' ) {$( function() {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'advanced',
'group': 'format',
'tools': {'section': {
label: 'Indenta i versi selezionati [alt-shift-y]',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/2/25/Btn_toolbar_indent_more.png',
action: {type: 'callback',
execute: function(context){indentSelection();}
}
}}});
$('[accesskey=y]').removeAttr('accesskey');
$('.wikiEditor-ui-toolbar [title="Indenta i versi selezionati [alt-shift-y]"]').attr('accesskey', 'y');
});}
/* deindentaVersi() */
if ( typeof $ != 'undefined' && typeof $.fn.wikiEditor != 'undefined' ) {$( function() {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'advanced',
'group': 'format',
'tools': {'section': {
label: 'De-indenta i versi selezionati [alt-shift-u]',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/a/ab/Btn_toolbar_indent_less.png',
action: {type: 'callback',
execute: function(context){deIndentSelection();}
}
}}});
$('[accesskey=u]').removeAttr('accesskey');
$('.wikiEditor-ui-toolbar [title="De-indenta i versi selezionati [alt-shift-u]"]').attr('accesskey', 'u');
});}
/* versoSpezzato() */
if ( typeof $ != 'undefined' && typeof $.fn.wikiEditor != 'undefined' ) {$( function() {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'advanced',
'group': 'format',
'tools': {'section': {
label: 'Indenta i versi spezzati [alt-shift-z]',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/d/d8/Btn_toolbar_indent_ulist.png',
action: {type: 'callback',
execute: function(context){versoSpezzato();}
}
}}});
$('[accesskey=u]').removeAttr('accesskey');
$('.wikiEditor-ui-toolbar [title="Indenta i versi spezzati [alt-shift-z]"]').attr('accesskey', 'z');
});}