The Dom/Widget parsing package
See the dojo/parser reference documentation for more information.
Convert a <script type="dojo/method" args="a, b, c"> ... </script>
into a function
Parameter | Type | Description |
---|---|---|
script | DOMNode | The |
attrData | String | For HTML5 compliance, searches for attrData + "args" (typically "data-dojo-args") instead of "args" |
Takes array of objects representing nodes, and turns them into class instances and potentially calls a startup method to allow them to connect with any children.
Parameter | Type | Description |
---|---|---|
nodes | Array | Array of objects like { ctor: Function (may be null) types: ["dijit/form/Button", "acme/MyMixin"] (used if ctor not specified) node: DOMNode, scripts: [ ... ], // array of <script type="dojo/..."> children of node inherited: { ... } // settings inherited from ancestors like dir, theme, etc. } |
mixin | Object | An object that will be mixed in with each node in the array. Values in the mixin will override values in the node, if they exist. |
options | Object | An options object used to hold kwArgs for instantiation. See parse.options argument for details. |
returnPromise | Boolean | Return a Promise rather than the instance; supports asynchronous widget creation. |
Array of instances, or if returnPromise is true, a promise for array of instances that resolves when instances have finished initializing.
Helper for _scanAMD(). Takes a <script type=dojo/require>bar: "acme/bar", ...</script>
node,
calls require() to load the specified modules and (asynchronously) assign them to the specified global
variables, and returns a Promise for when that operation completes.
In the example above, it is effectively doing a require(["acme/bar", ...], function(a){ bar = a; }).
Parameter | Type | Description |
---|---|---|
script | DOMNode | |
options | Object |
Optional
|
Scans the DOM for any declarative requires and returns their values.
Looks for <script type=dojo/require>bar: "acme/bar", ...</script>
node, calls require() to load the
specified modules and (asynchronously) assign them to the specified global variables,
and returns a Promise for when those operations complete.
Parameter | Type | Description |
---|---|---|
root | DomNode | The node to base the scan from. |
options | Object |
Optional a kwArgs options object, see parse() for details |
Calls new ctor(params, node), where params is the hash of parameters specified on the node, excluding data-dojo-type and data-dojo-mixins. Does not call startup().
Parameter | Type | Description |
---|---|---|
ctor | Function | Widget constructor. |
node | DOMNode | This node will be replaced/attached to by the widget. It also specifies the arguments to pass to ctor. |
mixin | Object |
Optional Attributes in this object will be passed as parameters to ctor, overriding attributes specified on the node. |
options | Object |
Optional An options object used to hold kwArgs for instantiation. See parse.options argument for details. |
scripts | DomNode[] |
Optional Array of |
inherited | Object |
Optional Settings from dir=rtl or lang=... on a node above this node. Overrides options.inherited. |
Instance or Promise for the instance, if markupFactory() itself returned a promise
Takes array of nodes, and turns them into class instances and potentially calls a startup method to allow them to connect with any children.
Parameter | Type | Description |
---|---|---|
nodes | Array | Array of DOM nodes |
mixin | Object |
Optional An object that will be mixed in with each node in the array. Values in the mixin will override values in the node, if they exist. |
options | Object |
Optional An object used to hold kwArgs for instantiation. See parse.options argument for details. |
Array of instances.
Scan the DOM for class instances, and instantiate them.
Search specified node (or root node) recursively for class instances, and instantiate them. Searches for either data-dojo-type="Class" or dojoType="Class" where "Class" is a a fully qualified class name, like dijit/form/Button
Using data-dojo-type
:
Attributes using can be mixed into the parameters used to instantiate the
Class by using a data-dojo-props
attribute on the node being converted.
data-dojo-props
should be a string attribute to be converted from JSON.
Using dojoType
:
Attributes are read from the original domNode and converted to appropriate
types by looking up the Class prototype values. This is the default behavior
from Dojo 1.0 to Dojo 1.5. dojoType
support is deprecated, and will
go away in Dojo 2.0.
Parameter | Type | Description |
---|---|---|
rootNode | DomNode |
Optional A default starting root node from which to start the parsing. Can be
omitted, defaulting to the entire document. If omitted, the |
options | Object |
Optional A hash of options.
|
Returns a blended object that is an array of the instantiated objects, but also can include
a promise that is resolved with the instantiated objects. This is done for backwards
compatibility. If the parser auto-requires modules, it will always behave in a promise
fashion and parser.parse().then(function(instances){...})
should be used.
Parse all widgets on a page:
parser.parse();
Parse all classes within the node with id="foo"
parser.parse(dojo.byId('foo'));
Parse all classes in a page, but do not call .startup() on any child
parser.parse({ noStart: true })
Parse all classes in a node, but do not call .startup()
parser.parse(someNode, { noStart:true }); // or parser.parse({ noStart:true, rootNode: someNode });
Scan a DOM tree and return an array of objects representing the DOMNodes that need to be turned into widgets.
Search specified node (or document root node) recursively for class instances and return an array of objects that represent potential widgets to be instantiated. Searches for either data-dojo-type="MID" or dojoType="MID" where "MID" is a module ID like "dijit/form/Button" or a fully qualified Class name like "dijit/form/Button". If the MID is not currently available, scan will attempt to require() in the module.
See parser.parse() for details of markup.
Parameter | Type | Description |
---|---|---|
root | DomNode |
Optional A default starting root node from which to start the parsing. Can be
omitted, defaulting to the entire document. If omitted, the |
options | Object | a kwArgs options object, see parse() for details |
A promise that is resolved with the nodes that have been parsed.