mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-04 12:09:30 +00:00
95e3271e79
Follows up the sticky header search refactors
in caed16e
Change-Id: I5832bc04f0c675ff8bc1a00fff17b6b9f8399e6e
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
/** @module search */
|
|
var
|
|
Vue = require( 'vue' ).default || require( 'vue' ),
|
|
App = require( './App.vue' ),
|
|
config = require( './config.json' );
|
|
|
|
/**
|
|
* @param {Function} createElement
|
|
* @param {Element} searchForm
|
|
* @return {Vue.VNode}
|
|
* @throws {Error} if the searchForm does not
|
|
* contain input[name=title] and input[name="search"] elements.
|
|
*/
|
|
function renderFn( createElement, 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.' );
|
|
}
|
|
|
|
return createElement( App, {
|
|
props: $.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
|
|
)
|
|
} );
|
|
}
|
|
|
|
/**
|
|
* @param {NodeList} searchForms
|
|
* @return {void}
|
|
*/
|
|
function initApp( searchForms ) {
|
|
searchForms.forEach( function ( searchForm ) {
|
|
// eslint-disable-next-line no-new
|
|
new Vue( {
|
|
el: /** @type {Element} */ ( searchForm ),
|
|
render: function ( createElement ) {
|
|
return renderFn( createElement, /** @type {Element} */ ( searchForm ) );
|
|
}
|
|
} );
|
|
} );
|
|
}
|
|
/**
|
|
* @param {Document} document
|
|
* @return {void}
|
|
*/
|
|
function main( document ) {
|
|
var
|
|
searchForms = document.querySelectorAll( '.vector-search-box-form' );
|
|
|
|
initApp( searchForms );
|
|
}
|
|
main( document );
|