PageSourceSearch

https://www.nivea.com.my/dist/NiveaX/modules/FilterAction.33518464.js

js nivea.com.my collected 2026-09-26 14:57:26 UTC 9,217 bytes, 2 lines download raw bytes

1"use strict";(self.NiveaXwebpackJsonp=self.NiveaXwebpackJsonp||[]).push([[5415,5728],{1469:(t,e,i)=>{i.d(e,{G:()=>s});var r=i(5547);const s=t=>({type:r.N,filter:t})},13689:(t,e,i)=>{i.r(e),i.d(e,{default:()=>l});var r=i(21464),s=i(98684),a=i(45956),n=i(1469),o=i(93022);class l{constructor(t,e={}){this.element=t,this.options=e,this.options=(0,r.$E)(this.element,Object.assign(this.getDefaultOptions(),this.options)),this.filterTag=this.element.querySelector(this.options.filterTagSelector),this.applyBtn=this.element.querySelector(this.options.applyBtnSelector),this.applyBtnCounter=this.applyBtn.firstElementChild,this.tagsMap={tagsStr:window.atob(this.filterTag.getAttribute(this.options.tagsMapAttrs.tagsStrAttr)),tagCount:parseInt(this.filterTag.getAttribute(this.options.tagsMapAttrs.tagCountAttr)),productsCount:parseInt(this.filterTag.getAttribute(this.options.tagsMapAttrs.productsCountAttr))},this.initURLNavigation().init()}init(){return this.recoverState(),this}initURLNavigation(){return window.addEventListener("popstate",()=>{this.getUrlParameters().resetState().update()}),this.getUrlParameters(),this}getUrlParameters(){return this.options.state=(0,r.WQ)(),this}getFilters(){const t=[];Array.from(document.querySelectorAll(this.options.hierarchicalFilterSelector)).forEach(e=>{const i=[];Array.from(e.querySelectorAll(this.options.hierarchicalFilterValueSelector)).forEach(t=>{const e=t.dataset.key;e&&i.push({node:t,key:e,checked:t.classList.contains(this.options.hierarchicalFilterValueActiveClass),hierarchical:!0,index:parseInt(t.dataset.index),parentsIndex:t.dataset.parents})});const r={node:e,key:e.dataset.key,values:i,isAnd:!1,hierarchical:!0,cache:[]};t.push(r)});return Array.from(this.element.querySelectorAll(this.options.filterItemSelector)).forEach(e=>{const i=e.dataset.key,r="True"===e.dataset.isAnd,s=Array.from(e.querySelectorAll(this.options.checkboxSelector)),a=[];s.forEach(t=>{a.push({node:t,key:t.name,checked:t.checked,hierarchical:!1,index:parseInt(t.dataset.index)})});const n={node:e,key:i,values:a,isAnd:r,hierarchical:!1,cache:[]};t.push(n)}),t}isProductTagged(t,e){const i=t*this.tagsMap.tagCount+e;return!!(this.tagsMap.tagsStr.charCodeAt(Math.floor(i/8))&1<<i%8)}isProductIncludedInFilter(t,e){let i=e.values,r=e.isAnd,s=!1;for(let e=0;e<i.length;e++){const a=i[e];if(a.checked)if(s=!0,this.isProductTagged(t,a.index)){if(!r)return!0}else if(r)return!1}return!!r||!s}isProductVisible(t){for(let i=0;i<this.filters.length;i++){const r=this.filters[i],s=r.cache[t];if(!0!==s){if(!1===s)return!1;var e=this.isProductIncludedInFilter(t,r);if(r.cache[t]=e,!e)return!1}}return!0}countResults(){let t=0;for(var e=0;e<this.tagsMap.productsCount;e++)this.isProductVisible(e)&&t++;return t}countSimulateChecked(t,e,i){const r=this.filters[t],s=r.cache;r.cache=[];const a=r.values[e],n=a.checked;a.checked=i;const o=this.countResults();return a.checked=n,r.cache=s,o}countHierarchicalSimulateOnlyThisChecked(t,e){const i=this.filters;this.filters=[];for(var r=0;r<i.length;r++){var s=i[r];s.hierarchical&&this.filters.push(s)}const a=this.countSimulateOnlyThisChecked(t,e);return this.filters=i,a}countSimulateOnlyThisChecked(t,e){const i=this.filters[t];this.filters[t]={cache:[],values:[{index:i.values[e].index,checked:!0}]};const r=this.countResults();return this.filters[t]=i,r}checkHierarchicalParendIdx(t){let e=t.parentsIndex,i=t.parentsIndex.split(", ");return!(e&&!i.includes(this.options.hierarchicalParentIndex)&&!1!==this.options.hierarchicalParentIndex)}setHierarchicalParendIdx(){const t=Array.from(document.querySelectorAll(`${this.options.hierarchicalFilterValueSelector}.${this.options.hierarchicalFilterValueActiveClass}`));if(0!=t.length){const e=t[t.length-1];this.options.hierarchicalParentIndex=e.getAttribute("data-index")}else this.options.hierarchicalParentIndex=!1}setVisibility(t,e){t.node.hidden=!e}setCount(t,e,i){let r,a;t.hierarchical?r=t.node.querySelector(".nx-filter-navigation__count"):(r=(0,s.rQ)(t.node,this.options.countNodeSelector)||t.node.nextSibling.nextSibling,a=(0,s.uN)(t.node,".nx-cat-item"),t.node.disabled=i,a.hidden=i),r&&(r.innerText=e)}anyValueChecked(t){const e=t.values;for(let t=0;t<e.length;t++)if(e[t].checked)return!0;return!1}setGlobalCount(t){return this.applyBtnCounter.innerText=`(${t})`,this.applyBtn.disabled=0===t,this}getReloadUrl(t){const e=(0,o.encodeParams)(this.saveCurrentState().getState());return t.dataset.ajaxUrl+"&"+e}getReloadUrlFromHistory(t,e){return t.dataset.ajaxUrl+"&"+e}getFilterParams(t){return(0,o.encodeParams)(this.saveCurrentState().getState())}getParams(){const t=this.getFilters(),e={},i=document.getElementById("sort"),r=i&&i.value;return t.forEach(t=>{const i=[];
1t.values.forEach(t=>{t.checked&&i.push(t.key)}),i.length>0&&(e[t.key]=i)}),e.sort=[r],e}update(){this.setHierarchicalParendIdx(),this.filters=this.getFilters();const t=this.countResults();return this.setGlobalCount(t),this.filters.forEach((e,i)=>{e.hierarchical&&e.values.forEach((t,e)=>{if(!t.checked){this.countHierarchicalSimulateOnlyThisChecked(i,e);const r=this.countHierarchicalSimulateOnlyThisChecked(i,e),s=this.checkHierarchicalParendIdx(t);this.setVisibility(t,0!==r&&s)}}),e.values.forEach((r,s)=>{let a;if(r.checked)a="";else{const r=this.countSimulateChecked(i,s,!0);if(e.isAnd||!this.anyValueChecked(e))a=r.toString();else if(0===this.countSimulateOnlyThisChecked(i,s))a="0";else{let e=r-t;a=0===e?"-":"+"+e}}let n="0"===a;this.setCount(r,a,n)});let r=Array.from(e.values).every(({node:{disabled:t}})=>t);(0,s.p1)(e.node,"nx-filter-tag--disabled",r)}),this.setAllCount(t),document.dispatchEvent(new CustomEvent("ScrollSlider:reset")),this}updateV2(){this.setHierarchicalParendIdx(),this.filters=this.getFilters();const t=this.countResults();return this.setGlobalCount(t),this.filters.forEach((e,i)=>{e.hierarchical&&e.values.forEach((t,e)=>{t.checked||this.countHierarchicalSimulateOnlyThisChecked(i,e)}),e.values.forEach((r,s)=>{let a;if(r.checked)a="";else{const r=this.countSimulateChecked(i,s,!0);if(e.isAnd||!this.anyValueChecked(e))a=r.toString();else if(0===this.countSimulateOnlyThisChecked(i,s))a="0";else{let e=r-t;a=0===e?"-":"+"+e}}let n="0"===a;this.setCount(r,a,n)});let r=Array.from(e.values).every(({node:{disabled:t}})=>t);(0,s.p1)(e.node,"nx-filter-tag--disabled",r)}),this.setAllCount(t),document.dispatchEvent(new CustomEvent("ScrollSlider:reset")),this}getActiveHierarchicalLevel(){let t,e,i=document.querySelectorAll(".nx-filter-navigation__item.nx-active");return i.length>0?(e=i[i.length-1].getAttribute("data-id"),t=document.querySelector(`.nx-filter-navigation__level[id="${e}"]`)):t=document.querySelector(".nx-filter-navigation__level"),t}reload(t=void 0){const e=document.querySelector(this.options.gridNodeSelector),i=new XMLHttpRequest;let r,l;return(0,s.sV)(e),void 0===t?(r=this.getReloadUrl(e),l=this.updateUrl(e),window.history.pushState(l,"",l)):r=this.getReloadUrlFromHistory(e,t),i.onload=()=>{if(i.status>=200&&i.status<300){const t=(0,s.Uo)(i.responseText),r=t.querySelector(this.options.gridNodeSelector)||t;(0,o.onFilterTeaserGridChange)(e),e.innerHTML=r.innerHTML,NiveaX.loadShopPrices(),NiveaX.initModules()}else console.error("The request failed!");(0,s.il)(e)},i.open("GET",r),i.send(),a.Ay.dispatch((0,n.G)(this.getState())),this}updateUrl(t){const e=new URLSearchParams(window.location.search).get("q");return`?${e?`q=${e}&`:""}${this.getFilterParams(t)}`}recoverState(){for(let t in this.options.state){const e=Array.from(this.filterTag.querySelectorAll(`[data-key="${t}"] input[type="checkbox"]`)),i=this.options.state[t];e.filter(t=>i.includes(t.name)).forEach(t=>t.checked=!0)}return a.Ay.dispatch((0,n.G)(this.getState())),this}resetState(){return Array.from(this.filterTag.querySelectorAll(this.options.checkboxSelector+":checked")).forEach(t=>t.checked=!1),this.recoverState(),this}getState(){return this.options.state}saveCurrentState(){return this.saveState(this.getParams()),this}saveState(t){return this.options.state=t,this}setAllCount(t){let e=this.getActiveHierarchicalLevel();if(!e)return;const i=e.querySelector(".nx-filter-navigation__item--all .nx-filter-navigation__count");i&&(i.innerText=t)}getDefaultOptions(){return{tagsMapAttrs:{tagsStrAttr:"data-atob",tagCountAttr:"data-tab-count",productsCountAttr:"data-teaser-count"},hierarchicalFilterSelector:".nx-filter-navigation__level",hierarchicalFilterValueSelector:".nx-filter-navigation__item",hierarchicalFilterValueActiveClass:"nx-active",filterTagSelector:".nx-tag-filter",filterBtnSelector:".nx-filter-button",filterItemSelector:".nx-tag-filter__item",checkboxSelector:".nx-cat-item__tag-value",applyBtnSelector:".nx-sort-filters__apply-btn",countNodeSelector:".nx-cat-item__count",gridNodeSelector:".nx-teaser-grid",state:{}}}}},93022:(t,e,i)=>{function r(t){return Object.entries(t).map(([t,e])=>`${encodeURIComponent(t)}=${e.map(t=>encodeURIComponent(t)).join(",")}`).join("&")}function s(t){const e=new MutationObserver(()=>{e.disconnect(),document.dispatchEvent(new Event("NiveaXLoadMoreLoaded"))});e.observe(t,{childList:!0})}i.r(e),i.d(e,{encodeParams:()=>r,onFilterTeaserGridChange:()=>s})}}]);
2//# sourceMappingURL=/dist/NiveaX/./modules/FilterAction.33518464.js.da5b2fa5.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.