Object for cross-browser working with events using bridge pattern.
This is a simple interface for adding and removing event listeners. Unfortunately, Internet Explorer 9 and older uses non-standard methods to do that.
You should use Event
polyfill if you want the full functionality with native syntax.
// create instance of ClassBridge object
var event_bridge = new EventBridge;
// add event listener
event_bridge.add(element, 'click', function (e) {/*...*/});
// remove event listener
// NOTE: you have to use reference to the same function object that you used
// when you were adding the event listener... so no anonymous functions
function handleEvent(e) {/*...*/}
eventBridge.add(element, 'click', handleEvent); // now the listener is active
eventBridge.remove(element, 'click', handleEvent); // now it is not
// handy methods for cross-browser handling of event objects
event_bridge.add(element, 'click', function (e) {
// get the event target (IE provides event.srcElement instead event.target)
event_bridge.target(e);
// stop the event
event_bridge.stop(e);
});
If you found any bugs, if you have feature requests or any questions, please, either file an issue at GitHub or send me an e-mail at [email protected].
Angle JS is published under the UNLICENSE license. Feel free to use it in any way.