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

Commit 57907e0

Browse files
author
Mobius1
committed
v0.0.3
1 parent 1e69d78 commit 57907e0

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

dist/pageable.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/js/pageable.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pageable",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "Create full page scrolling web pages. No jQuery.",
55
"main": "dist/pageable.js",
66
"scripts": {

src/index.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,28 @@ export default class Pageable {
2424
this.container = typeof container === "string" ?
2525
document.querySelector(container) : container;
2626

27+
this.config = Object.assign({}, defaults, options);
28+
29+
if ( this.config.anchors && Array.isArray(this.config.anchors) ) {
30+
const frag = document.createDocumentFragment();
31+
32+
this.config.anchors.forEach(anchor => {
33+
const page = document.createElement("div");
34+
page.dataset.anchor = anchor;
35+
frag.appendChild(page);
36+
});
37+
38+
this.container.appendChild(frag);
39+
}
40+
2741
// search for child nodes with the [data-anchor] attribute
2842
this.pages = Array.from(this.container.querySelectorAll("[data-anchor]"));
29-
43+
3044
// none found
3145
if ( !this.pages.length ) {
3246
return console.error("Pageable:", "No child nodes with the [data-anchor] attribute could be found.");
33-
}
47+
}
3448

35-
this.config = Object.assign({}, defaults, options);
3649
this.horizontal = this.config.orientation === "horizontal";
3750

3851
this.anchors = [];
@@ -204,8 +217,6 @@ export default class Pageable {
204217
if ( index > -1 ) {
205218
this.index = index;
206219
this.setPips();
207-
208-
this.wrapper[this.scrollAxis[this.axis]] = (this.horizontal ? window.innerWidth : window.innerHeight) * this.index;
209220

210221
this.config.onFinish.call(this, {
211222
id: this.pages[this.index].id,
@@ -280,8 +291,6 @@ export default class Pageable {
280291
const st = Date.now();
281292
const offset = this.getScrollOffset();
282293

283-
this.setURL(this.pages[this.index].id);
284-
285294
this.setPips();
286295

287296
// Scroll function
@@ -296,11 +305,11 @@ export default class Pageable {
296305
const position = this.data.window[this.size[this.axis]] * this.index;
297306

298307
this.container.style.transform = ``;
299-
300-
this.wrapper[this.scrollAxis[this.axis]] = this.scrollPosition = position;
301308

302309
this.frame = false;
303310
this.scrolling = false;
311+
312+
window.location.hash = this.pages[this.index].id;
304313

305314
this.config.onFinish.call(this, {
306315
hash: this.pages[this.index].id,
@@ -335,14 +344,6 @@ export default class Pageable {
335344
}, this.config.delay);
336345
}
337346

338-
setURL(id) {
339-
if(history.pushState) {
340-
history.pushState(null, '', `#${id}`);
341-
} else {
342-
location.hash = `#${id}`;
343-
}
344-
}
345-
346347
scrollToPage(page) {
347348
this.scrollToIndex(page - 1);
348349
}
@@ -372,7 +373,7 @@ export default class Pageable {
372373

373374
prev() {
374375
this.scrollToIndex(this.index-1);
375-
}
376+
}
376377

377378
update() {
378379
clearTimeout(this.timer);

0 commit comments

Comments
 (0)