New Paste

 

Recent Pastes

Administrate




PageLines PasteBin.

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