jquery.layout.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /**
  2. * jQuery EasyUI 1.4.1
  3. *
  4. * Copyright (c) 2009-2014 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,cls:("layout-panel layout-panel-"+dir),bodyCls:"layout-body",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);
  120. pp.panel(_1b);
  121. _1a[dir]=pp;
  122. if(pp.panel("options").split){
  123. var _1f=pp.panel("panel");
  124. _1f.addClass("layout-split-"+dir);
  125. var _20="";
  126. if(dir=="north"){
  127. _20="s";
  128. }
  129. if(dir=="south"){
  130. _20="n";
  131. }
  132. if(dir=="east"){
  133. _20="w";
  134. }
  135. if(dir=="west"){
  136. _20="e";
  137. }
  138. _1f.resizable($.extend({},{handles:_20,onStartResize:function(e){
  139. _1=true;
  140. if(dir=="north"||dir=="south"){
  141. var _21=$(">div.layout-split-proxy-v",_18);
  142. }else{
  143. var _21=$(">div.layout-split-proxy-h",_18);
  144. }
  145. var top=0,_22=0,_23=0,_24=0;
  146. var pos={display:"block"};
  147. if(dir=="north"){
  148. pos.top=parseInt(_1f.css("top"))+_1f.outerHeight()-_21.height();
  149. pos.left=parseInt(_1f.css("left"));
  150. pos.width=_1f.outerWidth();
  151. pos.height=_21.height();
  152. }else{
  153. if(dir=="south"){
  154. pos.top=parseInt(_1f.css("top"));
  155. pos.left=parseInt(_1f.css("left"));
  156. pos.width=_1f.outerWidth();
  157. pos.height=_21.height();
  158. }else{
  159. if(dir=="east"){
  160. pos.top=parseInt(_1f.css("top"))||0;
  161. pos.left=parseInt(_1f.css("left"))||0;
  162. pos.width=_21.width();
  163. pos.height=_1f.outerHeight();
  164. }else{
  165. if(dir=="west"){
  166. pos.top=parseInt(_1f.css("top"))||0;
  167. pos.left=_1f.outerWidth()-_21.width();
  168. pos.width=_21.width();
  169. pos.height=_1f.outerHeight();
  170. }
  171. }
  172. }
  173. }
  174. _21.css(pos);
  175. $("<div class=\"layout-mask\"></div>").css({left:0,top:0,width:cc.width(),height:cc.height()}).appendTo(cc);
  176. },onResize:function(e){
  177. if(dir=="north"||dir=="south"){
  178. var _25=$(">div.layout-split-proxy-v",_18);
  179. _25.css("top",e.pageY-$(_18).offset().top-_25.height()/2);
  180. }else{
  181. var _25=$(">div.layout-split-proxy-h",_18);
  182. _25.css("left",e.pageX-$(_18).offset().left-_25.width()/2);
  183. }
  184. return false;
  185. },onStopResize:function(e){
  186. cc.children("div.layout-split-proxy-v,div.layout-split-proxy-h").hide();
  187. pp.panel("resize",e.data);
  188. _2(_18);
  189. _1=false;
  190. cc.find(">div.layout-mask").remove();
  191. }},_19));
  192. }
  193. };
  194. function _26(_27,_28){
  195. var _29=$.data(_27,"layout").panels;
  196. if(_29[_28].length){
  197. _29[_28].panel("destroy");
  198. _29[_28]=$();
  199. var _2a="expand"+_28.substring(0,1).toUpperCase()+_28.substring(1);
  200. if(_29[_2a]){
  201. _29[_2a].panel("destroy");
  202. _29[_2a]=undefined;
  203. }
  204. }
  205. };
  206. function _2b(_2c,_2d,_2e){
  207. if(_2e==undefined){
  208. _2e="normal";
  209. }
  210. var _2f=$.data(_2c,"layout").panels;
  211. var p=_2f[_2d];
  212. var _30=p.panel("options");
  213. if(_30.onBeforeCollapse.call(p)==false){
  214. return;
  215. }
  216. var _31="expand"+_2d.substring(0,1).toUpperCase()+_2d.substring(1);
  217. if(!_2f[_31]){
  218. _2f[_31]=_32(_2d);
  219. _2f[_31].panel("panel").bind("click",function(){
  220. p.panel("expand",false).panel("open");
  221. var _33=_34();
  222. p.panel("resize",_33.collapse);
  223. p.panel("panel").animate(_33.expand,function(){
  224. $(this).unbind(".layout").bind("mouseleave.layout",{region:_2d},function(e){
  225. if(_1==true){
  226. return;
  227. }
  228. if($("body>div.combo-p>div.combo-panel:visible").length){
  229. return;
  230. }
  231. _2b(_2c,e.data.region);
  232. });
  233. });
  234. return false;
  235. });
  236. }
  237. var _35=_34();
  238. if(!_a(_2f[_31])){
  239. _2f.center.panel("resize",_35.resizeC);
  240. }
  241. p.panel("panel").animate(_35.collapse,_2e,function(){
  242. p.panel("collapse",false).panel("close");
  243. _2f[_31].panel("open").panel("resize",_35.expandP);
  244. $(this).unbind(".layout");
  245. });
  246. function _32(dir){
  247. var _36;
  248. if(dir=="east"){
  249. _36="layout-button-left";
  250. }else{
  251. if(dir=="west"){
  252. _36="layout-button-right";
  253. }else{
  254. if(dir=="north"){
  255. _36="layout-button-down";
  256. }else{
  257. if(dir=="south"){
  258. _36="layout-button-up";
  259. }
  260. }
  261. }
  262. }
  263. var p=$("<div></div>").appendTo(_2c);
  264. 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(){
  265. _3c(_2c,_2d);
  266. return false;
  267. }}]}));
  268. p.panel("panel").hover(function(){
  269. $(this).addClass("layout-expand-over");
  270. },function(){
  271. $(this).removeClass("layout-expand-over");
  272. });
  273. return p;
  274. };
  275. function _34(){
  276. var cc=$(_2c);
  277. var _37=_2f.center.panel("options");
  278. var _38=_30.collapsedSize;
  279. if(_2d=="east"){
  280. var _39=p.panel("panel")._outerWidth();
  281. var _3a=_37.width+_39-_38;
  282. if(_30.split||!_30.border){
  283. _3a++;
  284. }
  285. 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}};
  286. }else{
  287. if(_2d=="west"){
  288. var _39=p.panel("panel")._outerWidth();
  289. var _3a=_37.width+_39-_38;
  290. if(_30.split||!_30.border){
  291. _3a++;
  292. }
  293. 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}};
  294. }else{
  295. if(_2d=="north"){
  296. var _3b=p.panel("panel")._outerHeight();
  297. var hh=_37.height;
  298. if(!_a(_2f.expandNorth)){
  299. hh+=_3b-_38+((_30.split||!_30.border)?1:0);
  300. }
  301. _2f.east.add(_2f.west).add(_2f.expandEast).add(_2f.expandWest).panel("resize",{top:_38-1,height:hh});
  302. 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()}};
  303. }else{
  304. if(_2d=="south"){
  305. var _3b=p.panel("panel")._outerHeight();
  306. var hh=_37.height;
  307. if(!_a(_2f.expandSouth)){
  308. hh+=_3b-_38+((_30.split||!_30.border)?1:0);
  309. }
  310. _2f.east.add(_2f.west).add(_2f.expandEast).add(_2f.expandWest).panel("resize",{height:hh});
  311. 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()}};
  312. }
  313. }
  314. }
  315. }
  316. };
  317. };
  318. function _3c(_3d,_3e){
  319. var _3f=$.data(_3d,"layout").panels;
  320. var p=_3f[_3e];
  321. var _40=p.panel("options");
  322. if(_40.onBeforeExpand.call(p)==false){
  323. return;
  324. }
  325. var _41="expand"+_3e.substring(0,1).toUpperCase()+_3e.substring(1);
  326. if(_3f[_41]){
  327. _3f[_41].panel("close");
  328. p.panel("panel").stop(true,true);
  329. p.panel("expand",false).panel("open");
  330. var _42=_43();
  331. p.panel("resize",_42.collapse);
  332. p.panel("panel").animate(_42.expand,function(){
  333. _2(_3d);
  334. });
  335. }
  336. function _43(){
  337. var cc=$(_3d);
  338. var _44=_3f.center.panel("options");
  339. if(_3e=="east"&&_3f.expandEast){
  340. return {collapse:{left:cc.width(),top:_44.top,height:_44.height},expand:{left:cc.width()-p.panel("panel")._outerWidth()}};
  341. }else{
  342. if(_3e=="west"&&_3f.expandWest){
  343. return {collapse:{left:-p.panel("panel")._outerWidth(),top:_44.top,height:_44.height},expand:{left:0}};
  344. }else{
  345. if(_3e=="north"&&_3f.expandNorth){
  346. return {collapse:{top:-p.panel("panel")._outerHeight(),width:cc.width()},expand:{top:0}};
  347. }else{
  348. if(_3e=="south"&&_3f.expandSouth){
  349. return {collapse:{top:cc.height(),width:cc.width()},expand:{top:cc.height()-p.panel("panel")._outerHeight()}};
  350. }
  351. }
  352. }
  353. }
  354. };
  355. };
  356. function _a(pp){
  357. if(!pp){
  358. return false;
  359. }
  360. if(pp.length){
  361. return pp.panel("panel").is(":visible");
  362. }else{
  363. return false;
  364. }
  365. };
  366. function _45(_46){
  367. var _47=$.data(_46,"layout").panels;
  368. if(_47.east.length&&_47.east.panel("options").collapsed){
  369. _2b(_46,"east",0);
  370. }
  371. if(_47.west.length&&_47.west.panel("options").collapsed){
  372. _2b(_46,"west",0);
  373. }
  374. if(_47.north.length&&_47.north.panel("options").collapsed){
  375. _2b(_46,"north",0);
  376. }
  377. if(_47.south.length&&_47.south.panel("options").collapsed){
  378. _2b(_46,"south",0);
  379. }
  380. };
  381. $.fn.layout=function(_48,_49){
  382. if(typeof _48=="string"){
  383. return $.fn.layout.methods[_48](this,_49);
  384. }
  385. _48=_48||{};
  386. return this.each(function(){
  387. var _4a=$.data(this,"layout");
  388. if(_4a){
  389. $.extend(_4a.options,_48);
  390. }else{
  391. var _4b=$.extend({},$.fn.layout.defaults,$.fn.layout.parseOptions(this),_48);
  392. $.data(this,"layout",{options:_4b,panels:{center:$(),north:$(),south:$(),east:$(),west:$()}});
  393. _12(this);
  394. }
  395. _2(this);
  396. _45(this);
  397. });
  398. };
  399. $.fn.layout.methods={options:function(jq){
  400. return $.data(jq[0],"layout").options;
  401. },resize:function(jq,_4c){
  402. return jq.each(function(){
  403. _2(this,_4c);
  404. });
  405. },panel:function(jq,_4d){
  406. return $.data(jq[0],"layout").panels[_4d];
  407. },collapse:function(jq,_4e){
  408. return jq.each(function(){
  409. _2b(this,_4e);
  410. });
  411. },expand:function(jq,_4f){
  412. return jq.each(function(){
  413. _3c(this,_4f);
  414. });
  415. },add:function(jq,_50){
  416. return jq.each(function(){
  417. _17(this,_50);
  418. _2(this);
  419. if($(this).layout("panel",_50.region).panel("options").collapsed){
  420. _2b(this,_50.region,0);
  421. }
  422. });
  423. },remove:function(jq,_51){
  424. return jq.each(function(){
  425. _26(this,_51);
  426. _2(this);
  427. });
  428. }};
  429. $.fn.layout.parseOptions=function(_52){
  430. return $.extend({},$.parser.parseOptions(_52,[{fit:"boolean"}]));
  431. };
  432. $.fn.layout.defaults={fit:false};
  433. $.fn.layout.parsePanelOptions=function(_53){
  434. var t=$(_53);
  435. return $.extend({},$.fn.panel.parseOptions(_53),$.parser.parseOptions(_53,["region",{split:"boolean",collpasedSize:"number",minWidth:"number",minHeight:"number",maxWidth:"number",maxHeight:"number"}]));
  436. };
  437. $.fn.layout.paneldefaults=$.extend({},$.fn.panel.defaults,{region:null,split:false,collapsedSize:28,minWidth:10,minHeight:10,maxWidth:10000,maxHeight:10000});
  438. })(jQuery);