Guest User

Untitled

a guest
Jun 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. $(function() {
  2.  
  3. // Proof of concept
  4. var handleCurrentInput = function (e) {
  5.  
  6. var $this = $(this),
  7. valStr = $this.val(),
  8. valArr, lastIndexAt, lastItem;
  9.  
  10. if ( e.shiftKey && e.which === 50 ) {
  11.  
  12. lastIndexAt = valStr.lastIndexOf('@');
  13. valArr = valStr.split('@');
  14. lastItem = valArr.pop();
  15.  
  16. // fake logic that pretends to be twitter user autocomplete
  17. valArr.push('@user ')
  18. valArr.push(lastItem);
  19.  
  20. $this.val(valArr.map(function(str) {
  21. return $.trim(str);
  22. }).join(' '));
  23. }
  24.  
  25. };
  26.  
  27.  
  28. $('textarea')
  29. .bind('keyup', handleCurrentInput)
  30. .trigger('focus');
  31.  
  32.  
  33. });
Add Comment
Please, Sign In to add comment