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
*/
/* global mediaWiki, jQuery, OO */
( function( mw, $ ) {
'use strict';
var optDialog;
/**
Riga 29 ⟶ 25:
}
/**
* Basato su [[Special:Permalink/109422525]] e gli esempi su mw.org
*/
function showDialog() {
if ( optDialog ) {
windowManager.openWindow( optDialog );
return;
}
mw.util.addCSS( '.tradlinks-buttons { width: 100%; text-align: center; margin-top: 10px }' );
function OptDialog( config ) {
OptDialog.parent.call( this, config );
}
OO.inheritClass( OptDialog, OO.ui.Dialog );
OptDialog.static.name = 'optDialog';
OptDialog.static.title = 'Configurazione del tool TradLink'; // XXX
OptDialog.prototype.initialize = function () {
OptDialog.parent.prototype.initialize.call( this );
var lingue = getLingue();
var count = 1;
var input = new OO.ui.TextInputWidget( {
value: val || '',
maxLength: 3
} );
var
{
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() {
var lingue =
lingue
} );
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' ]
} );
this.panelLayout = new OO.ui.PanelLayout( { padded: true, expanded: false } );
this.panelLayout.$element.append( fieldsetLayout.$element, buttonsLayout.$element );
this.$body.append( this.panelLayout.$element );
};
};
optDialog = new OptDialog( {
size: 'small'
} );
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' ] )
.fail( function() { console.error( 'Errore configurazione tradLink' ); } );
event.preventDefault();
} else if ( event.which >= 49 && event.which < 57 ) {
| |||