44
|
1 <!doctype html>
|
|
2 <html>
|
|
3 <head>
|
|
4 <meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5 <style>
|
|
6 @import "bbcode.css";
|
|
7
|
|
8 [message] {
|
|
9 white-space: pre-wrap;
|
|
10 line-height: 1.4;
|
|
11 }
|
|
12 </style>
|
|
13 <script src="bbcode.js"></script>
|
|
14 <script>
|
|
15 // from /site.js
|
|
16 function ajax(url,postData) {
|
|
17 let request = new XMLHttpRequest();
|
|
18 let method = postData ? 'POST' : 'GET';
|
|
19 request.open( method, url );
|
|
20 if( postData )
|
|
21 request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
|
|
22 request.onload = function() {
|
|
23 if( request.status !== 200 ) {
|
|
24 window.console && console.log( 'ajax failed: ' + request.status );
|
|
25 if( request.responseText )
|
|
26 document.write('<pre>'+request.responseText+'</pre>');
|
|
27 return;
|
|
28 }
|
|
29 eval( request.responseText );
|
|
30 };
|
|
31 request.send(postData);
|
|
32 }
|
|
33
|
|
34 function save(event) {
|
|
35 let div = getBbcodeDiv(event.target);
|
|
36 let text = div.querySelector('textarea').value;
|
|
37 ajax( 'test.js?text=' + encodeURIComponent(text) );
|
|
38 }
|
|
39
|
|
40 function init() {
|
|
41 bbcodeCreate('p[edit]',{
|
|
42 save: save
|
|
43 });
|
|
44 }
|
|
45 </script>
|
|
46 </head>
|
|
47 <body onload='init()'>
|
|
48 <p>top</p>
|
|
49 <p edit></p>
|
|
50 <p>result:</p>
|
|
51 <p result><div message></div></p>
|
|
52 <p>bottom</p>
|
|
53 </body>
|
|
54 </html>
|