Skip to content

Commit 2c84afe

Browse files
Merge pull request imakewebthings#365 from lsthornt/master
Prevents console warnings from disabled waypoints
2 parents 11e5403 + f6c8507 commit 2c84afe

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

lib/waypoints.debug.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
2424
window.Waypoint.Context.prototype.refresh = function() {
2525
for (var axis in this.waypoints) {
2626
for (var key in this.waypoints[axis]) {
27-
var style = this.waypoints[axis][key].element.style
27+
var waypoint = this.waypoints[axis][key]
28+
var style = waypoint.element.style
29+
if (!waypoint.enabled) {
30+
continue
31+
}
2832
if (style && style.display === 'none') {
2933
console.error(displayNoneMessage)
3034
}

src/debug.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
window.Waypoint.Context.prototype.refresh = function() {
1919
for (var axis in this.waypoints) {
2020
for (var key in this.waypoints[axis]) {
21-
var style = this.waypoints[axis][key].element.style
21+
var waypoint = this.waypoints[axis][key]
22+
var style = waypoint.element.style
23+
if (!waypoint.enabled) {
24+
continue
25+
}
2226
if (style && style.display === 'none') {
2327
console.error(displayNoneMessage)
2428
}

test/debug-spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,22 @@ describe('Waypoints debug script', function() {
5454
describe('fixed position detection', function() {
5555

5656
})
57+
58+
describe('respect waypoint disabling', function() {
59+
beforeEach(function() {
60+
element = document.getElementById('same1')
61+
waypoint = new Waypoint({
62+
element: element,
63+
handler: function() {}
64+
})
65+
element.style.display = 'none'
66+
waypoint.disable()
67+
})
68+
69+
it('does not log a console error', function() {
70+
spyOn(console, 'error')
71+
waypoint.context.refresh()
72+
expect(console.error.calls.length).toEqual(0)
73+
})
74+
})
5775
})

0 commit comments

Comments
 (0)