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 </style>
|
|
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) {
|
46
|
30 let text = document.querySelector('textarea').value;
|
44
|
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>
|
|
41 <body onload='init()'>
|
|
42 <p>top</p>
|
|
43 <p edit></p>
|
|
44 <p>result:</p>
|
49
|
45 <p result></p>
|
44
|
46 <p>bottom</p>
|
|
47 </body>
|
|
48 </html>
|