From b33d5bbc876298e0cc69377793ede5c94dd427bc Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Mon, 28 Aug 2023 19:20:44 -0700 Subject: [PATCH] =?UTF-8?q?refactor(search):=20=E2=99=BB=EF=B8=8F=20rename?= =?UTF-8?q?=20typeaheadItems=20to=20htmlHelper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{typeaheadItem.js => htmlHelper.js} | 12 ++++++------ resources/skins.citizen.search/presult.js | 6 +++--- resources/skins.citizen.search/typeahead.js | 10 +++++----- skin.json | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) rename resources/skins.citizen.search/{typeaheadItem.js => htmlHelper.js} (91%) diff --git a/resources/skins.citizen.search/typeaheadItem.js b/resources/skins.citizen.search/htmlHelper.js similarity index 91% rename from resources/skins.citizen.search/typeaheadItem.js rename to resources/skins.citizen.search/htmlHelper.js index 9530cb62..1254e6d0 100644 --- a/resources/skins.citizen.search/typeaheadItem.js +++ b/resources/skins.citizen.search/htmlHelper.js @@ -10,7 +10,7 @@ * @property {string} desc */ -function typeaheadItem() { +function htmlHelper() { return { /** * Generate menu item HTML using the existing template @@ -18,7 +18,7 @@ function typeaheadItem() { * @param {TypeaheadItemData} data * @return {HTMLElement|void} */ - get: function ( data ) { + getItemElement: function ( data ) { // TODO: Should we use template element or Mustache or just Javascript? const template = document.getElementById( 'citizen-typeahead-template' ); @@ -31,7 +31,7 @@ function typeaheadItem() { fragment = template.content.cloneNode( true ), item = fragment.querySelector( '.citizen-typeahead__item' ); - this.update( item, data ); + this.updateItemElement( item, data ); return fragment; }, /** @@ -40,7 +40,7 @@ function typeaheadItem() { * @param {HTMLElement} item * @param {TypeaheadItemData} data */ - update: function ( item, data ) { + updateItemElement: function ( item, data ) { if ( data.id ) { item.setAttribute( 'id', data.id ); } @@ -82,5 +82,5 @@ function typeaheadItem() { }; } -/** @module typeaheadItem */ -module.exports = typeaheadItem; +/** @module htmlHelper */ +module.exports = htmlHelper; diff --git a/resources/skins.citizen.search/presult.js b/resources/skins.citizen.search/presult.js index 0957321d..81876c4a 100644 --- a/resources/skins.citizen.search/presult.js +++ b/resources/skins.citizen.search/presult.js @@ -1,5 +1,5 @@ const config = require( './config.json' ); -const typeaheadItem = require( './typeaheadItem.js' )(); +const htmlHelper = require( './htmlHelper.js' )(); const searchHistory = require( './searchHistory.js' )( config ); function presult() { @@ -18,7 +18,7 @@ function presult() { size: 'sm', desc: result }; - fragment.append( typeaheadItem.get( data ) ); + fragment.append( htmlHelper.getItemElement( data ) ); } ); } return fragment; @@ -35,7 +35,7 @@ function presult() { title: mw.message( 'searchsuggest-search' ).text(), desc: mw.message( 'citizen-search-empty-desc' ).text() }; - fragment.append( typeaheadItem.get( data ) ); + fragment.append( htmlHelper.getItemElement( data ) ); } typeaheadEl.querySelector( '.citizen-typeahead__item-placeholder' )?.remove(); diff --git a/resources/skins.citizen.search/typeahead.js b/resources/skins.citizen.search/typeahead.js index 6e44327e..0f3ccae5 100644 --- a/resources/skins.citizen.search/typeahead.js +++ b/resources/skins.citizen.search/typeahead.js @@ -5,7 +5,7 @@ const // Config object from getCitizenSearchResourceLoaderConfig() const config = require( './config.json' ); -const typeaheadItem = require( './typeaheadItem.js' )(); +const htmlHelper = require( './htmlHelper.js' )(); const presult = require( './presult.js' )(); const searchClient = require( './searchClient.js' )( config ); const searchHistory = require( './searchHistory.js' )( config ); @@ -384,7 +384,7 @@ function getSuggestions() { // Thumbnail placeholder icon data.icon = 'image'; } - fragment.append( typeaheadItem.get( data ) ); + fragment.append( htmlHelper.getItemElement( data ) ); } ); } else { // Update placeholder with no result content @@ -395,7 +395,7 @@ function getSuggestions() { title: mw.message( 'citizen-search-noresults-title', searchQuery.valueHtml ).text(), desc: mw.message( 'citizen-search-noresults-desc' ).text() }; - fragment.append( typeaheadItem.get( data ) ); + fragment.append( htmlHelper.getItemElement( data ) ); } typeahead.items.clear(); typeahead.element.querySelector( '.citizen-typeahead__item-placeholder' )?.remove(); @@ -460,13 +460,13 @@ function updateTypeaheadItems() { // Update existing element instead of creating a new one if ( item ) { // FIXME: Probably more efficient to just replace the query than the whole messaage? - typeaheadItem.update( item, { + htmlHelper.updateItemElement( item, { link: itemLink, desc: itemDesc } ); } else { - item = typeaheadItem.get( { + item = htmlHelper.getItemElement( { icon: data.icon, id: itemId, type: 'tool', diff --git a/skin.json b/skin.json index 513d0a80..999c6761 100644 --- a/skin.json +++ b/skin.json @@ -157,7 +157,7 @@ "callback": "MediaWiki\\Skins\\Citizen\\Hooks\\ResourceLoaderHooks::getCitizenSearchResourceLoaderConfig" }, "resources/skins.citizen.search/typeahead.js", - "resources/skins.citizen.search/typeaheadItem.js", + "resources/skins.citizen.search/htmlHelper.js", "resources/skins.citizen.search/fetch.js", "resources/skins.citizen.search/presult.js", "resources/skins.citizen.search/searchClient.js",