@@ -25,13 +25,11 @@ var IASHistoryExtension = function (options) {
25
25
* @param url
26
26
*/
27
27
this . onPageChange = function ( pageNum , scrollOffset , url ) {
28
- var state = { } ;
29
-
30
28
if ( ! window . history || ! window . history . replaceState ) {
31
29
return ;
32
30
}
33
31
34
- state = history . state ;
32
+ var state = history . state ;
35
33
36
34
history . replaceState ( state , document . title , url ) ;
37
35
} ;
@@ -55,6 +53,17 @@ var IASHistoryExtension = function (options) {
55
53
}
56
54
} ;
57
55
56
+ this . onReady = function ( ) {
57
+ var currentScrollOffset = this . ias . getCurrentScrollOffset ( this . ias . $scrollContainer ) ,
58
+ firstItemScrollThreshold = this . getScrollThresholdFirstItem ( ) ;
59
+
60
+ currentScrollOffset -= this . ias . $scrollContainer . height ( ) ;
61
+
62
+ if ( currentScrollOffset <= firstItemScrollThreshold ) {
63
+ this . prev ( ) ;
64
+ }
65
+ } ;
66
+
58
67
/**
59
68
* Returns the url for the next page
60
69
*
@@ -150,20 +159,19 @@ IASHistoryExtension.prototype.initialize = function (ias) {
150
159
* @param ias
151
160
*/
152
161
IASHistoryExtension . prototype . bind = function ( ias ) {
153
- var self = this ;
154
-
155
162
ias . on ( 'pageChange' , jQuery . proxy ( this . onPageChange , this ) ) ;
156
163
ias . on ( 'scroll' , jQuery . proxy ( this . onScroll , this ) ) ;
157
- ias . on ( 'ready' , function ( ) {
158
- var currentScrollOffset = ias . getCurrentScrollOffset ( ias . $scrollContainer ) ,
159
- firstItemScrollThreshold = self . getScrollThresholdFirstItem ( ) ;
160
-
161
- currentScrollOffset -= ias . $scrollContainer . height ( ) ;
164
+ ias . on ( 'ready' , jQuery . proxy ( this . onReady , this ) ) ;
165
+ } ;
162
166
163
- if ( currentScrollOffset <= firstItemScrollThreshold ) {
164
- self . prev ( ) ;
165
- }
166
- } ) ;
167
+ /**
168
+ * @public
169
+ * @param {object } ias
170
+ */
171
+ IASHistoryExtension . prototype . unbind = function ( ias ) {
172
+ ias . off ( 'pageChange' , this . onPageChange ) ;
173
+ ias . off ( 'scroll' , this . onScroll ) ;
174
+ ias . off ( 'ready' , this . onReady ) ;
167
175
} ;
168
176
169
177
/**
@@ -180,7 +188,7 @@ IASHistoryExtension.prototype.prev = function () {
180
188
return false ;
181
189
}
182
190
183
- ias . unbind ( ) ;
191
+ ias . pause ( ) ;
184
192
185
193
var promise = ias . fire ( 'prev' , [ url ] ) ;
186
194
@@ -189,7 +197,7 @@ IASHistoryExtension.prototype.prev = function () {
189
197
self . renderBefore ( items , function ( ) {
190
198
self . prevUrl = self . getPrevUrl ( data ) ;
191
199
192
- ias . bind ( ) ;
200
+ ias . resume ( ) ;
193
201
194
202
if ( self . prevUrl ) {
195
203
self . prev ( ) ;
@@ -199,7 +207,7 @@ IASHistoryExtension.prototype.prev = function () {
199
207
} ) ;
200
208
201
209
promise . fail ( function ( ) {
202
- ias . bind ( ) ;
210
+ ias . resume ( ) ;
203
211
} ) ;
204
212
205
213
return true ;
0 commit comments