jquery.layout.js 11 KB

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