מדיה ויקי:Gadget-TemplateParamWizard.js: הבדלים בין גרסאות בדף
←using [[mw:CodeEditor|CodeEditor]]: תמיכה בערבית |
הרחבה |
||
| שורה 1: | שורה 1: | ||
//Template parameters wizard | //Template parameters wizard | ||
//Written by [[User:קיפודנחש]] | //Written by [[User:קיפודנחש]] | ||
"use strict"; | |||
if(($.inArray(mw.config.get('wgAction'), ['edit', 'submit'])+1) && ( !$('#wpTextbox1').prop( 'readonly' ) ) ) | if(($.inArray(mw.config.get('wgAction'), ['edit', 'submit'])+1) && ( !$('#wpTextbox1').prop( 'readonly' ) ) ) | ||
$(function() { | $(function() { | ||
| שורה 30: | שורה 31: | ||
// test to see if a string contains wikiCode and hence needs parsing, or cen be used as is. | // test to see if a string contains wikiCode and hence needs parsing, or cen be used as is. | ||
wikiCodeFinder = /[\[\]\{\}\<\>]/, | wikiCodeFinder = /[\[\]\{\}\<\>]/, | ||
globalExplanation = ''; | globalExplanation = '', | ||
extendedParamCssRule, | |||
anyExtended = false; | |||
function addParam(name) { | function addParam(name) { | ||
if ($.inArray(name, paramsOrder) == -1) | if ($.inArray(name, paramsOrder) == -1) | ||
paramsOrder.push(name); | paramsOrder.push(name); | ||
} | } | ||
function paramsFromSelection() { | function paramsFromSelection() { | ||
var selection = $("#wpTextbox1").textSelection('getSelection').replace(/^\s*\{\{|\}\}\s*$/g, ''); //scrap the first {{ and last }} | var selection = $("#wpTextbox1").textSelection('getSelection').replace(/^\s*\{\{|\}\}\s*$/g, ''); //scrap the first {{ and last }} | ||
| שורה 128: | שורה 131: | ||
function analyzeOptions(str) { | function analyzeOptions(str) { | ||
var res = {}, | var res = {}, | ||
avail = ['multiline', 'required', 'depends', 'defval', 'choices', 'date'], // maybe we'll have more in the future | avail = ['multiline', 'required', 'depends', 'defval', 'choices', 'date', 'extended'], // maybe we'll have more in the future | ||
tavail = $.map(avail, i18n), | tavail = $.map(avail, i18n), | ||
options = str.split(/\s*;\s*/); | options = str.split(/\s*;\s*/); | ||
| שורה 137: | שורה 140: | ||
res[avail[ind]] = option.length > 1 ? option[1] : true; | res[avail[ind]] = option.length > 1 ? option[1] : true; | ||
} | } | ||
anyExtended = anyExtended || res.extended; | |||
return res; | return res; | ||
} | } | ||
| שורה 209: | שורה 213: | ||
case 'choices': return 'خيارات'; | case 'choices': return 'خيارات'; | ||
case 'date': return 'تاريخ'; | case 'date': return 'تاريخ'; | ||
case 'extended': return 'Extended'; | |||
case 'button hint': return 'معالج وسائط القالب'; | case 'button hint': return 'معالج وسائط القالب'; | ||
case 'able templates category name': return 'قوالب صالحة لمعالج وسائط القالب'; | case 'able templates category name': return 'قوالب صالحة لمعالج وسائط القالب'; | ||
| שורה 218: | שורה 223: | ||
case 'oneliner': return 'اجعله في صف واحد'; | case 'oneliner': return 'اجعله في صف واحد'; | ||
case 'dateFormat': return 'd MM yy'; | case 'dateFormat': return 'd MM yy'; | ||
case 'extended labels': return 'Show all parameters'; | |||
} | } | ||
case 'he': | case 'he': | ||
| שורה 237: | שורה 243: | ||
case 'choices': return 'אפשרויות'; | case 'choices': return 'אפשרויות'; | ||
case 'date': return 'תאריך'; | case 'date': return 'תאריך'; | ||
case 'extended': return 'משני'; | |||
case 'button hint': return 'אשף מילוי תבניות'; | case 'button hint': return 'אשף מילוי תבניות'; | ||
case 'able templates category name': return 'תבניות הנתמכות על ידי אשף התבניות'; | case 'able templates category name': return 'תבניות הנתמכות על ידי אשף התבניות'; | ||
| שורה 246: | שורה 253: | ||
case 'oneliner': return 'תבנית בשורה אחת'; | case 'oneliner': return 'תבנית בשורה אחת'; | ||
case 'dateFormat': return 'd בMM yy'; | case 'dateFormat': return 'd בMM yy'; | ||
case 'extended labels': return 'הראה את כל הפרמטרים'; | |||
} | } | ||
default: | default: | ||
| שורה 263: | שורה 271: | ||
case 'choices': return 'Choices'; | case 'choices': return 'Choices'; | ||
case 'date': return 'Date'; | case 'date': return 'Date'; | ||
case 'extended': return 'Extended'; | |||
case 'button hint': return 'Template parameters wizard'; | case 'button hint': return 'Template parameters wizard'; | ||
case 'able templates category name': throw('Must define category name for wizard-capable templates'); | case 'able templates category name': throw('Must define category name for wizard-capable templates'); | ||
| שורה 272: | שורה 281: | ||
case 'oneliner': return 'Single-line template'; | case 'oneliner': return 'Single-line template'; | ||
case 'dateFormat': return 'MM d, yy'; | case 'dateFormat': return 'MM d, yy'; | ||
case 'extended labels': return 'Show all parameters'; | |||
} | } | ||
} | } | ||
| שורה 415: | שורה 425: | ||
.append($('<td>').css({width: '30em'}).append(inputField)); | .append($('<td>').css({width: '30em'}).append(inputField)); | ||
dialogFields.push([paramName, inputField]); | dialogFields.push([paramName, inputField]); | ||
if (def.options.extended) | |||
tr.addClass('tpw_extended'); | |||
table.append(tr); | table.append(tr); | ||
rowsBypName[paramName] = tr; | rowsBypName[paramName] = tr; | ||
| שורה 422: | שורה 434: | ||
function injectResults() { | function injectResults() { | ||
$("#wpTextbox1").textSelection('encapsulateSelection', {replace: true, peri: createWikiCode()}); | $("#wpTextbox1").textSelection('encapsulateSelection', {replace: true, peri: createWikiCode()}); | ||
} | |||
function createExtendedCheckBox() { | |||
return $('<p>') | |||
.text(i18n('extended labels')) | |||
.append($('<input>', {type: 'checkbox'}) | |||
.change(function() { | |||
extendedParamCssRule.disabled = $(this).prop('checked'); | |||
}) | |||
); | |||
} | } | ||
| שורה 442: | שורה 464: | ||
.append($('<div>', {id: 'tpw_globalExplanation'}).html(globalExplanation)) | .append($('<div>', {id: 'tpw_globalExplanation'}).html(globalExplanation)) | ||
.append($('<p>').html(i18n('explain'))) | .append($('<p>').html(i18n('explain'))) | ||
.append(anyExtended ? createExtendedCheckBox() : '') | |||
.append(table) | .append(table) | ||
.append($('<p>') | .append($('<p>') | ||
| שורה 473: | שורה 496: | ||
fieldsBypName = {}; | fieldsBypName = {}; | ||
mw.util.addCSS(".tpw_hidden{display:none;}"); | mw.util.addCSS(".tpw_hidden{display:none;}"); | ||
extendedParamCssRule = extendedParamCssRule || mw.util.addCSS(".tpw_extended{display:none;}"); | |||
} | } | ||
| שורה 487: | שורה 511: | ||
function pickTemplate() { | function pickTemplate() { | ||
function okButtonPressed() { | |||
template = selector.val(); | |||
fireDialog(); | |||
templateSelector.dialog("close"); | |||
} | |||
var selector = $('<input>') | var selector = $('<input>') | ||
.css({width: '28em'}) | .css({width: '28em'}) | ||
| שורה 499: | שורה 528: | ||
} | } | ||
); | ); | ||
} | }, | ||
select: okButtonPressed | |||
}); | }); | ||
var templateSelector = $('<div>').dialog({ | var templateSelector = $('<div>').dialog({ | ||
| שורה 507: | שורה 537: | ||
modal: true, | modal: true, | ||
buttons: [ | buttons: [ | ||
{text: i18n('ok'), click: | {text: i18n('ok'), click: okButtonPressed}, | ||
{text: i18n('cancel'), click: function(){templateSelector.dialog("close")}} | {text: i18n('cancel'), click: function(){templateSelector.dialog("close")}} | ||
] | ] | ||
}).append(selector); | }).append(selector); | ||
circumventRtlBug(); | circumventRtlBug(); | ||
selector.focus(); | |||
} | } | ||