Utente:Tino/TradottoDa.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
rimuovo categorie
 
(4 versioni intermedie di uno stesso utente non sono mostrate)
Riga 10:
* @author [[Utente:Tino]]
*/
 
/* <nowiki> */
 
(function (mw, $) {
'use strict';
Riga 22 ⟶ 25:
var inputArea = $('#wpTextbox1');
var cursor;
// flag for default browser behaviour on the shortcut
Riga 68 ⟶ 70:
];
// text to be added afterfor the cursorcompiled positiontemplate
var text = '{{tradotto da|' + lang + '|';
var index;
Riga 90 ⟶ 92:
// insert template completion
inputArea.textSelection('setSelection', {
start: cursor - 2,
end: cursor
});
inputArea.textSelection('encapsulateSelection', {
peri: text,
Riga 121 ⟶ 119:
dataType: 'jsonp',
success: function(data) {
if (!data.success)
end: cursorreturn;
var wiki = lang + 'wiki';
Riga 126 ⟶ 127:
var index;
for (index in data.entities) {
});
// the voice may not exist in the specified language
if (!data.entities[index].sitelinks[wiki])
start: cursor - 2,return;
var title = data.entities[index].sitelinks[wiki].title;
Riga 143 ⟶ 149:
keystrokeDefault = false;
var prevText, cursor, beginning, langMatch;
// get cursor position and select "{{tradotto da|ll" on keypress
cursor = inputArea.textSelection('getCaretPosition');
prevText = inputArea.val().substring(0, cursor);
beginning = prevText.toLowerCase().lastIndexOf('{{tradotto da');
prevText = prevText.substring(beginning);
inputArea.textSelection('setSelection', {
{start: beginning, end: cursor});
// get language from the input in the textarea (last 2 chars)
var langlangMatch = inputAreaprevText.valmatch().substring/^{{tradotto da\|(cursor [a- z]{2, cursor})$/);
if (!langMatch || !langMatch[1])
return;
queryWikidata(langlangMatch[1]);
});
Riga 161 ⟶ 176:
});
}(mediaWiki, jQuery));
 
/* </nowiki> */