Yahoo! UI Library

makenode  1.0

Yahoo! UI Library > makenode > MakeNode
Search:
 
Filters

Class MakeNode

An extension for Widget to create markup from templates, create CSS classNames, locating elements, assist in attaching events to UI elements and to reflect attribute changes into the UI. All of its members are either protected or private. Developers using MakeNode should use only those marked protected. Enable the Show Protected checkbox to see them.

Constructor

MakeNode ( )

Properties

_ATTRS_2_UI - protected static Object

** This is a documentation entry only. This property is not defined in this file, it should be defined by the developer. **

Lists the attributes whose value should be reflected in the UI. It contains an object with two properties, BIND and SYNC, each containing the name of an attribute or an array of names of attributes. Those listed in BIND will have listeners attached to their change event so every such change is refreshed in the UI. Those listed in SYNC will be refreshed when the UI is rendered. For each entry in either list there should be a method named using the _uiSet prefix, followed by the name of the attribute, with its first character in uppercase. This function will receive the value to be set and the source of the change.

_CLASS_NAMES - protected static [String]

** This is a documentation entry only. This property is not defined in this file, it should be defined by the developer. **

Holds an array of strings, each the suffix used to define a CSS className using the _cssPrefix of each class. The names listed here are used as the keys into this._classNames, as the argument to the {c} template placeholder and as keys for the entries in the _EVENTS property. They are also used by _locateNodes to create the private properties that hold references to the nodes created.

_classNames - protected Object

Contains a hash of CSS classNames generated from the entries in _CLASS_NAMES indexed by those same values. It will also have the following entries added automatically:
  • . The className for the boundingBox
  • content The className for the contentBox
  • HEADER The className for the header section of a StdMod if Y.WidgetStdMod has been loaded
  • BODY The className for the body section of a StdMod if Y.WidgetStdMod has been loaded
  • FOOTER The className for the footer section of a StdMod if Y.WidgetStdMod has been loaded

_EVENTS - protected static Object

** This is a documentation entry only. This property is not defined in this file, it should be defined by the developer. **

Contains a hash of elements to attach event listeners to. Each element is identified by the suffix of its generated className, as declared in the _CLASS_NAMES property.
There are three further element identifiers, a "." identifies the boundingBox of the Widget, "content" its contextBox, and a ".." identifies the document where the component is in. If the Y.WidgetStdMod extension is used the "HEADER", "BODY" and "FOOTER" identifiers will also be available.
Each entry is made of a further hash using the type of event to listen to ("key", "mousedown", etc) as the key to each handler.
For each type of event, you can list either a string with the name of an instance method that will handle the event or an object with properties fn with a string with the name of the instance method and an args property with extra arguments for the listener, such as a key descriptor for key events

_TEMPLATE - protected static String

** This is a documentation entry only. This property is not defined in this file, it should be defined by the developer. **

Holds the default template to be used by _makeNode when none is explicitly provided.
The string should contain HTML code with placeholders made of a set of curly braces enclosing an initial processing code and arguments. Placeholders can be nested, any of the arguments in a placeholder can be another placeholder.
The template may also contain regular placeholders as used by Y.substitute, whose values will be extracted from the second argument to _makeNode. The processing codes are:
  • {@ attributeName} configuration attribute values
  • {p propertyName} instance property values
  • {m methodName arg1 arg2 ....} return value from instance method. The m code should be followed by the method name and any number of arguments. The placeholder is replaced by the return value or the named method.
  • {c classNameKey} CSS className generated from the _CLASS_NAMES static property
  • {s key} string from the strings attribute, using key as the sub-attribute.
  • {? arg1 arg2 arg3} If arg1 evaluates to true it returns arg2 otherwise arg3. Argument arg1 is usually a nested placeholder.
  • {1 arg1 arg2 arg3} If arg1 is 1 it returns arg2 otherwise arg3. Used to produce singular/plural text. Argument arg1 is usually a nested placeholder.
  • {} any other value will be handled just like Y.substitute does.
For placeholders containing several arguments they must be separated by white spaces. Strings must be enclosed in double quotes, no single quotes allowed. The backslash is the escape character within strings. Numbers, null, true and false will be recognized and converted to their native values. Any argument can be a further placeholder, enclosed in its own set of curly braces.

_templateHandlers - private Object

Hash listing the template processing codes and the functions to handle each. The processing functions will receive a string with the arguments that follow the processing code, and should return the replacement value for the placeholder.

Methods

_attachEvents

private void _attachEvents ( )
Attaches the events listed in the _EVENTS static property of each class in the inheritance chain.

_concatUIAttrs

private void _concatUIAttrs ( )
Concatenates the entries of the _ATTRS_2_UI static property of each class in the inheritance chain into this instance _UI_ATTRS property for the benefit or Widget. See Widget._UI_ATTRS

_detachEvents

private void _detachEvents ( )
Detaches all the events created by _attachEvents

_locateNodes

protected void _locateNodes ( arg1,.... )
Locates the nodes with the CSS classNames listed in the this._classNames property, or those specifically requested in its arguments and stores references to them in properties named after each className key, prefixed with an underscore and followed by "Node".
Parameters:
arg1,.... <String> (optional) If given, list of className heys of the nodes to be located. If missing, all the classNames stored in this._classNames will be located.

_makeClassNames

private void _makeClassNames ( )
Looks for static properties called _CLASS_NAMES in each of the classes of the inheritance chain and generates CSS classNames based on the _cssPrefix of each class and each of the suffixes listed in each them. The classNames generated will be stored in this._classNames indexed by the suffix. It will also store the classNames of the boundingBox ( . )and the contentBox ( content ). If the WidgetStdMod is used, it will also add the classNames for the three sections ( HEADER, BODY, FOOTER )

_makeNode

protected Y.Node _makeNode ( template , extras )
Processes the template given and returns a Y.Node instance.
Parameters:
template <String> (optional) Template to process. If missing, it will use the first static _TEMPLATE property found in the inheritance chain.
extras <Object> (optional) Hash of extra values to replace into the template, beyond MakeNode's processing codes.
Returns: Y.Node
Instance of Y.Node produced from the template

_parseMakeNodeArgs

private Array _parseMakeNodeArgs ( arg )
Parses the arguments received by the processor of the {m} placeholder. It recognizes numbers, true, false, null and double quoted strings, each separated by whitespace. It skips over anything else.
Parameters:
arg <String> String to be parsed for arguments
Returns: Array
Array of arguments found, each converted to its proper data type

_substitute

protected String _substitute ( template , extras )
Processes the given template and returns a string
Parameters:
template <String> (optional) Template to process. If missing, it will use the first static _TEMPLATE property found in the inheritance chain.
extras <Object> (optional) Hash of extra values to replace into the template, beyond MakeNode's processing codes.
Returns: String
Template with the placeholders replaced.


Copyright © 2011 Yahoo! Inc. All rights reserved.