MediaWiki:Minerva.js: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
 
(7 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 首次点击被主搜索框抢焦点的问题
// 针对 T402078/T410229 的改进方案:在 pointerdown 时记录目标,在焦点被抢后强制夺回
( function () {
    var inputBox = document.getElementById( 'homeSearchInput' );
    if ( !inputBox ) {
        return;
    }
    var targetInput = null;
    // 1. 在 pointerdown(早于 focus 事件)时,记录用户实际点击的目标输入框
    document.addEventListener( 'pointerdown', function ( event ) {
        if ( event.target === inputBox ) {
            targetInput = inputBox;
        } else {
            // 如果点击的是其他元素,清空记录,避免影响其他搜索框
            targetInput = null;
        }
    }, true ); // 使用捕获阶段,确保最先执行
    // 2. 在 focusin 事件中,检查焦点是否被错误地转移到了主搜索框
    document.addEventListener( 'focusin', function ( event ) {
        // 如果用户原本点击的是我们的输入框,但焦点现在却在别处
        if ( targetInput && event.target !== targetInput ) {
            // 强制将焦点夺回我们的输入框
            targetInput.focus();
            // 夺回后重置记录,避免重复触发
            targetInput = null;
        }
    }, true ); // 同样使用捕获阶段
} )();