From 3014a75b555488ce33cdce466e83b5b08891cc16 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 6 Sep 2021 18:38:10 +0000 Subject: [PATCH 1/5] guard document --- keymaster.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/keymaster.js b/keymaster.js index 8f5b5fc..e969436 100644 --- a/keymaster.js +++ b/keymaster.js @@ -264,8 +264,10 @@ }; // set the handlers globally on document - addEvent(document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 - addEvent(document, 'keyup', clearModifier); + if (document) { + addEvent(document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 + addEvent(document, 'keyup', clearModifier); + } // reset modifiers to false whenever the window is (re)focused. addEvent(window, 'focus', resetModifiers); From d8acc181697f6e351ca3b271f339dd2c33e938af Mon Sep 17 00:00:00 2001 From: will Date: Mon, 6 Sep 2021 18:41:29 +0000 Subject: [PATCH 2/5] window.document --- keymaster.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keymaster.js b/keymaster.js index e969436..7bd7c71 100644 --- a/keymaster.js +++ b/keymaster.js @@ -264,9 +264,9 @@ }; // set the handlers globally on document - if (document) { - addEvent(document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 - addEvent(document, 'keyup', clearModifier); + if (window.document) { + addEvent(window.document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 + addEvent(window.document, 'keyup', clearModifier); } // reset modifiers to false whenever the window is (re)focused. From 0872e93d486a7bc5618ac4dad1791a211711963d Mon Sep 17 00:00:00 2001 From: will Date: Mon, 6 Sep 2021 18:45:33 +0000 Subject: [PATCH 3/5] check for window as well --- keymaster.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keymaster.js b/keymaster.js index 7bd7c71..7aa0d17 100644 --- a/keymaster.js +++ b/keymaster.js @@ -264,7 +264,7 @@ }; // set the handlers globally on document - if (window.document) { + if (window && window.document) { addEvent(window.document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 addEvent(window.document, 'keyup', clearModifier); } From e0839d551d7165e9b0a9cd4677753edf8a0d6d30 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 6 Sep 2021 18:49:51 +0000 Subject: [PATCH 4/5] check typeof --- keymaster.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keymaster.js b/keymaster.js index 7aa0d17..463bb43 100644 --- a/keymaster.js +++ b/keymaster.js @@ -264,7 +264,7 @@ }; // set the handlers globally on document - if (window && window.document) { + if (typeof window !== 'undefined' && window.document) { addEvent(window.document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 addEvent(window.document, 'keyup', clearModifier); } From 8af9aa7ce8dd8639881f9896c178cc314a2e39fe Mon Sep 17 00:00:00 2001 From: will Date: Mon, 6 Sep 2021 18:51:05 +0000 Subject: [PATCH 5/5] expand check --- keymaster.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keymaster.js b/keymaster.js index 463bb43..290771a 100644 --- a/keymaster.js +++ b/keymaster.js @@ -267,11 +267,11 @@ if (typeof window !== 'undefined' && window.document) { addEvent(window.document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 addEvent(window.document, 'keyup', clearModifier); + + // reset modifiers to false whenever the window is (re)focused. + addEvent(window, 'focus', resetModifiers); } - // reset modifiers to false whenever the window is (re)focused. - addEvent(window, 'focus', resetModifiers); - // store previously defined key var previousKey = global.key;