elo7-events-amd
v1.2.1
Published
A small lib to add and remove events
Downloads
1,333
Maintainers
Readme
Event-amd
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
Install : npm install elo7-events-amd
Dependency
Event-amd depends on an amd implementation. We suggest define-async implementation for dependency lookup.
Parameters
element: DocumentElement
Ex.: document.querySelector('#link')
event: String
Event that will be added or removed from the element
Ex.: 'click'
callback: Function
Function that will be called when the event is triggered, only for addEvent
Ex.: function(){ ... }
configs: Object (optional) or String (optional)
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
Example
define(['event'], function(event) {
event.addEvent(element, event, callback, eventCategory);
event.removeEvent(element, event, eventCategory);
});
License
Event-amd is released under the BSD. Have at it.
Copyright :copyright: 2019 Elo7# event-amd