|
19 | 19 | {margin-right:5px} |
20 | 20 |
|
21 | 21 |
|
22 | | - #output |
| 22 | + #output, web-editor |
23 | 23 | {height:100%;border:2px solid lightgray;box-sizing:border-box;padding:10px} |
24 | 24 |
|
25 | 25 |
|
|
61 | 61 | <div id=output class=markdown-body> |
62 | 62 | </div> |
63 | 63 |
|
| 64 | + <web-editor component mode=html style='display:none'></web-editor> |
| 65 | + |
64 | 66 | </div> |
65 | 67 |
|
66 | 68 | </template> |
|
82 | 84 |
|
83 | 85 | obj.initmod = function(params){ |
84 | 86 |
|
85 | | - $ = mod.rd(params,'$',$); |
86 | | - debug = mod.rd(params,'debug',debug); |
| 87 | + $ = mod.rd(params,'$',$); |
| 88 | + debug = mod.rd(params,'debug',debug); |
87 | 89 |
|
88 | 90 | }//initmod |
89 | 91 |
|
|
92 | 94 |
|
93 | 95 | var md; |
94 | 96 |
|
| 97 | + var cur = {}; |
| 98 | + cur.mode = 'md'; |
| 99 | + cur.txt = null; |
| 100 | + |
95 | 101 | var shadow; |
96 | 102 | var output; |
97 | 103 | var chk = {}; |
98 | 104 |
|
| 105 | + var editor; |
99 | 106 |
|
100 | 107 | var btn = {}; |
| 108 | + var show = {}; |
101 | 109 |
|
102 | 110 |
|
103 | 111 | //: |
|
106 | 114 | obj.init = async function(){ |
107 | 115 | debug=eval(debug); |
108 | 116 | debug('init',obj.version); |
109 | | - |
110 | | - await libs(); |
| 117 | + editor = mod['web-editor']; |
| 118 | + |
| 119 | + |
| 120 | + await Promise.all([ |
| 121 | + libs(), |
| 122 | + mod.auto(), |
| 123 | + ]); |
111 | 124 |
|
112 | 125 |
|
113 | 126 | }//init |
|
161 | 174 |
|
162 | 175 | btn.mode = function(chk,id){ |
163 | 176 | debug('btn.mode',id); |
| 177 | + switch(id){ |
| 178 | + |
| 179 | + case 'mode-md' : cur.mode='md'; break; |
| 180 | + case 'mode-html' : cur.mode='html'; break; |
| 181 | + |
| 182 | + }//switch |
| 183 | + display(); |
| 184 | + |
164 | 185 | }//mode |
165 | 186 |
|
166 | 187 |
|
|
187 | 208 | |
188 | 209 | */ |
189 | 210 |
|
190 | | - obj.display = async function(txt){ |
| 211 | + |
| 212 | + obj.display = async function(txt){return display(txt)} |
| 213 | + |
| 214 | + function displayt(txt){ |
191 | 215 | debug('display'); |
192 | 216 | await libs; |
193 | 217 |
|
| 218 | + output.replaceChildren(); |
| 219 | + |
| 220 | + txt = txt||cur.txt; |
| 221 | + if(!txt){ |
| 222 | + return; |
| 223 | + } |
| 224 | + cur.txt = txt; |
| 225 | + |
194 | 226 | var opts = { |
195 | 227 | linkTarget : '_blank', |
196 | 228 | }; |
|
201 | 233 | var md = markdownit(opts); |
202 | 234 | var html = md.render(txt); |
203 | 235 |
|
204 | | - output.innerHTML = html; |
| 236 | + display[cur.mode](html); |
205 | 237 |
|
206 | 238 | }//show |
207 | 239 |
|
208 | 240 |
|
209 | | - obj.horiz = function(){ |
| 241 | + display.md = function(html){ |
| 242 | + debug('display.md'); |
| 243 | + output.innerHTML = html; |
| 244 | + |
| 245 | + output.style.display = ''; |
| 246 | + editor.__host.style.display = 'none'; |
| 247 | + |
| 248 | + }//md |
210 | 249 |
|
| 250 | + |
| 251 | + display.html = function(html){ |
| 252 | + debug('display.html'); |
| 253 | + editor.set(html); |
| 254 | + |
| 255 | + output.style.display = ''; |
| 256 | + editor.__host.style.display = 'none'; |
| 257 | + |
| 258 | + }//html |
| 259 | + |
| 260 | + |
| 261 | + //: |
| 262 | + |
| 263 | + |
| 264 | + obj.horiz = function(){ |
| 265 | + debug('horiz'); |
211 | 266 | host.style.width = '100%'; |
212 | 267 | host.style.height = '50%'; |
213 | 268 |
|
214 | 269 | }//horiz |
215 | 270 |
|
216 | 271 |
|
217 | 272 | obj.vert = function(){ |
218 | | - |
| 273 | + debug('vert'); |
219 | 274 | host.style.width = '50%'; |
220 | 275 | host.style.height = '100%'; |
221 | 276 |
|
222 | 277 | }//vert |
223 | 278 |
|
224 | 279 |
|
| 280 | + |
| 281 | + |
225 | 282 | //: |
226 | 283 |
|
227 | 284 |
|
|
0 commit comments