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) {
|
46
|
35 let text = document.querySelector('textarea').value;
|
44
|
36 ajax( 'test.js?text=' + encodeURIComponent(text) );
|
|
37 }
|
|
38
|
|
39 function init() {
|
|
40 bbcodeCreate('p[edit]',{
|
|
41 save: save
|
|
42 });
|
|
43 }
|
|
44 </script>
|
|
45 </head>
|
|
46 <body onload='init()'>
|
|
47 <p>top</p>
|
|
48 <p edit></p>
|
|
49 <p>result:</p>
|
|
50 <p result><div message></div></p>
|
|
51 <p>bottom</p>
|
|
52 </body>
|
|
53 </html>
|