Guest User

Untitled

a guest
Jul 17th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. /// Online Users
  2. function waitForMsg(){
  3. $.ajax({
  4. type: "GET",
  5. url: "ajax/onlineusers.php",
  6. async: true,
  7. cache: false,
  8.  
  9. success: function(data){
  10. $('#messages').html(data);
  11. clearTimeout('waitForMsg()');
  12. setTimeout('waitForMsg()', 150000);
  13. },
  14.  
  15. error: function(XMLHttpRequest, textStatus, errorThrown){ $('#messages').html("ERROR: " + textStatus);
  16. clearTimeout('waitForMsg()');
  17. setTimeout('waitForMsg()', 150000);
  18. }
  19.  
  20. });
  21. };
  22.  
  23. var lastTime = 0;
  24.  
  25. function waitForMsg2(){
  26. $.getJSON("ajax/new_shoutbox.php", {
  27. time: lastTime
  28. },
  29.  
  30. function(response){
  31.  
  32. $.each(response, function(i,item){
  33.  
  34. var string = '<div class="post" style="border-bottom: 1px solid #ebeff1; text-align: left; position: relative;" id="list-'+item.id+'">'
  35. + '<span class="PostTime" style="display: none">'+ item.date +'</span>'
  36. + '<span style="float: right; font-size: 10px; color: #999999;">'+ item.date_posted +'</span>'
  37. + '<span style="float: left; padding-right: 2px; font-weight: 600; '+ item.nick_color +'">'+item.nick_name+':</span>'
  38. + '<div style="clear: both;">'+item.message+'</span>'
  39. +'</div>';
  40.  
  41.  
  42. if ($('.post').length > 0 && lastTime > 0){
  43. $('.post:first').before(string);
  44. } else {
  45. $('#shoutcontent').append(string);
  46. }
  47.  
  48. $('#list-'+item.id).fadeIn('slow');
  49.  
  50. });
  51.  
  52. lastTime = $('#shoutcontent .post:first .PostTime').text();
  53. timeoutID = setTimeout(waitForMsg2, 5000);
  54. })
  55.  
  56.  
  57. };
  58.  
  59. $(document).ready(function(){
  60. waitForMsg();
  61. waitForMsg2();
  62.  
  63. $('#form textarea').bind('keydown', function(e) {
  64. if (e.keyCode == 13 && !e.shiftKey) {
  65.  
  66. if ($('#form textarea').val().length > 0) {
  67.  
  68. $.ajax({
  69. type: "POST",
  70. url: "ajax/sendshout.php",
  71. data: "message=" + $('#message').val(),
  72.  
  73. complete: function(data){
  74. window.clearTimeout(timeoutID);
  75. delete timeoutID;
  76. waitForMsg2();
  77. }
  78.  
  79. });
  80.  
  81. e.preventDefault();
  82. $('#form textarea').val('');
  83.  
  84. }else {
  85. alert("Please enter a message!!");
  86. }
  87.  
  88. }
  89.  
  90. });
  91.  
  92. });
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. /*
  105. $.ajax({
  106. type: "GET",
  107. url: "ajax/new_shoutbox.php",
  108. data: "time=" + lastTime,
  109. dataType: "json",
  110. async: true,
  111. cache: false,
  112.  
  113. success: function(response){
  114.  
  115. var string = '<div class="post" style="border-bottom: 1px solid #ebeff1; text-align: left; position: relative;" id="list-'+response.id+'">'
  116. + '<span id="PostTime" style="display: none">'+ response.date +'</span>'
  117. + '<span style="float: right; font-size: 10px; color: #999999;">'+ response.date_posted +'</span>'
  118. + '<span style="float: left; padding-right: 2px; font-weight: 600; '+ response.nick_color +'">'+response.nick_name+':</span>'
  119. + '<div style="clear: both;">'+response.message+'</span>'
  120. +'</div>';
  121.  
  122. lastTime = response.date;
  123. $('#shoutcontent').append(string);
  124.  
  125. $('#list-'+response.id).fadeIn('slow');
  126. timeoutID = setTimeout(waitForMsg2, 3000);
  127. }
  128.  
  129. });
  130.  
  131. */
Add Comment
Please, Sign In to add comment