1 if (rio.EventDelegator) { rio.EventDelegator.disable(); } 2 3 rio.EventDelegator = { 4 observers: [], 5 6 processEvent: function(eventName, e) { 7 var body = Element.body(); 8 var rioComponent; 9 var target = e.target; 10 while (target && target != body) { 11 rioComponent = target.rioComponent; 12 if (rioComponent) { 13 if (Object.isFunction(rioComponent[eventName])) { 14 rioComponent[eventName](Event.extend(e)); 15 } 16 } 17 target = target.parentNode; 18 } 19 }, 20 21 enable: function() { 22 this.observers = [ 23 { 24 eventName: "click", 25 element: Element.body(), 26 observer: this.processEvent.bind(this, "click") 27 }, 28 { 29 eventName: "dblclick", 30 element: Element.body(), 31 observer: this.processEvent.bind(this, "dblClick") 32 }, 33 { 34 eventName: "keyup", 35 element: document, 36 observer: this.processEvent.bind(this, "keyUp") 37 } 38 ]; 39 40 this.observers.each(function(o) { 41 Event.observe(o.element, o.eventName, o.observer); 42 }); 43 }, 44 45 disable: function() { 46 this.observers.each(function(o) { 47 try { 48 Event.stopObserving(o.element, o.eventName, o.observer); 49 } catch(e) { 50 // Don't let one failure ruin the party 51 } 52 }); 53 54 this.observers.clear(); 55 } 56 57 58 }; 59