Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Online Users
- function waitForMsg(){
- $.ajax({
- type: "GET",
- url: "ajax/onlineusers.php",
- async: true,
- cache: false,
- success: function(data){
- $('#messages').html(data);
- clearTimeout('waitForMsg()');
- setTimeout('waitForMsg()', 150000);
- },
- error: function(XMLHttpRequest, textStatus, errorThrown){ $('#messages').html("ERROR: " + textStatus);
- clearTimeout('waitForMsg()');
- setTimeout('waitForMsg()', 150000);
- }
- });
- };
- var lastTime = 0;
- function waitForMsg2(){
- $.getJSON("ajax/new_shoutbox.php", {
- time: lastTime
- },
- function(response){
- $.each(response, function(i,item){
- var string = '<div class="post" style="border-bottom: 1px solid #ebeff1; text-align: left; position: relative;" id="list-'+item.id+'">'
- + '<span class="PostTime" style="display: none">'+ item.date +'</span>'
- + '<span style="float: right; font-size: 10px; color: #999999;">'+ item.date_posted +'</span>'
- + '<span style="float: left; padding-right: 2px; font-weight: 600; '+ item.nick_color +'">'+item.nick_name+':</span>'
- + '<div style="clear: both;">'+item.message+'</span>'
- +'</div>';
- if ($('.post').length > 0 && lastTime > 0){
- $('.post:first').before(string);
- } else {
- $('#shoutcontent').append(string);
- }
- $('#list-'+item.id).fadeIn('slow');
- });
- lastTime = $('#shoutcontent .post:first .PostTime').text();
- timeoutID = setTimeout(waitForMsg2, 5000);
- })
- };
- $(document).ready(function(){
- waitForMsg();
- waitForMsg2();
- $('#form textarea').bind('keydown', function(e) {
- if (e.keyCode == 13 && !e.shiftKey) {
- if ($('#form textarea').val().length > 0) {
- $.ajax({
- type: "POST",
- url: "ajax/sendshout.php",
- data: "message=" + $('#message').val(),
- complete: function(data){
- window.clearTimeout(timeoutID);
- delete timeoutID;
- waitForMsg2();
- }
- });
- e.preventDefault();
- $('#form textarea').val('');
- }else {
- alert("Please enter a message!!");
- }
- }
- });
- });
- /*
- $.ajax({
- type: "GET",
- url: "ajax/new_shoutbox.php",
- data: "time=" + lastTime,
- dataType: "json",
- async: true,
- cache: false,
- success: function(response){
- var string = '<div class="post" style="border-bottom: 1px solid #ebeff1; text-align: left; position: relative;" id="list-'+response.id+'">'
- + '<span id="PostTime" style="display: none">'+ response.date +'</span>'
- + '<span style="float: right; font-size: 10px; color: #999999;">'+ response.date_posted +'</span>'
- + '<span style="float: left; padding-right: 2px; font-weight: 600; '+ response.nick_color +'">'+response.nick_name+':</span>'
- + '<div style="clear: both;">'+response.message+'</span>'
- +'</div>';
- lastTime = response.date;
- $('#shoutcontent').append(string);
- $('#list-'+response.id).fadeIn('slow');
- timeoutID = setTimeout(waitForMsg2, 3000);
- }
- });
- */
Add Comment
Please, Sign In to add comment