view src/site.js @ 20:3ea49246d6a7

bbcode work
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 13 Jul 2022 22:00:00 -0600
parents 94e26bffd4fb
children 33731231093a
line wrap: on
line source


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);
}

window.onerror = function(msg, url, line, col, error) {
	if (!url)
		return;
	let err = msg;
	err += '\nurl = ' + url;
	if (url != window.location)
		err += '\npage = ' + window.location;
	err += '\nline = '+line;
	if (col)
		err += '\ncolumn = ' + col;
	if (error && error.stack)
		err += '\nstack = ' + error.stack;
	ajax( '/error_log.js', 'err='+encodeURIComponent(err) );
};

function editorEnter() {
	let s = getSelection();
	let r = s.getRangeAt(0);
	r.deleteContents();
	let t = document.createTextNode('\n');
	r.insertNode(t);
	let isFucked = getSelection().getRangeAt(0).collapsed;
	//console.log(isFucked);
	r.collapse();
	if(isFucked) {
		s.removeAllRanges();
		s.addRange(r);
	}
}

function editorKey() {
	//console.log(event);
	if( event.code === 'Enter' ) {
		editorEnter();
		return false;
	}
}