lb.core.plugins.dom

Document Object Model Plugin for the Sandbox API

Authors

Copyright

Eric Bréchemier © 2011, Some Rights Reserved Legal-Box SAS © 2010-2011, All Rights Reserved

License

BSD License http://creativecommons.org/licenses/BSD/

Version

2011-08-14

Summary
lb.core.plugins.domDocument Object Model Plugin for the Sandbox API
Functions
dom(sandbox)Define methods in the ‘dom’ property of given sandbox.
sandbox.dom.$(localId): DOM ElementGet the element of the box with given local identifier.
sandbox.dom.element(name[,attributes[,childNodes]]): DOM ElementCreate a new DOM element using the configured DOM factory.
sandbox.dom.fireEvent(element,type[,properties]): DOM EventCreate and dispatch a new DOM event to the given element, using the configured DOM factory.
sandbox.dom.cancelEvent(event)Cancel an event using the configured DOM factory.
sandbox.dom.getListeners(): arrayGet the list of listeners configured on DOM elements of the box.
sandbox.dom.addListener(element,type,callback): ListenerRegister a new listener for a type of event on a DOM element of the box using the configured DOM factory.
sandbox.dom.removeListener(listener)Unregister a listener, using the configured DOM factory.
sandbox.dom.removeAllListeners()Remove all listeners configured on DOM elements of the box, using the configured DOM factory.

Functions

dom(sandbox)

Define methods in the ‘dom’ property of given sandbox.

Parameters

sandboxobject, the sandbox instance to enrich with DOM methods

sandbox.dom.$(localId): DOM Element

Get the element of the box with given local identifier.

Parameter

localIdstring, the local identifier of the element, without prefix.  See getId() for details.

Returns

  • DOM Element, the element from the box with corresponding localId
  • null if no element is found in the box with the localId

Note

A call to $() with no argument will return the box element, similarly to getBox(false).

sandbox.dom.element(name[,attributes[,childNodes]]): DOM Element

Create a new DOM element using the configured DOM factory.  For example, using the default DOM factory,

element('a',{href:'#here',title:'Here'},'Click here')

will create a new DOM element

<a href='#here' title='Here'>Click here</a>

A custom DOM factory can be configured using the property lbFactory with lb.core.application.setOptions(options).

Parameters

namestring, the name of the element
attributesobject, optional arguments as a set of named properties
childNodesarray or list of arguments, the optional child nodes.  Text nodes shall be represented simply as strings.

Returns

DOM Element, the newly created DOM element.

sandbox.dom.fireEvent(element,type[,properties]): DOM Event

Create and dispatch a new DOM event to the given element, using the configured DOM factory.

Parameters

elementDOM Element, an element of the box
typestring, the name of an event (without ‘on’) e.g.  ‘click’
propertiesobject, optional event properties.  Each property will be copied to the new DOM event.

Returns

DOM Event, the new DOM event

sandbox.dom.cancelEvent(event)

Cancel an event using the configured DOM factory.

Using the default DOM factory, cancelling an event prevents the default action and stops bubbling.

Parameter

eventDOM Event

sandbox.dom.getListeners(): array

Get the list of listeners configured on DOM elements of the box.  Listeners can be added with addListener() and removed one by one with removeListener(), or all at once with removeAllListeners().

Returns

array, the current list of listener objects (lb.base.dom.Listener)

sandbox.dom.addListener(element,type,callback): Listener

Register a new listener for a type of event on a DOM element of the box using the configured DOM factory.

Parameters

elementDOM Element, an element of the box
typestring, the name of an event (without ‘on’) e.g.  ‘click’
callbackfunction, a function to call when the event is dispatched.

Returns

  • null, when the element is outside the box (no listener added),
  • object, the new listener otherwise.  This object shall be provided to removeListener() to unregister the listener.  No other interaction is expected with this object.

Notes

  • the listener is set on bubbling phase.
  • the target element must be part of the box, i.e. already added to the DOM; otherwise the call is ignored per sandbox policy.

sandbox.dom.removeListener(listener)

Unregister a listener, using the configured DOM factory.

Parameters

listenerobject, a listener instance returned by addListener().

Note

Nothing happens when the listener has already been removed.

sandbox.dom.removeAllListeners()

Remove all listeners configured on DOM elements of the box, using the configured DOM factory.

All remaining listeners, previously configured with addListener(), add removed.  This method is intended as a cleanup utility ; it is called automatically by the framework after the module terminates in end(), which makes its use optional for the module itself.

Configure a set of option properties.
Close