Widget modules are used as part of the RenderingMechanism to implement each type of renderable entity. As well as the widgets that are familiar to end users, the following primitives are also implemented as widgets:
All widgets inherit from a base widget class that is defined in $:/core/modules/widgets/widget.js.
The following widget properties are defined by the core. The lifecycle of a widget object is largely a matter of maintaining the consistency of these internal properties in the face of external state changes. Individual widgets usually add their own additional properties too.
Name | Description |
---|---|
parseTreeNode | Reference to the parse tree node corresponding to this widget |
wiki | Reference to the Wiki object associated with this widget |
variables | Hashmap of information about each widget variable (see below) |
parentWidget | Reference to the parent widget |
document | Reference to the document object associated with this widget. Usually either the browser global document variable or a reference to the FakeDomMechanism's $tw.fakeDocument |
attributes | Hashmap of information about each attribute attached to this widget (see below) |
children | Array of child widgets |
domNodes | For widgets that directly generate DOM nodes, an array of the generated nodes |
eventListeners | Array of event listener definitions |
The widget variables defined on a widget are stored in a hashmap of the variable name. The hashmap contains:
name
: name of variableparams
: array of parameters for macro definitions, each {name: "<name>", default: "<optionaldefault>"}
value
: string value of variableThe widget attributes associated with a widget are stored in a hashmap of the attribute name. The hashmap contains an object that describes the attribute value. Currently three attribute value types are supported:
{type: "string", value: "<value>"}
{type: "indirect", textReference: "<textref>"}
{type: "macro", value: {name: "<macroname>", params: [{name: "<paramname>", value: "<paramvalue>"}, ... ]}
The event listeners attached to a widget are stored as a hashmap by event type. Each value is a handler function that accepts a single event
parameter.
The individual methods defined by the widget object are documented in the source code of $:/core/modules/widgets/widget.js. Here we give an overview of the overall lifecycle, and how the methods fit together
initialise
methodwidgetClasses
methodrender
methodexecute
methodgetVariable
methodsubstituteVariableParameters
methodsubstituteVariableReferences
methodevaluateMacroModule
methodsetVariable
methodhasVariable
methodgetStateQualifier
methodcomputeAttributes
methodhasAttribute
methodgetAttribute
methodassignAttributes
methodmakeChildWidgets
methodmakeChildWidget
methodrenderChildren
methodaddEventListeners
methodaddEventListener
methoddispatchEvent
methodrefresh
methodrefreshSelf
methodrefreshChildren
methodfindNextSiblingDomNode
methodfindFirstDomNode
methodremoveChildDomNodes
method