Skip to content

Commit

Permalink
feat: init accepts an element to intialize else it will document quer…
Browse files Browse the repository at this point in the history
…y filter elements
  • Loading branch information
frankpagan committed Dec 14, 2024
1 parent d8851f1 commit f7c7915
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,28 @@ const elements = new Map();
const filters = new Map();
const dispatch = new Map();
const selector =
"[filter-selector], [filter-closest], [filter-parent], [filter-next], [filter-previous]";
"[filter-selector], [filter-closest], [filter-parent], [filter-next], [filter-previous], [filter-key], [filter-query-key], [filter-search], [filter-sort-key], [filter-on], [filter-limit], [filter-index]";

async function init() {
let filterSelector =
selector +
", [filter-key], [filter-query-key], [filter-search], [filter-sort-key], [filter-on], [filter-limit], [filter-index]";
let filterElements = document.querySelectorAll(filterSelector);

for (let i = 0; i < filterElements.length; i++)
await initElement(filterElements[i]);
async function init(element) {
if (!element) {
element = document.querySelectorAll(selector);
for (let i = 0; i < element.length; i++) {
await initElement(element[i]);
}
} else {
if (
!(element instanceof HTMLCollection) &&
!(element instanceof NodeList) &&
!Array.isArray(element)
) {
element = [element];
}
for (let i = 0; i < element.length; i++) {
if (element[i].matches(selector)) {
await initElement(element[i]);
}
}
}

return true;
}
Expand Down Expand Up @@ -459,7 +471,7 @@ observer.init({
}
});

// init()
init();

export default {
init,
Expand Down

0 comments on commit f7c7915

Please sign in to comment.