source: Dev/branches/rest-dojo-ui/client/dijit/_WidgetsInTemplateMixin.js @ 274

Last change on this file since 274 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.0 KB
Line 
1define([
2        "dojo/_base/array", // array.forEach
3        "dojo/_base/declare", // declare
4        "dojo/parser", // parser.parse
5        "dijit/registry"        // registry.findWidgets
6], function(array, declare, parser, registry){
7
8        // module:
9        //              dijit/_WidgetsInTemplateMixin
10        // summary:
11        //              Mixin to supplement _TemplatedMixin when template contains widgets
12
13        return declare("dijit._WidgetsInTemplateMixin", null, {
14                // summary:
15                //              Mixin to supplement _TemplatedMixin when template contains widgets
16
17                // _earlyTemplatedStartup: Boolean
18                //              A fallback to preserve the 1.0 - 1.3 behavior of children in
19                //              templates having their startup called before the parent widget
20                //              fires postCreate. Defaults to 'false', causing child widgets to
21                //              have their .startup() called immediately before a parent widget
22                //              .startup(), but always after the parent .postCreate(). Set to
23                //              'true' to re-enable to previous, arguably broken, behavior.
24                _earlyTemplatedStartup: false,
25
26                // widgetsInTemplate: [protected] Boolean
27                //              Should we parse the template to find widgets that might be
28                //              declared in markup inside it?  (Remove for 2.0 and assume true)
29                widgetsInTemplate: true,
30
31                _beforeFillContent: function(){
32                        if(this.widgetsInTemplate){
33                                // Before copying over content, instantiate widgets in template
34                                var node = this.domNode;
35
36                                var cw = (this._startupWidgets = parser.parse(node, {
37                                        noStart: !this._earlyTemplatedStartup,
38                                        template: true,
39                                        inherited: {dir: this.dir, lang: this.lang, textDir: this.textDir},
40                                        propsThis: this,        // so data-dojo-props of widgets in the template can reference "this" to refer to me
41                                        scope: "dojo"   // even in multi-version mode templates use dojoType/data-dojo-type
42                                }));
43
44                                this._supportingWidgets = registry.findWidgets(node);
45
46                                this._attachTemplateNodes(cw, function(n,p){
47                                        return n[p];
48                                });
49                        }
50                },
51
52                startup: function(){
53                        array.forEach(this._startupWidgets, function(w){
54                                if(w && !w._started && w.startup){
55                                        w.startup();
56                                }
57                        });
58                        this.inherited(arguments);
59                }
60        });
61});
Note: See TracBrowser for help on using the repository browser.