comparison src/test/editor.html @ 20:3ea49246d6a7

bbcode work
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 13 Jul 2022 22:00:00 -0600
parents da006d1c1eba
children
comparison
equal deleted inserted replaced
19:da006d1c1eba 20:3ea49246d6a7
7 padding: 7px; 7 padding: 7px;
8 border: 1px solid #777; 8 border: 1px solid #777;
9 white-space: pre-wrap; 9 white-space: pre-wrap;
10 } 10 }
11 </style> 11 </style>
12 <script src="/site.js"></script>
12 <script> 13 <script>
14 function getBrowser() {
15 let userAgent = navigator.userAgent;
16 if( userAgent.match(/chrome|chromium|crios/i) )
17 return 'chrome';
18 if( userAgent.match(/firefox|fxios/i) )
19 return 'firefox';
20 if( userAgent.match(/safari/i) )
21 return 'safari';
22 if( userAgent.match(/opr\//i) )
23 return 'opera';
24 if( userAgent.match(/edg/i) )
25 return 'edge';
26 return "unknown";
27 }
28
13 function log() { 29 function log() {
14 let edit = document.querySelector('[contentEditable]'); 30 let edit = document.querySelector('[contentEditable]');
15 console.log(edit.innerHTML); 31 console.log(edit.innerHTML);
16 //console.log(edit.textContent); 32 //console.log(edit.textContent);
17 } 33 }
18 function test() { 34 function test() {
19 let edit = document.querySelector('[contentEditable]'); 35 let edit = document.querySelector('[contentEditable]');
20 edit.focus(); 36 edit.focus();
21 let s = getSelection(); 37 editorEnter();
22 let r = s.getRangeAt(0);
23 //console.log(s);
24 r.deleteContents();
25 let t = document.createTextNode('\n');
26 r.insertNode(t);
27 r.collapse();
28 } 38 }
29 </script> 39 </script>
30 </head> 40 </head>
31 <body> 41 <body>
32 <p>top</p> 42 <p>top</p>
33 <div contentEditable> 43 <div contentEditable onkeypress="return editorKey()">
34 aaa <b>bbb</b> <i>iii</i> 44 aaa <b>bbb</b> <i>iii</i>
35 1 45 1
36 2 46 2
37 3 47 3
38 zzz 48 zzz
39 </div> 49 </div>
40 <p> 50 <p>
41 <button onclick="log()">log</button> 51 <button onclick="log()">log</button>
42 <button onclick="test()">test</button> 52 <button onclick="test()">test</button>
43 </p> 53 </p>
44 <p>bottom</p> 54 <p>bottom</p>