@@ -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