<node>
The base class for all Laszlo classes.

JavaScript: lz.node
extends lz.Eventable »
The lz.node class provides the basic interface for OpenLaszlo objects: parent/child hierarchy, setters, interaction with the instantiator, and reference resolution. New nodes (and subclasses thereof) can be created by new-ing the class, like this: var mynode= new LzNode( parent , args ); where parent is the parent for the new node, and args is an Object whose name/value pairs are attributes to be set on the new node.

Attributes

Name (CSS property) Type (tag) Type (js) Default Category
classroot   lz.node   readonly
  A reference to the node that is an instance of the <class> where this node is defined. Members of state subclasses do not define classroot. This is convenient to use when you want to access an attribute of the class in a method or event handler that is nested deep in the node hierarchy. For example, to set the bgcolor of the class object, instead of parent.parent.parent.setAttribute(bgcolor, 0xFFFFFF) you can simply use classroot.setAttribute(bgcolor, 0xFFFFFF).
cloneManager   lz.node   readonly
  If this node is replicated due to data replication, the LzReplicationManager which controls this node.
data expression Object   read/write
  The data context for the node
datapath string String   read/write
  A shorthand version of <datapath>, specifies the data source for this node and its children. You write a string to datapath; reading datapath will yield a lz.datapath. If the value begins with an identifier followed by a colon, the identifier names a dataset, and the portion of the string after the colon is an XPath description of a portion of the data. Otherwise the entire attribute value is an XPath description of the data, relative to the data source of this node's parent element. Examples: "mydata:", "mydata:/a/b", "/a/b".
defaultplacement token String   initialize-only
  An attribute used in container classes. If set to a non-null value, this forces this node to run its determinePlacement method for any node whose parent is this node. If the subnode has its own placement attribute, determinePlacement will be called with that value, otherwise it will be called with this value. Note that a class's defaultplacement attribute only applies to children in subclasses or in instances, not to the children of the class itself. This means that if a class and its subclass both define a defaultplacement attribute, the attribute will be set to one value before the subclass children are created and to a different one after they are created. See the determinePlacement method.
id token String   initialize-only
  A unique identifier for this element. Can be used as a global variable name in JavaScript code.
ignoreplacement   Boolean "false" initialize-only
  Overrides placement attribute (and defaultplacement in lexical parent). See the LzNode.determinePlacement method. Defaults to false.
immediateparent   lz.node   readonly
  Reference to this nodes's parent in the node hierarchy. This will be different from "parent" when a class uses placement or defaultplacement to assign a subnode a specific place. For example, always use immediateparent to get a mouse position in your views coordinate system.
inited   boolean   readonly
  Indicates that a node's init method has been called. True when init has been called and the oninit event has been sent. The execution of the init method is under control of the initstage attribute.
initstage "early" | "normal" | "late" | "immediate" | "defer" String "normal" initialize-only
  The execution of a node's init method and sending of the oninit event is under the control of its initstage attribute, as follows:
immediate
The init method is called immediately as the last stage of instantiation.
early
The init method is called immediately after the view and its children have been instantiated.
normal
The init method is called when the parent is initialized.
late
The init method is called during idle time. To check whether init has been called, check the inited property. Force calling init using the completeInstantiation method.
defer
The init method will not be called unless explicitly requested by the completeInstantiation method.
name token String   initialize-only
  The name for this subnode. If given, then this node's parent and immediate parent will store a pointer to this node as the given name value.
nodeLevel   Number   readonly
  The depth of this node in the overall node hierarchy
options css Object   initialize-only
  A CSS declaration of property: value pairs that modify the interaction of this node with controllers such as replicators and layouts. For example, setting options="ignorelayout: true" on a view will cause the view to not be controlled by any layout.
[Note] Note
The options that affect particular controllers and replicators are documented with each controller and replicator.
[Note] Note
options should not be accessed directly. You must use getOption and setOption to get or set the value of an option.
parent   lz.node   readonly
  Reference to the node that was passed as this node's ancestor in the constructor. If this node was created by declaring it in a tag, the parent will be its lexical parent. Its lexical parent is the tag that encloses it. Allow a null parent so that nodes can be garbage collected when they are no longer needed. See also, immediateparent.
placement string String   initialize-only
  Instructions to this element's container about where it should go within its container's internal hierarchy. See the LzNode.determinePlacement method. Defaults to the container itself.
styleclass string String   read/write
 

A space-separated list of CSS classes that can be used in a stylesheet to select this node. For example:

<canvas height="20" layout="axis: x; spacing: 5">
   <stylesheet>
     .red { background-color: red }
     .green { background-color: green }
     .red.green { background-color: yellow }
   </stylesheet>

   <class name="swatch" height="20" width="20">
     <attribute name="bgcolor" style="background-color" value="blue"/>
   </class>

   <swatch styleclass="red"/>
   <swatch styleclass="green"/>
   <swatch styleclass="red green"/>
   <swatch/>
 </canvas>

