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

מאין תקציר עריכה
ניסיון לתיקון בגים שדווחו בדף שיחתי במקום בדף השיחה של הגאדג'ט.
שורה 51: שורה 51:
var specials = [],
var specials = [],
match;
match;
while (true) { //extract inner links, inner templates and inner params - we don't want to sptit those.
while (true) { //extract inner links, inner templates and inner params - we don't want to split those.
match = selection.match(/(\{\{[^\{\}\]\[]*\}\}|\[\[[^\{\}\]\[]*\]\]|\[[^\{\}\]\[]*\])/);
match = selection.match(/(\{\{[^\{\}\]\[]*\}\}|\[\[[^\{\}\]\[]*\]\]|\[[^\{\}\]\[]*\])/);
if (! match || ! match.length)
if (! match || ! match.length)
שורה 58: שורה 58:
selection = selection.replace(match[0], "\0" + specials.length + "\0");
selection = selection.replace(match[0], "\0" + specials.length + "\0");
}
}
var params = selection.split(/\s*\|\s*/);
var params = selection.split(/ *\| */);
params.shift(); // remove the template name
var ordered = 0;
for (var i in params) {
for (var i in params) {
var param = params[i];
var param = params[i];
if ( ! /=/.test(param) ) {
param = ++ordered + '=' + param;
}
var paramPair = param.split("=");
var name = $.trim(paramPair.shift());
if ( ! isNaN( name ) ) {
ordered = parseInt( name ); // this still won't work as advertise when template contains explicit parameter 2 before implicit 1: {{x | 2 = hey | ho }}
}
var val = paramPair.join('=');
while (true) {
while (true) {
match = param.match(/\0(\d+)\0/);
match = val.match(/\0(\d+)\0/);
if (! match || ! match.length)
if (! match || ! match.length)
break;
break;
param = param.replace(match[0], specials[parseInt(match[1], 10)-1]);
val = param.replace(match[0], specials[parseInt(match[1], 10)-1]);
}
}
var paramPair = param.split("=");
var name = $.trim(paramPair.shift());
if (name && paramPair.length) {
if (name && paramPair.length) {
var tp = templateParams[name] = templateParams[name] || {options: {notInParamPage: 1}},
var tp = templateParams[name] = templateParams[name] || {options: {notInParamPage: 1}};
val = paramPair.join( '=' );
addParam(name);
addParam(name);
$.extend( tp.options, { 'defval': val } );
$.extend( tp.options, { defval: val } );
if ( /\n/.test( val ) ) $.extend( tp.options, { multiline : 5 } );
// next line is for the case where there are "choices"' but current value is not one of them: add it as a new choice.
// next line is for the case where there are "choices"' but current value is not one of them: add it as a new choice.
if ( typeof tp.options.choices === 'string' && tp.options.choices.indexOf( val ) < 0 )
if ( typeof tp.options.choices === 'string' && tp.options.choices.indexOf( val ) < 0 )
שורה 208: שורה 217:
f = field[1],
f = field[1],
hidden = f.parents('.tpw_hidden').length,
hidden = f.parents('.tpw_hidden').length,
val = $.trim(f.val());
val = f.val();
if (f.attr('type') == 'checkbox' && ! f.prop('checked'))
if (f.attr('type') == 'checkbox' && ! f.prop('checked'))
val = "";
val = "";