mirror of
https://github.com/webslides/WebSlides.git
synced 2025-08-23 05:14:29 +02:00
Minor refactor
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import Keys from '../utils/keys';
|
import Keys from '../utils/keys';
|
||||||
|
import DOM from '../utils/dom';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keyboard plugin.
|
* Keyboard plugin.
|
||||||
@@ -28,17 +29,9 @@ export default class Keyboard {
|
|||||||
let method;
|
let method;
|
||||||
let argument;
|
let argument;
|
||||||
|
|
||||||
// Check if there's a focused element that might use the keyboard.
|
if (DOM.isFocusableElement()) {
|
||||||
if (document.activeElement) {
|
|
||||||
const isContentEditable = document.activeElement
|
|
||||||
.contentEditable !== 'inherit';
|
|
||||||
const isInput = ['INPUT', 'SELECT', 'OPTION', 'TEXTAREA']
|
|
||||||
.indexOf(document.activeElement.tagName) > -1;
|
|
||||||
|
|
||||||
if (isInput || isContentEditable) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch (event.which) {
|
switch (event.which) {
|
||||||
case Keys.AV_PAGE:
|
case Keys.AV_PAGE:
|
||||||
|
@@ -144,4 +144,25 @@ export default class DOM {
|
|||||||
static toArray(iterable) {
|
static toArray(iterable) {
|
||||||
return [].slice.call(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