c295c53eb7f0a75b37f39064fc7da45a5175dbcb.svn-base 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. /**
  7. * @class Ext.SplitLayoutRegion
  8. * @extends Ext.LayoutRegion Adds a splitbar and other (private) useful
  9. * functionality to a {@link Ext.LayoutRegion}.
  10. */
  11. Ext.SplitLayoutRegion = function(mgr, config, pos, cursor) {
  12. this.cursor = cursor;
  13. Ext.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
  14. };
  15. Ext.extend(Ext.SplitLayoutRegion, Ext.LayoutRegion, {
  16. splitTip : "Drag to resize.",
  17. collapsibleSplitTip : "Drag to resize. Double click to hide.",
  18. useSplitTips : false,
  19. applyConfig : function(config) {
  20. Ext.SplitLayoutRegion.superclass.applyConfig.call(this, config);
  21. if (config.split) {
  22. if (!this.split) {
  23. var splitEl = Ext.DomHelper.append(this.mgr.el.dom, {
  24. tag : "div",
  25. id : this.el.id + "-split",
  26. cls : "x-layout-split x-layout-split-"
  27. + this.position,
  28. html : " "
  29. });
  30. /**
  31. * The SplitBar for this region
  32. *
  33. * @type Ext.SplitBar
  34. */
  35. this.split = new Ext.SplitBar(splitEl, this.el,
  36. this.orientation);
  37. this.split.on("moved", this.onSplitMove, this);
  38. this.split.useShim = config.useShim === true;
  39. this.split.getMaximumSize = this[this.position == 'north'
  40. || this.position == 'south'
  41. ? 'getVMaxSize'
  42. : 'getHMaxSize'].createDelegate(this);
  43. if (this.useSplitTips) {
  44. this.split.el.dom.title = config.collapsible
  45. ? this.collapsibleSplitTip
  46. : this.splitTip;
  47. }
  48. if (config.collapsible) {
  49. this.split.el.on("dblclick", this.collapse, this);
  50. }
  51. }
  52. if (typeof config.minSize != "undefined") {
  53. this.split.minSize = config.minSize;
  54. }
  55. if (typeof config.maxSize != "undefined") {
  56. this.split.maxSize = config.maxSize;
  57. }
  58. if (config.hideWhenEmpty || config.hidden) {
  59. this.hideSplitter();
  60. }
  61. }
  62. },
  63. getHMaxSize : function() {
  64. var cmax = this.config.maxSize || 10000;
  65. var center = this.mgr.getRegion("center");
  66. return Math.min(cmax, (this.el.getWidth() + center.getEl()
  67. .getWidth())
  68. - center.getMinWidth());
  69. },
  70. getVMaxSize : function() {
  71. var cmax = this.config.maxSize || 10000;
  72. var center = this.mgr.getRegion("center");
  73. return Math.min(cmax, (this.el.getHeight() + center.getEl()
  74. .getHeight())
  75. - center.getMinHeight());
  76. },
  77. onSplitMove : function(split, newSize) {
  78. this.fireEvent("resized", this, newSize);
  79. },
  80. /**
  81. * Returns the {@link Ext.SplitBar} for this region.
  82. *
  83. * @return {Ext.SplitBar}
  84. */
  85. getSplitBar : function() {
  86. return this.split;
  87. },
  88. hide : function() {
  89. this.hideSplitter();
  90. Ext.SplitLayoutRegion.superclass.hide.call(this);
  91. },
  92. hideSplitter : function() {
  93. if (this.split) {
  94. this.split.el.setLocation(-2000, -2000);
  95. this.split.el.hide();
  96. }
  97. },
  98. show : function() {
  99. if (this.split) {
  100. this.split.el.show();
  101. }
  102. Ext.SplitLayoutRegion.superclass.show.call(this);
  103. },
  104. beforeSlide : function() {
  105. if (Ext.isGecko) {// firefox overflow auto bug workaround
  106. this.bodyEl.clip();
  107. if (this.tabs)
  108. this.tabs.bodyEl.clip();
  109. if (this.activePanel) {
  110. this.activePanel.getEl().clip();
  111. if (this.activePanel.beforeSlide) {
  112. this.activePanel.beforeSlide();
  113. }
  114. }
  115. }
  116. },
  117. afterSlide : function() {
  118. if (Ext.isGecko) {// firefox overflow auto bug workaround
  119. this.bodyEl.unclip();
  120. if (this.tabs)
  121. this.tabs.bodyEl.unclip();
  122. if (this.activePanel) {
  123. this.activePanel.getEl().unclip();
  124. if (this.activePanel.afterSlide) {
  125. this.activePanel.afterSlide();
  126. }
  127. }
  128. }
  129. },
  130. initAutoHide : function() {
  131. if (this.autoHide !== false) {
  132. if (!this.autoHideHd) {
  133. var st = new Ext.util.DelayedTask(this.slideIn, this);
  134. this.autoHideHd = {
  135. "mouseout" : function(e) {
  136. if (!e.within(this.el, true)) {
  137. st.delay(500);
  138. }
  139. },
  140. "mouseover" : function(e) {
  141. st.cancel();
  142. },
  143. scope : this
  144. };
  145. }
  146. this.el.on(this.autoHideHd);
  147. }
  148. },
  149. clearAutoHide : function() {
  150. if (this.autoHide !== false) {
  151. this.el.un("mouseout", this.autoHideHd.mouseout);
  152. this.el.un("mouseover", this.autoHideHd.mouseover);
  153. }
  154. },
  155. clearMonitor : function() {
  156. Ext.getDoc().un("click", this.slideInIf, this);
  157. },
  158. // these names are backwards but not changed for compat
  159. slideOut : function() {
  160. if (this.isSlid || this.el.hasActiveFx()) {
  161. return;
  162. }
  163. this.isSlid = true;
  164. if (this.collapseBtn) {
  165. this.collapseBtn.hide();
  166. }
  167. this.closeBtnState = this.closeBtn.getStyle('display');
  168. this.closeBtn.hide();
  169. if (this.stickBtn) {
  170. this.stickBtn.show();
  171. }
  172. this.el.show();
  173. this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
  174. this.beforeSlide();
  175. this.el.setStyle("z-index", 10001);
  176. this.el.slideIn(this.getSlideAnchor(), {
  177. callback : function() {
  178. this.afterSlide();
  179. this.initAutoHide();
  180. Ext.getDoc().on("click", this.slideInIf, this);
  181. this.fireEvent("slideshow", this);
  182. },
  183. scope : this,
  184. block : true
  185. });
  186. },
  187. afterSlideIn : function() {
  188. this.clearAutoHide();
  189. this.isSlid = false;
  190. this.clearMonitor();
  191. this.el.setStyle("z-index", "");
  192. if (this.collapseBtn) {
  193. this.collapseBtn.show();
  194. }
  195. this.closeBtn.setStyle('display', this.closeBtnState);
  196. if (this.stickBtn) {
  197. this.stickBtn.hide();
  198. }
  199. this.fireEvent("slidehide", this);
  200. },
  201. slideIn : function(cb) {
  202. if (!this.isSlid || this.el.hasActiveFx()) {
  203. Ext.callback(cb);
  204. return;
  205. }
  206. this.isSlid = false;
  207. this.beforeSlide();
  208. this.el.slideOut(this.getSlideAnchor(), {
  209. callback : function() {
  210. this.el.setLeftTop(-10000, -10000);
  211. this.afterSlide();
  212. this.afterSlideIn();
  213. Ext.callback(cb);
  214. },
  215. scope : this,
  216. block : true
  217. });
  218. },
  219. slideInIf : function(e) {
  220. if (!e.within(this.el)) {
  221. this.slideIn();
  222. }
  223. },
  224. animateCollapse : function() {
  225. this.beforeSlide();
  226. this.el.setStyle("z-index", 20000);
  227. var anchor = this.getSlideAnchor();
  228. this.el.slideOut(anchor, {
  229. callback : function() {
  230. this.el.setStyle("z-index", "");
  231. this.collapsedEl.slideIn(anchor, {
  232. duration : .3
  233. });
  234. this.afterSlide();
  235. this.el.setLocation(-10000, -10000);
  236. this.el.hide();
  237. this.fireEvent("collapsed", this);
  238. },
  239. scope : this,
  240. block : true
  241. });
  242. },
  243. animateExpand : function() {
  244. this.beforeSlide();
  245. this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(),
  246. this.getExpandAdj());
  247. this.el.setStyle("z-index", 20000);
  248. this.collapsedEl.hide({
  249. duration : .1
  250. });
  251. this.el.slideIn(this.getSlideAnchor(), {
  252. callback : function() {
  253. this.el.setStyle("z-index", "");
  254. this.afterSlide();
  255. if (this.split) {
  256. this.split.el.show();
  257. }
  258. this.fireEvent("invalidated", this);
  259. this.fireEvent("expanded", this);
  260. },
  261. scope : this,
  262. block : true
  263. });
  264. },
  265. anchors : {
  266. "west" : "left",
  267. "east" : "right",
  268. "north" : "top",
  269. "south" : "bottom"
  270. },
  271. sanchors : {
  272. "west" : "l",
  273. "east" : "r",
  274. "north" : "t",
  275. "south" : "b"
  276. },
  277. canchors : {
  278. "west" : "tl-tr",
  279. "east" : "tr-tl",
  280. "north" : "tl-bl",
  281. "south" : "bl-tl"
  282. },
  283. getAnchor : function() {
  284. return this.anchors[this.position];
  285. },
  286. getCollapseAnchor : function() {
  287. return this.canchors[this.position];
  288. },
  289. getSlideAnchor : function() {
  290. return this.sanchors[this.position];
  291. },
  292. getAlignAdj : function() {
  293. var cm = this.cmargins;
  294. switch (this.position) {
  295. case "west" :
  296. return [0, 0];
  297. break;
  298. case "east" :
  299. return [0, 0];
  300. break;
  301. case "north" :
  302. return [0, 0];
  303. break;
  304. case "south" :
  305. return [0, 0];
  306. break;
  307. }
  308. },
  309. getExpandAdj : function() {
  310. var c = this.collapsedEl, cm = this.cmargins;
  311. switch (this.position) {
  312. case "west" :
  313. return [-(cm.right + c.getWidth() + cm.left), 0];
  314. break;
  315. case "east" :
  316. return [cm.right + c.getWidth() + cm.left, 0];
  317. break;
  318. case "north" :
  319. return [0, -(cm.top + cm.bottom + c.getHeight())];
  320. break;
  321. case "south" :
  322. return [0, cm.top + cm.bottom + c.getHeight()];
  323. break;
  324. }
  325. }
  326. });