MediaWiki:Minerva.js: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 41: Line 41:
             var group1 = [
             var group1 = [
                 { text: '3500Word', url: 'http://www.chinaenglish.com/index.php?title=3500Word' },
                 { text: '3500Word', url: 'http://www.chinaenglish.com/index.php?title=3500Word' },
                 { text: 'China Travel Phrases', url: 'http://viesz2.com' },
                { text: 'Coined Words', url: 'https://www.chinaenglish.com/index.php?title=Category:Coined_Words' },
                 { text: 'Africa Work Phrases', url: 'http://viesz3.com' }
                 { text: 'China Travel Phrases', url: 'https://www.chinaenglish.com/index.php?title=Category:China_Travel_Phrases' },
                 { text: 'Africa Work Phrases', url: 'https://www.chinaenglish.com/index.php?title=Category:Africa_Work_Phrases' }
             ];
             ];
             var group2 = [
             var group2 = [
                 { text: 'ZH Pros/Cons', url: 'http://www.chinaenglish.com/index.php?title=Category:ZH_Pros/Cons' },
                 { text: 'ZH Pros/Cons', url: 'http://www.chinaenglish.com/index.php?title=Category:ZH_Pros/Cons' },
                 { text: 'EN Pros/Cons', url: 'http://www.chinaenglish.com/index.php?title=Category:EN_ros/Cons' },
                 { text: 'EN Pros/Cons', url: 'http://www.chinaenglish.com/index.php?title=Category:EN_Pros/Cons' },
                 { text: 'Articles', url: 'http://www.chinaenglish.com/index.php?title=Category:Articles' }
                 { text: 'Articles', url: 'http://www.chinaenglish.com/index.php?title=Category:Articles' }
             ];
             ];
Line 81: Line 82:


//viesz88结束端
//viesz88结束端
// 修复 Minerva 皮肤下 InputBox 首次点击被主搜索框抢焦点的问题
( function () {
    // 仅在 Minerva 皮肤下执行
    if ( mw.config.get( 'skin' ) !== 'minerva' ) {
        return;
    }
    var customInputId = 'homeSearchInput';
    var originalFocus = HTMLInputElement.prototype.focus;
    // 重写所有 input 元素的 focus 方法
    HTMLInputElement.prototype.focus = function () {
        // 当前正在被聚焦的元素(this)如果不是我们的自定义搜索框
        if ( this.id !== customInputId ) {
            var active = document.activeElement;
            // 检查当前实际获得焦点的元素是否是我们的自定义搜索框
            if ( active && active.id === customInputId ) {
                // 如果是,说明有脚本(Minerva 组件)正试图从我们的输入框抢走焦点
                // 直接终止这次 focus 操作,不执行原始逻辑
                return;
            }
        }
        // 其他所有情况(例如正常点击主搜索框、页面初始化聚焦等),放行原始方法
        return originalFocus.apply( this, arguments );
    };
} )();