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
|
2020-11-19 17:12:53 +00:00
|
|
|
Vue = require( 'vue' ).default || 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 ) {
|
2022-01-31 21:43:32 +00:00
|
|
|
const searchForm = searchBox.querySelector( '.vector-search-box-form' ),
|
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
|
|
|
),
|
2021-12-16 03:13:56 +00:00
|
|
|
search = /** @type {HTMLInputElement|null} */ ( searchBox.querySelector( 'input[name="search"]' ) ),
|
2021-09-16 18:00:05 +00:00
|
|
|
searchPageTitle = titleInput && titleInput.value;
|
|
|
|
|
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.' );
|
|
|
|
}
|
|
|
|
|
2021-11-05 22:53:34 +00:00
|
|
|
// @ts-ignore
|
|
|
|
Vue.createMwApp(
|
|
|
|
App, $.extend( {
|
2021-09-16 18:00:05 +00:00
|
|
|
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' ),
|
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 )
|
|
|
|
)
|
2021-12-01 22:32:13 +00:00
|
|
|
.mount( searchForm.parentNode );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param {Document} document
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function main( document ) {
|
2022-01-31 21:43:32 +00:00
|
|
|
const searchBoxes = document.querySelectorAll( '.vector-search-box' );
|
2021-09-09 21:40:06 +00:00
|
|
|
|
2022-01-31 21:43:32 +00:00
|
|
|
searchBoxes.forEach( ( searchBox ) => {
|
2021-12-16 03:13:56 +00:00
|
|
|
initApp( searchBox );
|
2021-11-05 22:53:34 +00:00
|
|
|
} );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
main( document );
|