EventListenerHelper

EventListenerHelper

new EventListenerHelper()

This library allows you to: get a list of event listeners attached to the target node, confirms the existence of event listener registered on the target node, deletes all event listeners registered on the target node, registers event listeners with name (rather than a reference). These benefits can be received by calling addEventListener and removeEventListener through this library. MIT License
Author:
  • Tom Misawa (riversun.org@gmail.com,https://github.com/riversun)
Source:

Methods

addEventListener(eventTarget, eventType, listener, optionsopt)

Source:
Parameters:
Name Type Attributes Description
eventTarget EventTarget EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.

EventTarget by Mozilla Contributors is licensed under CC-BY-SA 2.5.

eventType String A case-sensitive string representing the event type to listen for.
listener function The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs. This must be an object implementing the EventListener interface, or a JavaScript function. See The event listener callback for details on the callback itself.
options Object <optional>
An options object specifies characteristics about the event listener. The available options are:
listenerName
A StringBy assigning listenerName, the specified listener function (callback function) can be specified.In other words, it is possible to retrieve the listener function later using this listenerName as a key.listenerName must be unique.
capture
A Boolean indicating that events of this type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.
once
A Boolean indicating that the listener should be invoked at most once after being added. If true, the listener would be automatically removed when invoked.

addEventListener by Mozilla Contributors is licensed under CC-BY-SA 2.5.

Returns:

clearAllEventListeners()

Removes all registered events through the addEventListener method.
Source:

clearEventListener(eventTarget, eventTypeopt, listenerName)

Removes the eventListener with eventTarget, eventType, and listenerName as arguments. The functions are the same as those of removeEventListener, except for the way to give arguments.
Source:
Parameters:
Name Type Attributes Description
eventTarget EventTarget EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.

EventTarget by Mozilla Contributors is licensed under CC-BY-SA 2.5.

eventType String <optional>
A case-sensitive string representing the event type to listen for.
listenerName String The listener name of the listener you want to find

clearEventListeners(eventTarget, eventTypeopt)

Remove all listeners matching the specified eventTarget and eventType (optional).
Source:
Parameters:
Name Type Attributes Description
eventTarget EventTarget EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.

EventTarget by Mozilla Contributors is licensed under CC-BY-SA 2.5.

eventType String <optional>
A case-sensitive string representing the event type to listen for.

getAllEventTargets()

Get all registered eventTargets through the #addEventListener method.
Source:
Returns:

getEventListener(eventTarget, eventType, listenerName) → {function}

Get a listener with the specified eventTarget, eventType and listenerName. The listenerName must be unique for one eventTarget and eventType combination, but it does not have to be unique for different eventTargets or different eventTypes.
Source:
Parameters:
Name Type Description
eventTarget EventTarget EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.

EventTarget by Mozilla Contributors is licensed under CC-BY-SA 2.5.

eventType String A case-sensitive string representing the event type to listen for.
listenerName String The listener name of the listener you want to find
Returns:
Type:
function
Returns null if no listener function is found

getEventListeners(eventTarget, eventTypeopt)

Get a listener definition matching the specified eventTarget and eventType (optional). Please note that the return value is immutable.
Source:
Parameters:
Name Type Attributes Description
eventTarget EventTarget EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.

EventTarget by Mozilla Contributors is licensed under CC-BY-SA 2.5.

eventType String <optional>
A case-sensitive string representing the event type to listen for.
Returns:
Example of the returned value when only eventTarget is specified:
   [
   {
      eventType:click,
      listener:[
         {
            listener:func,
            options:{
               listenerName:my-test-listener-1
            }
         },
         {
            listener:func,
            options:{
               capture:true,
               listenerName:my-test-listener-2
            }
         }
      ]
   },
   {
      eventType:mousemove,
      listener:[
         {
            listener:func,
            options:{
               once:true,
               listenerName:my-test-listener-3
            }
         }
      ]
   }
   ]
   

Example of returned value when eventType is also specified as an argument:
   [
   {
      options:{
         listenerName:my-test-listener-1
      },
      listener:func1
   },
   {
      options:{
         capture:true,
         listenerName:my-test-listener-2
      },
      listener:func2
   },
   {
      options:{
         once:true,
         listenerName:my-test-listener-3
      },
      listener:func3
   }
   ]
   

hasEventListener(eventTarget, eventType, listenerName) → {boolean}

Returns whether a listenerName exists for the specified eventTarget and eventType.
Source:
Parameters:
Name Type Description
eventTarget EventTarget EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.

EventTarget by Mozilla Contributors is licensed under CC-BY-SA 2.5.

eventType String A case-sensitive string representing the event type to listen for.
listenerName String The listener name of the listener you want to find
Returns:
Type:
boolean

hasEventListeners(eventTarget, eventType) → {boolean}

Returns whether or not there are more than one event listener for the given eventTarget and eventType.
Source:
Parameters:
Name Type Description
eventTarget
eventType
Returns:
Type:
boolean

removeEventListener(eventTarget, eventType, listeneropt, optionsopt)

The EventListenerHelper#removeEventListener method removes from the EventTarget an event listener previously registered with EventListenerHelper#addEventListener. The event listener to be removed is identified using option. listenerName and a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal
Source:
Parameters:
Name Type Attributes Description
eventTarget EventTarget EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.

EventTarget by Mozilla Contributors is licensed under CC-BY-SA 2.5.

eventType String A string which specifies the type of event for which to remove an event listener.
listener function <optional>
(Either the listener or options.listenerName must be specified. If both are specified, options.listenerName takes precedence.)
The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs. This must be an object implementing the EventListener interface, or a JavaScript function. See The event listener callback for details on the callback itself.
options Object <optional>
(Either the listener or options.listenerName must be specified. If both are specified, options.listenerName takes precedence.)
An options object specifies characteristics about the event listener. The available options are:
listenerName
A StringBy assigning listenerName, the specified listener function (callback function) can be specified.In other words, it is possible to retrieve the listener function later using this listenerName as a key.listenerName must be unique.
capture
A Boolean indicating that events of this type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.

removeEventListener by Mozilla Contributors is licensed under CC-BY-SA 2.5.

Returns:

searchEventListenersByName(listenerName)

Get all listeners(listener definition) with a given listenerName. Since listeners need only be unique to the eventTarget and eventType, it is possible to have the same listenerName for different eventTargets and eventTypes.
Source:
Parameters:
Name Type Description
listenerName String The listener name of the listener you want to find
Returns:
[ { options: { listenerName: 'my-test-listener' },
        listener: [Function: func] },
   { options: { capture: true, listenerName: 'my-test-listener' },
        listener: [Function: func] },
   { options: { once: true, listenerName: 'my-test-listener' },
        listener: [Function: func] },
   { options: { once: true, listenerName: 'my-test-listener' },
        listener: [Function: func] } ]