Remove most jQuery function calls from the repository topic box (#30191)

Remove most jQuery function calls

---------

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
(cherry picked from commit 0497b2607d1052e771af4017c2c4180adb7d86b2)
This commit is contained in:
Yarden Shoham 2024-03-31 18:39:50 +03:00 committed by Gergely Nagy
parent 4be577085e
commit 1983226581
No known key found for this signature in database
5 changed files with 54 additions and 75 deletions

View file

@ -51,8 +51,22 @@ export function isElemHidden(el) {
return res[0];
}
export function queryElemSiblings(el, selector = '*') {
return Array.from(el.parentNode.children).filter((child) => child !== el && child.matches(selector));
function applyElemsCallback(elems, fn) {
if (fn) {
for (const el of elems) {
fn(el);
}
}
return elems;
}
export function queryElemSiblings(el, selector = '*', fn) {
return applyElemsCallback(Array.from(el.parentNode.children).filter((child) => child !== el && child.matches(selector)), fn);
}
// it works like jQuery.children: only the direct children are selected
export function queryElemChildren(parent, selector = '*', fn) {
return applyElemsCallback(parent.querySelectorAll(`:scope > ${selector}`), fn);
}
export function onDomReady(cb) {