subcollection
Version:
A collection of scripts to send Core Web Vital data to GA4
41 lines (33 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getSelector = getSelector;
/**
* Get Largest Layout Shift Entry
*
* @since 1.0.0
* @param {object} node The object to iterate over.
* @param {number} maxLen the max length of the string
* @returns {Array} Returns the picked values.
*
*/
function getSelector(node) {
var maxLen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
var sel = '';
try {
while (node && node.nodeType !== 9) {
var part = node.id ? "#".concat(node.id) : node.nodeName.toLowerCase() + (node.className && node.className.length ? ".".concat(Array.from(node.classList.values()).join('.')) : '');
if (sel.length + part.length > maxLen - 1) {
return sel || part;
}
sel = sel ? "".concat(part, " > ").concat(sel) : part;
if (node.id) {
break;
}
node = node.parentNode; // eslint-disable-line no-param-reassign
}
} catch (err) {// Do nothing...
}
return sel;
}