2020-11-24 22:16:03 +00:00
|
|
|
/** @module search */
|
2021-11-05 22:53:34 +00:00
|
|
|
|
2022-01-31 21:43:32 +00:00
|
|
|
const
|
2022-02-01 20:52:16 +00:00
|
|
|
Vue = require( 'vue' ),
|
2020-11-26 00:58:10 +00:00
|
|
|
App = require( './App.vue' ),
|
|
|
|
config = require( './config.json' );
|
2020-11-19 17:12:53 +00:00
|
|
|
|
|
|
|
/**
|
2021-12-16 03:13:56 +00:00
|
|
|
* @param {Element} searchBox
|
2021-11-05 22:53:34 +00:00
|
|
|
* @return {void}
|
2020-11-19 17:12:53 +00:00
|
|
|
*/
|
2021-12-16 03:13:56 +00:00
|
|
|
function initApp( searchBox ) {
|
2023-06-12 22:22:33 +00:00
|
|
|
const searchForm = searchBox.querySelector( '.cdx-search-input' ),
|
2021-09-16 18:00:05 +00:00
|
|
|
titleInput = /** @type {HTMLInputElement|null} */ (
|
2021-12-16 03:13:56 +00:00
|
|
|
searchBox.querySelector( 'input[name=title]' )
|
2021-09-16 18:00:05 +00:00
|
|
|
),
|
2022-09-30 16:25:35 +00:00
|
|
|
search = /** @type {HTMLInputElement|null} */ ( searchBox.querySelector( 'input[name=search]' ) ),
|
2023-05-24 19:39:52 +00:00
|
|
|
searchPageTitle = titleInput && titleInput.value,
|
|
|
|
searchContainer = searchBox.querySelector( '.vector-typeahead-search-container' );
|
2021-09-16 18:00:05 +00:00
|
|
|
|
2021-12-16 03:13:56 +00:00
|
|
|
if ( !searchForm || !search || !titleInput ) {
|
2021-09-16 18:00:05 +00:00
|
|
|
throw new Error( 'Attempted to create Vue search element from an incompatible element.' );
|
|
|
|
}
|
|
|
|
|
2023-03-28 18:45:35 +00:00
|
|
|
// @ts-ignore MediaWiki-specific function
|
2021-11-05 22:53:34 +00:00
|
|
|
Vue.createMwApp(
|
2023-04-12 22:37:36 +00:00
|
|
|
App, Object.assign( {
|
2021-09-16 18:00:05 +00:00
|
|
|
id: searchForm.id,
|
2022-10-26 20:22:06 +00:00
|
|
|
autocapitalizeValue: search.getAttribute( 'autocapitalize' ),
|
2021-09-16 18:00:05 +00:00
|
|
|
autofocusInput: search === document.activeElement,
|
|
|
|
action: searchForm.getAttribute( 'action' ),
|
|
|
|
searchAccessKey: search.getAttribute( 'accessKey' ),
|
|
|
|
searchPageTitle: searchPageTitle,
|
|
|
|
searchTitle: search.getAttribute( 'title' ),
|
|
|
|
searchPlaceholder: search.getAttribute( 'placeholder' ),
|
2021-12-16 03:13:56 +00:00
|
|
|
searchQuery: search.value,
|
|
|
|
autoExpandWidth: searchBox ? searchBox.classList.contains( 'vector-search-box-auto-expand-width' ) : false
|
2021-09-16 18:00:05 +00:00
|
|
|
// Pass additional config from server.
|
2021-11-05 22:53:34 +00:00
|
|
|
}, config )
|
|
|
|
)
|
2023-06-12 22:22:33 +00:00
|
|
|
.mount( searchContainer );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param {Document} document
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function main( document ) {
|
2022-09-30 16:25:35 +00:00
|
|
|
document.querySelectorAll( '.vector-search-box' )
|
|
|
|
.forEach( initApp );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
main( document );
|