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

Contenuto cancellato Contenuto aggiunto
fix vari
Conversione a OOUI e fix vari
Riga 2:
* Considera il testo selezionato come il titolo di una voce straniera, e lo
* trasforma nel titolo dell'equivalente voce italiana
*
* Autore : [[:it:User:Jalo]]
*
* Lo script contiene funzioni (showDialog e keypress) derivate da:
* http://it.wikipedia.org/w/index.php?title=MediaWiki:Gadget-tb-base.js&oldid=66478020
* scritto da [[:it:User:Rotpunkt]]
*/
 
/* global mediaWiki, jQuery, OO */
( function( mw, $ ) {
'use strict';
 
var optDialog;
 
/**
Riga 29 ⟶ 25:
}
 
/**
// Show the dialog in order to ask for the template parameters.
* Basato su [[Special:Permalink/109422525]] e gli esempi su mw.org
function showDialog( data, page ) {
*/
var lingue = getLingue(),
function showDialog() {
$dialog = $( '#gtb-dialog' ).html( "Inserire l'elenco delle lingue da utilizzare per il tool TradLink" ),
if ( optDialog ) {
$fieldset = $( '<fieldset>' ).css( 'border-color', 'gray' ).appendTo( $dialog );
windowManager.openWindow( optDialog );
return;
}
 
mw.util.addCSS( '.tradlinks-buttons { width: 100%; text-align: center; margin-top: 10px }' );
$( '<legend>' ).text( "Elenco" ).appendTo( $fieldset );
function OptDialog( config ) {
var count = 1;
OptDialog.parent.call( this, config );
lingue.forEach( function( val, id ) {
}
$( '<label>' )
OO.inheritClass( OptDialog, OO.ui.Dialog );
.attr( 'for', id )
OptDialog.static.name = 'optDialog';
.text( "Alt+" + count + ': ' )
OptDialog.static.title = 'Configurazione del tool TradLink'; // XXX
.appendTo( $fieldset );
OptDialog.prototype.initialize = function () {
var $input = $( '<input/>' )
.attr(var 'id',self id= )this;
OptDialog.parent.prototype.initialize.call( this );
.attr( 'type', 'text' )
this.attr(fields 'size',= 3 )[];
var lingue = getLingue();
.attr( 'value', ( val || '' ) );
var count = 1;
$fieldset
lingue.appendforEach( $inputfunction( val ) {
var input = new OO.ui.TextInputWidget( {
.append( '<br/>' );
value: val || '',
count++;
maxLength: 3
} );
} );
// show the dialog
var buttonsfield = {},new OO.ui.FieldLayout(
OKText = 'OK' input,
{
cancelText = 'Cancel';
label: 'Alt+' + count + ':',
align: 'left'
}
);
self.fields.push( field );
count++;
} );
var fieldsetLayout = new OO.ui.FieldsetLayout( {
items: this.fields,
label: 'Elenco delle lingue da utilizzare per il tool TradLink'
} );
 
function submitHandler() {
buttons[ OKText ] = function() {
var lingue = ''[];
$dialog self.find( 'input:text' )fields.eachforEach( function( f ) {
lingue += $.push( this )f.valfieldWidget.getValue().trim() );
} );
var d = new Date();
d.setTime( d.getTime() + ( 20 * 365 * 24 * 60 * 60 * 1000 ) ); // 20 years
var expires = "expires=" + d.toUTCString();
document.cookie = "tradLinkLangs=" + lingue.join() + "; " + expires;
optDialog.close();
}
 
var submitButton = new OO.ui.ButtonWidget(
{ label: 'Imposta' }
).on( 'click', submitHandler );
var cancelButton = new OO.ui.ButtonWidget(
{ label: 'Annulla' }
).on( 'click', function () { optDialog.close(); } );
 
var buttonsLayout = new OO.ui.HorizontalLayout( {
items: [ submitButton, cancelButton ],
classes: [ 'tradlinks-buttons' ]
} );
 
var d = new Date();
this.panelLayout = new OO.ui.PanelLayout( { padded: true, expanded: false } );
d.setTime( d.getTime() + ( 20 * 365 * 24 * 60 * 60 * 1000 ) ); // 20 years
this.panelLayout.$element.append( fieldsetLayout.$element, buttonsLayout.$element );
var expires = "expires=" + d.toUTCString();
this.$body.append( this.panelLayout.$element );
document.cookie = "tradLinkLangs=" + lingue + "; " + expires;
$( this ).dialog( 'close' );
};
buttons[ cancelText ]OptDialog.prototype.getBodyHeight = function () {
$(return this ).dialogpanelLayout.$element.outerHeight( 'close'true );
};
optDialog = new OptDialog( {
$dialog.dialog( {
size: 'small'
title: "Configurazione del tool TradLink",
width: 300,
resizable: false,
modal: true,
zIndex: 10000,
buttons: buttons
} );
windowManager = new OO.ui.WindowManager();
$( 'body' ).append( windowManager.$element );
windowManager.addWindows( [ optDialog ] );
windowManager.openWindow( optDialog );
}
 
/**
* @return {array} Di codici lingua
*/
function getLingue() {
var value = "",
Riga 98 ⟶ 128:
}
 
/**
* Routine principale
* @param {string} cod Codice lingua
*/
function tradLink( cod ) {
var lingue = getLingue();
Riga 148 ⟶ 182:
if ( event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey ) {
if ( event.which === 48 ) {
mw.loader.using( [ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows', 'mediawiki.widgets' ] )
// configure
showDialog .done( showDialog );
.fail( function() { console.error( 'Errore configurazione tradLink' ); } );
event.preventDefault();
} else if ( event.which >= 49 && event.which < 57 ) {