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();
var msgEdit = 'Inserire l\'oggetto per l\'edit di cancellazione.\n' +▼
/**
$( document ).ready( function () {▼
* Cancella una sezione della pagina corrente.
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {▼
*/
function removeSection( section, summary ) {
api.postWithEditToken( {
action: 'edit',
$( '#wpTextbox1' ).val( '' );▼
format: 'json',
$( '#wpSummary' ).val( function ( i, text ) {▼
title: mw.config.get( 'wgPageName' ),
section: section,
summary: summary
} ).done ( function ( data ) {
___location.reload();
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' } )
$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() {
if ( summary.length === 0 ) {
alert( 'L\'oggetto è obbligatorio.' );
$label.text( 'Cancellazione in corso...' );
$inputText.replaceWith( $.createSpinner( { size: 'large', type: 'block' } ).css( 'margin', '10px' ) );
removeSection( section, summary );
}
},
'Annulla': function () {
}
}
}
}
$( 'span.mw-editsection > a:not( .mw-editsection-visualeditor )' ).each( function () {▼
▲ if
section = $( this ).attr( 'title' ).split( 'Modifica la sezione ' )[1];▼
▲ $( 'span.mw-editsection > a:
▲ $( '<a>' )
var $link, sectiontitle ;
$link = $( '<a>' )
.attr( 'href', '#' )
.attr( 'title', 'Cancella la sezione ' +
.text(
.click( function ( event ) {
mw.loader.using( [ 'mediawiki.api.edit', 'jquery.ui.dialog', 'jquery.spinner' ], function () {
▲ var summary = prompt( msgEdit.replace( '$1', section ) );
} );
return false;
▲ } )
▲ $( this ).after( '<span style="color: #555;"> | </span>' );
} );
}
|