Utente:Ricordisamoa/RimuoviTemplateO.js: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Contenuto cancellato Contenuto aggiunto
m ora non agisce nel namespace "Template:" |
nuovissima versione: migliorata compatibilità con il template O, aggiunte animazioni e gestione degli errori |
||
Riga 5: | Riga 5: | ||
*/ |
*/ |
||
$(document).ready(function(){ |
$(document).ready(function(){ |
||
if(mw.config.get('wgAction') === 'view' |
|||
if(wgAction==="view"&&wgPageName!="Utente:Ricordisamoa/RimuoviTemplateO"&&wgNamespaceNumber!=10){// in modalità 'view' |
|||
&& mw.config.get('wgPageName') !== 'Utente:Ricordisamoa/RimuoviTemplateO' |
|||
var post=""; |
|||
&& mw.config.get('wgNamespaceNumber') !== 10){ |
|||
$("div").filter(function(){ |
|||
$('div').each(function(){ |
|||
if($(this).text()==="Inseriscine almeno uno pertinente e non generico e rimuovi l'avviso."){ |
|||
$(this) |
|||
return true; |
|||
.contents() |
|||
.filter(function(){ |
|||
else if($(this).text()==="Inseriscine almeno uno pertinente e non generico e rimuovi l'avviso. Segui i suggerimenti del progetto di riferimento."){ |
|||
return this.nodeType === 3; |
|||
return true; |
|||
} |
|||
else return false; |
|||
}) |
|||
.empty() |
|||
.text("Inseriscine almeno uno pertinente e non generico e ") |
|||
.append( |
|||
$("<a>") |
|||
.text("rimuovi") |
|||
.attr({ |
|||
href:"#", |
|||
title:"Rimuovi questo avviso automaticamente" |
|||
}) |
}) |
||
. |
.each(function(){ |
||
var parts = ['almeno uno pertinente e non generico e ', 'rimuovi', ' l\'avviso'], |
|||
event.preventDefault(); |
|||
find = this.textContent.indexOf(parts.join('')); |
|||
$.get( |
|||
if(find !== -1){ |
|||
mw.util.wikiScript(), |
|||
var node = this.splitText(find + parts[0].length); |
|||
{title:wgPageName,action:"raw"} |
|||
$(node.splitText(parts[1].length).previousSibling) |
|||
) |
|||
. |
.wrap('<a>').parent() |
||
.attr({ |
|||
href: '#', |
|||
title: 'Rimuovi questo avviso automaticamente' |
|||
{ |
|||
action:"edit", |
|||
text:d.replace(/\{\{o(\|[^\{\}]+)*\}\}\n?/i,""), |
|||
title:wgPageName, |
|||
summary:"[[Utente:Ricordisamoa/RimuoviTemplateO|RimuoviTemplateO.js]]: rimozione di {{[[Template:O|O]]}}"+ |
|||
" (controlla i [[Speciale:PuntanoQui/"+wgPageName+"|collegamenti in entrata]])", |
|||
token:mw.user.tokens.get("editToken") |
|||
} |
|||
) |
|||
.done(function(data){ |
|||
if(data.error&&data.error.info) jsMsg("RimuoviTemplateO.js - Errore:<br/>"+data.error.info); |
|||
else{ |
|||
jsMsg("RimuoviTemplateO.js:<br/>Template rimosso!"); |
|||
setTimeout(function(){document.location.reload();},2500); |
|||
} |
|||
}) |
}) |
||
. |
.click(function(event){ |
||
event.preventDefault(); |
|||
jsMsg("RimuoviTemplateO.js:<br/>La richiesta ajax è fallita."); |
|||
var $container = $(this).parents('table.avviso'); |
|||
$(this).replaceWith($(this).text()); |
|||
mw.loader.using('jquery.spinner', function(){ |
|||
$container |
|||
.find('td.avviso-immagine img').slideUp({}, function(){ |
|||
$(this).parents('td').hide(); |
|||
}) |
|||
.parents('td') |
|||
.next('td.avviso-testo') |
|||
.animate({ |
|||
opacity: .5 |
|||
}, 500) |
|||
.append($.createSpinner({ |
|||
size: 'large', |
|||
type: 'block' |
|||
})); |
|||
var fail = function(){ |
|||
mw.notify('RimuoviTemplateO.js:\nla richiesta ajax è fallita.'); |
|||
$container |
|||
.find('td.avviso-immagine').show() |
|||
.find('img').stop().show().end() |
|||
.next('td.avviso-testo') |
|||
.stop().css('opacity', 1) |
|||
.find('.mw-spinner').remove(); |
|||
}; |
|||
$.get( |
|||
mw.util.wikiScript(), |
|||
{ |
|||
title: mw.config.get('wgPageName'), |
|||
action: 'raw' |
|||
} |
|||
) |
|||
.done(function(d){ |
|||
new mw.Api().postWithToken('edit', { |
|||
action: 'edit', |
|||
format: 'json', |
|||
text: d.replace(/\{\{o(\|[^\{\}]+)*\}\}\n?/i, ''), |
|||
title: mw.config.get('wgPageName'), |
|||
summary: 'rimozione [[Utente:Ricordisamoa/RimuoviTemplateO|automatica]] di {{[[Template:O|O]]}}' + |
|||
' (controlla i [[Speciale:PuntanoQui/' + mw.config.get('wgPageName') + '|collegamenti in entrata]])', |
|||
}) |
|||
.done(function(){ |
|||
$container.animate({ |
|||
opacity: 0 |
|||
}, 500, function(){ |
|||
$(this).remove(); |
|||
}); |
|||
}) |
|||
.fail(fail); |
|||
}) |
|||
.fail(fail); |
|||
}); |
|||
}); |
}); |
||
return false; |
|||
} |
} |
||
) |
}); |
||
}); |
|||
.append(" l'avviso.") |
|||
.append(post==""?"":" Segui i suggerimenti del ") |
|||
.append(post) |
|||
.append(post==""?"":"."); |
|||
} |
} |
||
}); |
}); |
||
/* </nowiki> */ |
Versione delle 19:01, 24 apr 2014
/* <nowiki>
* RimuoviTemplateO.js di [[Utente:Ricordisamoa]]
* usa jQuery & Ajax
* sostituisce "rimuovi" nel Template:O con un link per rimuovere il template rapidamente
*/
$(document).ready(function(){
if(mw.config.get('wgAction') === 'view'
&& mw.config.get('wgPageName') !== 'Utente:Ricordisamoa/RimuoviTemplateO'
&& mw.config.get('wgNamespaceNumber') !== 10){
$('div').each(function(){
$(this)
.contents()
.filter(function(){
return this.nodeType === 3;
})
.each(function(){
var parts = ['almeno uno pertinente e non generico e ', 'rimuovi', ' l\'avviso'],
find = this.textContent.indexOf(parts.join(''));
if(find !== -1){
var node = this.splitText(find + parts[0].length);
$(node.splitText(parts[1].length).previousSibling)
.wrap('<a>').parent()
.attr({
href: '#',
title: 'Rimuovi questo avviso automaticamente'
})
.click(function(event){
event.preventDefault();
var $container = $(this).parents('table.avviso');
$(this).replaceWith($(this).text());
mw.loader.using('jquery.spinner', function(){
$container
.find('td.avviso-immagine img').slideUp({}, function(){
$(this).parents('td').hide();
})
.parents('td')
.next('td.avviso-testo')
.animate({
opacity: .5
}, 500)
.append($.createSpinner({
size: 'large',
type: 'block'
}));
var fail = function(){
mw.notify('RimuoviTemplateO.js:\nla richiesta ajax è fallita.');
$container
.find('td.avviso-immagine').show()
.find('img').stop().show().end()
.next('td.avviso-testo')
.stop().css('opacity', 1)
.find('.mw-spinner').remove();
};
$.get(
mw.util.wikiScript(),
{
title: mw.config.get('wgPageName'),
action: 'raw'
}
)
.done(function(d){
new mw.Api().postWithToken('edit', {
action: 'edit',
format: 'json',
text: d.replace(/\{\{o(\|[^\{\}]+)*\}\}\n?/i, ''),
title: mw.config.get('wgPageName'),
summary: 'rimozione [[Utente:Ricordisamoa/RimuoviTemplateO|automatica]] di {{[[Template:O|O]]}}' +
' (controlla i [[Speciale:PuntanoQui/' + mw.config.get('wgPageName') + '|collegamenti in entrata]])',
})
.done(function(){
$container.animate({
opacity: 0
}, 500, function(){
$(this).remove();
});
})
.fail(fail);
})
.fail(fail);
});
});
return false;
}
});
});
}
});