MCPcopy
hub / github.com/GoogleChromeLabs/ui-element-samples / setInert

Method setInert

3d-card-flip/inert.js:427–455  ·  view source on GitHub ↗

* Set whether the given element should be an inert root or not. * @param {Element} root * @param {boolean} inert

(root, inert)

Source from the content-addressed store, hash-verified

425 * @param {boolean} inert
426 */
427 setInert(root, inert) {
428 if (inert) {
429 if (this._inertRoots.has(root)) // element is already inert
430 return;
431
432 const inertRoot = new InertRoot(root, this);
433 root.setAttribute('inert', '');
434 this._inertRoots.set(root, inertRoot);
435 // If not contained in the document, it must be in a shadowRoot.
436 // Ensure inert styles are added there.
437 if (!this._document.body.contains(root)) {
438 let parent = root.parentNode;
439 while (parent) {
440 if (parent.nodeType === 11) {
441 addInertStyle(parent);
442 }
443 parent = parent.parentNode;
444 }
445 }
446 } else {
447 if (!this._inertRoots.has(root)) // element is already non-inert
448 return;
449
450 const inertRoot = this._inertRoots.get(root);
451 inertRoot.destructor();
452 this._inertRoots.delete(root);
453 root.removeAttribute('inert');
454 }
455 }
456
457 /**
458 * Get the InertRoot object corresponding to the given inert root element, if any.

Callers 6

_onDocumentLoadedMethod · 0.95
_watchForInertMethod · 0.95
inert.min.jsFile · 0.80
eFunction · 0.80
_adoptInertRootMethod · 0.80
inert.jsFile · 0.80

Calls 3

destructorMethod · 0.95
addInertStyleFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected