mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Add KeyboardEvent constructor polyfill
(cherry picked from commit 11ae2ff43f
)
This commit is contained in:
parent
8c8e240792
commit
ab5c4949c3
2 changed files with 49 additions and 0 deletions
|
@ -32,6 +32,7 @@ import './components/playback/playerSelectionMenu';
|
|||
import './legacy/domParserTextHtml';
|
||||
import './legacy/focusPreventScroll';
|
||||
import './legacy/htmlMediaElement';
|
||||
import './legacy/keyboardEvent';
|
||||
import './legacy/vendorStyles';
|
||||
import { currentSettings } from './scripts/settings/userSettings';
|
||||
import taskButton from './scripts/taskbutton';
|
||||
|
|
48
src/legacy/keyboardEvent.js
Normal file
48
src/legacy/keyboardEvent.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Polyfill for KeyboardEvent
|
||||
* - Constructor.
|
||||
*/
|
||||
|
||||
(function (window) {
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
new window.KeyboardEvent('event', { bubbles: true, cancelable: true });
|
||||
} catch (e) {
|
||||
// We can't use `KeyboardEvent` in old WebKit because `initKeyboardEvent`
|
||||
// doesn't seem to populate some properties (`keyCode`, `which`) that
|
||||
// are read-only.
|
||||
const KeyboardEventOriginal = window.Event;
|
||||
|
||||
const KeyboardEvent = function (eventName, options) {
|
||||
options = options || {};
|
||||
|
||||
const event = document.createEvent('Event');
|
||||
|
||||
event.initEvent(eventName, !!options.bubbles, !!options.cancelable);
|
||||
|
||||
event.view = options.view || document.defaultView;
|
||||
|
||||
event.key = options.key || options.keyIdentifier || '';
|
||||
event.keyCode = options.keyCode || 0;
|
||||
event.code = options.code || '';
|
||||
event.charCode = options.charCode || 0;
|
||||
event.char = options.char || '';
|
||||
event.which = options.which || 0;
|
||||
|
||||
event.location = options.location || options.keyLocation || 0;
|
||||
|
||||
event.ctrlKey = !!options.ctrlKey;
|
||||
event.altKey = !!options.altKey;
|
||||
event.shiftKey = !!options.shiftKey;
|
||||
event.metaKey = !!options.metaKey;
|
||||
|
||||
event.repeat = !!options.repeat;
|
||||
|
||||
return event;
|
||||
};
|
||||
|
||||
KeyboardEvent.prototype = KeyboardEventOriginal.prototype;
|
||||
window.KeyboardEvent = KeyboardEvent;
|
||||
}
|
||||
}(window));
|
Loading…
Add table
Add a link
Reference in a new issue