lb.core.Sandbox

Sandbox for Modules of Legal Box Scalable JavaScript Application

A new instance of Sandbox gets attributed to each instance of Module.  It acts both as a proxy and a facade to the application core, restricting modifications to the box assigned to the module, an HTML element which encloses the module.

The methods related to the module itself are defined on the Sandbox.  Other methods are defined by separate plugin modules.

Module (sandbox)

Cascading Style Sheets (sandbox.css, defined by lb.core.plugins.css)

Document Object Model (sandbox.dom, defined by lb.core.plugins.dom)

Events for loose coupling with other modules (sandbox.events, defined by lb.core.plugins.events)

Internationalization through language properties (sandbox.i18n, defined by lb.core.plugins.i18n)

Asynchronous communication with a remote server (sandbox.server, defined by lb.core.plugins.server)

Uniform Resource Locator, local navigation (sandbox.url, defined by lb.core.plugins.url)

General utilities (sandbox.utils)

The plugins are loaded by the Sandbox Builder.  The sandbox API can be customized by configuring a different sandbox builder to load additional or alternative plugins.  See lb.core.plugins.builder for details.

Authors

Copyright

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

License

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

Version

2013-09-10

Summary
lb.core.SandboxSandbox for Modules of Legal Box Scalable JavaScript Application
Functions
new Sandbox(id): SandboxConstructor of a new Sandbox.
sandbox.getId([localId]): stringGet the identifier of the module, when optional parameter is omitted.
sandbox.getBox(createIfMissing): DOM ElementGet the root HTML element for this module.
sandbox.isInBox(element): booleanCheck whether the given element is in the box.

Functions

new Sandbox(id): Sandbox

Constructor of a new Sandbox.

Parameters

idstring, the identifier of the module, which is also the id of the root HTML element for this module.  If the element does not exist in the document, it will get created on the first call to getBox().

Returns

object, the new instance of Sandbox

sandbox.getId([localId]): string

Get the identifier of the module, when optional parameter is omitted.  With optional parameter, get the full identifier corresponding to the given local identifier.

Parameter

localIdstring, optional local identifier

Returns

string, the identifier of the module, as provided in constructor, or the full identifier corresponding to given local identifier.

Note

The full identifier is made of the module identifier, followed by the separator ‘.’, followed by the local identifier.

sandbox.getBox(createIfMissing): DOM Element

Get the root HTML element for this module.

Parameter

createIfMissingboolean, optional, defaults to true, Whether to create the box element if it is not found in the document.  Note: In case createIfMissing is true (by default) and no HTML element is found in the document with the module id, a new div element is created with this id and inserted last in the document body.

Returns

  • DOM Element, the HTML element corresponding to the module id,
  • or null, in case createIfMissing is false and the element is missing

sandbox.isInBox(element): boolean

Check whether the given element is in the box.

Parameter

elementDOM Element, an element

Returns

  • true if the element is a descendant of or the root of the box itself
  • false otherwise
Get the identifier of the module, when optional parameter is omitted.
Get the root HTML element for this module.
Check whether the given element is in the box.
Cascading Style Sheets Plugin for the Sandbox API
Get the CSS classes of given DOM element.
Append a CSS class to a DOM element part of the box.
Remove a CSS class from a DOM element part of the box.
Document Object Model Plugin for the Sandbox API
Get the element of the box with given local identifier.
Create a new DOM element using the configured DOM factory.
Create and dispatch a new DOM event to the given element, using the configured DOM factory.
Cancel an event using the configured DOM factory.
Get the list of listeners configured on DOM elements of the box.
Register a new listener for a type of event on a DOM element of the box using the configured DOM factory.
Unregister a listener, using the configured DOM factory.
Remove all listeners configured on DOM elements of the box, using the configured DOM factory.
Publish/Subscribe Plugin for the Sandbox API
Create a new event subscription, triggering the callback only for events matching the provided filter.
Remove all subscriptions for given filter.
Publish a new event for broadcasting to all interested subscribers.
Internationalization Plugin for the Sandbox API
Get the list of available languages.
Get the language currently selected for the application.
Select the language of the application, shared by all modules.
Define or replace properties for given language.
Get the value of the property identified by given key.
Get a string computed by replacing data values in the most specific value found for given key, used as a string template.
Replace parameters and trim nodes based on html ‘lang’ attribute.
Asynchronous Communication with a Remote Server Plugin for the Sandbox API
Send and receive data from the remote host.
Uniform Resource Locator Plugin for the Sandbox API
Get the properties of the current URL location
Jump to a new local location by replacing the hash part of the URL.
Set a listener to observe changes in local part of the URL.
Check whether given value is null or undefined
Get a default value when given value is null or undefined
Check whether an object property is present and not null nor undefined.
Check the type of a value, possibly nested in sub-properties.
Get current timestamp, in milliseconds.
Plan the delayed execution of a callback function.
Cancels the planned execution of a callback function.
Remove leading and trailing whitespace from a string.
Log a message.
Open a confirmation (OK/Cancel) dialog.
Sandbox Builder, associate plugins to define the different parts of the API
Close