Environment

The Environment Base class provide base functions to run an UWA Widget Execution Environnement.  It is an abstract class, and must be extended to be useful.  The object must be filled with DOM elements (at least body), in the “<onInit>” or “<onRegisterModule>” callbacks for example.

Summary
EnvironmentThe Environment Base class provide base functions to run an UWA Widget Execution Environnement.
Properties
widgetWidget: current widget registered in this environnement.
htmlObject: HTML Dom elements related to this environnement
loadedBoolean: flag to know if the Environnement is loaded.
registeredBoolean: flag to know if a Widget is registered.
debugModeBoolean: activates or desactivates the debug mode for the widget.
periodicalsObject: Stores environment’s periodical events.
delaysObject: Stores environment’s delayed events.
heightInteger: The current height of the widget in pixel.
Functions
initInitialize the Environment, when DOM is ready
getModuleReturns the widget (= module) currently registered in the Environment.
registerModuleRegisters a Widget (module) into the execution Environment.
launchModuleLaunch the registered widget by fire the widget.launch method.
callbackFire Environment.key then the callback method associated with the given callback name (key).
setPeriodicalRegister a function as periodical event.
clearPeriodicalUnregister a periodical event previously registered with setPeriodical
setDelayedRegisters a function as delayed event.
clearDelayedUnregister a delayed event previously registered with setDelayed
logLogs environment’s messages in the console, if one exists and if the debugMode is true.

Properties

widget

Widget: current widget registered in this environnement.

html

Object: HTML Dom elements related to this environnement

Common Elements are ‘title’, ‘edit’, ‘body’ & ‘icon’

loaded

Boolean: flag to know if the Environnement is loaded.

Environment is likely ready once it is instanciated and the DOM is ready to be manipulated.

registered

Boolean: flag to know if a Widget is registered.

A widget is not registered until the Environment is loaded

debugMode

Boolean: activates or desactivates the debug mode for the widget.

The default value is TRUE.  When TRUE, messages written with log method will appear in the console.

periodicals

Object: Stores environment’s periodical events.

The object is initially empty.  It is filled by the setPeriodical method.

delays

Object: Stores environment’s delayed events.

The object is initially empty.  It is filled by the setDelayed method.

height

Integer: The current height of the widget in pixel.

Notes

Experimental.  Only used in some environments.

Functions

init

init: function()

Initialize the Environment, when DOM is ready

Parameters

  • None.

getModule

getModule: function()

Returns the widget (= module) currently registered in the Environment.  If no widget is registered, the Environment creates one and registers it.

Parameters

  • None.

Returns

  • Widget: the (maybe newly created) registered widget.

registerModule

registerModule: function(module)

Registers a Widget (module) into the execution Environment.  Once done, fire the onRegisterModule callback.

Parameters

  • Widget : the widget to register in the Environment.

Returns

  • Nothing.

launchModule

launchModule: function()

Launch the registered widget by fire the widget.launch method.

If needed, wait until the environment is fully loaded and a widget registered.

Parameters

  • None.

callback

callback: function(name,
args,
bind)

Fire Environment.key then the callback method associated with the given callback name (key).  Returns false if no callback method is associated with the given key.

Parameters

  • String name: the callback name (e.g.  “onUpdateTitle”);
  • Object args: one optional argument
  • Object: an object to bind the callback to

Returns

  • Nothing, but calls the method associated with the given callback name (key)

setPeriodical

setPeriodical: function(name,
fn,
delay,
force)

Register a function as periodical event.

The function will automatically be binded to the current environment object.

Parameters

  • String name: the name of the event
  • Function fn: the function to register
  • Integer delay: the execution delay in milliseconds
  • Boolean force: If true, fire the function for the time right now.

Notes

internal or advanced use only

clearPeriodical

clearPeriodical: function(name)

Unregister a periodical event previously registered with setPeriodical

Parameters

  • String name: the name of the event

Notes

internal or advanced use only

setDelayed

setDelayed: function(name,
fn,
delay,
bind)

Registers a function as delayed event.

If ‘bind’ is not defined, the function will automatically be bound to the current environment object.

Parameters

  • String name: the name of the event
  • Function fn: the function to register
  • Integer delay: the delay in milliseconds
  • Object bind: A javascript object to bind the function to.

Notes

internal or advanced use only

clearDelayed

clearDelayed: function(name)

Unregister a delayed event previously registered with setDelayed

Parameters

  • String name: the name of the event

Notes

internal or advanced use only

log

log: function(string)

Logs environment’s messages in the console, if one exists and if the debugMode is true.  It is using <UWA.log> which usually works with Firebug, Safari and Opera.

Parameters

  • String message: the message to display in the console.

Example

widget.log("Environment is loading");
init: function()
Initialize the Environment, when DOM is ready
getModule: function()
Returns the widget (= module) currently registered in the Environment.
registerModule: function(module)
Registers a Widget (module) into the execution Environment.
launchModule: function()
Launch the registered widget by fire the widget.launch method.
callback: function(name,
args,
bind)
Fire Environment.key then the callback method associated with the given callback name (key).
setPeriodical: function(name,
fn,
delay,
force)
Register a function as periodical event.
clearPeriodical: function(name)
Unregister a periodical event previously registered with setPeriodical
setDelayed: function(name,
fn,
delay,
bind)
Registers a function as delayed event.
clearDelayed: function(name)
Unregister a delayed event previously registered with setDelayed
log: function(string)
Logs environment’s messages in the console, if one exists and if the debugMode is true.
Boolean: activates or desactivates the debug mode for the widget.