Event-amd add/remove event library
Event.js is a tiny library to add and remove events in any browser. This library uses amd structure.
Install : npm install elo7-events-amd
Event-amd depends on an amd implementation. We suggest define-async implementation for dependency lookup.
Ex.: document.querySelector('#link')
Event that will be added or removed from the element
Ex.: 'click'
Function that will be called when the event is triggered, only for addEvent
Ex.: function(){ ... }
You can pass a config with the following parameters:
-
named: like eventCategory You can add multiple 'events' of the same type (e.g: click) and use the eventCategory parameter to remove certain events when needed.
Ex.: event.addEvent(element, 'click', callback, { named: 'tracking' });
-
passive: Boolean (optional) If true, indicates that the function specified by listener will never call preventDefault(). Only works on
addEvent
Ex.: event.addEvent(element, 'click', callback, { passive: true });
Ex.: event.addEvent(element, 'click', callback, { named: 'tracking', passive: true });
Or you can use the shorthand and only pass the eventCategory as parameter.
Ex.:
event.addEvent(element, 'click', callback, 'tracking');
event.addEvent(element, 'click', callback, 'action');
event.removeEvent(element, 'click', 'action');
removeEvent
only supports Strings as last parameter
define(['event'], function(event) {
event.addEvent(element, event, callback, eventCategory);
event.removeEvent(element, event, eventCategory);
});
Event-amd is released under the BSD. Have at it.
Copyright ©️ 2019 Elo7# event-amd