מדיה ויקי:Gadget-TemplatesExternalLinks.js: הבדלים בין גרסאות בדף
לבקשת קיפודנחש |
לבקשת קיפודנחש |
||
| שורה 6: | שורה 6: | ||
function templates(templateName) { | function templates(templateName) { | ||
var constants = ["", | var constants = ["", | ||
| שורה 64: | שורה 64: | ||
var templatesAr = [ | var templatesAr = [ | ||
{t: 'קישור כללי', np: [ | {t: 'קישור כללי', np: [ | ||
[' | ['הכותב', 'שמות כותבי המאמר', 1], | ||
['כותרת', 'שם המאמר המקושר'], | ['כותרת', 'שם המאמר המקושר'], | ||
[' | ['כתובת', 'הקישור (כלומר ה-URL) עצמו'], | ||
['תאריך', 'תאריך המאמר', 1], | ['תאריך', 'תאריך המאמר', 1], | ||
['עמודים', 'מספר העמודים', 1], | ['עמודים', 'מספר העמודים', 1], | ||
['מידע נוסף', 'מידע נוסף (לא תאריך)', 1], | |||
['שפה', 'שפה (אם המאמר לא בעברית)', 1], | ['שפה', 'שפה (אם המאמר לא בעברית)', 1], | ||
['פורמט', 'פורמט המאמר, אם | ['פורמט', 'פורמט המאמר, אם אינו HTML (PDF או DOC)', 1], | ||
['ציטוט', 'ציטוט משפט מהדף המקושר (יכול לעזור במציאת הדף בעתיד, אם הקישור ישתנה)', 1] | ['ציטוט', 'ציטוט משפט מהדף המקושר (יכול לעזור במציאת הדף בעתיד, אם הקישור ישתנה)', 1] | ||
]}, | ]}, | ||
| שורה 150: | שורה 151: | ||
{t: 'mako', p: [1,2,3,6,4], r: /www\.mako\.co\.il\/(.*?)\/Article-(.*?)\.htm/i, rp: [4,3], bm: 1, op: [4]} | {t: 'mako', p: [1,2,3,6,4], r: /www\.mako\.co\.il\/(.*?)\/Article-(.*?)\.htm/i, rp: [4,3], bm: 1, op: [4]} | ||
]; | ]; | ||
if (! templateName) { | if (! templateName) { | ||
var en = /^[a-z]/; | var en = /^[a-z]/; | ||
| שורה 162: | שורה 163: | ||
return templatesAr; | return templatesAr; | ||
} | } | ||
var template; | var template; | ||
for (var i in templatesAr) | for (var i in templatesAr) | ||
if (templatesAr[i].t == templateName) | if (templatesAr[i].t == templateName) | ||
template = templatesAr[i]; | template = templatesAr[i]; | ||
var historic = {"דבר": "DAV", "מעריב": "MAR", "הצבי": "HZV", "הצפירה": "HZF", "המגיד": "MGD", "המליץ": "HMZ", "חבצלת": "HZT", "PalPost": "PLS"}; | var historic = {"דבר": "DAV", "מעריב": "MAR", "הצבי": "HZV", "הצפירה": "HZF", "המגיד": "MGD", "המליץ": "HMZ", "חבצלת": "HZT", "PalPost": "PLS"}; | ||
if (historic[template.t]) { | if (historic[template.t]) { | ||
| שורה 177: | שורה 178: | ||
if (typeof template.p[i] == "number") | if (typeof template.p[i] == "number") | ||
template.p[i] = constants[template.p[i]]; | template.p[i] = constants[template.p[i]]; | ||
return template; | return template; | ||
} | } | ||
function templateDialog(dialog, template) { | function templateDialog(dialog, template) { | ||
var brainDamage = $.browser.msie && $.browser.version < 8; | |||
var orderedFields = [], | var orderedFields = [], | ||
namedFields = [], | namedFields = [], | ||
| שורה 222: | שורה 224: | ||
function updatePreview(){ | function updatePreview(){ | ||
$('#ltw2_preview').text(createWikiCode()); | $('#ltw2_preview').text(createWikiCode()); | ||
var | var canOK = 'enable'; | ||
var f = orderedFields.concat(namedFields) | var f = orderedFields.concat([]); //clone - we don't want to touch orderedFields. | ||
for (i in f) | for (var i in namedFields) | ||
f.push(namedFields[i][1]); | |||
for (var i in f) | |||
if (f[i].hasClass('ltw_required') && $.trim(f[i].val()).length == 0) | if (f[i].hasClass('ltw_required') && $.trim(f[i].val()).length == 0) | ||
canOK = 'disable'; | |||
$(".ui-dialog-buttonpane button:contains('אישור')").button( | $(".ui-dialog-buttonpane button:contains('אישור')").button(canOK); | ||
$('#ltw2_list').attr('disabled', $('#ltw2_ref').attr('checked')); | $('#ltw2_list').attr('disabled', $('#ltw2_ref').attr('checked'));//disable list if ref | ||
$('#ltw2_ref').attr('disabled', $('#ltw2_list').attr('checked')); | $('#ltw2_ref').attr('disabled', $('#ltw2_list').attr('checked'));//disable ref if list | ||
if (brainDamage) { //IOW: internet explorer. | |||
var width = $('#ltw_dialog').width() - 12; | |||
$('.ui-dialog-titlebar').width(width); | |||
$('.ui-dialog-buttonpane').width(width); | |||
} | |||
} | } | ||
function addRow(labelText, paramName, optional) { | function addRow(labelText, paramName, optional) { | ||
var inputField = $('<input>', {id: 'ltw2_inputfield_' + paramName, type: 'text', width: 600}).css({width: '28em'}).bind('input', updatePreview); | var inputField = $('<input>', {id: 'ltw2_inputfield_' + paramName, type: 'text', width: 600}).css({width: '28em'}).bind('paste cut drop input change', updatePreview); | ||
if (! (optional || 0)) | if (! (optional || 0)) | ||
inputField.addClass('ltw_required').css({border: '1px red solid'}); | inputField.addClass('ltw_required').css({border: '1px red solid'}); | ||
| שורה 245: | שורה 254: | ||
table.append(tr); | table.append(tr); | ||
} | } | ||
function extractParamsFromURL() { | function extractParamsFromURL() { | ||
var str = | var str = $('#ltw_urlinput').val(); | ||
if (template.replace) | if (template.replace) | ||
for (var r in template.replace) | for (var r in template.replace) | ||
| שורה 257: | שורה 266: | ||
updatePreview(); | updatePreview(); | ||
} | } | ||
if (template.bm) | if (template.bm) | ||
dialog.append($('<p>', {title: 'ראו דף "עזרה:בוקמרקלטים"'}).css({color: 'red', fontWeight: 'bold'}) | dialog.append($('<p>', {title: 'ראו דף "עזרה:בוקמרקלטים"'}).css({color: 'red', fontWeight: 'bold'}) | ||
.text('קיים בוקמרקלט שמייצר תבנית "' + template.t + '" באופן אוטומטי. אנא שקלו להשתמש בו.')) | .text('קיים בוקמרקלט שמייצר תבנית "' + template.t + '" באופן אוטומטי. אנא שקלו להשתמש בו.')) | ||
.append($('<hr>')); | .append($('<hr>')); | ||
if (template.r) | if (template.r) | ||
dialog.append($('<span>').text('הדביקו את הקישור כאן:').css({width: '20em'})) | dialog.append($('<span>').text('הדביקו את הקישור כאן:').css({width: '20em'})) | ||
.append($('<input>', {type: "text", maxLength: 600}).css({width: ' | .append($('<input>', {type: "text", id: 'ltw_urlinput', maxLength: 600}).css({width: '26em'}).bind('paste cut drop input change', extractParamsFromURL)) | ||
.append($('<hr>')) | .append($('<hr>')) | ||
dialog | dialog | ||
.append($('<p>').text('השדות המסומנים באדום הם חובה, השאר אופציונליים')) | .append($('<p>').text('השדות המסומנים באדום הם חובה, השאר אופציונליים')) | ||
| שורה 278: | שורה 287: | ||
.append($('<p>').css({height: '1.5em'})) | .append($('<p>').css({height: '1.5em'})) | ||
.append($('<p>', {id: 'ltw2_preview'}).css({backgroundColor: "lightGreen", fontSize: '120%', maxWidth: '40em'})); | .append($('<p>', {id: 'ltw2_preview'}).css({backgroundColor: "lightGreen", fontSize: '120%', maxWidth: '40em'})); | ||
for (var i = 0; i < (template.p || []).length; i++) | for (var i = 0; i < (template.p || []).length; i++) | ||
if (template.p[i].length == 0) // this allow defining an empty parameter. by use of a "pseudo field". | if (template.p[i].length == 0) // this allow defining an empty parameter. by use of a "pseudo field". | ||
| שורה 284: | שורה 294: | ||
else | else | ||
addRow(template.p[i], parseInt(i, 10) + 1, template.op && ($.inArray(i, template.op)+1)); | addRow(template.p[i], parseInt(i, 10) + 1, template.op && ($.inArray(i, template.op)+1)); | ||
for (var i in template.np) | for (var i in template.np) | ||
addRow(template.np[i][1], template.np[i][0], template.np[i][2]); | addRow(template.np[i][1], template.np[i][0], template.np[i][2]); | ||
dialog.dialog('option', 'buttons', { | dialog.dialog('option', 'buttons', { | ||
'אישור': function() {insertTags('', '', createWikiCode()); dialog.dialog('close');}, | 'אישור': function() {insertTags('', '', createWikiCode()); dialog.dialog('close');}, | ||
| שורה 299: | שורה 309: | ||
position: [(window.width - dialog.width()) / 2, (window.height - dialog.height()) / 2] | position: [(window.width - dialog.width()) / 2, (window.height - dialog.height()) / 2] | ||
}); | }); | ||
$('.ui-dialog-buttonpane').css({direction: 'ltr'}); | |||
$('.ui-dialog-buttonpane > button').css({float: 'right'}); // jQuery has problems with rtl dialogs + ie is braindamaged. | |||
updatePreview(); | updatePreview(); | ||
} | } | ||
| שורה 305: | שורה 317: | ||
$('#ltw_dialog').remove(); // kill existing popup when button is pressed again. | $('#ltw_dialog').remove(); // kill existing popup when button is pressed again. | ||
var title = 'יצירת תבנית קישור', | var title = 'יצירת תבנית קישור', | ||
dialog = $('<div>', {id: 'ltw_dialog'}).css({backgroundColor: '#E8E8E8'}).dialog({ | dialog = $('<div>', {id: 'ltw_dialog'}).css({backgroundColor: '#E8E8E8', maxWidth: '58em'}).dialog({ | ||
title: title, | title: title, | ||
resizable: false, | resizable: false, | ||
| שורה 316: | שורה 328: | ||
templateDialog(dialog, templates(this.value)); | templateDialog(dialog, templates(this.value)); | ||
}); | }); | ||
selector.append($('<option>', {text: 'בחרו תבנית מהרשימה'})); | selector.append($('<option>', {text: 'בחרו תבנית מהרשימה'})); | ||
var fullList = templates(false); | var fullList = templates(false); | ||
| שורה 322: | שורה 334: | ||
selector.append($('<option>', {text: fullList[i].t, value: fullList[i].t})); | selector.append($('<option>', {text: fullList[i].t, value: fullList[i].t})); | ||
dialog.append(selector); | dialog.append(selector); | ||
dialog.append($('<p>').css({fontSize: '0.8em'}).text(' | dialog.append($('<p>').css({fontSize: '0.8em'}).text('הוראות שימוש ודיווח על בעיות בדף "עזרה:אשף תבניות קישורים"')); | ||
} | } | ||