MediaWiki:Gadget-DeleteSection.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiunti spazi parentesi, tab, jslint=>jshint per mw:Manual:Coding conventions/JavaScript
aggiornato all'uso di jquery dialog e mediawiki API
Riga 14:
'use strict';
 
var $dialog, api = new mw.Api();
// Messaggio di richiesta dell'oggetto della modifica
var msgEdit = 'Inserire l\'oggetto per l\'edit di cancellazione.\n' +
'Se non viene inserito verrà usato quello standard (Sezione "$1" eliminata)';
 
/**
$( document ).ready( function () {
* Cancella una sezione della pagina corrente.
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
*/
// edit richiamato dallo script stesso per modificare la sezione
function removeSection( section, summary ) {
var gdsummary = mw.util.getParamValue( 'gdsummary' );
api.postWithEditToken( {
if ( gdsummary && $( '#wpTextbox1' ).length && $( '#wpSummary' ).length && $( '#wpSave' ).length ) {
action: 'edit',
$( '#wpTextbox1' ).val( '' );
format: 'json',
$( '#wpSummary' ).val( function ( i, text ) {
title: mw.config.get( 'wgPageName' ),
var summary = text.replace( /\/\*\s(.+)\s\*\/.*/, 'Sezione "$1" eliminata' );
section: section,
return summary + ( gdsummary === 'true' ? '' : ': ' + gdsummary );
}text: );'',
summary: summary
$( '#wpSave' ).click();
} ).done ( function ( data ) {
___location.reload();
$( '#wpSummary'} ).valfail ( function ( icode, textdata ) {
alert( 'Errore nel cancellare la sezione: ' + code );
$dialog.dialog( 'close' );
} );
}
 
/**
* Richiede il testo per l'oggetto della modifica.
*/
function showDialog( section, sectiontitle ) {
var $descr, $label, $inputText;
if ( !$dialog ) {
$dialog = $( '<div>' ).attr( 'id', 'gds-dialog' ).appendTo( 'body' );
}
$descr = $( '<p>' ).text( 'Sezione: ' + sectiontitle );
$label = $( '<label>' ).css( { display: 'block', 'margin': '10px 0 2px 0' } )
var msgEdit = .text( 'Inserire l\'oggettoOggetto per l\'edit di cancellazione.\n:' +);
$inputText = $( '<input/>' ).attr( 'type', 'text' )
.attr( 'size', 40 ).val( 'Sezione ' + sectiontitle + ' eliminata' );
$dialog.empty().append( $descr, $label, $inputText );
 
$dialog.dialog( {
title: 'Accessorio cancella sezione',
position: { my: 'center', at: 'center', of: window },
buttons: {
'Ok': function() {
var summary = prompt$.trim( msgEdit$inputText.replaceval( '$1', section ) );
if ( summary.length === 0 ) {
alert( 'L\'oggetto è obbligatorio.' );
$( } '<a>'else ){
$label.text( 'Cancellazione in corso...' );
$inputText.replaceWith( $.createSpinner( { size: 'large', type: 'block' } ).css( 'margin', '10px' ) );
removeSection( section, summary );
}
},
'Annulla': function () {
$( '#wpTextbox1'this ).valdialog( 'close' );
}
}
} else {);
}
$( 'span.mw-editsection > a:not( .mw-editsection-visualeditor )' ).each( function () {
 
var url, section;
$( document ).ready( function () {
url = $( this ).attr( 'href' );
if ( $.inArray( mw.config.get( 'wgAction' ), [=== 'editview', && mw.config.get( 'submitwgNamespaceNumber'] ) !% 2 === -10 ) {
section = $( this ).attr( 'title' ).split( 'Modifica la sezione ' )[1];
$( 'span.mw-editsection > a:not( .mwlast-editsectionof-visualeditor )type' ).each( function ( i, el ) {
$( '<a>' )
var $link, sectiontitle ;
sectionsectiontitle = $( thisel ).attr( 'title' ).split( 'Modifica la sezione ' )[1];
$link = $( '<a>' )
.attr( 'href', '#' )
.attr( 'title', 'Cancella la sezione ' + sectionsectiontitle )
.text( "'cancella"' )
.click( function ( event ) {
mw.loader.using( [ 'mediawiki.api.edit', 'jquery.ui.dialog', 'jquery.spinner' ], function () {
var summary = prompt( msgEdit.replace( '$1', section ) );
if showDialog( summaryi !==+ null1, sectiontitle ) {;
} );
document.___location = url + '&gdsummary=' +
return false;
( summary === '' ? 'true' : summary );
} );
$( thisel ).after( '<span style="color: #555;"> | </span>', $link );
} )
.before( ' | ' ).insertAfter( this );
$( this ).after( '<span style="color: #555;"> | </span>' );
} );
}