diff options
Diffstat (limited to 'js/dojo/dojox/mvc/_Container.js')
| -rw-r--r-- | js/dojo/dojox/mvc/_Container.js | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/js/dojo/dojox/mvc/_Container.js b/js/dojo/dojox/mvc/_Container.js new file mode 100644 index 0000000..330a92f --- /dev/null +++ b/js/dojo/dojox/mvc/_Container.js @@ -0,0 +1,108 @@ +//>>built +define("dojox/mvc/_Container", [ + "dojo/_base/declare", + "dojo/_base/lang", + "dijit/_WidgetBase", + "dojo/regexp" +], function(declare, lang, _WidgetBase, regexp){ + /*===== + declare = dojo.declare; + _WidgetBase = dijit._WidgetBase; + =====*/ + + return declare("dojox.mvc._Container", [_WidgetBase], { + + // stopParser: [private] Boolean + // Flag to parser to not try and parse widgets declared inside the container. + stopParser: true, + + // exprchar: Character + // Character to use for a substitution expression, for a substitution string like ${this.index} + exprchar: '$', + + // templateString: [private] String + // The template or content for this container. It is usually obtained from the + // body of the container and may be modified or repeated over a collection/array. + // In this simple implementation, attach points, attach events and WAI + // attributes are not supported in the template. + templateString : "", + + // _containedWidgets: [protected] dijit._Widget[] + // The array of contained widgets at any given point in time within this container. + _containedWidgets : [], + + ////////////////////// PROTECTED METHODS //////////////////////// + + _parser : null, + + _createBody: function(){ + // summary: + // Parse the body of this MVC container widget. + // description: + // The bodies of MVC containers may be model-bound views generated dynamically. + // Parse the body, start an contained widgets and attach template nodes for + // contained widgets as necessary. + // tags: + // protected + if(!this._parser){ + try{ + // returns dojo/parser if loaded, otherwise throws + this._parser = require("dojo/parser"); + }catch(e){ + // if here, dojo/parser not loaded + try{ + // returns dojox/mobile/parser if loaded, otherwise throws + this._parser = require("dojox/mobile/parser"); + }catch(e){ + // if here, both dojox/mobile/parser and dojo/parser are not loaded + console.error("Add explicit require(['dojo/parser']) or explicit require(['dojox/mobile/parser']), one of the parsers is required!"); + } + } + } + if(this._parser){ + this._containedWidgets = this._parser.parse(this.srcNodeRef,{ + template: true, + inherited: {dir: this.dir, lang: this.lang}, + propsThis: this, + scope: "dojo" + }); + } + }, + + _destroyBody: function(){ + // summary: + // Destroy the body of this MVC container widget. Also destroys any + // contained widgets. + // tags: + // protected + if(this._containedWidgets && this._containedWidgets.length > 0){ + for(var n = this._containedWidgets.length - 1; n > -1; n--){ + var w = this._containedWidgets[n]; + if(w && !w._destroyed && w.destroy){ + w.destroy(); + } + } + } + }, + + ////////////////////// PRIVATE METHODS //////////////////////// + + _exprRepl: function(tmpl){ + // summary: + // Does substitution of ${foo+bar} type expressions in template string. + // tags: + // private + var pThis = this, transform = function(value, key){ + if(!value){return "";} + var exp = value.substr(2); + exp = exp.substr(0, exp.length - 1); + with(pThis){return eval(exp);} + }; + transform = lang.hitch(this, transform); + return tmpl.replace(new RegExp(regexp.escapeString(this.exprchar)+"(\{.*?\})","g"), + function(match, key, format){ + return transform(match, key).toString(); + }); + } + }); +}); |
