1 if(!dojo._hasResource["dijit.Dialog"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit.Dialog"] = true;
3 dojo.provide("dijit.Dialog");
5 dojo.require("dojo.dnd.TimedMoveable");
6 dojo.require("dojo.fx");
8 dojo.require("dijit._Widget");
9 dojo.require("dijit._Templated");
10 dojo.require("dijit.layout.ContentPane");
11 dojo.require("dijit.form.Form");
12 dojo.requireLocalization("dijit", "common", null, "zh,pt,da,tr,ru,de,sv,ja,he,fi,nb,el,ar,ROOT,pt-pt,cs,fr,es,ko,nl,zh-tw,pl,it,hu");
15 "dijit.DialogUnderlay",
16 [dijit._Widget, dijit._Templated],
18 // summary: The component that grays out the screen behind the dialog
20 // Template has two divs; outer div is used for fade-in/fade-out, and also to hold background iframe.
21 // Inner div has opacity specified in CSS file.
22 templateString: "<div class='dijitDialogUnderlayWrapper' id='${id}_wrapper'><div class='dijitDialogUnderlay ${class}' id='${id}' dojoAttachPoint='node'></div></div>",
26 postCreate: function(){
27 // summary: Append the underlay to the body
28 dojo.body().appendChild(this.domNode);
29 this.bgIframe = new dijit.BackgroundIframe(this.domNode);
33 // summary: Sets the background to the size of the viewport
36 // Sets the background to the size of the viewport (rather than the size
37 // of the document) since we need to cover the whole browser window, even
38 // if the document is only a few lines long.
40 var viewport = dijit.getViewport();
41 var is = this.node.style,
42 os = this.domNode.style;
44 os.top = viewport.t + "px";
45 os.left = viewport.l + "px";
46 is.width = viewport.w + "px";
47 is.height = viewport.h + "px";
49 // process twice since the scroll bar may have been removed
50 // by the previous resizing
51 var viewport2 = dijit.getViewport();
52 if(viewport.w != viewport2.w){ is.width = viewport2.w + "px"; }
53 if(viewport.h != viewport2.h){ is.height = viewport2.h + "px"; }
57 // summary: Show the dialog underlay
58 this.domNode.style.display = "block";
60 if(this.bgIframe.iframe){
61 this.bgIframe.iframe.style.display = "block";
63 this._resizeHandler = this.connect(window, "onresize", "layout");
67 // summary: hides the dialog underlay
68 this.domNode.style.display = "none";
69 if(this.bgIframe.iframe){
70 this.bgIframe.iframe.style.display = "none";
72 this.disconnect(this._resizeHandler);
75 uninitialize: function(){
77 this.bgIframe.destroy();
84 dojo.declare("dijit._DialogMixin", null,
86 attributeMap: dijit._Widget.prototype.attributeMap,
89 // User defined function to do stuff when the user hits the submit button
90 execute: function(/*Object*/ formContents){},
93 // Callback when user has canceled dialog, to notify container
94 // (user shouldn't override)
95 onCancel: function(){},
97 // onExecute: Function
98 // Callback when user is about to execute dialog, to notify container
99 // (user shouldn't override)
100 onExecute: function(){},
102 _onSubmit: function(){
103 // summary: callback when user hits submit button
104 this.onExecute(); // notify container that we are about to execute
105 this.execute(this.getValues());
108 _getFocusItems: function(/*Node*/ dialogNode){
109 // find focusable Items each time a dialog is opened
110 var focusItem = dijit.getFirstInTabbingOrder(dialogNode);
111 this._firstFocusItem = focusItem ? focusItem : dialogNode;
112 focusItem = dijit.getLastInTabbingOrder(dialogNode);
113 this._lastFocusItem = focusItem ? focusItem : this._firstFocusItem;
114 if(dojo.isMoz && this._firstFocusItem.tagName.toLowerCase() == "input" && dojo.attr(this._firstFocusItem, "type").toLowerCase() == "file"){
115 //FF doesn't behave well when first element is input type=file, set first focusable to dialog container
116 dojo.attr(dialogNode, "tabindex", "0");
117 this._firstFocusItem = dialogNode;
125 [dijit.layout.ContentPane, dijit._Templated, dijit.form._FormMixin, dijit._DialogMixin],
127 // summary: A modal dialog Widget
130 // Pops up a modal dialog window, blocking access to the screen
131 // and also graying out the screen Dialog is extended from
132 // ContentPane so it supports all the same parameters (href, etc.)
135 // | <div dojoType="dijit.Dialog" href="test.html"></div>
138 // | <div id="test">test content</div>
140 // | var foo = new dijit.Dialog({ title: "test dialog" },dojo.byId("test"));
143 templateString: null,
144 templateString:"<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\">${title}</span>\n\t<span dojoAttachPoint=\"closeButtonNode\" class=\"dijitDialogCloseIcon\" dojoAttachEvent=\"onclick: onCancel\">\n\t\t<span dojoAttachPoint=\"closeText\" class=\"closeText\">x</span>\n\t</span>\n\t</div>\n\t\t<div dojoAttachPoint=\"containerNode\" class=\"dijitDialogPaneContent\"></div>\n</div>\n",
147 // is True or False depending on state of dialog
151 // The time in milliseconds it takes the dialog to fade in and out
155 // A Toggle to modify the default focus behavior of a Dialog, which
156 // is to re-focus the element which had focus before being opened.
157 // False will disable refocusing. Default: true
160 // _firstFocusItem: DomNode
161 // The pointer to the first focusable node in the dialog
162 _firstFocusItem:null,
164 // _lastFocusItem: DomNode
165 // The pointer to which node has focus prior to our dialog
169 // Don't change this parameter from the default value.
170 // This ContentPane parameter doesn't make sense for Dialog, since Dialog
171 // is never a child of a layout container, nor can you specify the size of
172 // Dialog in order to control the size of an inner widget.
175 attributeMap: dojo.mixin(dojo.clone(dijit._Widget.prototype.attributeMap),
176 {title: "titleBar"}),
178 postCreate: function(){
179 dojo.body().appendChild(this.domNode);
180 this.inherited(arguments);
181 var _nlsResources = dojo.i18n.getLocalization("dijit", "common");
182 if(this.closeButtonNode){
183 this.closeButtonNode.setAttribute("title", _nlsResources.buttonCancel);
186 this.closeText.setAttribute("title", _nlsResources.buttonCancel);
188 var s = this.domNode.style;
189 s.visibility = "hidden";
190 s.position = "absolute";
194 this.connect(this, "onExecute", "hide");
195 this.connect(this, "onCancel", "hide");
196 this._modalconnects = [];
200 // summary: when href is specified we need to reposition the dialog after the data is loaded
202 this.inherited(arguments);
207 // stuff we need to do before showing the Dialog for the first
208 // time (but we defer it until right beforehand, for
209 // performance reasons)
212 this._moveable = new dojo.dnd.TimedMoveable(this.domNode, { handle: this.titleBar, timeout: 0 });
215 this._underlay = new dijit.DialogUnderlay({
216 id: this.id+"_underlay",
217 "class": dojo.map(this["class"].split(/\s/), function(s){ return s+"_underlay"; }).join(" ")
220 var node = this.domNode;
221 this._fadeIn = dojo.fx.combine(
224 duration: this.duration
227 node: this._underlay.domNode,
228 duration: this.duration,
229 onBegin: dojo.hitch(this._underlay, "show")
234 this._fadeOut = dojo.fx.combine(
237 duration: this.duration,
239 node.style.visibility="hidden";
240 node.style.top = "-9999px";
244 node: this._underlay.domNode,
245 duration: this.duration,
246 onEnd: dojo.hitch(this._underlay, "hide")
252 uninitialize: function(){
253 if(this._fadeIn && this._fadeIn.status() == "playing"){
256 if(this._fadeOut && this._fadeOut.status() == "playing"){
257 this._fadeOut.stop();
260 this._underlay.destroy();
264 _position: function(){
265 // summary: position modal dialog in center of screen
267 if(dojo.hasClass(dojo.body(),"dojoMove")){ return; }
268 var viewport = dijit.getViewport();
269 var mb = dojo.marginBox(this.domNode);
271 var style = this.domNode.style;
272 style.left = Math.floor((viewport.l + (viewport.w - mb.w)/2)) + "px";
273 style.top = Math.floor((viewport.t + (viewport.h - mb.h)/2)) + "px";
276 _onKey: function(/*Event*/ evt){
277 // summary: handles the keyboard events for accessibility reasons
279 var node = evt.target;
280 if (evt.keyCode == dojo.keys.TAB){
281 this._getFocusItems(this.domNode);
283 var singleFocusItem = (this._firstFocusItem == this._lastFocusItem);
284 // see if we are shift-tabbing from first focusable item on dialog
285 if(node == this._firstFocusItem && evt.shiftKey && evt.keyCode == dojo.keys.TAB){
286 if(!singleFocusItem){
287 dijit.focus(this._lastFocusItem); // send focus to last item in dialog
290 }else if(node == this._lastFocusItem && evt.keyCode == dojo.keys.TAB && !evt.shiftKey){
291 if (!singleFocusItem){
292 dijit.focus(this._firstFocusItem); // send focus to first item in dialog
296 // see if the key is for the dialog
298 if(node == this.domNode){
299 if(evt.keyCode == dojo.keys.ESCAPE){
302 return; // just let it go
305 node = node.parentNode;
307 // this key is for the disabled document window
308 if(evt.keyCode != dojo.keys.TAB){ // allow tabbing into the dialog for a11y
310 // opera won't tab to a div
311 }else if(!dojo.isOpera){
313 this._firstFocusItem.focus();
314 }catch(e){ /*squelch*/ }
321 // summary: display the dialog
323 if(this.open){ return; }
325 // first time we show the dialog, there's some initialization stuff to do
326 if(!this._alreadyInitialized){
328 this._alreadyInitialized=true;
331 if(this._fadeOut.status() == "playing"){
332 this._fadeOut.stop();
335 this._modalconnects.push(dojo.connect(window, "onscroll", this, "layout"));
336 this._modalconnects.push(dojo.connect(dojo.doc.documentElement, "onkeypress", this, "_onKey"));
338 dojo.style(this.domNode, "opacity", 0);
339 this.domNode.style.visibility="";
341 this._loadCheck(); // lazy load trigger
347 this._savedFocus = dijit.getFocus(this);
349 // find focusable Items each time dialog is shown since if dialog contains a widget the
350 // first focusable items can change
351 this._getFocusItems(this.domNode);
353 // set timeout to allow the browser to render dialog
354 setTimeout(dojo.hitch(this, function(){
355 dijit.focus(this._firstFocusItem);
360 // summary: Hide the dialog
362 // if we haven't been initialized yet then we aren't showing and we can just return
363 if(!this._alreadyInitialized){
367 if(this._fadeIn.status() == "playing"){
370 this._fadeOut.play();
372 if (this._scrollConnected){
373 this._scrollConnected = false;
375 dojo.forEach(this._modalconnects, dojo.disconnect);
376 this._modalconnects = [];
378 this.connect(this._fadeOut,"onEnd",dojo.hitch(dijit,"focus",this._savedFocus));
384 // summary: position the Dialog and the underlay
385 if(this.domNode.style.visibility != "hidden"){
386 this._underlay.layout();
392 dojo.forEach(this._modalconnects, dojo.disconnect);
393 if(this.refocus && this.open){
394 var fo = this._savedFocus;
395 setTimeout(dojo.hitch(dijit,"focus",fo),25);
397 this.inherited(arguments);
403 "dijit.TooltipDialog",
404 [dijit.layout.ContentPane, dijit._Templated, dijit.form._FormMixin, dijit._DialogMixin],
407 // Pops up a dialog that appears like a Tooltip
410 // Description of tooltip dialog (required for a11Y)
414 // Don't change this parameter from the default value.
415 // This ContentPane parameter doesn't make sense for TooltipDialog, since TooltipDialog
416 // is never a child of a layout container, nor can you specify the size of
417 // TooltipDialog in order to control the size of an inner widget.
420 // _firstFocusItem: DomNode
421 // The pointer to the first focusable node in the dialog
422 _firstFocusItem:null,
424 // _lastFocusItem: DomNode
425 // The domNode that had focus before we took it.
426 _lastFocusItem: null,
428 templateString: null,
429 templateString:"<div class=\"dijitTooltipDialog\" waiRole=\"presentation\">\n\t<div class=\"dijitTooltipContainer\" waiRole=\"presentation\">\n\t\t<div class =\"dijitTooltipContents dijitTooltipFocusNode\" dojoAttachPoint=\"containerNode\" tabindex=\"-1\" waiRole=\"dialog\"></div>\n\t</div>\n\t<div class=\"dijitTooltipConnector\" waiRole=\"presenation\"></div>\n</div>\n",
431 postCreate: function(){
432 this.inherited(arguments);
433 this.connect(this.containerNode, "onkeypress", "_onKey");
434 this.containerNode.title = this.title;
437 orient: function(/*DomNode*/ node, /*String*/ aroundCorner, /*String*/ corner){
438 // summary: configure widget to be displayed in given position relative to the button
439 this.domNode.className="dijitTooltipDialog " +" dijitTooltipAB"+(corner.charAt(1)=='L'?"Left":"Right")+" dijitTooltip"+(corner.charAt(0)=='T' ? "Below" : "Above");
442 onOpen: function(/*Object*/ pos){
443 // summary: called when dialog is displayed
445 this._getFocusItems(this.containerNode);
446 this.orient(this.domNode,pos.aroundCorner, pos.corner);
447 this._loadCheck(); // lazy load trigger
448 dijit.focus(this._firstFocusItem);
451 _onKey: function(/*Event*/ evt){
452 // summary: keep keyboard focus in dialog; close dialog on escape key
453 var node = evt.target;
454 if (evt.keyCode == dojo.keys.TAB){
455 this._getFocusItems(this.containerNode);
457 var singleFocusItem = (this._firstFocusItem == this._lastFocusItem);
458 if(evt.keyCode == dojo.keys.ESCAPE){
460 }else if(node == this._firstFocusItem && evt.shiftKey && evt.keyCode == dojo.keys.TAB){
461 if(!singleFocusItem){
462 dijit.focus(this._lastFocusItem); // send focus to last item in dialog
465 }else if(node == this._lastFocusItem && evt.keyCode == dojo.keys.TAB && !evt.shiftKey){
466 if(!singleFocusItem){
467 dijit.focus(this._firstFocusItem); // send focus to first item in dialog
470 }else if(evt.keyCode == dojo.keys.TAB){
471 // we want the browser's default tab handling to move focus
472 // but we don't want the tab to propagate upwards
473 evt.stopPropagation();