UU跑腿标准版

ligerLayout.js 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. /**
  2. * jQuery ligerUI 1.2.4
  3. *
  4. * http://ligerui.com
  5. *
  6. * Author daomi 2014 [ gd_star@163.com ]
  7. *
  8. */
  9. (function ($)
  10. {
  11. $.fn.ligerLayout = function (options)
  12. {
  13. return $.ligerui.run.call(this, "ligerLayout", arguments);
  14. };
  15. $.fn.ligerGetLayoutManager = function ()
  16. {
  17. return $.ligerui.run.call(this, "ligerGetLayoutManager", arguments);
  18. };
  19. $.ligerDefaults.Layout = {
  20. topHeight: 50,
  21. bottomHeight: 50,
  22. leftWidth: 110,
  23. centerWidth: 300,
  24. rightWidth: 170,
  25. centerBottomHeight: 100,
  26. allowCenterBottomResize: true,
  27. inWindow: true, //是否以窗口的高度为准 height设置为百分比时可用
  28. heightDiff: 0, //高度补差
  29. height: '100%', //高度
  30. onHeightChanged: null,
  31. isLeftCollapse: false, //初始化时 左边是否隐藏
  32. isRightCollapse: false, //初始化时 右边是否隐藏
  33. allowLeftCollapse: true, //是否允许 左边可以隐藏
  34. allowRightCollapse: true, //是否允许 右边可以隐藏
  35. allowLeftResize: true, //是否允许 左边可以调整大小
  36. allowRightResize: true, //是否允许 右边可以调整大小
  37. allowTopResize: true, //是否允许 头部可以调整大小
  38. allowBottomResize: true, //是否允许 底部可以调整大小
  39. space: 3, //间隔
  40. onEndResize: null, //调整大小结束事件
  41. minLeftWidth: 80, //调整左侧宽度时的最小允许宽度
  42. minRightWidth: 80 //调整右侧宽度时的最小允许宽度
  43. };
  44. $.ligerMethos.Layout = {};
  45. $.ligerui.controls.Layout = function (element, options)
  46. {
  47. $.ligerui.controls.Layout.base.constructor.call(this, element, options);
  48. };
  49. $.ligerui.controls.Layout.ligerExtend($.ligerui.core.UIComponent, {
  50. __getType: function ()
  51. {
  52. return 'Layout';
  53. },
  54. __idPrev: function ()
  55. {
  56. return 'Layout';
  57. },
  58. _extendMethods: function ()
  59. {
  60. return $.ligerMethos.Layout;
  61. },
  62. _init: function()
  63. {
  64. $.ligerui.controls.Layout.base._init.call(this);
  65. var g = this, p = this.options;
  66. if (p.InWindow != null && p.inWindow == null) p.inWindow = p.InWindow; //旧版本命名错误纠正
  67. },
  68. _render: function ()
  69. {
  70. var g = this, p = this.options;
  71. g.layout = $(this.element);
  72. g.layout.addClass("l-layout");
  73. g.width = g.layout.width();
  74. //top
  75. if ($("> div[position=top]", g.layout).length > 0)
  76. {
  77. g.top = $("> div[position=top]", g.layout).wrap('<div class="l-layout-top" style="top:0px;"></div>').parent();
  78. g.top.content = $("> div[position=top]", g.top);
  79. if (!g.top.content.hasClass("l-layout-content"))
  80. g.top.content.addClass("l-layout-content");
  81. g.topHeight = p.topHeight;
  82. if (g.topHeight)
  83. {
  84. g.top.height(g.topHeight);
  85. }
  86. }
  87. //bottom
  88. if ($("> div[position=bottom]", g.layout).length > 0)
  89. {
  90. g.bottom = $("> div[position=bottom]", g.layout).wrap('<div class="l-layout-bottom"></div>').parent();
  91. g.bottom.content = $("> div[position=bottom]", g.bottom);
  92. if (!g.bottom.content.hasClass("l-layout-content"))
  93. g.bottom.content.addClass("l-layout-content");
  94. g.bottomHeight = p.bottomHeight;
  95. if (g.bottomHeight)
  96. {
  97. g.bottom.height(g.bottomHeight);
  98. }
  99. //set title
  100. var bottomtitle = g.bottom.content.attr("title");
  101. if (bottomtitle)
  102. {
  103. g.bottom.header = $('<div class="l-layout-header"></div>');
  104. g.bottom.prepend(g.bottom.header);
  105. g.bottom.header.html(bottomtitle);
  106. g.bottom.content.attr("title", "");
  107. }
  108. }
  109. //left
  110. if ($("> div[position=left]", g.layout).length > 0)
  111. {
  112. g.left = $("> div[position=left]", g.layout).wrap('<div class="l-layout-left" style="left:0px;"></div>').parent();
  113. g.left.header = $('<div class="l-layout-header"><div class="l-layout-header-toggle"></div><div class="l-layout-header-inner"></div></div>');
  114. g.left.prepend(g.left.header);
  115. g.left.header.toggle = $(".l-layout-header-toggle", g.left.header);
  116. g.left.content = $("> div[position=left]", g.left);
  117. if (!g.left.content.hasClass("l-layout-content"))
  118. g.left.content.addClass("l-layout-content");
  119. if (!p.allowLeftCollapse) $(".l-layout-header-toggle", g.left.header).remove();
  120. //set title
  121. var lefttitle = g.left.content.attr("title");
  122. if (lefttitle)
  123. {
  124. g.left.content.attr("title", "");
  125. $(".l-layout-header-inner", g.left.header).html(lefttitle);
  126. }
  127. //set title
  128. if (g.left.content.attr("hidetitle"))
  129. {
  130. g.left.content.attr("title", "");
  131. g.left.header.remove();
  132. }
  133. //set width
  134. g.leftWidth = p.leftWidth;
  135. if (g.leftWidth)
  136. g.left.width(g.leftWidth);
  137. }
  138. //center
  139. if ($("> div[position=center]", g.layout).length > 0)
  140. {
  141. g.center = $("> div[position=center]", g.layout).wrap('<div class="l-layout-center" ></div>').parent();
  142. g.center.content = $("> div[position=center]", g.center);
  143. g.center.content.addClass("l-layout-content");
  144. //set title
  145. var centertitle = g.center.content.attr("title");
  146. if (centertitle)
  147. {
  148. g.center.content.attr("title", "");
  149. g.center.header = $('<div class="l-layout-header"></div>');
  150. g.center.prepend(g.center.header);
  151. g.center.header.html(centertitle);
  152. }
  153. if (g.center.content.attr("hidetitle"))
  154. {
  155. g.center.content.attr("title", "");
  156. g.center.header.remove();
  157. }
  158. //set width
  159. g.centerWidth = p.centerWidth;
  160. if (g.centerWidth)
  161. g.center.width(g.centerWidth);
  162. //centerBottom
  163. if ($("> div[position=centerbottom]", g.layout).length > 0)
  164. {
  165. g.centerBottom = $("> div[position=centerbottom]", g.layout).wrap('<div class="l-layout-centerbottom" ></div>').parent();
  166. g.centerBottom.content = $("> div[position=centerbottom]", g.centerBottom);
  167. g.centerBottom.content.addClass("l-layout-content");
  168. //set title
  169. var centertitle = g.centerBottom.content.attr("title");
  170. if (centertitle)
  171. {
  172. g.centerBottom.content.attr("title", "");
  173. g.centerBottom.header = $('<div class="l-layout-header"></div>');
  174. g.centerBottom.prepend(g.centerBottom.header);
  175. g.centerBottom.header.html(centertitle);
  176. }
  177. if (g.centerBottom.content.attr("hidetitle"))
  178. {
  179. g.centerBottom.content.attr("title", "");
  180. if (g.centerBottom.header)
  181. {
  182. g.centerBottom.header.remove();
  183. }
  184. }
  185. if (g.centerWidth)
  186. g.centerBottom.width(g.centerWidth);
  187. }
  188. }
  189. //right
  190. if ($("> div[position=right]", g.layout).length > 0)
  191. {
  192. g.right = $("> div[position=right]", g.layout).wrap('<div class="l-layout-right"></div>').parent();
  193. g.right.header = $('<div class="l-layout-header"><div class="l-layout-header-toggle"></div><div class="l-layout-header-inner"></div></div>');
  194. g.right.prepend(g.right.header);
  195. g.right.header.toggle = $(".l-layout-header-toggle", g.right.header);
  196. if (!p.allowRightCollapse) $(".l-layout-header-toggle", g.right.header).remove();
  197. g.right.content = $("> div[position=right]", g.right);
  198. if (!g.right.content.hasClass("l-layout-content"))
  199. g.right.content.addClass("l-layout-content");
  200. //set title
  201. var righttitle = g.right.content.attr("title");
  202. if (righttitle)
  203. {
  204. g.right.content.attr("title", "");
  205. $(".l-layout-header-inner", g.right.header).html(righttitle);
  206. }
  207. if (g.right.content.attr("hidetitle"))
  208. {
  209. g.right.content.attr("title", "");
  210. g.right.header.remove();
  211. }
  212. //set width
  213. g.rightWidth = p.rightWidth;
  214. if (g.rightWidth)
  215. g.right.width(g.rightWidth);
  216. }
  217. //lock
  218. g.layout.lock = $("<div class='l-layout-lock'></div>");
  219. g.layout.append(g.layout.lock);
  220. //DropHandle
  221. g._addDropHandle();
  222. //Collapse
  223. g.isLeftCollapse = p.isLeftCollapse;
  224. g.isRightCollapse = p.isRightCollapse;
  225. g.leftCollapse = $('<div class="l-layout-collapse-left" style="display: none; "><div class="l-layout-collapse-left-toggle"></div></div>');
  226. g.rightCollapse = $('<div class="l-layout-collapse-right" style="display: none; "><div class="l-layout-collapse-right-toggle"></div></div>');
  227. g.layout.append(g.leftCollapse).append(g.rightCollapse);
  228. g.leftCollapse.toggle = $("> .l-layout-collapse-left-toggle", g.leftCollapse);
  229. g.rightCollapse.toggle = $("> .l-layout-collapse-right-toggle", g.rightCollapse);
  230. g._setCollapse();
  231. //init
  232. g._bulid();
  233. $(window).resize(function ()
  234. {
  235. g._onResize();
  236. });
  237. g.set(p);
  238. g.mask.height(g.layout.height());
  239. },
  240. setLeftCollapse: function (isCollapse)
  241. {
  242. var g = this, p = this.options;
  243. if (!g.left) return false;
  244. g.isLeftCollapse = isCollapse;
  245. if (g.isLeftCollapse)
  246. {
  247. g.leftCollapse.show();
  248. g.leftDropHandle && g.leftDropHandle.hide();
  249. g.left.hide();
  250. }
  251. else
  252. {
  253. g.leftCollapse.hide();
  254. g.leftDropHandle && g.leftDropHandle.show();
  255. g.left.show();
  256. }
  257. g._onResize();
  258. },
  259. setRightCollapse: function (isCollapse)
  260. {
  261. var g = this, p = this.options;
  262. if (!g.right) return false;
  263. g.isRightCollapse = isCollapse;
  264. g._onResize();
  265. if (g.isRightCollapse)
  266. {
  267. g.rightCollapse.show();
  268. g.rightDropHandle && g.rightDropHandle.hide();
  269. g.right.hide();
  270. }
  271. else
  272. {
  273. g.rightCollapse.hide();
  274. g.rightDropHandle && g.rightDropHandle.show();
  275. g.right.show();
  276. }
  277. g._onResize();
  278. },
  279. _bulid: function ()
  280. {
  281. var g = this, p = this.options;
  282. $("> .l-layout-left .l-layout-header,> .l-layout-right .l-layout-header", g.layout).hover(function ()
  283. {
  284. $(this).addClass("l-layout-header-over");
  285. }, function ()
  286. {
  287. $(this).removeClass("l-layout-header-over");
  288. });
  289. $(".l-layout-header-toggle", g.layout).hover(function ()
  290. {
  291. $(this).addClass("l-layout-header-toggle-over");
  292. }, function ()
  293. {
  294. $(this).removeClass("l-layout-header-toggle-over");
  295. });
  296. $(".l-layout-header-toggle", g.left).click(function ()
  297. {
  298. g.setLeftCollapse(true);
  299. });
  300. $(".l-layout-header-toggle", g.right).click(function ()
  301. {
  302. g.setRightCollapse(true);
  303. });
  304. //set top
  305. g.middleTop = 0;
  306. if (g.top)
  307. {
  308. g.middleTop += g.top.height();
  309. g.middleTop += parseInt(g.top.css('borderTopWidth'));
  310. g.middleTop += parseInt(g.top.css('borderBottomWidth'));
  311. g.middleTop += p.space;
  312. }
  313. if (g.left)
  314. {
  315. g.left.css({ top: g.middleTop });
  316. g.leftCollapse.css({ top: g.middleTop });
  317. }
  318. if (g.center) g.center.css({ top: g.middleTop });
  319. if (g.right)
  320. {
  321. g.right.css({ top: g.middleTop });
  322. g.rightCollapse.css({ top: g.middleTop });
  323. }
  324. //set left
  325. if (g.left) g.left.css({ left: 0 });
  326. g._onResize();
  327. g._onResize();
  328. },
  329. _setCollapse: function ()
  330. {
  331. var g = this, p = this.options;
  332. g.leftCollapse.hover(function ()
  333. {
  334. $(this).addClass("l-layout-collapse-left-over");
  335. }, function ()
  336. {
  337. $(this).removeClass("l-layout-collapse-left-over");
  338. });
  339. g.leftCollapse.toggle.hover(function ()
  340. {
  341. $(this).addClass("l-layout-collapse-left-toggle-over");
  342. }, function ()
  343. {
  344. $(this).removeClass("l-layout-collapse-left-toggle-over");
  345. });
  346. g.rightCollapse.hover(function ()
  347. {
  348. $(this).addClass("l-layout-collapse-right-over");
  349. }, function ()
  350. {
  351. $(this).removeClass("l-layout-collapse-right-over");
  352. });
  353. g.rightCollapse.toggle.hover(function ()
  354. {
  355. $(this).addClass("l-layout-collapse-right-toggle-over");
  356. }, function ()
  357. {
  358. $(this).removeClass("l-layout-collapse-right-toggle-over");
  359. });
  360. g.leftCollapse.toggle.click(function ()
  361. {
  362. g.setLeftCollapse(false);
  363. });
  364. g.rightCollapse.toggle.click(function ()
  365. {
  366. g.setRightCollapse(false);
  367. });
  368. if (g.left && g.isLeftCollapse)
  369. {
  370. g.leftCollapse.show();
  371. g.leftDropHandle && g.leftDropHandle.hide();
  372. g.left.hide();
  373. }
  374. if (g.right && g.isRightCollapse)
  375. {
  376. g.rightCollapse.show();
  377. g.rightDropHandle && g.rightDropHandle.hide();
  378. g.right.hide();
  379. }
  380. },
  381. _addDropHandle: function ()
  382. {
  383. var g = this, p = this.options;
  384. if (g.left && p.allowLeftResize)
  385. {
  386. g.leftDropHandle = $("<div class='l-layout-drophandle-left'></div>");
  387. g.layout.append(g.leftDropHandle);
  388. g.leftDropHandle && g.leftDropHandle.show();
  389. g.leftDropHandle.mousedown(function (e)
  390. {
  391. g._start('leftresize', e);
  392. });
  393. }
  394. if (g.right && p.allowRightResize)
  395. {
  396. g.rightDropHandle = $("<div class='l-layout-drophandle-right'></div>");
  397. g.layout.append(g.rightDropHandle);
  398. g.rightDropHandle && g.rightDropHandle.show();
  399. g.rightDropHandle.mousedown(function (e)
  400. {
  401. g._start('rightresize', e);
  402. });
  403. }
  404. if (g.top && p.allowTopResize)
  405. {
  406. g.topDropHandle = $("<div class='l-layout-drophandle-top'></div>");
  407. g.layout.append(g.topDropHandle);
  408. g.topDropHandle.show();
  409. g.topDropHandle.mousedown(function (e)
  410. {
  411. g._start('topresize', e);
  412. });
  413. }
  414. if (g.bottom && p.allowBottomResize)
  415. {
  416. g.bottomDropHandle = $("<div class='l-layout-drophandle-bottom'></div>");
  417. g.layout.append(g.bottomDropHandle);
  418. g.bottomDropHandle.show();
  419. g.bottomDropHandle.mousedown(function (e)
  420. {
  421. g._start('bottomresize', e);
  422. });
  423. }
  424. if (g.centerBottom && p.allowCenterBottomResize)
  425. {
  426. g.centerBottomDropHandle = $("<div class='l-layout-drophandle-centerbottom'></div>");
  427. g.layout.append(g.centerBottomDropHandle);
  428. g.centerBottomDropHandle.show();
  429. g.centerBottomDropHandle.mousedown(function (e)
  430. {
  431. g._start('centerbottomresize', e);
  432. });
  433. }
  434. g.draggingxline = $("<div class='l-layout-dragging-xline'></div>");
  435. g.draggingyline = $("<div class='l-layout-dragging-yline'></div>");
  436. g.mask = $("<div class='l-dragging-mask'></div>");
  437. g.layout.append(g.draggingxline).append(g.draggingyline).append(g.mask);
  438. },
  439. _setDropHandlePosition: function ()
  440. {
  441. var g = this, p = this.options;
  442. if (g.leftDropHandle)
  443. {
  444. g.leftDropHandle.css({ left: g.left.width() + parseInt(g.left.css('left')), height: g.middleHeight, top: g.middleTop });
  445. }
  446. if (g.rightDropHandle)
  447. {
  448. g.rightDropHandle.css({ left: parseInt(g.right.css('left')) - p.space, height: g.middleHeight, top: g.middleTop });
  449. }
  450. if (g.topDropHandle)
  451. {
  452. g.topDropHandle.css({ top: g.top.height() + parseInt(g.top.css('top')), width: g.top.width() });
  453. }
  454. if (g.bottomDropHandle)
  455. {
  456. g.bottomDropHandle.css({ top: parseInt(g.bottom.css('top')) - p.space, width: g.bottom.width() });
  457. }
  458. if (g.centerBottomDropHandle)
  459. {
  460. g.centerBottomDropHandle.css({
  461. top: parseInt(g.centerBottom.css('top')) - p.space,
  462. left: parseInt(g.center.css('left')),
  463. width: g.center.width()
  464. });
  465. }
  466. },
  467. _onResize: function ()
  468. {
  469. var g = this, p = this.options;
  470. var oldheight = g.layout.height();
  471. //set layout height
  472. var h = 0;
  473. var windowHeight = $(window).height();
  474. var parentHeight = null;
  475. if (typeof (p.height) == "string" && p.height.indexOf('%') > 0)
  476. {
  477. var layoutparent = g.layout.parent();
  478. if (p.inWindow || layoutparent[0].tagName.toLowerCase() == "body")
  479. {
  480. parentHeight = windowHeight;
  481. parentHeight -= parseInt($('body').css('paddingTop'));
  482. parentHeight -= parseInt($('body').css('paddingBottom'));
  483. }
  484. else
  485. {
  486. parentHeight = layoutparent.height();
  487. }
  488. h = parentHeight * parseFloat(p.height) * 0.01;
  489. if (p.inWindow || layoutparent[0].tagName.toLowerCase() == "body")
  490. h -= (g.layout.offset().top - parseInt($('body').css('paddingTop')));
  491. }
  492. else
  493. {
  494. h = parseInt(p.height);
  495. }
  496. h += p.heightDiff;
  497. g.layout.height(h);
  498. g.layoutHeight = g.layout.height();
  499. g.middleWidth = g.layout.width();
  500. g.middleHeight = g.layout.height();
  501. if (g.top)
  502. {
  503. g.middleHeight -= g.top.height();
  504. g.middleHeight -= parseInt(g.top.css('borderTopWidth'));
  505. g.middleHeight -= parseInt(g.top.css('borderBottomWidth'));
  506. g.middleHeight -= p.space;
  507. }
  508. if (g.bottom)
  509. {
  510. g.middleHeight -= g.bottom.height();
  511. g.middleHeight -= parseInt(g.bottom.css('borderTopWidth'));
  512. g.middleHeight -= parseInt(g.bottom.css('borderBottomWidth'));
  513. g.middleHeight -= p.space;
  514. }
  515. //specific
  516. g.middleHeight -= 2;
  517. if (g.hasBind('heightChanged') && g.layoutHeight != oldheight)
  518. {
  519. g.trigger('heightChanged', [{ layoutHeight: g.layoutHeight, diff: g.layoutHeight - oldheight, middleHeight: g.middleHeight}]);
  520. }
  521. if (g.center)
  522. {
  523. g.centerWidth = g.middleWidth;
  524. if (g.left)
  525. {
  526. if (g.isLeftCollapse)
  527. {
  528. g.centerWidth -= g.leftCollapse.width();
  529. g.centerWidth -= parseInt(g.leftCollapse.css('borderLeftWidth'));
  530. g.centerWidth -= parseInt(g.leftCollapse.css('borderRightWidth'));
  531. g.centerWidth -= parseInt(g.leftCollapse.css('left'));
  532. g.centerWidth -= p.space;
  533. }
  534. else
  535. {
  536. g.centerWidth -= g.leftWidth;
  537. g.centerWidth -= parseInt(g.left.css('borderLeftWidth'));
  538. g.centerWidth -= parseInt(g.left.css('borderRightWidth'));
  539. g.centerWidth -= parseInt(g.left.css('left'));
  540. g.centerWidth -= p.space;
  541. }
  542. }
  543. if (g.right)
  544. {
  545. if (g.isRightCollapse)
  546. {
  547. g.centerWidth -= g.rightCollapse.width();
  548. g.centerWidth -= parseInt(g.rightCollapse.css('borderLeftWidth'));
  549. g.centerWidth -= parseInt(g.rightCollapse.css('borderRightWidth'));
  550. g.centerWidth -= parseInt(g.rightCollapse.css('right'));
  551. g.centerWidth -= p.space;
  552. }
  553. else
  554. {
  555. g.centerWidth -= g.rightWidth;
  556. g.centerWidth -= parseInt(g.right.css('borderLeftWidth'));
  557. g.centerWidth -= parseInt(g.right.css('borderRightWidth'));
  558. g.centerWidth -= p.space;
  559. }
  560. }
  561. g.centerLeft = 0;
  562. if (g.left)
  563. {
  564. if (g.isLeftCollapse)
  565. {
  566. g.centerLeft += g.leftCollapse.width();
  567. g.centerLeft += parseInt(g.leftCollapse.css('borderLeftWidth'));
  568. g.centerLeft += parseInt(g.leftCollapse.css('borderRightWidth'));
  569. g.centerLeft += parseInt(g.leftCollapse.css('left'));
  570. g.centerLeft += p.space;
  571. }
  572. else
  573. {
  574. g.centerLeft += g.left.width();
  575. g.centerLeft += parseInt(g.left.css('borderLeftWidth'));
  576. g.centerLeft += parseInt(g.left.css('borderRightWidth'));
  577. g.centerLeft += p.space;
  578. }
  579. }
  580. g.center.css({ left: g.centerLeft });
  581. g.centerWidth >= 0 && g.center.width(g.centerWidth);
  582. g.middleHeight >= 0 && g.center.height(g.middleHeight);
  583. var contentHeight = g.middleHeight;
  584. if (g.center.header) contentHeight -= g.center.header.height();
  585. contentHeight >= 0 && g.center.content.height(contentHeight);
  586. g._updateCenterBottom(true);
  587. }
  588. if (g.left)
  589. {
  590. g.leftCollapse.height(g.middleHeight);
  591. g.left.height(g.middleHeight);
  592. }
  593. if (g.right)
  594. {
  595. g.rightCollapse.height(g.middleHeight);
  596. g.right.height(g.middleHeight);
  597. //set left
  598. g.rightLeft = 0;
  599. if (g.left)
  600. {
  601. if (g.isLeftCollapse)
  602. {
  603. g.rightLeft += g.leftCollapse.width();
  604. g.rightLeft += parseInt(g.leftCollapse.css('borderLeftWidth'));
  605. g.rightLeft += parseInt(g.leftCollapse.css('borderRightWidth'));
  606. g.rightLeft += p.space;
  607. }
  608. else
  609. {
  610. g.rightLeft += g.left.width();
  611. g.rightLeft += parseInt(g.left.css('borderLeftWidth'));
  612. g.rightLeft += parseInt(g.left.css('borderRightWidth'));
  613. g.rightLeft += parseInt(g.left.css('left'));
  614. g.rightLeft += p.space;
  615. }
  616. }
  617. if (g.center)
  618. {
  619. g.rightLeft += g.center.width();
  620. g.rightLeft += parseInt(g.center.css('borderLeftWidth'));
  621. g.rightLeft += parseInt(g.center.css('borderRightWidth'));
  622. g.rightLeft += p.space;
  623. }
  624. g.right.css({ left: g.rightLeft });
  625. }
  626. if (g.bottom)
  627. {
  628. g.bottomTop = g.layoutHeight - g.bottom.height() - 2;
  629. g.bottom.css({ top: g.bottomTop });
  630. }
  631. g._setDropHandlePosition();
  632. },
  633. //加了centerBottom以后,需要对centerBottom进行刷新处理一下
  634. _updateCenterBottom: function (isHeightResize)
  635. {
  636. var g = this, p = this.options;
  637. if (g.centerBottom)
  638. {
  639. if (isHeightResize)
  640. {
  641. var centerBottomHeight = g.centerBottomHeight || p.centerBottomHeight;
  642. g.centerBottom.css({ left: g.centerLeft });
  643. g.centerWidth >= 0 && g.centerBottom.width(g.centerWidth);
  644. var centerHeight = g.center.height(), centerTop = parseInt(g.center.css("top"));
  645. g.centerBottom.height(centerBottomHeight)
  646. g.centerBottom.css({ top: centerTop + centerHeight - centerBottomHeight + 2 });
  647. g.center.height(centerHeight - centerBottomHeight - 2);
  648. }
  649. var centerLeft = parseInt(g.center.css("left"));
  650. g.centerBottom.width(g.center.width()).css({ left: centerLeft });
  651. }
  652. },
  653. _start: function (dragtype, e)
  654. {
  655. var g = this, p = this.options;
  656. g.dragtype = dragtype;
  657. if (dragtype == 'leftresize' || dragtype == 'rightresize')
  658. {
  659. g.xresize = { startX: e.pageX };
  660. g.draggingyline.css({ left: e.pageX - g.layout.offset().left, height: g.middleHeight, top: g.middleTop }).show();
  661. $('body').css('cursor', 'col-resize');
  662. g.mask.height(g.layout.height()).removeClass("l-layout-ymask").addClass("l-layout-xmask").show();
  663. }
  664. else if (dragtype == 'topresize' || dragtype == 'bottomresize')
  665. {
  666. g.yresize = { startY: e.pageY };
  667. g.draggingxline.css({ top: e.pageY - g.layout.offset().top, width: g.layout.width() }).show();
  668. $('body').css('cursor', 'row-resize');
  669. g.mask.height(g.layout.height()).removeClass("l-layout-xmask").addClass("l-layout-ymask").show();
  670. }
  671. else if (dragtype == 'centerbottomresize')
  672. {
  673. g.yresize = { startY: e.pageY };
  674. g.draggingxline.css({ top: e.pageY - g.layout.offset().top, width: g.layout.width() }).show();
  675. $('body').css('cursor', 'row-resize');
  676. g.mask.height(g.layout.height()).removeClass("l-layout-xmask").addClass("l-layout-ymask").show();
  677. }
  678. else
  679. {
  680. return;
  681. }
  682. g.layout.lock.width(g.layout.width());
  683. g.layout.lock.height(g.layout.height());
  684. g.layout.lock.show();
  685. if ($.browser.msie || $.browser.safari) $('body').bind('selectstart', function () { return false; }); // 不能选择
  686. $(document).bind('mouseup', function ()
  687. {
  688. g._stop.apply(g, arguments);
  689. });
  690. $(document).bind('mousemove', function ()
  691. {
  692. g._drag.apply(g, arguments);
  693. });
  694. },
  695. _drag: function (e)
  696. {
  697. var g = this, p = this.options;
  698. if (g.xresize)
  699. {
  700. g.xresize.diff = e.pageX - g.xresize.startX;
  701. g.draggingyline.css({ left: e.pageX - g.layout.offset().left });
  702. $('body').css('cursor', 'col-resize');
  703. }
  704. else if (g.yresize)
  705. {
  706. g.yresize.diff = e.pageY - g.yresize.startY;
  707. g.draggingxline.css({ top: e.pageY - g.layout.offset().top });
  708. $('body').css('cursor', 'row-resize');
  709. }
  710. },
  711. _stop: function (e)
  712. {
  713. var g = this, p = this.options;
  714. var diff;
  715. if (g.xresize && g.xresize.diff != undefined)
  716. {
  717. diff = g.xresize.diff;
  718. if (g.dragtype == 'leftresize')
  719. {
  720. if (p.minLeftWidth)
  721. {
  722. if (g.leftWidth + g.xresize.diff < p.minLeftWidth)
  723. return;
  724. }
  725. g.leftWidth += g.xresize.diff;
  726. g.left.width(g.leftWidth);
  727. if (g.center)
  728. g.center.width(g.center.width() - g.xresize.diff).css({ left: parseInt(g.center.css('left')) + g.xresize.diff });
  729. else if (g.right)
  730. g.right.width(g.left.width() - g.xresize.diff).css({ left: parseInt(g.right.css('left')) + g.xresize.diff });
  731. }
  732. else if (g.dragtype == 'rightresize')
  733. {
  734. if (p.minRightWidth)
  735. {
  736. if (g.rightWidth - g.xresize.diff < p.minRightWidth)
  737. return;
  738. }
  739. g.rightWidth -= g.xresize.diff;
  740. g.right.width(g.rightWidth).css({ left: parseInt(g.right.css('left')) + g.xresize.diff });
  741. if (g.center)
  742. g.center.width(g.center.width() + g.xresize.diff);
  743. else if (g.left)
  744. g.left.width(g.left.width() + g.xresize.diff);
  745. }
  746. g._updateCenterBottom();
  747. }
  748. else if (g.yresize && g.yresize.diff != undefined)
  749. {
  750. diff = g.yresize.diff;
  751. if (g.dragtype == 'topresize')
  752. {
  753. g.top.height(g.top.height() + g.yresize.diff);
  754. g.middleTop += g.yresize.diff;
  755. g.middleHeight -= g.yresize.diff;
  756. if (g.left)
  757. {
  758. g.left.css({ top: g.middleTop }).height(g.middleHeight);
  759. g.leftCollapse.css({ top: g.middleTop }).height(g.middleHeight);
  760. }
  761. if (g.center) g.center.css({ top: g.middleTop }).height(g.middleHeight);
  762. if (g.right)
  763. {
  764. g.right.css({ top: g.middleTop }).height(g.middleHeight);
  765. g.rightCollapse.css({ top: g.middleTop }).height(g.middleHeight);
  766. }
  767. g._updateCenterBottom(true);
  768. }
  769. else if (g.dragtype == 'bottomresize')
  770. {
  771. g.bottom.height(g.bottom.height() - g.yresize.diff);
  772. g.middleHeight += g.yresize.diff;
  773. g.bottomTop += g.yresize.diff;
  774. g.bottom.css({ top: g.bottomTop });
  775. if (g.left)
  776. {
  777. g.left.height(g.middleHeight);
  778. g.leftCollapse.height(g.middleHeight);
  779. }
  780. if (g.center) g.center.height(g.middleHeight);
  781. if (g.right)
  782. {
  783. g.right.height(g.middleHeight);
  784. g.rightCollapse.height(g.middleHeight);
  785. }
  786. g._updateCenterBottom(true);
  787. }
  788. else if (g.dragtype == 'centerbottomresize')
  789. {
  790. g.centerBottomHeight = g.centerBottomHeight || p.centerBottomHeight;
  791. g.centerBottomHeight -= g.yresize.diff;
  792. var centerBottomTop = parseInt(g.centerBottom.css("top"));
  793. g.centerBottom.css("top" , centerBottomTop + g.yresize.diff);
  794. g.centerBottom.height(g.centerBottom.height() - g.yresize.diff);
  795. g.center.height(g.center.height() + g.yresize.diff);
  796. }
  797. }
  798. g.trigger('endResize', [{
  799. direction: g.dragtype ? g.dragtype.replace(/resize/, '') : '',
  800. diff: diff
  801. }, e]);
  802. g._setDropHandlePosition();
  803. g.draggingxline.hide();
  804. g.draggingyline.hide();
  805. g.mask.hide();
  806. g.xresize = g.yresize = g.dragtype = false;
  807. g.layout.lock.hide();
  808. if ($.browser.msie || $.browser.safari)
  809. $('body').unbind('selectstart');
  810. $(document).unbind('mousemove', g._drag);
  811. $(document).unbind('mouseup', g._stop);
  812. $('body').css('cursor', '');
  813. }
  814. });
  815. })(jQuery);