| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/lang", |
| 4 |
"dojo/dom", |
| 5 |
"dijit/_WidgetBase", |
| 6 |
"dojo/regexp" |
| 7 |
], function(declare, lang, dom, _WidgetBase, regexp){ |
| 8 |
|
| 9 |
return declare("dojox.mvc.Output", _WidgetBase, { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
exprchar: '$', |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
templateString : "", |
| 38 |
|
| 39 |
postscript: function(params, srcNodeRef){ |
| 40 |
|
| 41 |
|
| 42 |
this.srcNodeRef = dom.byId(srcNodeRef); |
| 43 |
if(this.srcNodeRef){ |
| 44 |
this.templateString = this.srcNodeRef.innerHTML; |
| 45 |
this.srcNodeRef.innerHTML = ""; |
| 46 |
} |
| 47 |
this.inherited(arguments); |
| 48 |
}, |
| 49 |
|
| 50 |
set: function(name, value){ |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
this.inherited(arguments); |
| 58 |
if(name === "value"){ |
| 59 |
this._output(); |
| 60 |
} |
| 61 |
}, |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
_updateBinding: function(name, old, current){ |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
this.inherited(arguments); |
| 71 |
this._output(); |
| 72 |
}, |
| 73 |
|
| 74 |
_output: function(){ |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
var outputNode = this.srcNodeRef || this.domNode; |
| 80 |
outputNode.innerHTML = this.templateString ? this._exprRepl(this.templateString) : this.value; |
| 81 |
}, |
| 82 |
|
| 83 |
_exprRepl: function(tmpl){ |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
var pThis = this, transform = function(value, key){ |
| 89 |
if(!value){return "";} |
| 90 |
var exp = value.substr(2); |
| 91 |
exp = exp.substr(0, exp.length - 1); |
| 92 |
with(pThis){ |
| 93 |
var val = eval(exp); |
| 94 |
return (val || val == 0 ? val : ""); |
| 95 |
} |
| 96 |
}; |
| 97 |
transform = lang.hitch(this, transform); |
| 98 |
return tmpl.replace(new RegExp(regexp.escapeString(this.exprchar)+"(\{.*?\})","g"), |
| 99 |
function(match, key, format){ |
| 100 |
return transform(match, key).toString(); |
| 101 |
}); |
| 102 |
} |
| 103 |
}); |
| 104 |
}); |