1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/legacy/keyboardEvent.js
Kasin Sparks a24b840153
Replace deprecated initEvent()
Replaced deprecated initEvent() with recommended event constructor, Event(), as per MDN web docs specification.
https://developer.mozilla.org/en-US/docs/Web/API/Event/initEvent#browser_compatibility
2024-01-21 21:02:18 -05:00

46 lines
1.5 KiB
JavaScript

/**
* 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 = new Event(eventName, { bubbles: !!options.bubbles, cancelable: !!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));