jquery.layout.js 11 KB

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