mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-01 02:37:05 +00:00
bb0b3373c7
Follow up to 5dee570cb2
.
It seems the mount works slightly different in that it creates a div,
appends by the App element to the element you give it, after
clearing all it's child nodes.
The previous behaviour was that the old element was /replaced/
by the App element.
Bug: T296889
Change-Id: Iee7493c032f4de5389207bba288a1a70e4cd14f3
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
/** @module search */
|
|
|
|
var
|
|
Vue = require( 'vue' ).default || require( 'vue' ),
|
|
App = require( './App.vue' ),
|
|
config = require( './config.json' );
|
|
|
|
/**
|
|
* @param {Element} searchForm
|
|
* @return {void}
|
|
*/
|
|
function initApp( searchForm ) {
|
|
var
|
|
titleInput = /** @type {HTMLInputElement|null} */ (
|
|
searchForm.querySelector( 'input[name=title]' )
|
|
),
|
|
search = /** @type {HTMLInputElement|null} */ ( searchForm.querySelector( 'input[name="search"]' ) ),
|
|
searchPageTitle = titleInput && titleInput.value;
|
|
|
|
if ( !search || !titleInput ) {
|
|
throw new Error( 'Attempted to create Vue search element from an incompatible element.' );
|
|
}
|
|
|
|
// @ts-ignore
|
|
Vue.createMwApp(
|
|
App, $.extend( {
|
|
id: searchForm.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 )
|
|
)
|
|
.mount( searchForm.parentNode );
|
|
}
|
|
/**
|
|
* @param {Document} document
|
|
* @return {void}
|
|
*/
|
|
function main( document ) {
|
|
var
|
|
searchForms = document.querySelectorAll( '.vector-search-box-form' );
|
|
|
|
searchForms.forEach( function ( searchForm ) {
|
|
initApp( searchForm );
|
|
} );
|
|
}
|
|
main( document );
|