4
|
1 'use strict';
|
|
2
|
|
3 function ajax(url,postData,context) {
|
|
4 let request = new XMLHttpRequest();
|
|
5 let method = postData ? 'POST' : 'GET';
|
|
6 request.open( method, url );
|
|
7 if( postData )
|
|
8 request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
|
|
9 request.onload = function() {
|
|
10 if( request.status !== 200 ) {
|
|
11 console.log( 'ajax failed: ' + request.status );
|
|
12 if( request.responseText )
|
|
13 document.write('<pre>'+request.responseText+'</pre>');
|
|
14 return;
|
|
15 }
|
|
16 try {
|
|
17 eval( request.responseText );
|
|
18 } catch(e) {
|
|
19 console.log( request.responseText );
|
|
20 window.err = '\najax-url = ' + url;
|
|
21 throw e;
|
|
22 }
|
|
23 };
|
|
24 request.send(postData);
|
|
25 }
|
|
26
|
|
27 window.onerror = function(msg, url, line, col, error) {
|
|
28 if (!url)
|
|
29 return;
|
|
30 let err = msg;
|
|
31 err += '\nurl = ' + url;
|
|
32 if (url != window.location)
|
|
33 err += '\npage = ' + window.location;
|
|
34 err += '\nline = '+line;
|
|
35 if (col)
|
|
36 err += '\ncolumn = ' + col;
|
|
37 if (error && error.stack)
|
|
38 err += '\nstack = ' + error.stack;
|
|
39 if( window.err ) {
|
|
40 err += window.err;
|
|
41 window.err = null;
|
|
42 }
|
|
43 ajax( '/error_log.js', 'err='+encodeURIComponent(err) );
|
|
44 };
|
|
45
|
9
|
46 let currentPulldown = null;
|
|
47 let newPulldown = null;
|
|
48
|
|
49 function clickMenu(clicked,display) {
|
|
50 //console.log("clickMenu");
|
|
51 let pulldown = clicked.parentNode.querySelector('[pulldown_menu]');
|
|
52 if( pulldown !== currentPulldown ) {
|
11
|
53 pulldown.style.display = display || "flex";
|
9
|
54 newPulldown = pulldown;
|
|
55 window.onclick = function() {
|
|
56 if( currentPulldown ) {
|
|
57 currentPulldown.style.display = "none";
|
|
58 if( !newPulldown )
|
|
59 window.onclick = null;
|
|
60 }
|
|
61 currentPulldown = newPulldown;
|
|
62 newPulldown = null;
|
|
63 };
|
|
64 pulldown.scrollIntoViewIfNeeded(false);
|
|
65 }
|
|
66 }
|
|
67
|
4
|
68 function logout() {
|
|
69 document.cookie = 'user=; Max-Age=0; path=/;';
|
|
70 location = '/';
|
|
71 }
|