The first selector applies to the first swatch; the second to the second; and all three selectors apply to the third swatch, with the latter taking precedence over the former. The final swatch has no styleclass and so uses the default value.

subnodes   Array   readonly
  An array of all of the LzNodes which consider this LzNode their parent. This list is similar to the subviews list, but it contains all the children of this node, not just the view children.
transition string String   read/write
  Allows node attributes to be automatically animated when set. A string of transitions, according to the css3 transition spec http://dev.w3.org/csswg/css3-transitions/#the-transition-shorthand-property- e.g. 'x 2s'. Note that transition-delay is not currently supported. [transition-property || transition-duration || transition-timing-function || transition-delay [, [transition-property || transition-duration || transition-timing-function || transition-delay]]*

Methods

animate()
node.animate(prop : String, to : Number, duration : Number, isRelative : Boolean, moreargs : Object);
animate is the simplest way to animate a property of a node. This method creates an animator which will change the value of the given property over the given duration. The result of this call is an LzAnimator object. Note that the animation is asynchronous -- that is, code that follows this call will be executed before the animation finishes. Calling this method with a duration of 0 does not create an animator, but instead just calls setAttribute.
Parameter Name Type Description
prop String a string specifying the property to animate. public properties are: x, y, width, height, rotation, alpha
to Number the end value of the animation
duration Number the duration of the animation
isRelative Boolean is the animator applied to the property relatively or not
moreargs Object A dictionary of attributes to pass to the LzAnimator constructor
Returns Type Description
  lz.animator a reference to the animator that was added

applyConstraintMethod()
node.applyConstraintMethod(constraintMethodName : String, dependencies : Array);
Applies a method as a constraint.
Parameter Name Type Description
constraintMethodName String The name of the method that will be invoked when any of the dependencies changes. Typically this method 'constrains' an attribute to a computation on the dependent attributes. E.g. `function constrain_foo () { this.setAttribute( 'foo' , this.x + myfriend.width ) }`. This method _must_ be a method on the instance to which you are applying the constraint.
dependencies Array An array of (reference, attribute) pairs that the constraint depends on. For instance, if the constraint depends on my x and my friend's width, the dependencies array would look like this: `[ this, "x" , myfriend, "width" ]`

applyData()
node.applyData(data : String);
Called on any node that is declared with a datapath that matches a terminal selector, such as text() or @attribute when the data it matches is changed.
Parameter Name Type Description
data String a string representing the matching data

childOf()
node.childOf(node : lz.node, ignore : Boolean);
Tests whether the given node is a parent (or grand-parent, etc.) of this node.
Parameter Name Type Description
node lz.node The node to test to see if it is somewhere above this one in the node hierarchy
ignore Boolean Not used by LzNode, but see LzDataNodeMixin
Returns Type Description
  Boolean true if this node is a child of the given node.

completeInstantiation()
node.completeInstantiation();
Ensures that the children of this node have been created, and this node has been inited. The LFC does this automatically for nodes with initstage other than late or defer. Call this function to force instantiation to complete synchronously for nodes with initstage=late, and to force it to happen at all for nodes with initstage=defer.

