Clear intervals if the plugin is destroyed.

This commit is contained in:
Hyunje Alex Jun 2014-10-31 19:17:38 +00:00
parent a3bf38ada2
commit aa92487ed3

View File

@ -57,6 +57,7 @@
return this.each(function () { return this.each(function () {
var settings = $.extend(true, {}, defaultSettings); var settings = $.extend(true, {}, defaultSettings);
var $this = $(this); var $this = $(this);
var isPluginAlive = function () { return !!$this; };
if (typeof suppliedSettings === "object") { if (typeof suppliedSettings === "object") {
// Override default settings with any supplied // Override default settings with any supplied
@ -544,6 +545,11 @@
function startScrolling() { function startScrolling() {
if (!scrollingLoop) { if (!scrollingLoop) {
scrollingLoop = setInterval(function () { scrollingLoop = setInterval(function () {
if (!isPluginAlive()) {
clearInterval(scrollingLoop);
return;
}
$this.scrollTop($this.scrollTop() + scrollDiff.top); $this.scrollTop($this.scrollTop() + scrollDiff.top);
$this.scrollLeft($this.scrollLeft() + scrollDiff.left); $this.scrollLeft($this.scrollLeft() + scrollDiff.left);
updateGeometry(); updateGeometry();
@ -712,6 +718,11 @@
clearInterval(breakingProcess); clearInterval(breakingProcess);
breakingProcess = setInterval(function () { breakingProcess = setInterval(function () {
if (!isPluginAlive()) {
clearInterval(breakingProcess);
return;
}
if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) { if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
clearInterval(breakingProcess); clearInterval(breakingProcess);
return; return;
@ -769,6 +780,7 @@
$scrollbarYRail.remove(); $scrollbarYRail.remove();
// clean all variables // clean all variables
$this =
$scrollbarXRail = $scrollbarXRail =
$scrollbarYRail = $scrollbarYRail =
$scrollbarX = $scrollbarX =