Debian Codegraph @

tests/gui/books/shadow-dom/shadow-dom.js

raw
1 (function() {
2 let shadowHost = null;
3 let shadowInput = null;
4
5 document.addEventListener('keypress', function(e) {
6 if (e.key === 'x' || e.key === 'X') {
7 if (shadowHost && shadowHost.isConnected) {
8 shadowInput.focus();
9 return;
10 }
11
12 shadowHost = document.createElement('div');
13 shadowHost.id = 'shadow-input-host';
14 shadowHost.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:9999;';
15
16 document.body.appendChild(shadowHost);
17
18 const shadowRoot = shadowHost.attachShadow({ mode: 'open' });
19
20 shadowInput = document.createElement('input');
21 shadowInput.type = 'text';
22 shadowInput.id = 'shadow-input';
23 shadowInput.placeholder = 'Shadow DOM input (press Escape to close)';
24 shadowInput.style.cssText = 'font-size:1.2em;padding:8px;width:300px;';
25
26 shadowRoot.appendChild(shadowInput);
27 shadowInput.focus();
28
29 shadowInput.addEventListener('keydown', function(e) {
30 if (e.key === 'Escape') {
31 shadowHost.remove();
32 shadowHost = null;
33 shadowInput = null;
34 }
35 });
36 }
37 });
38 })();