DialogUnderlay.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. define("dijit/DialogUnderlay", [
  2. "dojo/_base/declare", // declare
  3. "dojo/dom-attr", // domAttr.set
  4. "dojo/_base/window", // win.body
  5. "dojo/window", // winUtils.getBox
  6. "./_Widget",
  7. "./_TemplatedMixin",
  8. "./BackgroundIframe"
  9. ], function(declare, domAttr, win, winUtils, _Widget, _TemplatedMixin, BackgroundIframe){
  10. /*=====
  11. var _Widget = dijit._Widget;
  12. var _TemplatedMixin = dijit._TemplatedMixin;
  13. =====*/
  14. // module:
  15. // dijit/DialogUnderlay
  16. // summary:
  17. // The component that blocks the screen behind a `dijit.Dialog`
  18. return declare("dijit.DialogUnderlay", [_Widget, _TemplatedMixin], {
  19. // summary:
  20. // The component that blocks the screen behind a `dijit.Dialog`
  21. //
  22. // description:
  23. // A component used to block input behind a `dijit.Dialog`. Only a single
  24. // instance of this widget is created by `dijit.Dialog`, and saved as
  25. // a reference to be shared between all Dialogs as `dijit._underlay`
  26. //
  27. // The underlay itself can be styled based on and id:
  28. // | #myDialog_underlay { background-color:red; }
  29. //
  30. // In the case of `dijit.Dialog`, this id is based on the id of the Dialog,
  31. // suffixed with _underlay.
  32. // Template has two divs; outer div is used for fade-in/fade-out, and also to hold background iframe.
  33. // Inner div has opacity specified in CSS file.
  34. templateString: "<div class='dijitDialogUnderlayWrapper'><div class='dijitDialogUnderlay' data-dojo-attach-point='node'></div></div>",
  35. // Parameters on creation or updatable later
  36. // dialogId: String
  37. // Id of the dialog.... DialogUnderlay's id is based on this id
  38. dialogId: "",
  39. // class: String
  40. // This class name is used on the DialogUnderlay node, in addition to dijitDialogUnderlay
  41. "class": "",
  42. _setDialogIdAttr: function(id){
  43. domAttr.set(this.node, "id", id + "_underlay");
  44. this._set("dialogId", id);
  45. },
  46. _setClassAttr: function(clazz){
  47. this.node.className = "dijitDialogUnderlay " + clazz;
  48. this._set("class", clazz);
  49. },
  50. postCreate: function(){
  51. // summary:
  52. // Append the underlay to the body
  53. win.body().appendChild(this.domNode);
  54. },
  55. layout: function(){
  56. // summary:
  57. // Sets the background to the size of the viewport
  58. //
  59. // description:
  60. // Sets the background to the size of the viewport (rather than the size
  61. // of the document) since we need to cover the whole browser window, even
  62. // if the document is only a few lines long.
  63. // tags:
  64. // private
  65. var is = this.node.style,
  66. os = this.domNode.style;
  67. // hide the background temporarily, so that the background itself isn't
  68. // causing scrollbars to appear (might happen when user shrinks browser
  69. // window and then we are called to resize)
  70. os.display = "none";
  71. // then resize and show
  72. var viewport = winUtils.getBox();
  73. os.top = viewport.t + "px";
  74. os.left = viewport.l + "px";
  75. is.width = viewport.w + "px";
  76. is.height = viewport.h + "px";
  77. os.display = "block";
  78. },
  79. show: function(){
  80. // summary:
  81. // Show the dialog underlay
  82. this.domNode.style.display = "block";
  83. this.layout();
  84. this.bgIframe = new BackgroundIframe(this.domNode);
  85. },
  86. hide: function(){
  87. // summary:
  88. // Hides the dialog underlay
  89. this.bgIframe.destroy();
  90. delete this.bgIframe;
  91. this.domNode.style.display = "none";
  92. }
  93. });
  94. });