mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-28 17:40:12 +00:00
3028a4f9d8
In preparation for I30c670e3f195f77a27715c6b494a3088b7a55712, refactor the search component expand behavior so that it can accomodate the new changes in WVUI while maintaining backwards compatibility with the status quo. Additionally, pass/enable the `auto-expand-width` prop to the main header's search. This will be inert until the new changes in WVUI have landed. Bug: T297531 Change-Id: Id8d3bd4aa74113b91ecaf66cb58cf5625db8a302
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
/** @module search */
|
|
|
|
var
|
|
Vue = require( 'vue' ).default || require( 'vue' ),
|
|
App = require( './App.vue' ),
|
|
config = require( './config.json' );
|
|
|
|
/**
|
|
* @param {Element} searchBox
|
|
* @return {void}
|
|
*/
|
|
function initApp( searchBox ) {
|
|
var searchForm = searchBox.querySelector( '.vector-search-box-form' ),
|
|
titleInput = /** @type {HTMLInputElement|null} */ (
|
|
searchBox.querySelector( 'input[name=title]' )
|
|
),
|
|
search = /** @type {HTMLInputElement|null} */ ( searchBox.querySelector( 'input[name="search"]' ) ),
|
|
searchPageTitle = titleInput && titleInput.value;
|
|
|
|
if ( !searchForm || !search || !titleInput ) {
|
|
throw new Error( 'Attempted to create Vue search element from an incompatible element.' );
|
|
}
|
|
|
|
// @ts-ignore
|
|
Vue.createMwApp(
|
|
App, $.extend( {
|
|
id: searchForm.id,
|
|
autofocusInput: search === document.activeElement,
|
|
action: searchForm.getAttribute( 'action' ),
|
|
searchAccessKey: search.getAttribute( 'accessKey' ),
|
|
searchPageTitle: searchPageTitle,
|
|
searchTitle: search.getAttribute( 'title' ),
|
|
searchPlaceholder: search.getAttribute( 'placeholder' ),
|
|
searchQuery: search.value,
|
|
autoExpandWidth: searchBox ? searchBox.classList.contains( 'vector-search-box-auto-expand-width' ) : false
|
|
// Pass additional config from server.
|
|
}, config )
|
|
)
|
|
.mount( searchForm.parentNode );
|
|
}
|
|
/**
|
|
* @param {Document} document
|
|
* @return {void}
|
|
*/
|
|
function main( document ) {
|
|
var searchBoxes = document.querySelectorAll( '.vector-search-box' );
|
|
|
|
searchBoxes.forEach( function ( searchBox ) {
|
|
initApp( searchBox );
|
|
} );
|
|
}
|
|
main( document );
|