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
|
2021-09-09 21:40:06 +00:00
|
|
|
* @param {NodeList} secondarySearchElements
|
2020-11-19 17:12:53 +00:00
|
|
|
* @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-09-09 21:40:06 +00:00
|
|
|
function initApp( searchForm, secondarySearchElements, search, searchPageTitle ) {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
* @param {Function} createElement
|
|
|
|
* @param {string} id
|
|
|
|
* @return {Vue.VNode}
|
|
|
|
*/
|
|
|
|
var renderFn = function ( createElement, id ) {
|
|
|
|
return createElement( App, {
|
|
|
|
props: $.extend( {
|
|
|
|
id: 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
|
|
|
// 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
|
|
|
render: function ( createElement ) {
|
2021-09-09 21:40:06 +00:00
|
|
|
return renderFn( createElement, 'searchform' );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
} );
|
2021-09-09 21:40:06 +00:00
|
|
|
|
|
|
|
// Initialize secondary search elements like the search in the sticky header.
|
|
|
|
Array.prototype.forEach.call( secondarySearchElements, function ( secondarySearchElement ) {
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue( {
|
|
|
|
el: secondarySearchElement,
|
|
|
|
render: function ( createElement ) {
|
|
|
|
return renderFn( createElement, secondarySearchElement.id );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
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]' )
|
|
|
|
),
|
2021-09-09 21:40:06 +00:00
|
|
|
search = /** @type {HTMLInputElement|null} */ ( document.getElementById( 'searchInput' ) ),
|
|
|
|
// Since App.vue requires a unique id prop, only query elements with an id attribute.
|
|
|
|
secondarySearchElements = document.querySelectorAll( '.vector-secondary-search[id]' );
|
|
|
|
|
2020-11-19 17:12:53 +00:00
|
|
|
if ( search && searchForm ) {
|
2021-09-09 21:40:06 +00:00
|
|
|
initApp( searchForm, secondarySearchElements, search, titleInput && titleInput.value );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
main( document );
|