Dialog.js.uncompressed.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. require({cache:{
  2. 'url:dijit/templates/Dialog.html':"<div class=\"dijitDialog\" role=\"dialog\" aria-labelledby=\"${id}_title\">\n\t<div data-dojo-attach-point=\"titleBar\" class=\"dijitDialogTitleBar\">\n\t\t<span data-dojo-attach-point=\"titleNode\" class=\"dijitDialogTitle\" id=\"${id}_title\"\n\t\t\t\trole=\"heading\" level=\"1\"></span>\n\t\t<span data-dojo-attach-point=\"closeButtonNode\" class=\"dijitDialogCloseIcon\" data-dojo-attach-event=\"ondijitclick: onCancel\" title=\"${buttonCancel}\" role=\"button\" tabIndex=\"-1\">\n\t\t\t<span data-dojo-attach-point=\"closeText\" class=\"closeText\" title=\"${buttonCancel}\">x</span>\n\t\t</span>\n\t</div>\n\t<div data-dojo-attach-point=\"containerNode\" class=\"dijitDialogPaneContent\"></div>\n</div>\n"}});
  3. define("dijit/Dialog", [
  4. "require",
  5. "dojo/_base/array", // array.forEach array.indexOf array.map
  6. "dojo/_base/connect", // connect._keypress
  7. "dojo/_base/declare", // declare
  8. "dojo/_base/Deferred", // Deferred
  9. "dojo/dom", // dom.isDescendant
  10. "dojo/dom-class", // domClass.add domClass.contains
  11. "dojo/dom-geometry", // domGeometry.position
  12. "dojo/dom-style", // domStyle.set
  13. "dojo/_base/event", // event.stop
  14. "dojo/_base/fx", // fx.fadeIn fx.fadeOut
  15. "dojo/i18n", // i18n.getLocalization
  16. "dojo/keys",
  17. "dojo/_base/lang", // lang.mixin lang.hitch
  18. "dojo/on",
  19. "dojo/ready",
  20. "dojo/sniff", // has("ie") has("opera") has("dijit-legacy-requires")
  21. "dojo/window", // winUtils.getBox, winUtils.get
  22. "dojo/dnd/Moveable", // Moveable
  23. "dojo/dnd/TimedMoveable", // TimedMoveable
  24. "./focus",
  25. "./_base/manager", // manager.defaultDuration
  26. "./_Widget",
  27. "./_TemplatedMixin",
  28. "./_CssStateMixin",
  29. "./form/_FormMixin",
  30. "./_DialogMixin",
  31. "./DialogUnderlay",
  32. "./layout/ContentPane",
  33. "dojo/text!./templates/Dialog.html",
  34. "./main", // for back-compat, exporting dijit._underlay (remove in 2.0)
  35. "dojo/i18n!./nls/common"
  36. ], function(require, array, connect, declare, Deferred,
  37. dom, domClass, domGeometry, domStyle, event, fx, i18n, keys, lang, on, ready, has, winUtils,
  38. Moveable, TimedMoveable, focus, manager, _Widget, _TemplatedMixin, _CssStateMixin, _FormMixin, _DialogMixin,
  39. DialogUnderlay, ContentPane, template, dijit){
  40. // module:
  41. // dijit/Dialog
  42. /*=====
  43. dijit._underlay = function(kwArgs){
  44. // summary:
  45. // A shared instance of a `dijit.DialogUnderlay`
  46. //
  47. // description:
  48. // A shared instance of a `dijit.DialogUnderlay` created and
  49. // used by `dijit.Dialog`, though never created until some Dialog
  50. // or subclass thereof is shown.
  51. };
  52. =====*/
  53. var _DialogBase = declare("dijit._DialogBase", [_TemplatedMixin, _FormMixin, _DialogMixin, _CssStateMixin], {
  54. templateString: template,
  55. baseClass: "dijitDialog",
  56. cssStateNodes: {
  57. closeButtonNode: "dijitDialogCloseIcon"
  58. },
  59. // Map widget attributes to DOMNode attributes.
  60. _setTitleAttr: [
  61. { node: "titleNode", type: "innerHTML" },
  62. { node: "titleBar", type: "attribute" }
  63. ],
  64. // open: [readonly] Boolean
  65. // True if Dialog is currently displayed on screen.
  66. open: false,
  67. // duration: Integer
  68. // The time in milliseconds it takes the dialog to fade in and out
  69. duration: manager.defaultDuration,
  70. // refocus: Boolean
  71. // A Toggle to modify the default focus behavior of a Dialog, which
  72. // is to re-focus the element which had focus before being opened.
  73. // False will disable refocusing. Default: true
  74. refocus: true,
  75. // autofocus: Boolean
  76. // A Toggle to modify the default focus behavior of a Dialog, which
  77. // is to focus on the first dialog element after opening the dialog.
  78. // False will disable autofocusing. Default: true
  79. autofocus: true,
  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. // _lastFocusItem: [private readonly] DomNode
  85. // The pointer to which node has focus prior to our dialog.
  86. // Set by `dijit/_DialogMixin._getFocusItems()`.
  87. _lastFocusItem: null,
  88. // doLayout: [protected] Boolean
  89. // Don't change this parameter from the default value.
  90. // This ContentPane parameter doesn't make sense for Dialog, since Dialog
  91. // is never a child of a layout container, nor can you specify the size of
  92. // Dialog in order to control the size of an inner widget.
  93. doLayout: false,
  94. // draggable: Boolean
  95. // Toggles the moveable aspect of the Dialog. If true, Dialog
  96. // can be dragged by it's title. If false it will remain centered
  97. // in the viewport.
  98. draggable: true,
  99. _setDraggableAttr: function(/*Boolean*/ val){
  100. // Avoid _WidgetBase behavior of copying draggable attribute to this.domNode,
  101. // as that prevents text select on modern browsers (#14452)
  102. this._set("draggable", val);
  103. },
  104. // aria-describedby: String
  105. // Allows the user to add an aria-describedby attribute onto the dialog. The value should
  106. // be the id of the container element of text that describes the dialog purpose (usually
  107. // the first text in the dialog).
  108. // | <div data-dojo-type="dijit/Dialog" aria-describedby="intro" .....>
  109. // | <div id="intro">Introductory text</div>
  110. // | <div>rest of dialog contents</div>
  111. // | </div>
  112. "aria-describedby": "",
  113. // maxRatio: Number
  114. // Maximum size to allow the dialog to expand to, relative to viewport size
  115. maxRatio: 0.9,
  116. postMixInProperties: function(){
  117. var _nlsResources = i18n.getLocalization("dijit", "common");
  118. lang.mixin(this, _nlsResources);
  119. this.inherited(arguments);
  120. },
  121. postCreate: function(){
  122. domStyle.set(this.domNode, {
  123. display: "none",
  124. position:"absolute"
  125. });
  126. this.ownerDocumentBody.appendChild(this.domNode);
  127. this.inherited(arguments);
  128. this.connect(this, "onExecute", "hide");
  129. this.connect(this, "onCancel", "hide");
  130. this._modalconnects = [];
  131. },
  132. onLoad: function(){
  133. // summary:
  134. // Called when data has been loaded from an href.
  135. // Unlike most other callbacks, this function can be connected to (via `dojo.connect`)
  136. // but should *not* be overridden.
  137. // tags:
  138. // callback
  139. // when href is specified we need to reposition the dialog after the data is loaded
  140. // and find the focusable elements
  141. this._position();
  142. if(this.autofocus && DialogLevelManager.isTop(this)){
  143. this._getFocusItems(this.domNode);
  144. focus.focus(this._firstFocusItem);
  145. }
  146. this.inherited(arguments);
  147. },
  148. _onBlur: function(by){
  149. this.inherited(arguments);
  150. // If focus was accidentally removed from the dialog, such as if the user clicked a blank
  151. // area of the screen, or clicked the browser's address bar and then tabbed into the page,
  152. // then refocus. Won't do anything if focus was removed because the Dialog was closed, or
  153. // because a new Dialog popped up on top of the old one.
  154. var refocus = lang.hitch(this, function(){
  155. if(this.open && !this._destroyed && DialogLevelManager.isTop(this)){
  156. this._getFocusItems(this.domNode);
  157. focus.focus(this._firstFocusItem);
  158. }
  159. });
  160. if(by == "mouse"){
  161. // wait for mouse up, and then refocus dialog; otherwise doesn't work
  162. on.once(this.ownerDocument, "mouseup", refocus);
  163. }else{
  164. refocus();
  165. }
  166. },
  167. _endDrag: function(){
  168. // summary:
  169. // Called after dragging the Dialog. Saves the position of the dialog in the viewport,
  170. // and also adjust position to be fully within the viewport, so user doesn't lose access to handle
  171. var nodePosition = domGeometry.position(this.domNode),
  172. viewport = winUtils.getBox(this.ownerDocument);
  173. nodePosition.y = Math.min(Math.max(nodePosition.y, 0), (viewport.h - nodePosition.h));
  174. nodePosition.x = Math.min(Math.max(nodePosition.x, 0), (viewport.w - nodePosition.w));
  175. this._relativePosition = nodePosition;
  176. this._position();
  177. },
  178. _setup: function(){
  179. // summary:
  180. // Stuff we need to do before showing the Dialog for the first
  181. // time (but we defer it until right beforehand, for
  182. // performance reasons).
  183. // tags:
  184. // private
  185. var node = this.domNode;
  186. if(this.titleBar && this.draggable){
  187. this._moveable = new ((has("ie") == 6) ? TimedMoveable // prevent overload, see #5285
  188. : Moveable)(node, { handle: this.titleBar });
  189. this.connect(this._moveable, "onMoveStop", "_endDrag");
  190. }else{
  191. domClass.add(node,"dijitDialogFixed");
  192. }
  193. this.underlayAttrs = {
  194. dialogId: this.id,
  195. "class": array.map(this["class"].split(/\s/), function(s){ return s+"_underlay"; }).join(" "),
  196. ownerDocument: this.ownerDocument
  197. };
  198. },
  199. _size: function(){
  200. // summary:
  201. // If necessary, shrink dialog contents so dialog fits in viewport
  202. // tags:
  203. // private
  204. this._checkIfSingleChild();
  205. // If we resized the dialog contents earlier, reset them back to original size, so
  206. // that if the user later increases the viewport size, the dialog can display w/out a scrollbar.
  207. // Need to do this before the domGeometry.position(this.domNode) call below.
  208. if(this._singleChild){
  209. if(typeof this._singleChildOriginalStyle != "undefined"){
  210. this._singleChild.domNode.style.cssText = this._singleChildOriginalStyle;
  211. delete this._singleChildOriginalStyle;
  212. }
  213. }else{
  214. domStyle.set(this.containerNode, {
  215. width:"auto",
  216. height:"auto"
  217. });
  218. }
  219. var bb = domGeometry.position(this.domNode);
  220. // Get viewport size but then reduce it by a bit; Dialog should always have some space around it
  221. // to indicate that it's a popup. This will also compensate for possible scrollbars on viewport.
  222. var viewport = winUtils.getBox(this.ownerDocument);
  223. viewport.w *= this.maxRatio;
  224. viewport.h *= this.maxRatio;
  225. if(bb.w >= viewport.w || bb.h >= viewport.h){
  226. // Reduce size of dialog contents so that dialog fits in viewport
  227. var containerSize = domGeometry.position(this.containerNode),
  228. w = Math.min(bb.w, viewport.w) - (bb.w - containerSize.w),
  229. h = Math.min(bb.h, viewport.h) - (bb.h - containerSize.h);
  230. if(this._singleChild && this._singleChild.resize){
  231. if(typeof this._singleChildOriginalStyle == "undefined"){
  232. this._singleChildOriginalStyle = this._singleChild.domNode.style.cssText;
  233. }
  234. this._singleChild.resize({w: w, h: h});
  235. }else{
  236. domStyle.set(this.containerNode, {
  237. width: w + "px",
  238. height: h + "px",
  239. overflow: "auto",
  240. position: "relative" // workaround IE bug moving scrollbar or dragging dialog
  241. });
  242. }
  243. }else{
  244. if(this._singleChild && this._singleChild.resize){
  245. this._singleChild.resize();
  246. }
  247. }
  248. },
  249. _position: function(){
  250. // summary:
  251. // Position modal dialog in the viewport. If no relative offset
  252. // in the viewport has been determined (by dragging, for instance),
  253. // center the node. Otherwise, use the Dialog's stored relative offset,
  254. // and position the node to top: left: values based on the viewport.
  255. if(!domClass.contains(this.ownerDocumentBody, "dojoMove")){ // don't do anything if called during auto-scroll
  256. var node = this.domNode,
  257. viewport = winUtils.getBox(this.ownerDocument),
  258. p = this._relativePosition,
  259. bb = p ? null : domGeometry.position(node),
  260. l = Math.floor(viewport.l + (p ? p.x : (viewport.w - bb.w) / 2)),
  261. t = Math.floor(viewport.t + (p ? p.y : (viewport.h - bb.h) / 2))
  262. ;
  263. domStyle.set(node,{
  264. left: l + "px",
  265. top: t + "px"
  266. });
  267. }
  268. },
  269. _onKey: function(/*Event*/ evt){
  270. // summary:
  271. // Handles the keyboard events for accessibility reasons
  272. // tags:
  273. // private
  274. if(evt.charOrCode){
  275. var node = evt.target;
  276. if(evt.charOrCode === keys.TAB){
  277. this._getFocusItems(this.domNode);
  278. }
  279. var singleFocusItem = (this._firstFocusItem == this._lastFocusItem);
  280. // see if we are shift-tabbing from first focusable item on dialog
  281. if(node == this._firstFocusItem && evt.shiftKey && evt.charOrCode === keys.TAB){
  282. if(!singleFocusItem){
  283. focus.focus(this._lastFocusItem); // send focus to last item in dialog
  284. }
  285. event.stop(evt);
  286. }else if(node == this._lastFocusItem && evt.charOrCode === keys.TAB && !evt.shiftKey){
  287. if(!singleFocusItem){
  288. focus.focus(this._firstFocusItem); // send focus to first item in dialog
  289. }
  290. event.stop(evt);
  291. }else{
  292. // see if the key is for the dialog
  293. while(node){
  294. if(node == this.domNode || domClass.contains(node, "dijitPopup")){
  295. if(evt.charOrCode == keys.ESCAPE){
  296. this.onCancel();
  297. }else{
  298. return; // just let it go
  299. }
  300. }
  301. node = node.parentNode;
  302. }
  303. // this key is for the disabled document window
  304. if(evt.charOrCode !== keys.TAB){ // allow tabbing into the dialog for a11y
  305. event.stop(evt);
  306. // opera won't tab to a div
  307. }else if(!has("opera")){
  308. try{
  309. this._firstFocusItem.focus();
  310. }catch(e){ /*squelch*/ }
  311. }
  312. }
  313. }
  314. },
  315. show: function(){
  316. // summary:
  317. // Display the dialog
  318. // returns: dojo/_base/Deferred
  319. // Deferred object that resolves when the display animation is complete
  320. if(this.open){ return; }
  321. if(!this._started){
  322. this.startup();
  323. }
  324. // first time we show the dialog, there's some initialization stuff to do
  325. if(!this._alreadyInitialized){
  326. this._setup();
  327. this._alreadyInitialized=true;
  328. }
  329. if(this._fadeOutDeferred){
  330. this._fadeOutDeferred.cancel();
  331. }
  332. // Recenter Dialog if user scrolls browser. Connecting to document doesn't work on IE, need to use window.
  333. var win = winUtils.get(this.ownerDocument);
  334. this._modalconnects.push(on(win, "scroll", lang.hitch(this, "resize")));
  335. this._modalconnects.push(on(this.domNode, connect._keypress, lang.hitch(this, "_onKey")));
  336. domStyle.set(this.domNode, {
  337. opacity:0,
  338. display:""
  339. });
  340. this._set("open", true);
  341. this._onShow(); // lazy load trigger
  342. this._size();
  343. this._position();
  344. // fade-in Animation object, setup below
  345. var fadeIn;
  346. this._fadeInDeferred = new Deferred(lang.hitch(this, function(){
  347. fadeIn.stop();
  348. delete this._fadeInDeferred;
  349. }));
  350. fadeIn = fx.fadeIn({
  351. node: this.domNode,
  352. duration: this.duration,
  353. beforeBegin: lang.hitch(this, function(){
  354. DialogLevelManager.show(this, this.underlayAttrs);
  355. }),
  356. onEnd: lang.hitch(this, function(){
  357. if(this.autofocus && DialogLevelManager.isTop(this)){
  358. // find focusable items each time dialog is shown since if dialog contains a widget the
  359. // first focusable items can change
  360. this._getFocusItems(this.domNode);
  361. focus.focus(this._firstFocusItem);
  362. }
  363. this._fadeInDeferred.resolve(true);
  364. delete this._fadeInDeferred;
  365. })
  366. }).play();
  367. return this._fadeInDeferred;
  368. },
  369. hide: function(){
  370. // summary:
  371. // Hide the dialog
  372. // returns: dojo/_base/Deferred
  373. // Deferred object that resolves when the hide animation is complete
  374. // If we haven't been initialized yet then we aren't showing and we can just return.
  375. // Likewise if we are already hidden, or are currently fading out.
  376. if(!this._alreadyInitialized || !this.open){
  377. return;
  378. }
  379. if(this._fadeInDeferred){
  380. this._fadeInDeferred.cancel();
  381. }
  382. // fade-in Animation object, setup below
  383. var fadeOut;
  384. this._fadeOutDeferred = new Deferred(lang.hitch(this, function(){
  385. fadeOut.stop();
  386. delete this._fadeOutDeferred;
  387. }));
  388. // fire onHide when the promise resolves.
  389. this._fadeOutDeferred.then(lang.hitch(this, 'onHide'));
  390. fadeOut = fx.fadeOut({
  391. node: this.domNode,
  392. duration: this.duration,
  393. onEnd: lang.hitch(this, function(){
  394. this.domNode.style.display = "none";
  395. DialogLevelManager.hide(this);
  396. this._fadeOutDeferred.resolve(true);
  397. delete this._fadeOutDeferred;
  398. })
  399. }).play();
  400. if(this._scrollConnected){
  401. this._scrollConnected = false;
  402. }
  403. var h;
  404. while(h = this._modalconnects.pop()){
  405. h.remove();
  406. }
  407. if(this._relativePosition){
  408. delete this._relativePosition;
  409. }
  410. this._set("open", false);
  411. return this._fadeOutDeferred;
  412. },
  413. resize: function(){
  414. // summary:
  415. // Called when viewport scrolled or size changed. Position the Dialog and the underlay.
  416. // tags:
  417. // private
  418. if(this.domNode.style.display != "none"){
  419. if(DialogUnderlay._singleton){ // avoid race condition during show()
  420. DialogUnderlay._singleton.layout();
  421. }
  422. this._position();
  423. this._size();
  424. }
  425. },
  426. destroy: function(){
  427. if(this._fadeInDeferred){
  428. this._fadeInDeferred.cancel();
  429. }
  430. if(this._fadeOutDeferred){
  431. this._fadeOutDeferred.cancel();
  432. }
  433. if(this._moveable){
  434. this._moveable.destroy();
  435. }
  436. var h;
  437. while(h = this._modalconnects.pop()){
  438. h.remove();
  439. }
  440. DialogLevelManager.hide(this);
  441. this.inherited(arguments);
  442. }
  443. });
  444. var Dialog = declare("dijit.Dialog", [ContentPane, _DialogBase], {
  445. // summary:
  446. // A modal dialog Widget.
  447. // description:
  448. // Pops up a modal dialog window, blocking access to the screen
  449. // and also graying out the screen Dialog is extended from
  450. // ContentPane so it supports all the same parameters (href, etc.).
  451. // example:
  452. // | <div data-dojo-type="dijit/Dialog" data-dojo-props="href: 'test.html'"></div>
  453. // example:
  454. // | var foo = new Dialog({ title: "test dialog", content: "test content" };
  455. // | foo.placeAt(win.body());
  456. // | foo.startup();
  457. });
  458. Dialog._DialogBase = _DialogBase; // for monkey patching and dojox/widget/DialogSimple
  459. var DialogLevelManager = Dialog._DialogLevelManager = {
  460. // summary:
  461. // Controls the various active "levels" on the page, starting with the
  462. // stuff initially visible on the page (at z-index 0), and then having an entry for
  463. // each Dialog shown.
  464. _beginZIndex: 950,
  465. show: function(/*dijit/_WidgetBase*/ dialog, /*Object*/ underlayAttrs){
  466. // summary:
  467. // Call right before fade-in animation for new dialog.
  468. // Saves current focus, displays/adjusts underlay for new dialog,
  469. // and sets the z-index of the dialog itself.
  470. //
  471. // New dialog will be displayed on top of all currently displayed dialogs.
  472. //
  473. // Caller is responsible for setting focus in new dialog after the fade-in
  474. // animation completes.
  475. // Save current focus
  476. ds[ds.length-1].focus = focus.curNode;
  477. // Display the underlay, or if already displayed then adjust for this new dialog
  478. // TODO: one underlay per document (based on dialog.ownerDocument)
  479. var underlay = DialogUnderlay._singleton;
  480. if(!underlay || underlay._destroyed){
  481. underlay = dijit._underlay = DialogUnderlay._singleton = new DialogUnderlay(underlayAttrs);
  482. }else{
  483. underlay.set(dialog.underlayAttrs);
  484. }
  485. // Set z-index a bit above previous dialog
  486. var zIndex = ds[ds.length-1].dialog ? ds[ds.length-1].zIndex + 2 : Dialog._DialogLevelManager._beginZIndex;
  487. if(ds.length == 1){ // first dialog
  488. underlay.show();
  489. }
  490. domStyle.set(DialogUnderlay._singleton.domNode, 'zIndex', zIndex - 1);
  491. // Dialog
  492. domStyle.set(dialog.domNode, 'zIndex', zIndex);
  493. ds.push({dialog: dialog, underlayAttrs: underlayAttrs, zIndex: zIndex});
  494. },
  495. hide: function(/*dijit/_WidgetBase*/ dialog){
  496. // summary:
  497. // Called when the specified dialog is hidden/destroyed, after the fade-out
  498. // animation ends, in order to reset page focus, fix the underlay, etc.
  499. // If the specified dialog isn't open then does nothing.
  500. //
  501. // Caller is responsible for either setting display:none on the dialog domNode,
  502. // or calling dijit/popup.hide(), or removing it from the page DOM.
  503. if(ds[ds.length-1].dialog == dialog){
  504. // Removing the top (or only) dialog in the stack, return focus
  505. // to previous dialog
  506. ds.pop();
  507. var pd = ds[ds.length-1]; // the new active dialog (or the base page itself)
  508. // Adjust underlay, unless the underlay widget has already been destroyed
  509. // because we are being called during page unload (when all widgets are destroyed)
  510. if(!DialogUnderlay._singleton._destroyed){
  511. if(ds.length == 1){
  512. // Returning to original page. Hide the underlay.
  513. DialogUnderlay._singleton.hide();
  514. }else{
  515. // Popping back to previous dialog, adjust underlay.
  516. domStyle.set(DialogUnderlay._singleton.domNode, 'zIndex', pd.zIndex - 1);
  517. DialogUnderlay._singleton.set(pd.underlayAttrs);
  518. }
  519. }
  520. // Adjust focus
  521. if(dialog.refocus){
  522. // If we are returning control to a previous dialog but for some reason
  523. // that dialog didn't have a focused field, set focus to first focusable item.
  524. // This situation could happen if two dialogs appeared at nearly the same time,
  525. // since a dialog doesn't set it's focus until the fade-in is finished.
  526. var focus = pd.focus;
  527. if(pd.dialog && (!focus || !dom.isDescendant(focus, pd.dialog.domNode))){
  528. pd.dialog._getFocusItems(pd.dialog.domNode);
  529. focus = pd.dialog._firstFocusItem;
  530. }
  531. if(focus){
  532. // Refocus the button that spawned the Dialog. This will fail in corner cases including
  533. // page unload on IE, because the dijit/form/Button that launched the Dialog may get destroyed
  534. // before this code runs. (#15058)
  535. try{
  536. focus.focus();
  537. }catch(e){}
  538. }
  539. }
  540. }else{
  541. // Removing a dialog out of order (#9944, #10705).
  542. // Don't need to mess with underlay or z-index or anything.
  543. var idx = array.indexOf(array.map(ds, function(elem){return elem.dialog}), dialog);
  544. if(idx != -1){
  545. ds.splice(idx, 1);
  546. }
  547. }
  548. },
  549. isTop: function(/*dijit/_WidgetBase*/ dialog){
  550. // summary:
  551. // Returns true if specified Dialog is the top in the task
  552. return ds[ds.length-1].dialog == dialog;
  553. }
  554. };
  555. // Stack representing the various active "levels" on the page, starting with the
  556. // stuff initially visible on the page (at z-index 0), and then having an entry for
  557. // each Dialog shown.
  558. // Each element in stack has form {
  559. // dialog: dialogWidget,
  560. // focus: returnFromGetFocus(),
  561. // underlayAttrs: attributes to set on underlay (when this widget is active)
  562. // }
  563. var ds = Dialog._dialogStack = [
  564. {dialog: null, focus: null, underlayAttrs: null} // entry for stuff at z-index: 0
  565. ];
  566. // Back compat w/1.6, remove for 2.0
  567. if(has("dijit-legacy-requires")){
  568. ready(0, function(){
  569. var requires = ["dijit/TooltipDialog"];
  570. require(requires); // use indirection so modules not rolled into a build
  571. });
  572. }
  573. return Dialog;
  574. });