7
|
1
|
|
2 function ajax(url,postData) {
|
|
3 let request = new XMLHttpRequest();
|
|
4 let method = postData ? 'POST' : 'GET';
|
|
5 request.open( method, url );
|
|
6 if( postData )
|
|
7 request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
|
|
8 request.onload = function() {
|
|
9 if( request.status !== 200 ) {
|
|
10 window.console && console.log( 'ajax failed: ' + request.status );
|
|
11 if( request.responseText )
|
|
12 document.write('<pre>'+request.responseText+'</pre>');
|
|
13 return;
|
|
14 }
|
|
15 eval( request.responseText );
|
|
16 };
|
|
17 request.send(postData);
|
|
18 }
|
|
19
|
|
20 window.onerror = function(msg, url, line, col, error) {
|
|
21 if (!url)
|
|
22 return;
|
|
23 let err = msg;
|
|
24 err += '\nurl = ' + url;
|
|
25 if (url != window.location)
|
|
26 err += '\npage = ' + window.location;
|
|
27 err += '\nline = '+line;
|
|
28 if (col)
|
|
29 err += '\ncolumn = ' + col;
|
|
30 if (error && error.stack)
|
|
31 err += '\nstack = ' + error.stack;
|
|
32 ajax( '/error_log.js', 'err='+encodeURIComponent(err) );
|
|
33 };
|
18
|
34
|
20
|
35 function editorEnter() {
|
|
36 let s = getSelection();
|
|
37 let r = s.getRangeAt(0);
|
|
38 r.deleteContents();
|
|
39 let t = document.createTextNode('\n');
|
|
40 r.insertNode(t);
|
|
41 let isFucked = getSelection().getRangeAt(0).collapsed;
|
|
42 //console.log(isFucked);
|
|
43 r.collapse();
|
|
44 if(isFucked) {
|
|
45 s.removeAllRanges();
|
|
46 s.addRange(r);
|
|
47 }
|
18
|
48 }
|
20
|
49
|
|
50 function editorKey() {
|
|
51 //console.log(event);
|
|
52 if( event.code === 'Enter' ) {
|
|
53 editorEnter();
|
|
54 return false;
|
|
55 }
|
|
56 }
|