1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/minchat_ynh.git synced 2024-09-03 19:36:29 +02:00

Grows from bottom and greeting msg

This commit is contained in:
Chtixof 2015-04-17 09:09:51 +02:00
parent 9b2e332ce4
commit 69123fc39a
3 changed files with 49 additions and 28 deletions

View file

@ -79,7 +79,9 @@ if ($name.$room=="") {
<p class="welcome">Welcome to the <b><?php echo $room; ?></b> room, <b><?php echo $name; ?></b></p> <p class="welcome">Welcome to the <b><?php echo $room; ?></b> room, <b><?php echo $name; ?></b></p>
<div style="clear:both"></div> <div style="clear:both"></div>
</div> </div>
<div id="content">
<div id="chatbox"></div> <div id="chatbox"></div>
</div>
<form name="message" action=""> <form name="message" action="">
<input name="usermsg" type="text" id="usermsg" size="63" autocomplete="off" autofocus/> <input name="usermsg" type="text" id="usermsg" size="63" autocomplete="off" autofocus/>
<input name="submitmsg" type="submit" id="submitmsg" value="Send" /> <input name="submitmsg" type="submit" id="submitmsg" value="Send" />
@ -101,9 +103,9 @@ function lienurl(s){
} }
$(document).ready(function() { $(document).ready(function() {
var id = 'undefined';
var pos = 0; var pos = 0;
var lastdate = 0; var lastdate = 0;
var lastday='';
var oldscrollHeight = $("#chatbox")[0].scrollHeight; var oldscrollHeight = $("#chatbox")[0].scrollHeight;
$("#submitmsg").click(function() { $("#submitmsg").click(function() {
@ -136,6 +138,7 @@ function lienurl(s){
var html=''; var html='';
var date; var date;
var heure=''; var heure='';
var day='';
for (var k in data.data) { for (var k in data.data) {
lastdate = data.data[k][0]; lastdate = data.data[k][0];
date = new Date(parseInt(lastdate)*1000); date = new Date(parseInt(lastdate)*1000);
@ -147,16 +150,29 @@ function lienurl(s){
html=lienurl(html); html=lienurl(html);
if (pos==0 && heure!=''){ if (html!=""){
html='<b>----- '+date.toLocaleDateString()+' -----</b><br>'+html; if (pos==0){
day = date.toLocaleDateString();
if (day!=lastday){
$("#chatbox").append('<b>----- '+day+' -----</b><br>');
if (data.pos==0) {
$("#chatbox").append('<span id="nomsg">No message yet. Enter yours!<br></span>');
}
lastday=day;
}
if (data.pos>0) {
$("#nomsg").remove();
} else {
html="";
}
} }
pos = data.pos;
$("#chatbox").append(html); $("#chatbox").append(html);
}
var newscrollHeight = $("#chatbox")[0].scrollHeight; var newscrollHeight = $("#chatbox")[0].scrollHeight;
if (newscrollHeight > oldscrollHeight) { if (newscrollHeight > oldscrollHeight) {
$("#chatbox").scrollTop($("#chatbox")[0].scrollHeight); $("#chatbox").scrollTop(newscrollHeight);
} }
pos = data.pos;
}, },
}); });
} }

View file

@ -3,16 +3,17 @@
$pos = isset($_REQUEST['pos']) ? $_REQUEST['pos'] : ''; $pos = isset($_REQUEST['pos']) ? $_REQUEST['pos'] : '';
$lastdate = isset($_REQUEST['lastdate']) ? $_REQUEST['lastdate'] : ''; $lastdate = isset($_REQUEST['lastdate']) ? $_REQUEST['lastdate'] : '';
$room = isset($_REQUEST['room']) ? $_REQUEST['room'] : ''; $room = isset($_REQUEST['room']) ? $_REQUEST['room'] : '';
$date = date('Y-m-d'); $time = time();
$date = date('Y-m-d', $time);
$file = './history/'.$room.$date; $file = './history/'.$room.$date;
if (!ctype_digit($pos) || !file_exists($file)) return; if (!ctype_digit($pos)) return;
settype($pos, "integer"); settype($pos, "integer");
settype($lastdate, "integer"); settype($lastdate, "integer");
$data = array(); $data = array();
if (file_exists($file)) {
if ($pos!=0 && $date!=date('Y-m-d',$lastdate)) { if ($pos!=0 && $date!=date('Y-m-d',$lastdate)) {
$pos=0; $pos=0;
} else { } else {
@ -24,6 +25,9 @@ if ($pos!=0 && $date!=date('Y-m-d',$lastdate)) {
$pos =ftell($fh); $pos =ftell($fh);
} }
} }
} else if ($date!=date('Y-m-d',$lastdate)) {
$data[0]=array($time,"","");
}
echo json_encode(array('pos' => $pos, 'data' => $data)); echo json_encode(array('pos' => $pos, 'data' => $data));
?> ?>

View file

@ -46,13 +46,13 @@ a:hover { text-decoration: underline; }
#loginform p { margin: 5px; } #loginform p { margin: 5px; }
#chatbox { #chatbox {
text-align: left;
margin: 0 50px;
padding: 0.5em 1ex 0.1em;
background: #FEFFF4; background: #FEFFF4;
height: calc(100% - 120px); position: absolute;
border: 1px solid #C7C7C7; bottom: 80px;
overflow: auto; } right: 50px;
left: 50px; overflow-y: scroll;
max-height: calc(100% - 140px);
padding: .5em; }
#usermsg { #usermsg {
width: calc(100% - 100px); width: calc(100% - 100px);
@ -74,3 +74,4 @@ a:hover { text-decoration: underline; }
.tform label { display: table-cell; } .tform label { display: table-cell; }
.tform input { display: table-cell; } .tform input { display: table-cell; }
em {color:red;} em {color:red;}
#content{height: calc(100% - 120px); }