ligerLayout.js 29 KB

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