Guest User

Untitled

a guest
Apr 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. (function(){
  2. var CODE_FOR_KEYS = {
  3. 8: 'backspace',
  4. 9: 'tab',
  5. 13: 'return',
  6. 27: 'esc',
  7. 37: 'left',
  8. 38: 'up',
  9. 39: 'right',
  10. 40: 'down',
  11. 46: 'delete',
  12. 36: 'home',
  13. 35: 'end',
  14. 33: 'pageup',
  15. 34: 'pagedown',
  16. 45: 'insert'
  17. };
  18.  
  19. function checkForKey(event){
  20. var keyCode = event.keyCode || event.charCode;
  21. if (CODE_FOR_KEYS[keyCode]){
  22. var customEvent = Element.fire(Event.findElement(event) || document, event.type + ':' + CODE_FOR_KEYS[keyCode], {originalEvent: event});
  23. if (customEvent.stopped){
  24. event.stop();
  25. }
  26. }
  27. }
  28.  
  29. document.observe('keyup', checkForKey);
  30. document.observe('keypress', checkForKey);
  31. document.observe('keydown', checkForKey);
  32. })();
Add Comment
Please, Sign In to add comment