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

Contenuto cancellato Contenuto aggiunto
m variabile
ForeignApi
Riga 24:
OptDialog.parent.call( this, config );
}
// TODO Valutare se sia possibile usare un ProcessDialog
OO.inheritClass( OptDialog, OO.ui.Dialog );
OptDialog.static.name = 'optDialog';
// XXX Questo non viene visualizzato nei Dialog di base
OptDialog.static.title = 'Configurazione del tool TradLink'; // XXX
OptDialog.prototype.initialize = function () {
var self = this;
Riga 107 ⟶ 109:
var lingue = getLingue();
 
$.getJSONif ( "https://" + lingue[ cod ] + ".wikipedia.org/w/api.php?callback=?",== 'it' ) {
// TODO Validare l'input per evitare questo caso
action: "query",
return;
prop: "langlinks",
},
lllang: "it",
titles: $( '#wpTextbox1' ).textSelection( 'getSelection' ),
format: "json",
redirects: ""
},
function( data ) {
var selStart = document.getElementById( 'wpTextbox1' ).selectionStart,
selEnd = document.getElementById( 'wpTextbox1' ).selectionEnd;
if ( typeof( data ) != "undefined" &&
typeof( data.query ) != "undefined" &&
typeof( data.query.pages ) != "undefined"
) {
for ( var key in data.query.pages ) {
if ( typeof( data.query.pages[ key ] ) != "undefined" &&
typeof( data.query.pages[ key ].langlinks ) != "undefined" &&
typeof( data.query.pages[ key ].langlinks[ 0 ] ) != "undefined" &&
typeof( data.query.pages[ key ].langlinks[ 0 ][ "*" ] ) != "undefined"
) {
var trad = data.query.pages[ key ].langlinks[ 0 ][ "*" ];
$( '#wpTextbox1' ).textSelection( 'encapsulateSelection', {
pre: trad + "[",
post: "]"
} );
document.getElementById( 'wpTextbox1' ).selectionStart = selStart + trad.length;
document.getElementById( 'wpTextbox1' ).selectionEnd = selEnd + trad.length + 2;
 
new mw.ForeignApi( '//' + lingue[cod] + '.wikipedia.org/w/api.php' ).get( {
return;
action: "query",
}
prop: "langlinks",
lllang: "it",
titles: $( '#wpTextbox1' ).textSelection( 'getSelection' ),
format: "json",
redirects: ""
} ).done( function( data ) {
var selStart = document.getElementById( 'wpTextbox1' ).selectionStart,
selEnd = document.getElementById( 'wpTextbox1' ).selectionEnd;
if (
if ( typeof( data.query ) != "undefined" &&
typeof( data.query.pages ) != "undefined" &&
) {
for ( var key in data.query.pages ) {
if ( typeof( data.query.pages[ key ] ) != "undefined" &&
if ( typeof( data.query.pages[ key ].langlinks ) != "undefined" &&
typeof( data.query.pages[ key ].langlinks[ 0 ] ) != "undefined" &&
typeof( data.query.pages[ key ].langlinks[ 0 ][ "*" ] ) != "undefined" &&
) {
typeof(var trad = data.query.pages[ key ].langlinks[ 0 ][ "*" ] ) != "undefined";
$( '#wpTextbox1' ).textSelection( 'encapsulateSelection', {
pre: trad + "[",
post: "]"
} );
document.getElementById( 'wpTextbox1' ).selectionStart = selStart + trad.length;
document.getElementById( 'wpTextbox1' ).selectionEnd = selEnd + trad.length + 2;
return;
}
}
}
var noLinkLabel = "[NO LINK]";
var noLinkLabel = "[NO LINK]";
$( '#wpTextbox1' ).textSelection( 'encapsulateSelection', {
pre: "",
post: noLinkLabel
} );
document.getElementById( 'wpTextbox1' ).selectionStart = selEnd;
document.getElementById( 'wpTextbox1' ).selectionEnd = selEnd + noLinkLabel.length;
} );
document.getElementById( 'wpTextbox1' ).selectionStart = selEnd;
document.getElementById( 'wpTextbox1' ).selectionEnd = selEnd + noLinkLabel.length;
} );
}