纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6077 lines
238 KiB

3 years ago
  1. /**
  2. * @preserve
  3. * jquery.layout 1.4.4
  4. * $Date: 2014-11-29 08:00:00 (Sat, 29 November 2014) $
  5. * $Rev: 1.0404 $
  6. *
  7. * Copyright (c) 2014 Kevin Dalman (http://jquery-dev.com)
  8. * Based on work by Fabrizio Balliano (http://www.fabrizioballiano.net)
  9. *
  10. * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
  11. * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
  12. *
  13. * SEE: http://layout.jquery-dev.com/LICENSE.txt
  14. *
  15. * Changelog: http://layout.jquery-dev.com/changelog.cfm
  16. *
  17. * Docs: http://layout.jquery-dev.com/documentation.html
  18. * Tips: http://layout.jquery-dev.com/tips.html
  19. * Help: http://groups.google.com/group/jquery-ui-layout
  20. */
  21. /* JavaDoc Info: http://code.google.com/closure/compiler/docs/js-for-compiler.html
  22. * {!Object} non-nullable type (never NULL)
  23. * {?string} nullable type (sometimes NULL) - default for {Object}
  24. * {number=} optional parameter
  25. * {*} ALL types
  26. */
  27. /* TODO for jQ 2.x
  28. * check $.fn.disableSelection - this is in jQuery UI 1.9.x
  29. */
  30. // NOTE: For best readability, view with a fixed-width font and tabs equal to 4-chars
  31. ; (function ($) {
  32. // alias Math methods - used a lot!
  33. var min = Math.min
  34. , max = Math.max
  35. , round = Math.floor
  36. , isStr = function (v) { return $.type(v) === "string"; }
  37. /**
  38. * @param {!Object} Instance
  39. * @param {Array.<string>} a_fn
  40. */
  41. , runPluginCallbacks = function (Instance, a_fn) {
  42. if ($.isArray(a_fn))
  43. for (var i = 0, c = a_fn.length; i < c; i++) {
  44. var fn = a_fn[i];
  45. try {
  46. if (isStr(fn)) // 'name' of a function
  47. fn = eval(fn);
  48. if ($.isFunction(fn))
  49. g(fn)(Instance);
  50. } catch (ex) { }
  51. }
  52. function g(f) { return f; }; // compiler hack
  53. }
  54. ;
  55. /*
  56. * GENERIC $.layout METHODS - used by all layouts
  57. */
  58. $.layout = {
  59. version: "1.4.4"
  60. , revision: 1.0404 // eg: ver 1.4.4 = rev 1.0404 - major(n+).minor(nn)+patch(nn+)
  61. // $.layout.browser REPLACES $.browser
  62. , browser: {} // set below
  63. // *PREDEFINED* EFFECTS & DEFAULTS
  64. // MUST list effect here - OR MUST set an fxSettings option (can be an empty hash: {})
  65. , effects: {
  66. // Pane Open/Close Animations
  67. slide: {
  68. all: { duration: "fast" } // eg: duration: 1000, easing: "easeOutBounce"
  69. , north: { direction: "up" }
  70. , south: { direction: "down" }
  71. , east: { direction: "right" }
  72. , west: { direction: "left" }
  73. }
  74. , drop: {
  75. all: { duration: "slow" }
  76. , north: { direction: "up" }
  77. , south: { direction: "down" }
  78. , east: { direction: "right" }
  79. , west: { direction: "left" }
  80. }
  81. , scale: {
  82. all: { duration: "fast" }
  83. }
  84. // these are not recommended, but can be used
  85. , blind: {}
  86. , clip: {}
  87. , explode: {}
  88. , fade: {}
  89. , fold: {}
  90. , puff: {}
  91. // Pane Resize Animations
  92. , size: {
  93. all: { easing: "swing" }
  94. }
  95. }
  96. // INTERNAL CONFIG DATA - DO NOT CHANGE THIS!
  97. , config: {
  98. optionRootKeys: "effects,panes,north,south,west,east,center".split(",")
  99. , allPanes: "north,south,west,east,center".split(",")
  100. , borderPanes: "north,south,west,east".split(",")
  101. , oppositeEdge: {
  102. north: "south"
  103. , south: "north"
  104. , east: "west"
  105. , west: "east"
  106. }
  107. // offscreen data
  108. , offscreenCSS: { left: "-99999px", right: "auto" } // used by hide/close if useOffscreenClose=true
  109. , offscreenReset: "offscreenReset" // key used for data
  110. // CSS used in multiple places
  111. , hidden: { visibility: "hidden" }
  112. , visible: { visibility: "visible" }
  113. // layout element settings
  114. , resizers: {
  115. cssReq: {
  116. position: "absolute"
  117. , padding: 0
  118. , margin: 0
  119. , fontSize: "1px"
  120. , textAlign: "left" // to counter-act "center" alignment!
  121. , overflow: "hidden" // prevent toggler-button from overflowing
  122. // SEE $.layout.defaults.zIndexes.resizer_normal
  123. }
  124. , cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
  125. //background: "#fff",
  126. border: "none"
  127. }
  128. }
  129. , togglers: {
  130. cssReq: {
  131. position: "absolute"
  132. , display: "block"
  133. , padding: 0
  134. , margin: 0
  135. , overflow: "hidden"
  136. , textAlign: "center"
  137. , fontSize: "1px"
  138. , cursor: "pointer"
  139. , zIndex: 1
  140. }
  141. , cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
  142. background: "#AAA"
  143. }
  144. }
  145. , content: {
  146. cssReq: {
  147. position: "relative" /* contain floated or positioned elements */
  148. }
  149. , cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
  150. overflow: "auto"
  151. , padding: "10px"
  152. }
  153. , cssDemoPane: { // DEMO CSS - REMOVE scrolling from 'pane' when it has a content-div
  154. overflow: "hidden"
  155. , padding: 0
  156. }
  157. }
  158. , panes: { // defaults for ALL panes - overridden by 'per-pane settings' below
  159. cssReq: {
  160. position: "absolute"
  161. , margin: 0
  162. // $.layout.defaults.zIndexes.pane_normal
  163. }
  164. , cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
  165. padding: "0px",
  166. //background: "#fff",
  167. border: "1px solid #ddd"
  168. , overflow: "auto"
  169. }
  170. }
  171. , north: {
  172. side: "top"
  173. , sizeType: "Height"
  174. , dir: "horz"
  175. , cssReq: {
  176. top: 0
  177. , bottom: "auto"
  178. , left: 0
  179. , right: 0
  180. , width: "auto"
  181. // height: DYNAMIC
  182. }
  183. }
  184. , south: {
  185. side: "bottom"
  186. , sizeType: "Height"
  187. , dir: "horz"
  188. , cssReq: {
  189. top: "auto"
  190. , bottom: 0
  191. , left: 0
  192. , right: 0
  193. , width: "auto"
  194. // height: DYNAMIC
  195. }
  196. }
  197. , east: {
  198. side: "right"
  199. , sizeType: "Width"
  200. , dir: "vert"
  201. , cssReq: {
  202. left: "auto"
  203. , right: 0
  204. , top: "auto" // DYNAMIC
  205. , bottom: "auto" // DYNAMIC
  206. , height: "auto"
  207. // width: DYNAMIC
  208. }
  209. }
  210. , west: {
  211. side: "left"
  212. , sizeType: "Width"
  213. , dir: "vert"
  214. , cssReq: {
  215. left: 0
  216. , right: "auto"
  217. , top: "auto" // DYNAMIC
  218. , bottom: "auto" // DYNAMIC
  219. , height: "auto"
  220. // width: DYNAMIC
  221. }
  222. }
  223. , center: {
  224. dir: "center"
  225. , cssReq: {
  226. left: "auto" // DYNAMIC
  227. , right: "auto" // DYNAMIC
  228. , top: "auto" // DYNAMIC
  229. , bottom: "auto" // DYNAMIC
  230. , height: "auto"
  231. , width: "auto"
  232. }
  233. }
  234. }
  235. // CALLBACK FUNCTION NAMESPACE - used to store reusable callback functions
  236. , callbacks: {}
  237. , getParentPaneElem: function (el) {
  238. // must pass either a container or pane element
  239. var $el = $(el)
  240. , layout = $el.data("layout") || $el.data("parentLayout");
  241. if (layout) {
  242. var $cont = layout.container;
  243. // see if this container is directly-nested inside an outer-pane
  244. if ($cont.data("layoutPane")) return $cont;
  245. var $pane = $cont.closest("." + $.layout.defaults.panes.paneClass);
  246. // if a pane was found, return it
  247. if ($pane.data("layoutPane")) return $pane;
  248. }
  249. return null;
  250. }
  251. , getParentPaneInstance: function (el) {
  252. // must pass either a container or pane element
  253. var $pane = $.layout.getParentPaneElem(el);
  254. return $pane ? $pane.data("layoutPane") : null;
  255. }
  256. , getParentLayoutInstance: function (el) {
  257. // must pass either a container or pane element
  258. var $pane = $.layout.getParentPaneElem(el);
  259. return $pane ? $pane.data("parentLayout") : null;
  260. }
  261. , getEventObject: function (evt) {
  262. return typeof evt === "object" && evt.stopPropagation ? evt : null;
  263. }
  264. , parsePaneName: function (evt_or_pane) {
  265. var evt = $.layout.getEventObject(evt_or_pane)
  266. , pane = evt_or_pane;
  267. if (evt) {
  268. // ALWAYS stop propagation of events triggered in Layout!
  269. evt.stopPropagation();
  270. pane = $(this).data("layoutEdge");
  271. }
  272. if (pane && !/^(west|east|north|south|center)$/.test(pane)) {
  273. $.layout.msg('LAYOUT ERROR - Invalid pane-name: "' + pane + '"');
  274. pane = "error";
  275. }
  276. return pane;
  277. }
  278. // LAYOUT-PLUGIN REGISTRATION
  279. // more plugins can added beyond this default list
  280. , plugins: {
  281. draggable: !!$.fn.draggable // resizing
  282. , effects: {
  283. core: !!$.effects // animimations (specific effects tested by initOptions)
  284. , slide: $.effects && ($.effects.slide || ($.effects.effect && $.effects.effect.slide)) // default effect
  285. }
  286. }
  287. // arrays of plugin or other methods to be triggered for events in *each layout* - will be passed 'Instance'
  288. , onCreate: [] // runs when layout is just starting to be created - right after options are set
  289. , onLoad: [] // runs after layout container and global events init, but before initPanes is called
  290. , onReady: [] // runs after initialization *completes* - ie, after initPanes completes successfully
  291. , onDestroy: [] // runs after layout is destroyed
  292. , onUnload: [] // runs after layout is destroyed OR when page unloads
  293. , afterOpen: [] // runs after setAsOpen() completes
  294. , afterClose: [] // runs after setAsClosed() completes
  295. /*
  296. * GENERIC UTILITY METHODS
  297. */
  298. // calculate and return the scrollbar width, as an integer
  299. , scrollbarWidth: function () { return window.scrollbarWidth || $.layout.getScrollbarSize('width'); }
  300. , scrollbarHeight: function () { return window.scrollbarHeight || $.layout.getScrollbarSize('height'); }
  301. , getScrollbarSize: function (dim) {
  302. var $c = $('<div style="position: absolute; top: -10000px; left: -10000px; width: 100px; height: 100px; border: 0; overflow: scroll;"></div>').appendTo("body")
  303. , d = { width: $c.outerWidth - $c[0].clientWidth, height: 100 - $c[0].clientHeight };
  304. $c.remove();
  305. window.scrollbarWidth = d.width;
  306. window.scrollbarHeight = d.height;
  307. return dim.match(/^(width|height)$/) ? d[dim] : d;
  308. }
  309. , disableTextSelection: function () {
  310. var $d = $(document)
  311. , s = 'textSelectionDisabled'
  312. , x = 'textSelectionInitialized'
  313. ;
  314. if ($.fn.disableSelection) {
  315. if (!$d.data(x)) // document hasn't been initialized yet
  316. $d.on('mouseup', $.layout.enableTextSelection).data(x, true);
  317. if (!$d.data(s))
  318. $d.disableSelection().data(s, true);
  319. }
  320. }
  321. , enableTextSelection: function () {
  322. var $d = $(document)
  323. , s = 'textSelectionDisabled';
  324. if ($.fn.enableSelection && $d.data(s))
  325. $d.enableSelection().data(s, false);
  326. }
  327. /**
  328. * Returns hash container 'display' and 'visibility'
  329. *
  330. * @see $.swap() - swaps CSS, runs callback, resets CSS
  331. * @param {!Object} $E jQuery element
  332. * @param {boolean=} [force=false] Run even if display != none
  333. * @return {!Object} Returns current style props, if applicable
  334. */
  335. , showInvisibly: function ($E, force) {
  336. if ($E && $E.length && (force || $E.css("display") === "none")) { // only if not *already hidden*
  337. var s = $E[0].style
  338. // save ONLY the 'style' props because that is what we must restore
  339. , CSS = { display: s.display || '', visibility: s.visibility || '' };
  340. // show element 'invisibly' so can be measured
  341. $E.css({ display: "block", visibility: "hidden" });
  342. return CSS;
  343. }
  344. return {};
  345. }
  346. /**
  347. * Returns data for setting size of an element (container or a pane).
  348. *
  349. * @see _create(), onWindowResize() for container, plus others for pane
  350. * @return JSON Returns a hash of all dimensions: top, bottom, left, right, outerWidth, innerHeight, etc
  351. */
  352. , getElementDimensions: function ($E, inset) {
  353. var
  354. // dimensions hash - start with current data IF passed
  355. d = { css: {}, inset: {} }
  356. , x = d.css // CSS hash
  357. , i = { bottom: 0 } // TEMP insets (bottom = complier hack)
  358. , N = $.layout.cssNum
  359. , R = Math.round
  360. , off = $E.offset()
  361. , b, p, ei // TEMP border, padding
  362. ;
  363. d.offsetLeft = off.left;
  364. d.offsetTop = off.top;
  365. if (!inset) inset = {}; // simplify logic below
  366. $.each("Left,Right,Top,Bottom".split(","), function (idx, e) { // e = edge
  367. b = x["border" + e] = $.layout.borderWidth($E, e);
  368. p = x["padding" + e] = $.layout.cssNum($E, "padding" + e);
  369. ei = e.toLowerCase();
  370. d.inset[ei] = inset[ei] >= 0 ? inset[ei] : p; // any missing insetX value = paddingX
  371. i[ei] = d.inset[ei] + b; // total offset of content from outer side
  372. });
  373. x.width = R($E.width());
  374. x.height = R($E.height());
  375. x.top = N($E, "top", true);
  376. x.bottom = N($E, "bottom", true);
  377. x.left = N($E, "left", true);
  378. x.right = N($E, "right", true);
  379. d.outerWidth = R($E.outerWidth());
  380. d.outerHeight = R($E.outerHeight());
  381. // calc the TRUE inner-dimensions, even in quirks-mode!
  382. d.innerWidth = max(0, d.outerWidth - i.left - i.right);
  383. d.innerHeight = max(0, d.outerHeight - i.top - i.bottom);
  384. // layoutWidth/Height is used in calcs for manual resizing
  385. // layoutW/H only differs from innerW/H when in quirks-mode - then is like outerW/H
  386. d.layoutWidth = R($E.innerWidth());
  387. d.layoutHeight = R($E.innerHeight());
  388. //if ($E.prop('tagName') === 'BODY') { debugData( d, $E.prop('tagName') ); } // DEBUG
  389. //d.visible = $E.is(":visible");// && x.width > 0 && x.height > 0;
  390. return d;
  391. }
  392. , getElementStyles: function ($E, list) {
  393. var
  394. CSS = {}
  395. , style = $E[0].style
  396. , props = list.split(",")
  397. , sides = "Top,Bottom,Left,Right".split(",")
  398. , attrs = "Color,Style,Width".split(",")
  399. , p, s, a, i, j, k
  400. ;
  401. for (i = 0; i < props.length; i++) {
  402. p = props[i];
  403. if (p.match(/(border|padding|margin)$/))
  404. for (j = 0; j < 4; j++) {
  405. s = sides[j];
  406. if (p === "border")
  407. for (k = 0; k < 3; k++) {
  408. a = attrs[k];
  409. CSS[p + s + a] = style[p + s + a];
  410. }
  411. else
  412. CSS[p + s] = style[p + s];
  413. }
  414. else
  415. CSS[p] = style[p];
  416. };
  417. return CSS
  418. }
  419. /**
  420. * Return the innerWidth for the current browser/doctype
  421. *
  422. * @see initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
  423. * @param {Array.<Object>} $E Must pass a jQuery object - first element is processed
  424. * @param {number=} outerWidth (optional) Can pass a width, allowing calculations BEFORE element is resized
  425. * @return {number} Returns the innerWidth of the elem by subtracting padding and borders
  426. */
  427. , cssWidth: function ($E, outerWidth) {
  428. // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
  429. if (outerWidth <= 0) return 0;
  430. var lb = $.layout.browser
  431. , bs = !lb.boxModel ? "border-box" : lb.boxSizing ? $E.css("boxSizing") : "content-box"
  432. , b = $.layout.borderWidth
  433. , n = $.layout.cssNum
  434. , W = outerWidth
  435. ;
  436. // strip border and/or padding from outerWidth to get CSS Width
  437. if (bs !== "border-box")
  438. W -= (b($E, "Left") + b($E, "Right"));
  439. if (bs === "content-box")
  440. W -= (n($E, "paddingLeft") + n($E, "paddingRight"));
  441. return max(0, W);
  442. }
  443. /**
  444. * Return the innerHeight for the current browser/doctype
  445. *
  446. * @see initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
  447. * @param {Array.<Object>} $E Must pass a jQuery object - first element is processed
  448. * @param {number=} outerHeight (optional) Can pass a width, allowing calculations BEFORE element is resized
  449. * @return {number} Returns the innerHeight of the elem by subtracting padding and borders
  450. */
  451. , cssHeight: function ($E, outerHeight) {
  452. // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
  453. if (outerHeight <= 0) return 0;
  454. var lb = $.layout.browser
  455. , bs = !lb.boxModel ? "border-box" : lb.boxSizing ? $E.css("boxSizing") : "content-box"
  456. , b = $.layout.borderWidth
  457. , n = $.layout.cssNum
  458. , H = outerHeight
  459. ;
  460. // strip border and/or padding from outerHeight to get CSS Height
  461. if (bs !== "border-box")
  462. H -= (b($E, "Top") + b($E, "Bottom"));
  463. if (bs === "content-box")
  464. H -= (n($E, "paddingTop") + n($E, "paddingBottom"));
  465. return max(0, H);
  466. }
  467. /**
  468. * Returns the 'current CSS numeric value' for a CSS property - 0 if property does not exist
  469. *
  470. * @see Called by many methods
  471. * @param {Array.<Object>} $E Must pass a jQuery object - first element is processed
  472. * @param {string} prop The name of the CSS property, eg: top, width, etc.
  473. * @param {boolean=} [allowAuto=false] true = return 'auto' if that is value; false = return 0
  474. * @return {(string|number)} Usually used to get an integer value for position (top, left) or size (height, width)
  475. */
  476. , cssNum: function ($E, prop, allowAuto) {
  477. if (!$E.jquery) $E = $($E);
  478. var CSS = $.layout.showInvisibly($E)
  479. , p = $.css($E[0], prop, true)
  480. , v = allowAuto && p == "auto" ? p : Math.round(parseFloat(p) || 0);
  481. $E.css(CSS); // RESET
  482. return v;
  483. }
  484. , borderWidth: function (el, side) {
  485. if (el.jquery) el = el[0];
  486. var b = "border" + side.substr(0, 1).toUpperCase() + side.substr(1); // left => Left
  487. return $.css(el, b + "Style", true) === "none" ? 0 : Math.round(parseFloat($.css(el, b + "Width", true)) || 0);
  488. }
  489. /**
  490. * Mouse-tracking utility - FUTURE REFERENCE
  491. *
  492. * init: if (!window.mouse) {
  493. * window.mouse = { x: 0, y: 0 };
  494. * $(document).mousemove( $.layout.trackMouse );
  495. * }
  496. *
  497. * @param {Object} evt
  498. *
  499. , trackMouse: function (evt) {
  500. window.mouse = { x: evt.clientX, y: evt.clientY };
  501. }
  502. */
  503. /**
  504. * SUBROUTINE for preventPrematureSlideClose option
  505. *
  506. * @param {Object} evt
  507. * @param {Object=} el
  508. */
  509. , isMouseOverElem: function (evt, el) {
  510. var
  511. $E = $(el || this)
  512. , d = $E.offset()
  513. , T = d.top
  514. , L = d.left
  515. , R = L + $E.outerWidth()
  516. , B = T + $E.outerHeight()
  517. , x = evt.pageX // evt.clientX ?
  518. , y = evt.pageY // evt.clientY ?
  519. ;
  520. // if X & Y are < 0, probably means is over an open SELECT
  521. return ($.layout.browser.msie && x < 0 && y < 0) || ((x >= L && x <= R) && (y >= T && y <= B));
  522. }
  523. /**
  524. * Message/Logging Utility
  525. *
  526. * @example $.layout.msg("My message"); // log text
  527. * @example $.layout.msg("My message", true); // alert text
  528. * @example $.layout.msg({ foo: "bar" }, "Title"); // log hash-data, with custom title
  529. * @example $.layout.msg({ foo: "bar" }, true, "Title", { sort: false }); -OR-
  530. * @example $.layout.msg({ foo: "bar" }, "Title", { sort: false, display: true }); // alert hash-data
  531. *
  532. * @param {(Object|string)} info String message OR Hash/Array
  533. * @param {(Boolean|string|Object)=} [popup=false] True means alert-box - can be skipped
  534. * @param {(Object|string)=} [debugTitle=""] Title for Hash data - can be skipped
  535. * @param {Object=} [debugOpts] Extra options for debug output
  536. */
  537. , msg: function (info, popup, debugTitle, debugOpts) {
  538. if ($.isPlainObject(info) && window.debugData) {
  539. if (typeof popup === "string") {
  540. debugOpts = debugTitle;
  541. debugTitle = popup;
  542. }
  543. else if (typeof debugTitle === "object") {
  544. debugOpts = debugTitle;
  545. debugTitle = null;
  546. }
  547. var t = debugTitle || "log( <object> )"
  548. , o = $.extend({ sort: false, returnHTML: false, display: false }, debugOpts);
  549. if (popup === true || o.display)
  550. debugData(info, t, o);
  551. else if (window.console)
  552. console.log(debugData(info, t, o));
  553. }
  554. else if (popup)
  555. alert(info);
  556. else if (window.console)
  557. console.log(info);
  558. else {
  559. var id = "#layoutLogger"
  560. , $l = $(id);
  561. if (!$l.length)
  562. $l = createLog();
  563. $l.children("ul").append('<li style="padding: 4px 10px; margin: 0; border-top: 1px solid #CCC;">' + info.replace(/\</g, "&lt;").replace(/\>/g, "&gt;") + '</li>');
  564. }
  565. function createLog() {
  566. var pos = $.support.fixedPosition ? 'fixed' : 'absolute'
  567. , $e = $('<div id="layoutLogger" style="position: ' + pos + '; top: 5px; z-index: 999999; max-width: 25%; overflow: hidden; border: 1px solid #000; border-radius: 5px; background: #FBFBFB; box-shadow: 0 2px 10px rgba(0,0,0,0.3);">'
  568. + '<div style="font-size: 13px; font-weight: bold; padding: 5px 10px; background: #F6F6F6; border-radius: 5px 5px 0 0; cursor: move;">'
  569. + '<span style="float: right; padding-left: 7px; cursor: pointer;" title="Remove Console" onclick="$(this).closest(\'#layoutLogger\').remove()">X</span>Layout console.log</div>'
  570. + '<ul style="font-size: 13px; font-weight: none; list-style: none; margin: 0; padding: 0 0 2px;"></ul>'
  571. + '</div>'
  572. ).appendTo("body");
  573. $e.css('left', $(window).width() - $e.outerWidth() - 5)
  574. if ($.ui.draggable) $e.draggable({ handle: ':first-child' });
  575. return $e;
  576. };
  577. }
  578. };
  579. /*
  580. * $.layout.browser REPLACES removed $.browser, with extra data
  581. * Parsing code here adapted from jQuery 1.8 $.browse
  582. */
  583. (function () {
  584. var u = navigator.userAgent.toLowerCase()
  585. , m = /(chrome)[ \/]([\w.]+)/.exec(u)
  586. || /(webkit)[ \/]([\w.]+)/.exec(u)
  587. || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(u)
  588. || /(msie) ([\w.]+)/.exec(u)
  589. || u.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(u)
  590. || []
  591. , b = m[1] || ""
  592. , v = m[2] || 0
  593. , ie = b === "msie"
  594. , cm = document.compatMode
  595. , $s = $.support
  596. , bs = $s.boxSizing !== undefined ? $s.boxSizing : $s.boxSizingReliable
  597. , bm = !ie || !cm || cm === "CSS1Compat" || $s.boxModel || false
  598. , lb = $.layout.browser = {
  599. version: v
  600. , safari: b === "webkit" // webkit (NOT chrome) = safari
  601. , webkit: b === "chrome" // chrome = webkit
  602. , msie: ie
  603. , isIE6: ie && v == 6
  604. // ONLY IE reverts to old box-model - Note that compatMode was deprecated as of IE8
  605. , boxModel: bm
  606. , boxSizing: !!(typeof bs === "function" ? bs() : bs)
  607. };
  608. ;
  609. if (b) lb[b] = true; // set CURRENT browser
  610. /* OLD versions of jQuery only set $.support.boxModel after page is loaded
  611. * so if this is IE, use support.boxModel to test for quirks-mode (ONLY IE changes boxModel) */
  612. if (!bm && !cm) $(function () { lb.boxModel = $s.boxModel; });
  613. })();
  614. // DEFAULT OPTIONS
  615. $.layout.defaults = {
  616. /*
  617. * LAYOUT & LAYOUT-CONTAINER OPTIONS
  618. * - none of these options are applicable to individual panes
  619. */
  620. name: "" // Not required, but useful for buttons and used for the state-cookie
  621. , containerClass: "ui-layout-container" // layout-container element
  622. , inset: null // custom container-inset values (override padding)
  623. , scrollToBookmarkOnLoad: true // after creating a layout, scroll to bookmark in URL (.../page.htm#myBookmark)
  624. , resizeWithWindow: true // bind thisLayout.resizeAll() to the window.resize event
  625. , resizeWithWindowDelay: 200 // delay calling resizeAll because makes window resizing very jerky
  626. , resizeWithWindowMaxDelay: 0 // 0 = none - force resize every XX ms while window is being resized
  627. , maskPanesEarly: false // true = create pane-masks on resizer.mouseDown instead of waiting for resizer.dragstart
  628. , onresizeall_start: null // CALLBACK when resizeAll() STARTS - NOT pane-specific
  629. , onresizeall_end: null // CALLBACK when resizeAll() ENDS - NOT pane-specific
  630. , onload_start: null // CALLBACK when Layout inits - after options initialized, but before elements
  631. , onload_end: null // CALLBACK when Layout inits - after EVERYTHING has been initialized
  632. , onunload_start: null // CALLBACK when Layout is destroyed OR onWindowUnload
  633. , onunload_end: null // CALLBACK when Layout is destroyed OR onWindowUnload
  634. , initPanes: true // false = DO NOT initialize the panes onLoad - will init later
  635. , showErrorMessages: true // enables fatal error messages to warn developers of common errors
  636. , showDebugMessages: false // display console-and-alert debug msgs - IF this Layout version _has_ debugging code!
  637. // Changing this zIndex value will cause other zIndex values to automatically change
  638. , zIndex: null // the PANE zIndex - resizers and masks will be +1
  639. // DO NOT CHANGE the zIndex values below unless you clearly understand their relationships
  640. , zIndexes: { // set _default_ z-index values here...
  641. pane_normal: 0 // normal z-index for panes
  642. , content_mask: 1 // applied to overlays used to mask content INSIDE panes during resizing
  643. , resizer_normal: 2 // normal z-index for resizer-bars
  644. , pane_sliding: 100 // applied to *BOTH* the pane and its resizer when a pane is 'slid open'
  645. , pane_animate: 1000 // applied to the pane when being animated - not applied to the resizer
  646. , resizer_drag: 10000 // applied to the CLONED resizer-bar when being 'dragged'
  647. }
  648. , errors: {
  649. pane: "pane" // description of "layout pane element" - used only in error messages
  650. , selector: "selector" // description of "jQuery-selector" - used only in error messages
  651. , addButtonError: "Error Adding Button\nInvalid "
  652. , containerMissing: "UI Layout Initialization Error\nThe specified layout-container does not exist."
  653. , centerPaneMissing: "UI Layout Initialization Error\nThe center-pane element does not exist.\nThe center-pane is a required element."
  654. , noContainerHeight: "UI Layout Initialization Warning\nThe layout-container \"CONTAINER\" has no height.\nTherefore the layout is 0-height and hence 'invisible'!"
  655. , callbackError: "UI Layout Callback Error\nThe EVENT callback is not a valid function."
  656. }
  657. /*
  658. * PANE DEFAULT SETTINGS
  659. * - settings under the 'panes' key become the default settings for *all panes*
  660. * - ALL pane-options can also be set specifically for each panes, which will override these 'default values'
  661. */
  662. , panes: { // default options for 'all panes' - will be overridden by 'per-pane settings'
  663. applyDemoStyles: true // NOTE: renamed from applyDefaultStyles for clarity
  664. , closable: false // pane can open & close
  665. , resizable: true // when open, pane can be resized
  666. , slidable: true // when closed, pane can 'slide open' over other panes - closes on mouse-out
  667. , initClosed: false // true = init pane as 'closed'
  668. , initHidden: false // true = init pane as 'hidden' - no resizer-bar/spacing
  669. // SELECTORS
  670. //, paneSelector: "" // MUST be pane-specific - jQuery selector for pane
  671. , contentSelector: ".ui-layout-content" // INNER div/element to auto-size so only it scrolls, not the entire pane!
  672. , contentIgnoreSelector: ".ui-layout-ignore" // element(s) to 'ignore' when measuring 'content'
  673. , findNestedContent: false // true = $P.find(contentSelector), false = $P.children(contentSelector)
  674. // GENERIC ROOT-CLASSES - for auto-generated classNames
  675. , paneClass: "ui-layout-pane" // Layout Pane
  676. , resizerClass: "ui-layout-resizer" // Resizer Bar
  677. , togglerClass: "ui-layout-toggler" // Toggler Button
  678. , buttonClass: "ui-layout-button" // CUSTOM Buttons - eg: '[ui-layout-button]-toggle/-open/-close/-pin'
  679. // ELEMENT SIZE & SPACING
  680. //, size: 100 // MUST be pane-specific -initial size of pane
  681. , minSize: 0 // when manually resizing a pane
  682. , maxSize: 0 // ditto, 0 = no limit
  683. , spacing_open: 7 // space between pane and adjacent panes - when pane is 'open'
  684. , spacing_closed: 5 // ditto - when pane is 'closed'
  685. , togglerLength_open: 50 // Length = WIDTH of toggler button on north/south sides - HEIGHT on east/west sides
  686. , togglerLength_closed: 50 // 100% OR -1 means 'full height/width of resizer bar' - 0 means 'hidden'
  687. , togglerAlign_open: "center" // top/left, bottom/right, center, OR...
  688. , togglerAlign_closed: "center" // 1 => nn = offset from top/left, -1 => -nn == offset from bottom/right
  689. , togglerContent_open: "" // text or HTML to put INSIDE the toggler
  690. , togglerContent_closed: "" // ditto
  691. // RESIZING OPTIONS
  692. , resizerDblClickToggle: true //
  693. , autoResize: true // IF size is 'auto' or a percentage, then recalc 'pixel size' whenever the layout resizes
  694. , autoReopen: true // IF a pane was auto-closed due to noRoom, reopen it when there is room? False = leave it closed
  695. , resizerDragOpacity: 1 // option for ui.draggable
  696. //, resizerCursor: "" // MUST be pane-specific - cursor when over resizer-bar
  697. , maskContents: false // true = add DIV-mask over-or-inside this pane so can 'drag' over IFRAMES
  698. , maskObjects: false // true = add IFRAME-mask over-or-inside this pane to cover objects/applets - content-mask will overlay this mask
  699. , maskZindex: null // will override zIndexes.content_mask if specified - not applicable to iframe-panes
  700. , resizingGrid: false // grid size that the resizers will snap-to during resizing, eg: [20,20]
  701. , livePaneResizing: false // true = LIVE Resizing as resizer is dragged
  702. , liveContentResizing: false // true = re-measure header/footer heights as resizer is dragged
  703. , liveResizingTolerance: 1 // how many px change before pane resizes, to control performance
  704. // SLIDING OPTIONS
  705. , sliderCursor: "pointer" // cursor when resizer-bar will trigger 'sliding'
  706. , slideTrigger_open: "click" // click, dblclick, mouseenter
  707. , slideTrigger_close: "mouseleave"// click, mouseleave
  708. , slideDelay_open: 300 // applies only for mouseenter event - 0 = instant open
  709. , slideDelay_close: 300 // applies only for mouseleave event (300ms is the minimum!)
  710. , hideTogglerOnSlide: false // when pane is slid-open, should the toggler show?
  711. , preventQuickSlideClose: $.layout.browser.webkit // Chrome triggers slideClosed as it is opening
  712. , preventPrematureSlideClose: false // handle incorrect mouseleave trigger, like when over a SELECT-list in IE
  713. // PANE-SPECIFIC TIPS & MESSAGES
  714. , tips: {
  715. Open: "Open" // eg: "Open Pane"
  716. , Close: "Close"
  717. , Resize: "Resize"
  718. , Slide: "Slide Open"
  719. , Pin: "Pin"
  720. , Unpin: "Un-Pin"
  721. , noRoomToOpen: "Not enough room to show this panel." // alert if user tries to open a pane that cannot
  722. , minSizeWarning: "Panel has reached its minimum size" // displays in browser statusbar
  723. , maxSizeWarning: "Panel has reached its maximum size" // ditto
  724. }
  725. // HOT-KEYS & MISC
  726. , showOverflowOnHover: false // will bind allowOverflow() utility to pane.onMouseOver
  727. , enableCursorHotkey: true // enabled 'cursor' hotkeys
  728. //, customHotkey: "" // MUST be pane-specific - EITHER a charCode OR a character
  729. , customHotkeyModifier: "SHIFT" // either 'SHIFT', 'CTRL' or 'CTRL+SHIFT' - NOT 'ALT'
  730. // PANE ANIMATION
  731. // NOTE: fxSss_open, fxSss_close & fxSss_size options (eg: fxName_open) are auto-generated if not passed
  732. , fxName: "slide" // ('none' or blank), slide, drop, scale -- only relevant to 'open' & 'close', NOT 'size'
  733. , fxSpeed: null // slow, normal, fast, 200, nnn - if passed, will OVERRIDE fxSettings.duration
  734. , fxSettings: {} // can be passed, eg: { easing: "easeOutBounce", duration: 1500 }
  735. , fxOpacityFix: true // tries to fix opacity in IE to restore anti-aliasing after animation
  736. , animatePaneSizing: false // true = animate resizing after dragging resizer-bar OR sizePane() is called
  737. /* NOTE: Action-specific FX options are auto-generated from the options above if not specifically set:
  738. fxName_open: "slide" // 'Open' pane animation
  739. fnName_close: "slide" // 'Close' pane animation
  740. fxName_size: "slide" // 'Size' pane animation - when animatePaneSizing = true
  741. fxSpeed_open: null
  742. fxSpeed_close: null
  743. fxSpeed_size: null
  744. fxSettings_open: {}
  745. fxSettings_close: {}
  746. fxSettings_size: {}
  747. */
  748. // CHILD/NESTED LAYOUTS
  749. , children: null // Layout-options for nested/child layout - even {} is valid as options
  750. , containerSelector: '' // if child is NOT 'directly nested', a selector to find it/them (can have more than one child layout!)
  751. , initChildren: true // true = child layout will be created as soon as _this_ layout completes initialization
  752. , destroyChildren: true // true = destroy child-layout if this pane is destroyed
  753. , resizeChildren: true // true = trigger child-layout.resizeAll() when this pane is resized
  754. // EVENT TRIGGERING
  755. , triggerEventsOnLoad: false // true = trigger onopen OR onclose callbacks when layout initializes
  756. , triggerEventsDuringLiveResize: true // true = trigger onresize callback REPEATEDLY if livePaneResizing==true
  757. // PANE CALLBACKS
  758. , onshow_start: null // CALLBACK when pane STARTS to Show - BEFORE onopen/onhide_start
  759. , onshow_end: null // CALLBACK when pane ENDS being Shown - AFTER onopen/onhide_end
  760. , onhide_start: null // CALLBACK when pane STARTS to Close - BEFORE onclose_start
  761. , onhide_end: null // CALLBACK when pane ENDS being Closed - AFTER onclose_end
  762. , onopen_start: null // CALLBACK when pane STARTS to Open
  763. , onopen_end: null // CALLBACK when pane ENDS being Opened
  764. , onclose_start: null // CALLBACK when pane STARTS to Close
  765. , onclose_end: null // CALLBACK when pane ENDS being Closed
  766. , onresize_start: null // CALLBACK when pane STARTS being Resized ***FOR ANY REASON***
  767. , onresize_end: null // CALLBACK when pane ENDS being Resized ***FOR ANY REASON***
  768. , onsizecontent_start: null // CALLBACK when sizing of content-element STARTS
  769. , onsizecontent_end: null // CALLBACK when sizing of content-element ENDS
  770. , onswap_start: null // CALLBACK when pane STARTS to Swap
  771. , onswap_end: null // CALLBACK when pane ENDS being Swapped
  772. , ondrag_start: null // CALLBACK when pane STARTS being ***MANUALLY*** Resized
  773. , ondrag_end: null // CALLBACK when pane ENDS being ***MANUALLY*** Resized
  774. }
  775. /*
  776. * PANE-SPECIFIC SETTINGS
  777. * - options listed below MUST be specified per-pane - they CANNOT be set under 'panes'
  778. * - all options under the 'panes' key can also be set specifically for any pane
  779. * - most options under the 'panes' key apply only to 'border-panes' - NOT the the center-pane
  780. */
  781. , north: {
  782. paneSelector: ".ui-layout-north"
  783. , size: "auto" // eg: "auto", "30%", .30, 200
  784. , resizerCursor: "n-resize" // custom = url(myCursor.cur)
  785. , customHotkey: "" // EITHER a charCode (43) OR a character ("o")
  786. }
  787. , south: {
  788. paneSelector: ".ui-layout-south"
  789. , size: "auto"
  790. , resizerCursor: "s-resize"
  791. , customHotkey: ""
  792. }
  793. , east: {
  794. paneSelector: ".ui-layout-east"
  795. , size: 200
  796. , resizerCursor: "e-resize"
  797. , customHotkey: ""
  798. }
  799. , west: {
  800. paneSelector: ".ui-layout-west"
  801. , size: 200
  802. , resizerCursor: "col-resize"
  803. , customHotkey: ""
  804. }
  805. , center: {
  806. paneSelector: ".ui-layout-center"
  807. , minWidth: 0
  808. , minHeight: 0
  809. }
  810. };
  811. $.layout.optionsMap = {
  812. // layout/global options - NOT pane-options
  813. layout: ("name,instanceKey,stateManagement,effects,inset,zIndexes,errors,"
  814. + "zIndex,scrollToBookmarkOnLoad,showErrorMessages,maskPanesEarly,"
  815. + "outset,resizeWithWindow,resizeWithWindowDelay,resizeWithWindowMaxDelay,"
  816. + "onresizeall,onresizeall_start,onresizeall_end,onload,onload_start,onload_end,onunload,onunload_start,onunload_end").split(",")
  817. // borderPanes: [ ALL options that are NOT specified as 'layout' ]
  818. // default.panes options that apply to the center-pane (most options apply _only_ to border-panes)
  819. , center: ("paneClass,contentSelector,contentIgnoreSelector,findNestedContent,applyDemoStyles,triggerEventsOnLoad,"
  820. + "showOverflowOnHover,maskContents,maskObjects,liveContentResizing,"
  821. + "containerSelector,children,initChildren,resizeChildren,destroyChildren,"
  822. + "onresize,onresize_start,onresize_end,onsizecontent,onsizecontent_start,onsizecontent_end").split(",")
  823. // options that MUST be specifically set 'per-pane' - CANNOT set in the panes (defaults) key
  824. , noDefault: ("paneSelector,resizerCursor,customHotkey").split(",")
  825. };
  826. /**
  827. * Processes options passed in converts flat-format data into subkey (JSON) format
  828. * In flat-format, subkeys are _currently_ separated with 2 underscores, like north__optName
  829. * Plugins may also call this method so they can transform their own data
  830. *
  831. * @param {!Object} hash Data/options passed by user - may be a single level or nested levels
  832. * @param {boolean=} [addKeys=false] Should the primary layout.options keys be added if they do not exist?
  833. * @return {Object} Returns hash of minWidth & minHeight
  834. */
  835. $.layout.transformData = function (hash, addKeys) {
  836. var json = addKeys ? { panes: {}, center: {} } : {} // init return object
  837. , branch, optKey, keys, key, val, i, c;
  838. if (typeof hash !== "object") return json; // no options passed
  839. // convert all 'flat-keys' to 'sub-key' format
  840. for (optKey in hash) {
  841. branch = json;
  842. val = hash[optKey];
  843. keys = optKey.split("__"); // eg: west__size or north__fxSettings__duration
  844. c = keys.length - 1;
  845. // convert underscore-delimited to subkeys
  846. for (i = 0; i <= c; i++) {
  847. key = keys[i];
  848. if (i === c) { // last key = value
  849. if ($.isPlainObject(val))
  850. branch[key] = $.layout.transformData(val); // RECURSE
  851. else
  852. branch[key] = val;
  853. }
  854. else {
  855. if (!branch[key])
  856. branch[key] = {}; // create the subkey
  857. // recurse to sub-key for next loop - if not done
  858. branch = branch[key];
  859. }
  860. }
  861. }
  862. return json;
  863. };
  864. // INTERNAL CONFIG DATA - DO NOT CHANGE THIS!
  865. $.layout.backwardCompatibility = {
  866. // data used by renameOldOptions()
  867. map: {
  868. // OLD Option Name: NEW Option Name
  869. applyDefaultStyles: "applyDemoStyles"
  870. // CHILD/NESTED LAYOUTS
  871. , childOptions: "children"
  872. , initChildLayout: "initChildren"
  873. , destroyChildLayout: "destroyChildren"
  874. , resizeChildLayout: "resizeChildren"
  875. , resizeNestedLayout: "resizeChildren"
  876. // MISC Options
  877. , resizeWhileDragging: "livePaneResizing"
  878. , resizeContentWhileDragging: "liveContentResizing"
  879. , triggerEventsWhileDragging: "triggerEventsDuringLiveResize"
  880. , maskIframesOnResize: "maskContents"
  881. // STATE MANAGEMENT
  882. , useStateCookie: "stateManagement.enabled"
  883. , "cookie.autoLoad": "stateManagement.autoLoad"
  884. , "cookie.autoSave": "stateManagement.autoSave"
  885. , "cookie.keys": "stateManagement.stateKeys"
  886. , "cookie.name": "stateManagement.cookie.name"
  887. , "cookie.domain": "stateManagement.cookie.domain"
  888. , "cookie.path": "stateManagement.cookie.path"
  889. , "cookie.expires": "stateManagement.cookie.expires"
  890. , "cookie.secure": "stateManagement.cookie.secure"
  891. // OLD Language options
  892. , noRoomToOpenTip: "tips.noRoomToOpen"
  893. , togglerTip_open: "tips.Close" // open = Close
  894. , togglerTip_closed: "tips.Open" // closed = Open
  895. , resizerTip: "tips.Resize"
  896. , sliderTip: "tips.Slide"
  897. }
  898. /**
  899. * @param {Object} opts
  900. */
  901. , renameOptions: function (opts) {
  902. var map = $.layout.backwardCompatibility.map
  903. , oldData, newData, value
  904. ;
  905. for (var itemPath in map) {
  906. oldData = getBranch(itemPath);
  907. value = oldData.branch[oldData.key];
  908. if (value !== undefined) {
  909. newData = getBranch(map[itemPath], true);
  910. newData.branch[newData.key] = value;
  911. delete oldData.branch[oldData.key];
  912. }
  913. }
  914. /**
  915. * @param {string} path
  916. * @param {boolean=} [create=false] Create path if does not exist
  917. */
  918. function getBranch(path, create) {
  919. var a = path.split(".") // split keys into array
  920. , c = a.length - 1
  921. , D = { branch: opts, key: a[c] } // init branch at top & set key (last item)
  922. , i = 0, k, undef;
  923. for (; i < c; i++) { // skip the last key (data)
  924. k = a[i];
  925. if (D.branch[k] == undefined) { // child-key does not exist
  926. if (create) {
  927. D.branch = D.branch[k] = {}; // create child-branch
  928. }
  929. else // can't go any farther
  930. D.branch = {}; // branch is undefined
  931. }
  932. else
  933. D.branch = D.branch[k]; // get child-branch
  934. }
  935. return D;
  936. };
  937. }
  938. /**
  939. * @param {Object} opts
  940. */
  941. , renameAllOptions: function (opts) {
  942. var ren = $.layout.backwardCompatibility.renameOptions;
  943. // rename root (layout) options
  944. ren(opts);
  945. // rename 'defaults' to 'panes'
  946. if (opts.defaults) {
  947. if (typeof opts.panes !== "object")
  948. opts.panes = {};
  949. $.extend(true, opts.panes, opts.defaults);
  950. delete opts.defaults;
  951. }
  952. // rename options in the the options.panes key
  953. if (opts.panes) ren(opts.panes);
  954. // rename options inside *each pane key*, eg: options.west
  955. $.each($.layout.config.allPanes, function (i, pane) {
  956. if (opts[pane]) ren(opts[pane]);
  957. });
  958. return opts;
  959. }
  960. };
  961. /* ============================================================
  962. * BEGIN WIDGET: $( selector ).layout( {options} );
  963. * ============================================================
  964. */
  965. $.fn.layout = function (opts) {
  966. var
  967. // local aliases to global data
  968. browser = $.layout.browser
  969. , _c = $.layout.config
  970. // local aliases to utlity methods
  971. , cssW = $.layout.cssWidth
  972. , cssH = $.layout.cssHeight
  973. , elDims = $.layout.getElementDimensions
  974. , styles = $.layout.getElementStyles
  975. , evtObj = $.layout.getEventObject
  976. , evtPane = $.layout.parsePaneName
  977. /**
  978. * options - populated by initOptions()
  979. */
  980. , options = $.extend(true, {}, $.layout.defaults)
  981. , effects = options.effects = $.extend(true, {}, $.layout.effects)
  982. /**
  983. * layout-state object
  984. */
  985. , state = {
  986. // generate unique ID to use for event.namespace so can unbind only events added by 'this layout'
  987. id: "layout" + $.now() // code uses alias: sID
  988. , initialized: false
  989. , paneResizing: false
  990. , panesSliding: {}
  991. , container: { // list all keys referenced in code to avoid compiler error msgs
  992. innerWidth: 0
  993. , innerHeight: 0
  994. , outerWidth: 0
  995. , outerHeight: 0
  996. , layoutWidth: 0
  997. , layoutHeight: 0
  998. }
  999. , north: { childIdx: 0 }
  1000. , south: { childIdx: 0 }
  1001. , east: { childIdx: 0 }
  1002. , west: { childIdx: 0 }
  1003. , center: { childIdx: 0 }
  1004. }
  1005. /**
  1006. * parent/child-layout pointers
  1007. */
  1008. //, hasParentLayout = false - exists ONLY inside Instance so can be set externally
  1009. , children = {
  1010. north: null
  1011. , south: null
  1012. , east: null
  1013. , west: null
  1014. , center: null
  1015. }
  1016. /*
  1017. * ###########################
  1018. * INTERNAL HELPER FUNCTIONS
  1019. * ###########################
  1020. */
  1021. /**
  1022. * Manages all internal timers
  1023. */
  1024. , timer = {
  1025. data: {}
  1026. , set: function (s, fn, ms) { timer.clear(s); timer.data[s] = setTimeout(fn, ms); }
  1027. , clear: function (s) { var t = timer.data; if (t[s]) { clearTimeout(t[s]); delete t[s]; } }
  1028. }
  1029. /**
  1030. * Alert or console.log a message - IF option is enabled.
  1031. *
  1032. * @param {(string|!Object)} msg Message (or debug-data) to display
  1033. * @param {boolean=} [popup=false] True by default, means 'alert', false means use console.log
  1034. * @param {boolean=} [debug=false] True means is a widget debugging message
  1035. */
  1036. , _log = function (msg, popup, debug) {
  1037. var o = options;
  1038. if ((o.showErrorMessages && !debug) || (debug && o.showDebugMessages))
  1039. $.layout.msg(o.name + ' / ' + msg, (popup !== false));
  1040. return false;
  1041. }
  1042. /**
  1043. * Executes a Callback function after a trigger event, like resize, open or close
  1044. *
  1045. * @param {string} evtName Name of the layout callback, eg "onresize_start"
  1046. * @param {(string|boolean)=} [pane=""] This is passed only so we can pass the 'pane object' to the callback
  1047. * @param {(string|boolean)=} [skipBoundEvents=false] True = do not run events bound to the elements - only the callbacks set in options
  1048. */
  1049. , _runCallbacks = function (evtName, pane, skipBoundEvents) {
  1050. var hasPane = pane && isStr(pane)
  1051. , s = hasPane ? state[pane] : state
  1052. , o = hasPane ? options[pane] : options
  1053. , lName = options.name
  1054. // names like onopen and onopen_end separate are interchangeable in options...
  1055. , lng = evtName + (evtName.match(/_/) ? "" : "_end")
  1056. , shrt = lng.match(/_end$/) ? lng.substr(0, lng.length - 4) : ""
  1057. , fn = o[lng] || o[shrt]
  1058. , retVal = "NC" // NC = No Callback
  1059. , args = []
  1060. , $P = hasPane ? $Ps[pane] : 0
  1061. ;
  1062. if (hasPane && !$P) // a pane is specified, but does not exist!
  1063. return retVal;
  1064. if (!hasPane && $.type(pane) === "boolean") {
  1065. skipBoundEvents = pane; // allow pane param to be skipped for Layout callback
  1066. pane = "";
  1067. }
  1068. // first trigger the callback set in the options
  1069. if (fn) {
  1070. try {
  1071. // convert function name (string) to function object
  1072. if (isStr(fn)) {
  1073. if (fn.match(/,/)) {
  1074. // function name cannot contain a comma,
  1075. // so must be a function name AND a parameter to pass
  1076. args = fn.split(",")
  1077. , fn = eval(args[0]);
  1078. }
  1079. else // just the name of an external function?
  1080. fn = eval(fn);
  1081. }
  1082. // execute the callback, if exists
  1083. if ($.isFunction(fn)) {
  1084. if (args.length)
  1085. retVal = g(fn)(args[1]); // pass the argument parsed from 'list'
  1086. else if (hasPane)
  1087. // pass data: pane-name, pane-element, pane-state, pane-options, and layout-name
  1088. retVal = g(fn)(pane, $Ps[pane], s, o, lName);
  1089. else // must be a layout/container callback - pass suitable info
  1090. retVal = g(fn)(Instance, s, o, lName);
  1091. }
  1092. }
  1093. catch (ex) {
  1094. _log(options.errors.callbackError.replace(/EVENT/, $.trim((pane || "") + " " + lng)), false);
  1095. if ($.type(ex) === "string" && string.length)
  1096. _log("Exception: " + ex, false);
  1097. }
  1098. }
  1099. // trigger additional events bound directly to the pane
  1100. if (!skipBoundEvents && retVal !== false) {
  1101. if (hasPane) { // PANE events can be bound to each pane-elements
  1102. o = options[pane];
  1103. s = state[pane];
  1104. $P.triggerHandler("layoutpane" + lng, [pane, $P, s, o, lName]);
  1105. if (shrt)
  1106. $P.triggerHandler("layoutpane" + shrt, [pane, $P, s, o, lName]);
  1107. }
  1108. else { // LAYOUT events can be bound to the container-element
  1109. $N.triggerHandler("layout" + lng, [Instance, s, o, lName]);
  1110. if (shrt)
  1111. $N.triggerHandler("layout" + shrt, [Instance, s, o, lName]);
  1112. }
  1113. }
  1114. // ALWAYS resizeChildren after an onresize_end event - even during initialization
  1115. // IGNORE onsizecontent_end event because causes child-layouts to resize TWICE
  1116. if (hasPane && evtName === "onresize_end") // BAD: || evtName === "onsizecontent_end"
  1117. resizeChildren(pane + "", true); // compiler hack -force string
  1118. return retVal;
  1119. function g(f) { return f; }; // compiler hack
  1120. }
  1121. /**
  1122. * cure iframe display issues in IE & other browsers
  1123. */
  1124. , _fixIframe = function (pane) {
  1125. if (browser.mozilla) return; // skip FireFox - it auto-refreshes iframes onShow
  1126. var $P = $Ps[pane];
  1127. // if the 'pane' is an iframe, do it
  1128. if (state[pane].tagName === "IFRAME")
  1129. $P.css(_c.hidden).css(_c.visible);
  1130. else // ditto for any iframes INSIDE the pane
  1131. $P.find('IFRAME').css(_c.hidden).css(_c.visible);
  1132. }
  1133. /**
  1134. * @param {string} pane Can accept ONLY a 'pane' (east, west, etc)
  1135. * @param {number=} outerSize (optional) Can pass a width, allowing calculations BEFORE element is resized
  1136. * @return {number} Returns the innerHeight/Width of el by subtracting padding and borders
  1137. */
  1138. , cssSize = function (pane, outerSize) {
  1139. var fn = _c[pane].dir == "horz" ? cssH : cssW;
  1140. return fn($Ps[pane], outerSize);
  1141. }
  1142. /**
  1143. * @param {string} pane Can accept ONLY a 'pane' (east, west, etc)
  1144. * @return {Object} Returns hash of minWidth & minHeight
  1145. */
  1146. , cssMinDims = function (pane) {
  1147. // minWidth/Height means CSS width/height = 1px
  1148. var $P = $Ps[pane]
  1149. , dir = _c[pane].dir
  1150. , d = {
  1151. minWidth: 1001 - cssW($P, 1000)
  1152. , minHeight: 1001 - cssH($P, 1000)
  1153. }
  1154. ;
  1155. if (dir === "horz") d.minSize = d.minHeight;
  1156. if (dir === "vert") d.minSize = d.minWidth;
  1157. return d;
  1158. }
  1159. // TODO: see if these methods can be made more useful...
  1160. // TODO: *maybe* return cssW/H from these so caller can use this info
  1161. /**
  1162. * @param {(string|!Object)} el
  1163. * @param {number=} outerWidth
  1164. * @param {boolean=} [autoHide=false]
  1165. */
  1166. , setOuterWidth = function (el, outerWidth, autoHide) {
  1167. var $E = el, w;
  1168. if (isStr(el)) $E = $Ps[el]; // west
  1169. else if (!el.jquery) $E = $(el);
  1170. w = cssW($E, outerWidth);
  1171. $E.css({ width: w });
  1172. if (w > 0) {
  1173. if (autoHide && $E.data('autoHidden') && $E.innerHeight() > 0) {
  1174. $E.show().data('autoHidden', false);
  1175. if (!browser.mozilla) // FireFox refreshes iframes - IE does not
  1176. // make hidden, then visible to 'refresh' display after animation
  1177. $E.css(_c.hidden).css(_c.visible);
  1178. }
  1179. }
  1180. else if (autoHide && !$E.data('autoHidden'))
  1181. $E.hide().data('autoHidden', true);
  1182. }
  1183. /**
  1184. * @param {(string|!Object)} el
  1185. * @param {number=} outerHeight
  1186. * @param {boolean=} [autoHide=false]
  1187. */
  1188. , setOuterHeight = function (el, outerHeight, autoHide) {
  1189. var $E = el, h;
  1190. if (isStr(el)) $E = $Ps[el]; // west
  1191. else if (!el.jquery) $E = $(el);
  1192. h = cssH($E, outerHeight);
  1193. $E.css({ height: h, visibility: "visible" }); // may have been 'hidden' by sizeContent
  1194. if (h > 0 && $E.innerWidth() > 0) {
  1195. if (autoHide && $E.data('autoHidden')) {
  1196. $E.show().data('autoHidden', false);
  1197. if (!browser.mozilla) // FireFox refreshes iframes - IE does not
  1198. $E.css(_c.hidden).css(_c.visible);
  1199. }
  1200. }
  1201. else if (autoHide && !$E.data('autoHidden'))
  1202. $E.hide().data('autoHidden', true);
  1203. }
  1204. /**
  1205. * Converts any 'size' params to a pixel/integer size, if not already
  1206. * If 'auto' or a decimal/percentage is passed as 'size', a pixel-size is calculated
  1207. *
  1208. /**
  1209. * @param {string} pane
  1210. * @param {(string|number)=} size
  1211. * @param {string=} [dir]
  1212. * @return {number}
  1213. */
  1214. , _parseSize = function (pane, size, dir) {
  1215. if (!dir) dir = _c[pane].dir;
  1216. if (isStr(size) && size.match(/%/))
  1217. size = (size === '100%') ? -1 : parseInt(size, 10) / 100; // convert % to decimal
  1218. if (size === 0)
  1219. return 0;
  1220. else if (size >= 1)
  1221. return parseInt(size, 10);
  1222. var o = options, avail = 0;
  1223. if (dir == "horz") // north or south or center.minHeight
  1224. avail = sC.innerHeight - ($Ps.north ? o.north.spacing_open : 0) - ($Ps.south ? o.south.spacing_open : 0);
  1225. else if (dir == "vert") // east or west or center.minWidth
  1226. avail = sC.innerWidth - ($Ps.west ? o.west.spacing_open : 0) - ($Ps.east ? o.east.spacing_open : 0);
  1227. if (size === -1) // -1 == 100%
  1228. return avail;
  1229. else if (size > 0) // percentage, eg: .25
  1230. return round(avail * size);
  1231. else if (pane == "center")
  1232. return 0;
  1233. else { // size < 0 || size=='auto' || size==Missing || size==Invalid
  1234. // auto-size the pane
  1235. var dim = (dir === "horz" ? "height" : "width")
  1236. , $P = $Ps[pane]
  1237. , $C = dim === 'height' ? $Cs[pane] : false
  1238. , vis = $.layout.showInvisibly($P) // show pane invisibly if hidden
  1239. , szP = $P.css(dim) // SAVE current pane size
  1240. , szC = $C ? $C.css(dim) : 0 // SAVE current content size
  1241. ;
  1242. $P.css(dim, "auto");
  1243. if ($C) $C.css(dim, "auto");
  1244. size = (dim === "height") ? $P.outerHeight() : $P.outerWidth(); // MEASURE
  1245. $P.css(dim, szP).css(vis); // RESET size & visibility
  1246. if ($C) $C.css(dim, szC);
  1247. return size;
  1248. }
  1249. }
  1250. /**
  1251. * Calculates current 'size' (outer-width or outer-height) of a border-pane - optionally with 'pane-spacing' added
  1252. *
  1253. * @param {(string|!Object)} pane
  1254. * @param {boolean=} [inclSpace=false]
  1255. * @return {number} Returns EITHER Width for east/west panes OR Height for north/south panes
  1256. */
  1257. , getPaneSize = function (pane, inclSpace) {
  1258. var
  1259. $P = $Ps[pane]
  1260. , o = options[pane]
  1261. , s = state[pane]
  1262. , oSp = (inclSpace ? o.spacing_open : 0)
  1263. , cSp = (inclSpace ? o.spacing_closed : 0)
  1264. ;
  1265. if (!$P || s.isHidden)
  1266. return 0;
  1267. else if (s.isClosed || (s.isSliding && inclSpace))
  1268. return cSp;
  1269. else if (_c[pane].dir === "horz")
  1270. return $P.outerHeight() + oSp;
  1271. else // dir === "vert"
  1272. return $P.outerWidth() + oSp;
  1273. }
  1274. /**
  1275. * Calculate min/max pane dimensions and limits for resizing
  1276. *
  1277. * @param {string} pane
  1278. * @param {boolean=} [slide=false]
  1279. */
  1280. , setSizeLimits = function (pane, slide) {
  1281. if (!isInitialized()) return;
  1282. var
  1283. o = options[pane]
  1284. , s = state[pane]
  1285. , c = _c[pane]
  1286. , dir = c.dir
  1287. , type = c.sizeType.toLowerCase()
  1288. , isSliding = (slide != undefined ? slide : s.isSliding) // only open() passes 'slide' param
  1289. , $P = $Ps[pane]
  1290. , paneSpacing = o.spacing_open
  1291. // measure the pane on the *opposite side* from this pane
  1292. , altPane = _c.oppositeEdge[pane]
  1293. , altS = state[altPane]
  1294. , $altP = $Ps[altPane]
  1295. , altPaneSize = (!$altP || altS.isVisible === false || altS.isSliding ? 0 : (dir == "horz" ? $altP.outerHeight() : $altP.outerWidth()))
  1296. , altPaneSpacing = ((!$altP || altS.isHidden ? 0 : options[altPane][altS.isClosed !== false ? "spacing_closed" : "spacing_open"]) || 0)
  1297. // limitSize prevents this pane from 'overlapping' opposite pane
  1298. , containerSize = (dir == "horz" ? sC.innerHeight : sC.innerWidth)
  1299. , minCenterDims = cssMinDims("center")
  1300. , minCenterSize = dir == "horz" ? max(options.center.minHeight, minCenterDims.minHeight) : max(options.center.minWidth, minCenterDims.minWidth)
  1301. // if pane is 'sliding', then ignore center and alt-pane sizes - because 'overlays' them
  1302. , limitSize = (containerSize - paneSpacing - (isSliding ? 0 : (_parseSize("center", minCenterSize, dir) + altPaneSize + altPaneSpacing)))
  1303. , minSize = s.minSize = max(_parseSize(pane, o.minSize), cssMinDims(pane).minSize)
  1304. , maxSize = s.maxSize = min((o.maxSize ? _parseSize(pane, o.maxSize) : 100000), limitSize)
  1305. , r = s.resizerPosition = {} // used to set resizing limits
  1306. , top = sC.inset.top
  1307. , left = sC.inset.left
  1308. , W = sC.innerWidth
  1309. , H = sC.innerHeight
  1310. , rW = o.spacing_open // subtract resizer-width to get top/left position for south/east
  1311. ;
  1312. switch (pane) {
  1313. case "north": r.min = top + minSize;
  1314. r.max = top + maxSize;
  1315. break;
  1316. case "west": r.min = left + minSize;
  1317. r.max = left + maxSize;
  1318. break;
  1319. case "south": r.min = top + H - maxSize - rW;
  1320. r.max = top + H - minSize - rW;
  1321. break;
  1322. case "east": r.min = left + W - maxSize - rW;
  1323. r.max = left + W - minSize - rW;
  1324. break;
  1325. };
  1326. }
  1327. /**
  1328. * Returns data for setting the size/position of center pane. Also used to set Height for east/west panes
  1329. *
  1330. * @return JSON Returns a hash of all dimensions: top, bottom, left, right, (outer) width and (outer) height
  1331. */
  1332. , calcNewCenterPaneDims = function () {
  1333. var d = {
  1334. top: getPaneSize("north", true) // true = include 'spacing' value for pane
  1335. , bottom: getPaneSize("south", true)
  1336. , left: getPaneSize("west", true)
  1337. , right: getPaneSize("east", true)
  1338. , width: 0
  1339. , height: 0
  1340. };
  1341. // NOTE: sC = state.container
  1342. // calc center-pane outer dimensions
  1343. d.width = sC.innerWidth - d.left - d.right; // outerWidth
  1344. d.height = sC.innerHeight - d.bottom - d.top-9; // outerHeight
  1345. // add the 'container border/padding' to get final positions relative to the container
  1346. d.top += sC.inset.top;
  1347. d.bottom += sC.inset.bottom;
  1348. d.left += sC.inset.left;
  1349. d.right += sC.inset.right;
  1350. return d;
  1351. }
  1352. /**
  1353. * @param {!Object} el
  1354. * @param {boolean=} [allStates=false]
  1355. */
  1356. , getHoverClasses = function (el, allStates) {
  1357. var
  1358. $El = $(el)
  1359. , type = $El.data("layoutRole")
  1360. , pane = $El.data("layoutEdge")
  1361. , o = options[pane]
  1362. , root = o[type + "Class"]
  1363. , _pane = "-" + pane // eg: "-west"
  1364. , _open = "-open"
  1365. , _closed = "-closed"
  1366. , _slide = "-sliding"
  1367. , _hover = "-hover " // NOTE the trailing space
  1368. , _state = $El.hasClass(root + _closed) ? _closed : _open
  1369. , _alt = _state === _closed ? _open : _closed
  1370. , classes = (root + _hover) + (root + _pane + _hover) + (root + _state + _hover) + (root + _pane + _state + _hover)
  1371. ;
  1372. if (allStates) // when 'removing' classes, also remove alternate-state classes
  1373. classes += (root + _alt + _hover) + (root + _pane + _alt + _hover);
  1374. if (type == "resizer" && $El.hasClass(root + _slide))
  1375. classes += (root + _slide + _hover) + (root + _pane + _slide + _hover);
  1376. return $.trim(classes);
  1377. }
  1378. , addHover = function (evt, el) {
  1379. var $E = $(el || this);
  1380. if (evt && $E.data("layoutRole") === "toggler")
  1381. evt.stopPropagation(); // prevent triggering 'slide' on Resizer-bar
  1382. $E.addClass(getHoverClasses($E));
  1383. }
  1384. , removeHover = function (evt, el) {
  1385. var $E = $(el || this);
  1386. $E.removeClass(getHoverClasses($E, true));
  1387. }
  1388. , onResizerEnter = function (evt) { // ALSO called by toggler.mouseenter
  1389. var pane = $(this).data("layoutEdge")
  1390. , s = state[pane]
  1391. , $d = $(document)
  1392. ;
  1393. // ignore closed-panes and mouse moving back & forth over resizer!
  1394. // also ignore if ANY pane is currently resizing
  1395. if (s.isResizing || state.paneResizing) return;
  1396. if (options.maskPanesEarly)
  1397. showMasks(pane, { resizing: true });
  1398. }
  1399. , onResizerLeave = function (evt, el) {
  1400. var e = el || this // el is only passed when called by the timer
  1401. , pane = $(e).data("layoutEdge")
  1402. , name = pane + "ResizerLeave"
  1403. , $d = $(document)
  1404. ;
  1405. timer.clear(pane + "_openSlider"); // cancel slideOpen timer, if set
  1406. timer.clear(name); // cancel enableSelection timer - may re/set below
  1407. // this method calls itself on a timer because it needs to allow
  1408. // enough time for dragging to kick-in and set the isResizing flag
  1409. // dragging has a 100ms delay set, so this delay must be >100
  1410. if (!el) // 1st call - mouseleave event
  1411. timer.set(name, function () { onResizerLeave(evt, e); }, 200);
  1412. // if user is resizing, dragStop will reset everything, so skip it here
  1413. else if (options.maskPanesEarly && !state.paneResizing) // 2nd call - by timer
  1414. hideMasks();
  1415. }
  1416. /*
  1417. * ###########################
  1418. * INITIALIZATION METHODS
  1419. * ###########################
  1420. */
  1421. /**
  1422. * Initialize the layout - called automatically whenever an instance of layout is created
  1423. *
  1424. * @see none - triggered onInit
  1425. * @return mixed true = fully initialized | false = panes not initialized (yet) | 'cancel' = abort
  1426. */
  1427. , _create = function () {
  1428. // initialize config/options
  1429. initOptions();
  1430. var o = options
  1431. , s = state;
  1432. // TEMP state so isInitialized returns true during init process
  1433. s.creatingLayout = true;
  1434. // init plugins for this layout, if there are any (eg: stateManagement)
  1435. runPluginCallbacks(Instance, $.layout.onCreate);
  1436. // options & state have been initialized, so now run beforeLoad callback
  1437. // onload will CANCEL layout creation if it returns false
  1438. if (false === _runCallbacks("onload_start"))
  1439. return 'cancel';
  1440. // initialize the container element
  1441. _initContainer();
  1442. // bind hotkey function - keyDown - if required
  1443. initHotkeys();
  1444. // bind window.onunload
  1445. $(window).bind("unload." + sID, unload);
  1446. // init plugins for this layout, if there are any (eg: customButtons)
  1447. runPluginCallbacks(Instance, $.layout.onLoad);
  1448. // if layout elements are hidden, then layout WILL NOT complete initialization!
  1449. // initLayoutElements will set initialized=true and run the onload callback IF successful
  1450. if (o.initPanes) _initLayoutElements();
  1451. delete s.creatingLayout;
  1452. return state.initialized;
  1453. }
  1454. /**
  1455. * Initialize the layout IF not already
  1456. *
  1457. * @see All methods in Instance run this test
  1458. * @return boolean true = layoutElements have been initialized | false = panes are not initialized (yet)
  1459. */
  1460. , isInitialized = function () {
  1461. if (state.initialized || state.creatingLayout) return true; // already initialized
  1462. else return _initLayoutElements(); // try to init panes NOW
  1463. }
  1464. /**
  1465. * Initialize the layout - called automatically whenever an instance of layout is created
  1466. *
  1467. * @see _create() & isInitialized
  1468. * @param {boolean=} [retry=false] // indicates this is a 2nd try
  1469. * @return An object pointer to the instance created
  1470. */
  1471. , _initLayoutElements = function (retry) {
  1472. // initialize config/options
  1473. var o = options;
  1474. // CANNOT init panes inside a hidden container!
  1475. if (!$N.is(":visible")) {
  1476. // handle Chrome bug where popup window 'has no height'
  1477. // if layout is BODY element, try again in 50ms
  1478. // SEE: http://layout.jquery-dev.com/samples/test_popup_window.html
  1479. if (!retry && browser.webkit && $N[0].tagName === "BODY")
  1480. setTimeout(function () { _initLayoutElements(true); }, 50);
  1481. return false;
  1482. }
  1483. // a center pane is required, so make sure it exists
  1484. if (!getPane("center").length) {
  1485. return _log(o.errors.centerPaneMissing);
  1486. }
  1487. // TEMP state so isInitialized returns true during init process
  1488. state.creatingLayout = true;
  1489. // update Container dims
  1490. $.extend(sC, elDims($N, o.inset)); // passing inset means DO NOT include insetX values
  1491. // initialize all layout elements
  1492. initPanes(); // size & position panes - calls initHandles() - which calls initResizable()
  1493. if (o.scrollToBookmarkOnLoad) {
  1494. var l = self.location;
  1495. if (l.hash) l.replace(l.hash); // scrollTo Bookmark
  1496. }
  1497. // check to see if this layout 'nested' inside a pane
  1498. if (Instance.hasParentLayout)
  1499. o.resizeWithWindow = false;
  1500. // bind resizeAll() for 'this layout instance' to window.resize event
  1501. else if (o.resizeWithWindow)
  1502. $(window).bind("resize." + sID, windowResize);
  1503. delete state.creatingLayout;
  1504. state.initialized = true;
  1505. // init plugins for this layout, if there are any
  1506. runPluginCallbacks(Instance, $.layout.onReady);
  1507. // now run the onload callback, if exists
  1508. _runCallbacks("onload_end");
  1509. return true; // elements initialized successfully
  1510. }
  1511. /**
  1512. * Initialize nested layouts for a specific pane - can optionally pass layout-options
  1513. *
  1514. * @param {(string|Object)} evt_or_pane The pane being opened, ie: north, south, east, or west
  1515. * @param {Object=} [opts] Layout-options - if passed, will OVERRRIDE options[pane].children
  1516. * @return An object pointer to the layout instance created - or null
  1517. */
  1518. , createChildren = function (evt_or_pane, opts) {
  1519. var pane = evtPane.call(this, evt_or_pane)
  1520. , $P = $Ps[pane]
  1521. ;
  1522. if (!$P) return;
  1523. var $C = $Cs[pane]
  1524. , s = state[pane]
  1525. , o = options[pane]
  1526. , sm = options.stateManagement || {}
  1527. , cos = opts ? (o.children = opts) : o.children
  1528. ;
  1529. if ($.isPlainObject(cos))
  1530. cos = [cos]; // convert a hash to a 1-elem array
  1531. else if (!cos || !$.isArray(cos))
  1532. return;
  1533. $.each(cos, function (idx, co) {
  1534. if (!$.isPlainObject(co)) return;
  1535. // determine which element is supposed to be the 'child container'
  1536. // if pane has a 'containerSelector' OR a 'content-div', use those instead of the pane
  1537. var $containers = co.containerSelector ? $P.find(co.containerSelector) : ($C || $P);
  1538. $containers.each(function () {
  1539. var $cont = $(this)
  1540. , child = $cont.data("layout") // see if a child-layout ALREADY exists on this element
  1541. ;
  1542. // if no layout exists, but children are set, try to create the layout now
  1543. if (!child) {
  1544. // TODO: see about moving this to the stateManagement plugin, as a method
  1545. // set a unique child-instance key for this layout, if not already set
  1546. setInstanceKey({ container: $cont, options: co }, s);
  1547. // If THIS layout has a hash in stateManagement.autoLoad,
  1548. // then see if it also contains state-data for this child-layout
  1549. // If so, copy the stateData to child.options.stateManagement.autoLoad
  1550. if (sm.includeChildren && state.stateData[pane]) {
  1551. // THIS layout's state was cached when its state was loaded
  1552. var paneChildren = state.stateData[pane].children || {}
  1553. , childState = paneChildren[co.instanceKey]
  1554. , co_sm = co.stateManagement || (co.stateManagement = { autoLoad: true })
  1555. ;
  1556. // COPY the stateData into the autoLoad key
  1557. if (co_sm.autoLoad === true && childState) {
  1558. co_sm.autoSave = false; // disable autoSave because saving handled by parent-layout
  1559. co_sm.includeChildren = true; // cascade option - FOR NOW
  1560. co_sm.autoLoad = $.extend(true, {}, childState); // COPY the state-hash
  1561. }
  1562. }
  1563. // create the layout
  1564. child = $cont.layout(co);
  1565. // if successful, update data
  1566. if (child) {
  1567. // add the child and update all layout-pointers
  1568. // MAY have already been done by child-layout calling parent.refreshChildren()
  1569. refreshChildren(pane, child);
  1570. }
  1571. }
  1572. });
  1573. });
  1574. }
  1575. , setInstanceKey = function (child, parentPaneState) {
  1576. // create a named key for use in state and instance branches
  1577. var $c = child.container
  1578. , o = child.options
  1579. , sm = o.stateManagement
  1580. , key = o.instanceKey || $c.data("layoutInstanceKey")
  1581. ;
  1582. if (!key) key = (sm && sm.cookie ? sm.cookie.name : '') || o.name; // look for a name/key
  1583. if (!key) key = "layout" + (++parentPaneState.childIdx); // if no name/key found, generate one
  1584. else key = key.replace(/[^\w-]/gi, '_').replace(/_{2,}/g, '_'); // ensure is valid as a hash key
  1585. o.instanceKey = key;
  1586. $c.data("layoutInstanceKey", key); // useful if layout is destroyed and then recreated
  1587. return key;
  1588. }
  1589. /**
  1590. * @param {string} pane The pane being opened, ie: north, south, east, or west
  1591. * @param {Object=} newChild New child-layout Instance to add to this pane
  1592. */
  1593. , refreshChildren = function (pane, newChild) {
  1594. var $P = $Ps[pane]
  1595. , pC = children[pane]
  1596. , s = state[pane]
  1597. , o
  1598. ;
  1599. // check for destroy()ed layouts and update the child pointers & arrays
  1600. if ($.isPlainObject(pC)) {
  1601. $.each(pC, function (key, child) {
  1602. if (child.destroyed) delete pC[key]
  1603. });
  1604. // if no more children, remove the children hash
  1605. if ($.isEmptyObject(pC))
  1606. pC = children[pane] = null; // clear children hash
  1607. }
  1608. // see if there is a directly-nested layout inside this pane
  1609. // if there is, then there can be only ONE child-layout, so check that...
  1610. if (!newChild && !pC) {
  1611. newChild = $P.data("layout");
  1612. }
  1613. // if a newChild instance was passed, add it to children[pane]
  1614. if (newChild) {
  1615. // update child.state
  1616. newChild.hasParentLayout = true; // set parent-flag in child
  1617. // instanceKey is a key-name used in both state and children
  1618. o = newChild.options;
  1619. // set a unique child-instance key for this layout, if not already set
  1620. setInstanceKey(newChild, s);
  1621. // add pointer to pane.children hash
  1622. if (!pC) pC = children[pane] = {}; // create an empty children hash
  1623. pC[o.instanceKey] = newChild.container.data("layout"); // add childLayout instance
  1624. }
  1625. // ALWAYS refresh the pane.children alias, even if null
  1626. Instance[pane].children = children[pane];
  1627. // if newChild was NOT passed - see if there is a child layout NOW
  1628. if (!newChild) {
  1629. createChildren(pane); // MAY create a child and re-call this method
  1630. }
  1631. }
  1632. , windowResize = function () {
  1633. var o = options
  1634. , delay = Number(o.resizeWithWindowDelay);
  1635. if (delay < 10) delay = 100; // MUST have a delay!
  1636. // resizing uses a delay-loop because the resize event fires repeatly - except in FF, but delay anyway
  1637. timer.clear("winResize"); // if already running
  1638. timer.set("winResize", function () {
  1639. timer.clear("winResize");
  1640. timer.clear("winResizeRepeater");
  1641. var dims = elDims($N, o.inset);
  1642. // only trigger resizeAll() if container has changed size
  1643. if (dims.innerWidth !== sC.innerWidth || dims.innerHeight !== sC.innerHeight)
  1644. resizeAll();
  1645. }, delay);
  1646. // ALSO set fixed-delay timer, if not already running
  1647. if (!timer.data["winResizeRepeater"]) setWindowResizeRepeater();
  1648. }
  1649. , setWindowResizeRepeater = function () {
  1650. var delay = Number(options.resizeWithWindowMaxDelay);
  1651. if (delay > 0)
  1652. timer.set("winResizeRepeater", function () { setWindowResizeRepeater(); resizeAll(); }, delay);
  1653. }
  1654. , unload = function () {
  1655. var o = options;
  1656. _runCallbacks("onunload_start");
  1657. // trigger plugin callabacks for this layout (eg: stateManagement)
  1658. runPluginCallbacks(Instance, $.layout.onUnload);
  1659. _runCallbacks("onunload_end");
  1660. }
  1661. /**
  1662. * Validate and initialize container CSS and events
  1663. *
  1664. * @see _create()
  1665. */
  1666. , _initContainer = function () {
  1667. var
  1668. N = $N[0]
  1669. , $H = $("html")
  1670. , tag = sC.tagName = N.tagName
  1671. , id = sC.id = N.id
  1672. , cls = sC.className = N.className
  1673. , o = options
  1674. , name = o.name
  1675. , props = "position,margin,padding,border"
  1676. , css = "layoutCSS"
  1677. , CSS = {}
  1678. , hid = "hidden" // used A LOT!
  1679. // see if this container is a 'pane' inside an outer-layout
  1680. , parent = $N.data("parentLayout") // parent-layout Instance
  1681. , pane = $N.data("layoutEdge") // pane-name in parent-layout
  1682. , isChild = parent && pane
  1683. , num = $.layout.cssNum
  1684. , $parent, n
  1685. ;
  1686. // sC = state.container
  1687. sC.selector = $N.selector.split(".slice")[0];
  1688. sC.ref = (o.name ? o.name + ' layout / ' : '') + tag + (id ? "#" + id : cls ? '.[' + cls + ']' : ''); // used in messages
  1689. sC.isBody = (tag === "BODY");
  1690. // try to find a parent-layout
  1691. if (!isChild && !sC.isBody) {
  1692. $parent = $N.closest("." + $.layout.defaults.panes.paneClass);
  1693. parent = $parent.data("parentLayout");
  1694. pane = $parent.data("layoutEdge");
  1695. isChild = parent && pane;
  1696. }
  1697. $N.data({
  1698. layout: Instance
  1699. , layoutContainer: sID // FLAG to indicate this is a layout-container - contains unique internal ID
  1700. })
  1701. .addClass(o.containerClass)
  1702. ;
  1703. var layoutMethods = {
  1704. destroy: ''
  1705. , initPanes: ''
  1706. , resizeAll: 'resizeAll'
  1707. , resize: 'resizeAll'
  1708. };
  1709. // loop hash and bind all methods - include layoutID namespacing
  1710. for (name in layoutMethods) {
  1711. $N.bind("layout" + name.toLowerCase() + "." + sID, Instance[layoutMethods[name] || name]);
  1712. }
  1713. // if this container is another layout's 'pane', then set child/parent pointers
  1714. if (isChild) {
  1715. // update parent flag
  1716. Instance.hasParentLayout = true;
  1717. // set pointers to THIS child-layout (Instance) in parent-layout
  1718. parent.refreshChildren(pane, Instance);
  1719. }
  1720. // SAVE original container CSS for use in destroy()
  1721. if (!$N.data(css)) {
  1722. // handle props like overflow different for BODY & HTML - has 'system default' values
  1723. if (sC.isBody) {
  1724. // SAVE <BODY> CSS
  1725. $N.data(css, $.extend(styles($N, props), {
  1726. height: $N.css("height")
  1727. , overflow: $N.css("overflow")
  1728. , overflowX: $N.css("overflowX")
  1729. , overflowY: $N.css("overflowY")
  1730. }));
  1731. // ALSO SAVE <HTML> CSS
  1732. $H.data(css, $.extend(styles($H, 'padding'), {
  1733. height: "auto" // FF would return a fixed px-size!
  1734. , overflow: $H.css("overflow")
  1735. , overflowX: $H.css("overflowX")
  1736. , overflowY: $H.css("overflowY")
  1737. }));
  1738. }
  1739. else // handle props normally for non-body elements
  1740. $N.data(css, styles($N, props + ",top,bottom,left,right,width,height,overflow,overflowX,overflowY"));
  1741. }
  1742. try {
  1743. // common container CSS
  1744. CSS = {
  1745. overflow: hid
  1746. , overflowX: hid
  1747. , overflowY: hid
  1748. };
  1749. $N.css(CSS);
  1750. if (o.inset && !$.isPlainObject(o.inset)) {
  1751. // can specify a single number for equal outset all-around
  1752. n = parseInt(o.inset, 10) || 0
  1753. o.inset = {
  1754. top: n
  1755. , bottom: n
  1756. , left: n
  1757. , right: n
  1758. };
  1759. }
  1760. // format html & body if this is a full page layout
  1761. if (sC.isBody) {
  1762. // if HTML has padding, use this as an outer-spacing around BODY
  1763. if (!o.outset) {
  1764. // use padding from parent-elem (HTML) as outset
  1765. o.outset = {
  1766. top: num($H, "paddingTop")
  1767. , bottom: num($H, "paddingBottom")
  1768. , left: num($H, "paddingLeft")
  1769. , right: num($H, "paddingRight")
  1770. };
  1771. }
  1772. else if (!$.isPlainObject(o.outset)) {
  1773. // can specify a single number for equal outset all-around
  1774. n = parseInt(o.outset, 10) || 0
  1775. o.outset = {
  1776. top: n
  1777. , bottom: n
  1778. , left: n
  1779. , right: n
  1780. };
  1781. }
  1782. // HTML
  1783. $H.css(CSS).css({
  1784. height: "100%"
  1785. , border: "none" // no border or padding allowed when using height = 100%
  1786. , padding: 0 // ditto
  1787. , margin: 0
  1788. });
  1789. // BODY
  1790. if (browser.isIE6) {
  1791. // IE6 CANNOT use the trick of setting absolute positioning on all 4 sides - must have 'height'
  1792. $N.css({
  1793. width: "100%"
  1794. , height: "100%"
  1795. , border: "none" // no border or padding allowed when using height = 100%
  1796. , padding: 0 // ditto
  1797. , margin: 0
  1798. , position: "relative"
  1799. });
  1800. // convert body padding to an inset option - the border cannot be measured in IE6!
  1801. if (!o.inset) o.inset = elDims($N).inset;
  1802. }
  1803. else { // use absolute positioning for BODY to allow borders & padding without overflow
  1804. $N.css({
  1805. width: "auto"
  1806. , height: "auto"
  1807. , margin: 0
  1808. , position: "absolute" // allows for border and padding on BODY
  1809. });
  1810. // apply edge-positioning created above
  1811. $N.css(o.outset);
  1812. }
  1813. // set current layout-container dimensions
  1814. $.extend(sC, elDims($N, o.inset)); // passing inset means DO NOT include insetX values
  1815. }
  1816. else {
  1817. // container MUST have 'position'
  1818. var p = $N.css("position");
  1819. if (!p || !p.match(/(fixed|absolute|relative)/))
  1820. $N.css("position", "relative");
  1821. // set current layout-container dimensions
  1822. if ($N.is(":visible")) {
  1823. $.extend(sC, elDims($N, o.inset)); // passing inset means DO NOT change insetX (padding) values
  1824. if (sC.innerHeight < 1) // container has no 'height' - warn developer
  1825. _log(o.errors.noContainerHeight.replace(/CONTAINER/, sC.ref));
  1826. }
  1827. }
  1828. // if container has min-width/height, then enable scrollbar(s)
  1829. if (num($N, "minWidth")) $N.parent().css("overflowX", "auto");
  1830. if (num($N, "minHeight")) $N.parent().css("overflowY", "auto");
  1831. } catch (ex) { }
  1832. }
  1833. /**
  1834. * Bind layout hotkeys - if options enabled
  1835. *
  1836. * @see _create() and addPane()
  1837. * @param {string=} [panes=""] The edge(s) to process
  1838. */
  1839. , initHotkeys = function (panes) {
  1840. panes = panes ? panes.split(",") : _c.borderPanes;
  1841. // bind keyDown to capture hotkeys, if option enabled for ANY pane
  1842. $.each(panes, function (i, pane) {
  1843. var o = options[pane];
  1844. if (o.enableCursorHotkey || o.customHotkey) {
  1845. $(document).bind("keydown." + sID, keyDown); // only need to bind this ONCE
  1846. return false; // BREAK - binding was done
  1847. }
  1848. });
  1849. }
  1850. /**
  1851. * Build final OPTIONS data
  1852. *
  1853. * @see _create()
  1854. */
  1855. , initOptions = function () {
  1856. var data, d, pane, key, val, i, c, o;
  1857. // reprocess user's layout-options to have correct options sub-key structure
  1858. opts = $.layout.transformData(opts, true); // panes = default subkey
  1859. // auto-rename old options for backward compatibility
  1860. opts = $.layout.backwardCompatibility.renameAllOptions(opts);
  1861. // if user-options has 'panes' key (pane-defaults), clean it...
  1862. if (!$.isEmptyObject(opts.panes)) {
  1863. // REMOVE any pane-defaults that MUST be set per-pane
  1864. data = $.layout.optionsMap.noDefault;
  1865. for (i = 0, c = data.length; i < c; i++) {
  1866. key = data[i];
  1867. delete opts.panes[key]; // OK if does not exist
  1868. }
  1869. // REMOVE any layout-options specified under opts.panes
  1870. data = $.layout.optionsMap.layout;
  1871. for (i = 0, c = data.length; i < c; i++) {
  1872. key = data[i];
  1873. delete opts.panes[key]; // OK if does not exist
  1874. }
  1875. }
  1876. // MOVE any NON-layout-options from opts-root to opts.panes
  1877. data = $.layout.optionsMap.layout;
  1878. var rootKeys = $.layout.config.optionRootKeys;
  1879. for (key in opts) {
  1880. val = opts[key];
  1881. if ($.inArray(key, rootKeys) < 0 && $.inArray(key, data) < 0) {
  1882. if (!opts.panes[key])
  1883. opts.panes[key] = $.isPlainObject(val) ? $.extend(true, {}, val) : val;
  1884. delete opts[key]
  1885. }
  1886. }
  1887. // START by updating ALL options from opts
  1888. $.extend(true, options, opts);
  1889. // CREATE final options (and config) for EACH pane
  1890. $.each(_c.allPanes, function (i, pane) {
  1891. // apply 'pane-defaults' to CONFIG.[PANE]
  1892. _c[pane] = $.extend(true, {}, _c.panes, _c[pane]);
  1893. d = options.panes;
  1894. o = options[pane];
  1895. // center-pane uses SOME keys in defaults.panes branch
  1896. if (pane === 'center') {
  1897. // ONLY copy keys from opts.panes listed in: $.layout.optionsMap.center
  1898. data = $.layout.optionsMap.center; // list of 'center-pane keys'
  1899. for (i = 0, c = data.length; i < c; i++) { // loop the list...
  1900. key = data[i];
  1901. // only need to use pane-default if pane-specific value not set
  1902. if (!opts.center[key] && (opts.panes[key] || !o[key]))
  1903. o[key] = d[key]; // pane-default
  1904. }
  1905. }
  1906. else {
  1907. // border-panes use ALL keys in defaults.panes branch
  1908. o = options[pane] = $.extend(true, {}, d, o); // re-apply pane-specific opts AFTER pane-defaults
  1909. createFxOptions(pane);
  1910. // ensure all border-pane-specific base-classes exist
  1911. if (!o.resizerClass) o.resizerClass = "ui-layout-resizer";
  1912. if (!o.togglerClass) o.togglerClass = "ui-layout-toggler";
  1913. }
  1914. // ensure we have base pane-class (ALL panes)
  1915. if (!o.paneClass) o.paneClass = "ui-layout-pane";
  1916. });
  1917. // update options.zIndexes if a zIndex-option specified
  1918. var zo = opts.zIndex
  1919. , z = options.zIndexes;
  1920. if (zo > 0) {
  1921. z.pane_normal = zo;
  1922. z.content_mask = max(zo + 1, z.content_mask); // MIN = +1
  1923. z.resizer_normal = max(zo + 2, z.resizer_normal); // MIN = +2
  1924. }
  1925. // DELETE 'panes' key now that we are done - values were copied to EACH pane
  1926. delete options.panes;
  1927. function createFxOptions(pane) {
  1928. var o = options[pane]
  1929. , d = options.panes;
  1930. // ensure fxSettings key to avoid errors
  1931. if (!o.fxSettings) o.fxSettings = {};
  1932. if (!d.fxSettings) d.fxSettings = {};
  1933. $.each(["_open", "_close", "_size"], function (i, n) {
  1934. var
  1935. sName = "fxName" + n
  1936. , sSpeed = "fxSpeed" + n
  1937. , sSettings = "fxSettings" + n
  1938. // recalculate fxName according to specificity rules
  1939. , fxName = o[sName] =
  1940. o[sName] // options.west.fxName_open
  1941. || d[sName] // options.panes.fxName_open
  1942. || o.fxName // options.west.fxName
  1943. || d.fxName // options.panes.fxName
  1944. || "none" // MEANS $.layout.defaults.panes.fxName == "" || false || null || 0
  1945. , fxExists = $.effects && ($.effects[fxName] || ($.effects.effect && $.effects.effect[fxName]))
  1946. ;
  1947. // validate fxName to ensure is valid effect - MUST have effect-config data in options.effects
  1948. if (fxName === "none" || !options.effects[fxName] || !fxExists)
  1949. fxName = o[sName] = "none"; // effect not loaded OR unrecognized fxName
  1950. // set vars for effects subkeys to simplify logic
  1951. var fx = options.effects[fxName] || {} // effects.slide
  1952. , fx_all = fx.all || null // effects.slide.all
  1953. , fx_pane = fx[pane] || null // effects.slide.west
  1954. ;
  1955. // create fxSpeed[_open|_close|_size]
  1956. o[sSpeed] =
  1957. o[sSpeed] // options.west.fxSpeed_open
  1958. || d[sSpeed] // options.west.fxSpeed_open
  1959. || o.fxSpeed // options.west.fxSpeed
  1960. || d.fxSpeed // options.panes.fxSpeed
  1961. || null // DEFAULT - let fxSetting.duration control speed
  1962. ;
  1963. // create fxSettings[_open|_close|_size]
  1964. o[sSettings] = $.extend(
  1965. true
  1966. , {}
  1967. , fx_all // effects.slide.all
  1968. , fx_pane // effects.slide.west
  1969. , d.fxSettings // options.panes.fxSettings
  1970. , o.fxSettings // options.west.fxSettings
  1971. , d[sSettings] // options.panes.fxSettings_open
  1972. , o[sSettings] // options.west.fxSettings_open
  1973. );
  1974. });
  1975. // DONE creating action-specific-settings for this pane,
  1976. // so DELETE generic options - are no longer meaningful
  1977. delete o.fxName;
  1978. delete o.fxSpeed;
  1979. delete o.fxSettings;
  1980. }
  1981. }
  1982. /**
  1983. * Initialize module objects, styling, size and position for all panes
  1984. *
  1985. * @see _initElements()
  1986. * @param {string} pane The pane to process
  1987. */
  1988. , getPane = function (pane) {
  1989. var sel = options[pane].paneSelector
  1990. if (sel.substr(0, 1) === "#") // ID selector
  1991. // NOTE: elements selected 'by ID' DO NOT have to be 'children'
  1992. return $N.find(sel).eq(0);
  1993. else { // class or other selector
  1994. var $P = $N.children(sel).eq(0);
  1995. // look for the pane nested inside a 'form' element
  1996. return $P.length ? $P : $N.children("form:first").children(sel).eq(0);
  1997. }
  1998. }
  1999. /**
  2000. * @param {Object=} evt
  2001. */
  2002. , initPanes = function (evt) {
  2003. // stopPropagation if called by trigger("layoutinitpanes") - use evtPane utility
  2004. evtPane(evt);
  2005. // NOTE: do north & south FIRST so we can measure their height - do center LAST
  2006. $.each(_c.allPanes, function (idx, pane) {
  2007. addPane(pane, true);
  2008. });
  2009. // init the pane-handles NOW in case we have to hide or close the pane below
  2010. initHandles();
  2011. // now that all panes have been initialized and initially-sized,
  2012. // make sure there is really enough space available for each pane
  2013. $.each(_c.borderPanes, function (i, pane) {
  2014. if ($Ps[pane] && state[pane].isVisible) { // pane is OPEN
  2015. setSizeLimits(pane);
  2016. makePaneFit(pane); // pane may be Closed, Hidden or Resized by makePaneFit()
  2017. }
  2018. });
  2019. // size center-pane AGAIN in case we 'closed' a border-pane in loop above
  2020. sizeMidPanes("center");
  2021. // Chrome/Webkit sometimes fires callbacks BEFORE it completes resizing!
  2022. // Before RC30.3, there was a 10ms delay here, but that caused layout
  2023. // to load asynchrously, which is BAD, so try skipping delay for now
  2024. // process pane contents and callbacks, and init/resize child-layout if exists
  2025. $.each(_c.allPanes, function (idx, pane) {
  2026. afterInitPane(pane);
  2027. });
  2028. }
  2029. /**
  2030. * Add a pane to the layout - subroutine of initPanes()
  2031. *
  2032. * @see initPanes()
  2033. * @param {string} pane The pane to process
  2034. * @param {boolean=} [force=false] Size content after init
  2035. */
  2036. , addPane = function (pane, force) {
  2037. if (!force && !isInitialized()) return;
  2038. var
  2039. o = options[pane]
  2040. , s = state[pane]
  2041. , c = _c[pane]
  2042. , dir = c.dir
  2043. , fx = s.fx
  2044. , spacing = o.spacing_open || 0
  2045. , isCenter = (pane === "center")
  2046. , CSS = {}
  2047. , $P = $Ps[pane]
  2048. , size, minSize, maxSize, child
  2049. ;
  2050. // if pane-pointer already exists, remove the old one first
  2051. if ($P)
  2052. removePane(pane, false, true, false);
  2053. else
  2054. $Cs[pane] = false; // init
  2055. $P = $Ps[pane] = getPane(pane);
  2056. if (!$P.length) {
  2057. $Ps[pane] = false; // logic
  2058. return;
  2059. }
  2060. // SAVE original Pane CSS
  2061. if (!$P.data("layoutCSS")) {
  2062. var props = "position,top,left,bottom,right,width,height,overflow,zIndex,display,backgroundColor,padding,margin,border";
  2063. $P.data("layoutCSS", styles($P, props));
  2064. }
  2065. // create alias for pane data in Instance - initHandles will add more
  2066. Instance[pane] = {
  2067. name: pane
  2068. , pane: $Ps[pane]
  2069. , content: $Cs[pane]
  2070. , options: options[pane]
  2071. , state: state[pane]
  2072. , children: children[pane]
  2073. };
  2074. // add classes, attributes & events
  2075. $P.data({
  2076. parentLayout: Instance // pointer to Layout Instance
  2077. , layoutPane: Instance[pane] // NEW pointer to pane-alias-object
  2078. , layoutEdge: pane
  2079. , layoutRole: "pane"
  2080. })
  2081. .css(c.cssReq).css("zIndex", options.zIndexes.pane_normal)
  2082. .css(o.applyDemoStyles ? c.cssDemo : {}) // demo styles
  2083. .addClass(o.paneClass + " " + o.paneClass + "-" + pane) // default = "ui-layout-pane ui-layout-pane-west" - may be a dupe of 'paneSelector'
  2084. .bind("mouseenter." + sID, addHover)
  2085. .bind("mouseleave." + sID, removeHover)
  2086. ;
  2087. var paneMethods = {
  2088. hide: ''
  2089. , show: ''
  2090. , toggle: ''
  2091. , close: ''
  2092. , open: ''
  2093. , slideOpen: ''
  2094. , slideClose: ''
  2095. , slideToggle: ''
  2096. , size: 'sizePane'
  2097. , sizePane: 'sizePane'
  2098. , sizeContent: ''
  2099. , sizeHandles: ''
  2100. , enableClosable: ''
  2101. , disableClosable: ''
  2102. , enableSlideable: ''
  2103. , disableSlideable: ''
  2104. , enableResizable: ''
  2105. , disableResizable: ''
  2106. , swapPanes: 'swapPanes'
  2107. , swap: 'swapPanes'
  2108. , move: 'swapPanes'
  2109. , removePane: 'removePane'
  2110. , remove: 'removePane'
  2111. , createChildren: ''
  2112. , resizeChildren: ''
  2113. , resizeAll: 'resizeAll'
  2114. , resizeLayout: 'resizeAll'
  2115. }
  2116. , name;
  2117. // loop hash and bind all methods - include layoutID namespacing
  2118. for (name in paneMethods) {
  2119. $P.bind("layoutpane" + name.toLowerCase() + "." + sID, Instance[paneMethods[name] || name]);
  2120. }
  2121. // see if this pane has a 'scrolling-content element'
  2122. initContent(pane, false); // false = do NOT sizeContent() - called later
  2123. if (!isCenter) {
  2124. // call _parseSize AFTER applying pane classes & styles - but before making visible (if hidden)
  2125. // if o.size is auto or not valid, then MEASURE the pane and use that as its 'size'
  2126. size = s.size = _parseSize(pane, o.size);
  2127. minSize = _parseSize(pane, o.minSize) || 1;
  2128. maxSize = _parseSize(pane, o.maxSize) || 100000;
  2129. if (size > 0) size = max(min(size, maxSize), minSize);
  2130. s.autoResize = o.autoResize; // used with percentage sizes
  2131. // state for border-panes
  2132. s.isClosed = false; // true = pane is closed
  2133. s.isSliding = false; // true = pane is currently open by 'sliding' over adjacent panes
  2134. s.isResizing = false; // true = pane is in process of being resized
  2135. s.isHidden = false; // true = pane is hidden - no spacing, resizer or toggler is visible!
  2136. // array for 'pin buttons' whose classNames are auto-updated on pane-open/-close
  2137. if (!s.pins) s.pins = [];
  2138. }
  2139. // states common to ALL panes
  2140. s.tagName = $P[0].tagName;
  2141. s.edge = pane; // useful if pane is (or about to be) 'swapped' - easy find out where it is (or is going)
  2142. s.noRoom = false; // true = pane 'automatically' hidden due to insufficient room - will unhide automatically
  2143. s.isVisible = true; // false = pane is invisible - closed OR hidden - simplify logic
  2144. // init pane positioning
  2145. setPanePosition(pane);
  2146. // if pane is not visible,
  2147. if (dir === "horz") // north or south pane
  2148. CSS.height = cssH($P, size);
  2149. else if (dir === "vert") // east or west pane
  2150. CSS.width = cssW($P, size);
  2151. //else if (isCenter) {}
  2152. $P.css(CSS); // apply size -- top, bottom & height will be set by sizeMidPanes
  2153. if (dir != "horz") sizeMidPanes(pane, true); // true = skipCallback
  2154. // if manually adding a pane AFTER layout initialization, then...
  2155. if (state.initialized) {
  2156. initHandles(pane);
  2157. initHotkeys(pane);
  2158. }
  2159. // close or hide the pane if specified in settings
  2160. if (o.initClosed && o.closable && !o.initHidden)
  2161. close(pane, true, true); // true, true = force, noAnimation
  2162. else if (o.initHidden || o.initClosed)
  2163. hide(pane); // will be completely invisible - no resizer or spacing
  2164. else if (!s.noRoom)
  2165. // make the pane visible - in case was initially hidden
  2166. $P.css("display", "block");
  2167. // ELSE setAsOpen() - called later by initHandles()
  2168. // RESET visibility now - pane will appear IF display:block
  2169. $P.css("visibility", "visible");
  2170. // check option for auto-handling of pop-ups & drop-downs
  2171. if (o.showOverflowOnHover)
  2172. $P.hover(allowOverflow, resetOverflow);
  2173. // if manually adding a pane AFTER layout initialization, then...
  2174. if (state.initialized) {
  2175. afterInitPane(pane);
  2176. }
  2177. }
  2178. , afterInitPane = function (pane) {
  2179. var $P = $Ps[pane]
  2180. , s = state[pane]
  2181. , o = options[pane]
  2182. ;
  2183. if (!$P) return;
  2184. // see if there is a directly-nested layout inside this pane
  2185. if ($P.data("layout"))
  2186. refreshChildren(pane, $P.data("layout"));
  2187. // process pane contents and callbacks, and init/resize child-layout if exists
  2188. if (s.isVisible) { // pane is OPEN
  2189. if (state.initialized) // this pane was added AFTER layout was created
  2190. resizeAll(); // will also sizeContent
  2191. else
  2192. sizeContent(pane);
  2193. if (o.triggerEventsOnLoad)
  2194. _runCallbacks("onresize_end", pane);
  2195. else // automatic if onresize called, otherwise call it specifically
  2196. // resize child - IF inner-layout already exists (created before this layout)
  2197. resizeChildren(pane, true); // a previously existing childLayout
  2198. }
  2199. // init childLayouts - even if pane is not visible
  2200. if (o.initChildren && o.children)
  2201. createChildren(pane);
  2202. }
  2203. /**
  2204. * @param {string=} panes The pane(s) to process
  2205. */
  2206. , setPanePosition = function (panes) {
  2207. panes = panes ? panes.split(",") : _c.borderPanes;
  2208. // create toggler DIVs for each pane, and set object pointers for them, eg: $R.north = north toggler DIV
  2209. $.each(panes, function (i, pane) {
  2210. var $P = $Ps[pane]
  2211. , $R = $Rs[pane]
  2212. , o = options[pane]
  2213. , s = state[pane]
  2214. , side = _c[pane].side
  2215. , CSS = {}
  2216. ;
  2217. if (!$P) return; // pane does not exist - skip
  2218. // set css-position to account for container borders & padding
  2219. switch (pane) {
  2220. case "north": CSS.top = sC.inset.top;
  2221. CSS.left = sC.inset.left;
  2222. CSS.right = sC.inset.right;
  2223. break;
  2224. case "south": CSS.bottom = sC.inset.bottom;
  2225. CSS.left = sC.inset.left;
  2226. CSS.right = sC.inset.right;
  2227. break;
  2228. case "west": CSS.left = sC.inset.left; // top, bottom & height set by sizeMidPanes()
  2229. break;
  2230. case "east": CSS.right = sC.inset.right; // ditto
  2231. break;
  2232. case "center": // top, left, width & height set by sizeMidPanes()
  2233. }
  2234. // apply position
  2235. $P.css(CSS);
  2236. // update resizer position
  2237. if ($R && s.isClosed)
  2238. $R.css(side, sC.inset[side]);
  2239. else if ($R && !s.isHidden)
  2240. $R.css(side, sC.inset[side] + getPaneSize(pane));
  2241. });
  2242. }
  2243. /**
  2244. * Initialize module objects, styling, size and position for all resize bars and toggler buttons
  2245. *
  2246. * @see _create()
  2247. * @param {string=} [panes=""] The edge(s) to process
  2248. */
  2249. , initHandles = function (panes) {
  2250. panes = panes ? panes.split(",") : _c.borderPanes;
  2251. // create toggler DIVs for each pane, and set object pointers for them, eg: $R.north = north toggler DIV
  2252. $.each(panes, function (i, pane) {
  2253. var $P = $Ps[pane];
  2254. $Rs[pane] = false; // INIT
  2255. $Ts[pane] = false;
  2256. if (!$P) return; // pane does not exist - skip
  2257. var o = options[pane]
  2258. , s = state[pane]
  2259. , c = _c[pane]
  2260. , paneId = o.paneSelector.substr(0, 1) === "#" ? o.paneSelector.substr(1) : ""
  2261. , rClass = o.resizerClass
  2262. , tClass = o.togglerClass
  2263. , spacing = (s.isVisible ? o.spacing_open : o.spacing_closed)
  2264. , _pane = "-" + pane // used for classNames
  2265. , _state = (s.isVisible ? "-open" : "-closed") // used for classNames
  2266. , I = Instance[pane]
  2267. // INIT RESIZER BAR
  2268. , $R = I.resizer = $Rs[pane] = $("<div></div>")
  2269. // INIT TOGGLER BUTTON
  2270. , $T = I.toggler = (o.closable ? $Ts[pane] = $("<div></div>") : false)
  2271. ;
  2272. //if (s.isVisible && o.resizable) ... handled by initResizable
  2273. if (!s.isVisible && o.slidable)
  2274. $R.attr("title", o.tips.Slide).css("cursor", o.sliderCursor);
  2275. $R // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "paneLeft-resizer"
  2276. .attr("id", paneId ? paneId + "-resizer" : "")
  2277. .data({
  2278. parentLayout: Instance
  2279. , layoutPane: Instance[pane] // NEW pointer to pane-alias-object
  2280. , layoutEdge: pane
  2281. , layoutRole: "resizer"
  2282. })
  2283. .css(_c.resizers.cssReq).css("zIndex", options.zIndexes.resizer_normal)
  2284. .css(o.applyDemoStyles ? _c.resizers.cssDemo : {}) // add demo styles
  2285. .addClass(rClass + " " + rClass + _pane)
  2286. .hover(addHover, removeHover) // ALWAYS add hover-classes, even if resizing is not enabled - handle with CSS instead
  2287. .hover(onResizerEnter, onResizerLeave) // ALWAYS NEED resizer.mouseleave to balance toggler.mouseenter
  2288. .mousedown($.layout.disableTextSelection) // prevent text-selection OUTSIDE resizer
  2289. .mouseup($.layout.enableTextSelection) // not really necessary, but just in case
  2290. .appendTo($N) // append DIV to container
  2291. ;
  2292. if ($.fn.disableSelection)
  2293. $R.disableSelection(); // prevent text-selection INSIDE resizer
  2294. if (o.resizerDblClickToggle)
  2295. $R.bind("dblclick." + sID, toggle);
  2296. if ($T) {
  2297. $T // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "#paneLeft-toggler"
  2298. .attr("id", paneId ? paneId + "-toggler" : "")
  2299. .data({
  2300. parentLayout: Instance
  2301. , layoutPane: Instance[pane] // NEW pointer to pane-alias-object
  2302. , layoutEdge: pane
  2303. , layoutRole: "toggler"
  2304. })
  2305. .css(_c.togglers.cssReq) // add base/required styles
  2306. .css(o.applyDemoStyles ? _c.togglers.cssDemo : {}) // add demo styles
  2307. .addClass(tClass + " " + tClass + _pane)
  2308. .hover(addHover, removeHover) // ALWAYS add hover-classes, even if toggling is not enabled - handle with CSS instead
  2309. .bind("mouseenter", onResizerEnter) // NEED toggler.mouseenter because mouseenter MAY NOT fire on resizer
  2310. .appendTo($R) // append SPAN to resizer DIV
  2311. ;
  2312. // ADD INNER-SPANS TO TOGGLER
  2313. if (o.togglerContent_open) // ui-layout-open
  2314. $("<span>" + o.togglerContent_open + "</span>")
  2315. .data({
  2316. layoutEdge: pane
  2317. , layoutRole: "togglerContent"
  2318. })
  2319. .data("layoutRole", "togglerContent")
  2320. .data("layoutEdge", pane)
  2321. .addClass("content content-open")
  2322. .css("display", "none")
  2323. .appendTo($T)
  2324. //.hover( addHover, removeHover ) // use ui-layout-toggler-west-hover .content-open instead!
  2325. ;
  2326. if (o.togglerContent_closed) // ui-layout-closed
  2327. $("<span>" + o.togglerContent_closed + "</span>")
  2328. .data({
  2329. layoutEdge: pane
  2330. , layoutRole: "togglerContent"
  2331. })
  2332. .addClass("content content-closed")
  2333. .css("display", "none")
  2334. .appendTo($T)
  2335. //.hover( addHover, removeHover ) // use ui-layout-toggler-west-hover .content-closed instead!
  2336. ;
  2337. // ADD TOGGLER.click/.hover
  2338. enableClosable(pane);
  2339. }
  2340. // add Draggable events
  2341. initResizable(pane);
  2342. // ADD CLASSNAMES & SLIDE-BINDINGS - eg: class="resizer resizer-west resizer-open"
  2343. if (s.isVisible)
  2344. setAsOpen(pane); // onOpen will be called, but NOT onResize
  2345. else {
  2346. setAsClosed(pane); // onClose will be called
  2347. bindStartSlidingEvents(pane, true); // will enable events IF option is set
  2348. }
  2349. });
  2350. // SET ALL HANDLE DIMENSIONS
  2351. sizeHandles();
  2352. }
  2353. /**
  2354. * Initialize scrolling ui-layout-content div - if exists
  2355. *
  2356. * @see initPane() - or externally after an Ajax injection
  2357. * @param {string} pane The pane to process
  2358. * @param {boolean=} [resize=true] Size content after init
  2359. */
  2360. , initContent = function (pane, resize) {
  2361. if (!isInitialized()) return;
  2362. var
  2363. o = options[pane]
  2364. , sel = o.contentSelector
  2365. , I = Instance[pane]
  2366. , $P = $Ps[pane]
  2367. , $C
  2368. ;
  2369. if (sel) $C = I.content = $Cs[pane] = (o.findNestedContent)
  2370. ? $P.find(sel).eq(0) // match 1-element only
  2371. : $P.children(sel).eq(0)
  2372. ;
  2373. if ($C && $C.length) {
  2374. $C.data("layoutRole", "content");
  2375. // SAVE original Content CSS
  2376. if (!$C.data("layoutCSS"))
  2377. $C.data("layoutCSS", styles($C, "height"));
  2378. $C.css(_c.content.cssReq);
  2379. if (o.applyDemoStyles) {
  2380. $C.css(_c.content.cssDemo); // add padding & overflow: auto to content-div
  2381. $P.css(_c.content.cssDemoPane); // REMOVE padding/scrolling from pane
  2382. }
  2383. // ensure no vertical scrollbar on pane - will mess up measurements
  2384. if ($P.css("overflowX").match(/(scroll|auto)/)) {
  2385. $P.css("overflow", "hidden");
  2386. }
  2387. state[pane].content = {}; // init content state
  2388. if (resize !== false) sizeContent(pane);
  2389. // sizeContent() is called AFTER init of all elements
  2390. }
  2391. else
  2392. I.content = $Cs[pane] = false;
  2393. }
  2394. /**
  2395. * Add resize-bars to all panes that specify it in options
  2396. * -dependancy: $.fn.resizable - will skip if not found
  2397. *
  2398. * @see _create()
  2399. * @param {string=} [panes=""] The edge(s) to process
  2400. */
  2401. , initResizable = function (panes) {
  2402. var draggingAvailable = $.layout.plugins.draggable
  2403. , side // set in start()
  2404. ;
  2405. panes = panes ? panes.split(",") : _c.borderPanes;
  2406. $.each(panes, function (idx, pane) {
  2407. var o = options[pane];
  2408. if (!draggingAvailable || !$Ps[pane] || !o.resizable) {
  2409. o.resizable = false;
  2410. return true; // skip to next
  2411. }
  2412. var s = state[pane]
  2413. , z = options.zIndexes
  2414. , c = _c[pane]
  2415. , side = c.dir == "horz" ? "top" : "left"
  2416. , $P = $Ps[pane]
  2417. , $R = $Rs[pane]
  2418. , base = o.resizerClass
  2419. , lastPos = 0 // used when live-resizing
  2420. , r, live // set in start because may change
  2421. // 'drag' classes are applied to the ORIGINAL resizer-bar while dragging is in process
  2422. , resizerClass = base + "-drag" // resizer-drag
  2423. , resizerPaneClass = base + "-" + pane + "-drag" // resizer-north-drag
  2424. // 'helper' class is applied to the CLONED resizer-bar while it is being dragged
  2425. , helperClass = base + "-dragging" // resizer-dragging
  2426. , helperPaneClass = base + "-" + pane + "-dragging" // resizer-north-dragging
  2427. , helperLimitClass = base + "-dragging-limit" // resizer-drag
  2428. , helperPaneLimitClass = base + "-" + pane + "-dragging-limit" // resizer-north-drag
  2429. , helperClassesSet = false // logic var
  2430. ;
  2431. if (!s.isClosed)
  2432. $R.attr("title", o.tips.Resize)
  2433. .css("cursor", o.resizerCursor); // n-resize, s-resize, etc
  2434. $R.draggable({
  2435. containment: $N[0] // limit resizing to layout container
  2436. , axis: (c.dir == "horz" ? "y" : "x") // limit resizing to horz or vert axis
  2437. , delay: 0
  2438. , distance: 1
  2439. , grid: o.resizingGrid
  2440. // basic format for helper - style it using class: .ui-draggable-dragging
  2441. , helper: "clone"
  2442. , opacity: o.resizerDragOpacity
  2443. , addClasses: false // avoid ui-state-disabled class when disabled
  2444. //, iframeFix: o.draggableIframeFix // TODO: consider using when bug is fixed
  2445. , zIndex: z.resizer_drag
  2446. , start: function (e, ui) {
  2447. // REFRESH options & state pointers in case we used swapPanes
  2448. o = options[pane];
  2449. s = state[pane];
  2450. // re-read options
  2451. live = o.livePaneResizing;
  2452. // ondrag_start callback - will CANCEL hide if returns false
  2453. // TODO: dragging CANNOT be cancelled like this, so see if there is a way?
  2454. if (false === _runCallbacks("ondrag_start", pane)) return false;
  2455. s.isResizing = true; // prevent pane from closing while resizing
  2456. state.paneResizing = pane; // easy to see if ANY pane is resizing
  2457. timer.clear(pane + "_closeSlider"); // just in case already triggered
  2458. // SET RESIZER LIMITS - used in drag()
  2459. setSizeLimits(pane); // update pane/resizer state
  2460. r = s.resizerPosition;
  2461. lastPos = ui.position[side]
  2462. $R.addClass(resizerClass + " " + resizerPaneClass); // add drag classes
  2463. helperClassesSet = false; // reset logic var - see drag()
  2464. // MASK PANES CONTAINING IFRAMES, APPLETS OR OTHER TROUBLESOME ELEMENTS
  2465. showMasks(pane, { resizing: true });
  2466. }
  2467. , drag: function (e, ui) {
  2468. if (!helperClassesSet) { // can only add classes after clone has been added to the DOM
  2469. //$(".ui-draggable-dragging")
  2470. ui.helper
  2471. .addClass(helperClass + " " + helperPaneClass) // add helper classes
  2472. .css({ right: "auto", bottom: "auto" }) // fix dir="rtl" issue
  2473. .children().css("visibility", "hidden") // hide toggler inside dragged resizer-bar
  2474. ;
  2475. helperClassesSet = true;
  2476. // draggable bug!? RE-SET zIndex to prevent E/W resize-bar showing through N/S pane!
  2477. if (s.isSliding) $Ps[pane].css("zIndex", z.pane_sliding);
  2478. }
  2479. // CONTAIN RESIZER-BAR TO RESIZING LIMITS
  2480. var limit = 0;
  2481. if (ui.position[side] < r.min) {
  2482. ui.position[side] = r.min;
  2483. limit = -1;
  2484. }
  2485. else if (ui.position[side] > r.max) {
  2486. ui.position[side] = r.max;
  2487. limit = 1;
  2488. }
  2489. // ADD/REMOVE dragging-limit CLASS
  2490. if (limit) {
  2491. ui.helper.addClass(helperLimitClass + " " + helperPaneLimitClass); // at dragging-limit
  2492. window.defaultStatus = (limit > 0 && pane.match(/(north|west)/)) || (limit < 0 && pane.match(/(south|east)/)) ? o.tips.maxSizeWarning : o.tips.minSizeWarning;
  2493. }
  2494. else {
  2495. ui.helper.removeClass(helperLimitClass + " " + helperPaneLimitClass); // not at dragging-limit
  2496. window.defaultStatus = "";
  2497. }
  2498. // DYNAMICALLY RESIZE PANES IF OPTION ENABLED
  2499. // won't trigger unless resizer has actually moved!
  2500. if (live && Math.abs(ui.position[side] - lastPos) >= o.liveResizingTolerance) {
  2501. lastPos = ui.position[side];
  2502. resizePanes(e, ui, pane)
  2503. }
  2504. }
  2505. , stop: function (e, ui) {
  2506. $('body').enableSelection(); // RE-ENABLE TEXT SELECTION
  2507. window.defaultStatus = ""; // clear 'resizing limit' message from statusbar
  2508. $R.removeClass(resizerClass + " " + resizerPaneClass); // remove drag classes from Resizer
  2509. s.isResizing = false;
  2510. state.paneResizing = false; // easy to see if ANY pane is resizing
  2511. resizePanes(e, ui, pane, true); // true = resizingDone
  2512. }
  2513. });
  2514. });
  2515. /**
  2516. * resizePanes
  2517. *
  2518. * Sub-routine called from stop() - and drag() if livePaneResizing
  2519. *
  2520. * @param {!Object} evt
  2521. * @param {!Object} ui
  2522. * @param {string} pane
  2523. * @param {boolean=} [resizingDone=false]
  2524. */
  2525. var resizePanes = function (evt, ui, pane, resizingDone) {
  2526. var dragPos = ui.position
  2527. , c = _c[pane]
  2528. , o = options[pane]
  2529. , s = state[pane]
  2530. , resizerPos
  2531. ;
  2532. switch (pane) {
  2533. case "north": resizerPos = dragPos.top; break;
  2534. case "west": resizerPos = dragPos.left; break;
  2535. case "south": resizerPos = sC.layoutHeight - dragPos.top - o.spacing_open; break;
  2536. case "east": resizerPos = sC.layoutWidth - dragPos.left - o.spacing_open; break;
  2537. };
  2538. // remove container margin from resizer position to get the pane size
  2539. var newSize = resizerPos - sC.inset[c.side];
  2540. // Disable OR Resize Mask(s) created in drag.start
  2541. if (!resizingDone) {
  2542. // ensure we meet liveResizingTolerance criteria
  2543. if (Math.abs(newSize - s.size) < o.liveResizingTolerance)
  2544. return; // SKIP resize this time
  2545. // resize the pane
  2546. manualSizePane(pane, newSize, false, true); // true = noAnimation
  2547. sizeMasks(); // resize all visible masks
  2548. }
  2549. else { // resizingDone
  2550. // ondrag_end callback
  2551. if (false !== _runCallbacks("ondrag_end", pane))
  2552. manualSizePane(pane, newSize, false, true); // true = noAnimation
  2553. hideMasks(true); // true = force hiding all masks even if one is 'sliding'
  2554. if (s.isSliding) // RE-SHOW 'object-masks' so objects won't show through sliding pane
  2555. showMasks(pane, { resizing: true });
  2556. }
  2557. };
  2558. }
  2559. /**
  2560. * sizeMask
  2561. *
  2562. * Needed to overlay a DIV over an IFRAME-pane because mask CANNOT be *inside* the pane
  2563. * Called when mask created, and during livePaneResizing
  2564. */
  2565. , sizeMask = function () {
  2566. var $M = $(this)
  2567. , pane = $M.data("layoutMask") // eg: "west"
  2568. , s = state[pane]
  2569. ;
  2570. // only masks over an IFRAME-pane need manual resizing
  2571. if (s.tagName == "IFRAME" && s.isVisible) // no need to mask closed/hidden panes
  2572. $M.css({
  2573. top: s.offsetTop
  2574. , left: s.offsetLeft
  2575. , width: s.outerWidth
  2576. , height: s.outerHeight
  2577. });
  2578. /* ALT Method...
  2579. var $P = $Ps[pane];
  2580. $M.css( $P.position() ).css({ width: $P[0].offsetWidth, height: $P[0].offsetHeight });
  2581. */
  2582. }
  2583. , sizeMasks = function () {
  2584. $Ms.each(sizeMask); // resize all 'visible' masks
  2585. }
  2586. /**
  2587. * @param {string} pane The pane being resized, animated or isSliding
  2588. * @param {Object=} [args] (optional) Options: which masks to apply, and to which panes
  2589. */
  2590. , showMasks = function (pane, args) {
  2591. var c = _c[pane]
  2592. , panes = ["center"]
  2593. , z = options.zIndexes
  2594. , a = $.extend({
  2595. objectsOnly: false
  2596. , animation: false
  2597. , resizing: true
  2598. , sliding: state[pane].isSliding
  2599. }, args)
  2600. , o, s
  2601. ;
  2602. if (a.resizing)
  2603. panes.push(pane);
  2604. if (a.sliding)
  2605. panes.push(_c.oppositeEdge[pane]); // ADD the oppositeEdge-pane
  2606. if (c.dir === "horz") {
  2607. panes.push("west");
  2608. panes.push("east");
  2609. }
  2610. $.each(panes, function (i, p) {
  2611. s = state[p];
  2612. o = options[p];
  2613. if (s.isVisible && (o.maskObjects || (!a.objectsOnly && o.maskContents))) {
  2614. getMasks(p).each(function () {
  2615. sizeMask.call(this);
  2616. this.style.zIndex = s.isSliding ? z.pane_sliding + 1 : z.pane_normal + 1
  2617. this.style.display = "block";
  2618. });
  2619. }
  2620. });
  2621. }
  2622. /**
  2623. * @param {boolean=} force Hide masks even if a pane is sliding
  2624. */
  2625. , hideMasks = function (force) {
  2626. // ensure no pane is resizing - could be a timing issue
  2627. if (force || !state.paneResizing) {
  2628. $Ms.hide(); // hide ALL masks
  2629. }
  2630. // if ANY pane is sliding, then DO NOT remove masks from panes with maskObjects enabled
  2631. else if (!force && !$.isEmptyObject(state.panesSliding)) {
  2632. var i = $Ms.length - 1
  2633. , p, $M;
  2634. for (; i >= 0; i--) {
  2635. $M = $Ms.eq(i);
  2636. p = $M.data("layoutMask");
  2637. if (!options[p].maskObjects) {
  2638. $M.hide();
  2639. }
  2640. }
  2641. }
  2642. }
  2643. /**
  2644. * @param {string} pane
  2645. */
  2646. , getMasks = function (pane) {
  2647. var $Masks = $([])
  2648. , $M, i = 0, c = $Ms.length
  2649. ;
  2650. for (; i < c; i++) {
  2651. $M = $Ms.eq(i);
  2652. if ($M.data("layoutMask") === pane)
  2653. $Masks = $Masks.add($M);
  2654. }
  2655. if ($Masks.length)
  2656. return $Masks;
  2657. else
  2658. return createMasks(pane);
  2659. }
  2660. /**
  2661. * createMasks
  2662. *
  2663. * Generates both DIV (ALWAYS used) and IFRAME (optional) elements as masks
  2664. * An IFRAME mask is created *under* the DIV when maskObjects=true, because a DIV cannot mask an applet
  2665. *
  2666. * @param {string} pane
  2667. */
  2668. , createMasks = function (pane) {
  2669. var
  2670. $P = $Ps[pane]
  2671. , s = state[pane]
  2672. , o = options[pane]
  2673. , z = options.zIndexes
  2674. , isIframe, el, $M, css, i
  2675. ;
  2676. if (!o.maskContents && !o.maskObjects) return $([]);
  2677. // if o.maskObjects=true, then loop TWICE to create BOTH kinds of mask, else only create a DIV
  2678. for (i = 0; i < (o.maskObjects ? 2 : 1) ; i++) {
  2679. isIframe = o.maskObjects && i == 0;
  2680. el = document.createElement(isIframe ? "iframe" : "div");
  2681. $M = $(el).data("layoutMask", pane); // add data to relate mask to pane
  2682. el.className = "ui-layout-mask ui-layout-mask-" + pane; // for user styling
  2683. css = el.style;
  2684. // Both DIVs and IFRAMES
  2685. css.background = "#FFF";
  2686. css.position = "absolute";
  2687. css.display = "block";
  2688. if (isIframe) { // IFRAME-only props
  2689. el.src = "about:blank";
  2690. el.frameborder = 0;
  2691. css.border = 0;
  2692. css.opacity = 0;
  2693. css.filter = "Alpha(Opacity='0')";
  2694. //el.allowTransparency = true; - for IE, but breaks masking ability!
  2695. }
  2696. else { // DIV-only props
  2697. css.opacity = 0.001;
  2698. css.filter = "Alpha(Opacity='1')";
  2699. }
  2700. // if pane IS an IFRAME, then must mask the pane itself
  2701. if (s.tagName == "IFRAME") {
  2702. // NOTE sizing done by a subroutine so can be called during live-resizing
  2703. css.zIndex = z.pane_normal + 1; // 1-higher than pane
  2704. $N.append(el); // append to LAYOUT CONTAINER
  2705. }
  2706. // otherwise put masks *inside the pane* to mask its contents
  2707. else {
  2708. $M.addClass("ui-layout-mask-inside-pane");
  2709. css.zIndex = o.maskZindex || z.content_mask; // usually 1, but customizable
  2710. css.top = 0;
  2711. css.left = 0;
  2712. css.width = "100%";
  2713. css.height = "100%";
  2714. $P.append(el); // append INSIDE pane element
  2715. }
  2716. // add Mask to cached array so can be resized & reused
  2717. $Ms = $Ms.add(el);
  2718. }
  2719. return $Ms;
  2720. }
  2721. /**
  2722. * Destroy this layout and reset all elements
  2723. *
  2724. * @param {boolean=} [destroyChildren=false] Destory Child-Layouts first?
  2725. */
  2726. , destroy = function (evt_or_destroyChildren, destroyChildren) {
  2727. // UNBIND layout events and remove global object
  2728. $(window).unbind("." + sID); // resize & unload
  2729. $(document).unbind("." + sID); // keyDown (hotkeys)
  2730. if (typeof evt_or_destroyChildren === "object")
  2731. // stopPropagation if called by trigger("layoutdestroy") - use evtPane utility
  2732. evtPane(evt_or_destroyChildren);
  2733. else // no event, so transfer 1st param to destroyChildren param
  2734. destroyChildren = evt_or_destroyChildren;
  2735. // need to look for parent layout BEFORE we remove the container data, else skips a level
  2736. //var parentPane = Instance.hasParentLayout ? $.layout.getParentPaneInstance( $N ) : null;
  2737. // reset layout-container
  2738. $N.clearQueue()
  2739. .removeData("layout")
  2740. .removeData("layoutContainer")
  2741. .removeClass(options.containerClass)
  2742. .unbind("." + sID) // remove ALL Layout events
  2743. ;
  2744. // remove all mask elements that have been created
  2745. $Ms.remove();
  2746. // loop all panes to remove layout classes, attributes and bindings
  2747. $.each(_c.allPanes, function (i, pane) {
  2748. removePane(pane, false, true, destroyChildren); // true = skipResize
  2749. });
  2750. // do NOT reset container CSS if is a 'pane' (or 'content') in an outer-layout - ie, THIS layout is 'nested'
  2751. var css = "layoutCSS";
  2752. if ($N.data(css) && !$N.data("layoutRole")) // RESET CSS
  2753. $N.css($N.data(css)).removeData(css);
  2754. // for full-page layouts, also reset the <HTML> CSS
  2755. if (sC.tagName === "BODY" && ($N = $("html")).data(css)) // RESET <HTML> CSS
  2756. $N.css($N.data(css)).removeData(css);
  2757. // trigger plugins for this layout, if there are any
  2758. runPluginCallbacks(Instance, $.layout.onDestroy);
  2759. // trigger state-management and onunload callback
  2760. unload();
  2761. // clear the Instance of everything except for container & options (so could recreate)
  2762. // RE-CREATE: myLayout = myLayout.container.layout( myLayout.options );
  2763. for (var n in Instance)
  2764. if (!n.match(/^(container|options)$/)) delete Instance[n];
  2765. // add a 'destroyed' flag to make it easy to check
  2766. Instance.destroyed = true;
  2767. // if this is a child layout, CLEAR the child-pointer in the parent
  2768. /* for now the pointer REMAINS, but with only container, options and destroyed keys
  2769. if (parentPane) {
  2770. var layout = parentPane.pane.data("parentLayout")
  2771. , key = layout.options.instanceKey || 'error';
  2772. // THIS SYNTAX MAY BE WRONG!
  2773. parentPane.children[key] = layout.children[ parentPane.name ].children[key] = null;
  2774. }
  2775. */
  2776. return Instance; // for coding convenience
  2777. }
  2778. /**
  2779. * Remove a pane from the layout - subroutine of destroy()
  2780. *
  2781. * @see destroy()
  2782. * @param {(string|Object)} evt_or_pane The pane to process
  2783. * @param {boolean=} [remove=false] Remove the DOM element?
  2784. * @param {boolean=} [skipResize=false] Skip calling resizeAll()?
  2785. * @param {boolean=} [destroyChild=true] Destroy Child-layouts? If not passed, obeys options setting
  2786. */
  2787. , removePane = function (evt_or_pane, remove, skipResize, destroyChild) {
  2788. if (!isInitialized()) return;
  2789. var pane = evtPane.call(this, evt_or_pane)
  2790. , $P = $Ps[pane]
  2791. , $C = $Cs[pane]
  2792. , $R = $Rs[pane]
  2793. , $T = $Ts[pane]
  2794. ;
  2795. // NOTE: elements can still exist even after remove()
  2796. // so check for missing data(), which is cleared by removed()
  2797. if ($P && $.isEmptyObject($P.data())) $P = false;
  2798. if ($C && $.isEmptyObject($C.data())) $C = false;
  2799. if ($R && $.isEmptyObject($R.data())) $R = false;
  2800. if ($T && $.isEmptyObject($T.data())) $T = false;
  2801. if ($P) $P.stop(true, true);
  2802. var o = options[pane]
  2803. , s = state[pane]
  2804. , d = "layout"
  2805. , css = "layoutCSS"
  2806. , pC = children[pane]
  2807. , hasChildren = $.isPlainObject(pC) && !$.isEmptyObject(pC)
  2808. , destroy = destroyChild !== undefined ? destroyChild : o.destroyChildren
  2809. ;
  2810. // FIRST destroy the child-layout(s)
  2811. if (hasChildren && destroy) {
  2812. $.each(pC, function (key, child) {
  2813. if (!child.destroyed)
  2814. child.destroy(true);// tell child-layout to destroy ALL its child-layouts too
  2815. if (child.destroyed) // destroy was successful
  2816. delete pC[key];
  2817. });
  2818. // if no more children, remove the children hash
  2819. if ($.isEmptyObject(pC)) {
  2820. pC = children[pane] = null; // clear children hash
  2821. hasChildren = false;
  2822. }
  2823. }
  2824. // Note: can't 'remove' a pane element with non-destroyed children
  2825. if ($P && remove && !hasChildren)
  2826. $P.remove(); // remove the pane-element and everything inside it
  2827. else if ($P && $P[0]) {
  2828. // create list of ALL pane-classes that need to be removed
  2829. var root = o.paneClass // default="ui-layout-pane"
  2830. , pRoot = root + "-" + pane // eg: "ui-layout-pane-west"
  2831. , _open = "-open"
  2832. , _sliding = "-sliding"
  2833. , _closed = "-closed"
  2834. , classes = [root, root + _open, root + _closed, root + _sliding, // generic classes
  2835. pRoot, pRoot + _open, pRoot + _closed, pRoot + _sliding] // pane-specific classes
  2836. ;
  2837. $.merge(classes, getHoverClasses($P, true)); // ADD hover-classes
  2838. // remove all Layout classes from pane-element
  2839. $P.removeClass(classes.join(" ")) // remove ALL pane-classes
  2840. .removeData("parentLayout")
  2841. .removeData("layoutPane")
  2842. .removeData("layoutRole")
  2843. .removeData("layoutEdge")
  2844. .removeData("autoHidden") // in case set
  2845. .unbind("." + sID) // remove ALL Layout events
  2846. // TODO: remove these extra unbind commands when jQuery is fixed
  2847. //.unbind("mouseenter"+ sID)
  2848. //.unbind("mouseleave"+ sID)
  2849. ;
  2850. // do NOT reset CSS if this pane/content is STILL the container of a nested layout!
  2851. // the nested layout will reset its 'container' CSS when/if it is destroyed
  2852. if (hasChildren && $C) {
  2853. // a content-div may not have a specific width, so give it one to contain the Layout
  2854. $C.width($C.width());
  2855. $.each(pC, function (key, child) {
  2856. child.resizeAll(); // resize the Layout
  2857. });
  2858. }
  2859. else if ($C)
  2860. $C.css($C.data(css)).removeData(css).removeData("layoutRole");
  2861. // remove pane AFTER content in case there was a nested layout
  2862. if (!$P.data(d))
  2863. $P.css($P.data(css)).removeData(css);
  2864. }
  2865. // REMOVE pane resizer and toggler elements
  2866. if ($T) $T.remove();
  2867. if ($R) $R.remove();
  2868. // CLEAR all pointers and state data
  2869. Instance[pane] = $Ps[pane] = $Cs[pane] = $Rs[pane] = $Ts[pane] = false;
  2870. s = { removed: true };
  2871. if (!skipResize)
  2872. resizeAll();
  2873. }
  2874. /*
  2875. * ###########################
  2876. * ACTION METHODS
  2877. * ###########################
  2878. */
  2879. /**
  2880. * @param {string} pane
  2881. */
  2882. , _hidePane = function (pane) {
  2883. var $P = $Ps[pane]
  2884. , o = options[pane]
  2885. , s = $P[0].style
  2886. ;
  2887. if (o.useOffscreenClose) {
  2888. if (!$P.data(_c.offscreenReset))
  2889. $P.data(_c.offscreenReset, { left: s.left, right: s.right });
  2890. $P.css(_c.offscreenCSS);
  2891. }
  2892. else
  2893. $P.hide().removeData(_c.offscreenReset);
  2894. }
  2895. /**
  2896. * @param {string} pane
  2897. */
  2898. , _showPane = function (pane) {
  2899. var $P = $Ps[pane]
  2900. , o = options[pane]
  2901. , off = _c.offscreenCSS
  2902. , old = $P.data(_c.offscreenReset)
  2903. , s = $P[0].style
  2904. ;
  2905. $P.show() // ALWAYS show, just in case
  2906. .removeData(_c.offscreenReset);
  2907. if (o.useOffscreenClose && old) {
  2908. if (s.left == off.left)
  2909. s.left = old.left;
  2910. if (s.right == off.right)
  2911. s.right = old.right;
  2912. }
  2913. }
  2914. /**
  2915. * Completely 'hides' a pane, including its spacing - as if it does not exist
  2916. * The pane is not actually 'removed' from the source, so can use 'show' to un-hide it
  2917. *
  2918. * @param {(string|Object)} evt_or_pane The pane being hidden, ie: north, south, east, or west
  2919. * @param {boolean=} [noAnimation=false]
  2920. */
  2921. , hide = function (evt_or_pane, noAnimation) {
  2922. if (!isInitialized()) return;
  2923. var pane = evtPane.call(this, evt_or_pane)
  2924. , o = options[pane]
  2925. , s = state[pane]
  2926. , $P = $Ps[pane]
  2927. , $R = $Rs[pane]
  2928. ;
  2929. if (pane === "center" || !$P || s.isHidden) return; // pane does not exist OR is already hidden
  2930. // onhide_start callback - will CANCEL hide if returns false
  2931. if (state.initialized && false === _runCallbacks("onhide_start", pane)) return;
  2932. s.isSliding = false; // just in case
  2933. delete state.panesSliding[pane];
  2934. // now hide the elements
  2935. if ($R) $R.hide(); // hide resizer-bar
  2936. if (!state.initialized || s.isClosed) {
  2937. s.isClosed = true; // to trigger open-animation on show()
  2938. s.isHidden = true;
  2939. s.isVisible = false;
  2940. if (!state.initialized)
  2941. _hidePane(pane); // no animation when loading page
  2942. sizeMidPanes(_c[pane].dir === "horz" ? "" : "center");
  2943. if (state.initialized || o.triggerEventsOnLoad)
  2944. _runCallbacks("onhide_end", pane);
  2945. }
  2946. else {
  2947. s.isHiding = true; // used by onclose
  2948. close(pane, false, noAnimation); // adjust all panes to fit
  2949. }
  2950. }
  2951. /**
  2952. * Show a hidden pane - show as 'closed' by default unless openPane = true
  2953. *
  2954. * @param {(string|Object)} evt_or_pane The pane being opened, ie: north, south, east, or west
  2955. * @param {boolean=} [openPane=false]
  2956. * @param {boolean=} [noAnimation=false]
  2957. * @param {boolean=} [noAlert=false]
  2958. */
  2959. , show = function (evt_or_pane, openPane, noAnimation, noAlert) {
  2960. if (!isInitialized()) return;
  2961. var pane = evtPane.call(this, evt_or_pane)
  2962. , o = options[pane]
  2963. , s = state[pane]
  2964. , $P = $Ps[pane]
  2965. , $R = $Rs[pane]
  2966. ;
  2967. if (pane === "center" || !$P || !s.isHidden) return; // pane does not exist OR is not hidden
  2968. // onshow_start callback - will CANCEL show if returns false
  2969. if (false === _runCallbacks("onshow_start", pane)) return;
  2970. s.isShowing = true; // used by onopen/onclose
  2971. //s.isHidden = false; - will be set by open/close - if not cancelled
  2972. s.isSliding = false; // just in case
  2973. delete state.panesSliding[pane];
  2974. // now show the elements
  2975. //if ($R) $R.show(); - will be shown by open/close
  2976. if (openPane === false)
  2977. close(pane, true); // true = force
  2978. else
  2979. open(pane, false, noAnimation, noAlert); // adjust all panes to fit
  2980. }
  2981. /**
  2982. * Toggles a pane open/closed by calling either open or close
  2983. *
  2984. * @param {(string|Object)} evt_or_pane The pane being toggled, ie: north, south, east, or west
  2985. * @param {boolean=} [slide=false]
  2986. */
  2987. , toggle = function (evt_or_pane, slide) {
  2988. if (!isInitialized()) return;
  2989. var evt = evtObj(evt_or_pane)
  2990. , pane = evtPane.call(this, evt_or_pane)
  2991. , s = state[pane]
  2992. ;
  2993. if (evt) // called from to $R.dblclick OR triggerPaneEvent
  2994. evt.stopImmediatePropagation();
  2995. if (s.isHidden)
  2996. show(pane); // will call 'open' after unhiding it
  2997. else if (s.isClosed)
  2998. open(pane, !!slide);
  2999. else
  3000. close(pane);
  3001. }
  3002. /**
  3003. * Utility method used during init or other auto-processes
  3004. *
  3005. * @param {string} pane The pane being closed
  3006. * @param {boolean=} [setHandles=false]
  3007. */
  3008. , _closePane = function (pane, setHandles) {
  3009. var
  3010. $P = $Ps[pane]
  3011. , s = state[pane]
  3012. ;
  3013. _hidePane(pane);
  3014. s.isClosed = true;
  3015. s.isVisible = false;
  3016. if (setHandles) setAsClosed(pane);
  3017. }
  3018. /**
  3019. * Close the specified pane (animation optional), and resize all other panes as needed
  3020. *
  3021. * @param {(string|Object)} evt_or_pane The pane being closed, ie: north, south, east, or west
  3022. * @param {boolean=} [force=false]
  3023. * @param {boolean=} [noAnimation=false]
  3024. * @param {boolean=} [skipCallback=false]
  3025. */
  3026. , close = function (evt_or_pane, force, noAnimation, skipCallback) {
  3027. var pane = evtPane.call(this, evt_or_pane);
  3028. if (pane === "center") return; // validate
  3029. // if pane has been initialized, but NOT the complete layout, close pane instantly
  3030. if (!state.initialized && $Ps[pane]) {
  3031. _closePane(pane, true); // INIT pane as closed
  3032. return;
  3033. }
  3034. if (!isInitialized()) return;
  3035. var
  3036. $P = $Ps[pane]
  3037. , $R = $Rs[pane]
  3038. , $T = $Ts[pane]
  3039. , o = options[pane]
  3040. , s = state[pane]
  3041. , c = _c[pane]
  3042. , doFX, isShowing, isHiding, wasSliding;
  3043. // QUEUE in case another action/animation is in progress
  3044. $N.queue(function (queueNext) {
  3045. if (!$P
  3046. || (!o.closable && !s.isShowing && !s.isHiding) // invalid request // (!o.resizable && !o.closable) ???
  3047. || (!force && s.isClosed && !s.isShowing) // already closed
  3048. ) return queueNext();
  3049. // onclose_start callback - will CANCEL hide if returns false
  3050. // SKIP if just 'showing' a hidden pane as 'closed'
  3051. var abort = !s.isShowing && false === _runCallbacks("onclose_start", pane);
  3052. // transfer logic vars to temp vars
  3053. isShowing = s.isShowing;
  3054. isHiding = s.isHiding;
  3055. wasSliding = s.isSliding;
  3056. // now clear the logic vars (REQUIRED before aborting)
  3057. delete s.isShowing;
  3058. delete s.isHiding;
  3059. if (abort) return queueNext();
  3060. doFX = !noAnimation && !s.isClosed && (o.fxName_close != "none");
  3061. s.isMoving = true;
  3062. s.isClosed = true;
  3063. s.isVisible = false;
  3064. // update isHidden BEFORE sizing panes
  3065. if (isHiding) s.isHidden = true;
  3066. else if (isShowing) s.isHidden = false;
  3067. if (s.isSliding) // pane is being closed, so UNBIND trigger events
  3068. bindStopSlidingEvents(pane, false); // will set isSliding=false
  3069. else // resize panes adjacent to this one
  3070. sizeMidPanes(_c[pane].dir === "horz" ? "" : "center", false); // false = NOT skipCallback
  3071. // if this pane has a resizer bar, move it NOW - before animation
  3072. setAsClosed(pane);
  3073. // CLOSE THE PANE
  3074. if (doFX) { // animate the close
  3075. lockPaneForFX(pane, true); // need to set left/top so animation will work
  3076. $P.hide(o.fxName_close, o.fxSettings_close, o.fxSpeed_close, function () {
  3077. lockPaneForFX(pane, false); // undo
  3078. if (s.isClosed) close_2();
  3079. queueNext();
  3080. });
  3081. }
  3082. else { // hide the pane without animation
  3083. _hidePane(pane);
  3084. close_2();
  3085. queueNext();
  3086. };
  3087. });
  3088. // SUBROUTINE
  3089. function close_2() {
  3090. s.isMoving = false;
  3091. bindStartSlidingEvents(pane, true); // will enable if o.slidable = true
  3092. // if opposite-pane was autoClosed, see if it can be autoOpened now
  3093. var altPane = _c.oppositeEdge[pane];
  3094. if (state[altPane].noRoom) {
  3095. setSizeLimits(altPane);
  3096. makePaneFit(altPane);
  3097. }
  3098. if (!skipCallback && (state.initialized || o.triggerEventsOnLoad)) {
  3099. // onclose callback - UNLESS just 'showing' a hidden pane as 'closed'
  3100. if (!isShowing) _runCallbacks("onclose_end", pane);
  3101. // onhide OR onshow callback
  3102. if (isShowing) _runCallbacks("onshow_end", pane);
  3103. if (isHiding) _runCallbacks("onhide_end", pane);
  3104. }
  3105. }
  3106. }
  3107. /**
  3108. * @param {string} pane The pane just closed, ie: north, south, east, or west
  3109. */
  3110. , setAsClosed = function (pane) {
  3111. if (!$Rs[pane]) return; // handles not initialized yet!
  3112. var
  3113. $P = $Ps[pane]
  3114. , $R = $Rs[pane]
  3115. , $T = $Ts[pane]
  3116. , o = options[pane]
  3117. , s = state[pane]
  3118. , side = _c[pane].side
  3119. , rClass = o.resizerClass
  3120. , tClass = o.togglerClass
  3121. , _pane = "-" + pane // used for classNames
  3122. , _open = "-open"
  3123. , _sliding = "-sliding"
  3124. , _closed = "-closed"
  3125. ;
  3126. $R
  3127. .css(side, sC.inset[side]) // move the resizer
  3128. .removeClass(rClass + _open + " " + rClass + _pane + _open)
  3129. .removeClass(rClass + _sliding + " " + rClass + _pane + _sliding)
  3130. .addClass(rClass + _closed + " " + rClass + _pane + _closed)
  3131. ;
  3132. // handle already-hidden panes in case called by swap() or a similar method
  3133. if (s.isHidden) $R.hide(); // hide resizer-bar
  3134. // DISABLE 'resizing' when closed - do this BEFORE bindStartSlidingEvents?
  3135. if (o.resizable && $.layout.plugins.draggable)
  3136. $R
  3137. .draggable("disable")
  3138. .removeClass("ui-state-disabled") // do NOT apply disabled styling - not suitable here
  3139. .css("cursor", "default")
  3140. .attr("title", "")
  3141. ;
  3142. // if pane has a toggler button, adjust that too
  3143. if ($T) {
  3144. $T
  3145. .removeClass(tClass + _open + " " + tClass + _pane + _open)
  3146. .addClass(tClass + _closed + " " + tClass + _pane + _closed)
  3147. .attr("title", o.tips.Open) // may be blank
  3148. ;
  3149. // toggler-content - if exists
  3150. $T.children(".content-open").hide();
  3151. $T.children(".content-closed").css("display", "block");
  3152. }
  3153. // sync any 'pin buttons'
  3154. syncPinBtns(pane, false);
  3155. if (state.initialized) {
  3156. // resize 'length' and position togglers for adjacent panes
  3157. sizeHandles();
  3158. }
  3159. }
  3160. /**
  3161. * Open the specified pane (animation optional), and resize all other panes as needed
  3162. *
  3163. * @param {(string|Object)} evt_or_pane The pane being opened, ie: north, south, east, or west
  3164. * @param {boolean=} [slide=false]
  3165. * @param {boolean=} [noAnimation=false]
  3166. * @param {boolean=} [noAlert=false]
  3167. */
  3168. , open = function (evt_or_pane, slide, noAnimation, noAlert) {
  3169. if (!isInitialized()) return;
  3170. var pane = evtPane.call(this, evt_or_pane)
  3171. , $P = $Ps[pane]
  3172. , $R = $Rs[pane]
  3173. , $T = $Ts[pane]
  3174. , o = options[pane]
  3175. , s = state[pane]
  3176. , c = _c[pane]
  3177. , doFX, isShowing
  3178. ;
  3179. if (pane === "center") return; // validate
  3180. // QUEUE in case another action/animation is in progress
  3181. $N.queue(function (queueNext) {
  3182. if (!$P
  3183. || (!o.resizable && !o.closable && !s.isShowing) // invalid request
  3184. || (s.isVisible && !s.isSliding) // already open
  3185. ) return queueNext();
  3186. // pane can ALSO be unhidden by just calling show(), so handle this scenario
  3187. if (s.isHidden && !s.isShowing) {
  3188. queueNext(); // call before show() because it needs the queue free
  3189. show(pane, true);
  3190. return;
  3191. }
  3192. if (s.autoResize && s.size != o.size) // resize pane to original size set in options
  3193. sizePane(pane, o.size, true, true, true); // true=skipCallback/noAnimation/forceResize
  3194. else
  3195. // make sure there is enough space available to open the pane
  3196. setSizeLimits(pane, slide);
  3197. // onopen_start callback - will CANCEL open if returns false
  3198. var cbReturn = _runCallbacks("onopen_start", pane);
  3199. if (cbReturn === "abort")
  3200. return queueNext();
  3201. // update pane-state again in case options were changed in onopen_start
  3202. if (cbReturn !== "NC") // NC = "No Callback"
  3203. setSizeLimits(pane, slide);
  3204. if (s.minSize > s.maxSize) { // INSUFFICIENT ROOM FOR PANE TO OPEN!
  3205. syncPinBtns(pane, false); // make sure pin-buttons are reset
  3206. if (!noAlert && o.tips.noRoomToOpen)
  3207. alert(o.tips.noRoomToOpen);
  3208. return queueNext(); // ABORT
  3209. }
  3210. if (slide) // START Sliding - will set isSliding=true
  3211. bindStopSlidingEvents(pane, true); // BIND trigger events to close sliding-pane
  3212. else if (s.isSliding) // PIN PANE (stop sliding) - open pane 'normally' instead
  3213. bindStopSlidingEvents(pane, false); // UNBIND trigger events - will set isSliding=false
  3214. else if (o.slidable)
  3215. bindStartSlidingEvents(pane, false); // UNBIND trigger events
  3216. s.noRoom = false; // will be reset by makePaneFit if 'noRoom'
  3217. makePaneFit(pane);
  3218. // transfer logic var to temp var
  3219. isShowing = s.isShowing;
  3220. // now clear the logic var
  3221. delete s.isShowing;
  3222. doFX = !noAnimation && s.isClosed && (o.fxName_open != "none");
  3223. s.isMoving = true;
  3224. s.isVisible = true;
  3225. s.isClosed = false;
  3226. // update isHidden BEFORE sizing panes - WHY??? Old?
  3227. if (isShowing) s.isHidden = false;
  3228. if (doFX) { // ANIMATE
  3229. // mask adjacent panes with objects
  3230. lockPaneForFX(pane, true); // need to set left/top so animation will work
  3231. $P.show(o.fxName_open, o.fxSettings_open, o.fxSpeed_open, function () {
  3232. lockPaneForFX(pane, false); // undo
  3233. if (s.isVisible) open_2(); // continue
  3234. queueNext();
  3235. });
  3236. }
  3237. else { // no animation
  3238. _showPane(pane);// just show pane and...
  3239. open_2(); // continue
  3240. queueNext();
  3241. };
  3242. });
  3243. // SUBROUTINE
  3244. function open_2() {
  3245. s.isMoving = false;
  3246. // cure iframe display issues
  3247. _fixIframe(pane);
  3248. // NOTE: if isSliding, then other panes are NOT 'resized'
  3249. if (!s.isSliding) { // resize all panes adjacent to this one
  3250. sizeMidPanes(_c[pane].dir == "vert" ? "center" : "", false); // false = NOT skipCallback
  3251. }
  3252. // set classes, position handles and execute callbacks...
  3253. setAsOpen(pane);
  3254. };
  3255. }
  3256. /**
  3257. * @param {string} pane The pane just opened, ie: north, south, east, or west
  3258. * @param {boolean=} [skipCallback=false]
  3259. */
  3260. , setAsOpen = function (pane, skipCallback) {
  3261. var
  3262. $P = $Ps[pane]
  3263. , $R = $Rs[pane]
  3264. , $T = $Ts[pane]
  3265. , o = options[pane]
  3266. , s = state[pane]
  3267. , side = _c[pane].side
  3268. , rClass = o.resizerClass
  3269. , tClass = o.togglerClass
  3270. , _pane = "-" + pane // used for classNames
  3271. , _open = "-open"
  3272. , _closed = "-closed"
  3273. , _sliding = "-sliding"
  3274. ;
  3275. $R
  3276. .css(side, sC.inset[side] + getPaneSize(pane)) // move the resizer
  3277. .removeClass(rClass + _closed + " " + rClass + _pane + _closed)
  3278. .addClass(rClass + _open + " " + rClass + _pane + _open)
  3279. ;
  3280. if (s.isSliding)
  3281. $R.addClass(rClass + _sliding + " " + rClass + _pane + _sliding)
  3282. else // in case 'was sliding'
  3283. $R.removeClass(rClass + _sliding + " " + rClass + _pane + _sliding)
  3284. removeHover(0, $R); // remove hover classes
  3285. if (o.resizable && $.layout.plugins.draggable)
  3286. $R.draggable("enable")
  3287. .css("cursor", o.resizerCursor)
  3288. .attr("title", o.tips.Resize);
  3289. else if (!s.isSliding)
  3290. $R.css("cursor", "default"); // n-resize, s-resize, etc
  3291. // if pane also has a toggler button, adjust that too
  3292. if ($T) {
  3293. $T.removeClass(tClass + _closed + " " + tClass + _pane + _closed)
  3294. .addClass(tClass + _open + " " + tClass + _pane + _open)
  3295. .attr("title", o.tips.Close); // may be blank
  3296. removeHover(0, $T); // remove hover classes
  3297. // toggler-content - if exists
  3298. $T.children(".content-closed").hide();
  3299. $T.children(".content-open").css("display", "block");
  3300. }
  3301. // sync any 'pin buttons'
  3302. syncPinBtns(pane, !s.isSliding);
  3303. // update pane-state dimensions - BEFORE resizing content
  3304. $.extend(s, elDims($P));
  3305. if (state.initialized) {
  3306. // resize resizer & toggler sizes for all panes
  3307. sizeHandles();
  3308. // resize content every time pane opens - to be sure
  3309. sizeContent(pane, true); // true = remeasure headers/footers, even if 'pane.isMoving'
  3310. }
  3311. if (!skipCallback && (state.initialized || o.triggerEventsOnLoad) && $P.is(":visible")) {
  3312. // onopen callback
  3313. _runCallbacks("onopen_end", pane);
  3314. // onshow callback - TODO: should this be here?
  3315. if (s.isShowing) _runCallbacks("onshow_end", pane);
  3316. // ALSO call onresize because layout-size *may* have changed while pane was closed
  3317. if (state.initialized)
  3318. _runCallbacks("onresize_end", pane);
  3319. }
  3320. // TODO: Somehow sizePane("north") is being called after this point???
  3321. }
  3322. /**
  3323. * slideOpen / slideClose / slideToggle
  3324. *
  3325. * Pass-though methods for sliding
  3326. */
  3327. , slideOpen = function (evt_or_pane) {
  3328. if (!isInitialized()) return;
  3329. var evt = evtObj(evt_or_pane)
  3330. , pane = evtPane.call(this, evt_or_pane)
  3331. , s = state[pane]
  3332. , delay = options[pane].slideDelay_open
  3333. ;
  3334. if (pane === "center") return; // validate
  3335. // prevent event from triggering on NEW resizer binding created below
  3336. if (evt) evt.stopImmediatePropagation();
  3337. if (s.isClosed && evt && evt.type === "mouseenter" && delay > 0)
  3338. // trigger = mouseenter - use a delay
  3339. timer.set(pane + "_openSlider", open_NOW, delay);
  3340. else
  3341. open_NOW(); // will unbind events if is already open
  3342. /**
  3343. * SUBROUTINE for timed open
  3344. */
  3345. function open_NOW() {
  3346. if (!s.isClosed) // skip if no longer closed!
  3347. bindStopSlidingEvents(pane, true); // BIND trigger events to close sliding-pane
  3348. else if (!s.isMoving)
  3349. open(pane, true); // true = slide - open() will handle binding
  3350. };
  3351. }
  3352. , slideClose = function (evt_or_pane) {
  3353. if (!isInitialized()) return;
  3354. var evt = evtObj(evt_or_pane)
  3355. , pane = evtPane.call(this, evt_or_pane)
  3356. , o = options[pane]
  3357. , s = state[pane]
  3358. , delay = s.isMoving ? 1000 : 300 // MINIMUM delay - option may override
  3359. ;
  3360. if (pane === "center") return; // validate
  3361. if (s.isClosed || s.isResizing)
  3362. return; // skip if already closed OR in process of resizing
  3363. else if (o.slideTrigger_close === "click")
  3364. close_NOW(); // close immediately onClick
  3365. else if (o.preventQuickSlideClose && s.isMoving)
  3366. return; // handle Chrome quick-close on slide-open
  3367. else if (o.preventPrematureSlideClose && evt && $.layout.isMouseOverElem(evt, $Ps[pane]))
  3368. return; // handle incorrect mouseleave trigger, like when over a SELECT-list in IE
  3369. else if (evt) // trigger = mouseleave - use a delay
  3370. // 1 sec delay if 'opening', else .3 sec
  3371. timer.set(pane + "_closeSlider", close_NOW, max(o.slideDelay_close, delay));
  3372. else // called programically
  3373. close_NOW();
  3374. /**
  3375. * SUBROUTINE for timed close
  3376. */
  3377. function close_NOW() {
  3378. if (s.isClosed) // skip 'close' if already closed!
  3379. bindStopSlidingEvents(pane, false); // UNBIND trigger events - TODO: is this needed here?
  3380. else if (!s.isMoving)
  3381. close(pane); // close will handle unbinding
  3382. };
  3383. }
  3384. /**
  3385. * @param {(string|Object)} evt_or_pane The pane being opened, ie: north, south, east, or west
  3386. */
  3387. , slideToggle = function (evt_or_pane) {
  3388. var pane = evtPane.call(this, evt_or_pane);
  3389. toggle(pane, true);
  3390. }
  3391. /**
  3392. * Must set left/top on East/South panes so animation will work properly
  3393. *
  3394. * @param {string} pane The pane to lock, 'east' or 'south' - any other is ignored!
  3395. * @param {boolean} doLock true = set left/top, false = remove
  3396. */
  3397. , lockPaneForFX = function (pane, doLock) {
  3398. var $P = $Ps[pane]
  3399. , s = state[pane]
  3400. , o = options[pane]
  3401. , z = options.zIndexes
  3402. ;
  3403. if (doLock) {
  3404. showMasks(pane, { animation: true, objectsOnly: true });
  3405. $P.css({ zIndex: z.pane_animate }); // overlay all elements during animation
  3406. if (pane == "south")
  3407. $P.css({ top: sC.inset.top + sC.innerHeight - $P.outerHeight() });
  3408. else if (pane == "east")
  3409. $P.css({ left: sC.inset.left + sC.innerWidth - $P.outerWidth() });
  3410. }
  3411. else { // animation DONE - RESET CSS
  3412. hideMasks();
  3413. $P.css({ zIndex: (s.isSliding ? z.pane_sliding : z.pane_normal) });
  3414. if (pane == "south")
  3415. $P.css({ top: "auto" });
  3416. // if pane is positioned 'off-screen', then DO NOT screw with it!
  3417. else if (pane == "east" && !$P.css("left").match(/\-99999/))
  3418. $P.css({ left: "auto" });
  3419. // fix anti-aliasing in IE - only needed for animations that change opacity
  3420. if (browser.msie && o.fxOpacityFix && o.fxName_open != "slide" && $P.css("filter") && $P.css("opacity") == 1)
  3421. $P[0].style.removeAttribute('filter');
  3422. }
  3423. }
  3424. /**
  3425. * Toggle sliding functionality of a specific pane on/off by adding removing 'slide open' trigger
  3426. *
  3427. * @see open(), close()
  3428. * @param {string} pane The pane to enable/disable, 'north', 'south', etc.
  3429. * @param {boolean} enable Enable or Disable sliding?
  3430. */
  3431. , bindStartSlidingEvents = function (pane, enable) {
  3432. var o = options[pane]
  3433. , $P = $Ps[pane]
  3434. , $R = $Rs[pane]
  3435. , evtName = o.slideTrigger_open.toLowerCase()
  3436. ;
  3437. if (!$R || (enable && !o.slidable)) return;
  3438. // make sure we have a valid event
  3439. if (evtName.match(/mouseover/))
  3440. evtName = o.slideTrigger_open = "mouseenter";
  3441. else if (!evtName.match(/(click|dblclick|mouseenter)/))
  3442. evtName = o.slideTrigger_open = "click";
  3443. // must remove double-click-toggle when using dblclick-slide
  3444. if (o.resizerDblClickToggle && evtName.match(/click/)) {
  3445. $R[enable ? "unbind" : "bind"]('dblclick.' + sID, toggle)
  3446. }
  3447. $R
  3448. // add or remove event
  3449. [enable ? "bind" : "unbind"](evtName + '.' + sID, slideOpen)
  3450. // set the appropriate cursor & title/tip
  3451. .css("cursor", enable ? o.sliderCursor : "default")
  3452. .attr("title", enable ? o.tips.Slide : "")
  3453. ;
  3454. }
  3455. /**
  3456. * Add or remove 'mouseleave' events to 'slide close' when pane is 'sliding' open or closed
  3457. * Also increases zIndex when pane is sliding open
  3458. * See bindStartSlidingEvents for code to control 'slide open'
  3459. *
  3460. * @see slideOpen(), slideClose()
  3461. * @param {string} pane The pane to process, 'north', 'south', etc.
  3462. * @param {boolean} enable Enable or Disable events?
  3463. */
  3464. , bindStopSlidingEvents = function (pane, enable) {
  3465. var o = options[pane]
  3466. , s = state[pane]
  3467. , c = _c[pane]
  3468. , z = options.zIndexes
  3469. , evtName = o.slideTrigger_close.toLowerCase()
  3470. , action = (enable ? "bind" : "unbind")
  3471. , $P = $Ps[pane]
  3472. , $R = $Rs[pane]
  3473. ;
  3474. timer.clear(pane + "_closeSlider"); // just in case
  3475. if (enable) {
  3476. s.isSliding = true;
  3477. state.panesSliding[pane] = true;
  3478. // remove 'slideOpen' event from resizer
  3479. // ALSO will raise the zIndex of the pane & resizer
  3480. bindStartSlidingEvents(pane, false);
  3481. }
  3482. else {
  3483. s.isSliding = false;
  3484. delete state.panesSliding[pane];
  3485. }
  3486. // RE/SET zIndex - increases when pane is sliding-open, resets to normal when not
  3487. $P.css("zIndex", enable ? z.pane_sliding : z.pane_normal);
  3488. $R.css("zIndex", enable ? z.pane_sliding + 2 : z.resizer_normal); // NOTE: mask = pane_sliding+1
  3489. // make sure we have a valid event
  3490. if (!evtName.match(/(click|mouseleave)/))
  3491. evtName = o.slideTrigger_close = "mouseleave"; // also catches 'mouseout'
  3492. // add/remove slide triggers
  3493. $R[action](evtName, slideClose); // base event on resize
  3494. // need extra events for mouseleave
  3495. if (evtName === "mouseleave") {
  3496. // also close on pane.mouseleave
  3497. $P[action]("mouseleave." + sID, slideClose);
  3498. // cancel timer when mouse moves between 'pane' and 'resizer'
  3499. $R[action]("mouseenter." + sID, cancelMouseOut);
  3500. $P[action]("mouseenter." + sID, cancelMouseOut);
  3501. }
  3502. if (!enable)
  3503. timer.clear(pane + "_closeSlider");
  3504. else if (evtName === "click" && !o.resizable) {
  3505. // IF pane is not resizable (which already has a cursor and tip)
  3506. // then set the a cursor & title/tip on resizer when sliding
  3507. $R.css("cursor", enable ? o.sliderCursor : "default");
  3508. $R.attr("title", enable ? o.tips.Close : ""); // use Toggler-tip, eg: "Close Pane"
  3509. }
  3510. // SUBROUTINE for mouseleave timer clearing
  3511. function cancelMouseOut(evt) {
  3512. timer.clear(pane + "_closeSlider");
  3513. evt.stopPropagation();
  3514. }
  3515. }
  3516. /**
  3517. * Hides/closes a pane if there is insufficient room - reverses this when there is room again
  3518. * MUST have already called setSizeLimits() before calling this method
  3519. *
  3520. * @param {string} pane The pane being resized
  3521. * @param {boolean=} [isOpening=false] Called from onOpen?
  3522. * @param {boolean=} [skipCallback=false] Should the onresize callback be run?
  3523. * @param {boolean=} [force=false]
  3524. */
  3525. , makePaneFit = function (pane, isOpening, skipCallback, force) {
  3526. var o = options[pane]
  3527. , s = state[pane]
  3528. , c = _c[pane]
  3529. , $P = $Ps[pane]
  3530. , $R = $Rs[pane]
  3531. , isSidePane = c.dir === "vert"
  3532. , hasRoom = false
  3533. ;
  3534. // special handling for center & east/west panes
  3535. if (pane === "center" || (isSidePane && s.noVerticalRoom)) {
  3536. // see if there is enough room to display the pane
  3537. // ERROR: hasRoom = s.minHeight <= s.maxHeight && (isSidePane || s.minWidth <= s.maxWidth);
  3538. hasRoom = (s.maxHeight >= 0);
  3539. if (hasRoom && s.noRoom) { // previously hidden due to noRoom, so show now
  3540. _showPane(pane);
  3541. if ($R) $R.show();
  3542. s.isVisible = true;
  3543. s.noRoom = false;
  3544. if (isSidePane) s.noVerticalRoom = false;
  3545. _fixIframe(pane);
  3546. }
  3547. else if (!hasRoom && !s.noRoom) { // not currently hidden, so hide now
  3548. _hidePane(pane);
  3549. if ($R) $R.hide();
  3550. s.isVisible = false;
  3551. s.noRoom = true;
  3552. }
  3553. }
  3554. // see if there is enough room to fit the border-pane
  3555. if (pane === "center") {
  3556. // ignore center in this block
  3557. }
  3558. else if (s.minSize <= s.maxSize) { // pane CAN fit
  3559. hasRoom = true;
  3560. if (s.size > s.maxSize) // pane is too big - shrink it
  3561. sizePane(pane, s.maxSize, skipCallback, true, force); // true = noAnimation
  3562. else if (s.size < s.minSize) // pane is too small - enlarge it
  3563. sizePane(pane, s.minSize, skipCallback, true, force); // true = noAnimation
  3564. // need s.isVisible because new pseudoClose method keeps pane visible, but off-screen
  3565. else if ($R && s.isVisible && $P.is(":visible")) {
  3566. // make sure resizer-bar is positioned correctly
  3567. // handles situation where nested layout was 'hidden' when initialized
  3568. var pos = s.size + sC.inset[c.side];
  3569. if ($.layout.cssNum($R, c.side) != pos) $R.css(c.side, pos);
  3570. }
  3571. // if was previously hidden due to noRoom, then RESET because NOW there is room
  3572. if (s.noRoom) {
  3573. // s.noRoom state will be set by open or show
  3574. if (s.wasOpen && o.closable) {
  3575. if (o.autoReopen)
  3576. open(pane, false, true, true); // true = noAnimation, true = noAlert
  3577. else // leave the pane closed, so just update state
  3578. s.noRoom = false;
  3579. }
  3580. else
  3581. show(pane, s.wasOpen, true, true); // true = noAnimation, true = noAlert
  3582. }
  3583. }
  3584. else { // !hasRoom - pane CANNOT fit
  3585. if (!s.noRoom) { // pane not set as noRoom yet, so hide or close it now...
  3586. s.noRoom = true; // update state
  3587. s.wasOpen = !s.isClosed && !s.isSliding;
  3588. if (s.isClosed) { } // SKIP
  3589. else if (o.closable) // 'close' if possible
  3590. close(pane, true, true); // true = force, true = noAnimation
  3591. else // 'hide' pane if cannot just be closed
  3592. hide(pane, true); // true = noAnimation
  3593. }
  3594. }
  3595. }
  3596. /**
  3597. * manualSizePane is an exposed flow-through method allowing extra code when pane is 'manually resized'
  3598. *
  3599. * @param {(string|Object)} evt_or_pane The pane being resized
  3600. * @param {number} size The *desired* new size for this pane - will be validated
  3601. * @param {boolean=} [skipCallback=false] Should the onresize callback be run?
  3602. * @param {boolean=} [noAnimation=false]
  3603. * @param {boolean=} [force=false] Force resizing even if does not seem necessary
  3604. */
  3605. , manualSizePane = function (evt_or_pane, size, skipCallback, noAnimation, force) {
  3606. if (!isInitialized()) return;
  3607. var pane = evtPane.call(this, evt_or_pane)
  3608. , o = options[pane]
  3609. , s = state[pane]
  3610. // if resizing callbacks have been delayed and resizing is now DONE, force resizing to complete...
  3611. , forceResize = force || (o.livePaneResizing && !s.isResizing)
  3612. ;
  3613. if (pane === "center") return; // validate
  3614. // ANY call to manualSizePane disables autoResize - ie, percentage sizing
  3615. s.autoResize = false;
  3616. // flow-through...
  3617. sizePane(pane, size, skipCallback, noAnimation, forceResize); // will animate resize if option enabled
  3618. }
  3619. /**
  3620. * sizePane is called only by internal methods whenever a pane needs to be resized
  3621. *
  3622. * @param {(string|Object)} evt_or_pane The pane being resized
  3623. * @param {number} size The *desired* new size for this pane - will be validated
  3624. * @param {boolean=} [skipCallback=false] Should the onresize callback be run?
  3625. * @param {boolean=} [noAnimation=false]
  3626. * @param {boolean=} [force=false] Force resizing even if does not seem necessary
  3627. */
  3628. , sizePane = function (evt_or_pane, size, skipCallback, noAnimation, force) {
  3629. if (!isInitialized()) return;
  3630. var pane = evtPane.call(this, evt_or_pane) // probably NEVER called from event?
  3631. , o = options[pane]
  3632. , s = state[pane]
  3633. , $P = $Ps[pane]
  3634. , $R = $Rs[pane]
  3635. , side = _c[pane].side
  3636. , dimName = _c[pane].sizeType.toLowerCase()
  3637. , skipResizeWhileDragging = s.isResizing && !o.triggerEventsDuringLiveResize
  3638. , doFX = noAnimation !== true && o.animatePaneSizing
  3639. , oldSize, newSize
  3640. ;
  3641. if (pane === "center") return; // validate
  3642. // QUEUE in case another action/animation is in progress
  3643. $N.queue(function (queueNext) {
  3644. // calculate 'current' min/max sizes
  3645. setSizeLimits(pane); // update pane-state
  3646. oldSize = s.size;
  3647. size = _parseSize(pane, size); // handle percentages & auto
  3648. size = max(size, _parseSize(pane, o.minSize));
  3649. size = min(size, s.maxSize);
  3650. if (size < s.minSize) { // not enough room for pane!
  3651. queueNext(); // call before makePaneFit() because it needs the queue free
  3652. makePaneFit(pane, false, skipCallback); // will hide or close pane
  3653. return;
  3654. }
  3655. // IF newSize is same as oldSize, then nothing to do - abort
  3656. if (!force && size === oldSize)
  3657. return queueNext();
  3658. s.newSize = size;
  3659. // onresize_start callback CANNOT cancel resizing because this would break the layout!
  3660. if (!skipCallback && state.initialized && s.isVisible)
  3661. _runCallbacks("onresize_start", pane);
  3662. // resize the pane, and make sure its visible
  3663. newSize = cssSize(pane, size);
  3664. if (doFX && $P.is(":visible")) { // ANIMATE
  3665. var fx = $.layout.effects.size[pane] || $.layout.effects.size.all
  3666. , easing = o.fxSettings_size.easing || fx.easing
  3667. , z = options.zIndexes
  3668. , props = {};
  3669. props[dimName] = newSize + 'px';
  3670. s.isMoving = true;
  3671. // overlay all elements during animation
  3672. $P.css({ zIndex: z.pane_animate })
  3673. .show().animate(props, o.fxSpeed_size, easing, function () {
  3674. // reset zIndex after animation
  3675. $P.css({ zIndex: (s.isSliding ? z.pane_sliding : z.pane_normal) });
  3676. s.isMoving = false;
  3677. delete s.newSize;
  3678. sizePane_2(); // continue
  3679. queueNext();
  3680. });
  3681. }
  3682. else { // no animation
  3683. $P.css(dimName, newSize); // resize pane
  3684. delete s.newSize;
  3685. // if pane is visible, then
  3686. if ($P.is(":visible"))
  3687. sizePane_2(); // continue
  3688. else {
  3689. // pane is NOT VISIBLE, so just update state data...
  3690. // when pane is *next opened*, it will have the new size
  3691. s.size = size; // update state.size
  3692. //$.extend(s, elDims($P)); // update state dimensions - CANNOT do this when not visible! }
  3693. }
  3694. queueNext();
  3695. };
  3696. });
  3697. // SUBROUTINE
  3698. function sizePane_2() {
  3699. /* Panes are sometimes not sized precisely in some browsers!?
  3700. * This code will resize the pane up to 3 times to nudge the pane to the correct size
  3701. */
  3702. var actual = dimName === 'width' ? $P.outerWidth() : $P.outerHeight()
  3703. , tries = [{
  3704. pane: pane
  3705. , count: 1
  3706. , target: size
  3707. , actual: actual
  3708. , correct: (size === actual)
  3709. , attempt: size
  3710. , cssSize: newSize
  3711. }]
  3712. , lastTry = tries[0]
  3713. , thisTry = {}
  3714. , msg = 'Inaccurate size after resizing the ' + pane + '-pane.'
  3715. ;
  3716. while (!lastTry.correct) {
  3717. thisTry = { pane: pane, count: lastTry.count + 1, target: size };
  3718. if (lastTry.actual > size)
  3719. thisTry.attempt = max(0, lastTry.attempt - (lastTry.actual - size));
  3720. else // lastTry.actual < size
  3721. thisTry.attempt = max(0, lastTry.attempt + (size - lastTry.actual));
  3722. thisTry.cssSize = cssSize(pane, thisTry.attempt);
  3723. $P.css(dimName, thisTry.cssSize);
  3724. thisTry.actual = dimName == 'width' ? $P.outerWidth() : $P.outerHeight();
  3725. thisTry.correct = (size === thisTry.actual);
  3726. // log attempts and alert the user of this *non-fatal error* (if showDebugMessages)
  3727. if (tries.length === 1) {
  3728. _log(msg, false, true);
  3729. _log(lastTry, false, true);
  3730. }
  3731. _log(thisTry, false, true);
  3732. // after 4 tries, is as close as its gonna get!
  3733. if (tries.length > 3) break;
  3734. tries.push(thisTry);
  3735. lastTry = tries[tries.length - 1];
  3736. }
  3737. // END TESTING CODE
  3738. // update pane-state dimensions
  3739. s.size = size;
  3740. $.extend(s, elDims($P));
  3741. if (s.isVisible && $P.is(":visible")) {
  3742. // reposition the resizer-bar
  3743. if ($R) $R.css(side, size + sC.inset[side]);
  3744. // resize the content-div
  3745. sizeContent(pane);
  3746. }
  3747. if (!skipCallback && !skipResizeWhileDragging && state.initialized && s.isVisible)
  3748. _runCallbacks("onresize_end", pane);
  3749. // resize all the adjacent panes, and adjust their toggler buttons
  3750. // when skipCallback passed, it means the controlling method will handle 'other panes'
  3751. if (!skipCallback) {
  3752. // also no callback if live-resize is in progress and NOT triggerEventsDuringLiveResize
  3753. if (!s.isSliding) sizeMidPanes(_c[pane].dir == "horz" ? "" : "center", skipResizeWhileDragging, force);
  3754. sizeHandles();
  3755. }
  3756. // if opposite-pane was autoClosed, see if it can be autoOpened now
  3757. var altPane = _c.oppositeEdge[pane];
  3758. if (size < oldSize && state[altPane].noRoom) {
  3759. setSizeLimits(altPane);
  3760. makePaneFit(altPane, false, skipCallback);
  3761. }
  3762. // DEBUG - ALERT user/developer so they know there was a sizing problem
  3763. if (tries.length > 1)
  3764. _log(msg + '\nSee the Error Console for details.', true, true);
  3765. }
  3766. }
  3767. /**
  3768. * @see initPanes(), sizePane(), resizeAll(), open(), close(), hide()
  3769. * @param {(Array.<string>|string)} panes The pane(s) being resized, comma-delmited string
  3770. * @param {boolean=} [skipCallback=false] Should the onresize callback be run?
  3771. * @param {boolean=} [force=false]
  3772. */
  3773. , sizeMidPanes = function (panes, skipCallback, force) {
  3774. panes = (panes ? panes : "east,west,center").split(",");
  3775. $.each(panes, function (i, pane) {
  3776. if (!$Ps[pane]) return; // NO PANE - skip
  3777. var
  3778. o = options[pane]
  3779. , s = state[pane]
  3780. , $P = $Ps[pane]
  3781. , $R = $Rs[pane]
  3782. , isCenter = (pane == "center")
  3783. , hasRoom = true
  3784. , CSS = {}
  3785. // if pane is not visible, show it invisibly NOW rather than for *each call* in this script
  3786. , visCSS = $.layout.showInvisibly($P)
  3787. , newCenter = calcNewCenterPaneDims()
  3788. ;
  3789. // update pane-state dimensions
  3790. $.extend(s, elDims($P));
  3791. if (pane === "center") {
  3792. if (!force && s.isVisible && newCenter.width === s.outerWidth && newCenter.height === s.outerHeight) {
  3793. $P.css(visCSS);
  3794. return true; // SKIP - pane already the correct size
  3795. }
  3796. // set state for makePaneFit() logic
  3797. $.extend(s, cssMinDims(pane), {
  3798. maxWidth: newCenter.width
  3799. , maxHeight: newCenter.height
  3800. });
  3801. CSS = newCenter;
  3802. s.newWidth = CSS.width;
  3803. s.newHeight = CSS.height;
  3804. // convert OUTER width/height to CSS width/height
  3805. CSS.width = cssW($P, CSS.width);
  3806. // NEW - allow pane to extend 'below' visible area rather than hide it
  3807. CSS.height = cssH($P, CSS.height);
  3808. hasRoom = CSS.width >= 0 && CSS.height >= 0; // height >= 0 = ALWAYS TRUE NOW
  3809. // during layout init, try to shrink east/west panes to make room for center
  3810. if (!state.initialized && o.minWidth > newCenter.width) {
  3811. var
  3812. reqPx = o.minWidth - s.outerWidth
  3813. , minE = options.east.minSize || 0
  3814. , minW = options.west.minSize || 0
  3815. , sizeE = state.east.size
  3816. , sizeW = state.west.size
  3817. , newE = sizeE
  3818. , newW = sizeW
  3819. ;
  3820. if (reqPx > 0 && state.east.isVisible && sizeE > minE) {
  3821. newE = max(sizeE - minE, sizeE - reqPx);
  3822. reqPx -= sizeE - newE;
  3823. }
  3824. if (reqPx > 0 && state.west.isVisible && sizeW > minW) {
  3825. newW = max(sizeW - minW, sizeW - reqPx);
  3826. reqPx -= sizeW - newW;
  3827. }
  3828. // IF we found enough extra space, then resize the border panes as calculated
  3829. if (reqPx === 0) {
  3830. if (sizeE && sizeE != minE)
  3831. sizePane('east', newE, true, true, force); // true = skipCallback/noAnimation - initPanes will handle when done
  3832. if (sizeW && sizeW != minW)
  3833. sizePane('west', newW, true, true, force); // true = skipCallback/noAnimation
  3834. // now start over!
  3835. sizeMidPanes('center', skipCallback, force);
  3836. $P.css(visCSS);
  3837. return; // abort this loop
  3838. }
  3839. }
  3840. }
  3841. else { // for east and west, set only the height, which is same as center height
  3842. // set state.min/maxWidth/Height for makePaneFit() logic
  3843. if (s.isVisible && !s.noVerticalRoom)
  3844. $.extend(s, elDims($P), cssMinDims(pane))
  3845. if (!force && !s.noVerticalRoom && newCenter.height === s.outerHeight) {
  3846. $P.css(visCSS);
  3847. return true; // SKIP - pane already the correct size
  3848. }
  3849. // east/west have same top, bottom & height as center
  3850. CSS.top = newCenter.top;
  3851. CSS.bottom = newCenter.bottom;
  3852. s.newSize = newCenter.height
  3853. // NEW - allow pane to extend 'below' visible area rather than hide it
  3854. CSS.height = cssH($P, newCenter.height);
  3855. s.maxHeight = CSS.height;
  3856. hasRoom = (s.maxHeight >= 0); // ALWAYS TRUE NOW
  3857. if (!hasRoom) s.noVerticalRoom = true; // makePaneFit() logic
  3858. }
  3859. if (hasRoom) {
  3860. // resizeAll passes skipCallback because it triggers callbacks after ALL panes are resized
  3861. if (!skipCallback && state.initialized)
  3862. _runCallbacks("onresize_start", pane);
  3863. $P.css(CSS); // apply the CSS to pane
  3864. if (pane !== "center")
  3865. sizeHandles(pane); // also update resizer length
  3866. if (s.noRoom && !s.isClosed && !s.isHidden)
  3867. makePaneFit(pane); // will re-open/show auto-closed/hidden pane
  3868. if (s.isVisible) {
  3869. $.extend(s, elDims($P)); // update pane dimensions
  3870. if (state.initialized) sizeContent(pane); // also resize the contents, if exists
  3871. }
  3872. }
  3873. else if (!s.noRoom && s.isVisible) // no room for pane
  3874. makePaneFit(pane); // will hide or close pane
  3875. // reset visibility, if necessary
  3876. $P.css(visCSS);
  3877. delete s.newSize;
  3878. delete s.newWidth;
  3879. delete s.newHeight;
  3880. if (!s.isVisible)
  3881. return true; // DONE - next pane
  3882. /*
  3883. * Extra CSS for IE6 or IE7 in Quirks-mode - add 'width' to NORTH/SOUTH panes
  3884. * Normally these panes have only 'left' & 'right' positions so pane auto-sizes
  3885. * ALSO required when pane is an IFRAME because will NOT default to 'full width'
  3886. * TODO: Can I use width:100% for a north/south iframe?
  3887. * TODO: Sounds like a job for $P.outerWidth( sC.innerWidth ) SETTER METHOD
  3888. */
  3889. if (pane === "center") { // finished processing midPanes
  3890. var fix = browser.isIE6 || !browser.boxModel;
  3891. if ($Ps.north && (fix || state.north.tagName == "IFRAME"))
  3892. $Ps.north.css("width", cssW($Ps.north, sC.innerWidth));
  3893. if ($Ps.south && (fix || state.south.tagName == "IFRAME"))
  3894. $Ps.south.css("width", cssW($Ps.south, sC.innerWidth));
  3895. }
  3896. // resizeAll passes skipCallback because it triggers callbacks after ALL panes are resized
  3897. if (!skipCallback && state.initialized)
  3898. _runCallbacks("onresize_end", pane);
  3899. });
  3900. }
  3901. /**
  3902. * @see window.onresize(), callbacks or custom code
  3903. * @param {(Object|boolean)=} evt_or_refresh If 'true', then also reset pane-positioning
  3904. */
  3905. , resizeAll = function (evt_or_refresh) {
  3906. var oldW = sC.innerWidth
  3907. , oldH = sC.innerHeight
  3908. ;
  3909. // stopPropagation if called by trigger("layoutdestroy") - use evtPane utility
  3910. evtPane(evt_or_refresh);
  3911. // cannot size layout when 'container' is hidden or collapsed
  3912. if (!$N.is(":visible")) return;
  3913. if (!state.initialized) {
  3914. _initLayoutElements();
  3915. return; // no need to resize since we just initialized!
  3916. }
  3917. if (evt_or_refresh === true && $.isPlainObject(options.outset)) {
  3918. // update container CSS in case outset option has changed
  3919. $N.css(options.outset);
  3920. }
  3921. // UPDATE container dimensions
  3922. $.extend(sC, elDims($N, options.inset));
  3923. if (!sC.outerHeight) return;
  3924. // if 'true' passed, refresh pane & handle positioning too
  3925. if (evt_or_refresh === true) {
  3926. setPanePosition();
  3927. }
  3928. // onresizeall_start will CANCEL resizing if returns false
  3929. // state.container has already been set, so user can access this info for calcuations
  3930. if (false === _runCallbacks("onresizeall_start")) return false;
  3931. var // see if container is now 'smaller' than before
  3932. shrunkH = (sC.innerHeight < oldH)
  3933. , shrunkW = (sC.innerWidth < oldW)
  3934. , $P, o, s
  3935. ;
  3936. // NOTE special order for sizing: S-N-E-W
  3937. $.each(["south", "north", "east", "west"], function (i, pane) {
  3938. if (!$Ps[pane]) return; // no pane - SKIP
  3939. o = options[pane];
  3940. s = state[pane];
  3941. if (s.autoResize && s.size != o.size) // resize pane to original size set in options
  3942. sizePane(pane, o.size, true, true, true); // true=skipCallback/noAnimation/forceResize
  3943. else {
  3944. setSizeLimits(pane);
  3945. makePaneFit(pane, false, true, true); // true=skipCallback/forceResize
  3946. }
  3947. });
  3948. sizeMidPanes("", true, true); // true=skipCallback/forceResize
  3949. sizeHandles(); // reposition the toggler elements
  3950. // trigger all individual pane callbacks AFTER layout has finished resizing
  3951. $.each(_c.allPanes, function (i, pane) {
  3952. $P = $Ps[pane];
  3953. if (!$P) return; // SKIP
  3954. if (state[pane].isVisible) // undefined for non-existent panes
  3955. _runCallbacks("onresize_end", pane); // callback - if exists
  3956. });
  3957. _runCallbacks("onresizeall_end");
  3958. //_triggerLayoutEvent(pane, 'resizeall');
  3959. }
  3960. /**
  3961. * Whenever a pane resizes or opens that has a nested layout, trigger resizeAll
  3962. *
  3963. * @param {(string|Object)} evt_or_pane The pane just resized or opened
  3964. */
  3965. , resizeChildren = function (evt_or_pane, skipRefresh) {
  3966. var pane = evtPane.call(this, evt_or_pane);
  3967. if (!options[pane].resizeChildren) return;
  3968. // ensure the pane-children are up-to-date
  3969. if (!skipRefresh) refreshChildren(pane);
  3970. var pC = children[pane];
  3971. if ($.isPlainObject(pC)) {
  3972. // resize one or more children
  3973. $.each(pC, function (key, child) {
  3974. if (!child.destroyed) child.resizeAll();
  3975. });
  3976. }
  3977. }
  3978. /**
  3979. * IF pane has a content-div, then resize all elements inside pane to fit pane-height
  3980. *
  3981. * @param {(string|Object)} evt_or_panes The pane(s) being resized
  3982. * @param {boolean=} [remeasure=false] Should the content (header/footer) be remeasured?
  3983. */
  3984. , sizeContent = function (evt_or_panes, remeasure) {
  3985. if (!isInitialized()) return;
  3986. var panes = evtPane.call(this, evt_or_panes);
  3987. panes = panes ? panes.split(",") : _c.allPanes;
  3988. $.each(panes, function (idx, pane) {
  3989. var
  3990. $P = $Ps[pane]
  3991. , $C = $Cs[pane]
  3992. , o = options[pane]
  3993. , s = state[pane]
  3994. , m = s.content // m = measurements
  3995. ;
  3996. if (!$P || !$C || !$P.is(":visible")) return true; // NOT VISIBLE - skip
  3997. // if content-element was REMOVED, update OR remove the pointer
  3998. if (!$C.length) {
  3999. initContent(pane, false); // false = do NOT sizeContent() - already there!
  4000. if (!$C) return; // no replacement element found - pointer have been removed
  4001. }
  4002. // onsizecontent_start will CANCEL resizing if returns false
  4003. if (false === _runCallbacks("onsizecontent_start", pane)) return;
  4004. // skip re-measuring offsets if live-resizing
  4005. if ((!s.isMoving && !s.isResizing) || o.liveContentResizing || remeasure || m.top == undefined) {
  4006. _measure();
  4007. // if any footers are below pane-bottom, they may not measure correctly,
  4008. // so allow pane overflow and re-measure
  4009. if (m.hiddenFooters > 0 && $P.css("overflow") === "hidden") {
  4010. $P.css("overflow", "visible");
  4011. _measure(); // remeasure while overflowing
  4012. $P.css("overflow", "hidden");
  4013. }
  4014. }
  4015. // NOTE: spaceAbove/Below *includes* the pane paddingTop/Bottom, but not pane.borders
  4016. var newH = s.innerHeight - (m.spaceAbove - s.css.paddingTop) - (m.spaceBelow - s.css.paddingBottom);
  4017. if (!$C.is(":visible") || m.height != newH) {
  4018. // size the Content element to fit new pane-size - will autoHide if not enough room
  4019. setOuterHeight($C, newH, true); // true=autoHide
  4020. m.height = newH; // save new height
  4021. };
  4022. if (state.initialized)
  4023. _runCallbacks("onsizecontent_end", pane);
  4024. function _below($E) {
  4025. return max(s.css.paddingBottom, (parseInt($E.css("marginBottom"), 10) || 0));
  4026. };
  4027. function _measure() {
  4028. var
  4029. ignore = options[pane].contentIgnoreSelector
  4030. , $Fs = $C.nextAll().not(".ui-layout-mask").not(ignore || ":lt(0)") // not :lt(0) = ALL
  4031. , $Fs_vis = $Fs.filter(':visible')
  4032. , $F = $Fs_vis.filter(':last')
  4033. ;
  4034. m = {
  4035. top: $C[0].offsetTop
  4036. , height: $C.outerHeight()
  4037. , numFooters: $Fs.length
  4038. , hiddenFooters: $Fs.length - $Fs_vis.length
  4039. , spaceBelow: 0 // correct if no content footer ($E)
  4040. }
  4041. m.spaceAbove = m.top; // just for state - not used in calc
  4042. m.bottom = m.top + m.height;
  4043. if ($F.length)
  4044. //spaceBelow = (LastFooter.top + LastFooter.height) [footerBottom] - Content.bottom + max(LastFooter.marginBottom, pane.paddingBotom)
  4045. m.spaceBelow = ($F[0].offsetTop + $F.outerHeight()) - m.bottom + _below($F);
  4046. else // no footer - check marginBottom on Content element itself
  4047. m.spaceBelow = _below($C);
  4048. };
  4049. });
  4050. }
  4051. /**
  4052. * Called every time a pane is opened, closed, or resized to slide the togglers to 'center' and adjust their length if necessary
  4053. *
  4054. * @see initHandles(), open(), close(), resizeAll()
  4055. * @param {(string|Object)=} evt_or_panes The pane(s) being resized
  4056. */
  4057. , sizeHandles = function (evt_or_panes) {
  4058. var panes = evtPane.call(this, evt_or_panes)
  4059. panes = panes ? panes.split(",") : _c.borderPanes;
  4060. $.each(panes, function (i, pane) {
  4061. var
  4062. o = options[pane]
  4063. , s = state[pane]
  4064. , $P = $Ps[pane]
  4065. , $R = $Rs[pane]
  4066. , $T = $Ts[pane]
  4067. , $TC
  4068. ;
  4069. if (!$P || !$R) return;
  4070. var
  4071. dir = _c[pane].dir
  4072. , _state = (s.isClosed ? "_closed" : "_open")
  4073. , spacing = o["spacing" + _state]
  4074. , togAlign = o["togglerAlign" + _state]
  4075. , togLen = o["togglerLength" + _state]
  4076. , paneLen
  4077. , left
  4078. , offset
  4079. , CSS = {}
  4080. ;
  4081. if (spacing === 0) {
  4082. $R.hide();
  4083. return;
  4084. }
  4085. else if (!s.noRoom && !s.isHidden) // skip if resizer was hidden for any reason
  4086. $R.show(); // in case was previously hidden
  4087. // Resizer Bar is ALWAYS same width/height of pane it is attached to
  4088. if (dir === "horz") { // north/south
  4089. //paneLen = $P.outerWidth(); // s.outerWidth ||
  4090. paneLen = sC.innerWidth; // handle offscreen-panes
  4091. s.resizerLength = paneLen;
  4092. left = $.layout.cssNum($P, "left")
  4093. $R.css({
  4094. width: cssW($R, paneLen) // account for borders & padding
  4095. , height: cssH($R, spacing) // ditto
  4096. , left: left > -9999 ? left : sC.inset.left // handle offscreen-panes
  4097. });
  4098. }
  4099. else { // east/west
  4100. paneLen = $P.outerHeight(); // s.outerHeight ||
  4101. s.resizerLength = paneLen;
  4102. $R.css({
  4103. height: cssH($R, paneLen) // account for borders & padding
  4104. , width: cssW($R, spacing) // ditto
  4105. , top: sC.inset.top + getPaneSize("north", true) // TODO: what if no North pane?
  4106. //, top: $.layout.cssNum($Ps["center"], "top")
  4107. });
  4108. }
  4109. // remove hover classes
  4110. removeHover(o, $R);
  4111. if ($T) {
  4112. if (togLen === 0 || (s.isSliding && o.hideTogglerOnSlide)) {
  4113. $T.hide(); // always HIDE the toggler when 'sliding'
  4114. return;
  4115. }
  4116. else
  4117. $T.show(); // in case was previously hidden
  4118. if (!(togLen > 0) || togLen === "100%" || togLen > paneLen) {
  4119. togLen = paneLen;
  4120. offset = 0;
  4121. }
  4122. else { // calculate 'offset' based on options.PANE.togglerAlign_open/closed
  4123. if (isStr(togAlign)) {
  4124. switch (togAlign) {
  4125. case "top":
  4126. case "left": offset = 0;
  4127. break;
  4128. case "bottom":
  4129. case "right": offset = paneLen - togLen;
  4130. break;
  4131. case "middle":
  4132. case "center":
  4133. default: offset = round((paneLen - togLen) / 2); // 'default' catches typos
  4134. }
  4135. }
  4136. else { // togAlign = number
  4137. var x = parseInt(togAlign, 10); //
  4138. if (togAlign >= 0) offset = x;
  4139. else offset = paneLen - togLen + x; // NOTE: x is negative!
  4140. }
  4141. }
  4142. if (dir === "horz") { // north/south
  4143. var width = cssW($T, togLen);
  4144. $T.css({
  4145. width: width // account for borders & padding
  4146. , height: cssH($T, spacing) // ditto
  4147. , left: offset // TODO: VERIFY that toggler positions correctly for ALL values
  4148. , top: 0
  4149. });
  4150. // CENTER the toggler content SPAN
  4151. $T.children(".content").each(function () {
  4152. $TC = $(this);
  4153. $TC.css("marginLeft", round((width - $TC.outerWidth()) / 2)); // could be negative
  4154. });
  4155. }
  4156. else { // east/west
  4157. var height = cssH($T, togLen);
  4158. $T.css({
  4159. height: height // account for borders & padding
  4160. , width: cssW($T, spacing) // ditto
  4161. , top: offset // POSITION the toggler
  4162. , left: 0
  4163. });
  4164. // CENTER the toggler content SPAN
  4165. $T.children(".content").each(function () {
  4166. $TC = $(this);
  4167. $TC.css("marginTop", round((height - $TC.outerHeight()) / 2)); // could be negative
  4168. });
  4169. }
  4170. // remove ALL hover classes
  4171. removeHover(0, $T);
  4172. }
  4173. // DONE measuring and sizing this resizer/toggler, so can be 'hidden' now
  4174. if (!state.initialized && (o.initHidden || s.isHidden)) {
  4175. $R.hide();
  4176. if ($T) $T.hide();
  4177. }
  4178. });
  4179. }
  4180. /**
  4181. * @param {(string|Object)} evt_or_pane
  4182. */
  4183. , enableClosable = function (evt_or_pane) {
  4184. if (!isInitialized()) return;
  4185. var pane = evtPane.call(this, evt_or_pane)
  4186. , $T = $Ts[pane]
  4187. , o = options[pane]
  4188. ;
  4189. if (!$T) return;
  4190. o.closable = true;
  4191. $T.bind("click." + sID, function (evt) { evt.stopPropagation(); toggle(pane); })
  4192. .css("visibility", "visible")
  4193. .css("cursor", "pointer")
  4194. .attr("title", state[pane].isClosed ? o.tips.Open : o.tips.Close) // may be blank
  4195. .show();
  4196. }
  4197. /**
  4198. * @param {(string|Object)} evt_or_pane
  4199. * @param {boolean=} [hide=false]
  4200. */
  4201. , disableClosable = function (evt_or_pane, hide) {
  4202. if (!isInitialized()) return;
  4203. var pane = evtPane.call(this, evt_or_pane)
  4204. , $T = $Ts[pane]
  4205. ;
  4206. if (!$T) return;
  4207. options[pane].closable = false;
  4208. // is closable is disable, then pane MUST be open!
  4209. if (state[pane].isClosed) open(pane, false, true);
  4210. $T.unbind("." + sID)
  4211. .css("visibility", hide ? "hidden" : "visible") // instead of hide(), which creates logic issues
  4212. .css("cursor", "default")
  4213. .attr("title", "");
  4214. }
  4215. /**
  4216. * @param {(string|Object)} evt_or_pane
  4217. */
  4218. , enableSlidable = function (evt_or_pane) {
  4219. if (!isInitialized()) return;
  4220. var pane = evtPane.call(this, evt_or_pane)
  4221. , $R = $Rs[pane]
  4222. ;
  4223. if (!$R || !$R.data('draggable')) return;
  4224. options[pane].slidable = true;
  4225. if (state[pane].isClosed)
  4226. bindStartSlidingEvents(pane, true);
  4227. }
  4228. /**
  4229. * @param {(string|Object)} evt_or_pane
  4230. */
  4231. , disableSlidable = function (evt_or_pane) {
  4232. if (!isInitialized()) return;
  4233. var pane = evtPane.call(this, evt_or_pane)
  4234. , $R = $Rs[pane]
  4235. ;
  4236. if (!$R) return;
  4237. options[pane].slidable = false;
  4238. if (state[pane].isSliding)
  4239. close(pane, false, true);
  4240. else {
  4241. bindStartSlidingEvents(pane, false);
  4242. $R.css("cursor", "default")
  4243. .attr("title", "");
  4244. removeHover(null, $R[0]); // in case currently hovered
  4245. }
  4246. }
  4247. /**
  4248. * @param {(string|Object)} evt_or_pane
  4249. */
  4250. , enableResizable = function (evt_or_pane) {
  4251. if (!isInitialized()) return;
  4252. var pane = evtPane.call(this, evt_or_pane)
  4253. , $R = $Rs[pane]
  4254. , o = options[pane]
  4255. ;
  4256. if (!$R || !$R.data('draggable')) return;
  4257. o.resizable = true;
  4258. $R.draggable("enable");
  4259. if (!state[pane].isClosed)
  4260. $R.css("cursor", o.resizerCursor)
  4261. .attr("title", o.tips.Resize);
  4262. }
  4263. /**
  4264. * @param {(string|Object)} evt_or_pane
  4265. */
  4266. , disableResizable = function (evt_or_pane) {
  4267. if (!isInitialized()) return;
  4268. var pane = evtPane.call(this, evt_or_pane)
  4269. , $R = $Rs[pane]
  4270. ;
  4271. if (!$R || !$R.data('draggable')) return;
  4272. options[pane].resizable = false;
  4273. $R.draggable("disable")
  4274. .css("cursor", "default")
  4275. .attr("title", "");
  4276. removeHover(null, $R[0]); // in case currently hovered
  4277. }
  4278. /**
  4279. * Move a pane from source-side (eg, west) to target-side (eg, east)
  4280. * If pane exists on target-side, move that to source-side, ie, 'swap' the panes
  4281. *
  4282. * @param {(string|Object)} evt_or_pane1 The pane/edge being swapped
  4283. * @param {string} pane2 ditto
  4284. */
  4285. , swapPanes = function (evt_or_pane1, pane2) {
  4286. if (!isInitialized()) return;
  4287. var pane1 = evtPane.call(this, evt_or_pane1);
  4288. // change state.edge NOW so callbacks can know where pane is headed...
  4289. state[pane1].edge = pane2;
  4290. state[pane2].edge = pane1;
  4291. // run these even if NOT state.initialized
  4292. if (false === _runCallbacks("onswap_start", pane1)
  4293. || false === _runCallbacks("onswap_start", pane2)
  4294. ) {
  4295. state[pane1].edge = pane1; // reset
  4296. state[pane2].edge = pane2;
  4297. return;
  4298. }
  4299. var
  4300. oPane1 = copy(pane1)
  4301. , oPane2 = copy(pane2)
  4302. , sizes = {}
  4303. ;
  4304. sizes[pane1] = oPane1 ? oPane1.state.size : 0;
  4305. sizes[pane2] = oPane2 ? oPane2.state.size : 0;
  4306. // clear pointers & state
  4307. $Ps[pane1] = false;
  4308. $Ps[pane2] = false;
  4309. state[pane1] = {};
  4310. state[pane2] = {};
  4311. // ALWAYS remove the resizer & toggler elements
  4312. if ($Ts[pane1]) $Ts[pane1].remove();
  4313. if ($Ts[pane2]) $Ts[pane2].remove();
  4314. if ($Rs[pane1]) $Rs[pane1].remove();
  4315. if ($Rs[pane2]) $Rs[pane2].remove();
  4316. $Rs[pane1] = $Rs[pane2] = $Ts[pane1] = $Ts[pane2] = false;
  4317. // transfer element pointers and data to NEW Layout keys
  4318. move(oPane1, pane2);
  4319. move(oPane2, pane1);
  4320. // cleanup objects
  4321. oPane1 = oPane2 = sizes = null;
  4322. // make panes 'visible' again
  4323. if ($Ps[pane1]) $Ps[pane1].css(_c.visible);
  4324. if ($Ps[pane2]) $Ps[pane2].css(_c.visible);
  4325. // fix any size discrepancies caused by swap
  4326. resizeAll();
  4327. // run these even if NOT state.initialized
  4328. _runCallbacks("onswap_end", pane1);
  4329. _runCallbacks("onswap_end", pane2);
  4330. return;
  4331. function copy(n) { // n = pane
  4332. var
  4333. $P = $Ps[n]
  4334. , $C = $Cs[n]
  4335. ;
  4336. return !$P ? false : {
  4337. pane: n
  4338. , P: $P ? $P[0] : false
  4339. , C: $C ? $C[0] : false
  4340. , state: $.extend(true, {}, state[n])
  4341. , options: $.extend(true, {}, options[n])
  4342. }
  4343. };
  4344. function move(oPane, pane) {
  4345. if (!oPane) return;
  4346. var
  4347. P = oPane.P
  4348. , C = oPane.C
  4349. , oldPane = oPane.pane
  4350. , c = _c[pane]
  4351. // save pane-options that should be retained
  4352. , s = $.extend(true, {}, state[pane])
  4353. , o = options[pane]
  4354. // RETAIN side-specific FX Settings - more below
  4355. , fx = { resizerCursor: o.resizerCursor }
  4356. , re, size, pos
  4357. ;
  4358. $.each("fxName,fxSpeed,fxSettings".split(","), function (i, k) {
  4359. fx[k + "_open"] = o[k + "_open"];
  4360. fx[k + "_close"] = o[k + "_close"];
  4361. fx[k + "_size"] = o[k + "_size"];
  4362. });
  4363. // update object pointers and attributes
  4364. $Ps[pane] = $(P)
  4365. .data({
  4366. layoutPane: Instance[pane] // NEW pointer to pane-alias-object
  4367. , layoutEdge: pane
  4368. })
  4369. .css(_c.hidden)
  4370. .css(c.cssReq)
  4371. ;
  4372. $Cs[pane] = C ? $(C) : false;
  4373. // set options and state
  4374. options[pane] = $.extend(true, {}, oPane.options, fx);
  4375. state[pane] = $.extend(true, {}, oPane.state);
  4376. // change classNames on the pane, eg: ui-layout-pane-east ==> ui-layout-pane-west
  4377. re = new RegExp(o.paneClass + "-" + oldPane, "g");
  4378. P.className = P.className.replace(re, o.paneClass + "-" + pane);
  4379. // ALWAYS regenerate the resizer & toggler elements
  4380. initHandles(pane); // create the required resizer & toggler
  4381. // if moving to different orientation, then keep 'target' pane size
  4382. if (c.dir != _c[oldPane].dir) {
  4383. size = sizes[pane] || 0;
  4384. setSizeLimits(pane); // update pane-state
  4385. size = max(size, state[pane].minSize);
  4386. // use manualSizePane to disable autoResize - not useful after panes are swapped
  4387. manualSizePane(pane, size, true, true); // true/true = skipCallback/noAnimation
  4388. }
  4389. else // move the resizer here
  4390. $Rs[pane].css(c.side, sC.inset[c.side] + (state[pane].isVisible ? getPaneSize(pane) : 0));
  4391. // ADD CLASSNAMES & SLIDE-BINDINGS
  4392. if (oPane.state.isVisible && !s.isVisible)
  4393. setAsOpen(pane, true); // true = skipCallback
  4394. else {
  4395. setAsClosed(pane);
  4396. bindStartSlidingEvents(pane, true); // will enable events IF option is set
  4397. }
  4398. // DESTROY the object
  4399. oPane = null;
  4400. };
  4401. }
  4402. /**
  4403. * INTERNAL method to sync pin-buttons when pane is opened or closed
  4404. * Unpinned means the pane is 'sliding' - ie, over-top of the adjacent panes
  4405. *
  4406. * @see open(), setAsOpen(), setAsClosed()
  4407. * @param {string} pane These are the params returned to callbacks by layout()
  4408. * @param {boolean} doPin True means set the pin 'down', False means 'up'
  4409. */
  4410. , syncPinBtns = function (pane, doPin) {
  4411. if ($.layout.plugins.buttons)
  4412. $.each(state[pane].pins, function (i, selector) {
  4413. $.layout.buttons.setPinState(Instance, $(selector), pane, doPin);
  4414. });
  4415. }
  4416. ; // END var DECLARATIONS
  4417. /**
  4418. * Capture keys when enableCursorHotkey - toggle pane if hotkey pressed
  4419. *
  4420. * @see document.keydown()
  4421. */
  4422. function keyDown(evt) {
  4423. if (!evt) return true;
  4424. var code = evt.keyCode;
  4425. if (code < 33) return true; // ignore special keys: ENTER, TAB, etc
  4426. var
  4427. PANE = {
  4428. 38: "north" // Up Cursor - $.ui.keyCode.UP
  4429. , 40: "south" // Down Cursor - $.ui.keyCode.DOWN
  4430. , 37: "west" // Left Cursor - $.ui.keyCode.LEFT
  4431. , 39: "east" // Right Cursor - $.ui.keyCode.RIGHT
  4432. }
  4433. , ALT = evt.altKey // no worky!
  4434. , SHIFT = evt.shiftKey
  4435. , CTRL = evt.ctrlKey
  4436. , CURSOR = (CTRL && code >= 37 && code <= 40)
  4437. , o, k, m, pane
  4438. ;
  4439. if (CURSOR && options[PANE[code]].enableCursorHotkey) // valid cursor-hotkey
  4440. pane = PANE[code];
  4441. else if (CTRL || SHIFT) // check to see if this matches a custom-hotkey
  4442. $.each(_c.borderPanes, function (i, p) { // loop each pane to check its hotkey
  4443. o = options[p];
  4444. k = o.customHotkey;
  4445. m = o.customHotkeyModifier; // if missing or invalid, treated as "CTRL+SHIFT"
  4446. if ((SHIFT && m == "SHIFT") || (CTRL && m == "CTRL") || (CTRL && SHIFT)) { // Modifier matches
  4447. if (k && code === (isNaN(k) || k <= 9 ? k.toUpperCase().charCodeAt(0) : k)) { // Key matches
  4448. pane = p;
  4449. return false; // BREAK
  4450. }
  4451. }
  4452. });
  4453. // validate pane
  4454. if (!pane || !$Ps[pane] || !options[pane].closable || state[pane].isHidden)
  4455. return true;
  4456. toggle(pane);
  4457. evt.stopPropagation();
  4458. evt.returnValue = false; // CANCEL key
  4459. return false;
  4460. };
  4461. /*
  4462. * ######################################
  4463. * UTILITY METHODS
  4464. * called externally or by initButtons
  4465. * ######################################
  4466. */
  4467. /**
  4468. * Change/reset a pane overflow setting & zIndex to allow popups/drop-downs to work
  4469. *
  4470. * @param {Object=} [el] (optional) Can also be 'bound' to a click, mouseOver, or other event
  4471. */
  4472. function allowOverflow(el) {
  4473. if (!isInitialized()) return;
  4474. if (this && this.tagName) el = this; // BOUND to element
  4475. var $P;
  4476. if (isStr(el))
  4477. $P = $Ps[el];
  4478. else if ($(el).data("layoutRole"))
  4479. $P = $(el);
  4480. else
  4481. $(el).parents().each(function () {
  4482. if ($(this).data("layoutRole")) {
  4483. $P = $(this);
  4484. return false; // BREAK
  4485. }
  4486. });
  4487. if (!$P || !$P.length) return; // INVALID
  4488. var
  4489. pane = $P.data("layoutEdge")
  4490. , s = state[pane]
  4491. ;
  4492. // if pane is already raised, then reset it before doing it again!
  4493. // this would happen if allowOverflow is attached to BOTH the pane and an element
  4494. if (s.cssSaved)
  4495. resetOverflow(pane); // reset previous CSS before continuing
  4496. // if pane is raised by sliding or resizing, or its closed, then abort
  4497. if (s.isSliding || s.isResizing || s.isClosed) {
  4498. s.cssSaved = false;
  4499. return;
  4500. }
  4501. var
  4502. newCSS = { zIndex: (options.zIndexes.resizer_normal + 1) }
  4503. , curCSS = {}
  4504. , of = $P.css("overflow")
  4505. , ofX = $P.css("overflowX")
  4506. , ofY = $P.css("overflowY")
  4507. ;
  4508. // determine which, if any, overflow settings need to be changed
  4509. if (of != "visible") {
  4510. curCSS.overflow = of;
  4511. newCSS.overflow = "visible";
  4512. }
  4513. if (ofX && !ofX.match(/(visible|auto)/)) {
  4514. curCSS.overflowX = ofX;
  4515. newCSS.overflowX = "visible";
  4516. }
  4517. if (ofY && !ofY.match(/(visible|auto)/)) {
  4518. curCSS.overflowY = ofX;
  4519. newCSS.overflowY = "visible";
  4520. }
  4521. // save the current overflow settings - even if blank!
  4522. s.cssSaved = curCSS;
  4523. // apply new CSS to raise zIndex and, if necessary, make overflow 'visible'
  4524. $P.css(newCSS);
  4525. // make sure the zIndex of all other panes is normal
  4526. $.each(_c.allPanes, function (i, p) {
  4527. if (p != pane) resetOverflow(p);
  4528. });
  4529. };
  4530. /**
  4531. * @param {Object=} [el] (optional) Can also be 'bound' to a click, mouseOver, or other event
  4532. */
  4533. function resetOverflow(el) {
  4534. if (!isInitialized()) return;
  4535. if (this && this.tagName) el = this; // BOUND to element
  4536. var $P;
  4537. if (isStr(el))
  4538. $P = $Ps[el];
  4539. else if ($(el).data("layoutRole"))
  4540. $P = $(el);
  4541. else
  4542. $(el).parents().each(function () {
  4543. if ($(this).data("layoutRole")) {
  4544. $P = $(this);
  4545. return false; // BREAK
  4546. }
  4547. });
  4548. if (!$P || !$P.length) return; // INVALID
  4549. var
  4550. pane = $P.data("layoutEdge")
  4551. , s = state[pane]
  4552. , CSS = s.cssSaved || {}
  4553. ;
  4554. // reset the zIndex
  4555. if (!s.isSliding && !s.isResizing)
  4556. $P.css("zIndex", options.zIndexes.pane_normal);
  4557. // reset Overflow - if necessary
  4558. $P.css(CSS);
  4559. // clear var
  4560. s.cssSaved = false;
  4561. };
  4562. /*
  4563. * #####################
  4564. * CREATE/RETURN LAYOUT
  4565. * #####################
  4566. */
  4567. // validate that container exists
  4568. var $N = $(this).eq(0); // FIRST matching Container element
  4569. if (!$N.length) {
  4570. return _log(options.errors.containerMissing);
  4571. };
  4572. // Users retrieve Instance of a layout with: $N.layout() OR $N.data("layout")
  4573. // return the Instance-pointer if layout has already been initialized
  4574. if ($N.data("layoutContainer") && $N.data("layout"))
  4575. return $N.data("layout"); // cached pointer
  4576. // init global vars
  4577. var
  4578. $Ps = {} // Panes x5 - set in initPanes()
  4579. , $Cs = {} // Content x5 - set in initPanes()
  4580. , $Rs = {} // Resizers x4 - set in initHandles()
  4581. , $Ts = {} // Togglers x4 - set in initHandles()
  4582. , $Ms = $([]) // Masks - up to 2 masks per pane (IFRAME + DIV)
  4583. // aliases for code brevity
  4584. , sC = state.container // alias for easy access to 'container dimensions'
  4585. , sID = state.id // alias for unique layout ID/namespace - eg: "layout435"
  4586. ;
  4587. // create Instance object to expose data & option Properties, and primary action Methods
  4588. var Instance = {
  4589. // layout data
  4590. options: options // property - options hash
  4591. , state: state // property - dimensions hash
  4592. // object pointers
  4593. , container: $N // property - object pointers for layout container
  4594. , panes: $Ps // property - object pointers for ALL Panes: panes.north, panes.center
  4595. , contents: $Cs // property - object pointers for ALL Content: contents.north, contents.center
  4596. , resizers: $Rs // property - object pointers for ALL Resizers, eg: resizers.north
  4597. , togglers: $Ts // property - object pointers for ALL Togglers, eg: togglers.north
  4598. // border-pane open/close
  4599. , hide: hide // method - ditto
  4600. , show: show // method - ditto
  4601. , toggle: toggle // method - pass a 'pane' ("north", "west", etc)
  4602. , open: open // method - ditto
  4603. , close: close // method - ditto
  4604. , slideOpen: slideOpen // method - ditto
  4605. , slideClose: slideClose // method - ditto
  4606. , slideToggle: slideToggle // method - ditto
  4607. // pane actions
  4608. , setSizeLimits: setSizeLimits // method - pass a 'pane' - update state min/max data
  4609. , _sizePane: sizePane // method -intended for user by plugins only!
  4610. , sizePane: manualSizePane // method - pass a 'pane' AND an 'outer-size' in pixels or percent, or 'auto'
  4611. , sizeContent: sizeContent // method - pass a 'pane'
  4612. , swapPanes: swapPanes // method - pass TWO 'panes' - will swap them
  4613. , showMasks: showMasks // method - pass a 'pane' OR list of panes - default = all panes with mask option set
  4614. , hideMasks: hideMasks // method - ditto'
  4615. // pane element methods
  4616. , initContent: initContent // method - ditto
  4617. , addPane: addPane // method - pass a 'pane'
  4618. , removePane: removePane // method - pass a 'pane' to remove from layout, add 'true' to delete the pane-elem
  4619. , createChildren: createChildren // method - pass a 'pane' and (optional) layout-options (OVERRIDES options[pane].children
  4620. , refreshChildren: refreshChildren // method - pass a 'pane' and a layout-instance
  4621. // special pane option setting
  4622. , enableClosable: enableClosable // method - pass a 'pane'
  4623. , disableClosable: disableClosable // method - ditto
  4624. , enableSlidable: enableSlidable // method - ditto
  4625. , disableSlidable: disableSlidable // method - ditto
  4626. , enableResizable: enableResizable // method - ditto
  4627. , disableResizable: disableResizable// method - ditto
  4628. // utility methods for panes
  4629. , allowOverflow: allowOverflow // utility - pass calling element (this)
  4630. , resetOverflow: resetOverflow // utility - ditto
  4631. // layout control
  4632. , destroy: destroy // method - no parameters
  4633. , initPanes: isInitialized // method - no parameters
  4634. , resizeAll: resizeAll // method - no parameters
  4635. // callback triggering
  4636. , runCallbacks: _runCallbacks // method - pass evtName & pane (if a pane-event), eg: trigger("onopen", "west")
  4637. // alias collections of options, state and children - created in addPane and extended elsewhere
  4638. , hasParentLayout: false // set by initContainer()
  4639. , children: children // pointers to child-layouts, eg: Instance.children.west.layoutName
  4640. , north: false // alias group: { name: pane, pane: $Ps[pane], options: options[pane], state: state[pane], children: children[pane] }
  4641. , south: false // ditto
  4642. , west: false // ditto
  4643. , east: false // ditto
  4644. , center: false // ditto
  4645. };
  4646. // create the border layout NOW
  4647. if (_create() === 'cancel') // onload_start callback returned false to CANCEL layout creation
  4648. return null;
  4649. else // true OR false -- if layout-elements did NOT init (hidden or do not exist), can auto-init later
  4650. return Instance; // return the Instance object
  4651. }
  4652. })(jQuery);
  4653. /**
  4654. * jquery.layout.state 1.2
  4655. * $Date: 2014-08-30 08:00:00 (Sat, 30 Aug 2014) $
  4656. *
  4657. * Copyright (c) 2014
  4658. * Kevin Dalman (http://allpro.net)
  4659. *
  4660. * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
  4661. * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
  4662. *
  4663. * @requires: UI Layout 1.4.0 or higher
  4664. * @requires: $.ui.cookie (above)
  4665. *
  4666. * @see: http://groups.google.com/group/jquery-ui-layout
  4667. */
  4668. ; (function ($) {
  4669. if (!$.layout) return;
  4670. /**
  4671. * UI COOKIE UTILITY
  4672. *
  4673. * A $.cookie OR $.ui.cookie namespace *should be standard*, but until then...
  4674. * This creates $.ui.cookie so Layout does not need the cookie.jquery.js plugin
  4675. * NOTE: This utility is REQUIRED by the layout.state plugin
  4676. *
  4677. * Cookie methods in Layout are created as part of State Management
  4678. */
  4679. if (!$.ui) $.ui = {};
  4680. $.ui.cookie = {
  4681. // cookieEnabled is not in DOM specs, but DOES works in all browsers,including IE6
  4682. acceptsCookies: !!navigator.cookieEnabled
  4683. , read: function (name) {
  4684. var
  4685. c = document.cookie
  4686. , cs = c ? c.split(';') : []
  4687. , pair, data, i
  4688. ;
  4689. for (i = 0; pair = cs[i]; i++) {
  4690. data = $.trim(pair).split('='); // name=value => [ name, value ]
  4691. if (data[0] == name) // found the layout cookie
  4692. return decodeURIComponent(data[1]);
  4693. }
  4694. return null;
  4695. }
  4696. , write: function (name, val, cookieOpts) {
  4697. var params = ""
  4698. , date = ""
  4699. , clear = false
  4700. , o = cookieOpts || {}
  4701. , x = o.expires || null
  4702. , t = $.type(x)
  4703. ;
  4704. if (t === "date")
  4705. date = x;
  4706. else if (t === "string" && x > 0) {
  4707. x = parseInt(x, 10);
  4708. t = "number";
  4709. }
  4710. if (t === "number") {
  4711. date = new Date();
  4712. if (x > 0)
  4713. date.setDate(date.getDate() + x);
  4714. else {
  4715. date.setFullYear(1970);
  4716. clear = true;
  4717. }
  4718. }
  4719. if (date) params += ";expires=" + date.toUTCString();
  4720. if (o.path) params += ";path=" + o.path;
  4721. if (o.domain) params += ";domain=" + o.domain;
  4722. if (o.secure) params += ";secure";
  4723. document.cookie = name + "=" + (clear ? "" : encodeURIComponent(val)) + params; // write or clear cookie
  4724. }
  4725. , clear: function (name) {
  4726. $.ui.cookie.write(name, "", { expires: -1 });
  4727. }
  4728. };
  4729. // if cookie.jquery.js is not loaded, create an alias to replicate it
  4730. // this may be useful to other plugins or code dependent on that plugin
  4731. if (!$.cookie) $.cookie = function (k, v, o) {
  4732. var C = $.ui.cookie;
  4733. if (v === null)
  4734. C.clear(k);
  4735. else if (v === undefined)
  4736. return C.read(k);
  4737. else
  4738. C.write(k, v, o);
  4739. };
  4740. /**
  4741. * State-management options stored in options.stateManagement, which includes a .cookie hash
  4742. * Default options saves ALL KEYS for ALL PANES, ie: pane.size, pane.isClosed, pane.isHidden
  4743. *
  4744. * // STATE/COOKIE OPTIONS
  4745. * @example $(el).layout({
  4746. stateManagement: {
  4747. enabled: true
  4748. , stateKeys: "east.size,west.size,east.isClosed,west.isClosed"
  4749. , cookie: { name: "appLayout", path: "/" }
  4750. }
  4751. })
  4752. * @example $(el).layout({ stateManagement__enabled: true }) // enable auto-state-management using cookies
  4753. * @example $(el).layout({ stateManagement__cookie: { name: "appLayout", path: "/" } })
  4754. * @example $(el).layout({ stateManagement__cookie__name: "appLayout", stateManagement__cookie__path: "/" })
  4755. *
  4756. * // STATE/COOKIE METHODS
  4757. * @example myLayout.saveCookie( "west.isClosed,north.size,south.isHidden", {expires: 7} );
  4758. * @example myLayout.loadCookie();
  4759. * @example myLayout.deleteCookie();
  4760. * @example var JSON = myLayout.readState(); // CURRENT Layout State
  4761. * @example var JSON = myLayout.readCookie(); // SAVED Layout State (from cookie)
  4762. * @example var JSON = myLayout.state.stateData; // LAST LOADED Layout State (cookie saved in layout.state hash)
  4763. *
  4764. * CUSTOM STATE-MANAGEMENT (eg, saved in a database)
  4765. * @example var JSON = myLayout.readState( "west.isClosed,north.size,south.isHidden" );
  4766. * @example myLayout.loadState( JSON );
  4767. */
  4768. // tell Layout that the state plugin is available
  4769. $.layout.plugins.stateManagement = true;
  4770. // Add State-Management options to layout.defaults
  4771. $.layout.defaults.stateManagement = {
  4772. enabled: false // true = enable state-management, even if not using cookies
  4773. , autoSave: true // Save a state-cookie when page exits?
  4774. , autoLoad: true // Load the state-cookie when Layout inits?
  4775. , animateLoad: true // animate panes when loading state into an active layout
  4776. , includeChildren: true // recurse into child layouts to include their state as well
  4777. // List state-data to save - must be pane-specific
  4778. , stateKeys: "north.size,south.size,east.size,west.size," +
  4779. "north.isClosed,south.isClosed,east.isClosed,west.isClosed," +
  4780. "north.isHidden,south.isHidden,east.isHidden,west.isHidden"
  4781. , cookie: {
  4782. name: "" // If not specified, will use Layout.name, else just "Layout"
  4783. , domain: "" // blank = current domain
  4784. , path: "" // blank = current page, "/" = entire website
  4785. , expires: "" // 'days' to keep cookie - leave blank for 'session cookie'
  4786. , secure: false
  4787. }
  4788. };
  4789. // Set stateManagement as a 'layout-option', NOT a 'pane-option'
  4790. $.layout.optionsMap.layout.push("stateManagement");
  4791. // Update config so layout does not move options into the pane-default branch (panes)
  4792. $.layout.config.optionRootKeys.push("stateManagement");
  4793. /*
  4794. * State Management methods
  4795. */
  4796. $.layout.state = {
  4797. /**
  4798. * Get the current layout state and save it to a cookie
  4799. *
  4800. * myLayout.saveCookie( keys, cookieOpts )
  4801. *
  4802. * @param {Object} inst
  4803. * @param {(string|Array)=} keys
  4804. * @param {Object=} cookieOpts
  4805. */
  4806. saveCookie: function (inst, keys, cookieOpts) {
  4807. var o = inst.options
  4808. , sm = o.stateManagement
  4809. , oC = $.extend(true, {}, sm.cookie, cookieOpts || null)
  4810. , data = inst.state.stateData = inst.readState(keys || sm.stateKeys) // read current panes-state
  4811. ;
  4812. $.ui.cookie.write(oC.name || o.name || "Layout", $.layout.state.encodeJSON(data), oC);
  4813. return $.extend(true, {}, data); // return COPY of state.stateData data
  4814. }
  4815. /**
  4816. * Remove the state cookie
  4817. *
  4818. * @param {Object} inst
  4819. */
  4820. , deleteCookie: function (inst) {
  4821. var o = inst.options;
  4822. $.ui.cookie.clear(o.stateManagement.cookie.name || o.name || "Layout");
  4823. }
  4824. /**
  4825. * Read & return data from the cookie - as JSON
  4826. *
  4827. * @param {Object} inst
  4828. */
  4829. , readCookie: function (inst) {
  4830. var o = inst.options;
  4831. var c = $.ui.cookie.read(o.stateManagement.cookie.name || o.name || "Layout");
  4832. // convert cookie string back to a hash and return it
  4833. return c ? $.layout.state.decodeJSON(c) : {};
  4834. }
  4835. /**
  4836. * Get data from the cookie and USE IT to loadState
  4837. *
  4838. * @param {Object} inst
  4839. */
  4840. , loadCookie: function (inst) {
  4841. var c = $.layout.state.readCookie(inst); // READ the cookie
  4842. if (c && !$.isEmptyObject(c)) {
  4843. inst.state.stateData = $.extend(true, {}, c); // SET state.stateData
  4844. inst.loadState(c); // LOAD the retrieved state
  4845. }
  4846. return c;
  4847. }
  4848. /**
  4849. * Update layout options from the cookie, if one exists
  4850. *
  4851. * @param {Object} inst
  4852. * @param {Object=} stateData
  4853. * @param {boolean=} animate
  4854. */
  4855. , loadState: function (inst, data, opts) {
  4856. if (!$.isPlainObject(data) || $.isEmptyObject(data)) return;
  4857. // normalize data & cache in the state object
  4858. data = inst.state.stateData = $.layout.transformData(data); // panes = default subkey
  4859. // add missing/default state-restore options
  4860. var smo = inst.options.stateManagement;
  4861. opts = $.extend({
  4862. animateLoad: false //smo.animateLoad
  4863. , includeChildren: smo.includeChildren
  4864. }, opts);
  4865. if (!inst.state.initialized) {
  4866. /*
  4867. * layout NOT initialized, so just update its options
  4868. */
  4869. // MUST remove pane.children keys before applying to options
  4870. // use a copy so we don't remove keys from original data
  4871. var o = $.extend(true, {}, data);
  4872. //delete o.center; // center has no state-data - only children
  4873. $.each($.layout.config.allPanes, function (idx, pane) {
  4874. if (o[pane]) delete o[pane].children;
  4875. });
  4876. // update CURRENT layout-options with saved state data
  4877. $.extend(true, inst.options, o);
  4878. }
  4879. else {
  4880. /*
  4881. * layout already initialized, so modify layout's configuration
  4882. */
  4883. var noAnimate = !opts.animateLoad
  4884. , o, c, h, state, open
  4885. ;
  4886. $.each($.layout.config.borderPanes, function (idx, pane) {
  4887. o = data[pane];
  4888. if (!$.isPlainObject(o)) return; // no key, skip pane
  4889. s = o.size;
  4890. c = o.initClosed;
  4891. h = o.initHidden;
  4892. ar = o.autoResize
  4893. state = inst.state[pane];
  4894. open = state.isVisible;
  4895. // reset autoResize
  4896. if (ar)
  4897. state.autoResize = ar;
  4898. // resize BEFORE opening
  4899. if (!open)
  4900. inst._sizePane(pane, s, false, false, false); // false=skipCallback/noAnimation/forceResize
  4901. // open/close as necessary - DO NOT CHANGE THIS ORDER!
  4902. if (h === true) inst.hide(pane, noAnimate);
  4903. else if (c === true) inst.close(pane, false, noAnimate);
  4904. else if (c === false) inst.open(pane, false, noAnimate);
  4905. else if (h === false) inst.show(pane, false, noAnimate);
  4906. // resize AFTER any other actions
  4907. if (open)
  4908. inst._sizePane(pane, s, false, false, noAnimate); // animate resize if option passed
  4909. });
  4910. /*
  4911. * RECURSE INTO CHILD-LAYOUTS
  4912. */
  4913. if (opts.includeChildren) {
  4914. var paneStateChildren, childState;
  4915. $.each(inst.children, function (pane, paneChildren) {
  4916. paneStateChildren = data[pane] ? data[pane].children : 0;
  4917. if (paneStateChildren && paneChildren) {
  4918. $.each(paneChildren, function (stateKey, child) {
  4919. childState = paneStateChildren[stateKey];
  4920. if (child && childState)
  4921. child.loadState(childState);
  4922. });
  4923. }
  4924. });
  4925. }
  4926. }
  4927. }
  4928. /**
  4929. * Get the *current layout state* and return it as a hash
  4930. *
  4931. * @param {Object=} inst // Layout instance to get state for
  4932. * @param {object=} [opts] // State-Managements override options
  4933. */
  4934. , readState: function (inst, opts) {
  4935. // backward compatility
  4936. if ($.type(opts) === 'string') opts = { keys: opts };
  4937. if (!opts) opts = {};
  4938. var sm = inst.options.stateManagement
  4939. , ic = opts.includeChildren
  4940. , recurse = ic !== undefined ? ic : sm.includeChildren
  4941. , keys = opts.stateKeys || sm.stateKeys
  4942. , alt = { isClosed: 'initClosed', isHidden: 'initHidden' }
  4943. , state = inst.state
  4944. , panes = $.layout.config.allPanes
  4945. , data = {}
  4946. , pair, pane, key, val
  4947. , ps, pC, child, array, count, branch
  4948. ;
  4949. if ($.isArray(keys)) keys = keys.join(",");
  4950. // convert keys to an array and change delimiters from '__' to '.'
  4951. keys = keys.replace(/__/g, ".").split(',');
  4952. // loop keys and create a data hash
  4953. for (var i = 0, n = keys.length; i < n; i++) {
  4954. pair = keys[i].split(".");
  4955. pane = pair[0];
  4956. key = pair[1];
  4957. if ($.inArray(pane, panes) < 0) continue; // bad pane!
  4958. val = state[pane][key];
  4959. if (val == undefined) continue;
  4960. if (key == "isClosed" && state[pane]["isSliding"])
  4961. val = true; // if sliding, then *really* isClosed
  4962. (data[pane] || (data[pane] = {}))[alt[key] ? alt[key] : key] = val;
  4963. }
  4964. // recurse into the child-layouts for each pane
  4965. if (recurse) {
  4966. $.each(panes, function (idx, pane) {
  4967. pC = inst.children[pane];
  4968. ps = state.stateData[pane];
  4969. if ($.isPlainObject(pC) && !$.isEmptyObject(pC)) {
  4970. // ensure a key exists for this 'pane', eg: branch = data.center
  4971. branch = data[pane] || (data[pane] = {});
  4972. if (!branch.children) branch.children = {};
  4973. $.each(pC, function (key, child) {
  4974. // ONLY read state from an initialize layout
  4975. if (child.state.initialized)
  4976. branch.children[key] = $.layout.state.readState(child);
  4977. // if we have PREVIOUS (onLoad) state for this child-layout, KEEP IT!
  4978. else if (ps && ps.children && ps.children[key]) {
  4979. branch.children[key] = $.extend(true, {}, ps.children[key]);
  4980. }
  4981. });
  4982. }
  4983. });
  4984. }
  4985. return data;
  4986. }
  4987. /**
  4988. * Stringify a JSON hash so can save in a cookie or db-field
  4989. */
  4990. , encodeJSON: function (json) {
  4991. var local = window.JSON || {};
  4992. return (local.stringify || stringify)(json);
  4993. function stringify(h) {
  4994. var D = [], i = 0, k, v, t // k = key, v = value
  4995. , a = $.isArray(h)
  4996. ;
  4997. for (k in h) {
  4998. v = h[k];
  4999. t = typeof v;
  5000. if (t == 'string') // STRING - add quotes
  5001. v = '"' + v + '"';
  5002. else if (t == 'object') // SUB-KEY - recurse into it
  5003. v = parse(v);
  5004. D[i++] = (!a ? '"' + k + '":' : '') + v;
  5005. }
  5006. return (a ? '[' : '{') + D.join(',') + (a ? ']' : '}');
  5007. };
  5008. }
  5009. /**
  5010. * Convert stringified JSON back to a hash object
  5011. * @see $.parseJSON(), adding in jQuery 1.4.1
  5012. */
  5013. , decodeJSON: function (str) {
  5014. try { return $.parseJSON ? $.parseJSON(str) : window["eval"]("(" + str + ")") || {}; }
  5015. catch (e) { return {}; }
  5016. }
  5017. , _create: function (inst) {
  5018. var s = $.layout.state
  5019. , o = inst.options
  5020. , sm = o.stateManagement
  5021. ;
  5022. // ADD State-Management plugin methods to inst
  5023. $.extend(inst, {
  5024. // readCookie - update options from cookie - returns hash of cookie data
  5025. readCookie: function () { return s.readCookie(inst); }
  5026. // deleteCookie
  5027. , deleteCookie: function () { s.deleteCookie(inst); }
  5028. // saveCookie - optionally pass keys-list and cookie-options (hash)
  5029. , saveCookie: function (keys, cookieOpts) { return s.saveCookie(inst, keys, cookieOpts); }
  5030. // loadCookie - readCookie and use to loadState() - returns hash of cookie data
  5031. , loadCookie: function () { return s.loadCookie(inst); }
  5032. // loadState - pass a hash of state to use to update options
  5033. , loadState: function (stateData, opts) { s.loadState(inst, stateData, opts); }
  5034. // readState - returns hash of current layout-state
  5035. , readState: function (keys) { return s.readState(inst, keys); }
  5036. // add JSON utility methods too...
  5037. , encodeJSON: s.encodeJSON
  5038. , decodeJSON: s.decodeJSON
  5039. });
  5040. // init state.stateData key, even if plugin is initially disabled
  5041. inst.state.stateData = {};
  5042. // autoLoad MUST BE one of: data-array, data-hash, callback-function, or TRUE
  5043. if (!sm.autoLoad) return;
  5044. // When state-data exists in the autoLoad key USE IT,
  5045. // even if stateManagement.enabled == false
  5046. if ($.isPlainObject(sm.autoLoad)) {
  5047. if (!$.isEmptyObject(sm.autoLoad)) {
  5048. inst.loadState(sm.autoLoad);
  5049. }
  5050. }
  5051. else if (sm.enabled) {
  5052. // update the options from cookie or callback
  5053. // if options is a function, call it to get stateData
  5054. if ($.isFunction(sm.autoLoad)) {
  5055. var d = {};
  5056. try {
  5057. d = sm.autoLoad(inst, inst.state, inst.options, inst.options.name || ''); // try to get data from fn
  5058. } catch (e) { }
  5059. if (d && $.isPlainObject(d) && !$.isEmptyObject(d))
  5060. inst.loadState(d);
  5061. }
  5062. else // any other truthy value will trigger loadCookie
  5063. inst.loadCookie();
  5064. }
  5065. }
  5066. , _unload: function (inst) {
  5067. var sm = inst.options.stateManagement;
  5068. if (sm.enabled && sm.autoSave) {
  5069. // if options is a function, call it to save the stateData
  5070. if ($.isFunction(sm.autoSave)) {
  5071. try {
  5072. sm.autoSave(inst, inst.state, inst.options, inst.options.name || ''); // try to get data from fn
  5073. } catch (e) { }
  5074. }
  5075. else // any truthy value will trigger saveCookie
  5076. inst.saveCookie();
  5077. }
  5078. }
  5079. };
  5080. // add state initialization method to Layout's onCreate array of functions
  5081. $.layout.onCreate.push($.layout.state._create);
  5082. $.layout.onUnload.push($.layout.state._unload);
  5083. })(jQuery);
  5084. /**
  5085. * @preserve jquery.layout.buttons 1.0
  5086. * $Date: 2011-07-16 08:00:00 (Sat, 16 July 2011) $
  5087. *
  5088. * Copyright (c) 2011
  5089. * Kevin Dalman (http://allpro.net)
  5090. *
  5091. * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
  5092. * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
  5093. *
  5094. * @dependancies: UI Layout 1.3.0.rc30.1 or higher
  5095. *
  5096. * @support: http://groups.google.com/group/jquery-ui-layout
  5097. *
  5098. * Docs: [ to come ]
  5099. * Tips: [ to come ]
  5100. */
  5101. ; (function ($) {
  5102. if (!$.layout) return;
  5103. // tell Layout that the state plugin is available
  5104. $.layout.plugins.buttons = true;
  5105. // Add State-Management options to layout.defaults
  5106. $.layout.defaults.autoBindCustomButtons = false;
  5107. // Set stateManagement as a layout-option, NOT a pane-option
  5108. $.layout.optionsMap.layout.push("autoBindCustomButtons");
  5109. /*
  5110. * Button methods
  5111. */
  5112. $.layout.buttons = {
  5113. // set data used by multiple methods below
  5114. config: {
  5115. borderPanes: "north,south,west,east"
  5116. }
  5117. /**
  5118. * Searches for .ui-layout-button-xxx elements and auto-binds them as layout-buttons
  5119. *
  5120. * @see _create()
  5121. */
  5122. , init: function (inst) {
  5123. var pre = "ui-layout-button-"
  5124. , layout = inst.options.name || ""
  5125. , name;
  5126. $.each("toggle,open,close,pin,toggle-slide,open-slide".split(","), function (i, action) {
  5127. $.each($.layout.buttons.config.borderPanes.split(","), function (ii, pane) {
  5128. $("." + pre + action + "-" + pane).each(function () {
  5129. // if button was previously 'bound', data.layoutName was set, but is blank if layout has no 'name'
  5130. name = $(this).data("layoutName") || $(this).attr("layoutName");
  5131. if (name == undefined || name === layout)
  5132. inst.bindButton(this, action, pane);
  5133. });
  5134. });
  5135. });
  5136. }
  5137. /**
  5138. * Helper function to validate params received by addButton utilities
  5139. *
  5140. * Two classes are added to the element, based on the buttonClass...
  5141. * The type of button is appended to create the 2nd className:
  5142. * - ui-layout-button-pin
  5143. * - ui-layout-pane-button-toggle
  5144. * - ui-layout-pane-button-open
  5145. * - ui-layout-pane-button-close
  5146. *
  5147. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  5148. * @param {string} pane Name of the pane the button is for: 'north', 'south', etc.
  5149. * @return {Array.<Object>} If both params valid, the element matching 'selector' in a jQuery wrapper - otherwise returns null
  5150. */
  5151. , get: function (inst, selector, pane, action) {
  5152. var $E = $(selector)
  5153. , o = inst.options
  5154. //, err = o.showErrorMessages
  5155. ;
  5156. if ($E.length && $.layout.buttons.config.borderPanes.indexOf(pane) >= 0) {
  5157. var btn = o[pane].buttonClass + "-" + action;
  5158. $E.addClass(btn + " " + btn + "-" + pane)
  5159. .data("layoutName", o.name); // add layout identifier - even if blank!
  5160. }
  5161. return $E;
  5162. }
  5163. /**
  5164. * NEW syntax for binding layout-buttons - will eventually replace addToggle, addOpen, etc.
  5165. *
  5166. * @param {(string|!Object)} sel jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  5167. * @param {string} action
  5168. * @param {string} pane
  5169. */
  5170. , bind: function (inst, sel, action, pane) {
  5171. var _ = $.layout.buttons;
  5172. switch (action.toLowerCase()) {
  5173. case "toggle": _.addToggle(inst, sel, pane); break;
  5174. case "open": _.addOpen(inst, sel, pane); break;
  5175. case "close": _.addClose(inst, sel, pane); break;
  5176. case "pin": _.addPin(inst, sel, pane); break;
  5177. case "toggle-slide": _.addToggle(inst, sel, pane, true); break;
  5178. case "open-slide": _.addOpen(inst, sel, pane, true); break;
  5179. }
  5180. return inst;
  5181. }
  5182. /**
  5183. * Add a custom Toggler button for a pane
  5184. *
  5185. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  5186. * @param {string} pane Name of the pane the button is for: 'north', 'south', etc.
  5187. * @param {boolean=} slide true = slide-open, false = pin-open
  5188. */
  5189. , addToggle: function (inst, selector, pane, slide) {
  5190. $.layout.buttons.get(inst, selector, pane, "toggle")
  5191. .click(function (evt) {
  5192. inst.toggle(pane, !!slide);
  5193. evt.stopPropagation();
  5194. });
  5195. return inst;
  5196. }
  5197. /**
  5198. * Add a custom Open button for a pane
  5199. *
  5200. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  5201. * @param {string} pane Name of the pane the button is for: 'north', 'south', etc.
  5202. * @param {boolean=} slide true = slide-open, false = pin-open
  5203. */
  5204. , addOpen: function (inst, selector, pane, slide) {
  5205. $.layout.buttons.get(inst, selector, pane, "open")
  5206. .attr("title", inst.options[pane].tips.Open)
  5207. .click(function (evt) {
  5208. inst.open(pane, !!slide);
  5209. evt.stopPropagation();
  5210. });
  5211. return inst;
  5212. }
  5213. /**
  5214. * Add a custom Close button for a pane
  5215. *
  5216. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  5217. * @param {string} pane Name of the pane the button is for: 'north', 'south', etc.
  5218. */
  5219. , addClose: function (inst, selector, pane) {
  5220. $.layout.buttons.get(inst, selector, pane, "close")
  5221. .attr("title", inst.options[pane].tips.Close)
  5222. .click(function (evt) {
  5223. inst.close(pane);
  5224. evt.stopPropagation();
  5225. });
  5226. return inst;
  5227. }
  5228. /**
  5229. * Add a custom Pin button for a pane
  5230. *
  5231. * Four classes are added to the element, based on the paneClass for the associated pane...
  5232. * Assuming the default paneClass and the pin is 'up', these classes are added for a west-pane pin:
  5233. * - ui-layout-pane-pin
  5234. * - ui-layout-pane-west-pin
  5235. * - ui-layout-pane-pin-up
  5236. * - ui-layout-pane-west-pin-up
  5237. *
  5238. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  5239. * @param {string} pane Name of the pane the pin is for: 'north', 'south', etc.
  5240. */
  5241. , addPin: function (inst, selector, pane) {
  5242. var $E = $.layout.buttons.get(inst, selector, pane, "pin");
  5243. if ($E.length) {
  5244. var s = inst.state[pane];
  5245. $E.click(function (evt) {
  5246. $.layout.buttons.setPinState(inst, $(this), pane, (s.isSliding || s.isClosed));
  5247. if (s.isSliding || s.isClosed) inst.open(pane); // change from sliding to open
  5248. else inst.close(pane); // slide-closed
  5249. evt.stopPropagation();
  5250. });
  5251. // add up/down pin attributes and classes
  5252. $.layout.buttons.setPinState(inst, $E, pane, (!s.isClosed && !s.isSliding));
  5253. // add this pin to the pane data so we can 'sync it' automatically
  5254. // PANE.pins key is an array so we can store multiple pins for each pane
  5255. s.pins.push(selector); // just save the selector string
  5256. }
  5257. return inst;
  5258. }
  5259. /**
  5260. * Change the class of the pin button to make it look 'up' or 'down'
  5261. *
  5262. * @see addPin(), syncPins()
  5263. * @param {Array.<Object>} $Pin The pin-span element in a jQuery wrapper
  5264. * @param {string} pane These are the params returned to callbacks by layout()
  5265. * @param {boolean} doPin true = set the pin 'down', false = set it 'up'
  5266. */
  5267. , setPinState: function (inst, $Pin, pane, doPin) {
  5268. var updown = $Pin.attr("pin");
  5269. if (updown && doPin === (updown == "down")) return; // already in correct state
  5270. var
  5271. po = inst.options[pane]
  5272. , lang = po.tips
  5273. , pin = po.buttonClass + "-pin"
  5274. , side = pin + "-" + pane
  5275. , UP = pin + "-up " + side + "-up"
  5276. , DN = pin + "-down " + side + "-down"
  5277. ;
  5278. $Pin
  5279. .attr("pin", doPin ? "down" : "up") // logic
  5280. .attr("title", doPin ? lang.Unpin : lang.Pin)
  5281. .removeClass(doPin ? UP : DN)
  5282. .addClass(doPin ? DN : UP)
  5283. ;
  5284. }
  5285. /**
  5286. * INTERNAL function to sync 'pin buttons' when pane is opened or closed
  5287. * Unpinned means the pane is 'sliding' - ie, over-top of the adjacent panes
  5288. *
  5289. * @see open(), close()
  5290. * @param {string} pane These are the params returned to callbacks by layout()
  5291. * @param {boolean} doPin True means set the pin 'down', False means 'up'
  5292. */
  5293. , syncPinBtns: function (inst, pane, doPin) {
  5294. // REAL METHOD IS _INSIDE_ LAYOUT - THIS IS HERE JUST FOR REFERENCE
  5295. $.each(state[pane].pins, function (i, selector) {
  5296. $.layout.buttons.setPinState(inst, $(selector), pane, doPin);
  5297. });
  5298. }
  5299. , _load: function (inst) {
  5300. // ADD Button methods to Layout Instance
  5301. $.extend(inst, {
  5302. bindButton: function (selector, action, pane) { return $.layout.buttons.bind(inst, selector, action, pane); }
  5303. // DEPRECATED METHODS...
  5304. , addToggleBtn: function (selector, pane, slide) { return $.layout.buttons.addToggle(inst, selector, pane, slide); }
  5305. , addOpenBtn: function (selector, pane, slide) { return $.layout.buttons.addOpen(inst, selector, pane, slide); }
  5306. , addCloseBtn: function (selector, pane) { return $.layout.buttons.addClose(inst, selector, pane); }
  5307. , addPinBtn: function (selector, pane) { return $.layout.buttons.addPin(inst, selector, pane); }
  5308. });
  5309. // init state array to hold pin-buttons
  5310. for (var i = 0; i < 4; i++) {
  5311. var pane = $.layout.buttons.config.borderPanes[i];
  5312. inst.state[pane].pins = [];
  5313. }
  5314. // auto-init buttons onLoad if option is enabled
  5315. if (inst.options.autoBindCustomButtons)
  5316. $.layout.buttons.init(inst);
  5317. }
  5318. , _unload: function (inst) {
  5319. // TODO: unbind all buttons???
  5320. }
  5321. };
  5322. // add initialization method to Layout's onLoad array of functions
  5323. $.layout.onLoad.push($.layout.buttons._load);
  5324. //$.layout.onUnload.push( $.layout.buttons._unload );
  5325. })(jQuery);
  5326. /**
  5327. * jquery.layout.browserZoom 1.0
  5328. * $Date: 2011-12-29 08:00:00 (Thu, 29 Dec 2011) $
  5329. *
  5330. * Copyright (c) 2012
  5331. * Kevin Dalman (http://allpro.net)
  5332. *
  5333. * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
  5334. * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
  5335. *
  5336. * @requires: UI Layout 1.3.0.rc30.1 or higher
  5337. *
  5338. * @see: http://groups.google.com/group/jquery-ui-layout
  5339. *
  5340. * TODO: Extend logic to handle other problematic zooming in browsers
  5341. * TODO: Add hotkey/mousewheel bindings to _instantly_ respond to these zoom event
  5342. */
  5343. (function ($) {
  5344. // tell Layout that the plugin is available
  5345. $.layout.plugins.browserZoom = true;
  5346. $.layout.defaults.browserZoomCheckInterval = 1000;
  5347. $.layout.optionsMap.layout.push("browserZoomCheckInterval");
  5348. /*
  5349. * browserZoom methods
  5350. */
  5351. $.layout.browserZoom = {
  5352. _init: function (inst) {
  5353. // abort if browser does not need this check
  5354. if ($.layout.browserZoom.ratio() !== false)
  5355. $.layout.browserZoom._setTimer(inst);
  5356. }
  5357. , _setTimer: function (inst) {
  5358. // abort if layout destroyed or browser does not need this check
  5359. if (inst.destroyed) return;
  5360. var o = inst.options
  5361. , s = inst.state
  5362. // don't need check if inst has parentLayout, but check occassionally in case parent destroyed!
  5363. // MINIMUM 100ms interval, for performance
  5364. , ms = inst.hasParentLayout ? 5000 : Math.max(o.browserZoomCheckInterval, 100)
  5365. ;
  5366. // set the timer
  5367. setTimeout(function () {
  5368. if (inst.destroyed || !o.resizeWithWindow) return;
  5369. var d = $.layout.browserZoom.ratio();
  5370. if (d !== s.browserZoom) {
  5371. s.browserZoom = d;
  5372. inst.resizeAll();
  5373. }
  5374. // set a NEW timeout
  5375. $.layout.browserZoom._setTimer(inst);
  5376. }
  5377. , ms);
  5378. }
  5379. , ratio: function () {
  5380. var w = window
  5381. , s = screen
  5382. , d = document
  5383. , dE = d.documentElement || d.body
  5384. , b = $.layout.browser
  5385. , v = b.version
  5386. , r, sW, cW
  5387. ;
  5388. // we can ignore all browsers that fire window.resize event onZoom
  5389. if (!b.msie || v > 8)
  5390. return false; // don't need to track zoom
  5391. if (s.deviceXDPI && s.systemXDPI) // syntax compiler hack
  5392. return calc(s.deviceXDPI, s.systemXDPI);
  5393. // everything below is just for future reference!
  5394. if (b.webkit && (r = d.body.getBoundingClientRect))
  5395. return calc((r.left - r.right), d.body.offsetWidth);
  5396. if (b.webkit && (sW = w.outerWidth))
  5397. return calc(sW, w.innerWidth);
  5398. if ((sW = s.width) && (cW = dE.clientWidth))
  5399. return calc(sW, cW);
  5400. return false; // no match, so cannot - or don't need to - track zoom
  5401. function calc(x, y) { return (parseInt(x, 10) / parseInt(y, 10) * 100).toFixed(); }
  5402. }
  5403. };
  5404. // add initialization method to Layout's onLoad array of functions
  5405. $.layout.onReady.push($.layout.browserZoom._init);
  5406. })(jQuery);
  5407. /**
  5408. * UI Layout Plugin: Slide-Offscreen Animation
  5409. *
  5410. * Prevent panes from being 'hidden' so that an iframes/objects
  5411. * does not reload/refresh when pane 'opens' again.
  5412. * This plug-in adds a new animation called "slideOffscreen".
  5413. * It is identical to the normal "slide" effect, but avoids hiding the element
  5414. *
  5415. * Requires Layout 1.3.0.RC30.1 or later for Close offscreen
  5416. * Requires Layout 1.3.0.RC30.5 or later for Hide, initClosed & initHidden offscreen
  5417. *
  5418. * Version: 1.1 - 2012-11-18
  5419. * Author: Kevin Dalman (kevin@jquery-dev.com)
  5420. * @preserve jquery.layout.slideOffscreen-1.1.js
  5421. */
  5422. ; (function ($) {
  5423. // Add a new "slideOffscreen" effect
  5424. if ($.effects) {
  5425. // add an option so initClosed and initHidden will work
  5426. $.layout.defaults.panes.useOffscreenClose = false; // user must enable when needed
  5427. /* set the new animation as the default for all panes
  5428. $.layout.defaults.panes.fxName = "slideOffscreen";
  5429. */
  5430. if ($.layout.plugins)
  5431. $.layout.plugins.effects.slideOffscreen = true;
  5432. // dupe 'slide' effect defaults as new effect defaults
  5433. $.layout.effects.slideOffscreen = $.extend(true, {}, $.layout.effects.slide);
  5434. // add new effect to jQuery UI
  5435. $.effects.slideOffscreen = function (o) {
  5436. return this.queue(function () {
  5437. var fx = $.effects
  5438. , opt = o.options
  5439. , $el = $(this)
  5440. , pane = $el.data('layoutEdge')
  5441. , state = $el.data('parentLayout').state
  5442. , dist = state[pane].size
  5443. , s = this.style
  5444. , props = ['top', 'bottom', 'left', 'right']
  5445. // Set options
  5446. , mode = fx.setMode($el, opt.mode || 'show') // Set Mode
  5447. , show = (mode == 'show')
  5448. , dir = opt.direction || 'left' // Default Direction
  5449. , ref = (dir == 'up' || dir == 'down') ? 'top' : 'left'
  5450. , pos = (dir == 'up' || dir == 'left')
  5451. , offscrn = $.layout.config.offscreenCSS || {}
  5452. , keyLR = $.layout.config.offscreenReset
  5453. , keyTB = 'offscreenResetTop' // only used internally
  5454. , animation = {}
  5455. ;
  5456. // Animation settings
  5457. animation[ref] = (show ? (pos ? '+=' : '-=') : (pos ? '-=' : '+=')) + dist;
  5458. if (show) { // show() animation, so save top/bottom but retain left/right set when 'hidden'
  5459. $el.data(keyTB, { top: s.top, bottom: s.bottom });
  5460. // set the top or left offset in preparation for animation
  5461. // Note: ALL animations work by shifting the top or left edges
  5462. if (pos) { // top (north) or left (west)
  5463. $el.css(ref, isNaN(dist) ? "-" + dist : -dist); // Shift outside the left/top edge
  5464. }
  5465. else { // bottom (south) or right (east) - shift all the way across container
  5466. if (dir === 'right')
  5467. $el.css({ left: state.container.layoutWidth, right: 'auto' });
  5468. else // dir === bottom
  5469. $el.css({ top: state.container.layoutHeight, bottom: 'auto' });
  5470. }
  5471. // restore the left/right setting if is a top/bottom animation
  5472. if (ref === 'top')
  5473. $el.css($el.data(keyLR) || {});
  5474. }
  5475. else { // hide() animation, so save ALL CSS
  5476. $el.data(keyTB, { top: s.top, bottom: s.bottom });
  5477. $el.data(keyLR, { left: s.left, right: s.right });
  5478. }
  5479. // Animate
  5480. $el.show().animate(animation, {
  5481. queue: false, duration: o.duration, easing: opt.easing, complete: function () {
  5482. // Restore top/bottom
  5483. if ($el.data(keyTB))
  5484. $el.css($el.data(keyTB)).removeData(keyTB);
  5485. if (show) // Restore left/right too
  5486. $el.css($el.data(keyLR) || {}).removeData(keyLR);
  5487. else // Move the pane off-screen (left: -99999, right: 'auto')
  5488. $el.css(offscrn);
  5489. if (o.callback) o.callback.apply(this, arguments); // Callback
  5490. $el.dequeue();
  5491. }
  5492. });
  5493. });
  5494. };
  5495. }
  5496. })(jQuery);