From 16c134fc1e1c1a6938c2d86d8e884530a0ad4711 Mon Sep 17 00:00:00 2001 From: Andre Gagnon Date: Sat, 23 Jan 2021 17:32:45 -0600 Subject: Fix to work inside iframes. (#2069) * Fix to work inside iframes. Right now Plyr fails to load inside iframes because the selectors are not instances of Element (iframes have their own, separate globals). This is an alternative method to check isElement that will work inside iframes. This is battle-tested fallback code used before browsers supported HTMLElement. * Update is.js --- src/js/utils/is.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/js/utils/is.js') diff --git a/src/js/utils/is.js b/src/js/utils/is.js index 3bb50a00..5a60da06 100644 --- a/src/js/utils/is.js +++ b/src/js/utils/is.js @@ -13,7 +13,6 @@ const isFunction = (input) => getConstructor(input) === Function; const isArray = (input) => Array.isArray(input); const isWeakMap = (input) => instanceOf(input, WeakMap); const isNodeList = (input) => instanceOf(input, NodeList); -const isElement = (input) => instanceOf(input, Element); const isTextNode = (input) => getConstructor(input) === Text; const isEvent = (input) => instanceOf(input, Event); const isKeyboardEvent = (input) => instanceOf(input, KeyboardEvent); @@ -21,6 +20,13 @@ const isCue = (input) => instanceOf(input, window.TextTrackCue) || instanceOf(in const isTrack = (input) => instanceOf(input, TextTrack) || (!isNullOrUndefined(input) && isString(input.kind)); const isPromise = (input) => instanceOf(input, Promise) && isFunction(input.then); +const isElement = (input) => + input !== null && + (typeof input === "object") && + (input.nodeType === 1) && + (typeof input.style === "object") && + (typeof input.ownerDocument === "object"); + const isEmpty = (input) => isNullOrUndefined(input) || ((isString(input) || isArray(input) || isNodeList(input)) && !input.length) || -- cgit v1.2.3