Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

4227 linhas
138 KiB

  1. /**
  2. * @preserve jquery.layout 1.3.0 - Release Candidate 29.12
  3. * $Date: 2010-11-12 08:00:00 (Thu, 18 Nov 2010) $
  4. * $Rev: 302912 $
  5. *
  6. * Copyright (c) 2010
  7. * Fabrizio Balliano (http://www.fabrizioballiano.net)
  8. * Kevin Dalman (http://allpro.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. * Docs: http://layout.jquery-dev.net/documentation.html
  14. * Tips: http://layout.jquery-dev.net/tips.html
  15. * Help: http://groups.google.com/group/jquery-ui-layout
  16. */
  17. // NOTE: For best readability, view with a fixed-width font and tabs equal to 4-chars
  18. ;(function ($) {
  19. var $b = $.browser;
  20. /*
  21. * GENERIC $.layout METHODS - used by all layouts
  22. */
  23. $.layout = {
  24. // can update code here if $.browser is phased out
  25. browser: {
  26. mozilla: !!$b.mozilla
  27. , webkit: !!$b.webkit || !!$b.safari // webkit = jQ 1.4
  28. , msie: !!$b.msie
  29. , isIE6: !!$b.msie && $b.version == 6
  30. , boxModel: false // page must load first, so will be updated set by _create
  31. //, version: $b.version - not used
  32. }
  33. /*
  34. * USER UTILITIES
  35. */
  36. // calculate and return the scrollbar width, as an integer
  37. , scrollbarWidth: function () { return window.scrollbarWidth || $.layout.getScrollbarSize('width'); }
  38. , scrollbarHeight: function () { return window.scrollbarHeight || $.layout.getScrollbarSize('height'); }
  39. , getScrollbarSize: function (dim) {
  40. var $c = $('<div style="position: absolute; top: -10000px; left: -10000px; width: 100px; height: 100px; overflow: scroll;"></div>').appendTo("body");
  41. var d = { width: $c.width() - $c[0].clientWidth, height: $c.height() - $c[0].clientHeight };
  42. $c.remove();
  43. window.scrollbarWidth = d.width;
  44. window.scrollbarHeight = d.height;
  45. return dim.match(/^(width|height)$/i) ? d[dim] : d;
  46. }
  47. /**
  48. * Returns hash container 'display' and 'visibility'
  49. *
  50. * @see $.swap() - swaps CSS, runs callback, resets CSS
  51. */
  52. , showInvisibly: function ($E, force) {
  53. if (!$E) return {};
  54. if (!$E.jquery) $E = $($E);
  55. var CSS = {
  56. display: $E.css('display')
  57. , visibility: $E.css('visibility')
  58. };
  59. if (force || CSS.display == "none") { // only if not *already hidden*
  60. $E.css({ display: "block", visibility: "hidden" }); // show element 'invisibly' so can be measured
  61. return CSS;
  62. }
  63. else return {};
  64. }
  65. /**
  66. * Returns data for setting size of an element (container or a pane).
  67. *
  68. * @see _create(), onWindowResize() for container, plus others for pane
  69. * @return JSON Returns a hash of all dimensions: top, bottom, left, right, outerWidth, innerHeight, etc
  70. */
  71. , getElemDims: function ($E) {
  72. var
  73. d = {} // dimensions hash
  74. , x = d.css = {} // CSS hash
  75. , i = {} // TEMP insets
  76. , b, p // TEMP border, padding
  77. , off = $E.offset()
  78. ;
  79. d.offsetLeft = off.left;
  80. d.offsetTop = off.top;
  81. $.each("Left,Right,Top,Bottom".split(","), function (idx, e) { // e = edge
  82. b = x["border" + e] = $.layout.borderWidth($E, e);
  83. p = x["padding"+ e] = $.layout.cssNum($E, "padding"+e);
  84. i[e] = b + p; // total offset of content from outer side
  85. d["inset"+ e] = p;
  86. /* WRONG ???
  87. // if BOX MODEL, then 'position' = PADDING (ignore borderWidth)
  88. if ($E == $Container)
  89. d["inset"+ e] = (browser.boxModel ? p : 0);
  90. */
  91. });
  92. d.offsetWidth = $E.innerWidth();
  93. d.offsetHeight = $E.innerHeight();
  94. d.outerWidth = $E.outerWidth();
  95. d.outerHeight = $E.outerHeight();
  96. d.innerWidth = d.outerWidth - i.Left - i.Right;
  97. d.innerHeight = d.outerHeight - i.Top - i.Bottom;
  98. // TESTING
  99. x.width = $E.width();
  100. x.height = $E.height();
  101. return d;
  102. }
  103. , getElemCSS: function ($E, list) {
  104. var
  105. CSS = {}
  106. , style = $E[0].style
  107. , props = list.split(",")
  108. , sides = "Top,Bottom,Left,Right".split(",")
  109. , attrs = "Color,Style,Width".split(",")
  110. , p, s, a, i, j, k
  111. ;
  112. for (i=0; i < props.length; i++) {
  113. p = props[i];
  114. if (p.match(/(border|padding|margin)$/))
  115. for (j=0; j < 4; j++) {
  116. s = sides[j];
  117. if (p == "border")
  118. for (k=0; k < 3; k++) {
  119. a = attrs[k];
  120. CSS[p+s+a] = style[p+s+a];
  121. }
  122. else
  123. CSS[p+s] = style[p+s];
  124. }
  125. else
  126. CSS[p] = style[p];
  127. };
  128. return CSS
  129. }
  130. /**
  131. * Contains logic to check boxModel & browser, and return the correct width/height for the current browser/doctype
  132. *
  133. * @see initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
  134. * @param {Array.<Object>} $E Must pass a jQuery object - first element is processed
  135. * @param {number=} outerWidth/outerHeight (optional) Can pass a width, allowing calculations BEFORE element is resized
  136. * @return {number} Returns the innerWidth/Height of the elem by subtracting padding and borders
  137. */
  138. , cssWidth: function ($E, outerWidth) {
  139. var
  140. b = $.layout.borderWidth
  141. , n = $.layout.cssNum
  142. ;
  143. // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
  144. if (outerWidth <= 0) return 0;
  145. if (!$.layout.browser.boxModel) return outerWidth;
  146. // strip border and padding from outerWidth to get CSS Width
  147. var W = outerWidth
  148. - b($E, "Left")
  149. - b($E, "Right")
  150. - n($E, "paddingLeft")
  151. - n($E, "paddingRight")
  152. ;
  153. return W > 0 ? W : 0;
  154. }
  155. , cssHeight: function ($E, outerHeight) {
  156. var
  157. b = $.layout.borderWidth
  158. , n = $.layout.cssNum
  159. ;
  160. // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
  161. if (outerHeight <= 0) return 0;
  162. if (!$.layout.browser.boxModel) return outerHeight;
  163. // strip border and padding from outerHeight to get CSS Height
  164. var H = outerHeight
  165. - b($E, "Top")
  166. - b($E, "Bottom")
  167. - n($E, "paddingTop")
  168. - n($E, "paddingBottom")
  169. ;
  170. return H > 0 ? H : 0;
  171. }
  172. /**
  173. * Returns the 'current CSS numeric value' for an element - returns 0 if property does not exist
  174. *
  175. * @see Called by many methods
  176. * @param {Array.<Object>} $E Must pass a jQuery object - first element is processed
  177. * @param {string} prop The name of the CSS property, eg: top, width, etc.
  178. * @return {*} Usually is used to get an integer value for position (top, left) or size (height, width)
  179. */
  180. , cssNum: function ($E, prop) {
  181. if (!$E.jquery) $E = $($E);
  182. var CSS = $.layout.showInvisibly($E);
  183. var val = parseInt($.curCSS($E[0], prop, true), 10) || 0;
  184. $E.css( CSS ); // RESET
  185. return val;
  186. }
  187. , borderWidth: function (el, side) {
  188. if (el.jquery) el = el[0];
  189. var b = "border"+ side.substr(0,1).toUpperCase() + side.substr(1); // left => Left
  190. return $.curCSS(el, b+"Style", true) == "none" ? 0 : (parseInt($.curCSS(el, b+"Width", true), 10) || 0);
  191. }
  192. /**
  193. * SUBROUTINE for preventPrematureSlideClose option
  194. *
  195. * @param {Object} evt
  196. * @param {Object=} el
  197. */
  198. , isMouseOverElem: function (evt, el) {
  199. var
  200. $E = $(el || this)
  201. , d = $E.offset()
  202. , T = d.top
  203. , L = d.left
  204. , R = L + $E.outerWidth()
  205. , B = T + $E.outerHeight()
  206. , x = evt.pageX
  207. , y = evt.pageY
  208. ;
  209. // if X & Y are < 0, probably means is over an open SELECT
  210. return ($.layout.browser.msie && x < 0 && y < 0) || ((x >= L && x <= R) && (y >= T && y <= B));
  211. }
  212. };
  213. $.fn.layout = function (opts) {
  214. /*
  215. * ###########################
  216. * WIDGET CONFIG & OPTIONS
  217. * ###########################
  218. */
  219. // LANGUAGE CUSTOMIZATION - will be *externally customizable* in next version
  220. var lang = {
  221. Pane: "Pane"
  222. , Open: "Open" // eg: "Open Pane"
  223. , Close: "Close"
  224. , Resize: "Resize"
  225. , Slide: "Slide Open"
  226. , Pin: "Pin"
  227. , Unpin: "Un-Pin"
  228. , selector: "selector"
  229. , msgNoRoom: "Not enough room to show this pane."
  230. , errContainerMissing: "UI Layout Initialization Error\n\nThe specified layout-container does not exist."
  231. , errCenterPaneMissing: "UI Layout Initialization Error\n\nThe center-pane element does not exist.\n\nThe center-pane is a required element."
  232. , errContainerHeight: "UI Layout Initialization Warning\n\nThe layout-container \"CONTAINER\" has no height.\n\nTherefore the layout is 0-height and hence 'invisible'!"
  233. , errButton: "Error Adding Button \n\nInvalid "
  234. };
  235. // DEFAULT OPTIONS - CHANGE IF DESIRED
  236. var options = {
  237. name: "" // Not required, but useful for buttons and used for the state-cookie
  238. , scrollToBookmarkOnLoad: true // after creating a layout, scroll to bookmark in URL (.../page.htm#myBookmark)
  239. , resizeWithWindow: true // bind thisLayout.resizeAll() to the window.resize event
  240. , resizeWithWindowDelay: 200 // delay calling resizeAll because makes window resizing very jerky
  241. , resizeWithWindowMaxDelay: 0 // 0 = none - force resize every XX ms while window is being resized
  242. , onresizeall_start: null // CALLBACK when resizeAll() STARTS - NOT pane-specific
  243. , onresizeall_end: null // CALLBACK when resizeAll() ENDS - NOT pane-specific
  244. , onload: null // CALLBACK when Layout inits - after options initialized, but before elements
  245. , onunload: null // CALLBACK when Layout is destroyed OR onWindowUnload
  246. , autoBindCustomButtons: false // search for buttons with ui-layout-button class and auto-bind them
  247. , zIndex: null // the PANE zIndex - resizers and masks will be +1
  248. // PANE SETTINGS
  249. , defaults: { // default options for 'all panes' - will be overridden by 'per-pane settings'
  250. applyDemoStyles: false // NOTE: renamed from applyDefaultStyles for clarity
  251. , closable: true // pane can open & close
  252. , resizable: true // when open, pane can be resized
  253. , slidable: true // when closed, pane can 'slide open' over other panes - closes on mouse-out
  254. , initClosed: false // true = init pane as 'closed'
  255. , initHidden: false // true = init pane as 'hidden' - no resizer-bar/spacing
  256. // SELECTORS
  257. //, paneSelector: "" // MUST be pane-specific - jQuery selector for pane
  258. , contentSelector: ".ui-layout-content" // INNER div/element to auto-size so only it scrolls, not the entire pane!
  259. , contentIgnoreSelector: ".ui-layout-ignore" // element(s) to 'ignore' when measuring 'content'
  260. , findNestedContent: false // true = $P.find(contentSelector), false = $P.children(contentSelector)
  261. // GENERIC ROOT-CLASSES - for auto-generated classNames
  262. , paneClass: "ui-layout-pane" // border-Pane - default: 'ui-layout-pane'
  263. , resizerClass: "ui-layout-resizer" // Resizer Bar - default: 'ui-layout-resizer'
  264. , togglerClass: "ui-layout-toggler" // Toggler Button - default: 'ui-layout-toggler'
  265. , buttonClass: "ui-layout-button" // CUSTOM Buttons - default: 'ui-layout-button-toggle/-open/-close/-pin'
  266. // ELEMENT SIZE & SPACING
  267. //, size: 100 // MUST be pane-specific -initial size of pane
  268. , minSize: 0 // when manually resizing a pane
  269. , maxSize: 0 // ditto, 0 = no limit
  270. , spacing_open: 6 // space between pane and adjacent panes - when pane is 'open'
  271. , spacing_closed: 6 // ditto - when pane is 'closed'
  272. , togglerLength_open: 50 // Length = WIDTH of toggler button on north/south sides - HEIGHT on east/west sides
  273. , togglerLength_closed: 50 // 100% OR -1 means 'full height/width of resizer bar' - 0 means 'hidden'
  274. , togglerAlign_open: "center" // top/left, bottom/right, center, OR...
  275. , togglerAlign_closed: "center" // 1 => nn = offset from top/left, -1 => -nn == offset from bottom/right
  276. , togglerTip_open: lang.Close // Toggler tool-tip (title)
  277. , togglerTip_closed: lang.Open // ditto
  278. , togglerContent_open: "" // text or HTML to put INSIDE the toggler
  279. , togglerContent_closed: "" // ditto
  280. // RESIZING OPTIONS
  281. , resizerDblClickToggle: true //
  282. , autoResize: true // IF size is 'auto' or a percentage, then recalc 'pixel size' whenever the layout resizes
  283. , autoReopen: true // IF a pane was auto-closed due to noRoom, reopen it when there is room? False = leave it closed
  284. , resizerDragOpacity: 1 // option for ui.draggable
  285. //, resizerCursor: "" // MUST be pane-specific - cursor when over resizer-bar
  286. , maskIframesOnResize: true // true = all iframes OR = iframe-selector(s) - adds masking-div during resizing/dragging
  287. , resizeNestedLayout: true // true = trigger nested.resizeAll() when a 'pane' of this layout is the 'container' for another
  288. , resizeWhileDragging: false // true = LIVE Resizing as resizer is dragged
  289. , resizeContentWhileDragging: false // true = re-measure header/footer heights as resizer is dragged
  290. // TIPS & MESSAGES - also see lang object
  291. , noRoomToOpenTip: lang.msgNoRoom
  292. , resizerTip: lang.Resize // Resizer tool-tip (title)
  293. , sliderTip: lang.Slide // resizer-bar triggers 'sliding' when pane is closed
  294. , sliderCursor: "pointer" // cursor when resizer-bar will trigger 'sliding'
  295. , slideTrigger_open: "click" // click, dblclick, mouseenter
  296. , slideTrigger_close: "mouseleave"// click, mouseleave
  297. , hideTogglerOnSlide: false // when pane is slid-open, should the toggler show?
  298. , preventQuickSlideClose: !!($.browser.webkit || $.browser.safari) // Chrome triggers slideClosed as is opening
  299. , preventPrematureSlideClose: false
  300. // HOT-KEYS & MISC
  301. , showOverflowOnHover: false // will bind allowOverflow() utility to pane.onMouseOver
  302. , enableCursorHotkey: true // enabled 'cursor' hotkeys
  303. //, customHotkey: "" // MUST be pane-specific - EITHER a charCode OR a character
  304. , customHotkeyModifier: "SHIFT" // either 'SHIFT', 'CTRL' or 'CTRL+SHIFT' - NOT 'ALT'
  305. // PANE ANIMATION
  306. // NOTE: fxSss_open & fxSss_close options (eg: fxName_open) are auto-generated if not passed
  307. , fxName: "slide" // ('none' or blank), slide, drop, scale
  308. , fxSpeed: null // slow, normal, fast, 200, nnn - if passed, will OVERRIDE fxSettings.duration
  309. , fxSettings: {} // can be passed, eg: { easing: "easeOutBounce", duration: 1500 }
  310. , fxOpacityFix: true // tries to fix opacity in IE to restore anti-aliasing after animation
  311. // CALLBACKS
  312. , triggerEventsOnLoad: false // true = trigger onopen OR onclose callbacks when layout initializes
  313. , triggerEventsWhileDragging: true // true = trigger onresize callback REPEATEDLY if resizeWhileDragging==true
  314. , onshow_start: null // CALLBACK when pane STARTS to Show - BEFORE onopen/onhide_start
  315. , onshow_end: null // CALLBACK when pane ENDS being Shown - AFTER onopen/onhide_end
  316. , onhide_start: null // CALLBACK when pane STARTS to Close - BEFORE onclose_start
  317. , onhide_end: null // CALLBACK when pane ENDS being Closed - AFTER onclose_end
  318. , onopen_start: null // CALLBACK when pane STARTS to Open
  319. , onopen_end: null // CALLBACK when pane ENDS being Opened
  320. , onclose_start: null // CALLBACK when pane STARTS to Close
  321. , onclose_end: null // CALLBACK when pane ENDS being Closed
  322. , onresize_start: null // CALLBACK when pane STARTS being Resized ***FOR ANY REASON***
  323. , onresize_end: null // CALLBACK when pane ENDS being Resized ***FOR ANY REASON***
  324. , onsizecontent_start: null // CALLBACK when sizing of content-element STARTS
  325. , onsizecontent_end: null // CALLBACK when sizing of content-element ENDS
  326. , onswap_start: null // CALLBACK when pane STARTS to Swap
  327. , onswap_end: null // CALLBACK when pane ENDS being Swapped
  328. , ondrag_start: null // CALLBACK when pane STARTS being ***MANUALLY*** Resized
  329. , ondrag_end: null // CALLBACK when pane ENDS being ***MANUALLY*** Resized
  330. }
  331. , north: {
  332. paneSelector: ".ui-layout-north"
  333. , size: "auto" // eg: "auto", "30%", 200
  334. , resizerCursor: "n-resize" // custom = url(myCursor.cur)
  335. , customHotkey: "" // EITHER a charCode OR a character
  336. }
  337. , south: {
  338. paneSelector: ".ui-layout-south"
  339. , size: "auto"
  340. , resizerCursor: "s-resize"
  341. , customHotkey: ""
  342. }
  343. , east: {
  344. paneSelector: ".ui-layout-east"
  345. , size: 200
  346. , resizerCursor: "e-resize"
  347. , customHotkey: ""
  348. }
  349. , west: {
  350. paneSelector: ".ui-layout-west"
  351. , size: 200
  352. , resizerCursor: "w-resize"
  353. , customHotkey: ""
  354. }
  355. , center: {
  356. paneSelector: ".ui-layout-center"
  357. , minWidth: 0
  358. , minHeight: 0
  359. }
  360. // STATE MANAGMENT
  361. , useStateCookie: false // Enable cookie-based state-management - can fine-tune with cookie.autoLoad/autoSave
  362. , cookie: {
  363. name: "" // If not specified, will use Layout.name, else just "Layout"
  364. , autoSave: true // Save a state cookie when page exits?
  365. , autoLoad: true // Load the state cookie when Layout inits?
  366. // Cookie Options
  367. , domain: ""
  368. , path: ""
  369. , expires: "" // 'days' to keep cookie - leave blank for 'session cookie'
  370. , secure: false
  371. // List of options to save in the cookie - must be pane-specific
  372. , keys: "north.size,south.size,east.size,west.size,"+
  373. "north.isClosed,south.isClosed,east.isClosed,west.isClosed,"+
  374. "north.isHidden,south.isHidden,east.isHidden,west.isHidden"
  375. }
  376. };
  377. // PREDEFINED EFFECTS / DEFAULTS
  378. var effects = { // LIST *PREDEFINED EFFECTS* HERE, even if effect has no settings
  379. slide: {
  380. all: { duration: "fast" } // eg: duration: 1000, easing: "easeOutBounce"
  381. , north: { direction: "up" }
  382. , south: { direction: "down" }
  383. , east: { direction: "right"}
  384. , west: { direction: "left" }
  385. }
  386. , drop: {
  387. all: { duration: "slow" } // eg: duration: 1000, easing: "easeOutQuint"
  388. , north: { direction: "up" }
  389. , south: { direction: "down" }
  390. , east: { direction: "right"}
  391. , west: { direction: "left" }
  392. }
  393. , scale: {
  394. all: { duration: "fast" }
  395. }
  396. };
  397. // DYNAMIC DATA - IS READ-ONLY EXTERNALLY!
  398. var state = {
  399. // generate unique ID to use for event.namespace so can unbind only events added by 'this layout'
  400. id: "layout"+ new Date().getTime() // code uses alias: sID
  401. , initialized: false
  402. , container: {} // init all keys
  403. , north: {}
  404. , south: {}
  405. , east: {}
  406. , west: {}
  407. , center: {}
  408. , cookie: {} // State Managment data storage
  409. };
  410. // INTERNAL CONFIG DATA - DO NOT CHANGE THIS!
  411. var _c = {
  412. allPanes: "north,south,west,east,center"
  413. , borderPanes: "north,south,west,east"
  414. , altSide: {
  415. north: "south"
  416. , south: "north"
  417. , east: "west"
  418. , west: "east"
  419. }
  420. // CSS used in multiple places
  421. , hidden: { visibility: "hidden" }
  422. , visible: { visibility: "visible" }
  423. // layout element settings
  424. , zIndex: { // set z-index values here
  425. pane_normal: 1 // normal z-index for panes
  426. , resizer_normal: 2 // normal z-index for resizer-bars
  427. , iframe_mask: 2 // overlay div used to mask pane(s) during resizing
  428. , pane_sliding: 100 // applied to *BOTH* the pane and its resizer when a pane is 'slid open'
  429. , pane_animate: 1000 // applied to the pane when being animated - not applied to the resizer
  430. , resizer_drag: 10000 // applied to the CLONED resizer-bar when being 'dragged'
  431. }
  432. , resizers: {
  433. cssReq: {
  434. position: "absolute"
  435. , padding: 0
  436. , margin: 0
  437. , fontSize: "1px"
  438. , textAlign: "left" // to counter-act "center" alignment!
  439. , overflow: "hidden" // prevent toggler-button from overflowing
  440. // SEE c.zIndex.resizer_normal
  441. }
  442. , cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
  443. background: "#DDD"
  444. , border: "none"
  445. }
  446. }
  447. , togglers: {
  448. cssReq: {
  449. position: "absolute"
  450. , display: "block"
  451. , padding: 0
  452. , margin: 0
  453. , overflow: "hidden"
  454. , textAlign: "center"
  455. , fontSize: "1px"
  456. , cursor: "pointer"
  457. , zIndex: 1
  458. }
  459. , cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
  460. background: "#AAA"
  461. }
  462. }
  463. , content: {
  464. cssReq: {
  465. position: "relative" /* contain floated or positioned elements */
  466. }
  467. , cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
  468. overflow: "auto"
  469. , padding: "10px"
  470. }
  471. , cssDemoPane: { // DEMO CSS - REMOVE scrolling from 'pane' when it has a content-div
  472. overflow: "hidden"
  473. , padding: 0
  474. }
  475. }
  476. , panes: { // defaults for ALL panes - overridden by 'per-pane settings' below
  477. cssReq: {
  478. position: "absolute"
  479. , margin: 0
  480. // SEE c.zIndex.pane_normal
  481. }
  482. , cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
  483. padding: "10px"
  484. , background: "#FFF"
  485. , border: "1px solid #BBB"
  486. , overflow: "auto"
  487. }
  488. }
  489. , north: {
  490. side: "Top"
  491. , sizeType: "Height"
  492. , dir: "horz"
  493. , cssReq: {
  494. top: 0
  495. , bottom: "auto"
  496. , left: 0
  497. , right: 0
  498. , width: "auto"
  499. // height: DYNAMIC
  500. }
  501. , pins: [] // array of 'pin buttons' to be auto-updated on open/close (classNames)
  502. }
  503. , south: {
  504. side: "Bottom"
  505. , sizeType: "Height"
  506. , dir: "horz"
  507. , cssReq: {
  508. top: "auto"
  509. , bottom: 0
  510. , left: 0
  511. , right: 0
  512. , width: "auto"
  513. // height: DYNAMIC
  514. }
  515. , pins: []
  516. }
  517. , east: {
  518. side: "Right"
  519. , sizeType: "Width"
  520. , dir: "vert"
  521. , cssReq: {
  522. left: "auto"
  523. , right: 0
  524. , top: "auto" // DYNAMIC
  525. , bottom: "auto" // DYNAMIC
  526. , height: "auto"
  527. // width: DYNAMIC
  528. }
  529. , pins: []
  530. }
  531. , west: {
  532. side: "Left"
  533. , sizeType: "Width"
  534. , dir: "vert"
  535. , cssReq: {
  536. left: 0
  537. , right: "auto"
  538. , top: "auto" // DYNAMIC
  539. , bottom: "auto" // DYNAMIC
  540. , height: "auto"
  541. // width: DYNAMIC
  542. }
  543. , pins: []
  544. }
  545. , center: {
  546. dir: "center"
  547. , cssReq: {
  548. left: "auto" // DYNAMIC
  549. , right: "auto" // DYNAMIC
  550. , top: "auto" // DYNAMIC
  551. , bottom: "auto" // DYNAMIC
  552. , height: "auto"
  553. , width: "auto"
  554. }
  555. }
  556. };
  557. /*
  558. * ###########################
  559. * INTERNAL HELPER FUNCTIONS
  560. * ###########################
  561. */
  562. /**
  563. * Manages all internal timers
  564. */
  565. var timer = {
  566. data: {}
  567. , set: function (s, fn, ms) { timer.clear(s); timer.data[s] = setTimeout(fn, ms); }
  568. , clear: function (s) { var t=timer.data; if (t[s]) {clearTimeout(t[s]); delete t[s];} }
  569. };
  570. /**
  571. * Returns true if passed param is EITHER a simple string OR a 'string object' - otherwise returns false
  572. */
  573. var isStr = function (o) {
  574. try { return typeof o == "string"
  575. || (typeof o == "object" && o.constructor.toString().match(/string/i) !== null); }
  576. catch (e) { return false; }
  577. };
  578. /**
  579. * Returns a simple string if passed EITHER a simple string OR a 'string object',
  580. * else returns the original object
  581. */
  582. var str = function (o) { // trim converts 'String object' to a simple string
  583. return isStr(o) ? $.trim(o) : o == undefined || o == null ? "" : o;
  584. };
  585. /**
  586. * min / max
  587. *
  588. * Aliases for Math methods to simplify coding
  589. */
  590. var min = function (x,y) { return Math.min(x,y); };
  591. var max = function (x,y) { return Math.max(x,y); };
  592. /**
  593. * Processes the options passed in and transforms them into the format used by layout()
  594. * Missing keys are added, and converts the data if passed in 'flat-format' (no sub-keys)
  595. * In flat-format, pane-specific-settings are prefixed like: north__optName (2-underscores)
  596. * To update effects, options MUST use nested-keys format, with an effects key ???
  597. *
  598. * @see initOptions()
  599. * @param {Object} d Data/options passed by user - may be a single level or nested levels
  600. * @return {Object} Creates a data struture that perfectly matches 'options', ready to be imported
  601. */
  602. var _transformData = function (d) {
  603. var a, json = { cookie:{}, defaults:{fxSettings:{}}, north:{fxSettings:{}}, south:{fxSettings:{}}, east:{fxSettings:{}}, west:{fxSettings:{}}, center:{fxSettings:{}} };
  604. d = d || {};
  605. if (d.effects || d.cookie || d.defaults || d.north || d.south || d.west || d.east || d.center)
  606. json = $.extend( true, json, d ); // already in json format - add to base keys
  607. else
  608. // convert 'flat' to 'nest-keys' format - also handles 'empty' user-options
  609. $.each( d, function (key,val) {
  610. a = key.split("__");
  611. if (!a[1] || json[a[0]]) // check for invalid keys
  612. json[ a[1] ? a[0] : "defaults" ][ a[1] ? a[1] : a[0] ] = val;
  613. });
  614. return json;
  615. };
  616. /**
  617. * Set an INTERNAL callback to avoid simultaneous animation
  618. * Runs only if needed and only if all callbacks are not 'already set'
  619. * Called by open() and close() when isLayoutBusy=true
  620. *
  621. * @param {string} action Either 'open' or 'close'
  622. * @param {string} pane A valid border-pane name, eg 'west'
  623. * @param {boolean=} param Extra param for callback (optional)
  624. */
  625. var _queue = function (action, pane, param) {
  626. var tried = [];
  627. // if isLayoutBusy, then some pane must be 'moving'
  628. $.each(_c.borderPanes.split(","), function (i, p) {
  629. if (_c[p].isMoving) {
  630. bindCallback(p); // TRY to bind a callback
  631. return false; // BREAK
  632. }
  633. });
  634. // if pane does NOT have a callback, then add one, else follow the callback chain...
  635. function bindCallback (p) {
  636. var c = _c[p];
  637. if (!c.doCallback) {
  638. c.doCallback = true;
  639. c.callback = action +","+ pane +","+ (param ? 1 : 0);
  640. }
  641. else { // try to 'chain' this callback
  642. tried.push(p);
  643. var cbPane = c.callback.split(",")[1]; // 2nd param of callback is 'pane'
  644. // ensure callback target NOT 'itself' and NOT 'target pane' and NOT already tried (avoid loop)
  645. if (cbPane != pane && !$.inArray(cbPane, tried) >= 0)
  646. bindCallback(cbPane); // RECURSE
  647. }
  648. }
  649. };
  650. /**
  651. * RUN the INTERNAL callback for this pane - if one exists
  652. *
  653. * @param {string} pane A valid border-pane name, eg 'west'
  654. */
  655. var _dequeue = function (pane) {
  656. var c = _c[pane];
  657. // RESET flow-control flags
  658. _c.isLayoutBusy = false;
  659. delete c.isMoving;
  660. if (!c.doCallback || !c.callback) return;
  661. c.doCallback = false; // RESET logic flag
  662. // EXECUTE the callback
  663. var
  664. cb = c.callback.split(",")
  665. , param = (cb[2] > 0 ? true : false)
  666. ;
  667. if (cb[0] == "open")
  668. open( cb[1], param );
  669. else if (cb[0] == "close")
  670. close( cb[1], param );
  671. if (!c.doCallback) c.callback = null; // RESET - unless callback above enabled it again!
  672. };
  673. /**
  674. * Executes a Callback function after a trigger event, like resize, open or close
  675. *
  676. * @param {?string} pane This is passed only so we can pass the 'pane object' to the callback
  677. * @param {(string|function())} v_fn Accepts a function name, OR a comma-delimited array: [0]=function name, [1]=argument
  678. */
  679. var _execCallback = function (pane, v_fn) {
  680. if (!v_fn) return;
  681. var fn;
  682. try {
  683. if (typeof v_fn == "function")
  684. fn = v_fn;
  685. else if (!isStr(v_fn))
  686. return;
  687. else if (v_fn.match(/,/)) {
  688. // function name cannot contain a comma, so must be a function name AND a 'name' parameter
  689. var args = v_fn.split(",");
  690. fn = eval(args[0]);
  691. if (typeof fn=="function" && args.length > 1)
  692. return fn(args[1]); // pass the argument parsed from 'list'
  693. }
  694. else // just the name of an external function?
  695. fn = eval(v_fn);
  696. if (typeof fn=="function") {
  697. if (pane && $Ps[pane])
  698. // pass data: pane-name, pane-element, pane-state (copy), pane-options, and layout-name
  699. return fn( pane, $Ps[pane], $.extend({},state[pane]), options[pane], options.name );
  700. else // must be a layout/container callback - pass suitable info
  701. return fn( Instance, $.extend({},state), options, options.name );
  702. }
  703. }
  704. catch (ex) {}
  705. };
  706. /**
  707. * Returns hash container 'display' and 'visibility'
  708. *
  709. * @see $.swap() - swaps CSS, runs callback, resets CSS
  710. * @param {!Object} $E
  711. * @param {boolean=} force
  712. */
  713. var _showInvisibly = function ($E, force) {
  714. if (!$E) return {};
  715. if (!$E.jquery) $E = $($E);
  716. var CSS = {
  717. display: $E.css('display')
  718. , visibility: $E.css('visibility')
  719. };
  720. if (force || CSS.display == "none") { // only if not *already hidden*
  721. $E.css({ display: "block", visibility: "hidden" }); // show element 'invisibly' so can be measured
  722. return CSS;
  723. }
  724. else return {};
  725. };
  726. /**
  727. * cure iframe display issues in IE & other browsers
  728. */
  729. var _fixIframe = function (pane) {
  730. if (state.browser.mozilla) return; // skip FireFox - it auto-refreshes iframes onShow
  731. var $P = $Ps[pane];
  732. // if the 'pane' is an iframe, do it
  733. if (state[pane].tagName == "IFRAME")
  734. $P.css(_c.hidden).css(_c.visible);
  735. else // ditto for any iframes INSIDE the pane
  736. $P.find('IFRAME').css(_c.hidden).css(_c.visible);
  737. };
  738. /**
  739. * Returns the 'current CSS numeric value' for a CSS property - 0 if property does not exist
  740. *
  741. * @see Called by many methods
  742. * @param {Array.<Object>} $E Must pass a jQuery object - first element is processed
  743. * @param {string} prop The name of the CSS property, eg: top, width, etc.
  744. * @return {(string|number)} Usually used to get an integer value for position (top, left) or size (height, width)
  745. */
  746. var _cssNum = function ($E, prop) {
  747. if (!$E.jquery) $E = $($E);
  748. var CSS = _showInvisibly($E);
  749. var val = parseInt($.curCSS($E[0], prop, true), 10) || 0;
  750. $E.css( CSS ); // RESET
  751. return val;
  752. };
  753. /**
  754. * @param {!Object} E Can accept a 'pane' (east, west, etc) OR a DOM object OR a jQuery object
  755. * @param {string} side Which border (top, left, etc.) is resized
  756. * @return {number} Returns the borderWidth
  757. */
  758. var _borderWidth = function (E, side) {
  759. if (E.jquery) E = E[0];
  760. var b = "border"+ side.substr(0,1).toUpperCase() + side.substr(1); // left => Left
  761. return $.curCSS(E, b+"Style", true) == "none" ? 0 : (parseInt($.curCSS(E, b+"Width", true), 10) || 0);
  762. };
  763. /**
  764. * cssW / cssH / cssSize / cssMinDims
  765. *
  766. * Contains logic to check boxModel & browser, and return the correct width/height for the current browser/doctype
  767. *
  768. * @see initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
  769. * @param {(string|!Object)} el Can accept a 'pane' (east, west, etc) OR a DOM object OR a jQuery object
  770. * @param {number=} outerWidth (optional) Can pass a width, allowing calculations BEFORE element is resized
  771. * @return {number} Returns the innerWidth of el by subtracting padding and borders
  772. */
  773. var cssW = function (el, outerWidth) {
  774. var
  775. str = isStr(el)
  776. , $E = str ? $Ps[el] : $(el)
  777. ;
  778. if (isNaN(outerWidth)) // not specified
  779. outerWidth = str ? getPaneSize(el) : $E.outerWidth();
  780. // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
  781. if (outerWidth <= 0) return 0;
  782. if (!state.browser.boxModel) return outerWidth;
  783. // strip border and padding from outerWidth to get CSS Width
  784. var W = outerWidth
  785. - _borderWidth($E, "Left")
  786. - _borderWidth($E, "Right")
  787. - _cssNum($E, "paddingLeft")
  788. - _cssNum($E, "paddingRight")
  789. ;
  790. return W > 0 ? W : 0;
  791. };
  792. /**
  793. * @param {(string|!Object)} el Can accept a 'pane' (east, west, etc) OR a DOM object OR a jQuery object
  794. * @param {number=} outerHeight (optional) Can pass a width, allowing calculations BEFORE element is resized
  795. * @return {number} Returns the innerHeight el by subtracting padding and borders
  796. */
  797. var cssH = function (el, outerHeight) {
  798. var
  799. str = isStr(el)
  800. , $E = str ? $Ps[el] : $(el)
  801. ;
  802. if (isNaN(outerHeight)) // not specified
  803. outerHeight = str ? getPaneSize(el) : $E.outerHeight();
  804. // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
  805. if (outerHeight <= 0) return 0;
  806. if (!state.browser.boxModel) return outerHeight;
  807. // strip border and padding from outerHeight to get CSS Height
  808. var H = outerHeight
  809. - _borderWidth($E, "Top")
  810. - _borderWidth($E, "Bottom")
  811. - _cssNum($E, "paddingTop")
  812. - _cssNum($E, "paddingBottom")
  813. ;
  814. return H > 0 ? H : 0;
  815. };
  816. /**
  817. * @param {string} pane Can accept ONLY a 'pane' (east, west, etc)
  818. * @param {number=} outerSize (optional) Can pass a width, allowing calculations BEFORE element is resized
  819. * @return {number} Returns the innerHeight/Width of el by subtracting padding and borders
  820. */
  821. var cssSize = function (pane, outerSize) {
  822. if (_c[pane].dir=="horz") // pane = north or south
  823. return cssH(pane, outerSize);
  824. else // pane = east or west
  825. return cssW(pane, outerSize);
  826. };
  827. var cssMinDims = function (pane) {
  828. // minWidth/Height means CSS width/height = 1px
  829. var
  830. dir = _c[pane].dir
  831. , d = {
  832. minWidth: 1001 - cssW(pane, 1000)
  833. , minHeight: 1001 - cssH(pane, 1000)
  834. }
  835. ;
  836. if (dir == "horz") d.minSize = d.minHeight;
  837. if (dir == "vert") d.minSize = d.minWidth;
  838. return d;
  839. };
  840. // TODO: see if these methods can be made more useful...
  841. // TODO: *maybe* return cssW/H from these so caller can use this info
  842. /**
  843. * @param {(string|!Object)} el
  844. * @param {number=} outerWidth
  845. * @param {boolean=} autoHide
  846. */
  847. var setOuterWidth = function (el, outerWidth, autoHide) {
  848. var $E = el, w;
  849. if (isStr(el)) $E = $Ps[el]; // west
  850. else if (!el.jquery) $E = $(el);
  851. w = cssW($E, outerWidth);
  852. $E.css({ width: w });
  853. if (w > 0) {
  854. if (autoHide && $E.data('autoHidden') && $E.innerHeight() > 0) {
  855. $E.show().data('autoHidden', false);
  856. if (!state.browser.mozilla) // FireFox refreshes iframes - IE doesn't
  857. // make hidden, then visible to 'refresh' display after animation
  858. $E.css(_c.hidden).css(_c.visible);
  859. }
  860. }
  861. else if (autoHide && !$E.data('autoHidden'))
  862. $E.hide().data('autoHidden', true);
  863. };
  864. /**
  865. * @param {(string|!Object)} el
  866. * @param {number=} outerHeight
  867. * @param {boolean=} autoHide
  868. */
  869. var setOuterHeight = function (el, outerHeight, autoHide) {
  870. var $E = el, h;
  871. if (isStr(el)) $E = $Ps[el]; // west
  872. else if (!el.jquery) $E = $(el);
  873. h = cssH($E, outerHeight);
  874. $E.css({ height: h, visibility: "visible" }); // may have been 'hidden' by sizeContent
  875. if (h > 0 && $E.innerWidth() > 0) {
  876. if (autoHide && $E.data('autoHidden')) {
  877. $E.show().data('autoHidden', false);
  878. if (!state.browser.mozilla) // FireFox refreshes iframes - IE doesn't
  879. $E.css(_c.hidden).css(_c.visible);
  880. }
  881. }
  882. else if (autoHide && !$E.data('autoHidden'))
  883. $E.hide().data('autoHidden', true);
  884. };
  885. /**
  886. * @param {(string|!Object)} el
  887. * @param {number=} outerSize
  888. * @param {boolean=} autoHide
  889. */
  890. var setOuterSize = function (el, outerSize, autoHide) {
  891. if (_c[pane].dir=="horz") // pane = north or south
  892. setOuterHeight(el, outerSize, autoHide);
  893. else // pane = east or west
  894. setOuterWidth(el, outerSize, autoHide);
  895. };
  896. /**
  897. * Converts any 'size' params to a pixel/integer size, if not already
  898. * If 'auto' or a decimal/percentage is passed as 'size', a pixel-size is calculated
  899. *
  900. /**
  901. * @param {string} pane
  902. * @param {(string|number)=} size
  903. * @param {string=} dir
  904. * @return {number}
  905. */
  906. var _parseSize = function (pane, size, dir) {
  907. if (!dir) dir = _c[pane].dir;
  908. if (isStr(size) && size.match(/%/))
  909. size = parseInt(size, 10) / 100; // convert % to decimal
  910. if (size === 0)
  911. return 0;
  912. else if (size >= 1)
  913. return parseInt(size, 10);
  914. else if (size > 0) { // percentage, eg: .25
  915. var o = options, avail;
  916. if (dir=="horz") // north or south or center.minHeight
  917. avail = sC.innerHeight - ($Ps.north ? o.north.spacing_open : 0) - ($Ps.south ? o.south.spacing_open : 0);
  918. else if (dir=="vert") // east or west or center.minWidth
  919. avail = sC.innerWidth - ($Ps.west ? o.west.spacing_open : 0) - ($Ps.east ? o.east.spacing_open : 0);
  920. return Math.floor(avail * size);
  921. }
  922. else if (pane=="center")
  923. return 0;
  924. else { // size < 0 || size=='auto' || size==Missing || size==Invalid
  925. // auto-size the pane
  926. var
  927. $P = $Ps[pane]
  928. , dim = (dir == "horz" ? "height" : "width")
  929. , vis = _showInvisibly($P) // show pane invisibly if hidden
  930. , s = $P.css(dim); // SAVE current size
  931. ;
  932. $P.css(dim, "auto");
  933. size = (dim == "height") ? $P.outerHeight() : $P.outerWidth(); // MEASURE
  934. $P.css(dim, s).css(vis); // RESET size & visibility
  935. return size;
  936. }
  937. };
  938. /**
  939. * Calculates current 'size' (outer-width or outer-height) of a border-pane - optionally with 'pane-spacing' added
  940. *
  941. * @param {(string|!Object)} pane
  942. * @param {boolean=} inclSpace
  943. * @return {number} Returns EITHER Width for east/west panes OR Height for north/south panes - adjusted for boxModel & browser
  944. */
  945. var getPaneSize = function (pane, inclSpace) {
  946. var
  947. $P = $Ps[pane]
  948. , o = options[pane]
  949. , s = state[pane]
  950. , oSp = (inclSpace ? o.spacing_open : 0)
  951. , cSp = (inclSpace ? o.spacing_closed : 0)
  952. ;
  953. if (!$P || s.isHidden)
  954. return 0;
  955. else if (s.isClosed || (s.isSliding && inclSpace))
  956. return cSp;
  957. else if (_c[pane].dir == "horz")
  958. return $P.outerHeight() + oSp;
  959. else // dir == "vert"
  960. return $P.outerWidth() + oSp;
  961. };
  962. /**
  963. * Calculate min/max pane dimensions and limits for resizing
  964. *
  965. * @param {string} pane
  966. * @param {boolean=} slide
  967. */
  968. var setSizeLimits = function (pane, slide) {
  969. var
  970. o = options[pane]
  971. , s = state[pane]
  972. , c = _c[pane]
  973. , dir = c.dir
  974. , side = c.side.toLowerCase()
  975. , type = c.sizeType.toLowerCase()
  976. , isSliding = (slide != undefined ? slide : s.isSliding) // only open() passes 'slide' param
  977. , $P = $Ps[pane]
  978. , paneSpacing = o.spacing_open
  979. // measure the pane on the *opposite side* from this pane
  980. , altPane = _c.altSide[pane]
  981. , altS = state[altPane]
  982. , $altP = $Ps[altPane]
  983. , altPaneSize = (!$altP || altS.isVisible===false || altS.isSliding ? 0 : (dir=="horz" ? $altP.outerHeight() : $altP.outerWidth()))
  984. , altPaneSpacing = ((!$altP || altS.isHidden ? 0 : options[altPane][ altS.isClosed !== false ? "spacing_closed" : "spacing_open" ]) || 0)
  985. // limitSize prevents this pane from 'overlapping' opposite pane
  986. , containerSize = (dir=="horz" ? sC.innerHeight : sC.innerWidth)
  987. , minCenterDims = cssMinDims("center")
  988. , minCenterSize = dir=="horz" ? max(options.center.minHeight, minCenterDims.minHeight) : max(options.center.minWidth, minCenterDims.minWidth)
  989. // if pane is 'sliding', then ignore center and alt-pane sizes - because 'overlays' them
  990. , limitSize = (containerSize - paneSpacing - (isSliding ? 0 : (_parseSize("center", minCenterSize, dir) + altPaneSize + altPaneSpacing)))
  991. , minSize = s.minSize = max( _parseSize(pane, o.minSize), cssMinDims(pane).minSize )
  992. , maxSize = s.maxSize = min( (o.maxSize ? _parseSize(pane, o.maxSize) : 100000), limitSize )
  993. , r = s.resizerPosition = {} // used to set resizing limits
  994. , top = sC.insetTop
  995. , left = sC.insetLeft
  996. , W = sC.innerWidth
  997. , H = sC.innerHeight
  998. , rW = o.spacing_open // subtract resizer-width to get top/left position for south/east
  999. ;
  1000. switch (pane) {
  1001. case "north": r.min = top + minSize;
  1002. r.max = top + maxSize;
  1003. break;
  1004. case "west": r.min = left + minSize;
  1005. r.max = left + maxSize;
  1006. break;
  1007. case "south": r.min = top + H - maxSize - rW;
  1008. r.max = top + H - minSize - rW;
  1009. break;
  1010. case "east": r.min = left + W - maxSize - rW;
  1011. r.max = left + W - minSize - rW;
  1012. break;
  1013. };
  1014. };
  1015. /**
  1016. * Returns data for setting the size/position of center pane. Also used to set Height for east/west panes
  1017. *
  1018. * @return JSON Returns a hash of all dimensions: top, bottom, left, right, (outer) width and (outer) height
  1019. */
  1020. var calcNewCenterPaneDims = function () {
  1021. var d = {
  1022. top: getPaneSize("north", true) // true = include 'spacing' value for pane
  1023. , bottom: getPaneSize("south", true)
  1024. , left: getPaneSize("west", true)
  1025. , right: getPaneSize("east", true)
  1026. , width: 0
  1027. , height: 0
  1028. };
  1029. // NOTE: sC = state.container
  1030. // calc center-pane's outer dimensions
  1031. d.width = sC.innerWidth - d.left - d.right; // outerWidth
  1032. d.height = sC.innerHeight - d.bottom - d.top; // outerHeight
  1033. // add the 'container border/padding' to get final positions relative to the container
  1034. d.top += sC.insetTop;
  1035. d.bottom += sC.insetBottom;
  1036. d.left += sC.insetLeft;
  1037. d.right += sC.insetRight;
  1038. return d;
  1039. };
  1040. /**
  1041. * Returns data for setting size of an element (container or a pane).
  1042. *
  1043. * @see _create(), onWindowResize() for container, plus others for pane
  1044. * @return JSON Returns a hash of all dimensions: top, bottom, left, right, outerWidth, innerHeight, etc
  1045. */
  1046. var getElemDims = function ($E) {
  1047. var
  1048. d = {} // dimensions hash
  1049. , x = d.css = {} // CSS hash
  1050. , i = {} // TEMP insets
  1051. , b, p // TEMP border, padding
  1052. , off = $E.offset()
  1053. ;
  1054. d.offsetLeft = off.left;
  1055. d.offsetTop = off.top;
  1056. $.each("Left,Right,Top,Bottom".split(","), function (idx, e) {
  1057. b = x["border" + e] = _borderWidth($E, e);
  1058. p = x["padding"+ e] = _cssNum($E, "padding"+e);
  1059. i[e] = b + p; // total offset of content from outer side
  1060. d["inset"+ e] = p;
  1061. /* WRONG ???
  1062. // if BOX MODEL, then 'position' = PADDING (ignore borderWidth)
  1063. if ($E == $Container)
  1064. d["inset"+ e] = (state.browser.boxModel ? p : 0);
  1065. */
  1066. });
  1067. d.offsetWidth = $E.innerWidth(); // true=include Padding
  1068. d.offsetHeight = $E.innerHeight();
  1069. d.outerWidth = $E.outerWidth();
  1070. d.outerHeight = $E.outerHeight();
  1071. d.innerWidth = d.outerWidth - i.Left - i.Right;
  1072. d.innerHeight = d.outerHeight - i.Top - i.Bottom;
  1073. // TESTING
  1074. x.width = $E.width();
  1075. x.height = $E.height();
  1076. return d;
  1077. };
  1078. var getElemCSS = function ($E, list) {
  1079. var
  1080. CSS = {}
  1081. , style = $E[0].style
  1082. , props = list.split(",")
  1083. , sides = "Top,Bottom,Left,Right".split(",")
  1084. , attrs = "Color,Style,Width".split(",")
  1085. , p, s, a, i, j, k
  1086. ;
  1087. for (i=0; i < props.length; i++) {
  1088. p = props[i];
  1089. if (p.match(/(border|padding|margin)$/))
  1090. for (j=0; j < 4; j++) {
  1091. s = sides[j];
  1092. if (p == "border")
  1093. for (k=0; k < 3; k++) {
  1094. a = attrs[k];
  1095. CSS[p+s+a] = style[p+s+a];
  1096. }
  1097. else
  1098. CSS[p+s] = style[p+s];
  1099. }
  1100. else
  1101. CSS[p] = style[p];
  1102. };
  1103. return CSS
  1104. };
  1105. /**
  1106. * @param {!Object} el
  1107. * @param {boolean=} allStates
  1108. */
  1109. var getHoverClasses = function (el, allStates) {
  1110. var
  1111. $El = $(el)
  1112. , type = $El.data("layoutRole")
  1113. , pane = $El.data("layoutEdge")
  1114. , o = options[pane]
  1115. , root = o[type +"Class"]
  1116. , _pane = "-"+ pane // eg: "-west"
  1117. , _open = "-open"
  1118. , _closed = "-closed"
  1119. , _slide = "-sliding"
  1120. , _hover = "-hover " // NOTE the trailing space
  1121. , _state = $El.hasClass(root+_closed) ? _closed : _open
  1122. , _alt = _state == _closed ? _open : _closed
  1123. , classes = (root+_hover) + (root+_pane+_hover) + (root+_state+_hover) + (root+_pane+_state+_hover)
  1124. ;
  1125. if (allStates) // when 'removing' classes, also remove alternate-state classes
  1126. classes += (root+_alt+_hover) + (root+_pane+_alt+_hover);
  1127. if (type=="resizer" && $El.hasClass(root+_slide))
  1128. classes += (root+_slide+_hover) + (root+_pane+_slide+_hover);
  1129. return $.trim(classes);
  1130. };
  1131. var addHover = function (evt, el) {
  1132. var e = el || this;
  1133. $(e).addClass( getHoverClasses(e) );
  1134. //if (evt && $(e).data("layoutRole") == "toggler") evt.stopPropagation();
  1135. };
  1136. var removeHover = function (evt, el) {
  1137. var e = el || this;
  1138. $(e).removeClass( getHoverClasses(e, true) );
  1139. };
  1140. var onResizerEnter = function (evt) {
  1141. $('body').disableSelection();
  1142. addHover(evt, this);
  1143. };
  1144. var onResizerLeave = function (evt, el) {
  1145. var
  1146. e = el || this // el is only passed when called by the timer
  1147. , pane = $(e).data("layoutEdge")
  1148. , name = pane +"ResizerLeave"
  1149. ;
  1150. timer.clear(name);
  1151. if (!el) { // 1st call - mouseleave event
  1152. removeHover(evt, this); // do this on initial call
  1153. // this method calls itself on a timer because it needs to allow
  1154. // enough time for dragging to kick-in and set the isResizing flag
  1155. // dragging has a 100ms delay set, so this delay must be higher
  1156. timer.set(name, function(){ onResizerLeave(evt, e); }, 200);
  1157. }
  1158. // if user is resizing, then dragStop will enableSelection() when done
  1159. else if (!state[pane].isResizing) // 2nd call - by timer
  1160. $('body').enableSelection();
  1161. };
  1162. /*
  1163. * ###########################
  1164. * INITIALIZATION METHODS
  1165. * ###########################
  1166. */
  1167. /**
  1168. * Initialize the layout - called automatically whenever an instance of layout is created
  1169. *
  1170. * @see none - triggered onInit
  1171. * @return An object pointer to the instance created
  1172. */
  1173. var _create = function () {
  1174. // initialize config/options
  1175. initOptions();
  1176. var o = options;
  1177. // onload will CANCEL resizing if returns false
  1178. if (false === _execCallback(null, o.onload)) return false;
  1179. // a center pane is required, so make sure it exists
  1180. if (!getPane('center').length) {
  1181. alert( lang.errCenterPaneMissing );
  1182. return null;
  1183. }
  1184. // update options with saved state, if option enabled
  1185. if (o.useStateCookie && o.cookie.autoLoad)
  1186. loadCookie(); // Update options from state-cookie
  1187. // set environment - can update code here if $.browser is phased out
  1188. state.browser = {
  1189. mozilla: $.browser.mozilla
  1190. , webkit: $.browser.webkit || $.browser.safari
  1191. , msie: $.browser.msie
  1192. , isIE6: $.browser.msie && $.browser.version == 6
  1193. , boxModel: $.support.boxModel
  1194. //, version: $.browser.version - not used
  1195. };
  1196. // initialize all layout elements
  1197. initContainer(); // set CSS as needed and init state.container dimensions
  1198. initPanes(); // size & position panes - calls initHandles() - which calls initResizable()
  1199. sizeContent(); // AFTER panes & handles have been initialized, size 'content' divs
  1200. if (o.scrollToBookmarkOnLoad) {
  1201. var l = self.location;
  1202. if (l.hash) l.replace( l.hash ); // scrollTo Bookmark
  1203. }
  1204. // search for and bind custom-buttons
  1205. if (o.autoBindCustomButtons) initButtons();
  1206. // bind hotkey function - keyDown - if required
  1207. initHotkeys();
  1208. // bind resizeAll() for 'this layout instance' to window.resize event
  1209. if (o.resizeWithWindow && !$Container.data("layoutRole")) // skip if 'nested' inside a pane
  1210. $(window).bind("resize."+ sID, windowResize);
  1211. // bind window.onunload
  1212. $(window).bind("unload."+ sID, unload);
  1213. state.initialized = true;
  1214. };
  1215. var windowResize = function () {
  1216. var delay = Number(options.resizeWithWindowDelay) || 100; // there MUST be some delay!
  1217. if (delay > 0) {
  1218. // resizing uses a delay-loop because the resize event fires repeatly - except in FF, but delay anyway
  1219. timer.clear("winResize"); // if already running
  1220. timer.set("winResize", function(){ timer.clear("winResize"); timer.clear("winResizeRepeater"); resizeAll(); }, delay);
  1221. // ALSO set fixed-delay timer, if not already running
  1222. if (!timer.data["winResizeRepeater"]) setWindowResizeRepeater();
  1223. }
  1224. };
  1225. var setWindowResizeRepeater = function () {
  1226. var delay = Number(options.resizeWithWindowMaxDelay);
  1227. if (delay > 0)
  1228. timer.set("winResizeRepeater", function(){ setWindowResizeRepeater(); resizeAll(); }, delay);
  1229. };
  1230. var unload = function () {
  1231. var o = options;
  1232. state.cookie = getState(); // save state in case onunload has custom state-management
  1233. if (o.useStateCookie && o.cookie.autoSave) saveCookie();
  1234. _execCallback(null, o.onunload);
  1235. };
  1236. /**
  1237. * Validate and initialize container CSS and events
  1238. *
  1239. * @see _create()
  1240. */
  1241. var initContainer = function () {
  1242. var
  1243. $C = $Container // alias
  1244. , tag = sC.tagName = $C.attr("tagName")
  1245. , fullPage= (tag == "BODY")
  1246. , props = "position,margin,padding,border"
  1247. , CSS = {}
  1248. ;
  1249. sC.selector = $C.selector.split(".slice")[0];
  1250. sC.ref = tag +"/"+ sC.selector; // used in messages
  1251. $C .data("layout", Instance)
  1252. .data("layoutContainer", sID) // unique identifier for internal use
  1253. ;
  1254. // SAVE original container CSS for use in destroy()
  1255. if (!$C.data("layoutCSS")) {
  1256. // handle props like overflow different for BODY & HTML - has 'system default' values
  1257. if (fullPage) {
  1258. CSS = $.extend( getElemCSS($C, props), {
  1259. height: $C.css("height")
  1260. , overflow: $C.css("overflow")
  1261. , overflowX: $C.css("overflowX")
  1262. , overflowY: $C.css("overflowY")
  1263. });
  1264. // ALSO SAVE <HTML> CSS
  1265. var $H = $("html");
  1266. $H.data("layoutCSS", {
  1267. height: "auto" // FF would return a fixed px-size!
  1268. , overflow: $H.css("overflow")
  1269. , overflowX: $H.css("overflowX")
  1270. , overflowY: $H.css("overflowY")
  1271. });
  1272. }
  1273. else // handle props normally for non-body elements
  1274. CSS = getElemCSS($C, props+",top,bottom,left,right,width,height,overflow,overflowX,overflowY");
  1275. $C.data("layoutCSS", CSS);
  1276. }
  1277. try { // format html/body if this is a full page layout
  1278. if (fullPage) {
  1279. $("html").css({
  1280. height: "100%"
  1281. , overflow: "hidden"
  1282. , overflowX: "hidden"
  1283. , overflowY: "hidden"
  1284. });
  1285. $("body").css({
  1286. position: "relative"
  1287. , height: "100%"
  1288. , overflow: "hidden"
  1289. , overflowX: "hidden"
  1290. , overflowY: "hidden"
  1291. , margin: 0
  1292. , padding: 0 // TODO: test whether body-padding could be handled?
  1293. , border: "none" // a body-border creates problems because it cannot be measured!
  1294. });
  1295. }
  1296. else { // set required CSS for overflow and position
  1297. CSS = { overflow: "hidden" } // make sure container will not 'scroll'
  1298. var
  1299. p = $C.css("position")
  1300. , h = $C.css("height")
  1301. ;
  1302. // if this is a NESTED layout, then container/outer-pane ALREADY has position and height
  1303. if (!$C.data("layoutRole")) {
  1304. if (!p || !p.match(/fixed|absolute|relative/))
  1305. CSS.position = "relative"; // container MUST have a 'position'
  1306. /*
  1307. if (!h || h=="auto")
  1308. CSS.height = "100%"; // container MUST have a 'height'
  1309. */
  1310. }
  1311. $C.css( CSS );
  1312. if ($C.is(":visible") && $C.innerHeight() < 2)
  1313. alert( lang.errContainerHeight.replace(/CONTAINER/, sC.ref) );
  1314. }
  1315. } catch (ex) {}
  1316. // set current layout-container dimensions
  1317. $.extend(state.container, getElemDims( $C ));
  1318. };
  1319. /**
  1320. * Bind layout hotkeys - if options enabled
  1321. *
  1322. * @see _create()
  1323. */
  1324. var initHotkeys = function () {
  1325. // bind keyDown to capture hotkeys, if option enabled for ANY pane
  1326. $.each(_c.borderPanes.split(","), function (i, pane) {
  1327. var o = options[pane];
  1328. if (o.enableCursorHotkey || o.customHotkey) {
  1329. $(document).bind("keydown."+ sID, keyDown); // only need to bind this ONCE
  1330. return false; // BREAK - binding was done
  1331. }
  1332. });
  1333. };
  1334. /**
  1335. * Build final OPTIONS data
  1336. *
  1337. * @see _create()
  1338. */
  1339. var initOptions = function () {
  1340. // simplify logic by making sure passed 'opts' var has basic keys
  1341. opts = _transformData( opts );
  1342. // TODO: create a compatibility add-on for new UI widget that will transform old option syntax
  1343. var newOpts = {
  1344. applyDefaultStyles: "applyDemoStyles"
  1345. };
  1346. renameOpts(opts.defaults);
  1347. $.each(_c.allPanes.split(","), function (i, pane) {
  1348. renameOpts(opts[pane]);
  1349. });
  1350. // update default effects, if case user passed key
  1351. if (opts.effects) {
  1352. $.extend( effects, opts.effects );
  1353. delete opts.effects;
  1354. }
  1355. $.extend( options.cookie, opts.cookie );
  1356. // see if any 'global options' were specified
  1357. var globals = "name,zIndex,scrollToBookmarkOnLoad,resizeWithWindow,resizeWithWindowDelay,resizeWithWindowMaxDelay,"+
  1358. "onresizeall,onresizeall_start,onresizeall_end,onload,onunload,autoBindCustomButtons,useStateCookie";
  1359. $.each(globals.split(","), function (i, key) {
  1360. if (opts[key] !== undefined)
  1361. options[key] = opts[key];
  1362. else if (opts.defaults[key] !== undefined) {
  1363. options[key] = opts.defaults[key];
  1364. delete opts.defaults[key];
  1365. }
  1366. });
  1367. // remove any 'defaults' that MUST be set 'per-pane'
  1368. $.each("paneSelector,resizerCursor,customHotkey".split(","),
  1369. function (i, key) { delete opts.defaults[key]; } // is OK if key does not exist
  1370. );
  1371. // now update options.defaults
  1372. $.extend( true, options.defaults, opts.defaults );
  1373. // merge config for 'center-pane' - border-panes handled in the loop below
  1374. _c.center = $.extend( true, {}, _c.panes, _c.center );
  1375. // update config.zIndex values if zIndex option specified
  1376. var z = options.zIndex;
  1377. if (z === 0 || z > 0) {
  1378. _c.zIndex.pane_normal = z;
  1379. _c.zIndex.resizer_normal = z+1;
  1380. _c.zIndex.iframe_mask = z+1;
  1381. }
  1382. // merge options for 'center-pane' - border-panes handled in the loop below
  1383. $.extend( options.center, opts.center );
  1384. // Most 'default options' do not apply to 'center', so add only those that DO
  1385. var o_Center = $.extend( true, {}, options.defaults, opts.defaults, options.center ); // TEMP data
  1386. var optionsCenter = ("paneClass,contentSelector,applyDemoStyles,triggerEventsOnLoad,showOverflowOnHover,"
  1387. + "onresize,onresize_start,onresize_end,resizeNestedLayout,resizeContentWhileDragging,"
  1388. + "onsizecontent,onsizecontent_start,onsizecontent_end").split(",");
  1389. $.each(optionsCenter,
  1390. function (i, key) { options.center[key] = o_Center[key]; }
  1391. );
  1392. var o, defs = options.defaults;
  1393. // create a COMPLETE set of options for EACH border-pane
  1394. $.each(_c.borderPanes.split(","), function (i, pane) {
  1395. // apply 'pane-defaults' to CONFIG.[PANE]
  1396. _c[pane] = $.extend( true, {}, _c.panes, _c[pane] );
  1397. // apply 'pane-defaults' + user-options to OPTIONS.PANE
  1398. o = options[pane] = $.extend( true, {}, options.defaults, options[pane], opts.defaults, opts[pane] );
  1399. // make sure we have base-classes
  1400. if (!o.paneClass) o.paneClass = "ui-layout-pane";
  1401. if (!o.resizerClass) o.resizerClass = "ui-layout-resizer";
  1402. if (!o.togglerClass) o.togglerClass = "ui-layout-toggler";
  1403. // create FINAL fx options for each pane, ie: options.PANE.fxName/fxSpeed/fxSettings[_open|_close]
  1404. $.each(["_open","_close",""], function (i,n) {
  1405. var
  1406. sName = "fxName"+n
  1407. , sSpeed = "fxSpeed"+n
  1408. , sSettings = "fxSettings"+n
  1409. ;
  1410. // recalculate fxName according to specificity rules
  1411. o[sName] =
  1412. opts[pane][sName] // opts.west.fxName_open
  1413. || opts[pane].fxName // opts.west.fxName
  1414. || opts.defaults[sName] // opts.defaults.fxName_open
  1415. || opts.defaults.fxName // opts.defaults.fxName
  1416. || o[sName] // options.west.fxName_open
  1417. || o.fxName // options.west.fxName
  1418. || defs[sName] // options.defaults.fxName_open
  1419. || defs.fxName // options.defaults.fxName
  1420. || "none"
  1421. ;
  1422. // validate fxName to be sure is a valid effect
  1423. var fxName = o[sName];
  1424. if (fxName == "none" || !$.effects || !$.effects[fxName] || (!effects[fxName] && !o[sSettings] && !o.fxSettings))
  1425. fxName = o[sName] = "none"; // effect not loaded, OR undefined FX AND fxSettings not passed
  1426. // set vars for effects subkeys to simplify logic
  1427. var
  1428. fx = effects[fxName] || {} // effects.slide
  1429. , fx_all = fx.all || {} // effects.slide.all
  1430. , fx_pane = fx[pane] || {} // effects.slide.west
  1431. ;
  1432. // RECREATE the fxSettings[_open|_close] keys using specificity rules
  1433. o[sSettings] = $.extend(
  1434. {}
  1435. , fx_all // effects.slide.all
  1436. , fx_pane // effects.slide.west
  1437. , defs.fxSettings || {} // options.defaults.fxSettings
  1438. , defs[sSettings] || {} // options.defaults.fxSettings_open
  1439. , o.fxSettings // options.west.fxSettings
  1440. , o[sSettings] // options.west.fxSettings_open
  1441. , opts.defaults.fxSettings // opts.defaults.fxSettings
  1442. , opts.defaults[sSettings] || {} // opts.defaults.fxSettings_open
  1443. , opts[pane].fxSettings // opts.west.fxSettings
  1444. , opts[pane][sSettings] || {} // opts.west.fxSettings_open
  1445. );
  1446. // recalculate fxSpeed according to specificity rules
  1447. o[sSpeed] =
  1448. opts[pane][sSpeed] // opts.west.fxSpeed_open
  1449. || opts[pane].fxSpeed // opts.west.fxSpeed (pane-default)
  1450. || opts.defaults[sSpeed] // opts.defaults.fxSpeed_open
  1451. || opts.defaults.fxSpeed // opts.defaults.fxSpeed
  1452. || o[sSpeed] // options.west.fxSpeed_open
  1453. || o[sSettings].duration // options.west.fxSettings_open.duration
  1454. || o.fxSpeed // options.west.fxSpeed
  1455. || o.fxSettings.duration // options.west.fxSettings.duration
  1456. || defs.fxSpeed // options.defaults.fxSpeed
  1457. || defs.fxSettings.duration// options.defaults.fxSettings.duration
  1458. || fx_pane.duration // effects.slide.west.duration
  1459. || fx_all.duration // effects.slide.all.duration
  1460. || "normal" // DEFAULT
  1461. ;
  1462. });
  1463. });
  1464. function renameOpts (O) {
  1465. for (var key in newOpts) {
  1466. if (O[key] != undefined) {
  1467. O[newOpts[key]] = O[key];
  1468. delete O[key];
  1469. }
  1470. }
  1471. }
  1472. };
  1473. /**
  1474. * Initialize module objects, styling, size and position for all panes
  1475. *
  1476. * @see _create()
  1477. */
  1478. var getPane = function (pane) {
  1479. var sel = options[pane].paneSelector
  1480. if (sel.substr(0,1)==="#") // ID selector
  1481. // NOTE: elements selected 'by ID' DO NOT have to be 'children'
  1482. return $Container.find(sel).eq(0);
  1483. else { // class or other selector
  1484. var $P = $Container.children(sel).eq(0);
  1485. // look for the pane nested inside a 'form' element
  1486. return $P.length ? $P : $Container.children("form:first").children(sel).eq(0);
  1487. }
  1488. };
  1489. var initPanes = function () {
  1490. // NOTE: do north & south FIRST so we can measure their height - do center LAST
  1491. $.each(_c.allPanes.split(","), function (idx, pane) {
  1492. var
  1493. o = options[pane]
  1494. , s = state[pane]
  1495. , c = _c[pane]
  1496. , fx = s.fx
  1497. , dir = c.dir
  1498. , spacing = o.spacing_open || 0
  1499. , isCenter = (pane == "center")
  1500. , CSS = {}
  1501. , $P, $C
  1502. , size, minSize, maxSize
  1503. ;
  1504. $Cs[pane] = false; // init
  1505. $P = $Ps[pane] = getPane(pane);
  1506. if (!$P.length) {
  1507. $Ps[pane] = false; // logic
  1508. return true; // SKIP to next
  1509. }
  1510. // SAVE original Pane CSS
  1511. if (!$P.data("layoutCSS")) {
  1512. var props = "position,top,left,bottom,right,width,height,overflow,zIndex,display,backgroundColor,padding,margin,border";
  1513. $P.data("layoutCSS", getElemCSS($P, props));
  1514. }
  1515. // add basic classes & attributes
  1516. $P
  1517. .data("parentLayout", Instance)
  1518. .data("layoutRole", "pane")
  1519. .data("layoutEdge", pane)
  1520. .css(c.cssReq).css("zIndex", _c.zIndex.pane_normal)
  1521. .css(o.applyDemoStyles ? c.cssDemo : {}) // demo styles
  1522. .addClass( o.paneClass +" "+ o.paneClass+"-"+pane ) // default = "ui-layout-pane ui-layout-pane-west" - may be a dupe of 'paneSelector'
  1523. .bind("mouseenter."+ sID, addHover )
  1524. .bind("mouseleave."+ sID, removeHover )
  1525. ;
  1526. // see if this pane has a 'scrolling-content element'
  1527. initContent(pane, false); // false = do NOT sizeContent() - called later
  1528. if (!isCenter) {
  1529. // call _parseSize AFTER applying pane classes & styles - but before making visible (if hidden)
  1530. // if o.size is auto or not valid, then MEASURE the pane and use that as it's 'size'
  1531. size = s.size = _parseSize(pane, o.size);
  1532. minSize = _parseSize(pane,o.minSize) || 1;
  1533. maxSize = _parseSize(pane,o.maxSize) || 100000;
  1534. if (size > 0) size = max(min(size, maxSize), minSize);
  1535. // state for border-panes
  1536. s.isClosed = false; // true = pane is closed
  1537. s.isSliding = false; // true = pane is currently open by 'sliding' over adjacent panes
  1538. s.isResizing= false; // true = pane is in process of being resized
  1539. s.isHidden = false; // true = pane is hidden - no spacing, resizer or toggler is visible!
  1540. }
  1541. // state for all panes
  1542. s.tagName = $P.attr("tagName");
  1543. s.edge = pane // useful if pane is (or about to be) 'swapped' - easy find out where it is (or is going)
  1544. s.noRoom = false; // true = pane 'automatically' hidden due to insufficient room - will unhide automatically
  1545. s.isVisible = true; // false = pane is invisible - closed OR hidden - simplify logic
  1546. // set css-position to account for container borders & padding
  1547. switch (pane) {
  1548. case "north": CSS.top = sC.insetTop;
  1549. CSS.left = sC.insetLeft;
  1550. CSS.right = sC.insetRight;
  1551. break;
  1552. case "south": CSS.bottom = sC.insetBottom;
  1553. CSS.left = sC.insetLeft;
  1554. CSS.right = sC.insetRight;
  1555. break;
  1556. case "west": CSS.left = sC.insetLeft; // top, bottom & height set by sizeMidPanes()
  1557. break;
  1558. case "east": CSS.right = sC.insetRight; // ditto
  1559. break;
  1560. case "center": // top, left, width & height set by sizeMidPanes()
  1561. }
  1562. if (dir == "horz") // north or south pane
  1563. CSS.height = max(1, cssH(pane, size));
  1564. else if (dir == "vert") // east or west pane
  1565. CSS.width = max(1, cssW(pane, size));
  1566. //else if (isCenter) {}
  1567. $P.css(CSS); // apply size -- top, bottom & height will be set by sizeMidPanes
  1568. if (dir != "horz") sizeMidPanes(pane, true); // true = skipCallback
  1569. // NOW make the pane visible - in case was initially hidden
  1570. $P.css({ visibility: "visible", display: "block" });
  1571. // close or hide the pane if specified in settings
  1572. if (o.initClosed && o.closable)
  1573. close(pane, true, true); // true, true = force, noAnimation
  1574. else if (o.initHidden || o.initClosed)
  1575. hide(pane); // will be completely invisible - no resizer or spacing
  1576. // ELSE setAsOpen() - called later by initHandles()
  1577. // check option for auto-handling of pop-ups & drop-downs
  1578. if (o.showOverflowOnHover)
  1579. $P.hover( allowOverflow, resetOverflow );
  1580. });
  1581. /*
  1582. * init the pane-handles NOW in case we have to hide or close the pane below
  1583. */
  1584. initHandles();
  1585. // now that all panes have been initialized and initially-sized,
  1586. // make sure there is really enough space available for each pane
  1587. $.each(_c.borderPanes.split(","), function (i, pane) {
  1588. if ($Ps[pane] && state[pane].isVisible) { // pane is OPEN
  1589. setSizeLimits(pane);
  1590. makePaneFit(pane); // pane may be Closed, Hidden or Resized by makePaneFit()
  1591. }
  1592. });
  1593. // size center-pane AGAIN in case we 'closed' a border-pane in loop above
  1594. sizeMidPanes("center");
  1595. // trigger onResize callbacks for all panes with triggerEventsOnLoad = true
  1596. $.each(_c.allPanes.split(","), function (i, pane) {
  1597. var o = options[pane];
  1598. if ($Ps[pane] && o.triggerEventsOnLoad && state[pane].isVisible) // pane is OPEN
  1599. _execCallback(pane, o.onresize_end || o.onresize); // call onresize
  1600. });
  1601. if ($Container.innerHeight() < 2)
  1602. alert( lang.errContainerHeight.replace(/CONTAINER/, sC.ref) );
  1603. };
  1604. /**
  1605. * Initialize module objects, styling, size and position for all resize bars and toggler buttons
  1606. *
  1607. * @see _create()
  1608. * @param {string=} panes The edge(s) to process, blank = all
  1609. */
  1610. var initHandles = function (panes) {
  1611. if (!panes || panes == "all") panes = _c.borderPanes;
  1612. // create toggler DIVs for each pane, and set object pointers for them, eg: $R.north = north toggler DIV
  1613. $.each(panes.split(","), function (i, pane) {
  1614. var $P = $Ps[pane];
  1615. $Rs[pane] = false; // INIT
  1616. $Ts[pane] = false;
  1617. if (!$P) return; // pane does not exist - skip
  1618. var
  1619. o = options[pane]
  1620. , s = state[pane]
  1621. , c = _c[pane]
  1622. , rClass = o.resizerClass
  1623. , tClass = o.togglerClass
  1624. , side = c.side.toLowerCase()
  1625. , spacing = (s.isVisible ? o.spacing_open : o.spacing_closed)
  1626. , _pane = "-"+ pane // used for classNames
  1627. , _state = (s.isVisible ? "-open" : "-closed") // used for classNames
  1628. // INIT RESIZER BAR
  1629. , $R = $Rs[pane] = $("<div></div>")
  1630. // INIT TOGGLER BUTTON
  1631. , $T = (o.closable ? $Ts[pane] = $("<div></div>") : false)
  1632. ;
  1633. //if (s.isVisible && o.resizable) ... handled by initResizable
  1634. if (!s.isVisible && o.slidable)
  1635. $R.attr("title", o.sliderTip).css("cursor", o.sliderCursor);
  1636. $R
  1637. // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "paneLeft-resizer"
  1638. .attr("id", (o.paneSelector.substr(0,1)=="#" ? o.paneSelector.substr(1) + "-resizer" : ""))
  1639. .data("parentLayout", Instance)
  1640. .data("layoutRole", "resizer")
  1641. .data("layoutEdge", pane)
  1642. .css(_c.resizers.cssReq).css("zIndex", _c.zIndex.resizer_normal)
  1643. .css(o.applyDemoStyles ? _c.resizers.cssDemo : {}) // add demo styles
  1644. .addClass(rClass +" "+ rClass+_pane)
  1645. .appendTo($Container) // append DIV to container
  1646. ;
  1647. if ($T) {
  1648. $T
  1649. // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "#paneLeft-toggler"
  1650. .attr("id", (o.paneSelector.substr(0,1)=="#" ? o.paneSelector.substr(1) + "-toggler" : ""))
  1651. .data("parentLayout", Instance)
  1652. .data("layoutRole", "toggler")
  1653. .data("layoutEdge", pane)
  1654. .css(_c.togglers.cssReq) // add base/required styles
  1655. .css(o.applyDemoStyles ? _c.togglers.cssDemo : {}) // add demo styles
  1656. .addClass(tClass +" "+ tClass+_pane)
  1657. .appendTo($R) // append SPAN to resizer DIV
  1658. ;
  1659. // ADD INNER-SPANS TO TOGGLER
  1660. if (o.togglerContent_open) // ui-layout-open
  1661. $("<span>"+ o.togglerContent_open +"</span>")
  1662. .data("layoutRole", "togglerContent")
  1663. .data("layoutEdge", pane)
  1664. .addClass("content content-open")
  1665. .css("display","none")
  1666. .appendTo( $T )
  1667. .hover( addHover, removeHover )
  1668. ;
  1669. if (o.togglerContent_closed) // ui-layout-closed
  1670. $("<span>"+ o.togglerContent_closed +"</span>")
  1671. .data("layoutRole", "togglerContent")
  1672. .data("layoutEdge", pane)
  1673. .addClass("content content-closed")
  1674. .css("display","none")
  1675. .appendTo( $T )
  1676. .hover( addHover, removeHover )
  1677. ;
  1678. // ADD TOGGLER.click/.hover
  1679. enableClosable(pane);
  1680. }
  1681. // add Draggable events
  1682. initResizable(pane);
  1683. // ADD CLASSNAMES & SLIDE-BINDINGS - eg: class="resizer resizer-west resizer-open"
  1684. if (s.isVisible)
  1685. setAsOpen(pane); // onOpen will be called, but NOT onResize
  1686. else {
  1687. setAsClosed(pane); // onClose will be called
  1688. bindStartSlidingEvent(pane, true); // will enable events IF option is set
  1689. }
  1690. });
  1691. // SET ALL HANDLE DIMENSIONS
  1692. sizeHandles("all");
  1693. };
  1694. /**
  1695. * Initialize scrolling ui-layout-content div - if exists
  1696. *
  1697. * @see initPane() - or externally after an Ajax injection
  1698. * @param {string} pane The pane to process
  1699. * @param {boolean=} resize Size content after init, default = true
  1700. */
  1701. var initContent = function (pane, resize) {
  1702. var
  1703. o = options[pane]
  1704. , sel = o.contentSelector
  1705. , $P = $Ps[pane]
  1706. , $C
  1707. ;
  1708. if (sel) $C = $Cs[pane] = (o.findNestedContent)
  1709. ? $P.find(sel).eq(0) // match 1-element only
  1710. : $P.children(sel).eq(0)
  1711. ;
  1712. if ($C && $C.length) {
  1713. $C.css( _c.content.cssReq );
  1714. if (o.applyDemoStyles) {
  1715. $C.css( _c.content.cssDemo ); // add padding & overflow: auto to content-div
  1716. $P.css( _c.content.cssDemoPane ); // REMOVE padding/scrolling from pane
  1717. }
  1718. state[pane].content = {}; // init content state
  1719. if (resize !== false) sizeContent(pane);
  1720. // sizeContent() is called AFTER init of all elements
  1721. }
  1722. else
  1723. $Cs[pane] = false;
  1724. };
  1725. /**
  1726. * Searches for .ui-layout-button-xxx elements and auto-binds them as layout-buttons
  1727. *
  1728. * @see _create()
  1729. */
  1730. var initButtons = function () {
  1731. var pre = "ui-layout-button-", name;
  1732. $.each("toggle,open,close,pin,toggle-slide,open-slide".split(","), function (i, action) {
  1733. $.each(_c.borderPanes.split(","), function (ii, pane) {
  1734. $("."+pre+action+"-"+pane).each(function(){
  1735. // if button was previously 'bound', data.layoutName was set, but is blank if layout has no 'name'
  1736. name = $(this).data("layoutName") || $(this).attr("layoutName");
  1737. if (name == undefined || name == options.name)
  1738. bindButton(this, action, pane);
  1739. });
  1740. });
  1741. });
  1742. };
  1743. /**
  1744. * Add resize-bars to all panes that specify it in options
  1745. * -dependancy: $.fn.resizable - will skip if not found
  1746. *
  1747. * @see _create()
  1748. * @param {string=} panes The edge(s) to process, blank = all
  1749. */
  1750. var initResizable = function (panes) {
  1751. var
  1752. draggingAvailable = (typeof $.fn.draggable == "function")
  1753. , $Frames, side // set in start()
  1754. ;
  1755. if (!panes || panes == "all") panes = _c.borderPanes;
  1756. $.each(panes.split(","), function (idx, pane) {
  1757. var
  1758. o = options[pane]
  1759. , s = state[pane]
  1760. , c = _c[pane]
  1761. , side = (c.dir=="horz" ? "top" : "left")
  1762. , r, live // set in start because may change
  1763. ;
  1764. if (!draggingAvailable || !$Ps[pane] || !o.resizable) {
  1765. o.resizable = false;
  1766. return true; // skip to next
  1767. }
  1768. var
  1769. $P = $Ps[pane]
  1770. , $R = $Rs[pane]
  1771. , base = o.resizerClass
  1772. // 'drag' classes are applied to the ORIGINAL resizer-bar while dragging is in process
  1773. , resizerClass = base+"-drag" // resizer-drag
  1774. , resizerPaneClass = base+"-"+pane+"-drag" // resizer-north-drag
  1775. // 'helper' class is applied to the CLONED resizer-bar while it is being dragged
  1776. , helperClass = base+"-dragging" // resizer-dragging
  1777. , helperPaneClass = base+"-"+pane+"-dragging" // resizer-north-dragging
  1778. , helperLimitClass = base+"-dragging-limit" // resizer-drag
  1779. , helperClassesSet = false // logic var
  1780. ;
  1781. if (!s.isClosed)
  1782. $R
  1783. .attr("title", o.resizerTip)
  1784. .css("cursor", o.resizerCursor) // n-resize, s-resize, etc
  1785. ;
  1786. $R.bind("mouseenter."+ sID, onResizerEnter)
  1787. .bind("mouseleave."+ sID, onResizerLeave);
  1788. $R.draggable({
  1789. containment: $Container[0] // limit resizing to layout container
  1790. , axis: (c.dir=="horz" ? "y" : "x") // limit resizing to horz or vert axis
  1791. , delay: 0
  1792. , distance: 1
  1793. // basic format for helper - style it using class: .ui-draggable-dragging
  1794. , helper: "clone"
  1795. , opacity: o.resizerDragOpacity
  1796. , addClasses: false // avoid ui-state-disabled class when disabled
  1797. //, iframeFix: o.draggableIframeFix // TODO: consider using when bug is fixed
  1798. , zIndex: _c.zIndex.resizer_drag
  1799. , start: function (e, ui) {
  1800. // REFRESH options & state pointers in case we used swapPanes
  1801. o = options[pane];
  1802. s = state[pane];
  1803. // re-read options
  1804. live = o.resizeWhileDragging;
  1805. // ondrag_start callback - will CANCEL hide if returns false
  1806. // TODO: dragging CANNOT be cancelled like this, so see if there is a way?
  1807. if (false === _execCallback(pane, o.ondrag_start)) return false;
  1808. _c.isLayoutBusy = true; // used by sizePane() logic during a liveResize
  1809. s.isResizing = true; // prevent pane from closing while resizing
  1810. timer.clear(pane+"_closeSlider"); // just in case already triggered
  1811. // SET RESIZER LIMITS - used in drag()
  1812. setSizeLimits(pane); // update pane/resizer state
  1813. r = s.resizerPosition;
  1814. $R.addClass( resizerClass +" "+ resizerPaneClass ); // add drag classes
  1815. helperClassesSet = false; // reset logic var - see drag()
  1816. // MASK PANES WITH IFRAMES OR OTHER TROUBLESOME ELEMENTS
  1817. $Frames = $(o.maskIframesOnResize === true ? "iframe" : o.maskIframesOnResize).filter(":visible");
  1818. var id, i=0; // ID incrementer - used when 'resizing' masks during dynamic resizing
  1819. $Frames.each(function() {
  1820. id = "ui-layout-mask-"+ (++i);
  1821. $(this).data("layoutMaskID", id); // tag iframe with corresponding maskID
  1822. $('<div id="'+ id +'" class="ui-layout-mask ui-layout-mask-'+ pane +'"/>')
  1823. .css({
  1824. background: "#fff"
  1825. , opacity: "0.001"
  1826. , zIndex: _c.zIndex.iframe_mask
  1827. , position: "absolute"
  1828. , width: this.offsetWidth+"px"
  1829. , height: this.offsetHeight+"px"
  1830. })
  1831. .css($(this).position()) // top & left -- changed from offset()
  1832. .appendTo(this.parentNode) // put mask-div INSIDE pane to avoid zIndex issues
  1833. ;
  1834. });
  1835. // DISABLE TEXT SELECTION (though probably was already by resizer.mouseOver)
  1836. $('body').disableSelection();
  1837. }
  1838. , drag: function (e, ui) {
  1839. if (!helperClassesSet) { // can only add classes after clone has been added to the DOM
  1840. //$(".ui-draggable-dragging")
  1841. ui.helper
  1842. .addClass( helperClass +" "+ helperPaneClass ) // add helper classes
  1843. .children().css("visibility","hidden") // hide toggler inside dragged resizer-bar
  1844. ;
  1845. helperClassesSet = true;
  1846. // draggable bug!? RE-SET zIndex to prevent E/W resize-bar showing through N/S pane!
  1847. if (s.isSliding) $Ps[pane].css("zIndex", _c.zIndex.pane_sliding);
  1848. }
  1849. // CONTAIN RESIZER-BAR TO RESIZING LIMITS
  1850. var limit = 0;
  1851. if (ui.position[side] < r.min) {
  1852. ui.position[side] = r.min;
  1853. limit = -1;
  1854. }
  1855. else if (ui.position[side] > r.max) {
  1856. ui.position[side] = r.max;
  1857. limit = 1;
  1858. }
  1859. // ADD/REMOVE dragging-limit CLASS
  1860. if (limit) {
  1861. ui.helper.addClass( helperLimitClass ); // at dragging-limit
  1862. window.defaultStatus = "Panel has reached its " +
  1863. ((limit>0 && pane.match(/north|west/)) || (limit<0 && pane.match(/south|east/)) ? "maximum" : "minimum") +" size";
  1864. }
  1865. else {
  1866. ui.helper.removeClass( helperLimitClass ); // not at dragging-limit
  1867. window.defaultStatus = "";
  1868. }
  1869. // DYNAMICALLY RESIZE PANES IF OPTION ENABLED
  1870. if (live) resizePanes(e, ui, pane);
  1871. }
  1872. , stop: function (e, ui) {
  1873. // RE-ENABLE TEXT SELECTION
  1874. $('body').enableSelection();
  1875. window.defaultStatus = ""; // clear 'resizing limit' message from statusbar
  1876. $R.removeClass( resizerClass +" "+ resizerPaneClass +" "+ helperLimitClass ); // remove drag classes from Resizer
  1877. s.isResizing = false;
  1878. _c.isLayoutBusy = false; // set BEFORE resizePanes so other logic can pick it up
  1879. resizePanes(e, ui, pane, true); // true = resizingDone
  1880. }
  1881. });
  1882. /**
  1883. * resizePanes
  1884. *
  1885. * Sub-routine called from stop() and optionally drag()
  1886. *
  1887. * @param {!Object} evt
  1888. * @param {!Object} ui
  1889. * @param {string} pane
  1890. * @param {boolean=} resizingDone
  1891. */
  1892. var resizePanes = function (evt, ui, pane, resizingDone) {
  1893. var
  1894. dragPos = ui.position
  1895. , c = _c[pane]
  1896. , resizerPos, newSize
  1897. , i = 0 // ID incrementer
  1898. ;
  1899. switch (pane) {
  1900. case "north": resizerPos = dragPos.top; break;
  1901. case "west": resizerPos = dragPos.left; break;
  1902. case "south": resizerPos = sC.offsetHeight - dragPos.top - o.spacing_open; break;
  1903. case "east": resizerPos = sC.offsetWidth - dragPos.left - o.spacing_open; break;
  1904. };
  1905. if (resizingDone) {
  1906. // Remove OR Resize MASK(S) created in drag.start
  1907. $("div.ui-layout-mask").each(function() { this.parentNode.removeChild(this); });
  1908. //$("div.ui-layout-mask").remove(); // TODO: Is this less efficient?
  1909. // ondrag_start callback - will CANCEL hide if returns false
  1910. if (false === _execCallback(pane, o.ondrag_end || o.ondrag)) return false;
  1911. }
  1912. else
  1913. $Frames.each(function() {
  1914. $("#"+ $(this).data("layoutMaskID")) // get corresponding mask by ID
  1915. .css($(this).position()) // update top & left
  1916. .css({ // update width & height
  1917. width: this.offsetWidth +"px"
  1918. , height: this.offsetHeight+"px"
  1919. })
  1920. ;
  1921. });
  1922. // remove container margin from resizer position to get the pane size
  1923. newSize = resizerPos - sC["inset"+ c.side];
  1924. manualSizePane(pane, newSize);
  1925. }
  1926. });
  1927. };
  1928. /**
  1929. * Destroy this layout and reset all elements
  1930. */
  1931. var destroy = function () {
  1932. // UNBIND layout events and remove global object
  1933. $(window).unbind("."+ sID);
  1934. $(document).unbind("."+ sID);
  1935. var
  1936. fullPage= (sC.tagName == "BODY")
  1937. // create list of ALL pane-classes that need to be removed
  1938. , _open = "-open"
  1939. , _sliding= "-sliding"
  1940. , _closed = "-closed"
  1941. , $P, root, pRoot, pClasses // loop vars
  1942. ;
  1943. // loop all panes to remove layout classes, attributes and bindings
  1944. $.each(_c.allPanes.split(","), function (i, pane) {
  1945. $P = $Ps[pane];
  1946. if (!$P) return true; // no pane - SKIP
  1947. // REMOVE pane's resizer and toggler elements
  1948. if (pane != "center") {
  1949. if ($Ts[pane]) $Ts[pane].remove();
  1950. $Rs[pane].remove();
  1951. }
  1952. root = options[pane].paneClass; // default="ui-layout-pane"
  1953. pRoot = root +"-"+ pane; // eg: "ui-layout-pane-west"
  1954. pClasses = [ root, root+_open, root+_closed, root+_sliding, // generic classes
  1955. pRoot, pRoot+_open, pRoot+_closed, pRoot+_sliding // pane-specific classes
  1956. ];
  1957. $.merge(pClasses, getHoverClasses($P, true)); // ADD hover-classes
  1958. $P
  1959. .removeClass( pClasses.join(" ") ) // remove ALL pane-classes
  1960. .removeData("layoutRole")
  1961. .removeData("layoutEdge")
  1962. .unbind("."+ sID) // remove ALL Layout events
  1963. // TODO: remove these extra unbind commands when jQuery is fixed
  1964. .unbind("mouseenter")
  1965. .unbind("mouseleave")
  1966. ;
  1967. // do NOT reset CSS if this pane is STILL the container of a nested layout!
  1968. // the nested layout will reset its 'container' when/if it is destroyed
  1969. if (!$P.data("layoutContainer"))
  1970. $P.css( $P.data("layoutCSS") );
  1971. });
  1972. // reset layout-container
  1973. $Container.removeData("layoutContainer");
  1974. // do NOT reset container CSS if is a 'pane' in an outer-layout - ie, THIS layout is 'nested'
  1975. if (!$Container.data("layoutEdge"))
  1976. $Container.css( $Container.data("layoutCSS") ); // RESET CSS
  1977. // for full-page layouts, must also reset the <HTML> CSS
  1978. if (fullPage)
  1979. $("html").css( $("html").data("layoutCSS") ); // RESET CSS
  1980. // trigger state-management and onunload callback
  1981. unload();
  1982. };
  1983. /*
  1984. * ###########################
  1985. * ACTION METHODS
  1986. * ###########################
  1987. */
  1988. /**
  1989. * Completely 'hides' a pane, including its spacing - as if it does not exist
  1990. * The pane is not actually 'removed' from the source, so can use 'show' to un-hide it
  1991. *
  1992. * @param {string} pane The pane being hidden, ie: north, south, east, or west
  1993. * @param {boolean=} noAnimation
  1994. */
  1995. var hide = function (pane, noAnimation) {
  1996. var
  1997. o = options[pane]
  1998. , s = state[pane]
  1999. , $P = $Ps[pane]
  2000. , $R = $Rs[pane]
  2001. ;
  2002. if (!$P || s.isHidden) return; // pane does not exist OR is already hidden
  2003. // onhide_start callback - will CANCEL hide if returns false
  2004. if (state.initialized && false === _execCallback(pane, o.onhide_start)) return;
  2005. s.isSliding = false; // just in case
  2006. // now hide the elements
  2007. if ($R) $R.hide(); // hide resizer-bar
  2008. if (!state.initialized || s.isClosed) {
  2009. s.isClosed = true; // to trigger open-animation on show()
  2010. s.isHidden = true;
  2011. s.isVisible = false;
  2012. $P.hide(); // no animation when loading page
  2013. sizeMidPanes(_c[pane].dir == "horz" ? "all" : "center");
  2014. if (state.initialized || o.triggerEventsOnLoad)
  2015. _execCallback(pane, o.onhide_end || o.onhide);
  2016. }
  2017. else {
  2018. s.isHiding = true; // used by onclose
  2019. close(pane, false, noAnimation); // adjust all panes to fit
  2020. }
  2021. };
  2022. /**
  2023. * Show a hidden pane - show as 'closed' by default unless openPane = true
  2024. *
  2025. * @param {string} pane The pane being opened, ie: north, south, east, or west
  2026. * @param {boolean=} openPane
  2027. * @param {boolean=} noAnimation
  2028. * @param {boolean=} noAlert
  2029. */
  2030. var show = function (pane, openPane, noAnimation, noAlert) {
  2031. var
  2032. o = options[pane]
  2033. , s = state[pane]
  2034. , $P = $Ps[pane]
  2035. , $R = $Rs[pane]
  2036. ;
  2037. if (!$P || !s.isHidden) return; // pane does not exist OR is not hidden
  2038. // onshow_start callback - will CANCEL show if returns false
  2039. if (false === _execCallback(pane, o.onshow_start)) return;
  2040. s.isSliding = false; // just in case
  2041. s.isShowing = true; // used by onopen/onclose
  2042. //s.isHidden = false; - will be set by open/close - if not cancelled
  2043. // now show the elements
  2044. //if ($R) $R.show(); - will be shown by open/close
  2045. if (openPane === false)
  2046. close(pane, true); // true = force
  2047. else
  2048. open(pane, false, noAnimation, noAlert); // adjust all panes to fit
  2049. };
  2050. /**
  2051. * Toggles a pane open/closed by calling either open or close
  2052. *
  2053. * @param {string} pane The pane being toggled, ie: north, south, east, or west
  2054. * @param {boolean=} slide
  2055. */
  2056. var toggle = function (pane, slide) {
  2057. if (!isStr(pane)) {
  2058. pane.stopImmediatePropagation(); // pane = event
  2059. pane = $(this).data("layoutEdge"); // bound to $R.dblclick
  2060. }
  2061. var s = state[str(pane)];
  2062. if (s.isHidden)
  2063. show(pane); // will call 'open' after unhiding it
  2064. else if (s.isClosed)
  2065. open(pane, !!slide);
  2066. else
  2067. close(pane);
  2068. };
  2069. /**
  2070. * Utility method used during init or other auto-processes
  2071. *
  2072. * @param {string} pane The pane being closed
  2073. * @param {boolean=} setHandles
  2074. */
  2075. var _closePane = function (pane, setHandles) {
  2076. var
  2077. $P = $Ps[pane]
  2078. , s = state[pane]
  2079. ;
  2080. $P.hide();
  2081. s.isClosed = true;
  2082. s.isVisible = false;
  2083. // UNUSED: if (setHandles) setAsClosed(pane, true); // true = force
  2084. };
  2085. /**
  2086. * Close the specified pane (animation optional), and resize all other panes as needed
  2087. *
  2088. * @param {string} pane The pane being closed, ie: north, south, east, or west
  2089. * @param {boolean=} force
  2090. * @param {boolean=} noAnimation
  2091. * @param {boolean=} skipCallback
  2092. */
  2093. var close = function (pane, force, noAnimation, skipCallback) {
  2094. if (!state.initialized) {
  2095. _closePane(pane)
  2096. return;
  2097. }
  2098. var
  2099. $P = $Ps[pane]
  2100. , $R = $Rs[pane]
  2101. , $T = $Ts[pane]
  2102. , o = options[pane]
  2103. , s = state[pane]
  2104. , doFX = !noAnimation && !s.isClosed && (o.fxName_close != "none")
  2105. // transfer logic vars to temp vars
  2106. , isShowing = s.isShowing
  2107. , isHiding = s.isHiding
  2108. , wasSliding = s.isSliding
  2109. ;
  2110. // now clear the logic vars
  2111. delete s.isShowing;
  2112. delete s.isHiding;
  2113. if (!$P || (!o.closable && !isShowing && !isHiding)) return; // invalid request // (!o.resizable && !o.closable) ???
  2114. else if (!force && s.isClosed && !isShowing) return; // already closed
  2115. if (_c.isLayoutBusy) { // layout is 'busy' - probably with an animation
  2116. _queue("close", pane, force); // set a callback for this action, if possible
  2117. return; // ABORT
  2118. }
  2119. // onclose_start callback - will CANCEL hide if returns false
  2120. // SKIP if just 'showing' a hidden pane as 'closed'
  2121. if (!isShowing && false === _execCallback(pane, o.onclose_start)) return;
  2122. // SET flow-control flags
  2123. _c[pane].isMoving = true;
  2124. _c.isLayoutBusy = true;
  2125. s.isClosed = true;
  2126. s.isVisible = false;
  2127. // update isHidden BEFORE sizing panes
  2128. if (isHiding) s.isHidden = true;
  2129. else if (isShowing) s.isHidden = false;
  2130. if (s.isSliding) // pane is being closed, so UNBIND trigger events
  2131. bindStopSlidingEvents(pane, false); // will set isSliding=false
  2132. else // resize panes adjacent to this one
  2133. sizeMidPanes(_c[pane].dir == "horz" ? "all" : "center", false); // false = NOT skipCallback
  2134. // if this pane has a resizer bar, move it NOW - before animation
  2135. setAsClosed(pane);
  2136. // CLOSE THE PANE
  2137. if (doFX) { // animate the close
  2138. lockPaneForFX(pane, true); // need to set left/top so animation will work
  2139. $P.hide( o.fxName_close, o.fxSettings_close, o.fxSpeed_close, function () {
  2140. lockPaneForFX(pane, false); // undo
  2141. close_2();
  2142. });
  2143. }
  2144. else { // hide the pane without animation
  2145. $P.hide();
  2146. close_2();
  2147. };
  2148. // SUBROUTINE
  2149. function close_2 () {
  2150. if (s.isClosed) { // make sure pane was not 'reopened' before animation finished!
  2151. bindStartSlidingEvent(pane, true); // will enable if o.slidable = true
  2152. // if opposite-pane was autoClosed, see if it can be autoOpened now
  2153. var altPane = _c.altSide[pane];
  2154. if (state[ altPane ].noRoom) {
  2155. setSizeLimits( altPane );
  2156. makePaneFit( altPane );
  2157. }
  2158. if (!skipCallback && (state.initialized || o.triggerEventsOnLoad)) {
  2159. // onclose callback - UNLESS just 'showing' a hidden pane as 'closed'
  2160. if (!isShowing) _execCallback(pane, o.onclose_end || o.onclose);
  2161. // onhide OR onshow callback
  2162. if (isShowing) _execCallback(pane, o.onshow_end || o.onshow);
  2163. if (isHiding) _execCallback(pane, o.onhide_end || o.onhide);
  2164. }
  2165. }
  2166. // execute internal flow-control callback
  2167. _dequeue(pane);
  2168. }
  2169. };
  2170. /**
  2171. * @param {string} pane The pane just closed, ie: north, south, east, or west
  2172. */
  2173. var setAsClosed = function (pane) {
  2174. var
  2175. $P = $Ps[pane]
  2176. , $R = $Rs[pane]
  2177. , $T = $Ts[pane]
  2178. , o = options[pane]
  2179. , s = state[pane]
  2180. , side = _c[pane].side.toLowerCase()
  2181. , inset = "inset"+ _c[pane].side
  2182. , rClass = o.resizerClass
  2183. , tClass = o.togglerClass
  2184. , _pane = "-"+ pane // used for classNames
  2185. , _open = "-open"
  2186. , _sliding= "-sliding"
  2187. , _closed = "-closed"
  2188. ;
  2189. $R
  2190. .css(side, sC[inset]) // move the resizer
  2191. .removeClass( rClass+_open +" "+ rClass+_pane+_open )
  2192. .removeClass( rClass+_sliding +" "+ rClass+_pane+_sliding )
  2193. .addClass( rClass+_closed +" "+ rClass+_pane+_closed )
  2194. .unbind("dblclick."+ sID)
  2195. ;
  2196. // DISABLE 'resizing' when closed - do this BEFORE bindStartSlidingEvent?
  2197. if (o.resizable && typeof $.fn.draggable == "function")
  2198. $R
  2199. .draggable("disable")
  2200. .removeClass("ui-state-disabled") // do NOT apply disabled styling - not suitable here
  2201. .css("cursor", "default")
  2202. .attr("title","")
  2203. ;
  2204. // if pane has a toggler button, adjust that too
  2205. if ($T) {
  2206. $T
  2207. .removeClass( tClass+_open +" "+ tClass+_pane+_open )
  2208. .addClass( tClass+_closed +" "+ tClass+_pane+_closed )
  2209. .attr("title", o.togglerTip_closed) // may be blank
  2210. ;
  2211. // toggler-content - if exists
  2212. $T.children(".content-open").hide();
  2213. $T.children(".content-closed").css("display","block");
  2214. }
  2215. // sync any 'pin buttons'
  2216. syncPinBtns(pane, false);
  2217. if (state.initialized) {
  2218. // resize 'length' and position togglers for adjacent panes
  2219. sizeHandles("all");
  2220. }
  2221. };
  2222. /**
  2223. * Open the specified pane (animation optional), and resize all other panes as needed
  2224. *
  2225. * @param {string} pane The pane being opened, ie: north, south, east, or west
  2226. * @param {boolean=} slide
  2227. * @param {boolean=} noAnimation
  2228. * @param {boolean=} noAlert
  2229. */
  2230. var open = function (pane, slide, noAnimation, noAlert) {
  2231. var
  2232. $P = $Ps[pane]
  2233. , $R = $Rs[pane]
  2234. , $T = $Ts[pane]
  2235. , o = options[pane]
  2236. , s = state[pane]
  2237. , doFX = !noAnimation && s.isClosed && (o.fxName_open != "none")
  2238. // transfer logic var to temp var
  2239. , isShowing = s.isShowing
  2240. ;
  2241. // now clear the logic var
  2242. delete s.isShowing;
  2243. if (!$P || (!o.resizable && !o.closable && !isShowing)) return; // invalid request
  2244. else if (s.isVisible && !s.isSliding) return; // already open
  2245. // pane can ALSO be unhidden by just calling show(), so handle this scenario
  2246. if (s.isHidden && !isShowing) {
  2247. show(pane, true);
  2248. return;
  2249. }
  2250. if (_c.isLayoutBusy) { // layout is 'busy' - probably with an animation
  2251. _queue("open", pane, slide); // set a callback for this action, if possible
  2252. return; // ABORT
  2253. }
  2254. // onopen_start callback - will CANCEL hide if returns false
  2255. if (false === _execCallback(pane, o.onopen_start)) return;
  2256. // make sure there is enough space available to open the pane
  2257. setSizeLimits(pane, slide); // update pane-state
  2258. if (s.minSize > s.maxSize) { // INSUFFICIENT ROOM FOR PANE TO OPEN!
  2259. syncPinBtns(pane, false); // make sure pin-buttons are reset
  2260. if (!noAlert && o.noRoomToOpenTip) alert(o.noRoomToOpenTip);
  2261. return; // ABORT
  2262. }
  2263. // SET flow-control flags
  2264. _c[pane].isMoving = true;
  2265. _c.isLayoutBusy = true;
  2266. if (slide) // START Sliding - will set isSliding=true
  2267. bindStopSlidingEvents(pane, true); // BIND trigger events to close sliding-pane
  2268. else if (s.isSliding) // PIN PANE (stop sliding) - open pane 'normally' instead
  2269. bindStopSlidingEvents(pane, false); // UNBIND trigger events - will set isSliding=false
  2270. else if (o.slidable)
  2271. bindStartSlidingEvent(pane, false); // UNBIND trigger events
  2272. s.noRoom = false; // will be reset by makePaneFit if 'noRoom'
  2273. makePaneFit(pane);
  2274. s.isVisible = true;
  2275. s.isClosed = false;
  2276. // update isHidden BEFORE sizing panes - WHY??? Old?
  2277. if (isShowing) s.isHidden = false;
  2278. if (doFX) { // ANIMATE
  2279. lockPaneForFX(pane, true); // need to set left/top so animation will work
  2280. $P.show( o.fxName_open, o.fxSettings_open, o.fxSpeed_open, function() {
  2281. lockPaneForFX(pane, false); // undo
  2282. open_2(); // continue
  2283. });
  2284. }
  2285. else {// no animation
  2286. $P.show(); // just show pane and...
  2287. open_2(); // continue
  2288. };
  2289. // SUBROUTINE
  2290. function open_2 () {
  2291. if (s.isVisible) { // make sure pane was not closed or hidden before animation finished!
  2292. // cure iframe display issues
  2293. _fixIframe(pane);
  2294. // NOTE: if isSliding, then other panes are NOT 'resized'
  2295. if (!s.isSliding) // resize all panes adjacent to this one
  2296. sizeMidPanes(_c[pane].dir=="vert" ? "center" : "all", false); // false = NOT skipCallback
  2297. // set classes, position handles and execute callbacks...
  2298. setAsOpen(pane);
  2299. }
  2300. // internal flow-control callback
  2301. _dequeue(pane);
  2302. };
  2303. };
  2304. /**
  2305. * @param {string} pane The pane just opened, ie: north, south, east, or west
  2306. * @param {boolean=} skipCallback
  2307. */
  2308. var setAsOpen = function (pane, skipCallback) {
  2309. var
  2310. $P = $Ps[pane]
  2311. , $R = $Rs[pane]
  2312. , $T = $Ts[pane]
  2313. , o = options[pane]
  2314. , s = state[pane]
  2315. , side = _c[pane].side.toLowerCase()
  2316. , inset = "inset"+ _c[pane].side
  2317. , rClass = o.resizerClass
  2318. , tClass = o.togglerClass
  2319. , _pane = "-"+ pane // used for classNames
  2320. , _open = "-open"
  2321. , _closed = "-closed"
  2322. , _sliding= "-sliding"
  2323. ;
  2324. $R
  2325. .css(side, sC[inset] + getPaneSize(pane)) // move the resizer
  2326. .removeClass( rClass+_closed +" "+ rClass+_pane+_closed )
  2327. .addClass( rClass+_open +" "+ rClass+_pane+_open )
  2328. ;
  2329. if (s.isSliding)
  2330. $R.addClass( rClass+_sliding +" "+ rClass+_pane+_sliding )
  2331. else // in case 'was sliding'
  2332. $R.removeClass( rClass+_sliding +" "+ rClass+_pane+_sliding )
  2333. if (o.resizerDblClickToggle)
  2334. $R.bind("dblclick", toggle );
  2335. removeHover( 0, $R ); // remove hover classes
  2336. if (o.resizable && typeof $.fn.draggable == "function")
  2337. $R
  2338. .draggable("enable")
  2339. .css("cursor", o.resizerCursor)
  2340. .attr("title", o.resizerTip)
  2341. ;
  2342. else if (!s.isSliding)
  2343. $R.css("cursor", "default"); // n-resize, s-resize, etc
  2344. // if pane also has a toggler button, adjust that too
  2345. if ($T) {
  2346. $T
  2347. .removeClass( tClass+_closed +" "+ tClass+_pane+_closed )
  2348. .addClass( tClass+_open +" "+ tClass+_pane+_open )
  2349. .attr("title", o.togglerTip_open) // may be blank
  2350. ;
  2351. removeHover( 0, $T ); // remove hover classes
  2352. // toggler-content - if exists
  2353. $T.children(".content-closed").hide();
  2354. $T.children(".content-open").css("display","block");
  2355. }
  2356. // sync any 'pin buttons'
  2357. syncPinBtns(pane, !s.isSliding);
  2358. // update pane-state dimensions - BEFORE resizing content
  2359. $.extend(s, getElemDims($P));
  2360. if (state.initialized) {
  2361. // resize resizer & toggler sizes for all panes
  2362. sizeHandles("all");
  2363. // resize content every time pane opens - to be sure
  2364. sizeContent(pane, true); // true = remeasure headers/footers, even if 'isLayoutBusy'
  2365. }
  2366. if (!skipCallback && (state.initialized || o.triggerEventsOnLoad) && $P.is(":visible")) {
  2367. // onopen callback
  2368. _execCallback(pane, o.onopen_end || o.onopen);
  2369. // onshow callback - TODO: should this be here?
  2370. if (s.isShowing) _execCallback(pane, o.onshow_end || o.onshow);
  2371. // ALSO call onresize because layout-size *may* have changed while pane was closed
  2372. if (state.initialized) {
  2373. _execCallback(pane, o.onresize_end || o.onresize);
  2374. resizeNestedLayout(pane);
  2375. }
  2376. }
  2377. };
  2378. /**
  2379. * slideOpen / slideClose / slideToggle
  2380. *
  2381. * Pass-though methods for sliding
  2382. */
  2383. var slideOpen = function (evt_or_pane) {
  2384. var
  2385. type = typeof evt_or_pane
  2386. , pane = (type == "string" ? evt_or_pane : $(this).data("layoutEdge"))
  2387. ;
  2388. // prevent event from triggering on NEW resizer binding created below
  2389. if (type == "object") { evt_or_pane.stopImmediatePropagation(); }
  2390. if (state[pane].isClosed)
  2391. open(pane, true); // true = slide - ie, called from here!
  2392. else // skip 'open' if already open! // TODO: does this use-case make sense???
  2393. bindStopSlidingEvents(pane, true); // BIND trigger events to close sliding-pane
  2394. };
  2395. var slideClose = function (evt_or_pane) {
  2396. var
  2397. evt = isStr(evt_or_pane) ? null : evt_or_pane
  2398. $E = (evt ? $(this) : $Ps[evt_or_pane])
  2399. , pane= $E.data("layoutEdge")
  2400. , o = options[pane]
  2401. , s = state[pane]
  2402. , $P = $Ps[pane]
  2403. ;
  2404. if (s.isClosed || s.isResizing)
  2405. return; // skip if already closed OR in process of resizing
  2406. else if (o.slideTrigger_close == "click")
  2407. close_NOW(); // close immediately onClick
  2408. else if (o.preventQuickSlideClose && _c.isLayoutBusy)
  2409. return; // handle Chrome quick-close on slide-open
  2410. else if (o.preventPrematureSlideClose && evt && $.layout.isMouseOverElem(evt, $P))
  2411. return; // handle incorrect mouseleave trigger, like when over a SELECT-list in IE
  2412. else if (evt) // trigger = mouseleave - use a delay
  2413. timer.set(pane+"_closeSlider", close_NOW, _c[pane].isMoving ? 1000 : 300); // 1 sec delay if 'opening', else .3 sec
  2414. else // called programically
  2415. close_NOW();
  2416. /**
  2417. * SUBROUTINE for timed close
  2418. *
  2419. * @param {Object=} evt
  2420. */
  2421. function close_NOW (evt) {
  2422. if (s.isClosed) // skip 'close' if already closed!
  2423. bindStopSlidingEvents(pane, false); // UNBIND trigger events
  2424. else if (!_c[pane].isMoving)
  2425. close(pane); // close will handle unbinding
  2426. };
  2427. };
  2428. var slideToggle = function (pane) { toggle(pane, true); };
  2429. /**
  2430. * Must set left/top on East/South panes so animation will work properly
  2431. *
  2432. * @param {string} pane The pane to lock, 'east' or 'south' - any other is ignored!
  2433. * @param {boolean} doLock true = set left/top, false = remove
  2434. */
  2435. var lockPaneForFX = function (pane, doLock) {
  2436. var $P = $Ps[pane];
  2437. if (doLock) {
  2438. $P.css({ zIndex: _c.zIndex.pane_animate }); // overlay all elements during animation
  2439. if (pane=="south")
  2440. $P.css({ top: sC.insetTop + sC.innerHeight - $P.outerHeight() });
  2441. else if (pane=="east")
  2442. $P.css({ left: sC.insetLeft + sC.innerWidth - $P.outerWidth() });
  2443. }
  2444. else { // animation DONE - RESET CSS
  2445. // TODO: see if this can be deleted. It causes a quick-close when sliding in Chrome
  2446. $P.css({ zIndex: (state[pane].isSliding ? _c.zIndex.pane_sliding : _c.zIndex.pane_normal) });
  2447. if (pane=="south")
  2448. $P.css({ top: "auto" });
  2449. else if (pane=="east")
  2450. $P.css({ left: "auto" });
  2451. // fix anti-aliasing in IE - only needed for animations that change opacity
  2452. var o = options[pane];
  2453. if (state.browser.msie && o.fxOpacityFix && o.fxName_open != "slide" && $P.css("filter") && $P.css("opacity") == 1)
  2454. $P[0].style.removeAttribute('filter');
  2455. }
  2456. };
  2457. /**
  2458. * Toggle sliding functionality of a specific pane on/off by adding removing 'slide open' trigger
  2459. *
  2460. * @see open(), close()
  2461. * @param {string} pane The pane to enable/disable, 'north', 'south', etc.
  2462. * @param {boolean} enable Enable or Disable sliding?
  2463. */
  2464. var bindStartSlidingEvent = function (pane, enable) {
  2465. var
  2466. o = options[pane]
  2467. , $P = $Ps[pane]
  2468. , $R = $Rs[pane]
  2469. , trigger = o.slideTrigger_open
  2470. ;
  2471. if (!$R || (enable && !o.slidable)) return;
  2472. // make sure we have a valid event
  2473. if (trigger.match(/mouseover/))
  2474. trigger = o.slideTrigger_open = "mouseenter";
  2475. else if (!trigger.match(/click|dblclick|mouseenter/))
  2476. trigger = o.slideTrigger_open = "click";
  2477. $R
  2478. // add or remove trigger event
  2479. [enable ? "bind" : "unbind"](trigger +'.'+ sID, slideOpen)
  2480. // set the appropriate cursor & title/tip
  2481. .css("cursor", enable ? o.sliderCursor : "default")
  2482. .attr("title", enable ? o.sliderTip : "")
  2483. ;
  2484. };
  2485. /**
  2486. * Add or remove 'mouseleave' events to 'slide close' when pane is 'sliding' open or closed
  2487. * Also increases zIndex when pane is sliding open
  2488. * See bindStartSlidingEvent for code to control 'slide open'
  2489. *
  2490. * @see slideOpen(), slideClose()
  2491. * @param {string} pane The pane to process, 'north', 'south', etc.
  2492. * @param {boolean} enable Enable or Disable events?
  2493. */
  2494. var bindStopSlidingEvents = function (pane, enable) {
  2495. var
  2496. o = options[pane]
  2497. , s = state[pane]
  2498. , z = _c.zIndex
  2499. , trigger = o.slideTrigger_close
  2500. , action = (enable ? "bind" : "unbind")
  2501. , $P = $Ps[pane]
  2502. , $R = $Rs[pane]
  2503. ;
  2504. s.isSliding = enable; // logic
  2505. timer.clear(pane+"_closeSlider"); // just in case
  2506. // remove 'slideOpen' trigger event from resizer
  2507. // ALSO will raise the zIndex of the pane & resizer
  2508. if (enable) bindStartSlidingEvent(pane, false);
  2509. // RE/SET zIndex - increases when pane is sliding-open, resets to normal when not
  2510. $P.css("zIndex", enable ? z.pane_sliding : z.pane_normal);
  2511. $R.css("zIndex", enable ? z.pane_sliding : z.resizer_normal);
  2512. // make sure we have a valid event
  2513. if (!trigger.match(/click|mouseleave/))
  2514. trigger = o.slideTrigger_close = "mouseleave"; // also catches 'mouseout'
  2515. // add/remove slide triggers
  2516. $R[action](trigger, slideClose); // base event on resize
  2517. // need extra events for mouseleave
  2518. if (trigger == "mouseleave") {
  2519. // also close on pane.mouseleave
  2520. $P[action]("mouseleave."+ sID, slideClose);
  2521. // cancel timer when mouse moves between 'pane' and 'resizer'
  2522. $R[action]("mouseenter."+ sID, cancelMouseOut);
  2523. $P[action]("mouseenter."+ sID, cancelMouseOut);
  2524. }
  2525. if (!enable)
  2526. timer.clear(pane+"_closeSlider");
  2527. else if (trigger == "click" && !o.resizable) {
  2528. // IF pane is not resizable (which already has a cursor and tip)
  2529. // then set the a cursor & title/tip on resizer when sliding
  2530. $R.css("cursor", enable ? o.sliderCursor : "default");
  2531. $R.attr("title", enable ? o.togglerTip_open : ""); // use Toggler-tip, eg: "Close Pane"
  2532. }
  2533. // SUBROUTINE for mouseleave timer clearing
  2534. function cancelMouseOut (evt) {
  2535. timer.clear(pane+"_closeSlider");
  2536. evt.stopPropagation();
  2537. }
  2538. };
  2539. /**
  2540. * Hides/closes a pane if there is insufficient room - reverses this when there is room again
  2541. * MUST have already called setSizeLimits() before calling this method
  2542. *
  2543. * @param {string} pane The pane being resized
  2544. * @param {boolean=} isOpening Called from onOpen?
  2545. * @param {boolean=} skipCallback Should the onresize callback be run?
  2546. * @param {boolean=} force
  2547. */
  2548. var makePaneFit = function (pane, isOpening, skipCallback, force) {
  2549. var
  2550. o = options[pane]
  2551. , s = state[pane]
  2552. , c = _c[pane]
  2553. , $P = $Ps[pane]
  2554. , $R = $Rs[pane]
  2555. , isSidePane = c.dir=="vert"
  2556. , hasRoom = false
  2557. ;
  2558. // special handling for center pane
  2559. if (pane == "center" || (isSidePane && s.noVerticalRoom)) {
  2560. // see if there is enough room to display the center-pane
  2561. hasRoom = s.minHeight <= s.maxHeight && (isSidePane || s.minWidth <= s.maxWidth);
  2562. if (hasRoom && s.noRoom) { // previously hidden due to noRoom, so show now
  2563. $P.show();
  2564. if ($R) $R.show();
  2565. s.isVisible = true;
  2566. s.noRoom = false;
  2567. if (isSidePane) s.noVerticalRoom = false;
  2568. _fixIframe(pane);
  2569. }
  2570. else if (!hasRoom && !s.noRoom) { // not currently hidden, so hide now
  2571. $P.hide();
  2572. if ($R) $R.hide();
  2573. s.isVisible = false;
  2574. s.noRoom = true;
  2575. }
  2576. }
  2577. // see if there is enough room to fit the border-pane
  2578. if (pane == "center") {
  2579. // ignore center in this block
  2580. }
  2581. else if (s.minSize <= s.maxSize) { // pane CAN fit
  2582. hasRoom = true;
  2583. if (s.size > s.maxSize) // pane is too big - shrink it
  2584. sizePane(pane, s.maxSize, skipCallback, force);
  2585. else if (s.size < s.minSize) // pane is too small - enlarge it
  2586. sizePane(pane, s.minSize, skipCallback, force);
  2587. else if ($R && $P.is(":visible")) {
  2588. // make sure resizer-bar is positioned correctly
  2589. // handles situation where nested layout was 'hidden' when initialized
  2590. var
  2591. side = c.side.toLowerCase()
  2592. , pos = s.size + sC["inset"+ c.side]
  2593. ;
  2594. if (_cssNum($R, side) != pos) $R.css( side, pos );
  2595. }
  2596. // if was previously hidden due to noRoom, then RESET because NOW there is room
  2597. if (s.noRoom) {
  2598. // s.noRoom state will be set by open or show
  2599. if (s.wasOpen && o.closable) {
  2600. if (o.autoReopen)
  2601. open(pane, false, true, true); // true = noAnimation, true = noAlert
  2602. else // leave the pane closed, so just update state
  2603. s.noRoom = false;
  2604. }
  2605. else
  2606. show(pane, s.wasOpen, true, true); // true = noAnimation, true = noAlert
  2607. }
  2608. }
  2609. else { // !hasRoom - pane CANNOT fit
  2610. if (!s.noRoom) { // pane not set as noRoom yet, so hide or close it now...
  2611. s.noRoom = true; // update state
  2612. s.wasOpen = !s.isClosed && !s.isSliding;
  2613. if (s.isClosed){} // SKIP
  2614. else if (o.closable) // 'close' if possible
  2615. close(pane, true, true); // true = force, true = noAnimation
  2616. else // 'hide' pane if cannot just be closed
  2617. hide(pane, true); // true = noAnimation
  2618. }
  2619. }
  2620. };
  2621. /**
  2622. * sizePane / manualSizePane
  2623. * sizePane is called only by internal methods whenever a pane needs to be resized
  2624. * manualSizePane is an exposed flow-through method allowing extra code when pane is 'manually resized'
  2625. *
  2626. * @param {string} pane The pane being resized
  2627. * @param {number} size The *desired* new size for this pane - will be validated
  2628. * @param {boolean=} skipCallback Should the onresize callback be run?
  2629. */
  2630. var manualSizePane = function (pane, size, skipCallback) {
  2631. // ANY call to sizePane will disabled autoResize
  2632. var
  2633. o = options[pane]
  2634. // if resizing callbacks have been delayed and resizing is now DONE, force resizing to complete...
  2635. , forceResize = o.resizeWhileDragging && !_c.isLayoutBusy // && !o.triggerEventsWhileDragging
  2636. ;
  2637. o.autoResize = false;
  2638. // flow-through...
  2639. sizePane(pane, size, skipCallback, forceResize);
  2640. }
  2641. /**
  2642. * @param {string} pane The pane being resized
  2643. * @param {number} size The *desired* new size for this pane - will be validated
  2644. * @param {boolean=} skipCallback Should the onresize callback be run?
  2645. * @param {boolean=} force Force resizing even if does not seem necessary
  2646. */
  2647. var sizePane = function (pane, size, skipCallback, force) {
  2648. var
  2649. o = options[pane]
  2650. , s = state[pane]
  2651. , $P = $Ps[pane]
  2652. , $R = $Rs[pane]
  2653. , side = _c[pane].side.toLowerCase()
  2654. , inset = "inset"+ _c[pane].side
  2655. , skipResizeWhileDragging = _c.isLayoutBusy && !o.triggerEventsWhileDragging
  2656. , oldSize
  2657. ;
  2658. // calculate 'current' min/max sizes
  2659. setSizeLimits(pane); // update pane-state
  2660. oldSize = s.size;
  2661. size = _parseSize(pane, size); // handle percentages & auto
  2662. size = max(size, _parseSize(pane, o.minSize));
  2663. size = min(size, s.maxSize);
  2664. if (size < s.minSize) { // not enough room for pane!
  2665. makePaneFit(pane, false, skipCallback); // will hide or close pane
  2666. return;
  2667. }
  2668. // IF newSize is same as oldSize, then nothing to do - abort
  2669. if (!force && size == oldSize) return;
  2670. // onresize_start callback CANNOT cancel resizing because this would break the layout!
  2671. if (!skipCallback && state.initialized && s.isVisible)
  2672. _execCallback(pane, o.onresize_start);
  2673. // resize the pane, and make sure its visible
  2674. $P.css( _c[pane].sizeType.toLowerCase(), max(1, cssSize(pane, size)) );
  2675. // update pane-state dimensions
  2676. s.size = size;
  2677. $.extend(s, getElemDims($P));
  2678. // reposition the resizer-bar
  2679. if ($R && $P.is(":visible")) $R.css( side, size + sC[inset] );
  2680. sizeContent(pane);
  2681. if (!skipCallback && !skipResizeWhileDragging && state.initialized && s.isVisible) {
  2682. _execCallback(pane, o.onresize_end || o.onresize);
  2683. resizeNestedLayout(pane);
  2684. }
  2685. // resize all the adjacent panes, and adjust their toggler buttons
  2686. // when skipCallback passed, it means the controlling method will handle 'other panes'
  2687. if (!skipCallback) {
  2688. // also no callback if live-resize is in progress and NOT triggerEventsWhileDragging
  2689. if (!s.isSliding) sizeMidPanes(_c[pane].dir=="horz" ? "all" : "center", skipResizeWhileDragging, force);
  2690. sizeHandles("all");
  2691. }
  2692. // if opposite-pane was autoClosed, see if it can be autoOpened now
  2693. var altPane = _c.altSide[pane];
  2694. if (size < oldSize && state[ altPane ].noRoom) {
  2695. setSizeLimits( altPane );
  2696. makePaneFit( altPane, false, skipCallback );
  2697. }
  2698. };
  2699. /**
  2700. * @see initPanes(), sizePane(), resizeAll(), open(), close(), hide()
  2701. * @param {string} panes The pane(s) being resized, comma-delmited string
  2702. * @param {boolean=} skipCallback Should the onresize callback be run?
  2703. * @param {boolean=} force
  2704. */
  2705. var sizeMidPanes = function (panes, skipCallback, force) {
  2706. if (!panes || panes == "all") panes = "east,west,center";
  2707. $.each(panes.split(","), function (i, pane) {
  2708. if (!$Ps[pane]) return; // NO PANE - skip
  2709. var
  2710. o = options[pane]
  2711. , s = state[pane]
  2712. , $P = $Ps[pane]
  2713. , $R = $Rs[pane]
  2714. , isCenter= (pane=="center")
  2715. , hasRoom = true
  2716. , CSS = {}
  2717. , d = calcNewCenterPaneDims()
  2718. ;
  2719. // update pane-state dimensions
  2720. $.extend(s, getElemDims($P));
  2721. if (pane == "center") {
  2722. if (!force && s.isVisible && d.width == s.outerWidth && d.height == s.outerHeight)
  2723. return true; // SKIP - pane already the correct size
  2724. // set state for makePaneFit() logic
  2725. $.extend(s, cssMinDims(pane), {
  2726. maxWidth: d.width
  2727. , maxHeight: d.height
  2728. });
  2729. CSS = d;
  2730. // convert OUTER width/height to CSS width/height
  2731. CSS.width = cssW(pane, d.width);
  2732. CSS.height = cssH(pane, d.height);
  2733. hasRoom = CSS.width > 0 && CSS.height > 0;
  2734. // during layout init, try to shrink east/west panes to make room for center
  2735. if (!hasRoom && !state.initialized && o.minWidth > 0) {
  2736. var
  2737. reqPx = o.minWidth - s.outerWidth
  2738. , minE = options.east.minSize || 0
  2739. , minW = options.west.minSize || 0
  2740. , sizeE = state.east.size
  2741. , sizeW = state.west.size
  2742. , newE = sizeE
  2743. , newW = sizeW
  2744. ;
  2745. if (reqPx > 0 && state.east.isVisible && sizeE > minE) {
  2746. newE = max( sizeE-minE, sizeE-reqPx );
  2747. reqPx -= sizeE-newE;
  2748. }
  2749. if (reqPx > 0 && state.west.isVisible && sizeW > minW) {
  2750. newW = max( sizeW-minW, sizeW-reqPx );
  2751. reqPx -= sizeW-newW;
  2752. }
  2753. // IF we found enough extra space, then resize the border panes as calculated
  2754. if (reqPx == 0) {
  2755. if (sizeE != minE)
  2756. sizePane('east', newE, true); // true = skipCallback - initPanes will handle when done
  2757. if (sizeW != minW)
  2758. sizePane('west', newW, true);
  2759. // now start over!
  2760. sizeMidPanes('center', skipCallback, force);
  2761. return; // abort this loop
  2762. }
  2763. }
  2764. }
  2765. else { // for east and west, set only the height, which is same as center height
  2766. // set state.min/maxWidth/Height for makePaneFit() logic
  2767. if (s.isVisible && !s.noVerticalRoom)
  2768. $.extend(s, getElemDims($P), cssMinDims(pane))
  2769. if (!force && !s.noVerticalRoom && d.height == s.outerHeight)
  2770. return true; // SKIP - pane already the correct size
  2771. CSS.top = d.top;
  2772. CSS.bottom = d.bottom;
  2773. CSS.height = cssH(pane, d.height);
  2774. s.maxHeight = max(0, CSS.height);
  2775. hasRoom = (s.maxHeight > 0);
  2776. if (!hasRoom) s.noVerticalRoom = true; // makePaneFit() logic
  2777. }
  2778. if (hasRoom) {
  2779. // resizeAll passes skipCallback because it triggers callbacks after ALL panes are resized
  2780. if (!skipCallback && state.initialized)
  2781. _execCallback(pane, o.onresize_start);
  2782. $P.css(CSS); // apply the CSS to pane
  2783. if (s.isVisible) {
  2784. $.extend(s, getElemDims($P)); // update pane dimensions
  2785. if (s.noRoom) makePaneFit(pane); // will re-open/show auto-closed/hidden pane
  2786. if (state.initialized) sizeContent(pane); // also resize the contents, if exists
  2787. }
  2788. }
  2789. else if (!s.noRoom && s.isVisible) // no room for pane
  2790. makePaneFit(pane); // will hide or close pane
  2791. /*
  2792. * Extra CSS for IE6 or IE7 in Quirks-mode - add 'width' to NORTH/SOUTH panes
  2793. * Normally these panes have only 'left' & 'right' positions so pane auto-sizes
  2794. * ALSO required when pane is an IFRAME because will NOT default to 'full width'
  2795. */
  2796. if (pane == "center") { // finished processing midPanes
  2797. var b = state.browser;
  2798. var fix = b.isIE6 || (b.msie && !b.boxModel);
  2799. if ($Ps.north && (fix || state.north.tagName=="IFRAME"))
  2800. $Ps.north.css("width", cssW($Ps.north, sC.innerWidth));
  2801. if ($Ps.south && (fix || state.south.tagName=="IFRAME"))
  2802. $Ps.south.css("width", cssW($Ps.south, sC.innerWidth));
  2803. }
  2804. // resizeAll passes skipCallback because it triggers callbacks after ALL panes are resized
  2805. if (!skipCallback && state.initialized && s.isVisible) {
  2806. _execCallback(pane, o.onresize_end || o.onresize);
  2807. resizeNestedLayout(pane);
  2808. }
  2809. });
  2810. };
  2811. /**
  2812. * @see window.onresize(), callbacks or custom code
  2813. */
  2814. var resizeAll = function () {
  2815. var
  2816. oldW = sC.innerWidth
  2817. , oldH = sC.innerHeight
  2818. ;
  2819. $.extend( state.container, getElemDims( $Container ) ); // UPDATE container dimensions
  2820. if (!sC.outerHeight) return; // cannot size layout when 'container' is hidden or collapsed
  2821. // onresizeall_start will CANCEL resizing if returns false
  2822. // state.container has already been set, so user can access this info for calcuations
  2823. if (false === _execCallback(null, options.onresizeall_start)) return false;
  2824. var
  2825. // see if container is now 'smaller' than before
  2826. shrunkH = (sC.innerHeight < oldH)
  2827. , shrunkW = (sC.innerWidth < oldW)
  2828. , $P, o, s, dir
  2829. ;
  2830. // NOTE special order for sizing: S-N-E-W
  2831. $.each(["south","north","east","west"], function (i, pane) {
  2832. if (!$Ps[pane]) return; // no pane - SKIP
  2833. s = state[pane];
  2834. o = options[pane];
  2835. dir = _c[pane].dir;
  2836. if (o.autoResize && s.size != o.size) // resize pane to original size set in options
  2837. sizePane(pane, o.size, true, true); // true=skipCallback, true=forceResize
  2838. else {
  2839. setSizeLimits(pane);
  2840. makePaneFit(pane, false, true, true); // true=skipCallback, true=forceResize
  2841. }
  2842. });
  2843. sizeMidPanes("all", true, true); // true=skipCallback, true=forceResize
  2844. sizeHandles("all"); // reposition the toggler elements
  2845. // trigger all individual pane callbacks AFTER layout has finished resizing
  2846. o = options; // reuse alias
  2847. $.each(_c.allPanes.split(","), function (i, pane) {
  2848. $P = $Ps[pane];
  2849. if (!$P) return; // SKIP
  2850. if (state[pane].isVisible) // undefined for non-existent panes
  2851. _execCallback(pane, o[pane].onresize_end || o[pane].onresize); // callback - if exists
  2852. resizeNestedLayout(pane);
  2853. });
  2854. _execCallback(null, o.onresizeall_end || o.onresizeall); // onresizeall callback, if exists
  2855. };
  2856. /**
  2857. * Whenever a pane resizes or opens that has a nested layout, trigger resizeAll
  2858. *
  2859. * @param {string} pane The pane just resized or opened
  2860. */
  2861. var resizeNestedLayout = function (pane) {
  2862. var
  2863. $P = $Ps[pane]
  2864. , $C = $Cs[pane]
  2865. , d = "layoutContainer"
  2866. ;
  2867. if (options[pane].resizeNestedLayout) {
  2868. if ($P.data( d ))
  2869. $P.layout().resizeAll();
  2870. else if ($C && $C.data( d ))
  2871. $C.layout().resizeAll();
  2872. }
  2873. };
  2874. /**
  2875. * IF pane has a content-div, then resize all elements inside pane to fit pane-height
  2876. *
  2877. * @param {string=} panes The pane(s) being resized
  2878. * @param {boolean=} remeasure Should the content (header/footer) be remeasured?
  2879. */
  2880. var sizeContent = function (panes, remeasure) {
  2881. if (!panes || panes == "all") panes = _c.allPanes;
  2882. $.each(panes.split(","), function (idx, pane) {
  2883. var
  2884. $P = $Ps[pane]
  2885. , $C = $Cs[pane]
  2886. , o = options[pane]
  2887. , s = state[pane]
  2888. , m = s.content // m = measurements
  2889. ;
  2890. if (!$P || !$C || !$P.is(":visible")) return true; // NOT VISIBLE - skip
  2891. // onsizecontent_start will CANCEL resizing if returns false
  2892. if (false === _execCallback(null, o.onsizecontent_start)) return;
  2893. // skip re-measuring offsets if live-resizing
  2894. if (!_c.isLayoutBusy || m.top == undefined || remeasure || o.resizeContentWhileDragging) {
  2895. _measure();
  2896. // if any footers are below pane-bottom, they may not measure correctly,
  2897. // so allow pane overflow and re-measure
  2898. if (m.hiddenFooters > 0 && $P.css("overflow") == "hidden") {
  2899. $P.css("overflow", "visible");
  2900. _measure(); // remeasure while overflowing
  2901. $P.css("overflow", "hidden");
  2902. }
  2903. }
  2904. // NOTE: spaceAbove/Below *includes* the pane's paddingTop/Bottom, but not pane.borders
  2905. var newH = s.innerHeight - (m.spaceAbove - s.css.paddingTop) - (m.spaceBelow - s.css.paddingBottom);
  2906. if (!$C.is(":visible") || m.height != newH) {
  2907. // size the Content element to fit new pane-size - will autoHide if not enough room
  2908. setOuterHeight($C, newH, true); // true=autoHide
  2909. m.height = newH; // save new height
  2910. };
  2911. if (state.initialized) {
  2912. _execCallback(pane, o.onsizecontent_end || o.onsizecontent);
  2913. resizeNestedLayout(pane);
  2914. }
  2915. function _below ($E) {
  2916. return max(s.css.paddingBottom, (parseInt($E.css("marginBottom"), 10) || 0));
  2917. };
  2918. function _measure () {
  2919. var
  2920. ignore = options[pane].contentIgnoreSelector
  2921. , $Fs = $C.nextAll().not(ignore || ':lt(0)') // not :lt(0) = ALL
  2922. , $Fs_vis = $Fs.filter(':visible')
  2923. , $F = $Fs_vis.filter(':last')
  2924. ;
  2925. m = {
  2926. top: $C[0].offsetTop
  2927. , height: $C.outerHeight()
  2928. , numFooters: $Fs.length
  2929. , hiddenFooters: $Fs.length - $Fs_vis.length
  2930. , spaceBelow: 0 // correct if no content footer ($E)
  2931. }
  2932. m.spaceAbove = m.top; // just for state - not used in calc
  2933. m.bottom = m.top + m.height;
  2934. if ($F.length)
  2935. //spaceBelow = (LastFooter.top + LastFooter.height) [footerBottom] - Content.bottom + max(LastFooter.marginBottom, pane.paddingBotom)
  2936. m.spaceBelow = ($F[0].offsetTop + $F.outerHeight()) - m.bottom + _below($F);
  2937. else // no footer - check marginBottom on Content element itself
  2938. m.spaceBelow = _below($C);
  2939. };
  2940. });
  2941. };
  2942. /**
  2943. * Called every time a pane is opened, closed, or resized to slide the togglers to 'center' and adjust their length if necessary
  2944. *
  2945. * @see initHandles(), open(), close(), resizeAll()
  2946. * @param {string=} panes The pane(s) being resized
  2947. */
  2948. var sizeHandles = function (panes) {
  2949. if (!panes || panes == "all") panes = _c.borderPanes;
  2950. $.each(panes.split(","), function (i, pane) {
  2951. var
  2952. o = options[pane]
  2953. , s = state[pane]
  2954. , $P = $Ps[pane]
  2955. , $R = $Rs[pane]
  2956. , $T = $Ts[pane]
  2957. , $TC
  2958. ;
  2959. if (!$P || !$R) return;
  2960. var
  2961. dir = _c[pane].dir
  2962. , _state = (s.isClosed ? "_closed" : "_open")
  2963. , spacing = o["spacing"+ _state]
  2964. , togAlign = o["togglerAlign"+ _state]
  2965. , togLen = o["togglerLength"+ _state]
  2966. , paneLen
  2967. , offset
  2968. , CSS = {}
  2969. ;
  2970. if (spacing == 0) {
  2971. $R.hide();
  2972. return;
  2973. }
  2974. else if (!s.noRoom && !s.isHidden) // skip if resizer was hidden for any reason
  2975. $R.show(); // in case was previously hidden
  2976. // Resizer Bar is ALWAYS same width/height of pane it is attached to
  2977. if (dir == "horz") { // north/south
  2978. paneLen = $P.outerWidth(); // s.outerWidth ||
  2979. s.resizerLength = paneLen;
  2980. $R.css({
  2981. width: max(1, cssW($R, paneLen)) // account for borders & padding
  2982. , height: max(0, cssH($R, spacing)) // ditto
  2983. , left: _cssNum($P, "left")
  2984. });
  2985. }
  2986. else { // east/west
  2987. paneLen = $P.outerHeight(); // s.outerHeight ||
  2988. s.resizerLength = paneLen;
  2989. $R.css({
  2990. height: max(1, cssH($R, paneLen)) // account for borders & padding
  2991. , width: max(0, cssW($R, spacing)) // ditto
  2992. , top: sC.insetTop + getPaneSize("north", true) // TODO: what if no North pane?
  2993. //, top: _cssNum($Ps["center"], "top")
  2994. });
  2995. }
  2996. // remove hover classes
  2997. removeHover( o, $R );
  2998. if ($T) {
  2999. if (togLen == 0 || (s.isSliding && o.hideTogglerOnSlide)) {
  3000. $T.hide(); // always HIDE the toggler when 'sliding'
  3001. return;
  3002. }
  3003. else
  3004. $T.show(); // in case was previously hidden
  3005. if (!(togLen > 0) || togLen == "100%" || togLen > paneLen) {
  3006. togLen = paneLen;
  3007. offset = 0;
  3008. }
  3009. else { // calculate 'offset' based on options.PANE.togglerAlign_open/closed
  3010. if (isStr(togAlign)) {
  3011. switch (togAlign) {
  3012. case "top":
  3013. case "left": offset = 0;
  3014. break;
  3015. case "bottom":
  3016. case "right": offset = paneLen - togLen;
  3017. break;
  3018. case "middle":
  3019. case "center":
  3020. default: offset = Math.floor((paneLen - togLen) / 2); // 'default' catches typos
  3021. }
  3022. }
  3023. else { // togAlign = number
  3024. var x = parseInt(togAlign, 10); //
  3025. if (togAlign >= 0) offset = x;
  3026. else offset = paneLen - togLen + x; // NOTE: x is negative!
  3027. }
  3028. }
  3029. if (dir == "horz") { // north/south
  3030. var width = cssW($T, togLen);
  3031. $T.css({
  3032. width: max(0, width) // account for borders & padding
  3033. , height: max(1, cssH($T, spacing)) // ditto
  3034. , left: offset // TODO: VERIFY that toggler positions correctly for ALL values
  3035. , top: 0
  3036. });
  3037. // CENTER the toggler content SPAN
  3038. $T.children(".content").each(function(){
  3039. $TC = $(this);
  3040. $TC.css("marginLeft", Math.floor((width-$TC.outerWidth())/2)); // could be negative
  3041. });
  3042. }
  3043. else { // east/west
  3044. var height = cssH($T, togLen);
  3045. $T.css({
  3046. height: max(0, height) // account for borders & padding
  3047. , width: max(1, cssW($T, spacing)) // ditto
  3048. , top: offset // POSITION the toggler
  3049. , left: 0
  3050. });
  3051. // CENTER the toggler content SPAN
  3052. $T.children(".content").each(function(){
  3053. $TC = $(this);
  3054. $TC.css("marginTop", Math.floor((height-$TC.outerHeight())/2)); // could be negative
  3055. });
  3056. }
  3057. // remove ALL hover classes
  3058. removeHover( 0, $T );
  3059. }
  3060. // DONE measuring and sizing this resizer/toggler, so can be 'hidden' now
  3061. if (!state.initialized && o.initHidden) {
  3062. $R.hide();
  3063. if ($T) $T.hide();
  3064. }
  3065. });
  3066. };
  3067. var enableClosable = function (pane) {
  3068. var $T = $Ts[pane], o = options[pane];
  3069. if (!$T) return;
  3070. o.closable = true;
  3071. $T .bind("click."+ sID, function(evt){ toggle(pane); evt.stopPropagation(); })
  3072. .bind("mouseenter."+ sID, addHover)
  3073. .bind("mouseleave."+ sID, removeHover)
  3074. .css("visibility", "visible")
  3075. .css("cursor", "pointer")
  3076. .attr("title", state[pane].isClosed ? o.togglerTip_closed : o.togglerTip_open) // may be blank
  3077. .show()
  3078. ;
  3079. };
  3080. var disableClosable = function (pane, hide) {
  3081. var $T = $Ts[pane];
  3082. if (!$T) return;
  3083. options[pane].closable = false;
  3084. // is closable is disable, then pane MUST be open!
  3085. if (state[pane].isClosed) open(pane, false, true);
  3086. $T .unbind("."+ sID)
  3087. .css("visibility", hide ? "hidden" : "visible") // instead of hide(), which creates logic issues
  3088. .css("cursor", "default")
  3089. .attr("title", "")
  3090. ;
  3091. };
  3092. var enableSlidable = function (pane) {
  3093. var $R = $Rs[pane], o = options[pane];
  3094. if (!$R || !$R.data('draggable')) return;
  3095. options[pane].slidable = true;
  3096. if (s.isClosed)
  3097. bindStartSlidingEvent(pane, true);
  3098. };
  3099. var disableSlidable = function (pane) {
  3100. var $R = $Rs[pane];
  3101. if (!$R) return;
  3102. options[pane].slidable = false;
  3103. if (state[pane].isSliding)
  3104. close(pane, false, true);
  3105. else {
  3106. bindStartSlidingEvent(pane, false);
  3107. $R .css("cursor", "default")
  3108. .attr("title", "")
  3109. ;
  3110. removeHover(null, $R[0]); // in case currently hovered
  3111. }
  3112. };
  3113. var enableResizable = function (pane) {
  3114. var $R = $Rs[pane], o = options[pane];
  3115. if (!$R || !$R.data('draggable')) return;
  3116. o.resizable = true;
  3117. $R .draggable("enable")
  3118. .bind("mouseenter."+ sID, onResizerEnter)
  3119. .bind("mouseleave."+ sID, onResizerLeave)
  3120. ;
  3121. if (!state[pane].isClosed)
  3122. $R .css("cursor", o.resizerCursor)
  3123. .attr("title", o.resizerTip)
  3124. ;
  3125. };
  3126. var disableResizable = function (pane) {
  3127. var $R = $Rs[pane];
  3128. if (!$R || !$R.data('draggable')) return;
  3129. options[pane].resizable = false;
  3130. $R .draggable("disable")
  3131. .unbind("."+ sID)
  3132. .css("cursor", "default")
  3133. .attr("title", "")
  3134. ;
  3135. removeHover(null, $R[0]); // in case currently hovered
  3136. };
  3137. /**
  3138. * Move a pane from source-side (eg, west) to target-side (eg, east)
  3139. * If pane exists on target-side, move that to source-side, ie, 'swap' the panes
  3140. *
  3141. * @param {string} pane1 The pane/edge being swapped
  3142. * @param {string} pane2 ditto
  3143. */
  3144. var swapPanes = function (pane1, pane2) {
  3145. // change state.edge NOW so callbacks can know where pane is headed...
  3146. state[pane1].edge = pane2;
  3147. state[pane2].edge = pane1;
  3148. // run these even if NOT state.initialized
  3149. var cancelled = false;
  3150. if (false === _execCallback(pane1, options[pane1].onswap_start)) cancelled = true;
  3151. if (!cancelled && false === _execCallback(pane2, options[pane2].onswap_start)) cancelled = true;
  3152. if (cancelled) {
  3153. state[pane1].edge = pane1; // reset
  3154. state[pane2].edge = pane2;
  3155. return;
  3156. }
  3157. var
  3158. oPane1 = copy( pane1 )
  3159. , oPane2 = copy( pane2 )
  3160. , sizes = {}
  3161. ;
  3162. sizes[pane1] = oPane1 ? oPane1.state.size : 0;
  3163. sizes[pane2] = oPane2 ? oPane2.state.size : 0;
  3164. // clear pointers & state
  3165. $Ps[pane1] = false;
  3166. $Ps[pane2] = false;
  3167. state[pane1] = {};
  3168. state[pane2] = {};
  3169. // ALWAYS remove the resizer & toggler elements
  3170. if ($Ts[pane1]) $Ts[pane1].remove();
  3171. if ($Ts[pane2]) $Ts[pane2].remove();
  3172. if ($Rs[pane1]) $Rs[pane1].remove();
  3173. if ($Rs[pane2]) $Rs[pane2].remove();
  3174. $Rs[pane1] = $Rs[pane2] = $Ts[pane1] = $Ts[pane2] = false;
  3175. // transfer element pointers and data to NEW Layout keys
  3176. move( oPane1, pane2 );
  3177. move( oPane2, pane1 );
  3178. // cleanup objects
  3179. oPane1 = oPane2 = sizes = null;
  3180. // make panes 'visible' again
  3181. if ($Ps[pane1]) $Ps[pane1].css(_c.visible);
  3182. if ($Ps[pane2]) $Ps[pane2].css(_c.visible);
  3183. // fix any size discrepancies caused by swap
  3184. resizeAll();
  3185. // run these even if NOT state.initialized
  3186. _execCallback(pane1, options[pane1].onswap_end || options[pane1].onswap);
  3187. _execCallback(pane2, options[pane2].onswap_end || options[pane2].onswap);
  3188. return;
  3189. function copy (n) { // n = pane
  3190. var
  3191. $P = $Ps[n]
  3192. , $C = $Cs[n]
  3193. ;
  3194. return !$P ? false : {
  3195. pane: n
  3196. , P: $P ? $P[0] : false
  3197. , C: $C ? $C[0] : false
  3198. , state: $.extend({}, state[n])
  3199. , options: $.extend({}, options[n])
  3200. }
  3201. };
  3202. function move (oPane, pane) {
  3203. if (!oPane) return;
  3204. var
  3205. P = oPane.P
  3206. , C = oPane.C
  3207. , oldPane = oPane.pane
  3208. , c = _c[pane]
  3209. , side = c.side.toLowerCase()
  3210. , inset = "inset"+ c.side
  3211. // save pane-options that should be retained
  3212. , s = $.extend({}, state[pane])
  3213. , o = options[pane]
  3214. // RETAIN side-specific FX Settings - more below
  3215. , fx = { resizerCursor: o.resizerCursor }
  3216. , re, size, pos
  3217. ;
  3218. $.each("fxName,fxSpeed,fxSettings".split(","), function (i, k) {
  3219. fx[k] = o[k];
  3220. fx[k +"_open"] = o[k +"_open"];
  3221. fx[k +"_close"] = o[k +"_close"];
  3222. });
  3223. // update object pointers and attributes
  3224. $Ps[pane] = $(P)
  3225. .data("layoutEdge", pane)
  3226. .css(_c.hidden)
  3227. .css(c.cssReq)
  3228. ;
  3229. $Cs[pane] = C ? $(C) : false;
  3230. // set options and state
  3231. options[pane] = $.extend({}, oPane.options, fx);
  3232. state[pane] = $.extend({}, oPane.state);
  3233. // change classNames on the pane, eg: ui-layout-pane-east ==> ui-layout-pane-west
  3234. re = new RegExp(o.paneClass +"-"+ oldPane, "g");
  3235. P.className = P.className.replace(re, o.paneClass +"-"+ pane);
  3236. // ALWAYS regenerate the resizer & toggler elements
  3237. initHandles(pane); // create the required resizer & toggler
  3238. // if moving to different orientation, then keep 'target' pane size
  3239. if (c.dir != _c[oldPane].dir) {
  3240. size = sizes[pane] || 0;
  3241. setSizeLimits(pane); // update pane-state
  3242. size = max(size, state[pane].minSize);
  3243. // use manualSizePane to disable autoResize - not useful after panes are swapped
  3244. manualSizePane(pane, size, true); // true = skipCallback
  3245. }
  3246. else // move the resizer here
  3247. $Rs[pane].css(side, sC[inset] + (state[pane].isVisible ? getPaneSize(pane) : 0));
  3248. // ADD CLASSNAMES & SLIDE-BINDINGS
  3249. if (oPane.state.isVisible && !s.isVisible)
  3250. setAsOpen(pane, true); // true = skipCallback
  3251. else {
  3252. setAsClosed(pane);
  3253. bindStartSlidingEvent(pane, true); // will enable events IF option is set
  3254. }
  3255. // DESTROY the object
  3256. oPane = null;
  3257. };
  3258. };
  3259. /**
  3260. * Capture keys when enableCursorHotkey - toggle pane if hotkey pressed
  3261. *
  3262. * @see document.keydown()
  3263. */
  3264. function keyDown (evt) {
  3265. if (!evt) return true;
  3266. var code = evt.keyCode;
  3267. if (code < 33) return true; // ignore special keys: ENTER, TAB, etc
  3268. var
  3269. PANE = {
  3270. 38: "north" // Up Cursor - $.ui.keyCode.UP
  3271. , 40: "south" // Down Cursor - $.ui.keyCode.DOWN
  3272. , 37: "west" // Left Cursor - $.ui.keyCode.LEFT
  3273. , 39: "east" // Right Cursor - $.ui.keyCode.RIGHT
  3274. }
  3275. , ALT = evt.altKey // no worky!
  3276. , SHIFT = evt.shiftKey
  3277. , CTRL = evt.ctrlKey
  3278. , CURSOR = (CTRL && code >= 37 && code <= 40)
  3279. , o, k, m, pane
  3280. ;
  3281. if (CURSOR && options[PANE[code]].enableCursorHotkey) // valid cursor-hotkey
  3282. pane = PANE[code];
  3283. else if (CTRL || SHIFT) // check to see if this matches a custom-hotkey
  3284. $.each(_c.borderPanes.split(","), function (i, p) { // loop each pane to check its hotkey
  3285. o = options[p];
  3286. k = o.customHotkey;
  3287. m = o.customHotkeyModifier; // if missing or invalid, treated as "CTRL+SHIFT"
  3288. if ((SHIFT && m=="SHIFT") || (CTRL && m=="CTRL") || (CTRL && SHIFT)) { // Modifier matches
  3289. if (k && code == (isNaN(k) || k <= 9 ? k.toUpperCase().charCodeAt(0) : k)) { // Key matches
  3290. pane = p;
  3291. return false; // BREAK
  3292. }
  3293. }
  3294. });
  3295. // validate pane
  3296. if (!pane || !$Ps[pane] || !options[pane].closable || state[pane].isHidden)
  3297. return true;
  3298. toggle(pane);
  3299. evt.stopPropagation();
  3300. evt.returnValue = false; // CANCEL key
  3301. return false;
  3302. };
  3303. /*
  3304. * ######################################
  3305. * UTILITY METHODS
  3306. * called externally or by initButtons
  3307. * ######################################
  3308. */
  3309. /**
  3310. * Change/reset a pane's overflow setting & zIndex to allow popups/drop-downs to work
  3311. *
  3312. * @param {Object=} el (optional) Can also be 'bound' to a click, mouseOver, or other event
  3313. */
  3314. function allowOverflow (el) {
  3315. if (this && this.tagName) el = this; // BOUND to element
  3316. var $P;
  3317. if (isStr(el))
  3318. $P = $Ps[el];
  3319. else if ($(el).data("layoutRole"))
  3320. $P = $(el);
  3321. else
  3322. $(el).parents().each(function(){
  3323. if ($(this).data("layoutRole")) {
  3324. $P = $(this);
  3325. return false; // BREAK
  3326. }
  3327. });
  3328. if (!$P || !$P.length) return; // INVALID
  3329. var
  3330. pane = $P.data("layoutEdge")
  3331. , s = state[pane]
  3332. ;
  3333. // if pane is already raised, then reset it before doing it again!
  3334. // this would happen if allowOverflow is attached to BOTH the pane and an element
  3335. if (s.cssSaved)
  3336. resetOverflow(pane); // reset previous CSS before continuing
  3337. // if pane is raised by sliding or resizing, or it's closed, then abort
  3338. if (s.isSliding || s.isResizing || s.isClosed) {
  3339. s.cssSaved = false;
  3340. return;
  3341. }
  3342. var
  3343. newCSS = { zIndex: (_c.zIndex.pane_normal + 2) }
  3344. , curCSS = {}
  3345. , of = $P.css("overflow")
  3346. , ofX = $P.css("overflowX")
  3347. , ofY = $P.css("overflowY")
  3348. ;
  3349. // determine which, if any, overflow settings need to be changed
  3350. if (of != "visible") {
  3351. curCSS.overflow = of;
  3352. newCSS.overflow = "visible";
  3353. }
  3354. if (ofX && !ofX.match(/visible|auto/)) {
  3355. curCSS.overflowX = ofX;
  3356. newCSS.overflowX = "visible";
  3357. }
  3358. if (ofY && !ofY.match(/visible|auto/)) {
  3359. curCSS.overflowY = ofX;
  3360. newCSS.overflowY = "visible";
  3361. }
  3362. // save the current overflow settings - even if blank!
  3363. s.cssSaved = curCSS;
  3364. // apply new CSS to raise zIndex and, if necessary, make overflow 'visible'
  3365. $P.css( newCSS );
  3366. // make sure the zIndex of all other panes is normal
  3367. $.each(_c.allPanes.split(","), function(i, p) {
  3368. if (p != pane) resetOverflow(p);
  3369. });
  3370. };
  3371. function resetOverflow (el) {
  3372. if (this && this.tagName) el = this; // BOUND to element
  3373. var $P;
  3374. if (isStr(el))
  3375. $P = $Ps[el];
  3376. else if ($(el).data("layoutRole"))
  3377. $P = $(el);
  3378. else
  3379. $(el).parents().each(function(){
  3380. if ($(this).data("layoutRole")) {
  3381. $P = $(this);
  3382. return false; // BREAK
  3383. }
  3384. });
  3385. if (!$P || !$P.length) return; // INVALID
  3386. var
  3387. pane = $P.data("layoutEdge")
  3388. , s = state[pane]
  3389. , CSS = s.cssSaved || {}
  3390. ;
  3391. // reset the zIndex
  3392. if (!s.isSliding && !s.isResizing)
  3393. $P.css("zIndex", _c.zIndex.pane_normal);
  3394. // reset Overflow - if necessary
  3395. $P.css( CSS );
  3396. // clear var
  3397. s.cssSaved = false;
  3398. };
  3399. /**
  3400. * Helper function to validate params received by addButton utilities
  3401. *
  3402. * Two classes are added to the element, based on the buttonClass...
  3403. * The type of button is appended to create the 2nd className:
  3404. * - ui-layout-button-pin
  3405. * - ui-layout-pane-button-toggle
  3406. * - ui-layout-pane-button-open
  3407. * - ui-layout-pane-button-close
  3408. *
  3409. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  3410. * @param {string} pane Name of the pane the button is for: 'north', 'south', etc.
  3411. * @return {Array.<Object>} If both params valid, the element matching 'selector' in a jQuery wrapper - otherwise returns null
  3412. */
  3413. function getBtn (selector, pane, action) {
  3414. var $E = $(selector);
  3415. if (!$E.length) // element not found
  3416. alert(lang.errButton + lang.selector +": "+ selector);
  3417. else if (_c.borderPanes.indexOf(pane) == -1) // invalid 'pane' sepecified
  3418. alert(lang.errButton + lang.Pane.toLowerCase() +": "+ pane);
  3419. else { // VALID
  3420. var btn = options[pane].buttonClass +"-"+ action;
  3421. $E
  3422. .addClass( btn +" "+ btn +"-"+ pane )
  3423. .data("layoutName", options.name) // add layout identifier - even if blank!
  3424. ;
  3425. return $E;
  3426. }
  3427. return null; // INVALID
  3428. };
  3429. /**
  3430. * NEW syntax for binding layout-buttons - will eventually replace addToggleBtn, addOpenBtn, etc.
  3431. *
  3432. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  3433. * @param {string} action
  3434. * @param {string} pane
  3435. */
  3436. function bindButton (selector, action, pane) {
  3437. switch (action.toLowerCase()) {
  3438. case "toggle": addToggleBtn(selector, pane); break;
  3439. case "open": addOpenBtn(selector, pane); break;
  3440. case "close": addCloseBtn(selector, pane); break;
  3441. case "pin": addPinBtn(selector, pane); break;
  3442. case "toggle-slide": addToggleBtn(selector, pane, true); break;
  3443. case "open-slide": addOpenBtn(selector, pane, true); break;
  3444. }
  3445. };
  3446. /**
  3447. * Add a custom Toggler button for a pane
  3448. *
  3449. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  3450. * @param {string} pane Name of the pane the button is for: 'north', 'south', etc.
  3451. * @param {boolean=} slide true = slide-open, false = pin-open
  3452. */
  3453. function addToggleBtn (selector, pane, slide) {
  3454. var $E = getBtn(selector, pane, "toggle");
  3455. if ($E)
  3456. $E.click(function (evt) {
  3457. toggle(pane, !!slide);
  3458. evt.stopPropagation();
  3459. });
  3460. };
  3461. /**
  3462. * Add a custom Open button for a pane
  3463. *
  3464. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  3465. * @param {string} pane Name of the pane the button is for: 'north', 'south', etc.
  3466. * @param {boolean=} slide true = slide-open, false = pin-open
  3467. */
  3468. function addOpenBtn (selector, pane, slide) {
  3469. var $E = getBtn(selector, pane, "open");
  3470. if ($E)
  3471. $E
  3472. .attr("title", lang.Open)
  3473. .click(function (evt) {
  3474. open(pane, !!slide);
  3475. evt.stopPropagation();
  3476. })
  3477. ;
  3478. };
  3479. /**
  3480. * Add a custom Close button for a pane
  3481. *
  3482. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  3483. * @param {string} pane Name of the pane the button is for: 'north', 'south', etc.
  3484. */
  3485. function addCloseBtn (selector, pane) {
  3486. var $E = getBtn(selector, pane, "close");
  3487. if ($E)
  3488. $E
  3489. .attr("title", lang.Close)
  3490. .click(function (evt) {
  3491. close(pane);
  3492. evt.stopPropagation();
  3493. })
  3494. ;
  3495. };
  3496. /**
  3497. * addPinBtn
  3498. *
  3499. * Add a custom Pin button for a pane
  3500. *
  3501. * Four classes are added to the element, based on the paneClass for the associated pane...
  3502. * Assuming the default paneClass and the pin is 'up', these classes are added for a west-pane pin:
  3503. * - ui-layout-pane-pin
  3504. * - ui-layout-pane-west-pin
  3505. * - ui-layout-pane-pin-up
  3506. * - ui-layout-pane-west-pin-up
  3507. *
  3508. * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
  3509. * @param {string} pane Name of the pane the pin is for: 'north', 'south', etc.
  3510. */
  3511. function addPinBtn (selector, pane) {
  3512. var $E = getBtn(selector, pane, "pin");
  3513. if ($E) {
  3514. var s = state[pane];
  3515. $E.click(function (evt) {
  3516. setPinState($(this), pane, (s.isSliding || s.isClosed));
  3517. if (s.isSliding || s.isClosed) open( pane ); // change from sliding to open
  3518. else close( pane ); // slide-closed
  3519. evt.stopPropagation();
  3520. });
  3521. // add up/down pin attributes and classes
  3522. setPinState($E, pane, (!s.isClosed && !s.isSliding));
  3523. // add this pin to the pane data so we can 'sync it' automatically
  3524. // PANE.pins key is an array so we can store multiple pins for each pane
  3525. _c[pane].pins.push( selector ); // just save the selector string
  3526. }
  3527. };
  3528. /**
  3529. * INTERNAL function to sync 'pin buttons' when pane is opened or closed
  3530. * Unpinned means the pane is 'sliding' - ie, over-top of the adjacent panes
  3531. *
  3532. * @see open(), close()
  3533. * @param {string} pane These are the params returned to callbacks by layout()
  3534. * @param {boolean} doPin True means set the pin 'down', False means 'up'
  3535. */
  3536. function syncPinBtns (pane, doPin) {
  3537. $.each(_c[pane].pins, function (i, selector) {
  3538. setPinState($(selector), pane, doPin);
  3539. });
  3540. };
  3541. /**
  3542. * Change the class of the pin button to make it look 'up' or 'down'
  3543. *
  3544. * @see addPinBtn(), syncPinBtns()
  3545. * @param {Array.<Object>} $Pin The pin-span element in a jQuery wrapper
  3546. * @param {string} pane These are the params returned to callbacks by layout()
  3547. * @param {boolean} doPin true = set the pin 'down', false = set it 'up'
  3548. */
  3549. function setPinState ($Pin, pane, doPin) {
  3550. var updown = $Pin.attr("pin");
  3551. if (updown && doPin == (updown=="down")) return; // already in correct state
  3552. var
  3553. pin = options[pane].buttonClass +"-pin"
  3554. , side = pin +"-"+ pane
  3555. , UP = pin +"-up "+ side +"-up"
  3556. , DN = pin +"-down "+side +"-down"
  3557. ;
  3558. $Pin
  3559. .attr("pin", doPin ? "down" : "up") // logic
  3560. .attr("title", doPin ? lang.Unpin : lang.Pin)
  3561. .removeClass( doPin ? UP : DN )
  3562. .addClass( doPin ? DN : UP )
  3563. ;
  3564. };
  3565. /*
  3566. * LAYOUT STATE MANAGEMENT
  3567. *
  3568. * @example .layout({ cookie: { name: "myLayout", keys: "west.isClosed,east.isClosed" } })
  3569. * @example .layout({ cookie__name: "myLayout", cookie__keys: "west.isClosed,east.isClosed" })
  3570. * @example myLayout.getState( "west.isClosed,north.size,south.isHidden" );
  3571. * @example myLayout.saveCookie( "west.isClosed,north.size,south.isHidden", {expires: 7} );
  3572. * @example myLayout.deleteCookie();
  3573. * @example myLayout.loadCookie();
  3574. * @example var hSaved = myLayout.state.cookie;
  3575. */
  3576. function isCookiesEnabled () {
  3577. // TODO: is the cookieEnabled property common enough to be useful???
  3578. return (navigator.cookieEnabled != 0);
  3579. };
  3580. /**
  3581. * Read & return data from the cookie - as JSON
  3582. *
  3583. * @param {Object=} opts
  3584. */
  3585. function getCookie (opts) {
  3586. var
  3587. o = $.extend( {}, options.cookie, opts || {} )
  3588. , name = o.name || options.name || "Layout"
  3589. , c = document.cookie
  3590. , cs = c ? c.split(';') : []
  3591. , pair // loop var
  3592. ;
  3593. for (var i=0, n=cs.length; i < n; i++) {
  3594. pair = $.trim(cs[i]).split('='); // name=value pair
  3595. if (pair[0] == name) // found the layout cookie
  3596. // convert cookie string back to a hash
  3597. return decodeJSON( decodeURIComponent(pair[1]) );
  3598. }
  3599. return "";
  3600. };
  3601. /**
  3602. * Get the current layout state and save it to a cookie
  3603. *
  3604. * @param {(string|Array)=} keys
  3605. * @param {Object=} opts
  3606. */
  3607. function saveCookie (keys, opts) {
  3608. var
  3609. o = $.extend( {}, options.cookie, opts || {} )
  3610. , name = o.name || options.name || "Layout"
  3611. , params = ''
  3612. , date = ''
  3613. , clear = false
  3614. ;
  3615. if (o.expires.toUTCString)
  3616. date = o.expires;
  3617. else if (typeof o.expires == 'number') {
  3618. date = new Date();
  3619. if (o.expires > 0)
  3620. date.setDate(date.getDate() + o.expires);
  3621. else {
  3622. date.setYear(1970);
  3623. clear = true;
  3624. }
  3625. }
  3626. if (date) params += ';expires='+ date.toUTCString();
  3627. if (o.path) params += ';path='+ o.path;
  3628. if (o.domain) params += ';domain='+ o.domain;
  3629. if (o.secure) params += ';secure';
  3630. if (clear) {
  3631. state.cookie = {}; // clear data
  3632. document.cookie = name +'='+ params; // expire the cookie
  3633. }
  3634. else {
  3635. state.cookie = getState(keys || o.keys); // read current panes-state
  3636. document.cookie = name +'='+ encodeURIComponent( encodeJSON(state.cookie) ) + params; // write cookie
  3637. }
  3638. return $.extend({}, state.cookie); // return COPY of state.cookie
  3639. };
  3640. /**
  3641. * Remove the state cookie
  3642. */
  3643. function deleteCookie () {
  3644. saveCookie('', { expires: -1 });
  3645. };
  3646. /**
  3647. * Get data from the cookie and USE IT to loadState
  3648. *
  3649. * @param {Object=} opts
  3650. */
  3651. function loadCookie (opts) {
  3652. var o = getCookie(opts); // READ the cookie
  3653. if (o) {
  3654. state.cookie = $.extend({}, o); // SET state.cookie
  3655. loadState(o); // LOAD the retrieved state
  3656. }
  3657. return o;
  3658. };
  3659. /**
  3660. * Update layout options from the cookie, if one exists
  3661. *
  3662. * @param {Object=} opts
  3663. */
  3664. function loadState (opts, animate) {
  3665. $.extend( true, options, opts ); // update layout options
  3666. // if layout has already been initialized, then UPDATE layout state
  3667. if (state.initialized) {
  3668. var pane, o, v, a = !animate;
  3669. $.each(_c.allPanes.split(","), function (idx, pane) {
  3670. o = opts[ pane ];
  3671. if (typeof o != 'object') return; // no key, continue
  3672. v = o.initHidden;
  3673. if (v === true) hide(pane, a);
  3674. if (v === false) show(pane, 0, a);
  3675. v = o.size;
  3676. if (v > 0) sizePane(pane, v);
  3677. v = o.initClosed;
  3678. if (v === true) close(pane, 0, a);
  3679. if (v === false) open(pane, 0, a );
  3680. });
  3681. }
  3682. };
  3683. /**
  3684. * Get the *current layout state* and return it as a hash
  3685. *
  3686. * @param {(string|Array)=} keys
  3687. */
  3688. function getState (keys) {
  3689. var
  3690. data = {}
  3691. , alt = { isClosed: 'initClosed', isHidden: 'initHidden' }
  3692. , pair, pane, key, val
  3693. ;
  3694. if (!keys) keys = options.cookie.keys; // if called by user
  3695. if ($.isArray(keys)) keys = keys.join(",");
  3696. // convert keys to an array and change delimiters from '__' to '.'
  3697. keys = keys.replace(/__/g, ".").split(',');
  3698. // loop keys and create a data hash
  3699. for (var i=0,n=keys.length; i < n; i++) {
  3700. pair = keys[i].split(".");
  3701. pane = pair[0];
  3702. key = pair[1];
  3703. if (_c.allPanes.indexOf(pane) < 0) continue; // bad pane!
  3704. val = state[ pane ][ key ];
  3705. if (val == undefined) continue;
  3706. if (key=="isClosed" && state[pane]["isSliding"])
  3707. val = true; // if sliding, then *really* isClosed
  3708. ( data[pane] || (data[pane]={}) )[ alt[key] ? alt[key] : key ] = val;
  3709. }
  3710. return data;
  3711. };
  3712. /**
  3713. * Stringify a JSON hash so can save in a cookie or db-field
  3714. */
  3715. function encodeJSON (JSON) {
  3716. return parse( JSON );
  3717. function parse (h) {
  3718. var D=[], i=0, k, v, t; // k = key, v = value
  3719. for (k in h) {
  3720. v = h[k];
  3721. t = typeof v;
  3722. if (t == 'string') // STRING - add quotes
  3723. v = '"'+ v +'"';
  3724. else if (t == 'object') // SUB-KEY - recurse into it
  3725. v = parse(v);
  3726. D[i++] = '"'+ k +'":'+ v;
  3727. }
  3728. return "{"+ D.join(",") +"}";
  3729. };
  3730. };
  3731. /**
  3732. * Convert stringified JSON back to a hash object
  3733. */
  3734. function decodeJSON (str) {
  3735. try { return window["eval"]("("+ str +")") || {}; }
  3736. catch (e) { return {}; }
  3737. };
  3738. /*
  3739. * #####################
  3740. * CREATE/RETURN LAYOUT
  3741. * #####################
  3742. */
  3743. // validate that container exists
  3744. var $Container = $(this).eq(0); // FIRST matching Container element
  3745. if (!$Container.length) {
  3746. //alert( lang.errContainerMissing );
  3747. return null;
  3748. };
  3749. // Users retreive Instance of a layout with: $Container.layout() OR $Container.data("layout")
  3750. // return the Instance-pointer if layout has already been initialized
  3751. if ($Container.data("layoutContainer") && $Container.data("layout"))
  3752. return $Container.data("layout"); // cached pointer
  3753. // init global vars
  3754. var
  3755. $Ps = {} // Panes x5 - set in initPanes()
  3756. , $Cs = {} // Content x5 - set in initPanes()
  3757. , $Rs = {} // Resizers x4 - set in initHandles()
  3758. , $Ts = {} // Togglers x4 - set in initHandles()
  3759. // aliases for code brevity
  3760. , sC = state.container // alias for easy access to 'container dimensions'
  3761. , sID = state.id // alias for unique layout ID/namespace - eg: "layout435"
  3762. ;
  3763. // create Instance object to expose data & option Properties, and primary action Methods
  3764. var Instance = {
  3765. options: options // property - options hash
  3766. , state: state // property - dimensions hash
  3767. , container: $Container // property - object pointers for layout container
  3768. , panes: $Ps // property - object pointers for ALL Panes: panes.north, panes.center
  3769. , contents: $Cs // property - object pointers for ALL Content: content.north, content.center
  3770. , resizers: $Rs // property - object pointers for ALL Resizers, eg: resizers.north
  3771. , togglers: $Ts // property - object pointers for ALL Togglers, eg: togglers.north
  3772. , toggle: toggle // method - pass a 'pane' ("north", "west", etc)
  3773. , hide: hide // method - ditto
  3774. , show: show // method - ditto
  3775. , open: open // method - ditto
  3776. , close: close // method - ditto
  3777. , slideOpen: slideOpen // method - ditto
  3778. , slideClose: slideClose // method - ditto
  3779. , slideToggle: slideToggle // method - ditto
  3780. , initContent: initContent // method - ditto
  3781. , sizeContent: sizeContent // method - pass a 'pane'
  3782. , sizePane: manualSizePane // method - pass a 'pane' AND an 'outer-size' in pixels or percent, or 'auto'
  3783. , swapPanes: swapPanes // method - pass TWO 'panes' - will swap them
  3784. , resizeAll: resizeAll // method - no parameters
  3785. , destroy: destroy // method - no parameters
  3786. , setSizeLimits: setSizeLimits // method - pass a 'pane' - update state min/max data
  3787. , bindButton: bindButton // utility - pass element selector, 'action' and 'pane' (E, "toggle", "west")
  3788. , addToggleBtn: addToggleBtn // utility - pass element selector and 'pane' (E, "west")
  3789. , addOpenBtn: addOpenBtn // utility - ditto
  3790. , addCloseBtn: addCloseBtn // utility - ditto
  3791. , addPinBtn: addPinBtn // utility - ditto
  3792. , allowOverflow: allowOverflow // utility - pass calling element (this)
  3793. , resetOverflow: resetOverflow // utility - ditto
  3794. , encodeJSON: encodeJSON // method - pass a JSON object
  3795. , decodeJSON: decodeJSON // method - pass a string of encoded JSON
  3796. , getState: getState // method - returns hash of current layout-state
  3797. , getCookie: getCookie // method - update options from cookie - returns hash of cookie data
  3798. , saveCookie: saveCookie // method - optionally pass keys-list and cookie-options (hash)
  3799. , deleteCookie: deleteCookie // method
  3800. , loadCookie: loadCookie // method - update options from cookie - returns hash of cookie data
  3801. , loadState: loadState // method - pass a hash of state to use to update options
  3802. , cssWidth: cssW // utility - pass element and target outerWidth
  3803. , cssHeight: cssH // utility - ditto
  3804. , enableClosable: enableClosable
  3805. , disableClosable: disableClosable
  3806. , enableSlidable: enableSlidable
  3807. , disableSlidable: disableSlidable
  3808. , enableResizable: enableResizable
  3809. , disableResizable: disableResizable
  3810. };
  3811. // create the border layout NOW
  3812. _create();
  3813. // return the Instance object
  3814. return Instance;
  3815. }
  3816. })( jQuery );