const hasClass = (node, className) => ` ${node.classList} `.includes(` ${className} `);
module.exports = (node, from) => {
if (from && typeof from === 'object')
return from.contains(node);
Iif (typeof from !== 'string')
return false;
from = from.trim();
if (from.charAt(0) === '#')
return document.getElementById(from.replace('#', '')).contains(node);
Iif (from.charAt(0) !== '.')
return false;
from = from.replace('.', '');
while (node !== document.body.parentNode) {
if (hasClass(node, from))
return true;
node = node.parentNode;
}
return false;
};
|