ExpandoPane.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. require({cache:{
  2. 'url:dojox/layout/resources/ExpandoPane.html':"<div class=\"dojoxExpandoPane\">\n\t<div dojoAttachPoint=\"titleWrapper\" class=\"dojoxExpandoTitle\">\n\t\t<div class=\"dojoxExpandoIcon\" dojoAttachPoint=\"iconNode\" dojoAttachEvent=\"onclick:toggle\"><span class=\"a11yNode\">X</span></div>\t\t\t\n\t\t<span class=\"dojoxExpandoTitleNode\" dojoAttachPoint=\"titleNode\">${title}</span>\n\t</div>\n\t<div class=\"dojoxExpandoWrapper\" dojoAttachPoint=\"cwrapper\" dojoAttachEvent=\"ondblclick:_trap\">\n\t\t<div class=\"dojoxExpandoContent\" dojoAttachPoint=\"containerNode\"></div>\n\t</div>\n</div>\n"}});
  3. define("dojox/layout/ExpandoPane", ["dojo/_base/kernel","dojo/_base/lang","dojo/_base/declare","dojo/_base/array",
  4. "dojo/_base/connect","dojo/_base/event","dojo/_base/fx","dojo/dom-style",
  5. "dojo/dom-class","dojo/dom-geometry","dojo/text!./resources/ExpandoPane.html",
  6. "dijit/layout/ContentPane","dijit/_TemplatedMixin","dijit/_Contained","dijit/_Container"],
  7. function(kernel,lang,declare,arrayUtil,connectUtil,eventUtil,baseFx,domStyle,domClass,domGeom,
  8. template,ContentPane,TemplatedMixin,Contained,Container) {
  9. /*=====
  10. var ContentPane = dijit.layout.ContentPane;
  11. var TemplatedMixin = dijit._TemplatedMixin;
  12. var Contained = dijit._Contained;
  13. var Container = dijit._Container;
  14. =====*/
  15. kernel.experimental("dojox.layout.ExpandoPane"); // just to show it can be done?
  16. return declare("dojox.layout.ExpandoPane", [ContentPane, TemplatedMixin, Contained, Container],{
  17. // summary: An experimental collapsing-pane for dijit.layout.BorderContainer
  18. //
  19. // description:
  20. // Works just like a ContentPane inside of a borderContainer. Will expand/collapse on
  21. // command, and supports having Layout Children as direct descendants
  22. //
  23. //maxHeight: "",
  24. //maxWidth: "",
  25. //splitter: false,
  26. attributeMap: lang.delegate(ContentPane.prototype.attributeMap, {
  27. title: { node: "titleNode", type: "innerHTML" }
  28. }),
  29. templateString: template,
  30. // easeOut: String|Function
  31. // easing function used to hide pane
  32. easeOut: "dojo._DefaultEasing", // FIXME: This won't work with globalless AMD
  33. // easeIn: String|Function
  34. // easing function use to show pane
  35. easeIn: "dojo._DefaultEasing", // FIXME: This won't work with globalless AMD
  36. // duration: Integer
  37. // duration to run show/hide animations
  38. duration: 420,
  39. // startExpanded: Boolean
  40. // Does this widget start in an open (true) or closed (false) state
  41. startExpanded: true,
  42. // previewOpacity: Float
  43. // A value from 0 .. 1 indicating the opacity to use on the container
  44. // when only showing a preview
  45. previewOpacity: 0.75,
  46. // previewOnDblClick: Boolean
  47. // If true, will override the default behavior of a double-click calling a full toggle.
  48. // If false, a double-click will cause the preview to popup
  49. previewOnDblClick: false,
  50. baseClass: "dijitExpandoPane",
  51. postCreate: function(){
  52. this.inherited(arguments);
  53. this._animConnects = [];
  54. this._isHorizontal = true;
  55. if(lang.isString(this.easeOut)){
  56. this.easeOut = lang.getObject(this.easeOut);
  57. }
  58. if(lang.isString(this.easeIn)){
  59. this.easeIn = lang.getObject(this.easeIn);
  60. }
  61. var thisClass = "", rtl = !this.isLeftToRight();
  62. if(this.region){
  63. switch(this.region){
  64. case "trailing" :
  65. case "right" :
  66. thisClass = rtl ? "Left" : "Right";
  67. break;
  68. case "leading" :
  69. case "left" :
  70. thisClass = rtl ? "Right" : "Left";
  71. break;
  72. case "top" :
  73. thisClass = "Top";
  74. break;
  75. case "bottom" :
  76. thisClass = "Bottom";
  77. break;
  78. }
  79. domClass.add(this.domNode, "dojoxExpando" + thisClass);
  80. domClass.add(this.iconNode, "dojoxExpandoIcon" + thisClass);
  81. this._isHorizontal = /top|bottom/.test(this.region);
  82. }
  83. domStyle.set(this.domNode, {
  84. overflow: "hidden",
  85. padding:0
  86. });
  87. this.connect(this.domNode, "ondblclick", this.previewOnDblClick ? "preview" : "toggle");
  88. if(this.previewOnDblClick){
  89. this.connect(this.getParent(), "_layoutChildren", lang.hitch(this, function(){
  90. this._isonlypreview = false;
  91. }));
  92. }
  93. },
  94. _startupSizes: function(){
  95. this._container = this.getParent();
  96. this._closedSize = this._titleHeight = domGeom.getMarginBox(this.titleWrapper).h;
  97. if(this.splitter){
  98. // find our splitter and tie into it's drag logic
  99. var myid = this.id;
  100. arrayUtil.forEach(dijit.registry.toArray(), function(w){
  101. if(w && w.child && w.child.id == myid){
  102. this.connect(w,"_stopDrag","_afterResize");
  103. }
  104. }, this);
  105. }
  106. this._currentSize = domGeom.getContentBox(this.domNode); // TODO: can compute this from passed in value to resize(), see _LayoutWidget for example
  107. this._showSize = this._currentSize[(this._isHorizontal ? "h" : "w")];
  108. this._setupAnims();
  109. if(this.startExpanded){
  110. this._showing = true;
  111. }else{
  112. this._showing = false;
  113. this._hideWrapper();
  114. this._hideAnim.gotoPercent(99,true);
  115. }
  116. this._hasSizes = true;
  117. },
  118. _afterResize: function(e){
  119. var tmp = this._currentSize; // the old size
  120. this._currentSize = domGeom.getMarginBox(this.domNode); // the new size
  121. var n = this._currentSize[(this._isHorizontal ? "h" : "w")]
  122. if(n > this._titleHeight){
  123. if(!this._showing){
  124. this._showing = !this._showing;
  125. this._showEnd();
  126. }
  127. this._showSize = n;
  128. this._setupAnims();
  129. }else{
  130. this._showSize = tmp[(this._isHorizontal ? "h" : "w")];
  131. this._showing = false;
  132. this._hideWrapper();
  133. this._hideAnim.gotoPercent(89,true);
  134. }
  135. },
  136. _setupAnims: function(){
  137. // summary: Create the show and hide animations
  138. arrayUtil.forEach(this._animConnects, connectUtil.disconnect);
  139. var _common = {
  140. node:this.domNode,
  141. duration:this.duration
  142. },
  143. isHorizontal = this._isHorizontal,
  144. showProps = {},
  145. hideProps = {},
  146. dimension = isHorizontal ? "height" : "width"
  147. ;
  148. showProps[dimension] = {
  149. end: this._showSize
  150. };
  151. hideProps[dimension] = {
  152. end: this._closedSize
  153. };
  154. this._showAnim = baseFx.animateProperty(lang.mixin(_common,{
  155. easing:this.easeIn,
  156. properties: showProps
  157. }));
  158. this._hideAnim = baseFx.animateProperty(lang.mixin(_common,{
  159. easing:this.easeOut,
  160. properties: hideProps
  161. }));
  162. this._animConnects = [
  163. connectUtil.connect(this._showAnim, "onEnd", this, "_showEnd"),
  164. connectUtil.connect(this._hideAnim, "onEnd", this, "_hideEnd")
  165. ];
  166. },
  167. preview: function(){
  168. // summary: Expand this pane in preview mode (does not affect surrounding layout)
  169. if(!this._showing){
  170. this._isonlypreview = !this._isonlypreview;
  171. }
  172. this.toggle();
  173. },
  174. toggle: function(){
  175. // summary: Toggle this pane's visibility
  176. if(this._showing){
  177. this._hideWrapper();
  178. this._showAnim && this._showAnim.stop();
  179. this._hideAnim.play();
  180. }else{
  181. this._hideAnim && this._hideAnim.stop();
  182. this._showAnim.play();
  183. }
  184. this._showing = !this._showing;
  185. },
  186. _hideWrapper: function(){
  187. // summary: Set the Expando state to "closed"
  188. domClass.add(this.domNode, "dojoxExpandoClosed");
  189. domStyle.set(this.cwrapper,{
  190. visibility: "hidden",
  191. opacity: "0",
  192. overflow: "hidden"
  193. });
  194. },
  195. _showEnd: function(){
  196. // summary: Common animation onEnd code - "unclose"
  197. domStyle.set(this.cwrapper, {
  198. opacity: 0,
  199. visibility:"visible"
  200. });
  201. baseFx.anim(this.cwrapper, {
  202. opacity: this._isonlypreview ? this.previewOpacity : 1
  203. }, 227);
  204. domClass.remove(this.domNode, "dojoxExpandoClosed");
  205. if(!this._isonlypreview){
  206. setTimeout(lang.hitch(this._container, "layout"), 15);
  207. }else{
  208. this._previewShowing = true;
  209. this.resize();
  210. }
  211. },
  212. _hideEnd: function(){
  213. // summary: Callback for the hide animation - "close"
  214. // every time we hide, reset the "only preview" state
  215. if(!this._isonlypreview){
  216. setTimeout(lang.hitch(this._container, "layout"), 25);
  217. }else{
  218. this._previewShowing = false;
  219. }
  220. this._isonlypreview = false;
  221. },
  222. resize: function(/* Object? */newSize){
  223. // summary:
  224. // we aren't a layout widget, but need to act like one:
  225. // newSize: Object
  226. // The size object to resize to
  227. if(!this._hasSizes){ this._startupSizes(newSize); }
  228. // compute size of container (ie, size left over after title bar)
  229. var currentSize = domGeom.getMarginBox(this.domNode);
  230. this._contentBox = {
  231. w: newSize && "w" in newSize ? newSize.w : currentSize.w,
  232. h: (newSize && "h" in newSize ? newSize.h : currentSize.h) - this._titleHeight
  233. };
  234. domStyle.set(this.containerNode, "height", this._contentBox.h + "px");
  235. if(newSize){
  236. domGeom.setMarginBox(this.domNode, newSize);
  237. }
  238. this._layoutChildren();
  239. },
  240. _trap: function(e){
  241. // summary: Trap stray events
  242. eventUtil.stop(e);
  243. }
  244. });
  245. });