MediaWiki:Mobile.js: Difference between revisions

No edit summary
Tag: Reverted
Tags: Replaced Manual revert
 
Line 1: Line 1:
/* All JavaScript here will be loaded for users of the mobile site */
/* All JavaScript here will be loaded for users of the mobile site */
// 修复 Minerva 皮肤下 InputBox 首次点击被主搜索框抢焦点的问题
$( function () {
    // 等待页面基本就绪
    mw.loader.using( 'mediawiki.page.ready' ).then( function () {
        var $inputBox = $( '#homeSearchInput' );
        if ( $inputBox.length ) {
            // 当 InputBox 获得焦点时,立即让它“失焦”再重新聚焦,
            // 以此打断 Minerva 的焦点劫持流程。
            $inputBox.on( 'focus', function () {
                var self = this;
                // 使用 setTimeout 0 将操作推迟到当前事件循环之后,
                // 让 Minerva 的处理器先运行,然后我们再“抢回”焦点。
                setTimeout( function () {
                    self.blur();
                    self.focus();
                }, 0 );
            } );
        }
    } );
} );