2020-11-24 22:16:03 +00:00
|
|
|
/** @module search */
|
2021-11-05 22:53:34 +00:00
|
|
|
|
2020-11-19 17:12:53 +00:00
|
|
|
var
|
|
|
|
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-09-16 18:00:05 +00:00
|
|
|
* @param {Element} searchForm
|
2021-11-05 22:53:34 +00:00
|
|
|
* @return {void}
|
2020-11-19 17:12:53 +00:00
|
|
|
*/
|
2021-11-05 22:53:34 +00:00
|
|
|
function initApp( searchForm ) {
|
2021-09-16 18:00:05 +00:00
|
|
|
var
|
|
|
|
titleInput = /** @type {HTMLInputElement|null} */ (
|
|
|
|
searchForm.querySelector( 'input[name=title]' )
|
|
|
|
),
|
|
|
|
search = /** @type {HTMLInputElement|null} */ ( searchForm.querySelector( 'input[name="search"]' ) ),
|
|
|
|
searchPageTitle = titleInput && titleInput.value;
|
|
|
|
|
|
|
|
if ( !search || !titleInput ) {
|
|
|
|
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' ),
|
|
|
|
searchQuery: search.value
|
|
|
|
// 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 ) {
|
|
|
|
var
|
2021-09-28 16:27:10 +00:00
|
|
|
searchForms = document.querySelectorAll( '.vector-search-box-form' );
|
2021-09-09 21:40:06 +00:00
|
|
|
|
2021-11-05 22:53:34 +00:00
|
|
|
searchForms.forEach( function ( searchForm ) {
|
|
|
|
initApp( searchForm );
|
|
|
|
} );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
main( document );
|