1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-08-22 21:03:23 +02:00

Minor refactor

This commit is contained in:
Antonio Laguna
2017-03-12 23:01:41 +01:00
parent 94f21e7232
commit f8340bd821
2 changed files with 24 additions and 10 deletions

View File

@@ -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) {

View File

@@ -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;
}
}