mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-18 21:15:50 +00:00
aa10668e6d
Add event listeners and associated helpers to emit SearchSatisfaction events via the `mediawiki.searchSuggest` protocol. Bug: T257698 Change-Id: Ica040cd18d6c4bf8a1b1f607bb4647c7e8eb7108
51 lines
1.2 KiB
JavaScript
51 lines
1.2 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
|
|
* @return {void}
|
|
*/
|
|
function initApp( searchForm, search ) {
|
|
// eslint-disable-next-line no-new
|
|
new Vue( {
|
|
el: '#p-search',
|
|
/**
|
|
*
|
|
* @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' ),
|
|
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' ) ),
|
|
search = /** @type {HTMLInputElement|null} */ ( document.getElementById( 'searchInput' ) );
|
|
if ( search && searchForm ) {
|
|
initApp( searchForm, search );
|
|
}
|
|
}
|
|
main( document );
|