| 1 |
module.exports = function () { |
| 2 |
const mobile = require( 'mobile.startup' ); |
| 3 |
const SearchOverlay = mobile.search.SearchOverlay; |
| 4 |
const SearchGateway = mobile.search.SearchGateway; |
| 5 |
const overlayManager = mobile.getOverlayManager(); |
| 6 |
|
| 7 |
const $searchInput = $( '#searchInput' ); |
| 8 |
const placeholder = $searchInput.attr( 'placeholder' ); |
| 9 |
const defaultSearchPage = $searchInput.siblings( 'input[name=title]' ).val(); |
| 10 |
|
| 11 |
const $searchBar = $( '#searchInput, #searchIcon, .skin-minerva-search-trigger' ); |
| 12 |
const searchRoute = new RegExp( /\/search/ ); |
| 13 |
let searchOverlayInstance; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
if ( mw.config.get( 'skin' ) !== 'minerva' ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
function removeSearchOnPageLoad() { |
| 28 |
if ( searchRoute.test( overlayManager.router.getPath() ) ) { |
| 29 |
|
| 30 |
history.replaceState( '', document.title, window.location.pathname ); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
function getSearchOverlay() { |
| 35 |
if ( !searchOverlayInstance ) { |
| 36 |
searchOverlayInstance = new SearchOverlay( { |
| 37 |
router: overlayManager.router, |
| 38 |
gatewayClass: SearchGateway, |
| 39 |
api: new mw.Api(), |
| 40 |
autocapitalize: $searchInput.attr( 'autocapitalize' ), |
| 41 |
searchTerm: $searchInput.val(), |
| 42 |
placeholderMsg: placeholder, |
| 43 |
defaultSearchPage: defaultSearchPage |
| 44 |
} ); |
| 45 |
} |
| 46 |
return searchOverlayInstance; |
| 47 |
} |
| 48 |
|
| 49 |
removeSearchOnPageLoad(); |
| 50 |
overlayManager.add( searchRoute, getSearchOverlay ); |
| 51 |
|
| 52 |
|
| 53 |
$searchBar.prop( 'readonly', true ); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
$searchBar.on( 'touchstart click', ( ev ) => { |
| 62 |
ev.preventDefault(); |
| 63 |
overlayManager.router.navigate( '/search' ); |
| 64 |
} ); |
| 65 |
|
| 66 |
$searchBar.on( 'touchend', ( ev ) => { |
| 67 |
ev.preventDefault(); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
getSearchOverlay().showKeyboard(); |
| 76 |
} ); |
| 77 |
|
| 78 |
}; |