mediawiki-skins-Vector/resources/skins.vector.search/skins.vector.search.js
jdlrobson aebb3fb522 Use the search title if configured
Allow commons to use Special:MediaSearch

Depends-On: 	I37b9d3a2b263f496a283f4bfdc769b7dc880ab06
Bug: T287540
Change-Id: I2a2463d704ef5b2264574cdf186836ba00a639f5
2021-08-05 15:45:41 +00:00

57 lines
1.6 KiB
JavaScript

/** @module search */
var
Vue = require( 'vue' ).default || require( 'vue' ),
App = require( './App.vue' ),
config = require( './config.json' );
/**
* @param {HTMLElement} searchForm
* @param {HTMLInputElement} search
* @param {string|null} searchPageTitle title of page used for searching e.g. Special:Search
* If null then this will default to Special:Search.
* @return {void}
*/
function initApp( searchForm, search, searchPageTitle ) {
// eslint-disable-next-line no-new
new Vue( {
el: searchForm,
/**
*
* @param {Function} createElement
* @return {Vue.VNode}
*/
render: function ( createElement ) {
return createElement( App, {
props: $.extend( {
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
)
} );
}
} );
}
/**
* @param {Document} document
* @return {void}
*/
function main( document ) {
var
searchForm = /** @type {HTMLElement} */ ( document.querySelector( '#searchform' ) ),
titleInput = /** @type {HTMLInputElement|null} */ (
searchForm.querySelector( 'input[name=title]' )
),
search = /** @type {HTMLInputElement|null} */ ( document.getElementById( 'searchInput' ) );
if ( search && searchForm ) {
initApp( searchForm, search, titleInput && titleInput.value );
}
}
main( document );