Requires

Provides

Adds the functionallity to add pseudo events for Elements

License:
MIT-style license
Authors:
Arian Stolwijk
  1. 20
  2. 21
  3. 22
  4. 23
  5. 24
  6. 25
  7. 26
  8. 27
  9. 28
  10. 29
  11. 30
  12. 31
  13. 32
  14. 33
  15. 34
  16. 35
  17. 36
  18. 37
  19. 38
  20. 39
  21. 40
  22. 41
  23. 42
  24. 43
  25. 44
  26. 45
  27. 46
  28. 47
  29. 48
  30. 49
  31. 50
  32. 51
  33. 52
  34. 53
  35. 54
  36. 55
  37. 56
  38. 57
  39. 58
  40. 59
  41. 60
  42. 61
  43. 62
  44. 63
  45. 64
  46. 65
  47. 66
(function(){ var keysStoreKey = '$moo:keys-pressed', keysKeyupStoreKey = '$moo:keys-keyup'; var pseudos = { once: function(split, fn, args){ fn.apply(this, args); this.removeEvent(split.original, fn); }, keys: function(split, fn, args){ if (split.event != 'keydown') return; var event = args[0], keys = split.value.split('+'), pressed = this.retrieve(keysStoreKey, []); pressed.include(event.key); if (keys.every(function(key){ return pressed.contains(key); })) fn.apply(this, args); this.store(keysStoreKey, pressed); if (!this.retrieve(keysKeyupStoreKey)){ var keyup = function(){ this.store(keysStoreKey, []); }; this.store(keysKeyupStoreKey, keyup).addEvent('keyup', keyup); } } }; Event.definePseudo = function(key, fn){ pseudos[key] = fn; }; Element.implement(Events.Pseudos(pseudos, Element.prototype.addEvent, Element.prototype.removeEvent)); })();