From 8cc436ac4b78402f726d0a2d4d02388393c0038b Mon Sep 17 00:00:00 2001 From: bwang Date: Tue, 20 Jun 2023 13:21:07 -0500 Subject: [PATCH] Replace search loader indicator with Codex pending search message Bug: T321106 Change-Id: Ic27ecf16277725f6a08038a5501d0903a2494b5f --- bundlesize.config.json | 4 +- resources/skins.vector.js/searchLoader.js | 79 ++------------ resources/skins.vector.search/App.vue | 3 + .../components/SearchBoxLoader.less | 101 ------------------ resources/skins.vector.styles/skin.less | 1 - .../skins.vector.zebra.styles/variables.less | 1 - 6 files changed, 11 insertions(+), 178 deletions(-) delete mode 100644 resources/skins.vector.styles/components/SearchBoxLoader.less diff --git a/bundlesize.config.json b/bundlesize.config.json index 3c0ecd0d5..56c2fc78d 100644 --- a/bundlesize.config.json +++ b/bundlesize.config.json @@ -9,11 +9,11 @@ }, { "resourceModule": "skins.vector.styles", - "maxSize": "11.4 kB" + "maxSize": "11.2 kB" }, { "resourceModule": "skins.vector.js", - "maxSize": "14.8 kB" + "maxSize": "14.3 kB" }, { "resourceModule": "skins.vector.legacy.js", diff --git a/resources/skins.vector.js/searchLoader.js b/resources/skins.vector.js/searchLoader.js index 253dac340..7f35aeb70 100644 --- a/resources/skins.vector.js/searchLoader.js +++ b/resources/skins.vector.js/searchLoader.js @@ -19,8 +19,7 @@ const /** @type {VectorResourceLoaderVirtualConfig} */ performance.getEntriesByName ), LOAD_START_MARK = 'mwVectorVueSearchLoadStart', LOAD_END_MARK = 'mwVectorVueSearchLoadEnd', - LOAD_MEASURE = 'mwVectorVueSearchLoadStartToLoadEnd', - SEARCH_LOADING_CLASS = 'search-form__loader'; + LOAD_MEASURE = 'mwVectorVueSearchLoadStartToLoadEnd'; /** * Loads the search module via `mw.loader.using` on the element's @@ -55,64 +54,6 @@ function loadSearchModule( element, moduleName, startMarker, afterLoadFn ) { } } -/** - * Event callback that shows or hides the loading indicator based on the event type. - * The loading indicator states are: - * 1. Show on input event (while user is typing) - * 2. Hide on focusout event (when user removes focus from the input ) - * 3. Show when input is focused, if it contains a query. (in case user re-focuses on input) - * - * @param {Event} event - */ -function renderSearchLoadingIndicator( event ) { - - const form = /** @type {HTMLElement} */ ( event.currentTarget ), - input = /** @type {HTMLInputElement} */ ( event.target ); - - if ( - !( event.currentTarget instanceof HTMLElement ) || - !( event.target instanceof HTMLInputElement ) - ) { - return; - } - - if ( !form.dataset.loadingMsg ) { - form.dataset.loadingMsg = mw.msg( 'vector-search-loader' ); - } - - if ( event.type === 'input' ) { - form.classList.add( SEARCH_LOADING_CLASS ); - - } else if ( event.type === 'focusout' ) { - form.classList.remove( SEARCH_LOADING_CLASS ); - - } else if ( event.type === 'focusin' && input.value.trim() ) { - form.classList.add( SEARCH_LOADING_CLASS ); - } -} - -/** - * Attaches or detaches the event listeners responsible for activating - * the loading indicator. - * - * @param {Element} element - * @param {boolean} attach - * @param {function(Event): void} eventCallback - */ -function setLoadingIndicatorListeners( element, attach, eventCallback ) { - - /** @type { "addEventListener" | "removeEventListener" } */ - const addOrRemoveListener = ( attach ? 'addEventListener' : 'removeEventListener' ); - - [ 'input', 'focusin', 'focusout' ].forEach( function ( eventType ) { - element[ addOrRemoveListener ]( eventType, eventCallback ); - } ); - - if ( !attach ) { - element.classList.remove( SEARCH_LOADING_CLASS ); - } -} - /** * Marks when the lazy load has completed. * @@ -158,13 +99,6 @@ function initSearchLoader( document ) { Array.prototype.forEach.call( searchBoxes, function ( searchBox ) { const searchInner = searchBox.querySelector( 'form > div' ), searchInput = searchBox.querySelector( 'input[name="search"]' ), - clearLoadingIndicators = function () { - setLoadingIndicatorListeners( - searchInner, - false, - renderSearchLoadingIndicator - ); - }, isPrimarySearch = searchInput && searchInput.getAttribute( 'id' ) === 'searchInput'; if ( !searchInput || !searchInner ) { @@ -172,17 +106,16 @@ function initSearchLoader( document ) { } // Remove tooltips while Vue search is still loading searchInput.setAttribute( 'autocomplete', 'off' ); - setLoadingIndicatorListeners( searchInner, true, renderSearchLoadingIndicator ); loadSearchModule( searchInput, 'skins.vector.search', isPrimarySearch ? LOAD_START_MARK : null, - // Make sure we clearLoadingIndicators so that event listeners are removed. // Note, loading Vue.js will remove the element from the DOM. - isPrimarySearch ? function () { - markLoadEnd( LOAD_START_MARK, LOAD_END_MARK, LOAD_MEASURE ); - clearLoadingIndicators(); - } : clearLoadingIndicators + function () { + if ( isPrimarySearch ) { + markLoadEnd( LOAD_START_MARK, LOAD_END_MARK, LOAD_MEASURE ); + } + } ); } ); } diff --git a/resources/skins.vector.search/App.vue b/resources/skins.vector.search/App.vue index cc8ca7118..71e026a4f 100644 --- a/resources/skins.vector.search/App.vue +++ b/resources/skins.vector.search/App.vue @@ -38,6 +38,9 @@ :value="wprov" > +