remove mobile hotkey

This commit is contained in:
Harvey committed 2022-01-10 09:49:40 +08:00
1 parent d33a7229a9
commit c9a9e8e6e7
3 files changed
+100 -96

No files matched your search

+46 -42
View File
@@ -1,58 +1,62 @@
import { isMobile } from './utils';
export default class Hotkey {
constructor(art) {
this.art = art;
this.keys = {};
const {
option,
events: { proxy },
} = art;
art.once('ready', () => {
if (art.option.hotkey && !isMobile) {
this.init();
}
});
}
if (option.hotkey) {
art.once('ready', () => {
this.add(27, () => {
if (art.fullscreenWeb) {
art.fullscreenWeb = false;
}
});
init() {
const { proxy } = this.art.events;
this.add(32, () => {
art.toggle();
});
this.add(27, () => {
if (this.art.fullscreenWeb) {
this.art.fullscreenWeb = false;
}
});
this.add(37, () => {
art.backward = 5;
});
this.add(32, () => {
this.art.toggle();
});
this.add(38, () => {
art.volume += 0.1;
});
this.add(37, () => {
this.art.backward = 5;
});
this.add(39, () => {
art.forward = 5;
});
this.add(38, () => {
this.art.volume += 0.1;
});
this.add(40, () => {
art.volume -= 0.1;
});
this.add(39, () => {
this.art.forward = 5;
});
proxy(window, 'keydown', (event) => {
if (art.isFocus) {
const tag = document.activeElement.tagName.toUpperCase();
const editable = document.activeElement.getAttribute('contenteditable');
if (tag !== 'INPUT' && tag !== 'TEXTAREA' && editable !== '' && editable !== 'true') {
const events = this.keys[event.keyCode];
if (events) {
event.preventDefault();
for (let index = 0; index < events.length; index++) {
events[index].call(art, event);
}
art.emit('hotkey', event);
}
this.add(40, () => {
this.art.volume -= 0.1;
});
proxy(window, 'keydown', (event) => {
if (this.art.isFocus) {
const tag = document.activeElement.tagName.toUpperCase();
const editable = document.activeElement.getAttribute('contenteditable');
if (tag !== 'INPUT' && tag !== 'TEXTAREA' && editable !== '' && editable !== 'true') {
const events = this.keys[event.keyCode];
if (events) {
event.preventDefault();
for (let index = 0; index < events.length; index++) {
events[index].call(this.art, event);
}
this.art.emit('hotkey', event);
}
});
});
}
}
}
});
}
add(key, event) {