comparison sat_templates/templates/default/static/chat.js @ 164:e9f0a4215e46

multi-sites handling (moved templates to "templates" sub-directory) + noscript styles handling.
author Goffi <goffi@goffi.org>
date Mon, 10 Sep 2018 08:53:33 +0200
parents sat_templates/default/static/chat.js@33c7ce833d3f
children 6a26c8a43d10
comparison
equal deleted inserted replaced
163:33f67228686a 164:e9f0a4215e46
1 /* SàT Template: Chat page handling
2 *
3 * Copyright (C) 2017 Jérôme Poisson (goffi@goffi.org)
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20 var msgInput = document.getElementById('message_input');
21 var messages = document.getElementById('messages');
22 const messagesTransitionOri = messages.style.transition;
23
24 msgInput.addEventListener('keypress', function(event) {
25 if (event.which == 13 && !event.shiftKey) {
26 if (messages.style.height !== '100%') {
27 messages.style.transition = messagesTransitionOri;
28 setTimeout(function() {
29 messages.style.transition = 'initial';
30 messages.scrollTop = messages.scrollHeight;
31 }, 1000);
32 messages.style.height = "100%";
33 }
34 if (!this.value.trim()) {
35 return;
36 }
37 socket.send({'type': 'msg',
38 'body': this.value});
39 this.value = '';
40 event.preventDefault();
41 }}
42 );
43
44 var mutationCb = function(mutationsList) {
45 scrollPos = messages.scrollTop + messages.clientHeight;
46 if (messages.lastChild.offsetTop - scrollPos - 10 <= 0) {
47 // we auto scroll only if we are at the bottom of the page
48 // else the use is probably checking history
49 // Note thas this doesn't take margin into account,
50 // we suppose margin to be 0 for messages children
51 messages.scrollTop = messages.scrollHeight;
52 }
53 };
54
55 var observer = new MutationObserver(mutationCb);
56
57 observer.observe(messages, { childList: true });
58 // we want to start with scrolling at bottom
59 messages.scrollTop = messages.scrollHeight;
60 messages.style.transition = 'initial';