// Custom events to allow multiple things to happen when a date input is changed // It'd be nice to use the standard DOM interfaces to do this, but IE6 doesn't support them. // They could be monkeypatched in if it supported Node.prototype... but it doesn't. // (Adding a behaviour is too cumbersome.) // Modeled after Prototype's Event. var CustomEvent = { observe: function (target, type, listener) { target = $(target); if (!('customEventListeners' in target)) { target.customEventListeners = {}; } // create an array to hold the listeners for an event, if it doesn't already exist if (!(type in target.customEventListeners)) { target.customEventListeners[type] = []; } // add the new listener only if it's not already there if (!(target.customEventListeners[type].include(listener))) { target.customEventListeners[type].push(listener); } }, dispatch: function (target, evt) { target = $(target); // no listeners? do nothing and return if (!('customEventListeners' in target)) return; if (!(evt.type in target.customEventListeners)) return; // call each listener with the event evt.target = target; target.customEventListeners[evt.type].each(function (listener) { listener(evt); }); }, stopObserving: function (target, type, listener) { target = $(target); if (!('customEventListeners' in target)) return; // shorter name var listeners = target.customEventListeners; if (!(type in listeners)) return; listeners[type].each(function (current_listener, i) { if (current_listener == listener) { delete listeners[type][i]; return; } }); } }