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

מ עיצוב, שימוש ב-tipsy
אןעיא דיןפ
שורה 1: שורה 1:
//Adds wizard for using templates for external links
//Template parameters wizard
//Written by [[User:קיפודנחש]]
//Written by [[User:קיפודנחש]]
if($.inArray(mw.config.get('wgAction'), ['edit', 'submit'])+1)
if($.inArray(mw.config.get('wgAction'), ['edit', 'submit'])+1)
$(document).ready(function() {
mw.loader.using(['jquery.ui.widget','jquery.tipsy','jquery.textSelection', 'jquery.ui.dialog'], function() {
mw.loader.using(['jquery.ui.widget','jquery.tipsy','jquery.textSelection', 'jquery.ui.dialog'], function() {
 
$(function() {
// template parameter is an object with the following fields:
// template parameter is an object with the following fields:
// desc: desciption string
// desc: desciption string
// select: array of possible values (optional)
// defval: default value (optional)
// defval: default value (optional)
// options: object with 3 possible fields:
// options: object with optional fields:
//// multiline (boolean)
//// multiline: number of lines
//// depends (string - another field's name)
//// depends: another field's name
//// required (boolean)
//// required: boolean
////choices: array of legal values for the field
// templateParams is keyed by paramName.
// templateParams is keyed by paramName.
var templateParams,
var templateParams,
שורה 23: שורה 22:
// the fields, keyed by paramName
// the fields, keyed by paramName
fieldsBypName,
fieldsBypName,
rtl = $('body').css('direction') == 'rtl';
//collected from API using the category
allTemplates,
rtl = $('body').is('.rtl');


function paramsFromSelection() {
function paramsFromSelection() {
שורה 113: שורה 114:
$.post(mw.util.wikiScript('api'), {action: 'parse', title: mw.config.get('wgPageName'), prop: 'text', text: temp, format: 'json'}, function(data) {
$.post(mw.util.wikiScript('api'), {action: 'parse', title: mw.config.get('wgPageName'), prop: 'text', text: temp, format: 'json'}, function(data) {
if (data && data.parse && data.parse.text) {
if (data && data.parse && data.parse.text) {
var buttons = {},
var buttons = [{text: i18n('close'), click: function() {$(this).dialog('close');}}],
div = $('<div>')
div = $('<div>').html(data.parse.text['*']);
.html(data.parse.text['*']);
buttons[i18n('close')] = function() {$(this).dialog('close');};
$('a', div).attr('target', '_blank'); // we don't want people to click on links in preview - they'll lose their work.
$('a', div).attr('target', '_blank'); // we don't want people to click on links in preview - they'll lose their work.
$('<div>')
$('<div>')
.dialog(
.dialog(
{title: i18n('preview'),
{title: i18n('preview'),
width: 'auto',
height: 'auto',
overflow: 'auto',
modal: true,
modal: true,
position: [60, 60],
position: [60, 60],
buttons: buttons})
buttons: buttons})
.append(div);
.append(div);
circumventRtlBug();
}
}
});
});
}
function circumventRtlBug() {
if (rtl)
$('.ui-dialog-buttonpane button').css({float: 'right'}); // jQuery has problems with rtl dialogs + ie is braindamaged.
}
}


function i18n(key, param) {
function i18n(key, param) {
if (key == 'templates namespace')
return mw.config.get('wgFormattedNamespaces')[10];
switch (mw.config.get('wgContentLanguage')) {
switch (mw.config.get('wgContentLanguage')) {
case 'he':
case 'he':
switch (key) {
switch (key) {
case 'explain': return  'השדות המסומנים באדום הם חובה, השאר אופציונליים.' +
case 'explain': return  'השדות המסומנים באדום הם חובה, השאר אופציונליים.';
'<br />' + 'הקישו על שם הפרמטר לקבלת הסבר עליו, הקישו שוב להסתיר את ההסבר.';
case 'wizard dialog title': return 'מילוי הפרמטרים עבור תבנית: ' + template;
case 'wizard dialog title': return 'מילוי הפרמטרים עבור תבנית ' + template;
case 'ok': return 'אישור';
case 'ok': return 'אישור';
case 'cancel': return 'ביטול'
case 'cancel': return 'ביטול'
שורה 160: שורה 159:
switch (key) {
switch (key) {
case 'explain': return 'fields with red border are required, the rest are optional';
case 'explain': return 'fields with red border are required, the rest are optional';
case 'wizard dialog title': return 'Set up parameters for template: ' + template;
case 'ok': return 'OK';
case 'ok': return 'OK';
case 'cancel': return 'Cancel'
case 'cancel': return 'Cancel'
שורה 172: שורה 172:
case 'choices': return 'Choices';
case 'choices': return 'Choices';
case 'button hint': return 'Template parameters wizard';
case 'button hint': return 'Template parameters wizard';
case 'albe 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');
case 'template selector title': return 'Please select a template from this list';
case 'template selector title': return 'Please select a template from this list';


שורה 181: שורה 181:


function paramPage() {
function paramPage() {
return i18n('templates namespace') + ':' + $.trim(template) + '/' + i18n('params subpage');
return mw.config.get('wgFormattedNamespaces')[10] + ':' + $.trim(template) + '/' + i18n('params subpage');
}
}


שורה 199: שורה 199:
}
}
}
}
$(".ui-dialog-buttonpane button:contains('אישור')").button(canOK);
$(".ui-dialog-buttonpane button:contains('" + i18n('ok') + "')").button(canOK);
$('#tpw_preview').html(createWikiCode());
$('#tpw_preview').text(createWikiCode());
}
}


שורה 233: שורה 233:


if (!checkbox && f.autoCompleteWikiText) // teach the controls to autocomplete.
if (!checkbox && f.autoCompleteWikiText) // teach the controls to autocomplete.
f.autoCompleteWikiText({positionMy: $('body').is('.rtl')? "left top" : "right top"});
f.autoCompleteWikiText({positionMy: rtl ? "left top" : "right top"});


f.css({width: checkbox ? '1em' : '28em'})
f.css({width: checkbox ? '1em' : '28em'})
שורה 246: שורה 246:
return f;
return f;
}
}
 
var tipsyContent = function() {return $(this).data('templateParam').desc || '';},
tipsyParams = {title: tipsyContent, gravity: 'ne', opacity: 1};
function addRow(paramName, table) {
function addRow(paramName, table) {
var params = templateParams[paramName],
function tipsyContent() {return templateParams[$(this).text()].desc || '';};
inputField = createInputField(paramName),
 
var inputField = createInputField(paramName),
tr = $('<tr>')
tr = $('<tr>')
.append($('<td>', {maxWidth: '160'}).css({position: 'relative'})
.append(
.append($('<span>')
$('<td>', {maxWidth: '160'})
.text(paramName)
.text(paramName)
)
.tipsy({title: tipsyContent})
.data({templateParam: params})
.tipsy(tipsyParams)
)
)
.append($('<td>').css({width: '30em'}).append(inputField));
.append($('<td>').css({width: '30em'}).append(inputField));
שורה 288: שורה 284:
.append(table)
.append(table)
.append($('<p>').css({height: '2em'}))
.append($('<p>').css({height: '2em'}))
.append($('<pre>', {id: 'tpw_preview', 'class': 'tpw_disposable'})
.append($('<pre>', {id: 'tpw_preview'})
.css({backgroundColor: "lightGreen", maxWidth: '40em', maxHeight: '8em', overflow: 'auto'}));
.css({backgroundColor: "lightGreen", maxWidth: '40em', maxHeight: '8em', overflow: 'auto'}));


שורה 299: שורה 295:
buttons[i18n('preview')] = showPreview;
buttons[i18n('preview')] = showPreview;
dialog.dialog('option', 'buttons', buttons);
dialog.dialog('option', 'buttons', buttons);
$('.ui-dialog-buttonpane').css({backgroundColor: '#E0E0E0'});
circumventRtlBug();
$('.ui-dialog-buttonpane').css({direction: 'ltr'});
$('.ui-dialog-buttonpane button').css({float: 'right'}); // jQuery has problems with rtl dialogs + ie is braindamaged.
updateRawPreview();
updateRawPreview();
}
}
שורה 326: שורה 320:
alert('טעות בהפעלת האשף.' + '\n' + error);
alert('טעות בהפעלת האשף.' + '\n' + error);
}
}
var allTemplates;


function pickTemplate() {
function pickTemplate() {
שורה 343: שורה 335:
]
]
}).append(selector);
}).append(selector);
$('.ui-dialog-buttonpane button').css({float: 'right'});
circumventRtlBug();
}
}
function findTemplate(data) {
function findTemplate(data) {
if (data) {
if (data) {