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

Contenuto cancellato Contenuto aggiunto
fix
m fix
 
(8 versioni intermedie di uno stesso utente non sono mostrate)
Riga 20:
}
 
mw.util.addCSS(
'.tradlinks-buttons { width: 100%; text-align: center; margin-top: 10px }' );+
new OO'.ui.HtmlSnippet(tradlinks-error '<span{ style="color: red; font-size: 120%; font-weight: bold; text-align:center">' + error + }'</span>' )
);
function OptDialog( config ) {
OptDialog.parent.call( this, config );
Riga 32 ⟶ 35:
var self = this;
OptDialog.parent.prototype.initialize.call( this );
 
this.errorContainer = new OO.ui.LabelWidget( {
label: ''
} );
this.addError = function ( error ) {
thisself.errorContainer.setLabel(
new OO.ui.HtmlSnippet( '<span class="tradlinks-error">' + error + '</span>' )
} );
};
this.clearError = function () {
thisself.errorContainer.setLabel( '' );
};
 
this.fields = [];
var lingue = getLingue();
Riga 40 ⟶ 56:
maxLength: 3
} );
fieldinput.on( 'change', thisself.clearError );
var field = new OO.ui.FieldLayout(
input,
Riga 47 ⟶ 64:
}
);
field.on( 'change', this.clearError );
self.fields.push( field );
count++;
Riga 68 ⟶ 84:
classes: [ 'tradlinks-buttons' ]
} );
 
this.errorContainer = new OO.ui.LabelWidget( {
label: ''
} );
this.addError = function ( error ) {
this.errorContainer.setLabel(
new OO.ui.HtmlSnippet( '<span style="color: red; font-size: 120%; font-weight: bold; text-align:center">' + error + '</span>' )
);
};
this.clearError = function () {
this.errorContainer.setLabel( '' );
};
 
this.panelLayout = new OO.ui.PanelLayout( { padded: true, expanded: false } );
Riga 89 ⟶ 93:
};
optDialog = new OptDialog( {
size: 'mediumsmall'
} );
windowManager = new OO.ui.WindowManager();
Riga 168 ⟶ 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 196 ⟶ 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 215 ⟶ 213:
}
 
$( 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 ) );