מדיה ויקי:Gadget-TemplateParamWizard.js: הבדלים בין גרסאות בדף

redirects
מאין תקציר עריכה
שורה 110: שורה 110:
for (var paramname in params)
for (var paramname in params)
onemore(paramname);
onemore(paramname);
// derive placeholders for feilds derived from wikidata
if (data.maps && data.maps.hasOwnProperty('wikidata') && mw.config.get('wgWikibaseItemId')) {
var wikidataFormattedValues = $('<div>');
for (var k in data.maps['wikidata']) {
wikidataFormattedValues.append($('<span>', {id: k, text:'{{#property:' + k + '}}'}))
}
$.post(
mw.util.wikiScript('api'),
{action: 'parse', text: wikidataFormattedValues.html(), disablelimitreport: 1, format: 'json', prop: 'text', title: mw.config.get('wgPageName')},
function(wbd) {
if (!wbd || !wbd.parse || !wbd.parse.text) return;
for (var k in data.maps['wikidata']) {
var wikidataVal = $('#' + k, wbd.parse.text['*']).text(),
field = fieldsBypName[data.maps['wikidata'][k]];
if (field)
field.prop('placeholder', wikidataVal);
}
}
);
}
}
}


שורה 639: שורה 660:
error: readTemplateData
error: readTemplateData
});
});
}
function templateContext() {
var selection = $("#wpTextbox1").textSelection('getSelection'),
caretPos, beforeText, afterText, templateStart, templateEnd;
// trust the user
if ( selection.length > 0 ) {
return selection;
}
caretPos =  $("#wpTextbox1").textSelection('getCaretPosition');
beforeText = $("#wpTextbox1").val().substr(0, caretPos);
afterText = $("#wpTextbox1").val().substr(caretPos);
templateStart = beforeText.lastIndexOf('{{');
templateEnd = afterText.indexOf('}}') + 2;
// only under opportunistic template context assumptions
if ( $("#wpTextbox1").val().split('{').length != $("#wpTextbox1").val().split('}').length ||
  (beforeText.split('{{').length === beforeText.split('}}').length) ||
  (afterText.split('{{').length === afterText.split('}}').length) )
return '';
// determine the start and the end of the template context
while (beforeText.substr(templateStart).split('{{').length <= beforeText.substr(templateStart).split('}}').length)
templateStart = beforeText.lastIndexOf('{{', templateStart - 1)
while (afterText.substr(0, templateEnd).split('{{').length >= afterText.substr(0, templateEnd).split('}}').length)
templateEnd = afterText.indexOf('}}', templateEnd) + 2;
// extend the selection to the current template context
$("#wpTextbox1").focus().textSelection('setSelection', {
start: templateStart,
end: caretPos + templateEnd
});
return $("#wpTextbox1").textSelection('getSelection');
}
}


שורה 644: שורה 702:
mw.loader.using(['jquery.ui.widget','jquery.tipsy','jquery.textSelection', 'jquery.ui.autocomplete', 'jquery.ui.dialog', 'jquery.ui.datepicker', 'mediawiki.api'], function() {
mw.loader.using(['jquery.ui.widget','jquery.tipsy','jquery.textSelection', 'jquery.ui.autocomplete', 'jquery.ui.dialog', 'jquery.ui.datepicker', 'mediawiki.api'], function() {
init();
init();
var match = $("#wpTextbox1").textSelection('getSelection').match(/^\{\{([^|}]*)/);
var match = templateContext().match(/^\{\{([^|}]*)/);
template = match ? $.trim(match[1]) : null;
template = match ? $.trim(match[1]) : null;
if (template)
if (template)