]>
Commit | Line | Data |
---|---|---|
f0cfe83e AD |
1 | define("dijit/_WidgetsInTemplateMixin", [ |
2 | "dojo/_base/array", // array.forEach | |
3 | "dojo/_base/declare", // declare | |
4 | "dojo/parser" // parser.parse | |
5 | ], function(array, declare, parser){ | |
6 | ||
7 | // module: | |
8 | // dijit/_WidgetsInTemplateMixin | |
9 | ||
10 | return declare("dijit._WidgetsInTemplateMixin", null, { | |
11 | // summary: | |
12 | // Mixin to supplement _TemplatedMixin when template contains widgets | |
13 | ||
14 | // _earlyTemplatedStartup: Boolean | |
15 | // A fallback to preserve the 1.0 - 1.3 behavior of children in | |
16 | // templates having their startup called before the parent widget | |
17 | // fires postCreate. Defaults to 'false', causing child widgets to | |
18 | // have their .startup() called immediately before a parent widget | |
19 | // .startup(), but always after the parent .postCreate(). Set to | |
20 | // 'true' to re-enable to previous, arguably broken, behavior. | |
21 | _earlyTemplatedStartup: false, | |
22 | ||
23 | // widgetsInTemplate: [protected] Boolean | |
24 | // Should we parse the template to find widgets that might be | |
25 | // declared in markup inside it? (Remove for 2.0 and assume true) | |
26 | widgetsInTemplate: true, | |
27 | ||
28 | _beforeFillContent: function(){ | |
29 | if(this.widgetsInTemplate){ | |
30 | // Before copying over content, instantiate widgets in template | |
31 | var node = this.domNode; | |
32 | ||
33 | var cw = (this._startupWidgets = parser.parse(node, { | |
34 | noStart: !this._earlyTemplatedStartup, | |
35 | template: true, | |
36 | inherited: {dir: this.dir, lang: this.lang, textDir: this.textDir}, | |
37 | propsThis: this, // so data-dojo-props of widgets in the template can reference "this" to refer to me | |
38 | scope: "dojo" // even in multi-version mode templates use dojoType/data-dojo-type | |
39 | })); | |
40 | ||
41 | if(!cw.isFulfilled()){ | |
42 | throw new Error(this.declaredClass + ": parser returned unfilled promise (probably waiting for module auto-load), " + | |
43 | "unsupported by _WidgetsInTemplateMixin. Must pre-load all supporting widgets before instantiation."); | |
44 | } | |
45 | ||
46 | // _WidgetBase::destroy() will destroy any supporting widgets under this.domNode. | |
47 | // If we wanted to, we could call this.own() on anything in this._startupWidgets that was moved outside | |
48 | // of this.domNode (like Dialog, which is moved to <body>). | |
49 | ||
50 | this._attachTemplateNodes(cw, function(n,p){ | |
51 | return n[p]; | |
52 | }); | |
53 | } | |
54 | }, | |
55 | ||
56 | startup: function(){ | |
57 | array.forEach(this._startupWidgets, function(w){ | |
58 | if(w && !w._started && w.startup){ | |
59 | w.startup(); | |
60 | } | |
61 | }); | |
62 | this.inherited(arguments); | |
63 | } | |
64 | }); | |
65 | }); |