MediaWiki:Common.js: Difference between revisions

From The Radical Buddhism Project
Tag: Replaced
No edit summary
 
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* =====================================================================
  FOOTNOTE POPUPS
  ===================================================================== */
$(function() {
    $('.reference').each(function() {
        var $refLink = $(this);
        var targetId = $refLink.find('a').attr('href');
       
        if (targetId && targetId.indexOf('#') === 0) {
            var $footnoteElement = $(decodeURIComponent(targetId));
           
            if ($footnoteElement.length) {
                // Extracts the raw text content of the citation, stripping the default backlink arrow
                var footnoteText = $footnoteElement.find('.mw-reference-text').html() || $footnoteElement.text();
               
                // Construct the floating tip container box
                var $popup = $('<div class="custom-ref-popup"></div>').html(footnoteText).hide().appendTo('body');
               
                $refLink.hover(
                    function(e) {
                        $popup.css({
                            top: (e.pageY + 15) + 'px',
                            left: Math.min(e.pageX + 10, $(window).width() - 320) + 'px'
                        }).fadeIn(100);
                    },
                    function() {
                        $popup.fadeOut(100);
                    }
                );
               
                // Track mouse movement for smooth baseline hover positioning
                $refLink.mousemove(function(e) {
                    $popup.css({
                        top: (e.pageY + 15) + 'px',
                        left: Math.min(e.pageX + 10, $(window).width() - 320) + 'px'
                    });
                });
            }
        }
    });
});

Latest revision as of 23:35, 24 July 2026

/* =====================================================================
   FOOTNOTE POPUPS
   ===================================================================== */
$(function() {
    $('.reference').each(function() {
        var $refLink = $(this);
        var targetId = $refLink.find('a').attr('href');
        
        if (targetId && targetId.indexOf('#') === 0) {
            var $footnoteElement = $(decodeURIComponent(targetId));
            
            if ($footnoteElement.length) {
                // Extracts the raw text content of the citation, stripping the default backlink arrow
                var footnoteText = $footnoteElement.find('.mw-reference-text').html() || $footnoteElement.text();
                
                // Construct the floating tip container box
                var $popup = $('<div class="custom-ref-popup"></div>').html(footnoteText).hide().appendTo('body');
                
                $refLink.hover(
                    function(e) {
                        $popup.css({
                            top: (e.pageY + 15) + 'px',
                            left: Math.min(e.pageX + 10, $(window).width() - 320) + 'px'
                        }).fadeIn(100);
                    },
                    function() {
                        $popup.fadeOut(100);
                    }
                );
                
                // Track mouse movement for smooth baseline hover positioning
                $refLink.mousemove(function(e) {
                    $popup.css({
                        top: (e.pageY + 15) + 'px',
                        left: Math.min(e.pageX + 10, $(window).width() - 320) + 'px'
                    });
                });
            }
        }
    });
});