2020-11-24 22:16:03 +00:00
|
|
|
/** @module search */
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {HTMLElement} searchForm
|
|
|
|
* @param {HTMLInputElement} search
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function initApp( searchForm, search ) {
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue( {
|
2021-04-21 12:48:02 +00:00
|
|
|
el: searchForm,
|
2020-11-19 17:12:53 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Function} createElement
|
|
|
|
* @return {Vue.VNode}
|
|
|
|
*/
|
|
|
|
render: function ( createElement ) {
|
|
|
|
return createElement( App, {
|
2020-11-26 00:58:10 +00:00
|
|
|
props: $.extend( {
|
2020-11-19 17:12:53 +00:00
|
|
|
autofocusInput: search === document.activeElement,
|
|
|
|
action: searchForm.getAttribute( 'action' ),
|
|
|
|
searchAccessKey: search.getAttribute( 'accessKey' ),
|
|
|
|
searchTitle: search.getAttribute( 'title' ),
|
|
|
|
searchPlaceholder: search.getAttribute( 'placeholder' ),
|
|
|
|
searchQuery: search.value
|
2020-11-26 00:58:10 +00:00
|
|
|
},
|
|
|
|
// Pass additional config from server.
|
|
|
|
config
|
|
|
|
)
|
2020-11-19 17:12:53 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param {Document} document
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function main( document ) {
|
|
|
|
var
|
|
|
|
searchForm = /** @type {HTMLElement} */ ( document.querySelector( '#searchform' ) ),
|
|
|
|
search = /** @type {HTMLInputElement|null} */ ( document.getElementById( 'searchInput' ) );
|
|
|
|
if ( search && searchForm ) {
|
|
|
|
initApp( searchForm, search );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
main( document );
|