root / trunk / web / dojo / dijit / Dialog.js @ 10
History | View | Annotate | Download (7.97 KB)
1 |
/*
|
---|---|
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.Dialog"]){ |
9 |
dojo._hasResource["dijit.Dialog"]=true; |
10 |
dojo.provide("dijit.Dialog");
|
11 |
dojo.require("dojo.dnd.move");
|
12 |
dojo.require("dojo.dnd.TimedMoveable");
|
13 |
dojo.require("dojo.fx");
|
14 |
dojo.require("dojo.window");
|
15 |
dojo.require("dijit._Widget");
|
16 |
dojo.require("dijit._Templated");
|
17 |
dojo.require("dijit._CssStateMixin");
|
18 |
dojo.require("dijit.form._FormMixin");
|
19 |
dojo.require("dijit._DialogMixin");
|
20 |
dojo.require("dijit.DialogUnderlay");
|
21 |
dojo.require("dijit.layout.ContentPane");
|
22 |
dojo.requireLocalization("dijit","common",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"); |
23 |
dojo.declare("dijit._DialogBase",[dijit._Templated,dijit.form._FormMixin,dijit._DialogMixin,dijit._CssStateMixin],{templateString:dojo.cache("dijit","templates/Dialog.html","<div class=\"dijitDialog\" tabindex=\"-1\" waiRole=\"dialog\" waiState=\"labelledby-${id}_title\">\n\t<div dojoAttachPoint=\"titleBar\" class=\"dijitDialogTitleBar\">\n\t<span dojoAttachPoint=\"titleNode\" class=\"dijitDialogTitle\" id=\"${id}_title\"></span>\n\t<span dojoAttachPoint=\"closeButtonNode\" class=\"dijitDialogCloseIcon\" dojoAttachEvent=\"onclick: onCancel\" title=\"${buttonCancel}\">\n\t\t<span dojoAttachPoint=\"closeText\" class=\"closeText\" title=\"${buttonCancel}\">x</span>\n\t</span>\n\t</div>\n\t\t<div dojoAttachPoint=\"containerNode\" class=\"dijitDialogPaneContent\"></div>\n</div>\n"),baseClass:"dijitDialog",cssStateNodes:{closeButtonNode:"dijitDialogCloseIcon"},attributeMap:dojo.delegate(dijit._Widget.prototype.attributeMap,{title:[{node:"titleNode",type:"innerHTML"},{node:"titleBar",type:"attribute"}],"aria-describedby":""}),open:false,duration:dijit.defaultDuration,refocus:true,autofocus:true,_firstFocusItem:null,_lastFocusItem:null,doLayout:false,draggable:true,"aria-describedby":"",postMixInProperties:function(){ |
24 |
var _1=dojo.i18n.getLocalization("dijit","common"); |
25 |
dojo.mixin(this,_1);
|
26 |
this.inherited(arguments); |
27 |
},postCreate:function(){ |
28 |
dojo.style(this.domNode,{display:"none",position:"absolute"}); |
29 |
dojo.body().appendChild(this.domNode);
|
30 |
this.inherited(arguments); |
31 |
this.connect(this,"onExecute","hide"); |
32 |
this.connect(this,"onCancel","hide"); |
33 |
this._modalconnects=[];
|
34 |
},onLoad:function(){ |
35 |
this._position();
|
36 |
if(this.autofocus){ |
37 |
this._getFocusItems(this.domNode); |
38 |
dijit.focus(this._firstFocusItem);
|
39 |
} |
40 |
this.inherited(arguments); |
41 |
},_endDrag:function(e){ |
42 |
if(e&&e.node&&e.node===this.domNode){ |
43 |
this._relativePosition=dojo.position(e.node);
|
44 |
} |
45 |
},_setup:function(){ |
46 |
var _2=this.domNode; |
47 |
if(this.titleBar&&this.draggable){ |
48 |
this._moveable=(dojo.isIE==6)?new dojo.dnd.TimedMoveable(_2,{handle:this.titleBar}):new dojo.dnd.Moveable(_2,{handle:this.titleBar,timeout:0}); |
49 |
dojo.subscribe("/dnd/move/stop",this,"_endDrag"); |
50 |
}else{
|
51 |
dojo.addClass(_2,"dijitDialogFixed");
|
52 |
} |
53 |
this.underlayAttrs={dialogId:this.id,"class":dojo.map(this["class"].split(/\s/),function(s){ |
54 |
return s+"_underlay"; |
55 |
}).join(" ")};
|
56 |
this._fadeIn=dojo.fadeIn({node:_2,duration:this.duration,beforeBegin:dojo.hitch(this,function(){ |
57 |
var _3=dijit._underlay;
|
58 |
if(!_3){
|
59 |
_3=dijit._underlay=new dijit.DialogUnderlay(this.underlayAttrs); |
60 |
}else{
|
61 |
_3.set(this.underlayAttrs);
|
62 |
} |
63 |
var ds=dijit._dialogStack,_4=948+ds.length*2; |
64 |
if(ds.length==1){ |
65 |
_3.show(); |
66 |
} |
67 |
dojo.style(dijit._underlay.domNode,"zIndex",_4);
|
68 |
dojo.style(this.domNode,"zIndex",_4+1); |
69 |
}),onEnd:dojo.hitch(this,function(){ |
70 |
if(this.autofocus){ |
71 |
this._getFocusItems(this.domNode); |
72 |
dijit.focus(this._firstFocusItem);
|
73 |
} |
74 |
})}); |
75 |
this._fadeOut=dojo.fadeOut({node:_2,duration:this.duration,onEnd:dojo.hitch(this,function(){ |
76 |
_2.style.display="none";
|
77 |
var ds=dijit._dialogStack;
|
78 |
if(ds.length==0){ |
79 |
dijit._underlay.hide(); |
80 |
}else{
|
81 |
dojo.style(dijit._underlay.domNode,"zIndex",948+ds.length*2); |
82 |
dijit._underlay.set(ds[ds.length-1].underlayAttrs);
|
83 |
} |
84 |
if(this.refocus){ |
85 |
var _5=this._savedFocus; |
86 |
if(ds.length>0){ |
87 |
var pd=ds[ds.length-1]; |
88 |
if(!dojo.isDescendant(_5.node,pd.domNode)){
|
89 |
pd._getFocusItems(pd.domNode); |
90 |
_5=pd._firstFocusItem; |
91 |
} |
92 |
} |
93 |
dijit.focus(_5); |
94 |
} |
95 |
})}); |
96 |
},uninitialize:function(){ |
97 |
var _6=false; |
98 |
if(this._fadeIn&&this._fadeIn.status()=="playing"){ |
99 |
_6=true;
|
100 |
this._fadeIn.stop();
|
101 |
} |
102 |
if(this._fadeOut&&this._fadeOut.status()=="playing"){ |
103 |
_6=true;
|
104 |
this._fadeOut.stop();
|
105 |
} |
106 |
if((this.open||_6)&&!dijit._underlay._destroyed){ |
107 |
dijit._underlay.hide(); |
108 |
} |
109 |
if(this._moveable){ |
110 |
this._moveable.destroy();
|
111 |
} |
112 |
this.inherited(arguments); |
113 |
},_size:function(){ |
114 |
this._checkIfSingleChild();
|
115 |
if(this._singleChild){ |
116 |
if(this._singleChildOriginalStyle){ |
117 |
this._singleChild.domNode.style.cssText=this._singleChildOriginalStyle; |
118 |
} |
119 |
delete this._singleChildOriginalStyle; |
120 |
}else{
|
121 |
dojo.style(this.containerNode,{width:"auto",height:"auto"}); |
122 |
} |
123 |
var mb=dojo.marginBox(this.domNode); |
124 |
var _7=dojo.window.getBox();
|
125 |
if(mb.w>=_7.w||mb.h>=_7.h){
|
126 |
var w=Math.min(mb.w,Math.floor(_7.w*0.75)),h=Math.min(mb.h,Math.floor(_7.h*0.75)); |
127 |
if(this._singleChild&&this._singleChild.resize){ |
128 |
this._singleChildOriginalStyle=this._singleChild.domNode.style.cssText; |
129 |
this._singleChild.resize({w:w,h:h}); |
130 |
}else{
|
131 |
dojo.style(this.containerNode,{width:w+"px",height:h+"px",overflow:"auto",position:"relative"}); |
132 |
} |
133 |
}else{
|
134 |
if(this._singleChild&&this._singleChild.resize){ |
135 |
this._singleChild.resize();
|
136 |
} |
137 |
} |
138 |
},_position:function(){ |
139 |
if(!dojo.hasClass(dojo.body(),"dojoMove")){ |
140 |
var _8=this.domNode,_9=dojo.window.getBox(),p=this._relativePosition,bb=p?null:dojo._getBorderBox(_8),l=Math.floor(_9.l+(p?p.x:(_9.w-bb.w)/2)),t=Math.floor(_9.t+(p?p.y:(_9.h-bb.h)/2)); |
141 |
dojo.style(_8,{left:l+"px",top:t+"px"}); |
142 |
} |
143 |
},_onKey:function(_a){ |
144 |
var ds=dijit._dialogStack;
|
145 |
if(ds[ds.length-1]!=this){ |
146 |
return;
|
147 |
} |
148 |
if(_a.charOrCode){
|
149 |
var dk=dojo.keys;
|
150 |
var _b=_a.target;
|
151 |
if(_a.charOrCode===dk.TAB){
|
152 |
this._getFocusItems(this.domNode); |
153 |
} |
154 |
var _c=(this._firstFocusItem==this._lastFocusItem); |
155 |
if(_b==this._firstFocusItem&&_a.shiftKey&&_a.charOrCode===dk.TAB){ |
156 |
if(!_c){
|
157 |
dijit.focus(this._lastFocusItem);
|
158 |
} |
159 |
dojo.stopEvent(_a); |
160 |
}else{
|
161 |
if(_b==this._lastFocusItem&&_a.charOrCode===dk.TAB&&!_a.shiftKey){ |
162 |
if(!_c){
|
163 |
dijit.focus(this._firstFocusItem);
|
164 |
} |
165 |
dojo.stopEvent(_a); |
166 |
}else{
|
167 |
while(_b){
|
168 |
if(_b==this.domNode||dojo.hasClass(_b,"dijitPopup")){ |
169 |
if(_a.charOrCode==dk.ESCAPE){
|
170 |
this.onCancel();
|
171 |
}else{
|
172 |
return;
|
173 |
} |
174 |
} |
175 |
_b=_b.parentNode; |
176 |
} |
177 |
if(_a.charOrCode!==dk.TAB){
|
178 |
dojo.stopEvent(_a); |
179 |
}else{
|
180 |
if(!dojo.isOpera){
|
181 |
try{
|
182 |
this._firstFocusItem.focus();
|
183 |
} |
184 |
catch(e){
|
185 |
} |
186 |
} |
187 |
} |
188 |
} |
189 |
} |
190 |
} |
191 |
},show:function(){ |
192 |
if(this.open){ |
193 |
return;
|
194 |
} |
195 |
if(!this._alreadyInitialized){ |
196 |
this._setup();
|
197 |
this._alreadyInitialized=true; |
198 |
} |
199 |
if(this._fadeOut.status()=="playing"){ |
200 |
this._fadeOut.stop();
|
201 |
} |
202 |
this._modalconnects.push(dojo.connect(window,"onscroll",this,"layout")); |
203 |
this._modalconnects.push(dojo.connect(window,"onresize",this,function(){ |
204 |
var _d=dojo.window.getBox();
|
205 |
if(!this._oldViewport||_d.h!=this._oldViewport.h||_d.w!=this._oldViewport.w){ |
206 |
this.layout();
|
207 |
this._oldViewport=_d;
|
208 |
} |
209 |
})); |
210 |
this._modalconnects.push(dojo.connect(dojo.doc.documentElement,"onkeypress",this,"_onKey")); |
211 |
dojo.style(this.domNode,{opacity:0,display:""}); |
212 |
this.open=true; |
213 |
this._onShow();
|
214 |
this._size();
|
215 |
this._position();
|
216 |
dijit._dialogStack.push(this);
|
217 |
this._fadeIn.play();
|
218 |
this._savedFocus=dijit.getFocus(this); |
219 |
},hide:function(){ |
220 |
var ds=dijit._dialogStack;
|
221 |
if(!this._alreadyInitialized||this!=ds[ds.length-1]){ |
222 |
return;
|
223 |
} |
224 |
if(this._fadeIn.status()=="playing"){ |
225 |
this._fadeIn.stop();
|
226 |
} |
227 |
ds.pop(); |
228 |
this._fadeOut.play();
|
229 |
if(this._scrollConnected){ |
230 |
this._scrollConnected=false; |
231 |
} |
232 |
dojo.forEach(this._modalconnects,dojo.disconnect);
|
233 |
this._modalconnects=[];
|
234 |
if(this._relativePosition){ |
235 |
delete this._relativePosition; |
236 |
} |
237 |
this.open=false; |
238 |
this.onHide();
|
239 |
},layout:function(){ |
240 |
if(this.domNode.style.display!="none"){ |
241 |
if(dijit._underlay){
|
242 |
dijit._underlay.layout(); |
243 |
} |
244 |
this._position();
|
245 |
} |
246 |
},destroy:function(){ |
247 |
dojo.forEach(this._modalconnects,dojo.disconnect);
|
248 |
if(this.refocus&&this.open){ |
249 |
setTimeout(dojo.hitch(dijit,"focus",this._savedFocus),25); |
250 |
} |
251 |
this.inherited(arguments); |
252 |
}}); |
253 |
dojo.declare("dijit.Dialog",[dijit.layout.ContentPane,dijit._DialogBase],{});
|
254 |
dijit._dialogStack=[]; |
255 |
dojo.require("dijit.TooltipDialog");
|
256 |
} |