Error message

Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in _menu_load_objects() (line 579 of /home/drbiz/public/tools.realism.com/includes/menu.inc).

Revision of defineAttribute from Thu, 08/10/2017 - 11:23

The defineAttribute method of a defined tag adds an attribute to the tag parsing tables. The attribute includes the name and allowed data types and/or values of the attribute. This deviates a little from HTML5 in that although the attribute value is declared as a string (e.g., <tag attribute1="value1">), the XSeen parser enforces certain restrictions on the value. These restrictions ensure that the values are legal and within allowed range.

tagStructure = tagStructure.defineAttribute (name, dataType, defaultValue);

This can also be called with a JSON data structure with the above names as the field names all passed as the first argument. There are more options in the JSON data structure and that may be required for certain attributes. The details of the data structure are presented after the named arguments.

  • name
    This is the name of the attribute. It will be converted to lower case prior to storing in the strucuture. The first character must be a letter. Legal characters are [a-z0-9_-].
  • dataType
    The required data type of the attribute's value. Defined data types are:
    • string - this is the default and allows any set of characters in the HTML encoding
    • integer - must pass the JavaScript number check and have no fractional part
    • float - must pass the JavaScript number check
    • vec2 - a two-element vector of floats. The elements are space separated.
    • vec3 - a three-element vector of floats. The elements are space separated.
    • vec4 - a four-element vector of floats. The elements are space separated.
    • color - A color specified as one of the following
      • <name> - A valid HTML color name
      • #<24-bit hex> - A color specified as three douples of hex digits
      • #<base-10> - A color specified as an integer that converts to a 24-bit color
      • "r g b" - Where r, g, and b are either three floats from [0,1] or three integers from [0-255]. The elements are space separated.
    • id - A valid DOM id. It may or may not need to be defined at the time of parsing.
  • defaultValue
    This is the value to assign to the attribute if no value is present or the value incorrectly parses. This may be the empty string. It shall be the same data type as dataType.

Additional information available only through the JSON data structure

  • isAnimatable - a boolean indicating if this attribute can be animated
  • enumeration - a list of allowed values. If the provided attribute value is not one of these, the defaultValue will be used.
  • isCaseInsensitive - indicates that the value is case insensitive and will be converted to lower case prior to any parsing. This field only applies to attributes with dataType of 'string'.

The data type of each attribute is checked during parsing. Attribute values that fail the checked are replaced with the default value. Note that null passes all checks.

This method returns the tag data structure with the new attribute. This method may be daisy-chained with defineTag and defineAttribute to define the entire tag structure in one statement.