]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/_Templated.js
2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dijit._Templated"]){
9 dojo
._hasResource
["dijit._Templated"]=true;
10 dojo
.provide("dijit._Templated");
11 dojo
.require("dijit._Widget");
12 dojo
.require("dojo.string");
13 dojo
.require("dojo.parser");
14 dojo
.require("dojo.cache");
15 dojo
.declare("dijit._Templated",null,{templateString
:null,templatePath
:null,widgetsInTemplate
:false,_skipNodeCache
:false,_earlyTemplatedStartup
:false,constructor:function(){
16 this._attachPoints
=[];
17 },_stringRepl:function(_1
){
18 var _2
=this.declaredClass
,_3
=this;
19 return dojo
.string
.substitute(_1
,this,function(_4
,_5
){
20 if(_5
.charAt(0)=="!"){
21 _4
=dojo
.getObject(_5
.substr(1),false,_3
);
23 if(typeof _4
=="undefined"){
24 throw new Error(_2
+" template:"+_5
);
29 return _5
.charAt(0)=="!"?_4
:_4
.toString().replace(/"/g,""
;");
31 },buildRendering:function(){
32 var _6=dijit._Templated.getCachedTemplate(this.templatePath,this.templateString,this._skipNodeCache);
34 if(dojo.isString(_6)){
35 _7=dojo._toDom(this._stringRepl(_6));
37 throw new Error("Invalid template
: "+_6);
40 _7=_6.cloneNode(true);
43 this._attachTemplateNodes(_7);
44 if(this.widgetsInTemplate){
45 var _8=dojo.parser,_9,_a;
46 if(_8._query!="[dojoType
]"){
49 _8._query="[dojoType
]";
50 _8._attrName="dojoType
";
52 var cw=(this._startupWidgets=dojo.parser.parse(_7,{noStart:!this._earlyTemplatedStartup,inherited:{dir:this.dir,lang:this.lang}}));
57 this._supportingWidgets=dijit.findWidgets(_7);
58 this._attachTemplateNodes(cw,function(n,p){
62 this._fillContent(this.srcNodeRef);
63 },_fillContent:function(_b){
64 var _c=this.containerNode;
66 while(_b.hasChildNodes()){
67 _c.appendChild(_b.firstChild);
70 },_attachTemplateNodes:function(_d,_e){
72 return n.getAttribute(p);
74 var _f=dojo.isArray(_d)?_d:(_d.all||_d.getElementsByTagName("*"));
75 var x=dojo.isArray(_d)?0:-1;
76 for(;x<_f.length;x++){
77 var _10=(x==-1)?_d:_f[x];
78 if(this.widgetsInTemplate&&_e(_10,"dojoType
")){
81 var _11=_e(_10,"dojoAttachPoint
");
83 var _12,_13=_11.split(/\s*,\s*/);
84 while((_12=_13.shift())){
85 if(dojo.isArray(this[_12])){
90 this._attachPoints.push(_12);
93 var _14=_e(_10,"dojoAttachEvent
");
95 var _15,_16=_14.split(/\s*,\s*/);
97 while((_15=_16.shift())){
100 if(_15.indexOf(":")!=-1){
101 var _19=_15.split(":");
110 this.connect(_10,_15,_18);
114 var _1a=_e(_10,"waiRole
");
116 dijit.setWaiRole(_10,_1a);
118 var _1b=_e(_10,"waiState
");
120 dojo.forEach(_1b.split(/\s*,\s*/),function(_1c){
121 if(_1c.indexOf("-")!=-1){
122 var _1d=_1c.split("-");
123 dijit.setWaiState(_10,_1d[0],_1d[1]);
128 },startup:function(){
129 dojo.forEach(this._startupWidgets,function(w){
130 if(w&&!w._started&&w.startup){
134 this.inherited(arguments);
135 },destroyRendering:function(){
136 dojo.forEach(this._attachPoints,function(_1e){
139 this._attachPoints=[];
140 this.inherited(arguments);
142 dijit._Templated._templateCache={};
143 dijit._Templated.getCachedTemplate=function(_1f,_20,_21){
144 var _22=dijit._Templated._templateCache;
149 if(!_23.ownerDocument||_23.ownerDocument==dojo.doc){
158 _20=dojo.cache(_1f,{sanitize:true});
160 _20=dojo.string.trim(_20);
161 if(_21||_20.match(/\$\{([^\}]+)\}/g)){
162 return (_22[key]=_20);
164 var _24=dojo._toDom(_20);
166 throw new Error("Invalid template
: "+_20);
168 return (_22[key]=_24);
172 dojo.addOnWindowUnload(function(){
173 var _25=dijit._Templated._templateCache;
176 if(typeof _26=="object
"){
183 dojo.extend(dijit._Widget,{dojoAttachEvent:"",dojoAttachPoint:"",waiRole:"",waiState:""});