API Docs for: 7.2
Show:

MQA.EventUtil Class

Module: MQA

Event library. Provides a cross browser interface for handling DOM Events.

Methods

$

(
  • el
)
HTMLElement

Helper function to provide a easier way to use document.getElementById. Works with both a DOM Element, or an id String.

Parameters:

Returns <HTMLElement>

the element that matches the id

_dtorHandler

() private

Global destructor onunload handler, gets added as an unloadListener in a valiant attempt to help cleanup the mess rather than foisting on the the browser's garbage collector.

_onUnload

() private

Global event handler for the "unload" DOM Event. Iterates through all the registered OnUnload callbacks and executes them.

This is intended to be a way to cleanup when a page is closing, instead of vomiting memory leaks everywhere.

_unwireDOMEvents

(
  • domElt
)
private

If no arguments are given, then unwire all events from all elements. Otherwise, just unwire the events from the element specified. Note that event subscriptions are left as is, in case more elements are added.

Parameters:

_wireDOMEvents

(
  • domElt
)
private

Wire all existing DOM Event subscriptions to the given DOM Element

Parameters:

addDOMEvent

()

Add a DOM Event to the list of subscriptions, and wire all existing elements with that event.

AddDOMEventProtocol

(
  • target
)

AddDOMEventProtocol - Mixes in a protocol to managed objects where subscriptions of DOM events can be managed. The following methods will be added to the object:

  • addDOMEvent: function(varargs of mousedown, click, dblclick, etc ..) - Called by users of the instance to express interest in receiving DOM events of certain types.
  • _wireDOMEvents: function(domElt) - Should be called internally when events need to be wired (ie. when an element is constructed)
  • _unwireDOMEvents: function() - Should be called internally prior to removing elements previously connected.
  • dispose$Before: function() - Calls _unwireDOMEvents(), will execute before the target's dispose method is called, if it has one.

The mixin expects the following methods to be defined:

  • _onDOMEvent: function(domEvt) - Called for each DOM event wired. If this method does not exist, then it will be created.

The following fields will be defined by using this mixin:

  • _domSubs - array of event types to subscribe to
  • _domWired - array of elements that have been wired by _wireDOMEvents

Parameters:

  • target HTMLElement

    the DOM element to mix the protocol into

addDtor

(
  • object
  • methodName
)
Number

Add a destructor function to the registry. Return an index value which can be used to deregister the destructor if the object is destroyed naturally (see delDtor()). This method can be called in two forms:

  • addDtor(someObj, 'methodName');
  • addDtor(fcn)
The first is preferred in most cases, since it typically will eliminate the need for an extra closure and aids in debugging (since there is enough context in the _dtorRegistry to determine which objects are still live at any given time).

Parameters:

Returns <Number>

destructor index

addOnUnload

(
  • callback
)

Adds a callback to be executed when the window unload event fires. This mechanism provides a way to register multiple cleanup functions.

Parameters:

  • callback Function

    the callback to register with the unload event

delDtor

(
  • index
)

Delete a previously allocated destructor with the index returned from addDtor. This should typically be called from within the destructor so that naturally destroying the object will remove it from the registry.

Parameters:

dispose$Before

()

Add a pre-hook to the target's dispose method to unwire everything, or if no dispose method exists, create one.

element

(
  • event
)
HTMLElement

Returns the source element that the event was triggered on.

Parameters:

  • event Event

    the DOM event

Returns <HTMLElement>

the DOM element

EventCallback

(
  • obj
  • methodName
)

Provides a cross browser way to have the method on an object be the callback of an event listener. The only arg to the callback will be the DOM Event itself. (NOTE: This means you don't have to check for window.event on IE to get the event.)

Parameters:

  • obj Object

    the object containing the method

  • methodName String

    the method name to call on the object

EventUtil_processEventName

(
  • element
  • name
)
private

Provides a cross browser util to help standardize some event names.

Parameters:

falseFunction

()

Function that just returns false. Used for static event handlers.

hitch

(
  • tgtObj
  • tgtMethod
)
Function

Return a lightweight-closure function that when called will call tgtObj[tgtMethod]. Use in places such as elt.onload=function() { this.someMethod(); } to avoid capturing circular references in your context and to keep the correct context. (You'll know you need to use hitch when your 'this' context is unexpectedly 'window'.) Any arguments following tgtMethod will be passed to the method.

Parameters:

Returns <Function>

isLeftClick

(
  • event
)
Boolean

Returns true if the mouse event was triggered via the left mouse button.

Parameters:

  • event Event

    the DOM event

Returns <Boolean>

true if generated by a left click

isRightClick

(
  • event
)
Boolean

Determines from the event if it was triggered via the mouse right click button.

Parameters:

  • event Event

    the DOM event

Returns <Boolean>

true if generated by a right click

observe

(
  • element
  • name
  • observer
)
Function

Observe a DOM Element and listen for the provided DOM Event name, executing the provided callback function when the event is triggered on the element. (Yes, this is the cross browser wrapper for addEventListener.)

Parameters:

Returns <Function>

the provided observer callback function

stop

(
  • event
)

Stops the event propagation AND prevents the default action.

Parameters:

  • event Event

    the DOM event

stopObserving

(
  • element
  • name
  • observer
)

Remove the observer, listening for the event name, on the DOM Element. (Yes, this is the cross browser wrapper for removeEventListener.)

Parameters:

unselectable

(
  • elt
)

Make an element unselectable in a cross-platform way. NOTE: Execute this method on IMG elements if you want them to be draggable on the map.

Parameters: