Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit 438ef98

Browse files
authored
Merge pull request #13 from Xterm/master
adds option for custom child selector
2 parents 782d83d + 0b84b6f commit 438ef98

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/pageable.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
freeScroll: false,
135135
slideshow: false,
136136
infinite: false,
137+
childSelector: '[data-anchor]',
137138
events: {
138139
wheel: true,
139140
mouse: true,
@@ -163,20 +164,24 @@
163164
this.container.appendChild(frag);
164165
}
165166

166-
// search for child nodes with the [data-anchor] attribute
167-
this.pages = this.container.querySelectorAll("[data-anchor]");
167+
// search for child nodes using the child selector
168+
this.pages = this.container.querySelectorAll(this.config.childSelector);
168169

169170
// none found
170171
if (!this.pages.length) {
171-
return console.error("Pageable:", "No child nodes with the [data-anchor] attribute could be found.");
172+
return console.error("Pageable:", "No child nodes matching the selector " + this.config.childSelector + " could be found.");
172173
}
173174

174175
this.horizontal = this.config.orientation === "horizontal";
175176

176177
this.anchors = [];
177178

178179
this.pages.forEach(function(page, i) {
179-
var clean = page.dataset.anchor.replace(/\s+/, "-").toLowerCase();
180+
if (typeof page.dataset.anchor !== 'undefined') {
181+
var clean = page.dataset.anchor.replace(/\s+/, "-").toLowerCase();
182+
} else {
183+
var clean = page.classList.value.replace(/\s+/, "-").toLowerCase();
184+
}
180185
if (page.id !== clean) {
181186
page.id = clean;
182187
}
@@ -724,7 +729,7 @@
724729
}
725730

726731
// prevent firing if not on a page
727-
if (!evt.target.closest("[data-anchor]")) {
732+
if (!evt.target.closest(this.childSelector)) {
728733
return false;
729734
}
730735

0 commit comments

Comments
 (0)