2017-07-12 15:12:40 +00:00
|
|
|
( function ( M, $ ) {
|
2018-03-28 17:54:10 +00:00
|
|
|
var placeholder = $( '#searchInput' ).attr( 'placeholder' ),
|
|
|
|
SearchOverlay = M.require( 'mobile.search/SearchOverlay' ),
|
2017-07-12 15:12:40 +00:00
|
|
|
SearchGateway = M.require( 'mobile.search.api/SearchGateway' ),
|
|
|
|
router = require( 'mediawiki.router' ),
|
2017-08-28 20:13:10 +00:00
|
|
|
searchLogger = M.require( 'mobile.search/MobileWebSearchLogger' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reveal the search overlay
|
|
|
|
* @param {jQuery.Event} ev
|
|
|
|
* @event mobilefrontend.searchModule
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function openSearchOverlay( ev ) {
|
|
|
|
var overlay,
|
|
|
|
$this = $( this ),
|
2018-03-28 17:54:10 +00:00
|
|
|
searchTerm = $this.val();
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
ev.preventDefault();
|
|
|
|
// The loading of SearchOverlay should never be done inside a callback
|
|
|
|
// as this will result in issues with input focus
|
|
|
|
// see https://phabricator.wikimedia.org/T156508#2977463
|
|
|
|
overlay = new SearchOverlay( {
|
|
|
|
router: router,
|
|
|
|
gatewayClass: SearchGateway,
|
|
|
|
api: new mw.Api(),
|
|
|
|
searchTerm: searchTerm,
|
|
|
|
placeholderMsg: placeholder
|
|
|
|
} );
|
|
|
|
searchLogger.register( overlay );
|
|
|
|
overlay.show();
|
|
|
|
router.navigate( '/search' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only continue on mobile devices as it breaks desktop search
|
|
|
|
// See https://phabricator.wikimedia.org/T108432
|
|
|
|
if ( mw.config.get( 'skin' ) !== 'minerva' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-28 20:13:10 +00:00
|
|
|
// don't use focus event (https://bugzilla.wikimedia.org/show_bug.cgi?id=47499)
|
|
|
|
//
|
|
|
|
// focus() (see SearchOverlay#show) opens virtual keyboard only if triggered
|
|
|
|
// from user context event, so using it in route callback won't work
|
|
|
|
// http://stackoverflow.com/questions/6837543/show-virtual-keyboard-on-mobile-phones-in-javascript
|
2018-03-09 18:12:04 +00:00
|
|
|
$( '#searchInput, #searchIcon, .skin-minerva-search-trigger' ).on( 'click', openSearchOverlay )
|
2017-08-28 20:13:10 +00:00
|
|
|
// Apparently needed for main menu to work correctly.
|
|
|
|
.prop( 'readonly', true );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
}( mw.mobileFrontend, jQuery ) );
|