מדיה ויקי:Common.js: הבדלים בין גרסאות בדף

מתוך אוצר מהרי''ט
קפיצה לניווט קפיצה לחיפוש
אין תקציר עריכה
אין תקציר עריכה
שורה 1: שורה 1:
// הקוד הקיים
(function () {
    var userLang = mw.config.get('wgUserLanguage');
    var pageName = mw.config.get('wgPageName');
    if (pageName === 'רבי_יואל_טייטלבוים' && userLang === 'yi') {
        window.location.href = mw.util.getUrl('רבי_יואל_טייטלבוים/yi');
    }
    if (pageName === 'רבי_יואל_טייטלבוים/yi' && userLang === 'he') {
        window.location.href = mw.util.getUrl('רבי_יואל_טייטלבוים');
    }
})();
// הקוד החדש לתוכן העניינים
$(document).ready(function() {
$(document).ready(function() {
     const toc = document.querySelector('#toc');
     const $toc = $('#toc');
     const headers = document.querySelectorAll('h2, h3');
     const $headers = $('h2, h3');
     const tocLinks = document.querySelectorAll('#toc a');
     const $tocLinks = $('#toc a');
      
      
     $(window).on('scroll', function() {
     function updateTocPosition() {
         const headerHeight = $('#firstHeading').outerHeight();
         const headerHeight = $('#firstHeading').outerHeight();
       
         if ($(window).scrollTop() > headerHeight) {
         if ($(window).scrollTop() > headerHeight) {
             toc.style.top = '0px';
             $toc.css('top', '0px');
         } else {
         } else {
             toc.style.top = '220px';
             $toc.css('top', '220px');
         }
         }
     });
     }


     $(window).on('scroll', function() {
     function highlightCurrentSection() {
         let currentSection = '';
         let currentSection = '';
          
         $headers.each(function() {
        headers.forEach(header => {
             if ($(window).scrollTop() >= $(this).offset().top - 100) {
            const sectionTop = header.offsetTop;
                 currentSection = this.id;
             if ($(window).scrollTop() >= sectionTop - 100) {
                 currentSection = header.id;
             }
             }
         });
         });
       
 
         tocLinks.forEach(link => {
         $tocLinks.removeClass('toc-highlight');
            link.classList.remove('toc-highlight');
        $tocLinks.each(function() {
             if (link.getAttribute('href').slice(1) === currentSection) {
             if ($(this).attr('href').slice(1) === currentSection) {
                 link.classList.add('toc-highlight');
                 $(this).addClass('toc-highlight');
             }
             }
         });
         });
    }
    $(window).on('scroll', function() {
        updateTocPosition();
        highlightCurrentSection();
     });
     });
    updateTocPosition(); // קריאה ראשונית כדי לקבוע את המיקום בתחילת הטעינה
});
});

גרסה מ־18:24, 3 בפברואר 2025

$(document).ready(function() {
    const $toc = $('#toc');
    const $headers = $('h2, h3');
    const $tocLinks = $('#toc a');
    
    function updateTocPosition() {
        const headerHeight = $('#firstHeading').outerHeight();
        if ($(window).scrollTop() > headerHeight) {
            $toc.css('top', '0px');
        } else {
            $toc.css('top', '220px');
        }
    }

    function highlightCurrentSection() {
        let currentSection = '';
        $headers.each(function() {
            if ($(window).scrollTop() >= $(this).offset().top - 100) {
                currentSection = this.id;
            }
        });

        $tocLinks.removeClass('toc-highlight');
        $tocLinks.each(function() {
            if ($(this).attr('href').slice(1) === currentSection) {
                $(this).addClass('toc-highlight');
            }
        });
    }

    $(window).on('scroll', function() {
        updateTocPosition();
        highlightCurrentSection();
    });

    updateTocPosition(); // קריאה ראשונית כדי לקבוע את המיקום בתחילת הטעינה
});