Skip to content

Instantly share code, notes, and snippets.

View franktopel's full-sized avatar
🏠
Working from home

Frank Topel franktopel

🏠
Working from home
View GitHub Profile
@heyMP
heyMP / utils.js
Last active June 11, 2024 18:30
Recursively find elements through multiple layers of shadow dom.
/**
* Example usage:
* const hotspots = findAllDeep(element, `[slot*="hotspot"]`, 10);
*/
const findAllDeep = (parent, selectors, depth = null) => {
let nodes = new Set();
let currentDepth = 1;
const recordResult = (nodesArray) => {
for (const node of nodesArray) {
nodes.add(node)
@franktopel
franktopel / HTMLBaseElement.md
Last active August 25, 2023 12:03
HTMLBaseElement class solving the problem of connectedCallback being called before children are parsed

There is a huge practical problem with web components spec v1:

In certain cases connectedCallback is being called when the element's child nodes are not yet available.

This makes web components dysfunctional in those cases where they rely on their children for setup.

See WICG/webcomponents#551 for reference.

To solve this, we have created a HTMLBaseElement class in our team which serves as the new class to extend autonomous custom elements from.

@Alex1990
Alex1990 / safeActiveElement.js
Last active December 20, 2019 09:54
Get the current active element safely.
/**
* Get the current active element safely.
* Ref: https://github.com/jquery/jquery-ui/blob/2b84531ae9331f60e4d739fabca6d78abde89ae1/ui/safe-active-element.js
*/
function safeActiveElement(doc) {
doc = doc || document;
var activeElement;
// Support: IE 9 only
// IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>