Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="https://code.jquery.com/jquery-3.2.1.js"></script>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
- <label>
- <textarea name="textarea" typing_user="Chuy" class="textarea" cols="45" rows="5"></textarea>
- </label>
- <div id="typing_on"></div>
- <script>
- var user_id = $("textarea[typing_user]:last").attr("typing_user");
- var textarea = $('.textarea');
- var typingStatus = $('#typing_on');
- var lastTypedTime = new Date(0); // it's 01/01/1970
- var typingDelayMillis = 2000; // tiempo que dura el div de -> está escribiendo 2 segundos
- function refreshTypingStatus() {
- if (!textarea.is(':focus') || textarea.val() == '' || new Date().getTime() - lastTypedTime.getTime() > typingDelayMillis) {
- typingStatus.html('Nadie está escribiendo.');
- } else {
- typingStatus.html( user_id + ' - está escribiendo...');
- }
- }
- function updateLastTypedTime() {
- lastTypedTime = new Date();
- }
- setInterval(refreshTypingStatus, 100);
- textarea.keypress(updateLastTypedTime);
- textarea.blur(refreshTypingStatus);
- </script>
Add Comment
Please, Sign In to add comment