diff src/bbcode/test.html @ 44:96f0c3d65698

add /bbcode
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 10 Nov 2022 23:18:58 -0700
parents
children 289718f121e4
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/bbcode/test.html	Thu Nov 10 23:18:58 2022 -0700
@@ -0,0 +1,54 @@
+<!doctype html>
+<html>
+	<head>
+		<meta name="viewport" content="width=device-width, initial-scale=1">
+		<style>
+			@import "bbcode.css";
+
+			[message] {
+				white-space: pre-wrap;
+				line-height: 1.4;
+			}
+		</style>
+		<script src="bbcode.js"></script>
+		<script>
+			// from /site.js
+			function ajax(url,postData) {
+				let request = new XMLHttpRequest();
+				let method = postData ? 'POST' : 'GET';
+				request.open( method, url );
+				if( postData )
+					request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
+				request.onload = function() {
+					if( request.status !== 200 ) {
+						window.console && console.log( 'ajax failed: ' + request.status );
+						if( request.responseText )
+							document.write('<pre>'+request.responseText+'</pre>');
+						return;
+					}
+					eval( request.responseText );
+				};
+				request.send(postData);
+			}
+
+			function save(event) {
+				let div = getBbcodeDiv(event.target);
+				let text = div.querySelector('textarea').value;
+				ajax( 'test.js?text=' + encodeURIComponent(text) );
+			}
+
+			function init() {
+				bbcodeCreate('p[edit]',{
+					save: save
+				});
+			}
+		</script>
+	</head>
+	<body onload='init()'>
+		<p>top</p>
+		<p edit></p>
+		<p>result:</p>
+		<p result><div message></div></p>
+		<p>bottom</p>
+	</body>
+</html>