From c735536edeccd303813fcac30e1427eee2c74699 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sun, 30 Oct 2016 11:51:05 +0100 Subject: [PATCH] fix(panel): don't bind scroll event if scrolling is disabled Previously, the panel would bind to a scroll event and determine within the handler whether to do anything. This change moves the check outside of the event handler and only binds if scrolling is enabled. --- src/components/panel/panel.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/components/panel/panel.js b/src/components/panel/panel.js index 234f4e2a54c..b787e5cabe8 100644 --- a/src/components/panel/panel.js +++ b/src/components/panel/panel.js @@ -1889,23 +1889,24 @@ MdPanelRef.prototype._configureClickOutsideToClose = function() { * @private */ MdPanelRef.prototype._configureScrollListener = function() { - var updatePosition = angular.bind(this, this._updatePosition); - var debouncedUpdatePosition = this._$$rAF.throttle(updatePosition); - var self = this; + // No need to bind the event if scrolling is disabled. + if (!this.config['disableParentScroll']) { + var updatePosition = angular.bind(this, this._updatePosition); + var debouncedUpdatePosition = this._$$rAF.throttle(updatePosition); + var self = this; - var onScroll = function() { - if (!self.config['disableParentScroll']) { + var onScroll = function() { debouncedUpdatePosition(); - } - }; + }; - // Add listeners. - this._$window.addEventListener('scroll', onScroll, true); + // Add listeners. + this._$window.addEventListener('scroll', onScroll, true); - // Queue remove listeners function. - this._removeListeners.push(function() { - self._$window.removeEventListener('scroll', onScroll, true); - }); + // Queue remove listeners function. + this._removeListeners.push(function() { + self._$window.removeEventListener('scroll', onScroll, true); + }); + } };