Skip to content

Commit

Permalink
Rename method as toggleScrollListener
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia committed Sep 17, 2016
1 parent 00d3fb4 commit 38a20d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
26 changes: 13 additions & 13 deletions iron-scroll-target-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +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;
}

this._shouldHaveListener = hasListener;

if (!isAttached) {
return;
}
Expand All @@ -105,7 +102,7 @@

this._boundScrollHandler = this._boundScrollHandler || this._scrollHandler.bind(this);
this._oldScrollTarget = scrollTarget;
this._enableScrollListener(hasListener, scrollTarget);
this._toggleScrollListener(this._shouldHaveListener, scrollTarget);

}
},
Expand Down Expand Up @@ -235,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;
}
Expand All @@ -252,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);
}

};
Expand Down
6 changes: 3 additions & 3 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 38a20d0

Please sign in to comment.