Skip to content

Commit 4dac873

Browse files
committed
Merging changes with Dev branch
1 parent 79a1c5b commit 4dac873

1 file changed

Lines changed: 39 additions & 9 deletions

File tree

Dist/WebflowOnly/CMSFilter.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CMSFilter {
1818
//Pagination wrapper is a MUST for the full functionality of the filter to work properly,
1919
//if not added the filter will only work with whatever is loaded by default.
2020
this.paginationWrapper = document.querySelector('[wt-cmsfilter-element="pagination-wrapper"]') || null;
21-
this.loadMode = this.listElement.getAttribute('wt-cmsfilter-loadmode') || 'load-all'; //Currently only paginate and load-all
21+
this.loadMode = this.listElement.getAttribute('wt-cmsfilter-loadmode') || 'load-all';
2222
this.previousButton = document.querySelector('[wt-cmsfilter-pagination="prev"]');
2323
this.nextButton = document.querySelector('[wt-cmsfilter-pagination="next"]');
2424
this.customNextButton = document.querySelector('[wt-cmsfilter-element="custom-next"]');
@@ -30,6 +30,7 @@ class CMSFilter {
3030
this.sortOptions = document.querySelector('[wt-cmsfilter-element="sort-options"]');
3131
this.resultCount = document.querySelector('[wt-cmsfilter-element="results-count"]');
3232
this.emptyElement = document.querySelector('[wt-cmsfilter-element="empty"]');
33+
this.resetIx2 = this.listElement.getAttribute('wt-cmsfilter-resetix2') || false;
3334

3435
this.allItems = [];
3536
this.filteredItems = [];
@@ -206,18 +207,16 @@ class CMSFilter {
206207
const currentPage = this.filteredItems.slice(currentSlice, currentSlice + this.itemsPerPage);
207208
currentPage.forEach(item => {
208209
this.listElement.appendChild(item);
210+
if(this.resetIx2) this.ResetInteraction(item);
209211
});
210212
}
211213
} else {
212214
this.filteredItems.forEach(item => {
213215
this.listElement.appendChild(item);
216+
if(this.resetIx2) this.ResetInteraction(item);
214217
});
215218
}
216219

217-
var webflow = window.Webflow || [];
218-
if(webflow) {
219-
webflow.require('ix2').init();
220-
}
221220
this.ToggleEmptyState();
222221
this.UpdatePaginationDisplay();
223222
}
@@ -292,7 +291,6 @@ class CMSFilter {
292291
this.SetActiveTags();
293292
}
294293

295-
296294
ShowResultCount() {
297295
if(!this.resultCount) return;
298296
this.resultCount.innerText = this.GetResults();
@@ -369,7 +367,6 @@ class CMSFilter {
369367
return filters;
370368
}
371369

372-
373370
GetDataSet(str) {
374371
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
375372
return index === 0 ? word.toLowerCase() : word.toUpperCase();
@@ -523,8 +520,10 @@ class CMSFilter {
523520
}
524521
}
525522
if(this.allItems){
526-
if(this.allItems.length > 0) {
527-
return this.allItems.length;
523+
//trim out static elements from RenderStatic
524+
let elements = this.allItems.filter(item => !item.hasAttribute('wt-renderstatic-element'));
525+
if(elements.length > 0) {
526+
return elements.length;
528527
}
529528
return 0;
530529
}
@@ -564,6 +563,37 @@ class CMSFilter {
564563
this.ApplyFilters();
565564
}
566565

566+
ResetInteraction(element) {
567+
if (!element) {
568+
console.error('Element not found');
569+
return;
570+
}
571+
572+
const WebflowIX2 = window.Webflow && Webflow.require('ix2');
573+
if (!WebflowIX2) {
574+
console.error('Webflow IX2 engine not found.');
575+
return;
576+
}
577+
578+
const targetElement = element.hasAttribute('data-w-id')
579+
? element
580+
: element.querySelector('[data-w-id]');
581+
582+
if (!targetElement) {
583+
console.warn('No IX2 interaction found on the element or its children.');
584+
return;
585+
}
586+
587+
const dataWId = targetElement.getAttribute('data-w-id');
588+
if (dataWId) {
589+
targetElement.removeAttribute('data-w-id');
590+
targetElement.setAttribute('data-w-id', dataWId);
591+
592+
WebflowIX2.init();
593+
} else {
594+
console.warn('No valid data-w-id attribute found.');
595+
}
596+
}
567597

568598
GetFilterData() {
569599
let filterData = {

0 commit comments

Comments
 (0)