Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: isHTMLElement will return false when given 'splide__list" #932

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js/splide-renderer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/splide-renderer.min.js.map

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion dist/js/splide.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,26 @@ function isNull(subject) {
return subject === null;
}

function isInstanceOf(subject, typeName) {
if (subject === null) {
return false;
}

var p = subject.__proto__;

while (p !== null) {
if (p.constructor.name === typeName) {
return true;
}

p = p.__proto__;
}

return false;
}

function isHTMLElement(subject) {
return subject instanceof HTMLElement;
return isInstanceOf(subject, "HTMLElement");
}

function toArray(value) {
Expand Down
20 changes: 19 additions & 1 deletion dist/js/splide.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,26 @@ function isNull(subject) {
return subject === null;
}

function isInstanceOf(subject, typeName) {
if (subject === null) {
return false;
}

var p = subject.__proto__;

while (p !== null) {
if (p.constructor.name === typeName) {
return true;
}

p = p.__proto__;
}

return false;
}

function isHTMLElement(subject) {
return subject instanceof HTMLElement;
return isInstanceOf(subject, "HTMLElement");
}

function toArray(value) {
Expand Down
20 changes: 19 additions & 1 deletion dist/js/splide.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,26 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
return subject === null;
}

function isInstanceOf(subject, typeName) {
if (subject === null) {
return false;
}

var p = subject.__proto__;

while (p !== null) {
if (p.constructor.name === typeName) {
return true;
}

p = p.__proto__;
}

return false;
}

function isHTMLElement(subject) {
return subject instanceof HTMLElement;
return isInstanceOf(subject, "HTMLElement");
}

function toArray(value) {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/splide.min.js

Large diffs are not rendered by default.

Binary file modified dist/js/splide.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/js/splide.min.js.map

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions dist/js/utils/splide-utils.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,24 @@ const isUndefined = apply(typeOf, "undefined");
function isNull(subject) {
return subject === null;
}
function isInstanceOf(subject, typeName) {
if (subject === null) {
return false;
}
let p = subject.__proto__;
while (p !== null) {
if (p.constructor.name === typeName) {
return true;
}
p = p.__proto__;
}
return false;
}
function isHTMLElement(subject) {
return subject instanceof HTMLElement;
return isInstanceOf(subject, "HTMLElement");
}
function isHTMLButtonElement(subject) {
return subject instanceof HTMLButtonElement;
return isInstanceOf(subject, "HTMLButtonElement");
}

function toArray(value) {
Expand Down
17 changes: 15 additions & 2 deletions dist/js/utils/splide-utils.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,24 @@ const isUndefined = apply(typeOf, "undefined");
function isNull(subject) {
return subject === null;
}
function isInstanceOf(subject, typeName) {
if (subject === null) {
return false;
}
let p = subject.__proto__;
while (p !== null) {
if (p.constructor.name === typeName) {
return true;
}
p = p.__proto__;
}
return false;
}
function isHTMLElement(subject) {
return subject instanceof HTMLElement;
return isInstanceOf(subject, "HTMLElement");
}
function isHTMLButtonElement(subject) {
return subject instanceof HTMLButtonElement;
return isInstanceOf(subject, "HTMLButtonElement");
}

function toArray(value) {
Expand Down
29 changes: 27 additions & 2 deletions src/js/utils/type/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ export function isNull( subject: unknown ): subject is null {
return subject === null;
}

/**
* Tests to see if the given TypeName appears anywhere
* in the prototype chain of the given subject.
* This is a lose version of the instanceof operator
* (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof)
* required when checking the type of elements that cross window and iframe bouderies.
*
* @param subject
* @param typeName
* @returns `true` if
*/
function isInstanceOf(subject: any, typeName: string) {
if (subject === null) {
return false;
}
let p = subject.__proto__;
while (p !== null) {
if (p.constructor.name === typeName) {
return true;
}
p = p.__proto__;
}
return false;
}

/**
* Checks if the given subject is an HTMLElement or not.
*
Expand All @@ -80,7 +105,7 @@ export function isNull( subject: unknown ): subject is null {
* @return `true` if the subject is an HTMLElement instance, or otherwise `false`.
*/
export function isHTMLElement( subject: unknown ): subject is HTMLElement {
return subject instanceof HTMLElement;
return isInstanceOf( subject, 'HTMLElement' );
}

/**
Expand All @@ -91,5 +116,5 @@ export function isHTMLElement( subject: unknown ): subject is HTMLElement {
* @return `true` if the subject is an HTMLButtonElement, or otherwise `false`.
*/
export function isHTMLButtonElement( subject: unknown ): subject is HTMLButtonElement {
return subject instanceof HTMLButtonElement;
return isInstanceOf( subject, 'HTMLButtonElement' );
}