MediaWiki:Gadget-tradLink.js: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
tutto in una IIFE + use strict (e basta, anche se il diff fa paura) |
Migliorie sparse (devo ancora finire) |
||
Riga 13:
( function( mw, $ ) {
'use strict';
/**
* Polyfill per trimStart() (liste di browser non esaustive)
*/
function trimStringStart( str ) {
if ( 'trimStart' in String.prototype ) {
return str.trimStart();
} else if ( 'trimLeft' in String.prototype ) {
// Edge, Firefox 27-60, Chrome 31-65, Opera 18-52
return str.trimLeft();
} else {▼
// IE 9-11, Safari 9-11
return str.replace( /^\s+/, '' );
}▼
}
// Show the dialog in order to ask for the template parameters.
function tradLink_showDialog( data, page ) {
var lingue = tradLink_getLingue()
$dialog = $( '#gtb-dialog' ).html( "Inserire l'elenco delle lingue da utilizzare per il tool TradLink" )
$fieldset = $( '<fieldset>' ).css( 'border-color', 'gray' ).appendTo( $dialog );▼
▲ $dialog = $( '#gtb-dialog' ).html( "Inserire l'elenco delle lingue da utilizzare per il tool TradLink" );
▲ $fieldset = $( '<fieldset>' ).css( 'border-color', 'gray' ).appendTo( $dialog );
$( '<legend>' ).text( "Elenco" ).appendTo( $fieldset );
var count = 1;
$.each( lingue, function( id, val ) {
$( '<label>' )
Riga 31 ⟶ 44:
$fieldset
.append( $( '<input/>' )
.append( '<br/>' );
count++;
} );
// show the dialog
var Buttons = {}
Buttons[ OKText ] = function() {
var params = [];
count = 0;
$dialog.find( 'input:text' ).each( function() {
params[ count++ ] =
} );
lingue = params.join();
Riga 69 ⟶ 83:
function tradLink_getLingue() {
var value = ""
for ( var i = 0; i < ca.length; i++ ) {
var c = trimStringStart( ca[ i ] );
if ( c.indexOf( name ) === 0 ) {
value = c.substring( name.length, c.length );
break;
}
}
▲ } else {
▲ return [ 'en', 'nl', 'de', 'sv', 'fr', 'ru', 'es', 'war', 'vi' ];
▲ }
}
Riga 104 ⟶ 113:
},
function( data ) {
var selStart = document.getElementById( 'wpTextbox1' ).selectionStart
selEnd = document.getElementById( 'wpTextbox1' ).selectionEnd;
if ( typeof( data ) != "undefined" &&
typeof( data.query ) != "undefined" &&
Riga 116 ⟶ 125:
typeof( data.query.pages[ key ].langlinks[ 0 ][ "*" ] ) != "undefined"
) {
var trad = data.query.pages[ key ].langlinks[ 0 ][ "*" ];
try {
mw.html.escape( $( '#wpTextbox1' ).textSelection( 'encapsulateSelection', {
Riga 147 ⟶ 156:
// setup hotkeys
$( '#wpTextbox1' ).keydown( function( event ) {
if ( event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey ) {
if ( event.which === 48 ) {
| |||