משתמש:מהדורה קמא/בדיקת עוגנים.js: הבדלים בין גרסאות בדף

קפיצה לניווט קפיצה לחיפוש
(רעיון שלי)
תגית: שוחזרה
(אולי כך)
תגית: שוחזרה
שורה 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, index) { // נתקן מההופעה השנייה והלאה
       data.replacements.slice(1).forEach(function (replacement) { // נתקן מההופעה השנייה והלאה
         if (index > 1) { // רק אם אנחנו לא בהופעה הראשונה
         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;
         }
         }
       });
       });