Debian Codegraph @

demo/shadow-dom.html

raw
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6 <title>Editor</title>
7 <style type="text/css" media="screen">
8 .scrollmargin {
9 text-align: center;
10 }
11 .large-button {
12 color: lightblue;
13 cursor: pointer;
14 font: 30px arial;
15 padding: 20px;
16 text-align: center;
17 border: medium solid transparent;
18 display: inline-block;
19 }
20 .large-button:hover {
21 border: medium solid lightgray;
22 border-radius: 10px 10px 10px 10px;
23 box-shadow: 0 0 12px 0 lightblue;
24 }
25 body {
26 transform: translateZ(0);
27 }
28 </style>
29 </head>
30 <body>
31
32 <div class="scrollmargin">
33 <span onclick="add()" class="large-button">+</span>
34 </div>
35
36 <ace-playground></ace-playground>
37
38 <script src="kitchen-sink/require.js"></script>
39 <script>
40 require.config({paths: { "ace" : "../src"}});
41 require(["ace/ace"], function(ace) {
42
43 var dom = require("ace/lib/dom");
44
45
46 class AcePlayground extends HTMLElement {
47 constructor() {
48 super();
49
50 var shadow = this.attachShadow({mode: "open"});
51
52 var dom = require("ace/lib/dom");
53 dom.buildDom(["div", {id: "host"},
54 ["div", {id: "html"}],
55 ["div", {id: "css"}],
56 ["iframe", {id: "preview"}],
57 ["style", `
58 #host {
59 border: solid 1px gray;
60 display: grid;
61 grid-template-areas: "html preview" "css preview";
62 }
63 #html {
64 grid-area: html;
65 height: 200px;
66 }
67 #css {
68 grid-area: css;
69 height: 200px;
70 }
71 #preview {
72 grid-area: preview;
73 width: 100%;
74 height: 100%;
75 border: none;
76 }
77 `]
78 ], shadow);
79
80 var htmlEditor = ace.edit(shadow.querySelector("#html"), {
81 theme: "ace/theme/solarized_light",
82 mode: "ace/mode/html",
83 value: "<div>\n\thollow world!\n</div>\n<script><\/script>",
84 autoScrollEditorIntoView: true
85 });
86 var cssEditor = ace.edit(shadow.querySelector("#css"), {
87 theme: "ace/theme/solarized_dark",
88 mode: "ace/mode/css",
89 value: "*{\n\tcolor:red\n}",
90 autoScrollEditorIntoView: true
91 });
92
93 var preview = shadow.querySelector("#preview");
94
95 this.htmlEditor = htmlEditor;
96 this.cssEditor = cssEditor;
97 this.preview = preview;
98
99 htmlEditor.renderer.attachToShadowRoot();
100
101 this.updatePreview = this.updatePreview.bind(this)
102 htmlEditor.on("input", this.updatePreview);
103 cssEditor.on("input", this.updatePreview);
104
105 this.updatePreview();
106 }
107 updatePreview() {
108 var code = this.htmlEditor.getValue() + "<style>" + this.cssEditor.getValue() + "</style>";
109 this.preview.src = "data:text/html," + encodeURIComponent(code)
110 }
111 }
112
113 customElements.define('ace-playground', AcePlayground);
114
115 window.add = function() {
116 var el = document.createElement("ace-playground");
117 document.body.appendChild(el);
118 };
119
120 });
121 </script>
122
123 <script src="./show_own_source.js"></script>
124
125 </body>
126 </html>