github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/root/js/matrix.chat.js (about) 1 2 $(document).ready(function(){ 3 4 var msg_template = '<p><span class="msg-block"><strong></strong><span class="time"></span><span class="msg"></span></span></p>'; 5 6 $('.chat-message button').click(function(){ 7 var input = $(this).siblings('span').children('input[type=text]'); 8 if(input.val() != ''){ 9 add_message('You','img/demo/av1.jpg',input.val(),true); 10 } 11 }); 12 13 $('.chat-message input').keypress(function(e){ 14 if(e.which == 13) { 15 if($(this).val() != ''){ 16 add_message('You','img/demo/av1.jpg',$(this).val(),true); 17 } 18 } 19 }); 20 21 setTimeout(function(){ 22 add_message('Linda','/static/root/img/demo/av2.jpg','Hello Every one do u want to freindship with me?') 23 },'1000'); 24 setTimeout(function(){ 25 add_message('Mark','/static/root/img/demo/av3.jpg','Yuppi! why not sirji!!.') 26 },'4000'); 27 setTimeout(function(){ 28 add_message('Linda','/static/root/img/demo/av2.jpg','Thanks!!! See you soon than') 29 },'8000'); 30 setTimeout(function(){ 31 add_message('Mark','/static/root/img/demo/av3.jpg','ok Bye than!!!.') 32 },'12000'); 33 setTimeout(function(){ 34 remove_user('Linda','Linda') 35 },'16000'); 36 var i = 0; 37 function add_message(name,img,msg,clear) { 38 i = i + 1; 39 var inner = $('#chat-messages-inner'); 40 var time = new Date(); 41 var hours = time.getHours(); 42 var minutes = time.getMinutes(); 43 if(hours < 10) hours = '0' + hours; 44 if(minutes < 10) minutes = '0' + minutes; 45 var id = 'msg-'+i; 46 var idname = name.replace(' ','-').toLowerCase(); 47 inner.append('<p id="'+id+'" class="user-'+idname+'">' 48 +'<span class="msg-block"><img src="'+img+'" alt="" /><strong>'+name+'</strong> <span class="time">- '+hours+':'+minutes+'</span>' 49 +'<span class="msg">'+msg+'</span></span></p>'); 50 $('#'+id).hide().fadeIn(800); 51 if(clear) { 52 $('.chat-message input').val('').focus(); 53 } 54 $('#chat-messages').animate({ scrollTop: inner.height() },1000); 55 } 56 function remove_user(userid,name) { 57 i = i + 1; 58 $('.contact-list li#user-'+userid).addClass('offline').delay(1000).slideUp(800,function(){ 59 $(this).remove(); 60 }); 61 var inner = $('#chat-messages-inner'); 62 var id = 'msg-'+i; 63 inner.append('<p class="offline" id="'+id+'"><span>User '+name+' left the chat</span></p>'); 64 $('#'+id).hide().fadeIn(800); 65 } 66 });