mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-27 17:10:19 +00:00
Merge "search: Reduce skins.vector.search module size"
This commit is contained in:
commit
f8af368121
|
@ -64,8 +64,8 @@ function onFetchEnd( event ) {
|
||||||
// execute before the rendering steps happen (e.g. layout and paint). A
|
// execute before the rendering steps happen (e.g. layout and paint). A
|
||||||
// nested rAF will execute after these rendering steps have completed
|
// nested rAF will execute after these rendering steps have completed
|
||||||
// and ensure the search results are visible to the user.
|
// and ensure the search results are visible to the user.
|
||||||
requestAnimationFrame( function () {
|
requestAnimationFrame( () => {
|
||||||
requestAnimationFrame( function () {
|
requestAnimationFrame( () => {
|
||||||
if ( !performance.getEntriesByName( queryMark ).length ) {
|
if ( !performance.getEntriesByName( queryMark ).length ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,7 @@ function adaptApiResponse( config, query, restResponse, showDescription ) {
|
||||||
* @return {SearchClient}
|
* @return {SearchClient}
|
||||||
*/
|
*/
|
||||||
function restSearchClient( config ) {
|
function restSearchClient( config ) {
|
||||||
const customClient = config.get( 'wgVectorSearchClient' );
|
return config.get( 'wgVectorSearchClient', {
|
||||||
return customClient || {
|
|
||||||
/**
|
/**
|
||||||
* @type {fetchByTitle}
|
* @type {fetchByTitle}
|
||||||
*/
|
*/
|
||||||
|
@ -103,7 +102,7 @@ function restSearchClient( config ) {
|
||||||
fetch: searchResponsePromise
|
fetch: searchResponsePromise
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = restSearchClient;
|
module.exports = restSearchClient;
|
||||||
|
|
|
@ -14,7 +14,7 @@ function initApp( searchBox ) {
|
||||||
titleInput = /** @type {HTMLInputElement|null} */ (
|
titleInput = /** @type {HTMLInputElement|null} */ (
|
||||||
searchBox.querySelector( 'input[name=title]' )
|
searchBox.querySelector( 'input[name=title]' )
|
||||||
),
|
),
|
||||||
search = /** @type {HTMLInputElement|null} */ ( searchBox.querySelector( 'input[name="search"]' ) ),
|
search = /** @type {HTMLInputElement|null} */ ( searchBox.querySelector( 'input[name=search]' ) ),
|
||||||
searchPageTitle = titleInput && titleInput.value;
|
searchPageTitle = titleInput && titleInput.value;
|
||||||
|
|
||||||
if ( !searchForm || !search || !titleInput ) {
|
if ( !searchForm || !search || !titleInput ) {
|
||||||
|
@ -43,10 +43,7 @@ function initApp( searchBox ) {
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
function main( document ) {
|
function main( document ) {
|
||||||
const searchBoxes = document.querySelectorAll( '.vector-search-box' );
|
document.querySelectorAll( '.vector-search-box' )
|
||||||
|
.forEach( initApp );
|
||||||
searchBoxes.forEach( ( searchBox ) => {
|
|
||||||
initApp( searchBox );
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
main( document );
|
main( document );
|
||||||
|
|
|
@ -28,8 +28,7 @@
|
||||||
function urlGenerator( config ) {
|
function urlGenerator( config ) {
|
||||||
// TODO: This is a placeholder for enabling customization of the URL generator.
|
// TODO: This is a placeholder for enabling customization of the URL generator.
|
||||||
// wgVectorSearchUrlGenerator has not been defined as a config variable yet.
|
// wgVectorSearchUrlGenerator has not been defined as a config variable yet.
|
||||||
const customGenerator = config.get( 'wgVectorSearchUrlGenerator' );
|
return config.get( 'wgVectorSearchUrlGenerator', {
|
||||||
return customGenerator || {
|
|
||||||
/**
|
/**
|
||||||
* @type {generateUrl}
|
* @type {generateUrl}
|
||||||
*/
|
*/
|
||||||
|
@ -52,7 +51,7 @@ function urlGenerator( config ) {
|
||||||
|
|
||||||
return articlePath + '?' + $.param( $.extend( {}, params, { search: suggestion } ) );
|
return articlePath + '?' + $.param( $.extend( {}, params, { search: suggestion } ) );
|
||||||
}
|
}
|
||||||
};
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @module urlGenerator */
|
/** @module urlGenerator */
|
||||||
|
|
|
@ -4,14 +4,14 @@ const jestFetchMock = require( 'jest-fetch-mock' );
|
||||||
|
|
||||||
const mockedRequests = !process.env.TEST_LIVE_REQUESTS;
|
const mockedRequests = !process.env.TEST_LIVE_REQUESTS;
|
||||||
const configMock = {
|
const configMock = {
|
||||||
get: jest.fn().mockImplementation( key => {
|
get: jest.fn().mockImplementation( ( key, fallback = null ) => {
|
||||||
if ( key === 'wgScriptPath' ) {
|
if ( key === 'wgScriptPath' ) {
|
||||||
return '/w';
|
return '/w';
|
||||||
}
|
}
|
||||||
if ( key === 'wgScript' ) {
|
if ( key === 'wgScript' ) {
|
||||||
return '/w/index.php';
|
return '/w/index.php';
|
||||||
}
|
}
|
||||||
return null;
|
return fallback;
|
||||||
} ),
|
} ),
|
||||||
set: jest.fn()
|
set: jest.fn()
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue