מדיה ויקי:Gadget-TemplatesExternalLinks.js: הבדלים בין גרסאות בדף
formatting |
חילוץ פרמטרים |
||
| שורה 9: | שורה 9: | ||
} | } | ||
function popupPredefinedLinkTemplate(templateName, paramList) { | function popupPredefinedLinkTemplate(templateName, paramList, regexDict) { | ||
var height = 100 + 30 * paramList.length; | var height = 100 + 30 * paramList.length + (regexDict ? 60 : 0); | ||
for (i in paramList) | for (i in paramList) | ||
height += 20 * (paramList[i].length / 60) | height += 20 * (paramList[i].length / 60) | ||
| שורה 21: | שורה 21: | ||
var form = doc.createElement("form"); | var form = doc.createElement("form"); | ||
var body = doc.body; | var body = doc.body; | ||
if (regexDict) { | |||
body.appendChild(doc.createTextNode('הדביקו את הקישור כאן:')); | |||
var b = doc.createElement("input"); | |||
b.urlInput = doc.createElement("input"); | |||
b.urlInput.type = "text"; | |||
b.urlInput.maxLength = 600; | |||
b.urlInput.style.width = "20em"; | |||
body.appendChild(b.urlInput); | |||
b.type = "button"; | |||
b.value = "חילוץ פרמטרים מן הקישור"; | |||
b.regexDict = regexDict; | |||
b.doc = doc; | |||
b.onclick = function() { | |||
var matches = this.urlInput.value.match(this.regexDict.regex); | |||
if (matches) { | |||
for (var i = 1; i < matches.length; i++) { | |||
var fieldIndex = this.regexDict.params[i-1]-1; //parameters are counted from one, we count from 0. | |||
if (fieldIndex && this.doc.allFields[fieldIndex]) | |||
this.doc.allFields[fieldIndex].value = matches[i]; | |||
} | |||
} | |||
} | |||
body.appendChild(b); | |||
} | |||
var table = doc.createElement("table"); | var table = doc.createElement("table"); | ||
for (i in paramList) { | for (i in paramList) { | ||
| שורה 47: | שורה 71: | ||
var label = doc.createElement('label'); | var label = doc.createElement('label'); | ||
label.htmlFor = refCheckBox; | label.htmlFor = refCheckBox; | ||
label.innerHTML = " | label.innerHTML = "מיקום התבנית בתוך הערת שוליים"; | ||
body.appendChild(label); | body.appendChild(label); | ||
body.appendChild(refCheckBox); | body.appendChild(refCheckBox); | ||
| שורה 95: | שורה 119: | ||
select.options.add(new Option(allnames[i], allnames[i])); | select.options.add(new Option(allnames[i], allnames[i])); | ||
var toolbar = document.getElementById("toolbar"); | var toolbar = document.getElementById("toolbar"); | ||
if (toolbar) | if (toolbar) | ||
toolbar.appendChild(select); | toolbar.appendChild(select); | ||
} | } | ||
function templateRegex(templateName) { | |||
var regexes = { | |||
nrg: {regex: /http:\/\/(?:www\.){0,1}nrg\.co\.il\/online\/([^\/]+)\/ART([^\/]+)\/([^\.]+).html/i, params:[6,7,3]}, | |||
} | |||
return regexes[templateName]; | |||
} | |||
function fireLinkTemplatePopup(templateName) { | |||
var linkTemplates = knownLinkTemplates(); | |||
var templateParams = linkTemplates[templateName]; | |||
if (templateParams && templateParams.constructor == Array && templateParams.length > 0) | |||
popupPredefinedLinkTemplate(templateName, templateParams, templateRegex(templateName)); | |||
} | |||
if (wgAction == 'edit') | |||
addOnloadHook(createLinkTemplatesSelections); | |||
function knownLinkTemplates() { | function knownLinkTemplates() { | ||
| שורה 124: | שורה 165: | ||
]; | ]; | ||
var | var templatesDic = { | ||
"ynet": [1,2,3,4,5,0,], | "ynet": [1,2,3,4,5,0,], | ||
"הארץ": [1, 2, 3, 4], | "הארץ": [1, 2, 3, 4], | ||
| שורה 132: | שורה 173: | ||
"Mooma": [18], | "Mooma": [18], | ||
}; | }; | ||
for (var key in | for (var key in templatesDic) | ||
for (var i in | for (var i in templatesDic[key]) | ||
if (typeof( | if (typeof(templatesDic[key][i]) == "number") | ||
templatesDic[key][i] = constants[templatesDic[key][i]]; | |||
return | return templatesDic; | ||
} | } | ||