Requires

Provides

Allows to create custom events based on other custom events.

License:
MIT-style license.
Authors:
Christoph Pojer (@cpojer)
  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
  48. 67
  49. 68
  50. 69
  51. 70
  52. 71
  53. 72
  54. 73
  55. 74
  56. 75
  57. 76
  58. 77
  59. 78
  60. 79
  61. 80
  62. 81
  63. 82
  64. 83
  65. 84
  66. 85
  67. 86
  68. 87
  69. 88
  70. 89
  71. 90
  72. 91
(function(){ [Element, Window, Document].invoke('implement', {hasEvent: function(event){ var events = this.retrieve('events'), list = (events && events[event]) ? events[event].values : null; if (list){ for (var i = list.length; i--;) if (i in list){ return true; } } return false; }}); var wrap = function(custom, method, extended, name){ method = custom[method]; extended = custom[extended]; return function(fn, customName){ if (!customName) customName = name; if (extended && !this.hasEvent(customName)) extended.call(this, fn, customName); if (method) method.call(this, fn, customName); }; }; var inherit = function(custom, base, method, name){ return function(fn, customName){ base[method].call(this, fn, customName || name); custom[method].call(this, fn, customName || name); }; }; var events = Element.Events; Element.defineCustomEvent = function(name, custom){ var base = events[custom.base]; custom.onAdd = wrap(custom, 'onAdd', 'onSetup', name); custom.onRemove = wrap(custom, 'onRemove', 'onTeardown', name); events[name] = base ? Object.append({}, custom, { base: base.base, condition: function(event){ return (!base.condition || base.condition.call(this, event)) && (!custom.condition || custom.condition.call(this, event)); }, onAdd: inherit(custom, base, 'onAdd', name), onRemove: inherit(custom, base, 'onRemove', name) }) : custom; return this; }; var loop = function(name){ var method = 'on' + name.capitalize(); Element[name + 'CustomEvents'] = function(){ Object.each(events, function(event, name){ if (event[method]) event[method].call(event, name); }); }; return loop; }; loop('enable')('disable'); })();