source: Dev/trunk/src/client/dojox/mvc/_Container.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 3.7 KB
Line 
1define([
2        "dojo/_base/declare",
3        "dojo/_base/lang",
4        "dojo/when",
5        "dijit/_WidgetBase",
6        "dojo/regexp"
7], function(declare, lang, when, _WidgetBase, regexp){
8
9        return declare("dojox.mvc._Container", _WidgetBase, {
10       
11                // stopParser: [private] Boolean
12                //              Flag to parser to not try and parse widgets declared inside the container.
13                stopParser: true,
14
15                // exprchar:  Character
16                //              Character to use for a substitution expression, for a substitution string like ${this.index}
17                //              If this class is declared in a template HTML and exprchar is used in in-line template of this class, something other than `$` should be specified to avoid conflict with exprchar of outer-template.
18                exprchar: '$',
19       
20                // templateString: [private] String
21                //              The template or content for this container. It is usually obtained from the
22                //              body of the container and may be modified or repeated over a collection/array.
23                //              In this simple implementation, attach points, attach events and WAI
24                //              attributes are not supported in the template.
25                templateString : "",
26       
27                // inlineTemplateString: [private] String
28                //              Same as templateString. Used when this widget is mixed with a regular templated widget.
29                inlineTemplateString : "",
30
31                // _containedWidgets: [protected] dijit/_Widget[]
32                //              The array of contained widgets at any given point in time within this container.
33                _containedWidgets : [],
34       
35                ////////////////////// PROTECTED METHODS ////////////////////////
36       
37                _parser : null,
38               
39                _createBody: function(){
40                        // summary:
41                        //              Parse the body of this MVC container widget.
42                        // description:
43                        //              The bodies of MVC containers may be model-bound views generated dynamically.
44                        //              Parse the body, start an contained widgets and attach template nodes for
45                        //              contained widgets as necessary.
46                        // tags:
47                        //              protected
48                        if(!this._parser){
49                                try{
50                                        // returns dojo/parser if loaded, otherwise throws
51                                        this._parser = require("dojo/parser");
52                                }catch(e){
53                                        // if here, dojo/parser not loaded
54                                        try{
55                                                // returns dojox/mobile/parser if loaded, otherwise throws
56                                                this._parser = require("dojox/mobile/parser");
57                                        }catch(e){
58                                                // if here, both dojox/mobile/parser and dojo/parser are not loaded
59                                                console.error("Add explicit require(['dojo/parser']) or explicit require(['dojox/mobile/parser']), one of the parsers is required!");
60                                        }
61                                }
62                        }
63
64                        var _self = this;
65
66                        if(this._parser){
67                                return when(this._parser.parse(this.srcNodeRef,{
68                                        template: true,
69                                        inherited: {dir: this.dir, lang: this.lang},
70                                        propsThis: this,
71                                        scope: "dojo"
72                                }), function(widgets){
73                                        _self._containedWidgets = widgets;
74                                });
75                        }
76                },
77       
78                _destroyBody: function(){
79                        // summary:
80                        //              Destroy the body of this MVC container widget. Also destroys any
81                        //              contained widgets.
82                        // tags:
83                        //              protected
84                        if(this._containedWidgets && this._containedWidgets.length > 0){
85                                for(var n = this._containedWidgets.length - 1; n > -1; n--){
86                                        var w = this._containedWidgets[n];
87                                        if(w && !w._destroyed && w.destroy){
88                                                w.destroy();
89                                        }
90                                }
91                        }
92                },
93       
94                ////////////////////// PRIVATE METHODS ////////////////////////
95
96                _exprRepl: function(tmpl){
97                        // summary:
98                        //              Does substitution of ${foo+bar} type expressions in template string.
99                        // tags:
100                        //              private
101                        var pThis = this, transform = function(value, key){
102                                if(!value){return "";}
103                                var exp = value.substr(2);
104                                exp = exp.substr(0, exp.length - 1);
105                                with(pThis){return eval(exp);}
106                        };
107                        transform = lang.hitch(this, transform);
108                        return tmpl.replace(new RegExp(regexp.escapeString(this.exprchar)+"(\{.*?\})","g"),
109                                function(match, key, format){
110                                        return transform(match, key).toString();
111                                });
112                }
113        });
114});
Note: See TracBrowser for help on using the repository browser.