comparison sat_templates/default/static/chat.js @ 147:33c7ce833d3f

install: setup.py fix + moved "default" dir in a "sat_templates" dir: the merge request at https://bugs.goffi.org/mr/view/3 was a good basis, but not fully working ("default" dir was removed), this patch fixes it, and do some improvments: - moved "default" in "sat_templates" dir, which correspond to the python module, so it can be found easily from python - added VERSION, and mercurial hash detection, in the same way as for Cagou and backend - slight modification of classifiers - replaces tabs coming from MR by spaces
author Goffi <goffi@goffi.org>
date Sat, 02 Jun 2018 17:25:43 +0200
parents default/static/chat.js@05b500bd6235
children
comparison
equal deleted inserted replaced
146:7dc00829c32f 147:33c7ce833d3f
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';