Revision of defineTag from Thu, 08/10/2017 - 09:46
Submitted by Leonard Daly on Wed, 08/09/2017 - 21:29
The defineTag method of xseen.Tag is one of two ways to define a new tag (see loadTags for the other). It creates an entry in the parsing table (overwriting a previous entry if it exists) so the XSeen parser knows how to deal with this tag when it is encountered when parsing the XSeen tree in the DOM data structure.
tagStructure = xseen.Tag.defineTag (name, init, fin, event, tick);
This can also be called with a JSON data structure with the above names as the field names all passed as the first argument.
- name
The name of the tag as a string. The string is converted to lower case before saving. The first character must be a letter. Legal characters are [a-z0-9-]. Note that 'x-' is prepended to all tag names - init
The method that is called when the opening tag (i.e., <name ...>) is found. [Actually, it is when element.name is name, but that is really a minor point.]. All tag setup operations should be performed in this method. - fin
The method that is called when the closing tag (i.e., </name>) is found. [Actually, it is when the parser is done parsing all of the children of name and just before returning to parsing the parent of name.] Initialization that depends on children of this tag is done in this method. If this tag cannot have children, then all of the work can be done in either of the init or fin method. - event
The methid that is called when this tag receives an event. This method receives two arguments - the HTML event data structure and the attribute name the event applies to. This method must know how to interpert the event and make the requested modifications to internal data. - tick
This method is called on each rendered frame. It receives two arguments - the current time, and the delta time since the last tick. Not all tags may be animated. If no animation can happen for this tag, then the null value should be used.
All methods are required; however, they need to be defined as null.
This method returns the tag data structure. It needs to be used to define the tag's attributes.