* Set whether the given element should be an inert root or not. * @param {Element} root * @param {boolean} inert
(root, inert)
| 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. |
no test coverage detected