jquery.layout.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /**
  2. * jQuery EasyUI 1.3.4
  3. *
  4. * Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the GPL or commercial licenses
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. * http://www.gnu.org/licenses/gpl.txt
  9. * http://www.jeasyui.com/license_commercial.php
  10. *
  11. */
  12. (function($){
  13. var _1=false;
  14. function _2(_3){
  15. var _4=$.data(_3,"layout");
  16. var _5=_4.options;
  17. var _6=_4.panels;
  18. var cc=$(_3);
  19. if(_3.tagName=="BODY"){
  20. cc._fit();
  21. }else{
  22. _5.fit?cc.css(cc._fit()):cc._fit(false);
  23. }
  24. function _7(pp){
  25. var _8=pp.panel("options");
  26. return Math.min(Math.max(_8.height,_8.minHeight),_8.maxHeight);
  27. };
  28. function _9(pp){
  29. var _a=pp.panel("options");
  30. return Math.min(Math.max(_a.width,_a.minWidth),_a.maxWidth);
  31. };
  32. var _b={top:0,left:0,width:cc.width(),height:cc.height()};
  33. function _c(pp){
  34. if(!pp.length){
  35. return;
  36. }
  37. var _d=_7(pp);
  38. pp.panel("resize",{width:cc.width(),height:_d,left:0,top:0});
  39. _b.top+=_d;
  40. _b.height-=_d;
  41. };
  42. if(_14(_6.expandNorth)){
  43. _c(_6.expandNorth);
  44. }else{
  45. _c(_6.north);
  46. }
  47. function _e(pp){
  48. if(!pp.length){
  49. return;
  50. }
  51. var _f=_7(pp);
  52. pp.panel("resize",{width:cc.width(),height:_f,left:0,top:cc.height()-_f});
  53. _b.height-=_f;
  54. };
  55. if(_14(_6.expandSouth)){
  56. _e(_6.expandSouth);
  57. }else{
  58. _e(_6.south);
  59. }
  60. function _10(pp){
  61. if(!pp.length){
  62. return;
  63. }
  64. var _11=_9(pp);
  65. pp.panel("resize",{width:_11,height:_b.height,left:cc.width()-_11,top:_b.top});
  66. _b.width-=_11;
  67. };
  68. if(_14(_6.expandEast)){
  69. _10(_6.expandEast);
  70. }else{
  71. _10(_6.east);
  72. }
  73. function _12(pp){
  74. if(!pp.length){
  75. return;
  76. }
  77. var _13=_9(pp);
  78. pp.panel("resize",{width:_13,height:_b.height,left:0,top:_b.top});
  79. _b.left+=_13;
  80. _b.width-=_13;
  81. };
  82. if(_14(_6.expandWest)){
  83. _12(_6.expandWest);
  84. }else{
  85. _12(_6.west);
  86. }
  87. _6.center.panel("resize",_b);
  88. };
  89. function _15(_16){
  90. var cc=$(_16);
  91. cc.addClass("layout");
  92. function _17(cc){
  93. cc.children("div").each(function(){
  94. var _18=$.fn.layout.parsePanelOptions(this);
  95. if("north,south,east,west,center".indexOf(_18.region)>=0){
  96. _1b(_16,_18,this);
  97. }
  98. });
  99. };
  100. cc.children("form").length?_17(cc.children("form")):_17(cc);
  101. cc.append("<div class=\"layout-split-proxy-h\"></div><div class=\"layout-split-proxy-v\"></div>");
  102. cc.bind("_resize",function(e,_19){
  103. var _1a=$.data(_16,"layout").options;
  104. if(_1a.fit==true||_19){
  105. _2(_16);
  106. }
  107. return false;
  108. });
  109. };
  110. function _1b(_1c,_1d,el){
  111. _1d.region=_1d.region||"center";
  112. var _1e=$.data(_1c,"layout").panels;
  113. var cc=$(_1c);
  114. var dir=_1d.region;
  115. if(_1e[dir].length){
  116. return;
  117. }
  118. var pp=$(el);
  119. if(!pp.length){
  120. pp=$("<div></div>").appendTo(cc);
  121. }
  122. var _1f=$.extend({},$.fn.layout.paneldefaults,{width:(pp.length?parseInt(pp[0].style.width)||pp.outerWidth():"auto"),height:(pp.length?parseInt(pp[0].style.height)||pp.outerHeight():"auto"),doSize:false,collapsible:true,cls:("layout-panel layout-panel-"+dir),bodyCls:"layout-body",onOpen:function(){
  123. var _20=$(this).panel("header").children("div.panel-tool");
  124. _20.children("a.panel-tool-collapse").hide();
  125. var _21={north:"up",south:"down",east:"right",west:"left"};
  126. if(!_21[dir]){
  127. return;
  128. }
  129. var _22="layout-button-"+_21[dir];
  130. var t=_20.children("a."+_22);
  131. if(!t.length){
  132. t=$("<a href=\"javascript:void(0)\"></a>").addClass(_22).appendTo(_20);
  133. t.bind("click",{dir:dir},function(e){
  134. _2f(_1c,e.data.dir);
  135. return false;
  136. });
  137. }
  138. $(this).panel("options").collapsible?t.show():t.hide();
  139. }},_1d);
  140. pp.panel(_1f);
  141. _1e[dir]=pp;
  142. if(pp.panel("options").split){
  143. var _23=pp.panel("panel");
  144. _23.addClass("layout-split-"+dir);
  145. var _24="";
  146. if(dir=="north"){
  147. _24="s";
  148. }
  149. if(dir=="south"){
  150. _24="n";
  151. }
  152. if(dir=="east"){
  153. _24="w";
  154. }
  155. if(dir=="west"){
  156. _24="e";
  157. }
  158. _23.resizable($.extend({},{handles:_24,onStartResize:function(e){
  159. _1=true;
  160. if(dir=="north"||dir=="south"){
  161. var _25=$(">div.layout-split-proxy-v",_1c);
  162. }else{
  163. var _25=$(">div.layout-split-proxy-h",_1c);
  164. }
  165. var top=0,_26=0,_27=0,_28=0;
  166. var pos={display:"block"};
  167. if(dir=="north"){
  168. pos.top=parseInt(_23.css("top"))+_23.outerHeight()-_25.height();
  169. pos.left=parseInt(_23.css("left"));
  170. pos.width=_23.outerWidth();
  171. pos.height=_25.height();
  172. }else{
  173. if(dir=="south"){
  174. pos.top=parseInt(_23.css("top"));
  175. pos.left=parseInt(_23.css("left"));
  176. pos.width=_23.outerWidth();
  177. pos.height=_25.height();
  178. }else{
  179. if(dir=="east"){
  180. pos.top=parseInt(_23.css("top"))||0;
  181. pos.left=parseInt(_23.css("left"))||0;
  182. pos.width=_25.width();
  183. pos.height=_23.outerHeight();
  184. }else{
  185. if(dir=="west"){
  186. pos.top=parseInt(_23.css("top"))||0;
  187. pos.left=_23.outerWidth()-_25.width();
  188. pos.width=_25.width();
  189. pos.height=_23.outerHeight();
  190. }
  191. }
  192. }
  193. }
  194. _25.css(pos);
  195. $("<div class=\"layout-mask\"></div>").css({left:0,top:0,width:cc.width(),height:cc.height()}).appendTo(cc);
  196. },onResize:function(e){
  197. if(dir=="north"||dir=="south"){
  198. var _29=$(">div.layout-split-proxy-v",_1c);
  199. _29.css("top",e.pageY-$(_1c).offset().top-_29.height()/2);
  200. }else{
  201. var _29=$(">div.layout-split-proxy-h",_1c);
  202. _29.css("left",e.pageX-$(_1c).offset().left-_29.width()/2);
  203. }
  204. return false;
  205. },onStopResize:function(e){
  206. cc.children("div.layout-split-proxy-v,div.layout-split-proxy-h").hide();
  207. pp.panel("resize",e.data);
  208. _2(_1c);
  209. _1=false;
  210. cc.find(">div.layout-mask").remove();
  211. }},_1d));
  212. }
  213. };
  214. function _2a(_2b,_2c){
  215. var _2d=$.data(_2b,"layout").panels;
  216. if(_2d[_2c].length){
  217. _2d[_2c].panel("destroy");
  218. _2d[_2c]=$();
  219. var _2e="expand"+_2c.substring(0,1).toUpperCase()+_2c.substring(1);
  220. if(_2d[_2e]){
  221. _2d[_2e].panel("destroy");
  222. _2d[_2e]=undefined;
  223. }
  224. }
  225. };
  226. function _2f(_30,_31,_32){
  227. if(_32==undefined){
  228. _32="normal";
  229. }
  230. var _33=$.data(_30,"layout").panels;
  231. var p=_33[_31];
  232. if(p.panel("options").onBeforeCollapse.call(p)==false){
  233. return;
  234. }
  235. var _34="expand"+_31.substring(0,1).toUpperCase()+_31.substring(1);
  236. if(!_33[_34]){
  237. _33[_34]=_35(_31);
  238. _33[_34].panel("panel").bind("click",function(){
  239. var _36=_37();
  240. p.panel("expand",false).panel("open").panel("resize",_36.collapse);
  241. p.panel("panel").animate(_36.expand,function(){
  242. $(this).unbind(".layout").bind("mouseleave.layout",{region:_31},function(e){
  243. if(_1==true){
  244. return;
  245. }
  246. _2f(_30,e.data.region);
  247. });
  248. });
  249. return false;
  250. });
  251. }
  252. var _38=_37();
  253. if(!_14(_33[_34])){
  254. _33.center.panel("resize",_38.resizeC);
  255. }
  256. p.panel("panel").animate(_38.collapse,_32,function(){
  257. p.panel("collapse",false).panel("close");
  258. _33[_34].panel("open").panel("resize",_38.expandP);
  259. $(this).unbind(".layout");
  260. });
  261. function _35(dir){
  262. var _39;
  263. if(dir=="east"){
  264. _39="layout-button-left";
  265. }else{
  266. if(dir=="west"){
  267. _39="layout-button-right";
  268. }else{
  269. if(dir=="north"){
  270. _39="layout-button-down";
  271. }else{
  272. if(dir=="south"){
  273. _39="layout-button-up";
  274. }
  275. }
  276. }
  277. }
  278. var _3a=$.extend({},$.fn.layout.paneldefaults,{cls:"layout-expand",title:"&nbsp;",closed:true,doSize:false,tools:[{iconCls:_39,handler:function(){
  279. _3e(_30,_31);
  280. return false;
  281. }}]});
  282. var p=$("<div></div>").appendTo(_30).panel(_3a);
  283. p.panel("panel").hover(function(){
  284. $(this).addClass("layout-expand-over");
  285. },function(){
  286. $(this).removeClass("layout-expand-over");
  287. });
  288. return p;
  289. };
  290. function _37(){
  291. var cc=$(_30);
  292. var _3b=_33.center.panel("options");
  293. if(_31=="east"){
  294. var _3c=_33["east"].panel("options");
  295. return {resizeC:{width:_3b.width+_3c.width-28},expand:{left:cc.width()-_3c.width},expandP:{top:_3b.top,left:cc.width()-28,width:28,height:_3b.height},collapse:{left:cc.width(),top:_3b.top,height:_3b.height}};
  296. }else{
  297. if(_31=="west"){
  298. var _3d=_33["west"].panel("options");
  299. return {resizeC:{width:_3b.width+_3d.width-28,left:28},expand:{left:0},expandP:{left:0,top:_3b.top,width:28,height:_3b.height},collapse:{left:-_3d.width,top:_3b.top,height:_3b.height}};
  300. }else{
  301. if(_31=="north"){
  302. var hh=cc.height()-28;
  303. if(_14(_33.expandSouth)){
  304. hh-=_33.expandSouth.panel("options").height;
  305. }else{
  306. if(_14(_33.south)){
  307. hh-=_33.south.panel("options").height;
  308. }
  309. }
  310. _33.east.panel("resize",{top:28,height:hh});
  311. _33.west.panel("resize",{top:28,height:hh});
  312. if(_14(_33.expandEast)){
  313. _33.expandEast.panel("resize",{top:28,height:hh});
  314. }
  315. if(_14(_33.expandWest)){
  316. _33.expandWest.panel("resize",{top:28,height:hh});
  317. }
  318. return {resizeC:{top:28,height:hh},expand:{top:0},expandP:{top:0,left:0,width:cc.width(),height:28},collapse:{top:-_33["north"].panel("options").height,width:cc.width()}};
  319. }else{
  320. if(_31=="south"){
  321. var hh=cc.height()-28;
  322. if(_14(_33.expandNorth)){
  323. hh-=_33.expandNorth.panel("options").height;
  324. }else{
  325. if(_14(_33.north)){
  326. hh-=_33.north.panel("options").height;
  327. }
  328. }
  329. _33.east.panel("resize",{height:hh});
  330. _33.west.panel("resize",{height:hh});
  331. if(_14(_33.expandEast)){
  332. _33.expandEast.panel("resize",{height:hh});
  333. }
  334. if(_14(_33.expandWest)){
  335. _33.expandWest.panel("resize",{height:hh});
  336. }
  337. return {resizeC:{height:hh},expand:{top:cc.height()-_33["south"].panel("options").height},expandP:{top:cc.height()-28,left:0,width:cc.width(),height:28},collapse:{top:cc.height(),width:cc.width()}};
  338. }
  339. }
  340. }
  341. }
  342. };
  343. };
  344. function _3e(_3f,_40){
  345. var _41=$.data(_3f,"layout").panels;
  346. var _42=_43();
  347. var p=_41[_40];
  348. if(p.panel("options").onBeforeExpand.call(p)==false){
  349. return;
  350. }
  351. var _44="expand"+_40.substring(0,1).toUpperCase()+_40.substring(1);
  352. _41[_44].panel("close");
  353. p.panel("panel").stop(true,true);
  354. p.panel("expand",false).panel("open").panel("resize",_42.collapse);
  355. p.panel("panel").animate(_42.expand,function(){
  356. _2(_3f);
  357. });
  358. function _43(){
  359. var cc=$(_3f);
  360. var _45=_41.center.panel("options");
  361. if(_40=="east"&&_41.expandEast){
  362. return {collapse:{left:cc.width(),top:_45.top,height:_45.height},expand:{left:cc.width()-_41["east"].panel("options").width}};
  363. }else{
  364. if(_40=="west"&&_41.expandWest){
  365. return {collapse:{left:-_41["west"].panel("options").width,top:_45.top,height:_45.height},expand:{left:0}};
  366. }else{
  367. if(_40=="north"&&_41.expandNorth){
  368. return {collapse:{top:-_41["north"].panel("options").height,width:cc.width()},expand:{top:0}};
  369. }else{
  370. if(_40=="south"&&_41.expandSouth){
  371. return {collapse:{top:cc.height(),width:cc.width()},expand:{top:cc.height()-_41["south"].panel("options").height}};
  372. }
  373. }
  374. }
  375. }
  376. };
  377. };
  378. function _14(pp){
  379. if(!pp){
  380. return false;
  381. }
  382. if(pp.length){
  383. return pp.panel("panel").is(":visible");
  384. }else{
  385. return false;
  386. }
  387. };
  388. function _46(_47){
  389. var _48=$.data(_47,"layout").panels;
  390. if(_48.east.length&&_48.east.panel("options").collapsed){
  391. _2f(_47,"east",0);
  392. }
  393. if(_48.west.length&&_48.west.panel("options").collapsed){
  394. _2f(_47,"west",0);
  395. }
  396. if(_48.north.length&&_48.north.panel("options").collapsed){
  397. _2f(_47,"north",0);
  398. }
  399. if(_48.south.length&&_48.south.panel("options").collapsed){
  400. _2f(_47,"south",0);
  401. }
  402. };
  403. $.fn.layout=function(_49,_4a){
  404. if(typeof _49=="string"){
  405. return $.fn.layout.methods[_49](this,_4a);
  406. }
  407. _49=_49||{};
  408. return this.each(function(){
  409. var _4b=$.data(this,"layout");
  410. if(_4b){
  411. $.extend(_4b.options,_49);
  412. }else{
  413. var _4c=$.extend({},$.fn.layout.defaults,$.fn.layout.parseOptions(this),_49);
  414. $.data(this,"layout",{options:_4c,panels:{center:$(),north:$(),south:$(),east:$(),west:$()}});
  415. _15(this);
  416. }
  417. _2(this);
  418. _46(this);
  419. });
  420. };
  421. $.fn.layout.methods={resize:function(jq){
  422. return jq.each(function(){
  423. _2(this);
  424. });
  425. },panel:function(jq,_4d){
  426. return $.data(jq[0],"layout").panels[_4d];
  427. },collapse:function(jq,_4e){
  428. return jq.each(function(){
  429. _2f(this,_4e);
  430. });
  431. },expand:function(jq,_4f){
  432. return jq.each(function(){
  433. _3e(this,_4f);
  434. });
  435. },add:function(jq,_50){
  436. return jq.each(function(){
  437. _1b(this,_50);
  438. _2(this);
  439. if($(this).layout("panel",_50.region).panel("options").collapsed){
  440. _2f(this,_50.region,0);
  441. }
  442. });
  443. },remove:function(jq,_51){
  444. return jq.each(function(){
  445. _2a(this,_51);
  446. _2(this);
  447. });
  448. }};
  449. $.fn.layout.parseOptions=function(_52){
  450. return $.extend({},$.parser.parseOptions(_52,[{fit:"boolean"}]));
  451. };
  452. $.fn.layout.defaults={fit:false};
  453. $.fn.layout.parsePanelOptions=function(_53){
  454. var t=$(_53);
  455. return $.extend({},$.fn.panel.parseOptions(_53),$.parser.parseOptions(_53,["region",{split:"boolean",minWidth:"number",minHeight:"number",maxWidth:"number",maxHeight:"number"}]));
  456. };
  457. $.fn.layout.paneldefaults=$.extend({},$.fn.panel.defaults,{region:null,split:false,minWidth:10,minHeight:10,maxWidth:10000,maxHeight:10000});
  458. })(jQuery);