Skip to content

Commit

Permalink
Detect media element based on tag name
Browse files Browse the repository at this point in the history
This means it should work for foreign elements from other documents.
  • Loading branch information
joeldrapper committed Mar 1, 2024
1 parent ad01517 commit 8c340d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion dist/morphlex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/morphlex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Morph {
} else {
sensivity += 3;

if (sensitiveElement instanceof HTMLMediaElement && !sensitiveElement.ended) {
if (isMedia(sensitiveElement) && !sensitiveElement.ended) {
if (!sensitiveElement.paused) sensivity += 1;
if (sensitiveElement.currentTime > 0) sensivity += 1;
}
Expand Down Expand Up @@ -388,6 +388,12 @@ function isElement(node: Node | ReadonlyNode<Node>): boolean {
return node.nodeType === 1;
}

function isMedia(element: Element): element is HTMLMediaElement;
function isMedia(element: ReadonlyNode<Element>): element is ReadonlyNode<HTMLMediaElement>;
function isMedia(element: Element | ReadonlyNode<Element>): boolean {
return element.localName === "video" || element.localName === "audio";
}

function isInput(element: Element): element is HTMLInputElement;
function isInput(element: ReadonlyNode<Element>): element is ReadonlyNode<HTMLInputElement>;
function isInput(element: Element | ReadonlyNode<Element>): boolean {
Expand Down

0 comments on commit 8c340d1

Please sign in to comment.