mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-23 13:12:44 +00:00
24d69726f3
Performance: This reclaims 1.3kb of CSS. Bug: T336526 Change-Id: I6c1ed1523df8cc9e2f2ca09506f12a595b8b013d
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
/** @module search */
|
|
|
|
const
|
|
Vue = require( 'vue' ),
|
|
App = require( './App.vue' ),
|
|
config = require( './config.json' );
|
|
|
|
/**
|
|
* @param {Element} searchBox
|
|
* @return {void}
|
|
*/
|
|
function initApp( searchBox ) {
|
|
const searchForm = searchBox.querySelector( '.cdx-search-input' ),
|
|
titleInput = /** @type {HTMLInputElement|null} */ (
|
|
searchBox.querySelector( 'input[name=title]' )
|
|
),
|
|
search = /** @type {HTMLInputElement|null} */ ( searchBox.querySelector( 'input[name=search]' ) ),
|
|
searchPageTitle = titleInput && titleInput.value,
|
|
searchContainer = searchBox.querySelector( '.vector-typeahead-search-container' );
|
|
|
|
if ( !searchForm || !search || !titleInput ) {
|
|
throw new Error( 'Attempted to create Vue search element from an incompatible element.' );
|
|
}
|
|
|
|
// @ts-ignore MediaWiki-specific function
|
|
Vue.createMwApp(
|
|
App, Object.assign( {
|
|
id: searchForm.id,
|
|
autocapitalizeValue: search.getAttribute( 'autocapitalize' ),
|
|
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( searchContainer );
|
|
}
|
|
/**
|
|
* @param {Document} document
|
|
* @return {void}
|
|
*/
|
|
function main( document ) {
|
|
document.querySelectorAll( '.vector-search-box' )
|
|
.forEach( initApp );
|
|
}
|
|
main( document );
|