MediaWiki:Minerva.js: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
Tags: Reverted Mobile edit Mobile web edit
Line 83: Line 83:


// 修复 Minerva 皮肤下 InputBox 首次点击被主搜索框抢焦点的问题
// 修复 Minerva 皮肤下 InputBox 首次点击被主搜索框抢焦点的问题
// 从自定义 InputBox 上移除 mw-searchInput 类,防止被 Minerva 搜索组件劫持
( function () {
( function () {
     var inputBox = document.getElementById( 'homeSearchInput' );
    // 保存原始的模块加载方法
     if ( inputBox ) {
     var originalLoad = mw.loader.load;
         // 移除触发 Minerva 焦点劫持的类
 
         inputBox.classList.remove( 'mw-searchInput' );
     // 重写加载方法,加入针对性的拦截逻辑
        // 确保 id 也不是 'searchInput',虽然目前不是,但作为防御性措施
    mw.loader.load = function ( moduleName ) {
        if ( inputBox.id === 'searchInput' ) {
         // 当尝试加载 Minerva 搜索模块,并且当前焦点在自定义搜索框上时,直接跳过加载
             inputBox.id = 'homeSearchInput';
         if ( moduleName === 'skins.minerva.search' &&
            document.activeElement &&
            document.activeElement.id === 'homeSearchInput' ) {
             // 返回一个已解决的 Promise,避免调用方出错,但模块实际未被加载
            return Promise.resolve();
         }
         }
     }
        // 其他所有情况,都正常调用原始的加载方法
        return originalLoad.apply( this, arguments );
     };
} )();
} )();