MediaWiki

EventList.js:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
 
(未显示同一用户的4个中间版本)
第1行: 第1行:
$(function() {
$(function() {
mw.loader.load( mw.util.getUrl( 'MediaWiki:EventList.css', { action: 'raw', ctype: 'text/css' } ), 'text/css' );
    mw.loader.load(mw.util.getUrl('MediaWiki:EventList.css', { action: 'raw', ctype: 'text/css' }), 'text/css');
     // 为每个事件选项添加点击事件
 
     $('.event-option').click(function() {
     // 计算并设置容器高度
         var $this = $(this);
     function calculateHeight($container) {
        var optionIndex = $this.data('option-index');
         var baseHeight = 170; // 基础高度(到选项区域顶部)
        var $container = $this.closest('.event-container');
         var totalHeight = baseHeight;
         var $effect = $container.find('.event-effect[data-effect-index="' + optionIndex + '"]');
          
          
         // 切换active状态
         // 计算选项容器内所有内容的实际高度
         if ($this.hasClass('active')) {
         var $optionsContainer = $container.find('.event-options');
            // 如果已经是active,则隐藏效果并移除active
            $this.removeClass('active');
            $effect.slideUp(200, function() {
                adjustContainerHeight($container);
            });
        } else {
            // 隐藏同一事件中其他选项的效果
            $container.find('.event-option').removeClass('active');
            $container.find('.event-effect').slideUp(200);
           
            // 显示当前选项的效果
            $this.addClass('active');
            $effect.slideDown(200, function() {
                adjustContainerHeight($container);
            });
        }
    });
   
    // 调整容器高度的函数
    function adjustContainerHeight($container) {
        var totalHeight = 170; // 基础高度(到选项开始的位置)
        var backgroundHeight = 10; // 背景底部padding
          
          
         // 计算所有可见元素的高度
         // 遍历选项容器内的所有子元素(包括选项和效果)
         $container.find('.event-option, .event-effect:visible').each(function() {
         $optionsContainer.children().each(function() {
             totalHeight += $(this).outerHeight(true);
             totalHeight += $(this).outerHeight(true); // 包含 margin
         });
         });
          
          
         // 额外添加一些底部空间
         // 添加底部间距
         totalHeight += 10;
         totalHeight += 15;
          
          
         // 设置容器和背景的高度
         // 设置容器最小高度
         $container.css('min-height', totalHeight + 'px');
         $container.css('min-height', totalHeight + 'px');
         $container.find('.event-background').css('height', (totalHeight - 160) + 'px');
       
        // 背景高度 = 总高度 - 顶部偏移(160px)
        var bgHeight = totalHeight - 160;
         $container.find('.event-background').css('height', bgHeight + 'px');
     }
     }
      
      
     // 初始化时调整所有容器的高度
     // 初始化时计算所有容器的高度
     $('.event-container').each(function() {
     // 使用延迟确保图片和内容已加载
         adjustContainerHeight($(this));
    function initializeHeights() {
        $('.event-container').each(function() {
            calculateHeight($(this));
         });
    }
   
    // 页面加载完成后初始化
    initializeHeights();
   
    // 图片加载完成后重新计算
    $('.event-image img').on('load', function() {
        initializeHeights();
    });
   
    // 监听窗口大小变化,重新计算高度
    var resizeTimer;
    $(window).on('resize', function() {
        clearTimeout(resizeTimer);
        resizeTimer = setTimeout(function() {
            initializeHeights();
        }, 250); // 防抖处理
     });
     });
   
    // 使用 MutationObserver 监听内容变化
    if (window.MutationObserver) {
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                var $container = $(mutation.target).closest('.event-container');
                if ($container.length) {
                    calculateHeight($container);
                }
            });
        });
       
        $('.event-container').each(function() {
            observer.observe(this, {
                childList: true,
                subtree: true,
                characterData: true
            });
        });
    }
});
});

2025年10月18日 (六) 13:41的最新版本

$(function() {
    mw.loader.load(mw.util.getUrl('MediaWiki:EventList.css', { action: 'raw', ctype: 'text/css' }), 'text/css');

    // 计算并设置容器高度
    function calculateHeight($container) {
        var baseHeight = 170; // 基础高度(到选项区域顶部)
        var totalHeight = baseHeight;
        
        // 计算选项容器内所有内容的实际高度
        var $optionsContainer = $container.find('.event-options');
        
        // 遍历选项容器内的所有子元素(包括选项和效果)
        $optionsContainer.children().each(function() {
            totalHeight += $(this).outerHeight(true); // 包含 margin
        });
        
        // 添加底部间距
        totalHeight += 15;
        
        // 设置容器最小高度
        $container.css('min-height', totalHeight + 'px');
        
        // 背景高度 = 总高度 - 顶部偏移(160px)
        var bgHeight = totalHeight - 160;
        $container.find('.event-background').css('height', bgHeight + 'px');
    }
    
    // 初始化时计算所有容器的高度
    // 使用延迟确保图片和内容已加载
    function initializeHeights() {
        $('.event-container').each(function() {
            calculateHeight($(this));
        });
    }
    
    // 页面加载完成后初始化
    initializeHeights();
    
    // 图片加载完成后重新计算
    $('.event-image img').on('load', function() {
        initializeHeights();
    });
    
    // 监听窗口大小变化,重新计算高度
    var resizeTimer;
    $(window).on('resize', function() {
        clearTimeout(resizeTimer);
        resizeTimer = setTimeout(function() {
            initializeHeights();
        }, 250); // 防抖处理
    });
    
    // 使用 MutationObserver 监听内容变化
    if (window.MutationObserver) {
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                var $container = $(mutation.target).closest('.event-container');
                if ($container.length) {
                    calculateHeight($container);
                }
            });
        });
        
        $('.event-container').each(function() {
            observer.observe(this, {
                childList: true,
                subtree: true,
                characterData: true
            });
        });
    }
});