annotate src/site.js @ 10:ae9ebeb1c246

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