MediaWiki:Gadget-tradLink.js: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica |
m Convenzioni stilistiche |
||
Riga 5:
* Autore : [[:it:User:Jalo]]
*
* Lo script
* http://it.wikipedia.org/w/index.php?title=MediaWiki:Gadget-tb-base.js&oldid=66478020
* scritto da [[:it:User:Rotpunkt]]
Riga 11:
// Show the dialog in order to ask for the template parameters.
function tradLink_showDialog( data, page ) {
lingue = tradLink_getLingue();
}
} );
};
};
}
}
function tradLink_getLingue() {
value = "";
var
var ca = document.cookie.split( ';' );
for
var c
while ( c.charAt( 0 ) == ' '
}
if ( value != "" ) {
splitted = value.split( ',' );
return [ splitted[ 0 ], splitted[ 1 ], splitted[ 2 ], splitted[ 3 ], splitted[ 4 ], splitted[ 5 ], splitted[ 6 ], splitted[ 7 ], splitted[ 8 ] ];
} else
return [ 'en', 'nl', 'de', 'sv', 'fr', 'ru', 'es', 'war', 'vi' ];
}
function tradLink_tradLink( cod ) {
lingue = tradLink_getLingue();
var toTrad = mw.html.escape( $( '#wpTextbox1' ).textSelection( 'getSelection' ) );
var trad = "";
$.getJSON( "https://" + lingue[ cod ] + ".wikipedia.org/w/api.php?callback=?", {
action: "query",
prop: "langlinks",
lllang: "it",
titles: toTrad,
format: "json",
redirects: ""
},
function( data ) {
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" ) {
trad = data.query.pages[ key ].langlinks[ 0 ][ "*" ];
try {
mw.html.escape( $( '#wpTextbox1' ).textSelection( 'encapsulateSelection', {
pre: trad + "[",
post: "]"
} ) );
} catch ( err ) {}
document.getElementById( 'wpTextbox1' ).selectionStart = selStart + trad.length;
document.getElementById( 'wpTextbox1' ).selectionEnd = selEnd + trad.length + 2;
return;
}
}
}
try {
mw.html.escape( $( '#wpTextbox1' ).textSelection( 'encapsulateSelection', {
pre: "",
post: "[NO LINK]"
} ) );
} catch ( err ) {}
document.getElementById( 'wpTextbox1' ).selectionStart = selEnd;
document.getElementById( 'wpTextbox1' ).selectionEnd = selEnd + 9;
} );
}
// setup hotkeys
$( '#wpTextbox1' ).keydown(
var key = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;
if ( event.which === 48 ) // configure
{
tradLink_showDialog();
} else if ( event.which >= 49 && event.which < 57 ) // execute
{
tradLink_tradLink( event.which - 49 );
event.preventDefault();
}
}
} );
| |||