Skip to content

Commit 9122b72

Browse files
Ensure a window context always exists
We always care about window resizes to refresh trigger points, but previously if a developer only had non-window-context waypoints the window resize handler would never exist and no auto resize refreshes would happen. This commit ensures there is always a window context so there is always a window resize handler.
1 parent 28c2167 commit 9122b72

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/context.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
element.waypointContextKey = this.key
3131
contexts[element.waypointContextKey] = this
3232
keyCounter += 1
33+
if (!Waypoint.windowContext) {
34+
Waypoint.windowContext = true
35+
Waypoint.windowContext = new Context(window)
36+
}
3337

3438
this.createThrottledScrollHandler()
3539
this.createThrottledResizeHandler()
@@ -46,7 +50,8 @@
4650
Context.prototype.checkEmpty = function() {
4751
var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal)
4852
var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical)
49-
if (horizontalEmpty && verticalEmpty) {
53+
var isWindow = this.element == this.element.window
54+
if (horizontalEmpty && verticalEmpty && !isWindow) {
5055
this.adapter.off('.waypoints')
5156
delete contexts[this.key]
5257
}
@@ -292,6 +297,7 @@
292297
Context.refreshAll()
293298
}
294299

300+
295301
Waypoint.requestAnimationFrame = function(callback) {
296302
var requestFn = window.requestAnimationFrame ||
297303
window.mozRequestAnimationFrame ||

test/context-spec.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) {
7171
$scroller.scrollTop($target.offset().top)
7272
expect(currentDirection).toBeNull()
7373
})
74-
75-
it('removes context from global lookup', function() {
76-
skipDestroy = true
77-
context.destroy()
78-
expect(Waypoint.Context.findByElement(window)).toBeFalsy()
79-
})
8074
})
8175

8276
describe('Waypoint.Context.refreshAll()', function() {

0 commit comments

Comments
 (0)