Mercurial Hosting > freedit
comparison src/bbcode/test.html @ 51:78b2d6995244
add preview
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 22 Nov 2022 22:57:43 -0700 |
parents | f225e82b2bf8 |
children |
comparison
equal
deleted
inserted
replaced
50:0d99cec5142c | 51:78b2d6995244 |
---|---|
4 <meta name="viewport" content="width=device-width, initial-scale=1"> | 4 <meta name="viewport" content="width=device-width, initial-scale=1"> |
5 <style> | 5 <style> |
6 @import "bbcode.css"; | 6 @import "bbcode.css"; |
7 </style> | 7 </style> |
8 <script src="bbcode.js"></script> | 8 <script src="bbcode.js"></script> |
9 <script> | |
10 // from /site.js | |
11 function ajax(url,postData) { | |
12 let request = new XMLHttpRequest(); | |
13 let method = postData ? 'POST' : 'GET'; | |
14 request.open( method, url ); | |
15 if( postData ) | |
16 request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); | |
17 request.onload = function() { | |
18 if( request.status !== 200 ) { | |
19 window.console && console.log( 'ajax failed: ' + request.status ); | |
20 if( request.responseText ) | |
21 document.write('<pre>'+request.responseText+'</pre>'); | |
22 return; | |
23 } | |
24 eval( request.responseText ); | |
25 }; | |
26 request.send(postData); | |
27 } | |
28 | |
29 function save(event) { | |
30 let text = document.querySelector('textarea').value; | |
31 ajax( 'test.js?text=' + encodeURIComponent(text) ); | |
32 } | |
33 | |
34 function init() { | |
35 bbcodeCreate('p[edit]',{ | |
36 save: save | |
37 }); | |
38 } | |
39 </script> | |
40 </head> | 9 </head> |
41 <body onload='init()'> | 10 <body> |
42 <p>top</p> | 11 <p>top</p> |
43 <p edit></p> | 12 <p edit></p> |
44 <p>result:</p> | |
45 <p result></p> | |
46 <p>bottom</p> | 13 <p>bottom</p> |
47 </body> | 14 </body> |
15 <script> | |
16 bbcodeCreate('p[edit]'); | |
17 </script> | |
48 </html> | 18 </html> |