Skip to content

Commit 2c75637

Browse files
committed
Merge pull request #197 from fieg/issue-183
Prevent multiple initialisations (#183)
2 parents be8da4b + 4fcbc8d commit 2c75637

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/jquery-ias.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
this.nextUrl = null;
3030
this.isBound = false;
3131
this.isPaused = false;
32+
this.isInitialized = false;
3233
this.listeners = {
3334
next: new IASCallbacks(),
3435
load: new IASCallbacks(),
@@ -354,6 +355,10 @@
354355
* @public
355356
*/
356357
IAS.prototype.initialize = function() {
358+
if (this.isInitialized) {
359+
return false;
360+
}
361+
357362
var supportsOnScroll = (!!('onscroll' in this.$scrollContainer.get(0))),
358363
currentScrollOffset = this.getCurrentScrollOffset(this.$scrollContainer),
359364
scrollThreshold = this.getScrollThreshold();
@@ -373,6 +378,13 @@
373378
// start loading next page if content is shorter than page fold
374379
if (currentScrollOffset >= scrollThreshold) {
375380
this.next();
381+
382+
// flag as initialized when rendering is completed
383+
this.one('rendered', function() {
384+
this.isInitialized = true;
385+
});
386+
} else {
387+
this.isInitialized = true;
376388
}
377389

378390
return this;
@@ -384,6 +396,8 @@
384396
* @public
385397
*/
386398
IAS.prototype.reinitialize = function () {
399+
this.isInitialized = false;
400+
387401
this.unbind();
388402
this.initialize();
389403
};
@@ -557,7 +571,9 @@
557571

558572
this.extensions.push(extension);
559573

560-
this.reinitialize();
574+
if (this.isInitialized) {
575+
this.reinitialize();
576+
}
561577

562578
return this;
563579
};

0 commit comments

Comments
 (0)