Destroy old infinite scrollers to keep event bindings from piling up

This commit is contained in:
Raphael Sofaer 2011-05-02 14:08:29 -07:00
parent bc8b6097bc
commit 2abb592833

View file

@ -23,6 +23,11 @@
};
};
InfiniteScroll.prototype.reInitialize = function(){
this.clear();
this.initialize();
};
InfiniteScroll.prototype.initialize = function(){
$('#main_stream').infinitescroll(this.options(), function() {
Diaspora.widgets.publish("stream/scrolled");
@ -30,10 +35,14 @@
};
InfiniteScroll.prototype.start = function() {
Diaspora.widgets.subscribe("stream/reloaded", this.initialize, this);
Diaspora.widgets.subscribe("stream/reloaded", this.reInitialize, this);
this.initialize();
};
InfiniteScroll.prototype.clear = function() {
$('#main_stream').infinitescroll('destroy');
};
Diaspora.widgets.add("infinitescroll", InfiniteScroll);
})();