מדיה ויקי:Gadget-TemplatesExternalLinks.js
מראה
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
function createAndInsertLinkTemplate(templateName, fields, isRef) {
var par = ["{{" + templateName];
for (var i = 0; i < fields.length; i++)
par.push(fields[i].value);
var code = par.join("|") + "}}";
if (isRef)
code = "{{הערה|1=" + code + "}}";
insertTags( "", "", code);
}
function popupPredefinedLinkTemplate(templateName, paramList) {
var height = 100 + 30 * paramList.length;
for (i in paramList)
height += 20 * (paramList[i].length / 60)
var popup = window.open(null, "popup", "height=" + height + ",width=500" );
var doc = popup.document;
doc.title = " :הוספת תבנית " + templateName;
doc.direction = doc.dir = "rtl";
doc.templateName = templateName;
doc.allFields = [];
var form = doc.createElement("Form");
var body = doc.body;
form.style.direction = "rtl";
body.appendChild(form);
var table = doc.createElement("table");
form.appendChild(table);
for (i in paramList) {
if (paramList[i].length == 0) { // this allow defining an empty parameter. by use of a "pseudo field".
doc.allFields.push({value:""});
continue;
}
var row = doc.createElement("tr");
var cell = doc.createElement("td");
cell.innerHTML = paramList[i];
cell.style.maxWidth = "12em";
row.appendChild(cell);
var field = doc.createElement("input");
field.type = "text";
field.maxLength = 120;
field.style.width = "20em";
cell = doc.createElement("td");
cell.appendChild(field);
row.appendChild(cell);
table.appendChild(row);
doc.allFields.push(field);
}
body.appendChild(doc.createElement("p"));
var refCheckBox = doc.createElement('input');
refCheckBox.type = "checkbox";
var label = doc.createElement('label');
label.htmlFor = refCheckBox;
label.innerHTML = "מקם את התבנית בתוך הערת שוליים";
body.appendChild(label);
body.appendChild(refCheckBox);
body.appendChild(doc.createElement("p"));
var button = doc.createElement("input");
button.type = "button";
button.value = "אישור";
button.father = this;
button.doc = doc;
button.popup = popup;
button.refCheckBox = refCheckBox;
button.onclick = function() {
this.father.createAndInsertLinkTemplate(this.doc.templateName, this.doc.allFields, this.refCheckBox.checked);
this.popup.close();
}
body.appendChild(button);
var button = doc.createElement("input");
button.type = "button";
button.value = "ביטול";
button.popup = popup;
button.onclick = function() {
this.popup.close();
}
body.appendChild(button);
}
function createLinkTemplatesSelections() {
var select = document.createElement("select");
select.id = "linkTemplatesList";
select.onchange = function() {
fireLinkTemplatePopup(this.value);
this.selectedIndex = 0;
return false;
}
var fullList = knownLinkTemplates();
var names = [], hnames = [];
var re = /^([a-zA-Z])$/;
for (x in fullList)
if (re.test(x[0]))
names.push(x);
else
hnames.push(x);
names.sort; hnames.sort;
var allnames = hnames.concat(names);
select.options.add(new Option("בחר קישור להוספה", ""));
for (var i in allnames)
select.options.add(new Option(allnames[i], allnames[i]));
var toolbar = document.getElementById("toolbar");
if (toolbar)
toolbar.appendChild(select);
}
function knownLinkTemplates() {
var constants = [
"",
"שם המחבר",
"כותרת המאמר",
"מספר (כפי שמופע בקישור)",
"מידע נוסף (למשל תאריך)",
"מספר הסדרה",
"קידומת",
"מידע נוסף (לא תאריך)",
"ספר",
"פרק",
"פסוק",
"מסכת",
"דף",
"עמוד",
"משנה",
"סימן",
"סעיף",
"הלכות",
"שם",
"מספר הסדרה",
'מספר סדרת "ART"',
];
var teplatesDic = {
"ynet": [1, 2, 3, 4, 5, 0,],
"הארץ": [1, 2, 3, 4],
"דבר": [1,2,"תאריך כתבה, בצורה 1949/07/25 (כי שמופיע ב-URL של הכתבה)",3,6,"סוג הפרסום. אם ה-URL כולל 'EntityId=Ad' או 'EntityId=Pc' למלא 'Ad' או 'Pc'"],
'תנ"ך': [8,9,10],
"nrg": [1,2,3,4,0,19,20],
"Mooma": [18],
}
for (var key in teplatesDic)
for (var i in teplatesDic[key])
if (typeof(teplatesDic[key][i]) == "number")
teplatesDic[key][i] = constants[teplatesDic[key][i]];
return teplatesDic;
}
function fireLinkTemplatePopup(templateName) {
var linkTemplates = knownLinkTemplates();
var templateParams = linkTemplates[templateName];
if (templateParams && templateParams.constructor == Array && templateParams.length > 0)
popupPredefinedLinkTemplate(templateName, templateParams);
}
if (wgAction == 'edit')
addOnloadHook(createLinkTemplatesSelections);