mirror of
https://github.com/webslides/WebSlides.git
synced 2025-08-22 21:03:23 +02:00
Minor refactor
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import Keys from '../utils/keys';
|
||||
import DOM from '../utils/dom';
|
||||
|
||||
/**
|
||||
* Keyboard plugin.
|
||||
@@ -28,16 +29,8 @@ export default class Keyboard {
|
||||
let method;
|
||||
let argument;
|
||||
|
||||
// Check if there's a focused element that might use the keyboard.
|
||||
if (document.activeElement) {
|
||||
const isContentEditable = document.activeElement
|
||||
.contentEditable !== 'inherit';
|
||||
const isInput = ['INPUT', 'SELECT', 'OPTION', 'TEXTAREA']
|
||||
.indexOf(document.activeElement.tagName) > -1;
|
||||
|
||||
if (isInput || isContentEditable) {
|
||||
return;
|
||||
}
|
||||
if (DOM.isFocusableElement()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.which) {
|
||||
|
@@ -144,4 +144,25 @@ export default class DOM {
|
||||
static toArray(iterable) {
|
||||
return [].slice.call(iterable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the document has focus on an input or contenteditable
|
||||
* element.
|
||||
* @return {boolean} Whether the focused element is an input or content
|
||||
* editable.
|
||||
*/
|
||||
static isFocusableElement() {
|
||||
let result = false;
|
||||
|
||||
if (document.activeElement) {
|
||||
const isContentEditable = document.activeElement
|
||||
.contentEditable !== 'inherit';
|
||||
const isInput = ['INPUT', 'SELECT', 'OPTION', 'TEXTAREA']
|
||||
.indexOf(document.activeElement.tagName) > -1;
|
||||
|
||||
result = isInput || isContentEditable;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user