Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dijit / layout / ContentPane.js @ 13

History | View | Annotate | Download (8.13 KB)

1 9 andrej.cim
/*
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
5
*/
6
7
8
if(!dojo._hasResource["dijit.layout.ContentPane"]){
9
dojo._hasResource["dijit.layout.ContentPane"]=true;
10
dojo.provide("dijit.layout.ContentPane");
11
dojo.require("dijit._Widget");
12
dojo.require("dijit._Contained");
13
dojo.require("dijit.layout._LayoutWidget");
14
dojo.require("dojo.parser");
15
dojo.require("dojo.string");
16
dojo.require("dojo.html");
17
dojo.requireLocalization("dijit","loading",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
18
dojo.declare("dijit.layout.ContentPane",dijit._Widget,{href:"",extractContent:false,parseOnLoad:true,preventCache:false,preload:false,refreshOnShow:false,loadingMessage:"<span class='dijitContentPaneLoading'>${loadingState}</span>",errorMessage:"<span class='dijitContentPaneError'>${errorState}</span>",isLoaded:false,baseClass:"dijitContentPane",doLayout:true,ioArgs:{},isContainer:true,isLayoutContainer:true,onLoadDeferred:null,attributeMap:dojo.delegate(dijit._Widget.prototype.attributeMap,{title:[]}),postMixInProperties:function(){
19
this.inherited(arguments);
20
var _1=dojo.i18n.getLocalization("dijit","loading",this.lang);
21
this.loadingMessage=dojo.string.substitute(this.loadingMessage,_1);
22
this.errorMessage=dojo.string.substitute(this.errorMessage,_1);
23
if(!this.href&&this.srcNodeRef&&this.srcNodeRef.innerHTML){
24
this.isLoaded=true;
25
}
26
},buildRendering:function(){
27
this.inherited(arguments);
28
if(!this.containerNode){
29
this.containerNode=this.domNode;
30
}
31
},postCreate:function(){
32
this.domNode.title="";
33
if(!dojo.attr(this.domNode,"role")){
34
dijit.setWaiRole(this.domNode,"group");
35
}
36
dojo.addClass(this.domNode,this.baseClass);
37
},startup:function(){
38
if(this._started){
39
return;
40
}
41
var _2=dijit._Contained.prototype.getParent.call(this);
42
this._childOfLayoutWidget=_2&&_2.isLayoutContainer;
43
this._needLayout=!this._childOfLayoutWidget;
44
if(this.isLoaded){
45
dojo.forEach(this.getChildren(),function(_3){
46
_3.startup();
47
});
48
}
49
if(this._isShown()||this.preload){
50
this._onShow();
51
}
52
this.inherited(arguments);
53
},_checkIfSingleChild:function(){
54
var _4=dojo.query("> *",this.containerNode).filter(function(_5){
55
return _5.tagName!=="SCRIPT";
56
}),_6=_4.filter(function(_7){
57
return dojo.hasAttr(_7,"dojoType")||dojo.hasAttr(_7,"widgetId");
58
}),_8=dojo.filter(_6.map(dijit.byNode),function(_9){
59
return _9&&_9.domNode&&_9.resize;
60
});
61
if(_4.length==_6.length&&_8.length==1){
62
this._singleChild=_8[0];
63
}else{
64
delete this._singleChild;
65
}
66
dojo.toggleClass(this.containerNode,this.baseClass+"SingleChild",!!this._singleChild);
67
},setHref:function(_a){
68
dojo.deprecated("dijit.layout.ContentPane.setHref() is deprecated. Use set('href', ...) instead.","","2.0");
69
return this.set("href",_a);
70
},_setHrefAttr:function(_b){
71
this.cancel();
72
this.onLoadDeferred=new dojo.Deferred(dojo.hitch(this,"cancel"));
73
this.href=_b;
74
if(this._created&&(this.preload||this._isShown())){
75
this._load();
76
}else{
77
this._hrefChanged=true;
78
}
79
return this.onLoadDeferred;
80
},setContent:function(_c){
81
dojo.deprecated("dijit.layout.ContentPane.setContent() is deprecated.  Use set('content', ...) instead.","","2.0");
82
this.set("content",_c);
83
},_setContentAttr:function(_d){
84
this.href="";
85
this.cancel();
86
this.onLoadDeferred=new dojo.Deferred(dojo.hitch(this,"cancel"));
87
this._setContent(_d||"");
88
this._isDownloaded=false;
89
return this.onLoadDeferred;
90
},_getContentAttr:function(){
91
return this.containerNode.innerHTML;
92
},cancel:function(){
93
if(this._xhrDfd&&(this._xhrDfd.fired==-1)){
94
this._xhrDfd.cancel();
95
}
96
delete this._xhrDfd;
97
this.onLoadDeferred=null;
98
},uninitialize:function(){
99
if(this._beingDestroyed){
100
this.cancel();
101
}
102
this.inherited(arguments);
103
},destroyRecursive:function(_e){
104
if(this._beingDestroyed){
105
return;
106
}
107
this.inherited(arguments);
108
},resize:function(_f,_10){
109
if(!this._wasShown){
110
this._onShow();
111
}
112
this._resizeCalled=true;
113
if(_f){
114
dojo.marginBox(this.domNode,_f);
115
}
116
var cn=this.containerNode;
117
if(cn===this.domNode){
118
var mb=_10||{};
119
dojo.mixin(mb,_f||{});
120
if(!("h" in mb)||!("w" in mb)){
121
mb=dojo.mixin(dojo.marginBox(cn),mb);
122
}
123
this._contentBox=dijit.layout.marginBox2contentBox(cn,mb);
124
}else{
125
this._contentBox=dojo.contentBox(cn);
126
}
127
this._layoutChildren();
128
},_isShown:function(){
129
if(this._childOfLayoutWidget){
130
if(this._resizeCalled&&"open" in this){
131
return this.open;
132
}
133
return this._resizeCalled;
134
}else{
135
if("open" in this){
136
return this.open;
137
}else{
138
var _11=this.domNode;
139
return (_11.style.display!="none")&&(_11.style.visibility!="hidden")&&!dojo.hasClass(_11,"dijitHidden");
140
}
141
}
142
},_onShow:function(){
143
if(this.href){
144
if(!this._xhrDfd&&(!this.isLoaded||this._hrefChanged||this.refreshOnShow)){
145
this.refresh();
146
}
147
}else{
148
if(!this._childOfLayoutWidget&&this._needLayout){
149
this._layoutChildren();
150
}
151
}
152
this.inherited(arguments);
153
this._wasShown=true;
154
},refresh:function(){
155
this.cancel();
156
this.onLoadDeferred=new dojo.Deferred(dojo.hitch(this,"cancel"));
157
this._load();
158
return this.onLoadDeferred;
159
},_load:function(){
160
this._setContent(this.onDownloadStart(),true);
161
var _12=this;
162
var _13={preventCache:(this.preventCache||this.refreshOnShow),url:this.href,handleAs:"text"};
163
if(dojo.isObject(this.ioArgs)){
164
dojo.mixin(_13,this.ioArgs);
165
}
166
var _14=(this._xhrDfd=(this.ioMethod||dojo.xhrGet)(_13));
167
_14.addCallback(function(_15){
168
try{
169
_12._isDownloaded=true;
170
_12._setContent(_15,false);
171
_12.onDownloadEnd();
172
}
173
catch(err){
174
_12._onError("Content",err);
175
}
176
delete _12._xhrDfd;
177
return _15;
178
});
179
_14.addErrback(function(err){
180
if(!_14.canceled){
181
_12._onError("Download",err);
182
}
183
delete _12._xhrDfd;
184
return err;
185
});
186
delete this._hrefChanged;
187
},_onLoadHandler:function(_16){
188
this.isLoaded=true;
189
try{
190
this.onLoadDeferred.callback(_16);
191
this.onLoad(_16);
192
}
193
catch(e){
194
console.error("Error "+this.widgetId+" running custom onLoad code: "+e.message);
195
}
196
},_onUnloadHandler:function(){
197
this.isLoaded=false;
198
try{
199
this.onUnload();
200
}
201
catch(e){
202
console.error("Error "+this.widgetId+" running custom onUnload code: "+e.message);
203
}
204
},destroyDescendants:function(){
205
if(this.isLoaded){
206
this._onUnloadHandler();
207
}
208
var _17=this._contentSetter;
209
dojo.forEach(this.getChildren(),function(_18){
210
if(_18.destroyRecursive){
211
_18.destroyRecursive();
212
}
213
});
214
if(_17){
215
dojo.forEach(_17.parseResults,function(_19){
216
if(_19.destroyRecursive&&_19.domNode&&_19.domNode.parentNode==dojo.body()){
217
_19.destroyRecursive();
218
}
219
});
220
delete _17.parseResults;
221
}
222
dojo.html._emptyNode(this.containerNode);
223
delete this._singleChild;
224
},_setContent:function(_1a,_1b){
225
this.destroyDescendants();
226
var _1c=this._contentSetter;
227
if(!(_1c&&_1c instanceof dojo.html._ContentSetter)){
228
_1c=this._contentSetter=new dojo.html._ContentSetter({node:this.containerNode,_onError:dojo.hitch(this,this._onError),onContentError:dojo.hitch(this,function(e){
229
var _1d=this.onContentError(e);
230
try{
231
this.containerNode.innerHTML=_1d;
232
}
233
catch(e){
234
console.error("Fatal "+this.id+" could not change content due to "+e.message,e);
235
}
236
})});
237
}
238
var _1e=dojo.mixin({cleanContent:this.cleanContent,extractContent:this.extractContent,parseContent:this.parseOnLoad,dir:this.dir,lang:this.lang},this._contentSetterParams||{});
239
dojo.mixin(_1c,_1e);
240
_1c.set((dojo.isObject(_1a)&&_1a.domNode)?_1a.domNode:_1a);
241
delete this._contentSetterParams;
242
if(!_1b){
243
dojo.forEach(this.getChildren(),function(_1f){
244
if(!this.parseOnLoad||_1f.getParent){
245
_1f.startup();
246
}
247
},this);
248
this._scheduleLayout();
249
this._onLoadHandler(_1a);
250
}
251
},_onError:function(_20,err,_21){
252
this.onLoadDeferred.errback(err);
253
var _22=this["on"+_20+"Error"].call(this,err);
254
if(_21){
255
console.error(_21,err);
256
}else{
257
if(_22){
258
this._setContent(_22,true);
259
}
260
}
261
},_scheduleLayout:function(){
262
if(this._isShown()){
263
this._layoutChildren();
264
}else{
265
this._needLayout=true;
266
}
267
},_layoutChildren:function(){
268
if(this.doLayout){
269
this._checkIfSingleChild();
270
}
271
if(this._singleChild&&this._singleChild.resize){
272
var cb=this._contentBox||dojo.contentBox(this.containerNode);
273
this._singleChild.resize({w:cb.w,h:cb.h});
274
}else{
275
dojo.forEach(this.getChildren(),function(_23){
276
if(_23.resize){
277
_23.resize();
278
}
279
});
280
}
281
delete this._needLayout;
282
},onLoad:function(_24){
283
},onUnload:function(){
284
},onDownloadStart:function(){
285
return this.loadingMessage;
286
},onContentError:function(_25){
287
},onDownloadError:function(_26){
288
return this.errorMessage;
289
},onDownloadEnd:function(){
290
}});
291
}