Skip to content

Commit

Permalink
fixed some performance and cleanup issues
Browse files Browse the repository at this point in the history
Set this.horizontal and this.vertical properties to null when destroyed
and unbound scroll and mousewheel event listeners tied to the scrollbar
when it is destroyed.
  • Loading branch information
fontaineshu committed May 30, 2012
1 parent 6e96266 commit e745c0a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions antiscroll.js
Expand Up @@ -44,7 +44,7 @@
});

this.refresh();
};
}

/**
* refresh scrollbars
Expand Down Expand Up @@ -81,9 +81,11 @@
Antiscroll.prototype.destroy = function () {
if (this.horizontal) {
this.horizontal.destroy();
this.horizontal = null
}
if (this.vertical) {
this.vertical.destroy();
this.vertical = null
}
return this;
};
Expand Down Expand Up @@ -126,10 +128,12 @@
this.el.mousedown($.proxy(this, 'mousedown'));

// scrolling
this.pane.inner.scroll($.proxy(this, 'scroll'));
this.innerPaneScrollListener = $.proxy(this, 'scroll');
this.pane.inner.scroll(this.innerPaneScrollListener);

// wheel -optional-
this.pane.inner.bind('mousewheel', $.proxy(this, 'mousewheel'));
this.innerPaneMouseWheelListener = $.proxy(this, 'mousewheel');
this.pane.inner.bind('mousewheel', this.innerPaneMouseWheelListener);

// show
var initialDisplay = this.pane.options.initialDisplay;
Expand All @@ -138,7 +142,7 @@
this.show();
this.hiding = setTimeout($.proxy(this, 'hide'), parseInt(initialDisplay, 10) || 3000);
}
};
}

/**
* Cleans up.
Expand All @@ -149,6 +153,8 @@

Scrollbar.prototype.destroy = function () {
this.el.remove();
this.pane.inner.unbind('scroll', this.innerPaneScrollListener);
this.pane.inner.unbind('mousewheel', this.innerPaneMouseWheelListener);
return this;
};

Expand All @@ -175,7 +181,7 @@
if (!this.dragging) {
this.hide();
}
}
};

/**
* Called upon wrap scroll.
Expand Down Expand Up @@ -270,7 +276,7 @@
Scrollbar.Horizontal = function (pane) {
this.el = $('<div class="antiscroll-scrollbar antiscroll-scrollbar-horizontal">');
Scrollbar.call(this, pane);
}
};

/**
* Inherits from Scrollbar.
Expand All @@ -292,7 +298,7 @@
this.el
.css('width', trackWidth * paneWidth / innerEl.scrollWidth)
.css('left', trackWidth * innerEl.scrollLeft / innerEl.scrollWidth)
}
};

/**
* Called upon drag.
Expand Down Expand Up @@ -408,7 +414,7 @@
function f() {};
f.prototype = ctorB.prototype;
ctorA.prototype = new f;
};
}

/**
* Scrollbar size detection.
Expand All @@ -435,6 +441,6 @@
}

return size;
};
}

})(jQuery);

0 comments on commit e745c0a

Please sign in to comment.