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

Contenuto cancellato Contenuto aggiunto
fix alert
m fix
 
(13 versioni intermedie di uno stesso utente non sono mostrate)
Riga 10:
var cookieName = 'tradLinkLangs';
var windowManager, optDialog;
 
/**
* Mostra un errore relativo al dialog. Non possiamo usare OO.ui.alert() perché
* quello usa la sua window che viene messa sotto a quella del dialog.
* Codice basato sull'implementazione di OO.ui.alert()
*
* @param {string} text Messaggio di errore
*/
function showDialogError( text ) {
windowManager.openWindow( 'message', {
message: text,
actions: [ OO.ui.MessageDialog.static.actions[ 0 ] ]
} ).closed.then( function () {
return undefined;
} );
}
 
/**
Riga 36 ⟶ 20:
}
 
mw.util.addCSS(
'.tradlinks-buttons { width: 100%; text-align: center; margin-top: 10px }' );+
'.tradlinks-error { color: red; font-size: 120%; font-weight: bold; text-align:center }'
);
function OptDialog( config ) {
OptDialog.parent.call( this, config );
Riga 48 ⟶ 35:
var self = this;
OptDialog.parent.prototype.initialize.call( this );
 
this.errorContainer = new OO.ui.LabelWidget( {
label: ''
} );
this.addError = function ( error ) {
self.errorContainer.setLabel(
new OO.ui.HtmlSnippet( '<span class="tradlinks-error">' + error + '</span>' )
);
};
this.clearError = function () {
self.errorContainer.setLabel( '' );
};
 
this.fields = [];
var lingue = getLingue();
Riga 56:
maxLength: 3
} );
input.on( 'change', self.clearError );
var field = new OO.ui.FieldLayout(
input,
Riga 85 ⟶ 86:
 
this.panelLayout = new OO.ui.PanelLayout( { padded: true, expanded: false } );
this.panelLayout.$element.append( fieldsetLayout.$element, buttonsLayout.$element, this.errorContainer.$element );
this.$body.append( this.panelLayout.$element );
};
Riga 96 ⟶ 97:
windowManager = new OO.ui.WindowManager();
$( 'body' ).append( windowManager.$element );
windowManager.addWindows( [ optDialog, new OO.ui.MessageDialog() ] );
windowManager.openWindow( optDialog );
}
Riga 121 ⟶ 122:
var siteData = data.sitematrix[i];
if ( lingue.indexOf( siteData.code ) > -1 ) {
filteredMatrix[siteData.code] = siteData.site;
}
}
Riga 128 ⟶ 129:
var code = lingue[j];
if ( code === 'it' ) {
showDialogErroroptDialog.addError( 'Il codice "it" non può essere usato' );
return;
}
if ( !( code in filteredMatrix ) ) {
showDialogErroroptDialog.addError( 'Codice lingua non riconosciuto: ' + code );
return;
}
Riga 143 ⟶ 144:
}
if ( !found ) {
showDialogErroroptDialog.addError( 'Non esiste una Wikipedia nella seguente lingua: ' + code );
return;
}
Riga 171 ⟶ 172:
function tradLink( cod ) {
var lingue = getLingue();
 
if ( lingue[cod] === 'it' ) {
// TODO Validare l'input per evitare questo caso
return;
}
 
new mw.ForeignApi( '//' + lingue[cod] + '.wikipedia.org/w/api.php' ).get( {
Riga 199 ⟶ 195:
var trad = data.query.pages[ key ].langlinks[ 0 ][ "*" ];
$( '#wpTextbox1' ).textSelection( 'encapsulateSelection', {
pre: trad + "[|",
post: "]"
} );
document.getElementById( 'wpTextbox1' ).selectionStart = selStart + trad.length + 1;
document.getElementById( 'wpTextbox1' ).selectionEnd = selEnd + trad.length + 21;
return;
}
Riga 218 ⟶ 213:
}
 
} ).closed.then $( function () {
// setup hotkeys
$( '#wpTextbox1' ).keydown( function( event ) {
if ( event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey ) {
if ( event.which === 48 ) {
event.preventDefault();
mw.loader.using( [ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows', 'mediawiki.widgets' ] )
.done( showDialog )
.fail( function() { console.error( 'Errore configurazione tradLink' ); } );
} else if ( event.which >= 49 && event.which < 57 ) {
event.preventDefault();
tradLink( event.which - 49 );
}
}
} );
} );
}( mediaWiki, jQuery ) );