MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More languages
More actions
Content deleted Content added
OHC identity seed Tag: Reverted |
OHC identity seed Tag: Manual revert |
||
| Line 104: | Line 104: | ||
} |
} |
||
} ); |
} ); |
||
} |
|||
} ); |
|||
/** |
|||
* Main Page search trigger — opens Citizen's native search drawer. |
|||
* The #ohc-main-search div on the Main Page acts as a visual CTA; |
|||
* clicking it programmatically opens the skin's search details element. |
|||
*/ |
|||
mw.loader.using( 'mediawiki.util' ).then( function () { |
|||
'use strict'; |
|||
function initSearch() { |
|||
var trigger = document.getElementById( 'ohc-main-search' ); |
|||
if ( !trigger ) { return; } |
|||
function openSearch() { |
|||
var details = document.getElementById( 'citizen-search-details' ); |
|||
if ( details ) { |
|||
details.open = true; |
|||
setTimeout( function () { |
|||
var input = document.getElementById( 'searchInput' ); |
|||
if ( input ) { input.focus(); } |
|||
}, 100 ); |
|||
} |
|||
} |
|||
trigger.addEventListener( 'click', openSearch ); |
|||
trigger.addEventListener( 'keydown', function ( e ) { |
|||
if ( e.key === 'Enter' || e.key === ' ' ) { |
|||
e.preventDefault(); |
|||
openSearch(); |
|||
} |
|||
} ); |
|||
// Bind "/" keyboard shortcut on main page |
|||
if ( mw.config.get( 'wgIsMainPage' ) ) { |
|||
document.addEventListener( 'keydown', function ( e ) { |
|||
if ( e.key === '/' && !e.ctrlKey && !e.metaKey && !e.altKey ) { |
|||
var active = document.activeElement; |
|||
if ( active && ( active.tagName === 'INPUT' || active.tagName === 'TEXTAREA' || active.isContentEditable ) ) { |
|||
return; |
|||
} |
|||
e.preventDefault(); |
|||
openSearch(); |
|||
} |
|||
} ); |
|||
} |
|||
} |
|||
// Ensure DOM is ready |
|||
if ( document.readyState === 'loading' ) { |
|||
document.addEventListener( 'DOMContentLoaded', initSearch ); |
|||
} else { |
|||
initSearch(); |
|||
} |
} |
||
} ); |
} ); |
||