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
|
2021-07-28 16:15:57 +00:00
|
|
|
* @param {string|null} searchPageTitle title of page used for searching e.g. Special:Search
|
|
|
|
* If null then this will default to Special:Search.
|
2020-11-19 17:12:53 +00:00
|
|
|
* @return {void}
|
|
|
|
*/
|
2021-07-28 16:15:57 +00:00
|
|
|
function initApp( searchForm, search, searchPageTitle ) {
|
2020-11-19 17:12:53 +00:00
|
|
|
// 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' ),
|
2021-07-28 16:15:57 +00:00
|
|
|
searchPageTitle: searchPageTitle,
|
2020-11-19 17:12:53 +00:00
|
|
|
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' ) ),
|
2021-07-28 16:15:57 +00:00
|
|
|
titleInput = /** @type {HTMLInputElement|null} */ (
|
|
|
|
searchForm.querySelector( 'input[name=title]' )
|
|
|
|
),
|
2020-11-19 17:12:53 +00:00
|
|
|
search = /** @type {HTMLInputElement|null} */ ( document.getElementById( 'searchInput' ) );
|
|
|
|
if ( search && searchForm ) {
|
2021-07-28 16:15:57 +00:00
|
|
|
initApp( searchForm, search, titleInput && titleInput.value );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
main( document );
|