@@ -29,10 +29,11 @@ var defaultLabels = {
29
29
* @param {String } [options.labels.next] Label for the Next link
30
30
* @param {String } [options.labels.first] Label for the First link
31
31
* @param {String } [options.labels.last] Label for the Last link
32
- * @param {Number } [maxPages=20] The max number of pages to browse
33
- * @param {Number } [padding=3] The number of pages to display on each side of the current page
34
- * @param {boolean } [showFirstLast=true] Define if the First and Last links should be displayed
35
- * @param {boolean } [hideWhenNoResults=true] Hide the container when no results match
32
+ * @param {Number } [options.maxPages=20] The max number of pages to browse
33
+ * @param {Number } [options.padding=3] The number of pages to display on each side of the current page
34
+ * @param {String|DOMElement|boolean } [options.scrollTo='body'] Where to scroll after a click, set to `false` to disable
35
+ * @param {boolean } [options.showFirstLast=true] Define if the First and Last links should be displayed
36
+ * @param {boolean } [options.hideWhenNoResults=true] Hide the container when no results match
36
37
* @return {Object }
37
38
*/
38
39
function pagination ( {
@@ -42,9 +43,15 @@ function pagination({
42
43
maxPages = 20 ,
43
44
padding = 3 ,
44
45
showFirstLast = true ,
45
- hideWhenNoResults = true
46
+ hideWhenNoResults = true ,
47
+ scrollTo = 'body'
46
48
} ) {
49
+ if ( scrollTo === true ) {
50
+ scrollTo = 'body' ;
51
+ }
52
+
47
53
var containerNode = utils . getContainerNode ( container ) ;
54
+ var scrollToNode = scrollTo !== false ? utils . getContainerNode ( scrollTo ) : false ;
48
55
49
56
if ( ! container ) {
50
57
throw new Error ( 'Usage: pagination({container[, cssClasses.{root,item,page,previous,next,first,last,active,disabled}, labels.{previous,next,first,last}, maxPages, showFirstLast, hideWhenNoResults]})' ) ;
@@ -62,8 +69,6 @@ function pagination({
62
69
var nbPages = results . nbPages ;
63
70
var nbHits = results . nbHits ;
64
71
var hasResults = nbHits > 0 ;
65
- var setCurrentPage = this . setCurrentPage . bind ( this , helper ) ;
66
-
67
72
68
73
if ( maxPages !== undefined ) {
69
74
nbPages = Math . min ( maxPages , results . nbPages ) ;
@@ -79,7 +84,7 @@ function pagination({
79
84
nbHits = { nbHits }
80
85
nbPages = { nbPages }
81
86
padding = { padding }
82
- setCurrentPage = { setCurrentPage }
87
+ setCurrentPage = { setCurrentPage ( helper , scrollToNode ) }
83
88
showFirstLast = { showFirstLast }
84
89
/> ,
85
90
containerNode
@@ -88,4 +93,13 @@ function pagination({
88
93
} ;
89
94
}
90
95
96
+ function setCurrentPage ( helper , scrollToNode ) {
97
+ return askedPage => {
98
+ helper . setCurrentPage ( askedPage ) . search ( ) ;
99
+ if ( scrollToNode !== false ) {
100
+ scrollToNode . scrollIntoView ( ) ;
101
+ }
102
+ } ;
103
+ }
104
+
91
105
module . exports = pagination ;
0 commit comments