Skip to content

Commit 87725fa

Browse files
committed
MAGE-1241 Clean up static DOM when dynamicWidgets are enabled
1 parent 4b798ca commit 87725fa

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

view/frontend/web/js/instantsearch.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,27 @@ define([
558558
throw new Error(`[Algolia] Invalid facet widget type: ${facet.type}`);
559559
},
560560

561+
/**
562+
* Return DOM container for the facet
563+
* If dynamic widgets are enabled no container needs to be created
564+
*
565+
* @param facet
566+
* @returns {*|ActiveX.IXMLDOMNode|null}
567+
*/
568+
getFacetContainer(facet) {
569+
return !algoliaConfig.instant.isDynamicFacetsEnabled
570+
&& facet.wrapper.appendChild(algoliaCommon.createISWidgetContainer(facet.attribute))
571+
|| null;
572+
},
573+
561574
/**
562575
* Docs: https://www.algolia.com/doc/api-reference/widgets/range-input/js/
563576
*/
564577
getRangeInputFacetConfig(facet) {
565578
return [
566579
'rangeInput',
567580
{
568-
container : facet.wrapper.appendChild(
569-
algoliaCommon.createISWidgetContainer(facet.attribute)
570-
),
581+
container : this.getFacetContainer(facet),
571582
attribute : facet.attribute,
572583
templates : {
573584
separatorText: algoliaConfig.translations.to,
@@ -588,9 +599,7 @@ define([
588599
return [
589600
'rangeSlider',
590601
{
591-
container : facet.wrapper.appendChild(
592-
algoliaCommon.createISWidgetContainer(facet.attribute)
593-
),
602+
container : this.getFacetContainer(facet),
594603
attribute : facet.attribute,
595604
pips : false,
596605
panelOptions: this.getPricingFacetPanelOptions(facet),
@@ -653,9 +662,7 @@ define([
653662

654663
getRefinementListOptions(facet) {
655664
return {
656-
container : facet.wrapper.appendChild(
657-
algoliaCommon.createISWidgetContainer(facet.attribute)
658-
),
665+
container : this.getFacetContainer(facet),
659666
attribute : facet.attribute,
660667
limit : algoliaConfig.maxValuesPerFacet,
661668
templates : this.getRefinementsListTemplates(),
@@ -757,9 +764,7 @@ define([
757764
}
758765

759766
const hierarchicalMenuParams = {
760-
container : facet.wrapper.appendChild(
761-
algoliaCommon.createISWidgetContainer(facet.attribute)
762-
),
767+
container : this.getFacetContainer(facet),
763768
attributes : hierarchical_levels,
764769
separator : algoliaConfig.instant.categorySeparator,
765770
templates : [],

0 commit comments

Comments
 (0)