| 1 |
define([ |
| 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 |
|
| 12 |
|
| 13 |
stopParser: true, |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
exprchar: '$', |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
templateString : "", |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
inlineTemplateString : "", |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
_containedWidgets : [], |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
_parser : null, |
| 38 |
|
| 39 |
_createBody: function(){ |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
if(!this._parser){ |
| 49 |
try{ |
| 50 |
|
| 51 |
this._parser = require("dojo/parser"); |
| 52 |
}catch(e){ |
| 53 |
|
| 54 |
try{ |
| 55 |
|
| 56 |
this._parser = require("dojox/mobile/parser"); |
| 57 |
}catch(e){ |
| 58 |
|
| 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 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 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 |
|
| 95 |
|
| 96 |
_exprRepl: function(tmpl){ |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 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 |
}); |