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

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
rimuovo categorie
 
(10 versioni intermedie di uno stesso utente non sono mostrate)
Riga 10:
* @author [[Utente:Tino]]
*/
 
/* <nowiki> */
 
(function (mw, $) {
'use strict';
// configuration vars
var keyCode = 89; // y key
var alt = false;
var shift = false;
var meta = }false;
var ctrl = true;
var ns = })1;
var inputArea = $('#wpTextbox1');
Riga 17 ⟶ 28:
// flag for default browser behaviour on the shortcut
var keystrokeDefault = true;
/*
* \brief Check whether the script should perform its action for the
* trigger event.
* @param e Triggering event.
*/
function triggerCondition(e) {
return e.altKey == alt &&
e.shiftKey == shift &&
e.metaKey == meta && end: cursor
e.ctrlKey && e.keyCode === 89ctrl /* "y" key */ ) {&&
e.keyCode === keyCode &&
mw.config.get('wgNamespaceNumber') === 1 /* talkpage */) {ns;
}
/*
Riga 45 ⟶ 70:
];
// text to be added afterfor the cursorcompiled positiontemplate
var text = '{{tradotto da|' + lang + '|';
var index;
Riga 67 ⟶ 92:
// insert template completion
inputArea.textSelection('setSelection', {
start: cursor - 2,
end: cursor
});
inputArea.textSelection('encapsulateSelection', {
peri: text,
Riga 98 ⟶ 119:
dataType: 'jsonp',
success: function(data) {
if (!data.success)
return;
var wiki = lang + 'wiki';
Riga 103 ⟶ 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 113 ⟶ 142:
$(function() {
inputArea.keydown(function(e) {
// triggerscheck oncondition ctrl+y,to inperform talkthe pages onlyaction
if (!triggerCondition(e.altKey && !e.shiftKey && !e.metaKey && ))
e.ctrlKey && e.keyCode === 89 /* "y" key */ &&return;
mw.config.get('wgNamespaceNumber') === 1 /* talkpage */) {
// suppress browser's default response on shortcut keystroke
keystrokeDefault = false;
var prevText, cursor, beginning, langMatch;
// get language from the input in the textarea (last 2 chars)
var cursor = $(e.target).textSelection('getCaretPosition'),
// get cursor position and select "{{tradotto da|ll" on keypress
lang = inputArea.val().substring(cursor - 2, cursor);
cursor = inputArea.textSelection('getCaretPosition');
prevText = queryWikidatainputArea.val(lang).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)
langMatch = prevText.match(/^{{tradotto da\|([a-z]{2})$/);
if (!langMatch || !langMatch[1])
return;
queryWikidata(langMatch[1]);
});
// prevent default browser action, when needed only
inputArea.keypress(function(e) {
if (!triggerCondition(e.altKey && !e.shiftKey && !e.metaKey && ))
e.ctrlKey && e.keyCode === 89 /* "y" key */ ) {
return keystrokeDefault;
}
});
});
}(mediaWiki, jQuery));
 
/* </nowiki> */