bigpipe-util
Version:
This library currently implements small part of Facebook BigPipe so far, but the advantage is to efficiently insert/replace content and work with the DOM. It is also possible to easily call JavaScript modules from PHP.
39 lines (29 loc) • 852 B
JavaScript
import CSSCore from "fbjs/lib/CSSCore";
export function byTag(node, tagName) {
tagName = tagName.toUpperCase();
node = find(node, function (el) {
return el.nodeName === tagName;
});
return node instanceof Element ? node : null;
}
export function byClass(node, className) {
node = find(node, function (el) {
return el instanceof Element && CSSCore.hasClass(el, className);
});
return node instanceof Element ? node : null;
}
export function byAttribute(node, attribute) {
node = find(node, function (el) {
return el instanceof Element && el.hasAttribute(attribute);
});
return node instanceof Element ? node : null;
}
export function find(node, callback) {
while (node) {
if (callback(node)) {
return node;
}
node = node.parentNode;
}
return null;
}