construct()
node.construct(parent : lz.node, args : Object);
The construct method of a node is called as part of the process of constructing a node. It is called after attributes with constant initial values of the class have been filled in, but before any attributes that have setters or have been constrained have been applied. This is the method to override if you need to initialize instances of an LZX class as they are constructed. If you override this method, you must call the superclass method (super.construct(parent, args). Note that construct can only be overriden within a subclass definition, not within a customized instance. The construct method is also responsible for placing the newly-built view into the appropriate place within its lexical parent's view hierarchy. The process for this is as follows:
  • First, if the view has an ignoreplacement attribute with a true value, then the view will be placed directly under its lexical parent in all cases. The next steps are skipped.
  • Second, the placement view name is determined from the first of the following that matches:
    • the view's placement attribute, if that exists; or
    • the lexical parent's defaultplacement attribute, if that exists; or
    • nil.
  • Third, if there is no placement view name, the subview is placed within its lexical parent (that is, view.immediateparent = view.parent), and the next steps are skipped.
  • Fourth, the placement view name is looked up within the lexical parent by calling determinePlacement, and the result is taken as the view's placement view.
  • If this new placement view is a subview and it has a defaultplacement attribute, determinePlacement is called again. This process is repeated until no defaultplacement attribute is found to ensure that all placement directives are correctly followed.
Parameter Name Type Description
parent lz.node The node that encloses this node in source, or the node to which to attach this node.
args Object A dictionary of attribute initializations for attributes that have setters or that have been supplied by the instance declaration. In general, your construct method should not modify this dictionary. It may delete a value from the dictionary to indicate that it has been handled by the construct method (and should not be further processed).

createChildren()
node.createChildren(carr : Array);
This function is used to instantiate subnodes. LzNodes may override or extend this method to change the meaning of attached subnodes.
Parameter Name Type Description
carr Array an array of children where the structure of each child [c] takes the form: c.name = a string containing the name of the child -- usually its constructor c.args = a dictionary of attributes and values to be passed to the constructor of that child c.children = an array of children for the new child

dataBindAttribute()
node.dataBindAttribute(attr : String, path : String, type : String);
Binds the named attribute to the given path, relative to this node's datapath. This is the method that is called when the $path{} constraint is used. Note that the binding is two-way -- changing the value of the attribute will update the data.
Parameter Name Type Description
attr String The name of the attribute to bind to the given path.
path String The xpath (relative to this node's datapath) to which to bind the attribute.
type String The type of the attribute

destroy()
node.destroy();
Deletes the node and all the subnodes.

determinePlacement()
node.determinePlacement(aSub : lz.node, placement : String, args : dictionary);
Determines the immediateparent for a subnode whose parent is this node. This method will only be called for subnodes which have a placement attribute, or for all subnodes if this node has a non-null defaultplacement. The placement attribute of a subnode overrides a parent's defaultplacement. This method looks for a subnode with the name given in the placement parameter, and returns that node. If no such named node exists, it returns 'this'. A subclass might implement this method to cause the "placement" parameter to have a different behavior or additional effects.
[Note] Note
This function is not currently designed to be called by anyone but LzNode.construct. Do not expect to be able to 'place' a view properly after it has been constructed.
Parameter Name Type Description
aSub lz.node The new subnode
placement String The placement attribute for the new subnode
args dictionary The initialization args for the new subnode
Returns Type Description
  lz.node the node which will be the immediateparent of aSub

getOption()
node.getOption(key : String);
Returns the value for an option. Options are initialized by the options attribute for nodes created from LZX, or from the dictionary passed as the options attribute to the node constructor from script. Individual options may also be added or updated at runtime using setOption.
Parameter Name Type Description
key String The option to retrieve
Returns Type Description
  any The value for that option (or undefined, if the option has not been set)

getUID()
node.getUID();
Returns the unique ID of the node.
Returns Type Description
  String A string representing a unique ID for the node.

init()
node.init();
This is the method to override if you need to do complex initialization tasks on instances of an LZX class after their children have been initialized. After this method is called the oninit is sent, and the inited attribute will be true.

lookupSourceLocator()
node.lookupSourceLocator(sourceLocator : String);
Translate a source locator to the corresponding node
Parameter Name Type Description
sourceLocator String the locator to translate
Returns Type Description
  any Either the corresponding LzNode or undefined if the source locator is unknown

releaseConstraint()
node.releaseConstraint(attr : String);
Release a constraint on an attribute Only works for initial constraints. Constraints applied at runtime should be applied and released with `applyConstraintMethod` and `releaseConstraintMethod`.
Parameter Name Type Description
attr String The name of the attribute to release the constraint from

releaseConstraintMethod()
node.releaseConstraintMethod(constraintMethodName : String);
Release a constraint method
Parameter Name Type Description
constraintMethodName String the constraint to release

searchImmediateSubnodes()
node.searchImmediateSubnodes(prop : String, val : any);
Searches immediate subnodes for the given value of the given property.
Parameter Name Type Description
prop String The attribute name to search for
val any The value of the attribute.
Returns Type Description
  lz.node A pointer to a subnode with the given property, or null.

searchSubnodes()
node.searchSubnodes(prop : String, val : any);
Searches subnodes for the given value of the given property. For now, returns when it finds the first one. This is a width first search.
Parameter Name Type Description
prop String The attribute name to search for
val any The value of the attribute.
Returns Type Description
  lz.node A pointer to the first subnode with the given property or null if none is found

setOption()
node.setOption(key : String, val : any);
Sets the value for an option.
[Note] Note
Options are used primarily for modifying the interaction of this node with controllers and replicators. Whether or not changing an option at runtime will affect a particular controller or replicator interaction is documented with each controller or replicator.
Parameter Name Type Description
key String The option to set
val any The value for the option.

setSelected()
node.setSelected(sel : boolean);
Parameter Name Type Description
sel boolean true when this node was selected, false when it lost selection

updateData()
node.updateData();

Methods inherited from lz.Eventable

destroy, setAttribute

Events

Name Description
onconstruct This is the first event a node sends, right at the end of the instantiation process, but before any subnodes have been created or references resolved
ondata The ondata script is executed when the data selected by a view's datapath changes.
oninit This event is sent after the node's init method has been called. Simple actions that need to occur after the node's children have been initialized can be assigned to this event. For more complex initialization, see the init method.

Events inherited from lz.Eventable

ondestroy