Skip to content

Commit

Permalink
getCollectionElements: Now items query will return `HTMLDivElemen…
Browse files Browse the repository at this point in the history
…t[]` instead of `NodeListOf<HTMLDivElement>`
  • Loading branch information
alexiglesias93 committed Oct 1, 2021
1 parent 550dee7 commit 7112b4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finsweet/ts-utils",
"version": "0.13.7",
"version": "0.13.8",
"description": "Typescript utils for custom Webflow projects.",
"main": "index.ts",
"module": "index.ts",
Expand Down
10 changes: 3 additions & 7 deletions webflow/getCollectionElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
* @param page The page document.
* @returns The specified collection element/elements.
*/
export function getCollectionElements(
reference: string | Element,
target: 'items',
page?: Document
): NodeListOf<HTMLDivElement>;
export function getCollectionElements(reference: string | Element, target: 'items', page?: Document): HTMLDivElement[];
export function getCollectionElements(
reference: string | Element,
target: 'next' | 'previous',
Expand All @@ -25,13 +21,13 @@ export function getCollectionElements(
reference: string | Element,
target: 'wrapper' | 'list' | 'items' | 'next' | 'previous',
page: Document = document
): HTMLDivElement | NodeListOf<HTMLDivElement> | HTMLAnchorElement | null | undefined {
): HTMLDivElement | HTMLDivElement[] | HTMLAnchorElement | null | undefined {
const referenceElement = typeof reference === 'string' ? page.querySelector<HTMLDivElement>(reference) : reference;
if (!referenceElement) return;

if (target === 'wrapper') return referenceElement.closest<HTMLDivElement>(`.w-dyn-list`);

if (target === 'items') return referenceElement.querySelectorAll<HTMLDivElement>('.w-dyn-item');
if (target === 'items') return [...referenceElement.querySelectorAll<HTMLDivElement>('.w-dyn-item')];

if (target === 'next') return referenceElement.querySelector<HTMLAnchorElement>('.w-pagination-next');
if (target === 'previous') return referenceElement.querySelector<HTMLAnchorElement>('.w-pagination-previous');
Expand Down

0 comments on commit 7112b4b

Please sign in to comment.