Skip to content

Commit

Permalink
Merge pull request #197 from fieg/issue-183
Browse files Browse the repository at this point in the history
Prevent multiple initialisations (#183)
  • Loading branch information
fieg committed May 8, 2015
2 parents be8da4b + 4fcbc8d commit 2c75637
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/jquery-ias.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
this.nextUrl = null;
this.isBound = false;
this.isPaused = false;
this.isInitialized = false;
this.listeners = {
next: new IASCallbacks(),
load: new IASCallbacks(),
Expand Down Expand Up @@ -354,6 +355,10 @@
* @public
*/
IAS.prototype.initialize = function() {
if (this.isInitialized) {
return false;
}

var supportsOnScroll = (!!('onscroll' in this.$scrollContainer.get(0))),
currentScrollOffset = this.getCurrentScrollOffset(this.$scrollContainer),
scrollThreshold = this.getScrollThreshold();
Expand All @@ -373,6 +378,13 @@
// start loading next page if content is shorter than page fold
if (currentScrollOffset >= scrollThreshold) {
this.next();

// flag as initialized when rendering is completed
this.one('rendered', function() {
this.isInitialized = true;
});
} else {
this.isInitialized = true;
}

return this;
Expand All @@ -384,6 +396,8 @@
* @public
*/
IAS.prototype.reinitialize = function () {
this.isInitialized = false;

this.unbind();
this.initialize();
};
Expand Down Expand Up @@ -557,7 +571,9 @@

this.extensions.push(extension);

this.reinitialize();
if (this.isInitialized) {
this.reinitialize();
}

return this;
};
Expand Down

0 comments on commit 2c75637

Please sign in to comment.