diff --git a/iron-scroll-target-behavior.html b/iron-scroll-target-behavior.html index 8d5172b..7674611 100644 --- a/iron-scroll-target-behavior.html +++ b/iron-scroll-target-behavior.html @@ -79,13 +79,12 @@ _shouldHaveListener: true, _scrollTargetChanged: function(scrollTarget, isAttached) { - var eventTarget, hasListener = this._shouldHaveListener; + var eventTarget; if (this._oldScrollTarget) { - this._enableScrollListener(false, this._oldScrollTarget); + this._toggleScrollListener(false, this._oldScrollTarget); this._oldScrollTarget = null; } - if (!isAttached) { return; } @@ -103,7 +102,7 @@ this._boundScrollHandler = this._boundScrollHandler || this._scrollHandler.bind(this); this._oldScrollTarget = scrollTarget; - this._enableScrollListener(hasListener, scrollTarget); + this._toggleScrollListener(this._shouldHaveListener, scrollTarget); } }, @@ -233,13 +232,7 @@ return this.scrollTarget instanceof HTMLElement; }, - /** - * Enables or disables the scroll event listener - * - * @param {boolean} yes True to add the event, False to remove it - * @param {HTMLElement} scrollTarget The scroll target - */ - _enableScrollListener: function(yes, scrollTarget) { + _toggleScrollListener: function(yes, scrollTarget) { if (!this._boundScrollHandler) { return; } @@ -250,7 +243,16 @@ } else { eventTarget.removeEventListener('scroll', this._boundScrollHandler); } + }, + + /** + * Enables or disables the scroll event listener. + * + * @param {boolean} yes True to add the event, False to remove it. + */ + toggleScrollListener: function(yes) { this._shouldHaveListener = yes; + this._toggleScrollListener(yes, this.scrollTarget); } }; diff --git a/test/basic.html b/test/basic.html index cbaade2..d3a04e6 100644 --- a/test/basic.html +++ b/test/basic.html @@ -95,16 +95,16 @@ }); }); - test('_enableScrollListener', function(done) { + test('toggleScrollListener', function(done) { flush(function() { xScroll._scrollHandler = sinon.spy(); xScroll.scrollTarget = 'temporaryScrollingRegion'; xScroll.scroll(0, 100); - xScroll._enableScrollListener(true, xScroll.scrollTarget); + xScroll.toggleScrollListener(true); setTimeout(function() { assert.isTrue(xScroll._scrollHandler.called, '_scrollHandler should be called'); xScroll._scrollHandler.reset(); - xScroll._enableScrollListener(false, xScroll.scrollTarget); + xScroll.toggleScrollListener(false); xScroll.scroll(0, 200); setTimeout(function() { assert.isFalse(xScroll._scrollHandler.called, '_scrollHandler should not be called');