Utente:Samuele Papa/common.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Samuele Papa (discussione | contributi)
m small typo
updated TemplateScript usage
Riga 15:
*/
//Glboalizing the object, in order to use it from the console
var pathoglobal;
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
//console.log(pathoschild);
pathoglobal=pathoschild;
 
/**
* Add a template to a button box fixed to the bottom of the page. This implementation ignores the 'category' field.
Line 45 ⟶ 46:
.appendTo(bar);
});
 
/**
* Aggiunge il template di benvenuto alla fine della pagina. Scrive come oggetto 'Benvenuto!'
* Agisce solo nelle pagine con namespace=3, come quelle di discussione utente
*/
pathoschild.TemplateScript.add([
{ name: 'Benvenuto', template: '\{\{Benvenuto\}\} \~\~\~\~', position: 'after', editSummary: 'Benvenuto!', forNamespaces: 3,'discussioni forActions: 'editutente', renderer: 'buttonbox' },
// add your own templates or scripts here
{ name: 'Benvenuto', template: '\{\{Benvenuto\}\} \~\~\~\~', position: 'after', editSummary: 'Benvenuto!', forNamespaces: 3, forActions: 'edit', renderer: 'buttonbox' },
]);
 
/**
* Aggiunge un link sulla toolbar per vedere il contesto in console
*/
pathoschild.TemplateScript.add({
name:'Debugger',
script: function(contexteditor){
console.log(contexteditor);
}
});
 
/**
* Sposta tutte le note a pie di pagina sostituendole con i marcatori posti lungo il testo
*
*
**/
pathoschild.TemplateScript.add({
name:"spostamento note",
script: function(contexteditor) {
var val =editbox editor.valget();
if (val.indexOf("<sup>nota</sup>") === -1) { // note in posizione regolare
var editbox = context.$target;
var val=editbox.val();
if (val.indexOf("<sup>nota</sup>") == -1) { // note in posizione regolare
lista = produciLista(val, "<ref", "</ref>", 1);
lista = jQuery.grep(lista, function (n, i) {
Riga 79:
});
for (i = 0; i < lista.length; i += 1) {
editor
editbox.val(val.replace(lista[i], "<sup>nota</sup>"));
editbox .valreplace(editbox.val() + "\n" + lista[i], "<sup>nota</sup>");
.append('\n' + lista[i]);
}
} else { //presenza di marcatori
marks = count(val, "<ref>") + count(val, "<ref name=") + count(val, "<ref group=");
refs = count(val, "<sup>nota</sup>");
if (marks != refs) { // verifica parità
alert("ATTENZIONE: discordanza fra numero dei <br />segnaposti (" + marks + ") e numero delle note (" + refs + "). Controllare!");
return;
Line 93 ⟶ 94:
return (n.indexOf('<ref follow=') == -1);
});
editbox.val( valeditor.replace(/\n<ref/g, "<ref"));
for (i = 0; i < lista.length; i += 1) {
editbox.val(editbox.val()editor.replace(lista[i], "").replace("<sup>nota</sup>", lista[i]));
}
}
Line 104 ⟶ 105:
forNamespaces: [108],
renderer: 'buttonbox',
script: function(contexteditor){
context.helpereditor.replace('cioe','cioè');
}
});