Skip to content

Commit

Permalink
get rid of jQuery.is( usages
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0gr committed Nov 24, 2022
1 parent 50aa9b6 commit 5f900f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
18 changes: 18 additions & 0 deletions addon/src/-private/element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Borrowed from jquery https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/css/hiddenVisibleSelectors.js
*
* Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero.
*
* Elements with visibility: hidden or opacity: 0 are considered visible, since they still consume space in the layout.
*
* @private
* @param {Element} element
* @returns boolean
*/
export function isVisible(element) {
return !!(
element.offsetWidth ||
element.offsetHeight ||
element.getClientRects().length
);
}
5 changes: 3 additions & 2 deletions addon/src/properties/is-hidden.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { guardMultiple, $ } from '../-private/helpers';
import { guardMultiple } from '../-private/helpers';
import { findMany } from '../-private/finders';
import { getter } from '../macros/index';
import { isVisible } from '../-private/element';

/**
* Validates if an element or set of elements is hidden or does not exist in the DOM.
Expand Down Expand Up @@ -82,6 +83,6 @@ export function isHidden(selector, userOptions = {}) {

guardMultiple(elements, selector);

return elements.length === 0 || $(elements[0]).is(':hidden');
return elements.length === 0 || !isVisible(elements[0]);
});
}
5 changes: 3 additions & 2 deletions addon/src/properties/is-visible.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { guardMultiple, $ } from '../-private/helpers';
import { guardMultiple } from '../-private/helpers';
import { findMany } from '../-private/finders';
import { getter } from '../macros/index';
import { isVisible as isElementVisible } from '../-private/element';

/**
* Validates if an element or set of elements are visible.
Expand Down Expand Up @@ -87,6 +88,6 @@ export function isVisible(selector, userOptions = {}) {
let elements = findMany(this, selector, options);
guardMultiple(elements, selector, options.multiple);

return elements.length === 1 && $(elements[0]).is(':visible');
return elements.length === 1 && isElementVisible(elements[0]);
});
}

0 comments on commit 5f900f3

Please sign in to comment.