mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-25 08:05:51 +00:00
aebb3fb522
Allow commons to use Special:MediaSearch Depends-On: I37b9d3a2b263f496a283f4bfdc769b7dc880ab06 Bug: T287540 Change-Id: I2a2463d704ef5b2264574cdf186836ba00a639f5
57 lines
1.6 KiB
JavaScript
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 );
|