annotate src/chat.js @ 27:809193524522

responsive
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 06 Nov 2024 16:01:42 -0700
parents af41be2dcdec
children f4708943f29e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 'use strict';
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
18
0721dcf222e1 * alert
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
3 let title = document.title;
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 let currentChatId = null;
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
5 let eventSource;
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
16
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
7 function evalEvent(event) {
17
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
8 // console.log(event);
16
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
9 eval(event.data);
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
10 }
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
11
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
12 function setUserEventSource(userId) {
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
13 let userEventSource = new EventSource(`${location.origin}/user/${userId}`);
16
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
14 userEventSource.onmessage = evalEvent;
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
15 }
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
16
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 function selectChat(div) {
27
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 24
diff changeset
18 document.querySelector('div[content]').setAttribute('show','posts');
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 let chatId = div.getAttribute('chat');
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 if( chatId === currentChatId )
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 return;
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 let selected = div.parentNode.querySelector('[selected]');
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 if( selected ) selected.removeAttribute('selected');
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 div.setAttribute('selected','');
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 ajax(`get_chat.js?chat=${chatId}`);
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 currentChatId = chatId;
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
27
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
28 if(eventSource) eventSource.close();
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
29 eventSource = new EventSource(`${location.origin}/chat/${chatId}`);
16
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
30 eventSource.onmessage = evalEvent;
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
31 }
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
32
27
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 24
diff changeset
33 function back() {
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 24
diff changeset
34 document.querySelector('div[content]').setAttribute('show','chats');
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 24
diff changeset
35 }
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 24
diff changeset
36
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
37 function gotChat(html) {
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
38 document.querySelector('div[posts]').innerHTML = html;
19
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
39 fixPosts();
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
40 document.querySelector('div[input] textarea').focus();
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
41 document.querySelector('div[input]').scrollIntoView({block: 'end'});
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 }
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 function fixTextarea(event) {
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 let textarea = event.target;
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 textarea.style.height = 'initial';
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 textarea.style.height = (textarea.scrollHeight+2) + 'px';
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 textarea.scrollIntoViewIfNeeded(false);
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 }
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 function addPost() {
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 let textarea = document.querySelector('div[input] textarea');
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 let text = textarea.value;
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 if( text.trim() === '' )
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 return;
24
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
58 ajax(`add_post.js?chat=${currentChatId}`,`content=${encodeURIComponent(text)}`);
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 textarea.value = '';
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 }
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 function textareaKey(event) {
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) {
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 event.preventDefault();
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 addPost();
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 }
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 }
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68
19
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
69 function fixPosts() {
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 let spans = document.querySelectorAll('span[when][fix]');
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 for( let span of spans ) {
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 span.textContent = new Date(Number(span.textContent)).toLocaleString();
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 span.removeAttribute('fix');
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 }
19
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
75 let divs = document.querySelectorAll('div[text][fix]');
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
76 for( let div of divs ) {
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
77 div.innerHTML = urlsToLinks(div.innerHTML);
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
78 div.removeAttribute('fix');
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
79 }
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80 }
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
81
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
82 function deleteChat() {
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 19
diff changeset
83 let dialog = document.querySelector('dialog[delete_chat]');
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 19
diff changeset
84 openModal(dialog);
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 19
diff changeset
85 }
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 19
diff changeset
86
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 19
diff changeset
87 function doDeleteChat(el) {
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 19
diff changeset
88 closeModal(el);
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
89 ajax(`delete_chat.js?chat=${currentChatId}`);
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
90 }
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
91
23
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
92 let currentPostId;
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
93
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
94 function deletePost(postId) {
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
95 currentPostId = postId;
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
96 let dialog = document.querySelector('dialog[delete_post]');
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
97 openModal(dialog);
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
98 }
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
99
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
100 function doDeletePost(el) {
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
101 closeModal(el);
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
102 ajax(`delete_post.js?post=${currentPostId}`);
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
103 }
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
104
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
105 function deleted(postId) {
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
106 let div = document.querySelector(`div[post="${postId}"]`);
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
107 if( div )
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
108 div.outerHTML = '';
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
109 }
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 22
diff changeset
110
24
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
111 function editPost(postId) {
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
112 ajax(`edit_post.js?post=${postId}`);
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
113 }
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
114
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
115 function openEditPost(postId,text) {
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
116 currentPostId = postId;
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
117 let dialog = document.querySelector('dialog[edit_post]');
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
118 let textarea = dialog.querySelector('textarea');
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
119 textarea.value = text;
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
120 openModal(dialog);
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
121 }
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
122
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
123 function savePost(el) {
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
124 let text = document.querySelector('dialog[edit_post] textarea').value;
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
125 closeModal(el);
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
126 ajax(`save_post.js?post=${currentPostId}`,`content=${encodeURIComponent(text)}`);
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
127 }
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
128
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
129 function edited(postId,html) {
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
130 let div = document.querySelector(`div[post="${postId}"]`);
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
131 if( div ) {
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
132 div.outerHTML = html;
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
133 fixPosts();
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
134 }
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
135 }
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
136
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
137 function added(html) {
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
138 let input = document.querySelector('div[input]');
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
139 input.insertAdjacentHTML('beforebegin',html);
19
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
140 fixPosts();
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
141 input.scrollIntoView({block: 'end'});
18
0721dcf222e1 * alert
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
142 if( !document.hasFocus() )
0721dcf222e1 * alert
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
143 document.title = title + ' *';
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
144 }
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
145
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
146 function getChats(chatId) {
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
147 let first = document.querySelector('div[chat]');
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
148 if( !first || first.getAttribute('chat') != chatId ) {
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
149 // console.log('getChats');
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
150 ajax('get_chats.js');
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
151 }
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
152 }
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
153
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
154 function gotChats(html) {
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
155 document.querySelector('div[chats]').innerHTML = html;
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
156 if( currentChatId ) {
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
157 let current = document.querySelector(`div[chat="${currentChatId}"]`);
16
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
158 if( current ) {
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
159 current.setAttribute('selected','');
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
160 current.scrollIntoViewIfNeeded(false);
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
161 } else {
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
162 currentChatId = null;
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
163 document.querySelector('div[posts]').innerHTML = '';
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
164 }
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
165 }
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 14
diff changeset
166 }
18
0721dcf222e1 * alert
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
167
0721dcf222e1 * alert
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
168 window.onfocus = function() {
0721dcf222e1 * alert
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
169 document.title = title;
0721dcf222e1 * alert
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
170 };
19
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
171
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
172 let urlRegex = /(^|\s)(https?:\/\/\S+)/g;
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
173
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
174 function urlsToLinks(text) {
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
175 return text.replace( urlRegex, '$1<a href="$2">$2</a>' );
Franklin Schmidt <fschmidt@gmail.com>
parents: 18
diff changeset
176 }
22
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
177
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
178 let currentPulldown = null;
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
179 let newPulldown = null;
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
180
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
181 function clickMenu(clicked,display) {
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
182 //console.log("clickMenu");
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
183 let pulldown = clicked.parentNode.querySelector('div');
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
184 if( pulldown !== currentPulldown ) {
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
185 pulldown.style.display = display || "block";
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
186 newPulldown = pulldown;
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
187 window.onclick = function() {
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
188 //console.log("window.onclick");
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
189 if( currentPulldown ) {
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
190 currentPulldown.style.display = "none";
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
191 if( !newPulldown )
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
192 window.onclick = null;
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
193 }
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
194 currentPulldown = newPulldown;
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
195 newPulldown = null;
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
196 };
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
197 pulldown.scrollIntoViewIfNeeded(false);
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
198 }
949914955bfe add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
199 }