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
|
|
|
|
|
|
|
/**
|
2021-09-16 18:00:05 +00:00
|
|
|
* @param {Function} createElement
|
|
|
|
* @param {Element} searchForm
|
|
|
|
* @return {Vue.VNode}
|
|
|
|
* @throws {Error} if the searchForm does not
|
|
|
|
* contain input[name=title] and input[name="search"] elements.
|
2020-11-19 17:12:53 +00:00
|
|
|
*/
|
2021-09-16 18:00:05 +00:00
|
|
|
function renderFn( createElement, searchForm ) {
|
|
|
|
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.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return createElement( App, {
|
|
|
|
props: $.extend( {
|
|
|
|
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.
|
|
|
|
config
|
|
|
|
)
|
2020-11-19 17:12:53 +00:00
|
|
|
} );
|
2021-09-16 18:00:05 +00:00
|
|
|
}
|
2021-09-09 21:40:06 +00:00
|
|
|
|
2021-09-16 18:00:05 +00:00
|
|
|
/**
|
|
|
|
* @param {NodeList} searchForms
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function initApp( searchForms ) {
|
|
|
|
searchForms.forEach( function ( searchForm ) {
|
2021-09-09 21:40:06 +00:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue( {
|
2021-09-16 18:00:05 +00:00
|
|
|
el: /** @type {Element} */ ( searchForm ),
|
2021-09-09 21:40:06 +00:00
|
|
|
render: function ( createElement ) {
|
2021-09-16 18:00:05 +00:00
|
|
|
return renderFn( createElement, /** @type {Element} */ ( searchForm ) );
|
2021-09-09 21:40:06 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
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-09-16 18:00:05 +00:00
|
|
|
initApp( searchForms );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
main( document );
|