Skip to content

Commit 523ffd0

Browse files
authored
Guard against use of "document" madrobby#183 #1
Guard against use of "document" madrobby#183
2 parents f8f43dd + 8af9aa7 commit 523ffd0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

keymaster.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,13 @@
264264
};
265265

266266
// set the handlers globally on document
267-
addEvent(document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48
268-
addEvent(document, 'keyup', clearModifier);
269-
270-
// reset modifiers to false whenever the window is (re)focused.
271-
addEvent(window, 'focus', resetModifiers);
267+
if (typeof window !== 'undefined' && window.document) {
268+
addEvent(window.document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48
269+
addEvent(window.document, 'keyup', clearModifier);
270+
271+
// reset modifiers to false whenever the window is (re)focused.
272+
addEvent(window, 'focus', resetModifiers);
273+
}
272274

273275
// store previously defined key
274276
var previousKey = global.key;

0 commit comments

Comments
 (0)