Skip to content

Commit 32b677e

Browse files
authored
Merge pull request #40 from TheCodeRaccoons/Develop
Develop - > Main
2 parents b1771bd + e3bf1ad commit 32b677e

2 files changed

Lines changed: 51 additions & 18 deletions

File tree

Dist/WebflowOnly/CMSFilter.js

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CMSFilter {
3333
this.sortOptions = document.querySelector('[wt-cmsfilter-element="sort-options"]');
3434
this.resultCount = document.querySelector('[wt-cmsfilter-element="results-count"]');
3535
this.emptyElement = document.querySelector('[wt-cmsfilter-element="empty"]');
36+
this.resetIx2 = this.listElement.getAttribute('wt-cmsfilter-resetix2') || false;
3637

3738
//Data Tracking Values
3839
this.allItems = [];
@@ -206,6 +207,7 @@ 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 {
@@ -214,10 +216,6 @@ class CMSFilter {
214216
});
215217
}
216218

217-
var webflow = window.Webflow || [];
218-
if(webflow) {
219-
webflow.require('ix2').init();
220-
}
221219
this.ToggleEmptyState();
222220
this.UpdatePaginationDisplay();
223221
}
@@ -292,7 +290,6 @@ class CMSFilter {
292290
this.SetActiveTags();
293291
}
294292

295-
296293
ShowResultCount() {
297294
if(!this.resultCount) return;
298295
this.resultCount.innerText = this.GetResults();
@@ -369,7 +366,6 @@ class CMSFilter {
369366
return filters;
370367
}
371368

372-
373369
GetDataSet(str) {
374370
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
375371
return index === 0 ? word.toLowerCase() : word.toUpperCase();
@@ -524,8 +520,10 @@ class CMSFilter {
524520
}
525521
}
526522
if(this.allItems){
527-
if(this.allItems.length > 0) {
528-
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;
529527
}
530528
return 0;
531529
}
@@ -565,6 +563,37 @@ class CMSFilter {
565563
this.ApplyFilters();
566564
}
567565

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+
}
568597

569598
GetFilterData() {
570599
let filterData = {

Dist/WebflowOnly/RenderStatic.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,27 @@ class RenderStatic {
2525

2626
let insertIndex = this.gap;
2727
const totalChildren = childrenArray.length;
28-
const totalInsertions = Math.round(totalChildren / this.gap);
2928
let cloneIndex = 0;
3029

31-
for (let i = 0; i <= totalChildren + totalInsertions; i++) {
32-
if (i === insertIndex) {
33-
this.insertChildAtIndex(this.container, this.cloneables[cloneIndex], insertIndex);
34-
cloneIndex = (cloneIndex < this.cloneables.length - 1) ? cloneIndex + 1 : 0;
35-
insertIndex = i + this.gap + 1;
36-
}
30+
const maxInsertions = Math.floor((totalChildren - 1) / this.gap);
31+
32+
for (let i = 0; i < maxInsertions; i++) {
33+
const currentIndex = i * (this.gap + 1) + this.gap;
34+
35+
if (currentIndex >= totalChildren) break;
36+
37+
this.insertChildAtIndex(this.container, this.cloneables[cloneIndex], currentIndex);
38+
cloneIndex = (cloneIndex < this.cloneables.length - 1) ? cloneIndex + 1 : 0;
3739
}
3840

3941
this.observeContainer();
4042
}
4143

4244
insertChildAtIndex(parent, child, index = 0) {
4345
if (!child) return;
44-
if (parent.children.length === index) return;
46+
47+
if (index >= parent.children.length) return;
48+
4549
let childClone = child.cloneNode(true);
4650
if (parent) {
4751
parent.insertBefore(childClone, parent.children[index]);
@@ -77,5 +81,5 @@ const initializeRenderStatic = () => {
7781
if (/complete|interactive|loaded/.test(document.readyState)) {
7882
initializeRenderStatic();
7983
} else {
80-
window.addEventListener('DOMContentLoaded',initializeRenderStatic )
81-
}
84+
window.addEventListener('DOMContentLoaded', initializeRenderStatic);
85+
}

0 commit comments

Comments
 (0)