Skip to content

Commit e4a5f01

Browse files
authored
Merge pull request #42 from TheCodeRaccoons/cms-filter-updates
Updates to CMS Filter to get pagination elements to work properly
2 parents e3bf1ad + 99c2bbe commit e4a5f01

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

Dist/WebflowOnly/CMSFilter.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class CMSFilter {
77
this.filterForm = document.querySelector('[wt-cmsfilter-element="filter-form"]');
88
this.listElement = document.querySelector('[wt-cmsfilter-element="list"]');
99
this.filterElements = this.filterForm.querySelectorAll('[wt-cmsfilter-category]');
10-
this.currentPage = 1; // default value
11-
this.itemsPerPage = 0; // gets updated during init
10+
this.currentPage = 1;
11+
this.itemsPerPage = 0;
1212

1313
//TAG elements
1414
this.tagTemplate = document.querySelector('[wt-cmsfilter-element="tag-template"]');
@@ -18,31 +18,26 @@ 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"]');
2525
this.customPrevButton = document.querySelector('[wt-cmsfilter-element="custom-prev"]');
2626

27-
//pagination opt
2827
this.paginationcounter = document.querySelector('[wt-cmsfilter-element="page-count"]');
29-
30-
//OPT
3128
this.activeFilterClass = this.filterForm.getAttribute('wt-cmsfilter-class');
3229
this.clearAll = document.querySelector('[wt-cmsfilter-element="clear-all"]');
3330
this.sortOptions = document.querySelector('[wt-cmsfilter-element="sort-options"]');
3431
this.resultCount = document.querySelector('[wt-cmsfilter-element="results-count"]');
3532
this.emptyElement = document.querySelector('[wt-cmsfilter-element="empty"]');
3633
this.resetIx2 = this.listElement.getAttribute('wt-cmsfilter-resetix2') || false;
3734

38-
//Data Tracking Values
3935
this.allItems = [];
4036
this.filteredItems = [];
4137
this.totalPages = 1;
4238
this.activeFilters = {};
4339
this.availableFilters = {};
4440

45-
//Script Init
4641
this.init();
4742
}
4843

@@ -51,6 +46,11 @@ class CMSFilter {
5146
this.itemsPerPage = this.allItems.length;
5247
if (this.paginationWrapper) {
5348
await this.LoadAllItems();
49+
if (this.paginationcounter && this.paginationcounter != this.paginationWrapper.querySelector('.w-page-count')) {
50+
this.paginationWrapper.querySelector('.w-page-count').remove();
51+
} else {
52+
this.paginationcounter = this.paginationWrapper.querySelector('.w-page-count');
53+
}
5454
}
5555
this.SetupEventListeners();
5656
this.RenderItems();
@@ -213,6 +213,7 @@ class CMSFilter {
213213
} else {
214214
this.filteredItems.forEach(item => {
215215
this.listElement.appendChild(item);
216+
if(this.resetIx2) this.ResetInteraction(item);
216217
});
217218
}
218219

@@ -492,7 +493,6 @@ class CMSFilter {
492493
UpdatePaginationDisplay() {
493494
if(!this.paginationWrapper) return;
494495

495-
this.paginationcounter = this.paginationcounter ? this.paginationcounter : this.paginationWrapper.querySelector('.w-page-count');
496496
if (this.paginationcounter) {
497497
this.paginationcounter.innerText = `${this.currentPage} / ${this.totalPages}`;
498498
}
@@ -562,7 +562,7 @@ class CMSFilter {
562562

563563
this.ApplyFilters();
564564
}
565-
565+
566566
ResetInteraction(element) {
567567
if (!element) {
568568
console.error('Element not found');

0 commit comments

Comments
 (0)