Guest User

Untitled

a guest
Nov 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <script src="https://code.jquery.com/jquery-3.2.1.js"></script>
  2. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  3.  
  4.  
  5. <label>
  6. <textarea name="textarea" typing_user="Chuy" class="textarea" cols="45" rows="5"></textarea>
  7. </label>
  8. <div id="typing_on"></div>
  9.  
  10.  
  11.  
  12. <script>
  13.  
  14.  
  15. var user_id = $("textarea[typing_user]:last").attr("typing_user");
  16. var textarea = $('.textarea');
  17. var typingStatus = $('#typing_on');
  18. var lastTypedTime = new Date(0); // it's 01/01/1970
  19. var typingDelayMillis = 2000; // tiempo que dura el div de -> está escribiendo 2 segundos
  20.  
  21. function refreshTypingStatus() {
  22. if (!textarea.is(':focus') || textarea.val() == '' || new Date().getTime() - lastTypedTime.getTime() > typingDelayMillis) {
  23. typingStatus.html('Nadie está escribiendo.');
  24. } else {
  25. typingStatus.html( user_id + ' - está escribiendo...');
  26. }
  27. }
  28. function updateLastTypedTime() {
  29. lastTypedTime = new Date();
  30. }
  31.  
  32.  
  33.  
  34. setInterval(refreshTypingStatus, 100);
  35. textarea.keypress(updateLastTypedTime);
  36. textarea.blur(refreshTypingStatus);
  37.  
  38.  
  39.  
  40.  
  41. </script>
Add Comment
Please, Sign In to add comment