Dialog.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. require({cache:{
  2. 'url:dojox/widget/Dialog/Dialog.html':"<div class=\"dojoxDialog\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"${id}_title\">\n\t<div dojoAttachPoint=\"titleBar\" class=\"dojoxDialogTitleBar\">\n\t\t<span dojoAttachPoint=\"titleNode\" class=\"dojoxDialogTitle\" id=\"${id}_title\">${title}</span>\n\t</div>\n\t<div dojoAttachPoint=\"dojoxDialogWrapper\">\n\t\t<div dojoAttachPoint=\"containerNode\" class=\"dojoxDialogPaneContent\"></div>\n\t</div>\n\t<div dojoAttachPoint=\"closeButtonNode\" class=\"dojoxDialogCloseIcon\" dojoAttachEvent=\"onclick: onCancel\">\n\t\t\t<span dojoAttachPoint=\"closeText\" class=\"closeText\">x</span>\n\t</div>\n</div>\n"}});
  3. define("dojox/widget/Dialog", [
  4. "dojo", "dojox", "dojo/text!./Dialog/Dialog.html",
  5. "dijit/Dialog", "dojo/window", "dojox/fx", "./DialogSimple"
  6. ], function(dojo, dojox, template){
  7. dojo.getObject('widget', true, dojox);
  8. dojo.declare('dojox.widget.Dialog', dojox.widget.DialogSimple,
  9. {
  10. // summary:
  11. // A Lightbox-like Modal-dialog for HTML Content
  12. //
  13. // description:
  14. // An HTML-capable Dialog widget with advanced sizing
  15. // options, animated show/hide and other useful options.
  16. //
  17. // This Dialog is also very easy to apply custom styles to.
  18. //
  19. // It works identically to a `dijit.Dialog` with several
  20. // additional parameters.
  21. templateString: template,
  22. // sizeToViewport: Boolean
  23. // If true, fix the size of the dialog to the Viewport based on
  24. // viewportPadding value rather than the calculated or natural
  25. // stlye. If false, base the size on a passed dimension attribute.
  26. // Eitherway, the viewportPadding value is used if the the content
  27. // extends beyond the viewport size for whatever reason.
  28. sizeToViewport: false,
  29. // viewportPadding: Integer
  30. // If sizeToViewport="true", this is the amount of padding in pixels to leave
  31. // between the dialog border and the viewport edge.
  32. // This value is also used when sizeToViewport="false" and dimensions exceeded
  33. // by dialog content to ensure dialog does not go outside viewport boundary
  34. viewportPadding: 35,
  35. // dimensions: Array
  36. // A two-element array of [widht,height] to animate the Dialog to if sizeToViewport="false"
  37. // Defaults to [300,300]
  38. dimensions: null,
  39. // easing: Function?|String?
  40. // An easing function to apply to the sizing animation.
  41. easing: null,
  42. // sizeDuration: Integer
  43. // Time (in ms) to use in the Animation for sizing.
  44. sizeDuration: dijit._defaultDuration,
  45. // sizeMethod: String
  46. // To be passed to dojox.fx.sizeTo, one of "chain" or "combine" to effect
  47. // the animation sequence.
  48. sizeMethod: "chain",
  49. // showTitle: Boolean
  50. // Toogle to show or hide the Title area. Can only be set at startup.
  51. showTitle: false,
  52. // draggable: Boolean
  53. // Make the pane draggable. Differs from dijit.Dialog by setting default to false
  54. draggable: false, // simply over-ride the default from dijit.Dialog
  55. // modal: Boolean
  56. // If true, this Dialog instance will be truly modal and prevent closing until
  57. // explicitly told to by calling hide() - Defaults to false to preserve previous
  58. // behaviors.
  59. modal: false,
  60. constructor: function(props, node){
  61. this.easing = props.easing || dojo._defaultEasing;
  62. this.dimensions = props.dimensions || [300, 300];
  63. },
  64. _setup: function(){
  65. // summary: Piggyback on dijit.Dialog's _setup for load-time options, deferred to
  66. this.inherited(arguments);
  67. if(!this._alreadyInitialized){
  68. this._navIn = dojo.fadeIn({ node: this.closeButtonNode });
  69. this._navOut = dojo.fadeOut({ node: this.closeButtonNode });
  70. if(!this.showTitle){
  71. dojo.addClass(this.domNode,"dojoxDialogNoTitle");
  72. }
  73. }
  74. },
  75. layout: function(e){
  76. this._setSize();
  77. this.inherited(arguments);
  78. },
  79. _setSize: function(){
  80. // summary: cache and set our desired end position
  81. this._vp = dojo.window.getBox();
  82. var tc = this.containerNode,
  83. vpSized = this.sizeToViewport
  84. ;
  85. return this._displaysize = {
  86. w: vpSized ? tc.scrollWidth : this.dimensions[0],
  87. h: vpSized ? tc.scrollHeight : this.dimensions[1]
  88. }; // Object
  89. },
  90. show: function(){
  91. if(this.open){ return; }
  92. this._setSize();
  93. dojo.style(this.closeButtonNode,"opacity", 0);
  94. dojo.style(this.domNode, {
  95. overflow: "hidden",
  96. opacity: 0,
  97. width: "1px",
  98. height: "1px"
  99. });
  100. dojo.style(this.containerNode, {
  101. opacity: 0,
  102. overflow: "hidden"
  103. });
  104. this.inherited(arguments);
  105. if(this.modal){
  106. // prevent escape key from closing dialog
  107. // connect to body to trap this event from the Dialog a11y code, and stop escape key
  108. // from doing anything in the modal:true case:
  109. this._modalconnects.push(dojo.connect(dojo.body(), "onkeypress", function(e){
  110. if(e.charOrCode == dojo.keys.ESCAPE){
  111. dojo.stopEvent(e);
  112. }
  113. }));
  114. }else{
  115. // otherwise, allow clicking on the underlay to close
  116. this._modalconnects.push(dojo.connect(dijit._underlay.domNode, "onclick", this, "onCancel"));
  117. }
  118. this._modalconnects.push(dojo.connect(this.domNode,"onmouseenter",this,"_handleNav"));
  119. this._modalconnects.push(dojo.connect(this.domNode,"onmouseleave",this,"_handleNav"));
  120. },
  121. _handleNav: function(e){
  122. // summary: Handle's showing or hiding the close icon
  123. var navou = "_navOut",
  124. navin = "_navIn",
  125. animou = (e.type == "mouseout" ? navin : navou),
  126. animin = (e.type == "mouseout" ? navou : navin)
  127. ;
  128. this[animou].stop();
  129. this[animin].play();
  130. },
  131. // an experiment in a quicksilver-like hide. too choppy for me.
  132. /*
  133. hide: function(){
  134. // summary: Hide the dialog
  135. // if we haven't been initialized yet then we aren't showing and we can just return
  136. if(!this._alreadyInitialized){
  137. return;
  138. }
  139. this._fadeIn && this._fadeIn.stop();
  140. if (this._scrollConnected){
  141. this._scrollConnected = false;
  142. }
  143. dojo.forEach(this._modalconnects, dojo.disconnect);
  144. this._modalconnects = [];
  145. if(this.refocus){
  146. this.connect(this._fadeOut,"onEnd",dojo.hitch(dijit,"focus",this._savedFocus));
  147. }
  148. if(this._relativePosition){
  149. delete this._relativePosition;
  150. }
  151. dojox.fx.sizeTo({
  152. node: this.domNode,
  153. duration:this.sizeDuration || this.duration,
  154. width: this._vp.w - 1,
  155. height: 5,
  156. onBegin: dojo.hitch(this,function(){
  157. this._fadeOut.play(this.sizeDuration / 2);
  158. })
  159. }).play();
  160. this.open = false;
  161. }, */
  162. _position: function(){
  163. if(!this._started){ return; } // prevent content: from firing this anim #8914
  164. if(this._sizing){
  165. this._sizing.stop();
  166. this.disconnect(this._sizingConnect);
  167. delete this._sizing;
  168. }
  169. this.inherited(arguments);
  170. if(!this.open){ dojo.style(this.containerNode, "opacity", 0); }
  171. var pad = this.viewportPadding * 2;
  172. var props = {
  173. node: this.domNode,
  174. duration: this.sizeDuration || dijit._defaultDuration,
  175. easing: this.easing,
  176. method: this.sizeMethod
  177. };
  178. var ds = this._displaysize || this._setSize();
  179. props['width'] = ds.w = (ds.w + pad >= this._vp.w || this.sizeToViewport)
  180. ? this._vp.w - pad : ds.w;
  181. props['height'] = ds.h = (ds.h + pad >= this._vp.h || this.sizeToViewport)
  182. ? this._vp.h - pad : ds.h;
  183. this._sizing = dojox.fx.sizeTo(props);
  184. this._sizingConnect = this.connect(this._sizing,"onEnd","_showContent");
  185. this._sizing.play();
  186. },
  187. _showContent: function(e){
  188. // summary: Show the inner container after sizing animation
  189. var container = this.containerNode;
  190. dojo.style(this.domNode, {
  191. overflow: "visible",
  192. opacity: 1
  193. });
  194. dojo.style(this.closeButtonNode,"opacity",1);
  195. dojo.style(container, {
  196. height: this._displaysize.h - this.titleNode.offsetHeight + "px",
  197. width: this._displaysize.w + "px",
  198. overflow:"auto"
  199. });
  200. dojo.anim(container, { opacity:1 });
  201. }
  202. });
  203. return dojox.widget.Dialog;
  204. });