Debian Codegraph @

dijit/Dialog.js

raw symbols SCIP
1 define([
2 "require",
3 "dojo/_base/array", // array.forEach array.indexOf array.map
4 "dojo/aspect",
5 "dojo/_base/declare", // declare
6 "dojo/Deferred", // Deferred
7 "dojo/dom", // dom.isDescendant
8 "dojo/dom-class", // domClass.add domClass.contains
9 "dojo/dom-geometry", // domGeometry.position
10 "dojo/dom-style", // domStyle.set
11 "dojo/_base/fx", // fx.fadeIn fx.fadeOut
12 "dojo/i18n", // i18n.getLocalization
13 "dojo/keys",
14 "dojo/_base/lang", // lang.mixin lang.hitch
15 "dojo/on",
16 "dojo/ready",
17 "dojo/sniff", // has("ie") has("opera") has("dijit-legacy-requires")
18 "dojo/touch",
19 "dojo/window", // winUtils.getBox, winUtils.get
20 "dojo/dnd/Moveable", // Moveable
21 "dojo/dnd/TimedMoveable", // TimedMoveable
22 "./focus",
23 "./_base/manager", // manager.defaultDuration
24 "./_Widget",
25 "./_TemplatedMixin",
26 "./_CssStateMixin",
27 "./form/_FormMixin",
28 "./_DialogMixin",
29 "./DialogUnderlay",
30 "./layout/ContentPane",
31 "./layout/utils",
32 "dojo/text!./templates/Dialog.html",
33 "./a11yclick", // template uses ondijitclick
34 "dojo/i18n!./nls/common"
35 ], function(require, array, aspect, declare, Deferred,
36 dom, domClass, domGeometry, domStyle, fx, i18n, keys, lang, on, ready, has, touch, winUtils,
37 Moveable, TimedMoveable, focus, manager, _Widget, _TemplatedMixin, _CssStateMixin, _FormMixin, _DialogMixin,
38 DialogUnderlay, ContentPane, utils, template){
39
40 // module:
41 // dijit/Dialog
42
43 var resolvedDeferred = new Deferred();
44 resolvedDeferred.resolve(true);
45
46 function nop(){}
47
48 var _DialogBase = declare("dijit._DialogBase" + (has("dojo-bidi") ? "_NoBidi" : ""), [_TemplatedMixin, _FormMixin, _DialogMixin, _CssStateMixin], {
49 templateString: template,
50
51 baseClass: "dijitDialog",
52
53 cssStateNodes: {
54 closeButtonNode: "dijitDialogCloseIcon"
55 },
56
57 // Map widget attributes to DOMNode attributes.
58 _setTitleAttr: { node: "titleNode", type: "innerHTML" },
59
60 // open: [readonly] Boolean
61 // True if Dialog is currently displayed on screen.
62 open: false,
63
64 // duration: Integer
65 // The time in milliseconds it takes the dialog to fade in and out
66 duration: manager.defaultDuration,
67
68 // refocus: Boolean
69 // A Toggle to modify the default focus behavior of a Dialog, which
70 // is to re-focus the element which had focus before being opened.
71 // False will disable refocusing. Default: true
72 refocus: true,
73
74 // autofocus: Boolean
75 // A Toggle to modify the default focus behavior of a Dialog, which
76 // is to focus on the first dialog element after opening the dialog.
77 // False will disable autofocusing. Default: true
78 autofocus: true,
79
80 // _firstFocusItem: [private readonly] DomNode
81 // The pointer to the first focusable node in the dialog.
82 // Set by `dijit/_DialogMixin._getFocusItems()`.
83 _firstFocusItem: null,
84
85 // _lastFocusItem: [private readonly] DomNode
86 // The pointer to which node has focus prior to our dialog.
87 // Set by `dijit/_DialogMixin._getFocusItems()`.
88 _lastFocusItem: null,
89
90 // draggable: Boolean
91 // Toggles the movable aspect of the Dialog. If true, Dialog
92 // can be dragged by it's title. If false it will remain centered
93 // in the viewport.
94 draggable: true,
95 _setDraggableAttr: function(/*Boolean*/ val){
96 // Avoid _WidgetBase behavior of copying draggable attribute to this.domNode,
97 // as that prevents text select on modern browsers (#14452)
98 this._set("draggable", val);
99 },
100
101 // maxRatio: Number
102 // Maximum size to allow the dialog to expand to, relative to viewport size
103 maxRatio: 0.9,
104
105 // closable: Boolean
106 // Dialog show [x] icon to close itself, and ESC key will close the dialog.
107 closable: true,
108 _setClosableAttr: function(val){
109 this.closeButtonNode.style.display = val ? "" : "none";
110 this._set("closable", val);
111 },
112
113 postMixInProperties: function(){
114 var _nlsResources = i18n.getLocalization("dijit", "common");
115 lang.mixin(this, _nlsResources);
116 this.inherited(arguments);
117 },
118
119 postCreate: function(){
120 domStyle.set(this.domNode, {
121 display: "none",
122 position: "absolute"
123 });
124 this.ownerDocumentBody.appendChild(this.domNode);
125
126 this.inherited(arguments);
127
128 aspect.after(this, "onExecute", lang.hitch(this, "hide"), true);
129 aspect.after(this, "onCancel", lang.hitch(this, "hide"), true);
130 on(this.closeButtonNode, touch.press, function(e){
131 e.stopPropagation();
132 });
133
134 this._modalconnects = [];
135 },
136
137 onLoad: function(){
138 // summary:
139 // Called when data has been loaded from an href.
140 // Unlike most other callbacks, this function can be connected to (via `dojo.connect`)
141 // but should *not* be overridden.
142 // tags:
143 // callback
144
145 // when href is specified we need to reposition the dialog after the data is loaded
146 // and find the focusable elements
147 this.resize();
148 this._position();
149
150 if(this.autofocus && DialogLevelManager.isTop(this)){
151 this._getFocusItems();
152 focus.focus(this._firstFocusItem);
153 }
154
155 this.inherited(arguments);
156 },
157
158 focus: function(){
159 this._getFocusItems();
160 focus.focus(this._firstFocusItem);
161 },
162
163 _endDrag: function(){
164 // summary:
165 // Called after dragging the Dialog. Saves the position of the dialog in the viewport,
166 // and also adjust position to be fully within the viewport, so user doesn't lose access to handle
167 var nodePosition = domGeometry.position(this.domNode),
168 viewport = winUtils.getBox(this.ownerDocument);
169 nodePosition.y = Math.min(Math.max(nodePosition.y, 0), (viewport.h - nodePosition.h));
170 nodePosition.x = Math.min(Math.max(nodePosition.x, 0), (viewport.w - nodePosition.w));
171 this._relativePosition = nodePosition;
172 this._position();
173 },
174
175 _setup: function(){
176 // summary:
177 // Stuff we need to do before showing the Dialog for the first
178 // time (but we defer it until right beforehand, for
179 // performance reasons).
180 // tags:
181 // private
182
183 var node = this.domNode;
184
185 if(this.titleBar && this.draggable){
186 this._moveable = new ((has("ie") == 6) ? TimedMoveable // prevent overload, see #5285
187 : Moveable)(node, { handle: this.titleBar });
188 aspect.after(this._moveable, "onMoveStop", lang.hitch(this, "_endDrag"), true);
189 }else{
190 domClass.add(node, "dijitDialogFixed");
191 }
192
193 this.underlayAttrs = {
194 dialogId: this.id,
195 "class": array.map(this["class"].split(/\s/),function(s){
196 return s + "_underlay";
197 }).join(" "),
198 _onKeyDown: lang.hitch(this, "_onKey"),
199 ownerDocument: this.ownerDocument
200 };
201 },
202
203 _size: function(){
204 // TODO: remove for 2.0
205 this.resize();
206 },
207
208 _position: function(){
209 // summary:
210 // Position the dialog in the viewport. If no relative offset
211 // in the viewport has been determined (by dragging, for instance),
212 // center the dialog. Otherwise, use the Dialog's stored relative offset,
213 // clipped to fit inside the viewport (which may have been shrunk).
214 // Finally, adjust position according to viewport's scroll.
215
216 if(!domClass.contains(this.ownerDocumentBody, "dojoMove")){ // don't do anything if called during auto-scroll
217 var node = this.domNode,
218 viewport = winUtils.getBox(this.ownerDocument),
219 p = this._relativePosition,
220 bb = domGeometry.position(node),
221 l = Math.floor(viewport.l + (p ? Math.min(p.x, viewport.w - bb.w) : (viewport.w - bb.w) / 2)),
222 t = Math.floor(viewport.t + (p ? Math.min(p.y, viewport.h - bb.h) : (viewport.h - bb.h) / 2));
223
224 domStyle.set(node, {
225 left: l + "px",
226 top: t + "px"
227 });
228 }
229 },
230
231 _onKey: function(/*Event*/ evt){
232 // summary:
233 // Handles the keyboard events for accessibility reasons
234 // tags:
235 // private
236
237 if(evt.keyCode == keys.TAB){
238 this._getFocusItems();
239 var node = evt.target;
240 if(this._firstFocusItem == this._lastFocusItem){
241 // don't move focus anywhere, but don't allow browser to move focus off of dialog either
242 evt.stopPropagation();
243 evt.preventDefault();
244 }else if(node == this._firstFocusItem && evt.shiftKey){
245 // if we are shift-tabbing from first focusable item in dialog, send focus to last item
246 focus.focus(this._lastFocusItem);
247 evt.stopPropagation();
248 evt.preventDefault();
249 }else if(node == this._lastFocusItem && !evt.shiftKey){
250 // if we are tabbing from last focusable item in dialog, send focus to first item
251 focus.focus(this._firstFocusItem);
252 evt.stopPropagation();
253 evt.preventDefault();
254 }
255 }else if(this.closable && evt.keyCode == keys.ESCAPE){
256 this.onCancel();
257 evt.stopPropagation();
258 evt.preventDefault();
259 }
260 },
261
262 show: function(){
263 // summary:
264 // Display the dialog
265 // returns: dojo/promise/Promise
266 // Promise object that resolves when the display animation is complete
267
268 if(this.open){
269 return resolvedDeferred.promise;
270 }
271
272 if(!this._started){
273 this.startup();
274 }
275
276 // first time we show the dialog, there's some initialization stuff to do
277 if(!this._alreadyInitialized){
278 this._setup();
279 this._alreadyInitialized = true;
280 }
281
282 if(this._fadeOutDeferred){
283 // There's a hide() operation in progress, so cancel it, but still call DialogLevelManager.hide()
284 // as though the hide() completed, in preparation for the DialogLevelManager.show() call below.
285 this._fadeOutDeferred.cancel();
286 DialogLevelManager.hide(this);
287 }
288
289 // Recenter Dialog if user scrolls browser. Connecting to document doesn't work on IE, need to use window.
290 // Be sure that event object doesn't get passed to resize() method, because it's expecting an optional
291 // {w: ..., h:...} arg.
292 var win = winUtils.get(this.ownerDocument);
293 this._modalconnects.push(on(win, "scroll", lang.hitch(this, "resize", null)));
294
295 this._modalconnects.push(on(this.domNode, "keydown", lang.hitch(this, "_onKey")));
296
297 domStyle.set(this.domNode, {
298 opacity: 0,
299 display: ""
300 });
301
302 this._set("open", true);
303 this._onShow(); // lazy load trigger
304
305 this.resize();
306 this._position();
307
308 // fade-in Animation object, setup below
309 var fadeIn;
310
311 this._fadeInDeferred = new Deferred(lang.hitch(this, function(){
312 fadeIn.stop();
313 delete this._fadeInDeferred;
314 }));
315 this._fadeInDeferred.then(undefined, nop); // avoid spurious CancelError message to console
316
317 // If delay is 0, code below will delete this._fadeInDeferred instantly, so grab promise while we can.
318 var promise = this._fadeInDeferred.promise;
319
320 fadeIn = fx.fadeIn({
321 node: this.domNode,
322 duration: this.duration,
323 beforeBegin: lang.hitch(this, function(){
324 DialogLevelManager.show(this, this.underlayAttrs);
325 }),
326 onEnd: lang.hitch(this, function(){
327 if(this.autofocus && DialogLevelManager.isTop(this)){
328 // find focusable items each time dialog is shown since if dialog contains a widget the
329 // first focusable items can change
330 this._getFocusItems();
331 focus.focus(this._firstFocusItem);
332 }
333 this._fadeInDeferred.resolve(true);
334 delete this._fadeInDeferred;
335 })
336 }).play();
337
338 return promise;
339 },
340
341 hide: function(){
342 // summary:
343 // Hide the dialog
344 // returns: dojo/promise/Promise
345 // Promise object that resolves when the display animation is complete
346
347 // If we haven't been initialized yet then we aren't showing and we can just return.
348 // Likewise if we are already hidden, or are currently fading out.
349 if(!this._alreadyInitialized || !this.open){
350 return resolvedDeferred.promise;
351 }
352 if(this._fadeInDeferred){
353 this._fadeInDeferred.cancel();
354 }
355
356 // fade-in Animation object, setup below
357 var fadeOut;
358
359 this._fadeOutDeferred = new Deferred(lang.hitch(this, function(){
360 fadeOut.stop();
361 delete this._fadeOutDeferred;
362 }));
363 this._fadeOutDeferred.then(undefined, nop); // avoid spurious CancelError message to console
364
365 // fire onHide when the promise resolves.
366 this._fadeOutDeferred.then(lang.hitch(this, 'onHide'));
367
368 // If delay is 0, code below will delete this._fadeOutDeferred instantly, so grab promise while we can.
369 var promise = this._fadeOutDeferred.promise;
370
371 fadeOut = fx.fadeOut({
372 node: this.domNode,
373 duration: this.duration,
374 onEnd: lang.hitch(this, function(){
375 this.domNode.style.display = "none";
376 DialogLevelManager.hide(this);
377 this._fadeOutDeferred.resolve(true);
378 delete this._fadeOutDeferred;
379 })
380 }).play();
381
382 if(this._scrollConnected){
383 this._scrollConnected = false;
384 }
385 var h;
386 while(h = this._modalconnects.pop()){
387 h.remove();
388 }
389
390 if(this._relativePosition){
391 delete this._relativePosition;
392 }
393 this._set("open", false);
394
395 return promise;
396 },
397
398 resize: function(dim){
399 // summary:
400 // Called with no argument when viewport scrolled or viewport size changed. Adjusts Dialog as
401 // necessary to keep it visible.
402 //
403 // Can also be called with an argument (by dojox/layout/ResizeHandle etc.) to explicitly set the
404 // size of the dialog.
405 // dim: Object?
406 // Optional dimension object like {w: 200, h: 300}
407
408 if(this.domNode.style.display != "none"){
409
410 this._checkIfSingleChild();
411
412 if(!dim){
413 if(this._shrunk){
414 // If we earlier shrunk the dialog to fit in the viewport, reset it to its natural size
415 if(this._singleChild){
416 if(typeof this._singleChildOriginalStyle != "undefined"){
417 this._singleChild.domNode.style.cssText = this._singleChildOriginalStyle;
418 delete this._singleChildOriginalStyle;
419 }
420 }
421 array.forEach([this.domNode, this.containerNode, this.titleBar, this.actionBarNode], function(node){
422 if(node){ // because titleBar may not be defined
423 domStyle.set(node, {
424 position: "static",
425 width: "auto",
426 height: "auto"
427 });
428 }
429 });
430 this.domNode.style.position = "absolute";
431 }
432
433 // If necessary, shrink Dialog to fit in viewport and have some space around it
434 // to indicate that it's a popup. This will also compensate for possible scrollbars on viewport.
435 var viewport = winUtils.getBox(this.ownerDocument);
436 viewport.w *= this.maxRatio;
437 viewport.h *= this.maxRatio;
438
439 var bb = domGeometry.position(this.domNode);
440 this._shrunk = false;
441 // First check and limit width, because limiting the width may increase the height due to word wrapping.
442 if(bb.w >= viewport.w){
443 dim = {
444 w: viewport.w
445 };
446 domGeometry.setMarginBox(this.domNode, dim);
447 bb = domGeometry.position(this.domNode);
448 this._shrunk = true;
449 }
450 // Now check and limit the height
451 if(bb.h >= viewport.h){
452 if(!dim){
453 dim = {
454 w: bb.w
455 };
456 }
457 dim.h = viewport.h;
458 this._shrunk = true;
459 }
460 if(dim){
461 if(!dim.w){
462 dim.w = bb.w;
463 }
464 if(!dim.h){
465 dim.h = bb.h;
466 }
467 }
468 }
469
470 // Code to run if user has requested an explicit size, or the shrinking code above set an implicit size
471 if(dim){
472 // Set this.domNode to specified size
473 domGeometry.setMarginBox(this.domNode, dim);
474
475 // And then size this.containerNode
476 var layoutNodes = [];
477 if(this.titleBar){
478 layoutNodes.push({domNode: this.titleBar, region: "top"});
479 }
480 if(this.actionBarNode){
481 layoutNodes.push({domNode: this.actionBarNode, region: "bottom"});
482 }
483 var centerSize = {domNode: this.containerNode, region: "center"};
484 layoutNodes.push(centerSize);
485
486 var contentDim = utils.marginBox2contentBox(this.domNode, dim);
487 utils.layoutChildren(this.domNode, contentDim, layoutNodes);
488
489 // And then if this.containerNode has a single layout widget child, size it too.
490 // Otherwise, make this.containerNode show a scrollbar if it's overflowing.
491 if(this._singleChild){
492 var cb = utils.marginBox2contentBox(this.containerNode, centerSize);
493 // note: if containerNode has padding singleChildSize will have l and t set,
494 // but don't pass them to resize() or it will doubly-offset the child
495 this._singleChild.resize({w: cb.w, h: cb.h});
496 // TODO: save original size for restoring it on another show()?
497 }else{
498 this.containerNode.style.overflow = "auto";
499 this._layoutChildren(); // send resize() event to all child widgets
500 }
501 }else{
502 this._layoutChildren(); // send resize() event to all child widgets
503 }
504
505 if(!has("touch") && !dim){
506 // If the user has scrolled the viewport then reposition the Dialog. But don't do it for touch
507 // devices, because it will counteract when a keyboard pops up and then the browser auto-scrolls
508 // the focused node into view.
509 this._position();
510 }
511 }
512 },
513
514 _layoutChildren: function(){
515 // Override _ContentPaneResizeMixin._layoutChildren because even when there's just a single layout child
516 // widget, sometimes we don't want to size it explicitly (i.e. to pass a dim argument to resize())
517
518 array.forEach(this.getChildren(), function(widget){
519 if(widget.resize){
520 widget.resize();
521 }
522 });
523 },
524
525 destroy: function(){
526 if(this._fadeInDeferred){
527 this._fadeInDeferred.cancel();
528 }
529 if(this._fadeOutDeferred){
530 this._fadeOutDeferred.cancel();
531 }
532 if(this._moveable){
533 this._moveable.destroy();
534 }
535 var h;
536 while(h = this._modalconnects.pop()){
537 h.remove();
538 }
539
540 DialogLevelManager.hide(this);
541
542 this.inherited(arguments);
543 }
544 });
545
546 if(has("dojo-bidi")){
547 _DialogBase = declare("dijit._DialogBase", _DialogBase, {
548 _setTitleAttr: function(/*String*/ title){
549 this._set("title", title);
550 this.titleNode.innerHTML = title;
551 this.applyTextDir(this.titleNode);
552 },
553
554 _setTextDirAttr: function(textDir){
555 if(this._created && this.textDir != textDir){
556 this._set("textDir", textDir);
557 this.set("title", this.title);
558 }
559 }
560 });
561 }
562
563 var Dialog = declare("dijit.Dialog", [ContentPane, _DialogBase], {
564 // summary:
565 // A modal dialog Widget.
566 // description:
567 // Pops up a modal dialog window, blocking access to the screen
568 // and also graying out the screen Dialog is extended from
569 // ContentPane so it supports all the same parameters (href, etc.).
570 // example:
571 // | <div data-dojo-type="dijit/Dialog" data-dojo-props="href: 'test.html'"></div>
572 // example:
573 // | var foo = new Dialog({ title: "test dialog", content: "test content" });
574 // | foo.placeAt(win.body());
575 // | foo.startup();
576 });
577 Dialog._DialogBase = _DialogBase; // for monkey patching and dojox/widget/DialogSimple
578
579 var DialogLevelManager = Dialog._DialogLevelManager = {
580 // summary:
581 // Controls the various active "levels" on the page, starting with the
582 // stuff initially visible on the page (at z-index 0), and then having an entry for
583 // each Dialog shown.
584
585 _beginZIndex: 950,
586
587 show: function(/*dijit/_WidgetBase*/ dialog, /*Object*/ underlayAttrs){
588 // summary:
589 // Call right before fade-in animation for new dialog.
590 // Saves current focus, displays/adjusts underlay for new dialog,
591 // and sets the z-index of the dialog itself.
592 //
593 // New dialog will be displayed on top of all currently displayed dialogs.
594 //
595 // Caller is responsible for setting focus in new dialog after the fade-in
596 // animation completes.
597
598 // Save current focus
599 ds[ds.length - 1].focus = focus.curNode;
600
601 // Set z-index a bit above previous dialog
602 var zIndex = ds[ds.length - 1].dialog ? ds[ds.length - 1].zIndex + 2 : Dialog._DialogLevelManager._beginZIndex;
603 domStyle.set(dialog.domNode, 'zIndex', zIndex);
604
605 // Display the underlay, or if already displayed then adjust for this new dialog
606 DialogUnderlay.show(underlayAttrs, zIndex - 1);
607
608 ds.push({dialog: dialog, underlayAttrs: underlayAttrs, zIndex: zIndex});
609 },
610
611 hide: function(/*dijit/_WidgetBase*/ dialog){
612 // summary:
613 // Called when the specified dialog is hidden/destroyed, after the fade-out
614 // animation ends, in order to reset page focus, fix the underlay, etc.
615 // If the specified dialog isn't open then does nothing.
616 //
617 // Caller is responsible for either setting display:none on the dialog domNode,
618 // or calling dijit/popup.hide(), or removing it from the page DOM.
619
620 if(ds[ds.length - 1].dialog == dialog){
621 // Removing the top (or only) dialog in the stack, return focus
622 // to previous dialog
623
624 ds.pop();
625
626 var pd = ds[ds.length - 1]; // the new active dialog (or the base page itself)
627
628 // Adjust underlay
629 if(ds.length == 1){
630 // Returning to original page. Hide the underlay.
631 DialogUnderlay.hide();
632 }else{
633 // Popping back to previous dialog, adjust underlay.
634 DialogUnderlay.show(pd.underlayAttrs, pd.zIndex - 1);
635 }
636
637 // Adjust focus.
638 // TODO: regardless of setting of dialog.refocus, if the exeucte() method set focus somewhere,
639 // don't shift focus back to button. Note that execute() runs at the start of the fade-out but
640 // this code runs later, at the end of the fade-out. Menu has code like this.
641 if(dialog.refocus){
642 // If we are returning control to a previous dialog but for some reason
643 // that dialog didn't have a focused field, set focus to first focusable item.
644 // This situation could happen if two dialogs appeared at nearly the same time,
645 // since a dialog doesn't set it's focus until the fade-in is finished.
646 var focus = pd.focus;
647 if(pd.dialog && (!focus || !dom.isDescendant(focus, pd.dialog.domNode))){
648 pd.dialog._getFocusItems();
649 focus = pd.dialog._firstFocusItem;
650 }
651
652 if(focus){
653 // Refocus the button that spawned the Dialog. This will fail in corner cases including
654 // page unload on IE, because the dijit/form/Button that launched the Dialog may get destroyed
655 // before this code runs. (#15058)
656 try{
657 focus.focus();
658 }catch(e){
659 }
660 }
661 }
662 }else{
663 // Removing a dialog out of order (#9944, #10705).
664 // Don't need to mess with underlay or z-index or anything.
665 var idx = array.indexOf(array.map(ds, function(elem){
666 return elem.dialog;
667 }), dialog);
668 if(idx != -1){
669 ds.splice(idx, 1);
670 }
671 }
672 },
673
674 isTop: function(/*dijit/_WidgetBase*/ dialog){
675 // summary:
676 // Returns true if specified Dialog is the top in the task
677 return ds[ds.length - 1].dialog == dialog;
678 }
679 };
680
681 // Stack representing the various active "levels" on the page, starting with the
682 // stuff initially visible on the page (at z-index 0), and then having an entry for
683 // each Dialog shown.
684 // Each element in stack has form {
685 // dialog: dialogWidget,
686 // focus: returnFromGetFocus(),
687 // underlayAttrs: attributes to set on underlay (when this widget is active)
688 // }
689 var ds = Dialog._dialogStack = [
690 {dialog: null, focus: null, underlayAttrs: null} // entry for stuff at z-index: 0
691 ];
692
693 // If focus was accidentally removed from the dialog, such as if the user clicked a blank
694 // area of the screen, or clicked the browser's address bar and then tabbed into the page,
695 // then refocus. Won't do anything if focus was removed because the Dialog was closed, or
696 // because a new Dialog popped up on top of the old one, or when focus moves to popups
697 focus.watch("curNode", function(attr, oldNode, node){
698 // Note: if no dialogs, ds.length==1 but ds[ds.length-1].dialog is null
699 var topDialog = ds[ds.length - 1].dialog;
700
701 // If a node was focused, and there's a Dialog currently showing, and not in the process of fading out...
702 // Ignore focus events on other document though because it's likely an Editor inside of the Dialog.
703 if(node && topDialog && !topDialog._fadeOutDeferred && node.ownerDocument == topDialog.ownerDocument){
704 // If the node that was focused is inside the dialog or in a popup, even a context menu that isn't
705 // technically a descendant of the the dialog, don't do anything.
706 do{
707 if(node == topDialog.domNode || domClass.contains(node, "dijitPopup")){ return; }
708 }while(node = node.parentNode);
709
710 // Otherwise, return focus to the dialog. Use a delay to avoid confusing dijit/focus code's
711 // own tracking of focus.
712 topDialog.focus();
713 }
714 });
715
716 // Back compat w/1.6, remove for 2.0
717 if(has("dijit-legacy-requires")){
718 ready(0, function(){
719 var requires = ["dijit/TooltipDialog"];
720 require(requires); // use indirection so modules not rolled into a build
721 });
722 }
723
724 return Dialog;
725 });