Skip to content

Commit

Permalink
getCollectionElements: Added 'next' button query
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiglesias93 committed Sep 27, 2021
1 parent a8f242b commit 5e5157f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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.4",
"version": "0.13.5",
"description": "Typescript utils for custom Webflow projects.",
"main": "index.ts",
"module": "index.ts",
Expand Down
11 changes: 9 additions & 2 deletions webflow/getCollectionElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,30 @@ export function getCollectionElements(
target: 'items',
page?: Document
): NodeListOf<HTMLDivElement>;
export function getCollectionElements(
reference: string | Element,
target: 'next',
page?: Document
): HTMLAnchorElement | null | undefined;
export function getCollectionElements(
reference: string | Element,
target: 'wrapper' | 'list',
page?: Document
): HTMLDivElement | null | undefined;
export function getCollectionElements(
reference: string | Element,
target: 'wrapper' | 'list' | 'items',
target: 'wrapper' | 'list' | 'items' | 'next',
page: Document = document
): HTMLDivElement | NodeListOf<HTMLDivElement> | null | undefined {
): HTMLDivElement | NodeListOf<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 === 'next') return referenceElement.querySelector<HTMLAnchorElement>('.w-pagination-next');

return (
referenceElement.querySelector<HTMLDivElement>(`.w-dyn-items`) ||
referenceElement.closest<HTMLDivElement>(`.w-dyn-items`)
Expand Down

0 comments on commit 5e5157f

Please sign in to comment.