MediaWiki:Common.js: Difference between revisions

From The Radical Buddhism Project
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* =====================================================================
/* =====================================================================
   RADICAL BUDDHIST PROJECT - AUTOMATED DESKTOP CATEGORY GENERATOR
   FOOTNOTE POPUPS
   ===================================================================== */
   ===================================================================== */
$(document).ready(function() {
$(function() {
     var catLinks = $('.mw-normal-catlinks a, .catlinks a');
     $('.reference').each(function() {
    if (catLinks.length > 0 && $('#custom-cat-tray').length === 0) {
        var $refLink = $(this);
         var trayHtml = '<div id="custom-cat-tray" style="margin: 40px 0 20px 0; padding: 15px 20px; background-color: #f0f2f4; border: 1px solid #d0d4d8; font-family: sans-serif; font-size: 0.85em; color: #222222;"><strong>Categories:</strong> ';
         var targetId = $refLink.find('a').attr('href');
          
          
         catLinks.each(function(index) {
         if (targetId && targetId.indexOf('#') === 0) {
             var text = $(this).text();
             var $footnoteElement = $(decodeURIComponent(targetId));
             var href = $(this).attr('href');
              
            if (text !== 'Categories' && text !== 'カテゴリ') {
            if ($footnoteElement.length) {
                 if (index > 1) trayHtml += ' <span style="color: #d0d4d8; margin: 0 8px;">|</span> ';
                // Extracts the raw text content of the citation, stripping the default backlink arrow
                 trayHtml += '<a href="' + href + '" style="color: #222222; text-decoration: none;">' + text + '</a>';
                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'
                    });
                });
             }
             }
         });
         }
       
    });
        trayHtml += '</div>';
        $('.mw-body-content, #bodyContent').append(trayHtml);
    }
});
});

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'
                    });
                });
            }
        }
    });
});