176,460
עריכות
מהדורה קמא (שיחה | תרומות) (רעיון שלי) תגית: שוחזרה |
מהדורה קמא (שיחה | תרומות) (אולי כך) תגית: שוחזרה |
||
שורה 22: | שורה 22: | ||
var anchors = {}; | var anchors = {}; | ||
// אסוף את כל | // אסוף את כל הופעות של {{עוגן|}} ואת הערך שלהן | ||
var match; | var match; | ||
while ((match = anchorRegex.exec(content)) !== null) { | while ((match = anchorRegex.exec(content)) !== null) { | ||
שורה 34: | שורה 34: | ||
anchors[key].replacements.push(match[0]); | anchors[key].replacements.push(match[0]); | ||
} | } | ||
var isFirstReplacement = true; // מסמן אם זו ההחלפה הראשונה | |||
$.each(anchors, function (key, data) { | $.each(anchors, function (key, data) { | ||
שורה 40: | שורה 42: | ||
var counter = 1; // מתחילים מהמספר הראשון | var counter = 1; // מתחילים מהמספר הראשון | ||
var templateToUse = (data.template === 'עוגן1' || data.template === 'anchor1') ? 'עוגן' : data.template; | var templateToUse = (data.template === 'עוגן1' || data.template === 'anchor1') ? 'עוגן' : data.template; | ||
data.replacements.forEach(function (replacement | data.replacements.slice(1).forEach(function (replacement) { // נתקן מההופעה השנייה והלאה | ||
if ( | if (!isFirstReplacement) { // רק אם אינו ההופעה הראשונה | ||
var newKey = key + counter; | var newKey = key + counter; | ||
var newReplacement = '{{' + templateToUse + '|' + key + counter + '|' + key + '}}'; | var newReplacement = '{{' + templateToUse + '|' + key + counter + '|' + key + '}}'; | ||
content = content.replace(replacement, newReplacement); | content = content.replace(replacement, newReplacement); | ||
counter++; | counter++; | ||
} else { | |||
isFirstReplacement = false; | |||
} | } | ||
}); | }); |