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.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");
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
=[];
37 this._getFocusItems(this.domNode
);
38 dijit
.focus(this._firstFocusItem
);
40 this.inherited(arguments
);
41 },_endDrag:function(e
){
42 if(e
&&e
.node
&&e
.node
===this.domNode
){
43 this._relativePosition
=dojo
.position(e
.node
);
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");
51 dojo
.addClass(_2
,"dijitDialogFixed");
53 this.underlayAttrs
={dialogId
:this.id
,"class":dojo
.map(this["class"].split(/\s/),function(s
){
56 this._fadeIn
=dojo
.fadeIn({node
:_2
,duration
:this.duration
,beforeBegin
:dojo
.hitch(this,function(){
57 var _3
=dijit
._underlay
;
59 _3
=dijit
._underlay
=new dijit
.DialogUnderlay(this.underlayAttrs
);
61 _3
.set(this.underlayAttrs
);
63 var ds
=dijit
._dialogStack
,_4
=948+ds
.length
*2;
67 dojo
.style(dijit
._underlay
.domNode
,"zIndex",_4
);
68 dojo
.style(this.domNode
,"zIndex",_4
+1);
69 }),onEnd
:dojo
.hitch(this,function(){
71 this._getFocusItems(this.domNode
);
72 dijit
.focus(this._firstFocusItem
);
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
;
79 dijit
._underlay
.hide();
81 dojo
.style(dijit
._underlay
.domNode
,"zIndex",948+ds
.length
*2);
82 dijit
._underlay
.set(ds
[ds
.length
-1].underlayAttrs
);
85 var _5
=this._savedFocus
;
87 var pd
=ds
[ds
.length
-1];
88 if(!dojo
.isDescendant(_5
.node
,pd
.domNode
)){
89 pd
._getFocusItems(pd
.domNode
);
90 _5
=pd
._firstFocusItem
;
96 },uninitialize:function(){
98 if(this._fadeIn
&&this._fadeIn
.status()=="playing"){
102 if(this._fadeOut
&&this._fadeOut
.status()=="playing"){
104 this._fadeOut
.stop();
106 if((this.open
||_6
)&&!dijit
._underlay
._destroyed
){
107 dijit
._underlay
.hide();
110 this._moveable
.destroy();
112 this.inherited(arguments
);
114 this._checkIfSingleChild();
115 if(this._singleChild
){
116 if(this._singleChildOriginalStyle
){
117 this._singleChild
.domNode
.style
.cssText
=this._singleChildOriginalStyle
;
119 delete this._singleChildOriginalStyle
;
121 dojo
.style(this.containerNode
,{width
:"auto",height
:"auto"});
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
});
131 dojo
.style(this.containerNode
,{width
:w
+"px",height
:h
+"px",overflow
:"auto",position
:"relative"});
134 if(this._singleChild
&&this._singleChild
.resize
){
135 this._singleChild
.resize();
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"});
143 },_onKey:function(_a
){
144 var ds
=dijit
._dialogStack
;
145 if(ds
[ds
.length
-1]!=this){
151 if(_a
.charOrCode
===dk
.TAB
){
152 this._getFocusItems(this.domNode
);
154 var _c
=(this._firstFocusItem
==this._lastFocusItem
);
155 if(_b
==this._firstFocusItem
&&_a
.shiftKey
&&_a
.charOrCode
===dk
.TAB
){
157 dijit
.focus(this._lastFocusItem
);
161 if(_b
==this._lastFocusItem
&&_a
.charOrCode
===dk
.TAB
&&!_a
.shiftKey
){
163 dijit
.focus(this._firstFocusItem
);
168 if(_b
==this.domNode
||dojo
.hasClass(_b
,"dijitPopup")){
169 if(_a
.charOrCode
==dk
.ESCAPE
){
177 if(_a
.charOrCode
!==dk
.TAB
){
182 this._firstFocusItem
.focus();
195 if(!this._alreadyInitialized
){
197 this._alreadyInitialized
=true;
199 if(this._fadeOut
.status()=="playing"){
200 this._fadeOut
.stop();
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
){
207 this._oldViewport
=_d
;
210 this._modalconnects
.push(dojo
.connect(dojo
.doc
.documentElement
,"onkeypress",this,"_onKey"));
211 dojo
.style(this.domNode
,{opacity
:0,display
:""});
216 dijit
._dialogStack
.push(this);
218 this._savedFocus
=dijit
.getFocus(this);
220 var ds
=dijit
._dialogStack
;
221 if(!this._alreadyInitialized
||this!=ds
[ds
.length
-1]){
224 if(this._fadeIn
.status()=="playing"){
228 this._fadeOut
.play();
229 if(this._scrollConnected
){
230 this._scrollConnected
=false;
232 dojo
.forEach(this._modalconnects
,dojo
.disconnect
);
233 this._modalconnects
=[];
234 if(this._relativePosition
){
235 delete this._relativePosition
;
240 if(this.domNode
.style
.display
!="none"){
242 dijit
._underlay
.layout();
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);
251 this.inherited(arguments
);
253 dojo
.declare("dijit.Dialog",[dijit
.layout
.ContentPane
,dijit
._DialogBase
],{});
254 dijit
._dialogStack
=[];
255 dojo
.require("dijit.TooltipDialog");