8d28c0ffd705119327e39b4f696d3371f682c645.svn-base 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495
  1. (function($) {
  2. $.fn.layout = function (opts) {
  3. /*
  4. * ###########################
  5. * WIDGET CONFIG & OPTIONS
  6. * ###########################
  7. */
  8. // DEFAULTS for options
  9. var
  10. prefix = "ui-layout-" // prefix for ALL selectors and classNames
  11. , defaults = { // misc default values
  12. paneClass: prefix+"pane" // ui-layout-pane
  13. , resizerClass: prefix+"resizer" // ui-layout-resizer
  14. , togglerClass: prefix+"toggler" // ui-layout-toggler
  15. , togglerInnerClass: prefix+"" // ui-layout-open / ui-layout-closed
  16. , buttonClass: prefix+"button" // ui-layout-button
  17. , contentSelector: "."+prefix+"content"// ui-layout-content
  18. , contentIgnoreSelector: "."+prefix+"ignore" // ui-layout-mask
  19. }
  20. ;
  21. // DEFAULT PANEL OPTIONS - CHANGE IF DESIRED
  22. var options = {
  23. name: "" // FUTURE REFERENCE - not used right now
  24. , scrollToBookmarkOnLoad: true // after creating a layout, scroll to bookmark in URL (.../page.htm#myBookmark)
  25. , defaults: { // default options for 'all panes' - will be overridden by 'per-pane settings'
  26. applyDefaultStyles: false // apply basic styles directly to resizers & buttons? If not, then stylesheet must handle it
  27. , closable: true // pane can open & close
  28. , resizable: true // when open, pane can be resized
  29. , slidable: true // when closed, pane can 'slide' open over other panes - closes on mouse-out
  30. //, paneSelector: [ ] // MUST be pane-specific!
  31. , contentSelector: defaults.contentSelector // INNER div/element to auto-size so only it scrolls, not the entire pane!
  32. , contentIgnoreSelector: defaults.contentIgnoreSelector // elem(s) to 'ignore' when measuring 'content'
  33. , paneClass: defaults.paneClass // border-Pane - default: 'ui-layout-pane'
  34. , resizerClass: defaults.resizerClass // Resizer Bar - default: 'ui-layout-resizer'
  35. , togglerClass: defaults.togglerClass // Toggler Button - default: 'ui-layout-toggler'
  36. , buttonClass: defaults.buttonClass // CUSTOM Buttons - default: 'ui-layout-button-toggle/-open/-close/-pin'
  37. , resizerDragOpacity: 1 // option for ui.draggable
  38. //, resizerCursor: "" // MUST be pane-specific - cursor when over resizer-bar
  39. , maskIframesOnResize: true // true = all iframes OR = iframe-selector(s) - adds masking-div during resizing/dragging
  40. //, size: 100 // inital size of pane - defaults are set 'per pane'
  41. , minSize: 0 // when manually resizing a pane
  42. , maxSize: 0 // ditto, 0 = no limit
  43. , spacing_open: 6 // space between pane and adjacent panes - when pane is 'open'
  44. , spacing_closed: 6 // ditto - when pane is 'closed'
  45. , togglerLength_open: 50 // Length = WIDTH of toggler button on north/south edges - HEIGHT on east/west edges
  46. , togglerLength_closed: 50 // 100% OR -1 means 'full height/width of resizer bar' - 0 means 'hidden'
  47. , togglerAlign_open: "center" // top/left, bottom/right, center, OR...
  48. , togglerAlign_closed: "center" // 1 => nn = offset from top/left, -1 => -nn == offset from bottom/right
  49. , togglerTip_open: "Close" // Toggler tool-tip (title)
  50. , togglerTip_closed: "Open" // ditto
  51. , resizerTip: "Resize" // Resizer tool-tip (title)
  52. , sliderTip: "Slide Open" // resizer-bar triggers 'sliding' when pane is closed
  53. , sliderCursor: "pointer" // cursor when resizer-bar will trigger 'sliding'
  54. , slideTrigger_open: "click" // click, dblclick, mouseover
  55. , slideTrigger_close: "mouseout" // click, mouseout
  56. , hideTogglerOnSlide: false // when pane is slid-open, should the toggler show?
  57. , togglerContent_open: "" // text or HTML to put INSIDE the toggler
  58. , togglerContent_closed: "" // ditto
  59. , showOverflowOnHover: false // will bind allowOverflow() utility to pane.onMouseOver
  60. , enableCursorHotkey: true // enabled 'cursor' hotkeys
  61. //, customHotkey: "" // MUST be pane-specific - EITHER a charCode OR a character
  62. , customHotkeyModifier: "SHIFT" // either 'SHIFT', 'CTRL' or 'CTRL+SHIFT' - NOT 'ALT'
  63. // NOTE: fxSss_open & fxSss_close options (eg: fxName_open) are auto-generated if not passed
  64. , fxName: "slide" // ('none' or blank), slide, drop, scale
  65. , fxSpeed: null // slow, normal, fast, 200, nnn - if passed, will OVERRIDE fxSettings.duration
  66. , fxSettings: {} // can be passed, eg: { easing: "easeOutBounce", duration: 1500 }
  67. , initClosed: false // true = init pane as 'closed'
  68. , initHidden: false // true = init pane as 'hidden' - no resizer or spacing
  69. /* callback options do not have to be set - listed here for reference only
  70. , onshow_start: "" // CALLBACK when pane STARTS to Show - BEFORE onopen/onhide_start
  71. , onshow_end: "" // CALLBACK when pane ENDS being Shown - AFTER onopen/onhide_end
  72. , onhide_start: "" // CALLBACK when pane STARTS to Close - BEFORE onclose_start
  73. , onhide_end: "" // CALLBACK when pane ENDS being Closed - AFTER onclose_end
  74. , onopen_start: "" // CALLBACK when pane STARTS to Open
  75. , onopen_end: "" // CALLBACK when pane ENDS being Opened
  76. , onclose_start: "" // CALLBACK when pane STARTS to Close
  77. , onclose_end: "" // CALLBACK when pane ENDS being Closed
  78. , onresize_start: "" // CALLBACK when pane STARTS to be ***MANUALLY*** Resized
  79. , onresize_end: "" // CALLBACK when pane ENDS being Resized ***FOR ANY REASON***
  80. */
  81. }
  82. , north: {
  83. paneSelector: "."+prefix+"north" // default = .ui-layout-north
  84. , size: "auto"
  85. , resizerCursor: "n-resize"
  86. }
  87. , south: {
  88. paneSelector: "."+prefix+"south" // default = .ui-layout-south
  89. , size: "auto"
  90. , resizerCursor: "s-resize"
  91. }
  92. , east: {
  93. paneSelector: "."+prefix+"east" // default = .ui-layout-east
  94. , size: 200
  95. , resizerCursor: "e-resize"
  96. }
  97. , west: {
  98. paneSelector: "."+prefix+"west" // default = .ui-layout-west
  99. , size: 200
  100. , resizerCursor: "w-resize"
  101. }
  102. , center: {
  103. paneSelector: "."+prefix+"center" // default = .ui-layout-center
  104. }
  105. };
  106. var effects = { // LIST *PREDEFINED EFFECTS* HERE, even if effect has no settings
  107. slide: {
  108. all: { duration: "fast" } // eg: duration: 1000, easing: "easeOutBounce"
  109. , north: { direction: "up" }
  110. , south: { direction: "down" }
  111. , east: { direction: "right"}
  112. , west: { direction: "left" }
  113. }
  114. , drop: {
  115. all: { duration: "slow" } // eg: duration: 1000, easing: "easeOutQuint"
  116. , north: { direction: "up" }
  117. , south: { direction: "down" }
  118. , east: { direction: "right"}
  119. , west: { direction: "left" }
  120. }
  121. , scale: {
  122. all: { duration: "fast" }
  123. }
  124. };
  125. // STATIC, INTERNAL CONFIG - DO NOT CHANGE THIS!
  126. var config = {
  127. allPanes: "north,south,east,west,center"
  128. , borderPanes: "north,south,east,west"
  129. , zIndex: { // set z-index values here
  130. resizer_normal: 1 // normal z-index for resizer-bars
  131. , pane_normal: 2 // normal z-index for panes
  132. , mask: 4 // overlay div used to mask pane(s) during resizing
  133. , sliding: 100 // applied to both the pane and its resizer when a pane is 'slid open'
  134. , resizing: 10000 // applied to the CLONED resizer-bar when being 'dragged'
  135. , animation: 10000 // applied to the pane when being animated - not applied to the resizer
  136. }
  137. , resizers: {
  138. cssReq: {
  139. position: "absolute"
  140. , padding: 0
  141. , margin: 0
  142. , fontSize: "1px"
  143. , textAlign: "left" // to counter-act "center" alignment!
  144. , overflow: "hidden" // keep toggler button from overflowing
  145. , zIndex: 1
  146. }
  147. , cssDef: { // DEFAULT CSS - applied if: options.PANE.applyDefaultStyles=true
  148. background: "#DDD"
  149. , border: "none"
  150. }
  151. }
  152. , togglers: {
  153. cssReq: {
  154. position: "absolute"
  155. , display: "block"
  156. , padding: 0
  157. , margin: 0
  158. , overflow: "hidden"
  159. , textAlign: "center"
  160. , fontSize: "1px"
  161. , cursor: "pointer"
  162. , zIndex: 1
  163. }
  164. , cssDef: { // DEFAULT CSS - applied if: options.PANE.applyDefaultStyles=true
  165. background: "#AAA"
  166. }
  167. }
  168. , content: {
  169. cssReq: {
  170. overflow: "auto"
  171. }
  172. , cssDef: {}
  173. }
  174. , defaults: { // defaults for ALL panes - overridden by 'per-pane settings' below
  175. cssReq: {
  176. position: "absolute"
  177. , margin: 0
  178. , zIndex: 2
  179. }
  180. , cssDef: {
  181. padding: "10px"
  182. , background: "#FFF"
  183. , border: "1px solid #BBB"
  184. , overflow: "auto"
  185. }
  186. }
  187. , north: {
  188. edge: "top"
  189. , sizeType: "height"
  190. , dir: "horz"
  191. , cssReq: {
  192. top: 0
  193. , bottom: "auto"
  194. , left: 0
  195. , right: 0
  196. , width: "auto"
  197. // height: DYNAMIC
  198. }
  199. }
  200. , south: {
  201. edge: "bottom"
  202. , sizeType: "height"
  203. , dir: "horz"
  204. , cssReq: {
  205. top: "auto"
  206. , bottom: 0
  207. , left: 0
  208. , right: 0
  209. , width: "auto"
  210. // height: DYNAMIC
  211. }
  212. }
  213. , east: {
  214. edge: "right"
  215. , sizeType: "width"
  216. , dir: "vert"
  217. , cssReq: {
  218. left: "auto"
  219. , right: 0
  220. , top: "auto" // DYNAMIC
  221. , bottom: "auto" // DYNAMIC
  222. , height: "auto"
  223. // width: DYNAMIC
  224. }
  225. }
  226. , west: {
  227. edge: "left"
  228. , sizeType: "width"
  229. , dir: "vert"
  230. , cssReq: {
  231. left: 0
  232. , right: "auto"
  233. , top: "auto" // DYNAMIC
  234. , bottom: "auto" // DYNAMIC
  235. , height: "auto"
  236. // width: DYNAMIC
  237. }
  238. }
  239. , center: {
  240. dir: "center"
  241. , cssReq: {
  242. left: "auto" // DYNAMIC
  243. , right: "auto" // DYNAMIC
  244. , top: "auto" // DYNAMIC
  245. , bottom: "auto" // DYNAMIC
  246. , height: "auto"
  247. , width: "auto"
  248. }
  249. }
  250. };
  251. // DYNAMIC DATA
  252. var state = {
  253. // generate random 'ID#' to identify layout - used to create global namespace for timers
  254. id: Math.floor(Math.random() * 10000)
  255. , container: {}
  256. , north: {}
  257. , south: {}
  258. , east: {}
  259. , west: {}
  260. , center: {}
  261. };
  262. var
  263. altEdge = {
  264. top: "bottom"
  265. , bottom: "top"
  266. , left: "right"
  267. , right: "left"
  268. }
  269. , altSide = {
  270. north: "south"
  271. , south: "north"
  272. , east: "west"
  273. , west: "east"
  274. }
  275. ;
  276. /*
  277. * ###########################
  278. * INTERNAL HELPER FUNCTIONS
  279. * ###########################
  280. */
  281. /**
  282. * isStr
  283. *
  284. * Returns true if passed param is EITHER a simple string OR a 'string object' - otherwise returns false
  285. */
  286. var isStr = function (o) {
  287. if (typeof o == "string")
  288. return true;
  289. else if (typeof o == "object") {
  290. try {
  291. var match = o.constructor.toString().match(/string/i);
  292. return (match !== null);
  293. } catch (e) {}
  294. }
  295. return false;
  296. };
  297. /**
  298. * str
  299. *
  300. * Returns a simple string if the passed param is EITHER a simple string OR a 'string object',
  301. * else returns the original object
  302. */
  303. var str = function (o) {
  304. if (typeof o == "string" || isStr(o)) return $.trim(o); // trim converts 'String object' to a simple string
  305. else return o;
  306. };
  307. /**
  308. * min / max
  309. *
  310. * Alias for Math.min/.max to simplify coding
  311. */
  312. var min = function (x,y) { return Math.min(x,y); };
  313. var max = function (x,y) { return Math.max(x,y); };
  314. /**
  315. * transformData
  316. *
  317. * Processes the options passed in and transforms them into the format used by layout()
  318. * Missing keys are added, and converts the data if passed in 'flat-format' (no sub-keys)
  319. * In flat-format, pane-specific-settings are prefixed like: north__optName (2-underscores)
  320. * To update effects, options MUST use nested-keys format, with an effects key
  321. *
  322. * @callers initOptions()
  323. * @params JSON d Data/options passed by user - may be a single level or nested levels
  324. * @returns JSON Creates a data struture that perfectly matches 'options', ready to be imported
  325. */
  326. var transformData = function (d) {
  327. var json = { defaults:{fxSettings:{}}, north:{fxSettings:{}}, south:{fxSettings:{}}, east:{fxSettings:{}}, west:{fxSettings:{}}, center:{fxSettings:{}} };
  328. d = d || {};
  329. if (d.effects || d.defaults || d.north || d.south || d.west || d.east || d.center)
  330. json = $.extend( json, d ); // already in json format - add to base keys
  331. else
  332. // convert 'flat' to 'nest-keys' format - also handles 'empty' user-options
  333. $.each( d, function (key,val) {
  334. a = key.split("__");
  335. json[ a[1] ? a[0] : "defaults" ][ a[1] ? a[1] : a[0] ] = val;
  336. });
  337. return json;
  338. };
  339. /**
  340. * setFlowCallback
  341. *
  342. * Set an INTERNAL callback to avoid simultaneous animation
  343. * Runs only if needed and only if all callbacks are not 'already set'!
  344. *
  345. * @param String action Either 'open' or 'close'
  346. * @pane String pane A valid border-pane name, eg 'west'
  347. * @pane Boolean param Extra param for callback (optional)
  348. */
  349. var setFlowCallback = function (action, pane, param) {
  350. var
  351. cb = action +","+ pane +","+ (param ? 1 : 0)
  352. , cP, cbPane
  353. ;
  354. $.each(c.borderPanes.split(","), function (i,p) {
  355. if (c[p].isMoving) {
  356. bindCallback(p); // TRY to bind a callback
  357. return false; // BREAK
  358. }
  359. });
  360. function bindCallback (p, test) {
  361. cP = c[p];
  362. if (!cP.doCallback) {
  363. cP.doCallback = true;
  364. cP.callback = cb;
  365. }
  366. else { // try to 'chain' this callback
  367. cpPane = cP.callback.split(",")[1]; // 2nd param is 'pane'
  368. if (cpPane != p && cpPane != pane) // callback target NOT 'itself' and NOT 'this pane'
  369. bindCallback (cpPane, true); // RECURSE
  370. }
  371. }
  372. };
  373. /**
  374. * execFlowCallback
  375. *
  376. * RUN the INTERNAL callback for this pane - if one exists
  377. *
  378. * @param String action Either 'open' or 'close'
  379. * @pane String pane A valid border-pane name, eg 'west'
  380. * @pane Boolean param Extra param for callback (optional)
  381. */
  382. var execFlowCallback = function (pane) {
  383. var cP = c[pane];
  384. // RESET flow-control flaGs
  385. c.isLayoutBusy = false;
  386. delete cP.isMoving;
  387. if (!cP.doCallback || !cP.callback) return;
  388. cP.doCallback = false; // RESET logic flag
  389. // EXECUTE the callback
  390. var
  391. cb = cP.callback.split(",")
  392. , param = (cb[2] > 0 ? true : false)
  393. ;
  394. if (cb[0] == "open")
  395. open( cb[1], param );
  396. else if (cb[0] == "close")
  397. close( cb[1], param );
  398. if (!cP.doCallback) cP.callback = null; // RESET - unless callback above enabled it again!
  399. };
  400. /**
  401. * execUserCallback
  402. *
  403. * Executes a Callback function after a trigger event, like resize, open or close
  404. *
  405. * @param String pane This is passed only so we can pass the 'pane object' to the callback
  406. * @param String v_fn Accepts a function name, OR a comma-delimited array: [0]=function name, [1]=argument
  407. */
  408. var execUserCallback = function (pane, v_fn) {
  409. if (!v_fn) return;
  410. var fn;
  411. try {
  412. if (typeof v_fn == "function")
  413. fn = v_fn;
  414. else if (typeof v_fn != "string")
  415. return;
  416. else if (v_fn.indexOf(",") > 0) {
  417. // function name cannot contain a comma, so must be a function name AND a 'name' parameter
  418. var
  419. args = v_fn.split(",")
  420. , fn = eval(args[0])
  421. ;
  422. if (typeof fn=="function" && args.length > 1)
  423. return fn(args[1]); // pass the argument parsed from 'list'
  424. }
  425. else // just the name of an external function?
  426. fn = eval(v_fn);
  427. if (typeof fn=="function")
  428. // pass data: pane-name, pane-element, pane-state, pane-options, and layout-name
  429. return fn( pane, $Ps[pane], $.extend({},state[pane]), $.extend({},options[pane]), options.name );
  430. }
  431. catch (ex) {}
  432. };
  433. /**
  434. * cssNum
  435. *
  436. * Returns the 'current CSS value' for an element - returns 0 if property does not exist
  437. *
  438. * @callers Called by many methods
  439. * @param jQuery $Elem Must pass a jQuery object - first element is processed
  440. * @param String property The name of the CSS property, eg: top, width, etc.
  441. * @returns Variant Usually is used to get an integer value for position (top, left) or size (height, width)
  442. */
  443. var cssNum = function ($E, prop) {
  444. var
  445. val = 0
  446. , hidden = false
  447. , visibility = ""
  448. ;
  449. if (!$.browser.msie) { // IE CAN read dimensions of 'hidden' elements - FF CANNOT
  450. if ($.curCSS($E[0], "display", true) == "none") {
  451. hidden = true;
  452. visibility = $.curCSS($E[0], "visibility", true); // SAVE current setting
  453. $E.css({ display: "block", visibility: "hidden" }); // show element 'invisibly' so we can measure it
  454. }
  455. }
  456. val = parseInt($.curCSS($E[0], prop, true), 10) || 0;
  457. if (hidden) { // WAS hidden, so put back the way it was
  458. $E.css({ display: "none" });
  459. if (visibility && visibility != "hidden")
  460. $E.css({ visibility: visibility }); // reset 'visibility'
  461. }
  462. return val;
  463. };
  464. /**
  465. * cssW / cssH / cssSize
  466. *
  467. * Contains logic to check boxModel & browser, and return the correct width/height for the current browser/doctype
  468. *
  469. * @callers initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
  470. * @param Variant elem Can accept a 'pane' (east, west, etc) OR a DOM object OR a jQuery object
  471. * @param Integer outerWidth/outerHeight (optional) Can pass a width, allowing calculations BEFORE element is resized
  472. * @returns Integer Returns the innerHeight of the elem by subtracting padding and borders
  473. *
  474. * @TODO May need to add additional logic to handle more browser/doctype variations?
  475. */
  476. var cssW = function (e, outerWidth) {
  477. var $E;
  478. if (isStr(e)) {
  479. e = str(e);
  480. $E = $Ps[e];
  481. }
  482. else
  483. $E = $(e);
  484. // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
  485. if (outerWidth <= 0)
  486. return 0;
  487. else if (!(outerWidth>0))
  488. outerWidth = isStr(e) ? getPaneSize(e) : $E.outerWidth();
  489. if (!$.boxModel)
  490. return outerWidth;
  491. else // strip border and padding size from outerWidth to get CSS Width
  492. return outerWidth
  493. - cssNum($E, "paddingLeft")
  494. - cssNum($E, "paddingRight")
  495. - ($.curCSS($E[0], "borderLeftStyle", true) == "none" ? 0 : cssNum($E, "borderLeftWidth"))
  496. - ($.curCSS($E[0], "borderRightStyle", true) == "none" ? 0 : cssNum($E, "borderRightWidth"))
  497. ;
  498. };
  499. var cssH = function (e, outerHeight) {
  500. var $E;
  501. if (isStr(e)) {
  502. e = str(e);
  503. $E = $Ps[e];
  504. }
  505. else
  506. $E = $(e);
  507. // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
  508. if (outerHeight <= 0)
  509. return 0;
  510. else if (!(outerHeight>0))
  511. outerHeight = (isStr(e)) ? getPaneSize(e) : $E.outerHeight();
  512. if (!$.boxModel)
  513. return outerHeight;
  514. else // strip border and padding size from outerHeight to get CSS Height
  515. return outerHeight
  516. - cssNum($E, "paddingTop")
  517. - cssNum($E, "paddingBottom")
  518. - ($.curCSS($E[0], "borderTopStyle", true) == "none" ? 0 : cssNum($E, "borderTopWidth"))
  519. - ($.curCSS($E[0], "borderBottomStyle", true) == "none" ? 0 : cssNum($E, "borderBottomWidth"))
  520. ;
  521. };
  522. var cssSize = function (pane, outerSize) {
  523. if (c[pane].dir=="horz") // pane = north or south
  524. return cssH(pane, outerSize);
  525. else // pane = east or west
  526. return cssW(pane, outerSize);
  527. };
  528. /**
  529. * getPaneSize
  530. *
  531. * Calculates the current 'size' (width or height) of a border-pane - optionally with 'pane spacing' added
  532. *
  533. * @returns Integer Returns EITHER Width for east/west panes OR Height for north/south panes - adjusted for boxModel & browser
  534. */
  535. var getPaneSize = function (pane, inclSpace) {
  536. var
  537. $P = $Ps[pane]
  538. , o = options[pane]
  539. , s = state[pane]
  540. , oSp = (inclSpace ? o.spacing_open : 0)
  541. , cSp = (inclSpace ? o.spacing_closed : 0)
  542. ;
  543. if (!$P || s.isHidden)
  544. return 0;
  545. else if (s.isClosed || (s.isSliding && inclSpace))
  546. return cSp;
  547. else if (c[pane].dir == "horz")
  548. return $P.outerHeight() + oSp;
  549. else // dir == "vert"
  550. return $P.outerWidth() + oSp;
  551. };
  552. var setPaneMinMaxSizes = function (pane) {
  553. var
  554. d = cDims
  555. , edge = c[pane].edge
  556. , dir = c[pane].dir
  557. , o = options[pane]
  558. , s = state[pane]
  559. , $P = $Ps[pane]
  560. , $altPane = $Ps[ altSide[pane] ]
  561. , paneSpacing = o.spacing_open
  562. , altPaneSpacing = options[ altSide[pane] ].spacing_open
  563. , altPaneSize = (!$altPane ? 0 : (dir=="horz" ? $altPane.outerHeight() : $altPane.outerWidth()))
  564. , containerSize = (dir=="horz" ? d.innerHeight : d.innerWidth)
  565. // limitSize prevents this pane from 'overlapping' opposite pane - even if opposite pane is currently closed
  566. , limitSize = containerSize - paneSpacing - altPaneSize - altPaneSpacing
  567. , minSize = s.minSize || 0
  568. , maxSize = Math.min(s.maxSize || 9999, limitSize)
  569. , minPos, maxPos // used to set resizing limits
  570. ;
  571. switch (pane) {
  572. case "north": minPos = d.offsetTop + minSize;
  573. maxPos = d.offsetTop + maxSize;
  574. break;
  575. case "west": minPos = d.offsetLeft + minSize;
  576. maxPos = d.offsetLeft + maxSize;
  577. break;
  578. case "south": minPos = d.offsetTop + d.innerHeight - maxSize;
  579. maxPos = d.offsetTop + d.innerHeight - minSize;
  580. break;
  581. case "east": minPos = d.offsetLeft + d.innerWidth - maxSize;
  582. maxPos = d.offsetLeft + d.innerWidth - minSize;
  583. break;
  584. }
  585. // save data to pane-state
  586. $.extend(s, { minSize: minSize, maxSize: maxSize, minPosition: minPos, maxPosition: maxPos });
  587. };
  588. /**
  589. * getPaneDims
  590. *
  591. * Returns data for setting the size/position of center pane. Date is also used to set Height for east/west panes
  592. *
  593. * @returns JSON Returns a hash of all dimensions: top, bottom, left, right, (outer) width and (outer) height
  594. */
  595. var getPaneDims = function () {
  596. var d = {
  597. top: getPaneSize("north", true) // true = include 'spacing' value for p
  598. , bottom: getPaneSize("south", true)
  599. , left: getPaneSize("west", true)
  600. , right: getPaneSize("east", true)
  601. , width: 0
  602. , height: 0
  603. };
  604. with (d) {
  605. width = cDims.innerWidth - left - right;
  606. height = cDims.innerHeight - bottom - top;
  607. // now add the 'container border/padding' to get final positions - relative to the container
  608. top += cDims.top;
  609. bottom += cDims.bottom;
  610. left += cDims.left;
  611. right += cDims.right;
  612. }
  613. return d;
  614. };
  615. /**
  616. * getElemDims
  617. *
  618. * Returns data for setting size of an element (container or a pane).
  619. *
  620. * @callers create(), onWindowResize() for container, plus others for pane
  621. * @returns JSON Returns a hash of all dimensions: top, bottom, left, right, outerWidth, innerHeight, etc
  622. */
  623. var getElemDims = function ($E) {
  624. var
  625. d = {} // dimensions hash
  626. , e, b, p // edge, border, padding
  627. ;
  628. $.each("Left,Right,Top,Bottom".split(","), function () {
  629. e = str(this);
  630. b = d["border" +e] = cssNum($E, "border"+e+"Width");
  631. p = d["padding"+e] = cssNum($E, "padding"+e);
  632. d["offset" +e] = b + p; // total offset of content from outer edge
  633. // if BOX MODEL, then 'position' = PADDING (ignore borderWidth)
  634. if ($E == $Container)
  635. d[e.toLowerCase()] = ($.boxModel ? p : 0);
  636. });
  637. d.innerWidth = d.outerWidth = $E.outerWidth();
  638. d.innerHeight = d.outerHeight = $E.outerHeight();
  639. if ($.boxModel) {
  640. d.innerWidth -= (d.offsetLeft + d.offsetRight);
  641. d.innerHeight -= (d.offsetTop + d.offsetBottom);
  642. }
  643. return d;
  644. };
  645. var setTimer = function (pane, action, fn, ms) {
  646. var
  647. Layout = window.layout = window.layout || {}
  648. , Timers = Layout.timers = Layout.timers || {}
  649. , name = "layout_"+ state.id +"_"+ pane +"_"+ action // UNIQUE NAME for every layout-pane-action
  650. ;
  651. if (Timers[name]) return; // timer already set!
  652. else Timers[name] = setTimeout(fn, ms);
  653. };
  654. var clearTimer = function (pane, action) {
  655. var
  656. Layout = window.layout = window.layout || {}
  657. , Timers = Layout.timers = Layout.timers || {}
  658. , name = "layout_"+ state.id +"_"+ pane +"_"+ action // UNIQUE NAME for every layout-pane-action
  659. ;
  660. if (Timers[name]) {
  661. clearTimeout( Timers[name] );
  662. delete Timers[name];
  663. return true;
  664. }
  665. else
  666. return false;
  667. };
  668. /*
  669. * ###########################
  670. * INITIALIZATION METHODS
  671. * ###########################
  672. */
  673. /**
  674. * create
  675. *
  676. * Initialize the layout - called automatically whenever an instance of layout is created
  677. *
  678. * @callers NEVER explicity called
  679. * @returns An object pointer to the instance created
  680. */
  681. var create = function () {
  682. // initialize config/options
  683. initOptions();
  684. // initialize all objects
  685. initContainer(); // set CSS as needed and init state.container dimensions
  686. initPanes(); // size & position all panes
  687. initHandles(); // create and position all resize bars & togglers buttons
  688. initResizable(); // activate resizing on all panes where resizable=true
  689. sizeContent("all"); // AFTER panes & handles have been initialized, size 'content' divs
  690. if (options.scrollToBookmarkOnLoad)
  691. with (self.location) if (hash) replace( hash ); // scrollTo Bookmark
  692. // bind hotkey function - keyDown - if required
  693. initHotkeys();
  694. // bind resizeAll() for 'this layout instance' to window.resize event
  695. $(window).resize(function () {
  696. var timerID = "timerLayout_"+state.id;
  697. if (window[timerID]) clearTimeout(window[timerID]);
  698. window[timerID] = null;
  699. if (true || $.browser.msie) // use a delay for IE because the resize event fires repeatly
  700. window[timerID] = setTimeout(resizeAll, 100);
  701. else // most other browsers have a built-in delay before firing the resize event
  702. resizeAll(); // resize all layout elements NOW!
  703. });
  704. };
  705. /**
  706. * initContainer
  707. *
  708. * Validate and initialize container CSS and events
  709. *
  710. * @callers create()
  711. */
  712. var initContainer = function () {
  713. try { // format html/body if this is a full page layout
  714. if ($Container[0].tagName == "BODY") {
  715. $("html").css({
  716. height: "100%"
  717. , overflow: "hidden"
  718. });
  719. $("body").css({
  720. position: "relative"
  721. , height: "100%"
  722. , overflow: "hidden"
  723. , margin: 0
  724. , padding: 0 // TODO: test whether body-padding could be handled?
  725. , border: "none" // a body-border creates problems because it cannot be measured!
  726. });
  727. }
  728. else { // set required CSS - overflow and position
  729. var
  730. CSS = { overflow: "hidden" } // make sure container will not 'scroll'
  731. , p = $Container.css("position")
  732. , h = $Container.css("height")
  733. ;
  734. // if this is a NESTED layout, then outer-pane ALREADY has position and height
  735. if (!$Container.hasClass("ui-layout-pane")) {
  736. if (!p || "fixed,absolute,relative".indexOf(p) < 0)
  737. CSS.position = "relative"; // container MUST have a 'position'
  738. if (!h || h=="auto")
  739. CSS.height = "100%"; // container MUST have a 'height'
  740. }
  741. $Container.css( CSS );
  742. }
  743. } catch (ex) {}
  744. // get layout-container dimensions (updated when necessary)
  745. cDims = state.container = getElemDims( $Container ); // update data-pointer too
  746. };
  747. /**
  748. * initHotkeys
  749. *
  750. * Bind layout hotkeys - if options enabled
  751. *
  752. * @callers create()
  753. */
  754. var initHotkeys = function () {
  755. // bind keyDown to capture hotkeys, if option enabled for ANY pane
  756. $.each(c.borderPanes.split(","), function (i,pane) {
  757. var o = options[pane];
  758. if (o.enableCursorHotkey || o.customHotkey) {
  759. $(document).keydown( keyDown ); // only need to bind this ONCE
  760. return false; // BREAK - binding was done
  761. }
  762. });
  763. };
  764. /**
  765. * initOptions
  766. *
  767. * Build final CONFIG and OPTIONS data
  768. *
  769. * @callers create()
  770. */
  771. var initOptions = function () {
  772. // simplify logic by making sure passed 'opts' var has basic keys
  773. opts = transformData( opts );
  774. // update default effects, if case user passed key
  775. if (opts.effects) {
  776. $.extend( effects, opts.effects );
  777. delete opts.effects;
  778. }
  779. // see if any 'global options' were specified
  780. $.each("name,scrollToBookmarkOnLoad".split(","), function (idx,key) {
  781. if (opts[key] !== undefined)
  782. options[key] = opts[key];
  783. else if (opts.defaults[key] !== undefined) {
  784. options[key] = opts.defaults[key];
  785. delete opts.defaults[key];
  786. }
  787. });
  788. // remove any 'defaults' that MUST be set 'per-pane'
  789. $.each("paneSelector,resizerCursor,customHotkey".split(","),
  790. function (idx,key) { delete opts.defaults[key]; } // is OK if key does not exist
  791. );
  792. // now update options.defaults
  793. $.extend( options.defaults, opts.defaults );
  794. // make sure required sub-keys exist
  795. //if (typeof options.defaults.fxSettings != "object") options.defaults.fxSettings = {};
  796. // merge all config & options for the 'center' pane
  797. c.center = $.extend( true, {}, c.defaults, c.center );
  798. $.extend( options.center, opts.center );
  799. // Most 'default options' do not apply to 'center', so add only those that DO
  800. var o_Center = $.extend( true, {}, options.defaults, opts.defaults, options.center ); // TEMP data
  801. $.each("paneClass,contentSelector,contentIgnoreSelector,applyDefaultStyles,showOverflowOnHover".split(","),
  802. function (idx,key) { options.center[key] = o_Center[key]; }
  803. );
  804. var defs = options.defaults;
  805. // create a COMPLETE set of options for EACH border-pane
  806. $.each(c.borderPanes.split(","), function(i,pane) {
  807. // apply 'pane-defaults' to CONFIG.PANE
  808. c[pane] = $.extend( true, {}, c.defaults, c[pane] );
  809. // apply 'pane-defaults' + user-options to OPTIONS.PANE
  810. o = options[pane] = $.extend( true, {}, options.defaults, options[pane], opts.defaults, opts[pane] );
  811. // make sure we have base-classes
  812. if (!o.paneClass) o.paneClass = defaults.paneClass;
  813. if (!o.resizerClass) o.resizerClass = defaults.resizerClass;
  814. if (!o.togglerClass) o.togglerClass = defaults.togglerClass;
  815. // create FINAL fx options for each pane, ie: options.PANE.fxName/fxSpeed/fxSettings[_open|_close]
  816. $.each(["_open","_close",""], function (i,n) {
  817. var
  818. sName = "fxName"+n
  819. , sSpeed = "fxSpeed"+n
  820. , sSettings = "fxSettings"+n
  821. ;
  822. // recalculate fxName according to specificity rules
  823. o[sName] =
  824. opts[pane][sName] // opts.west.fxName_open
  825. || opts[pane].fxName // opts.west.fxName
  826. || opts.defaults[sName] // opts.defaults.fxName_open
  827. || opts.defaults.fxName // opts.defaults.fxName
  828. || o[sName] // options.west.fxName_open
  829. || o.fxName // options.west.fxName
  830. || defs[sName] // options.defaults.fxName_open
  831. || defs.fxName // options.defaults.fxName
  832. || "none"
  833. ;
  834. // validate fxName to be sure is a valid effect
  835. var fxName = o[sName];
  836. if (fxName == "none" || !$.effects || !$.effects[fxName] || (!effects[fxName] && !o[sSettings] && !o.fxSettings))
  837. fxName = o[sName] = "none"; // effect not loaded, OR undefined FX AND fxSettings not passed
  838. // set vars for effects subkeys to simplify logic
  839. var
  840. fx = effects[fxName] || {} // effects.slide
  841. , fx_all = fx.all || {} // effects.slide.all
  842. , fx_pane = fx[pane] || {} // effects.slide.west
  843. ;
  844. // RECREATE the fxSettings[_open|_close] keys using specificity rules
  845. o[sSettings] = $.extend(
  846. {}
  847. , fx_all // effects.slide.all
  848. , fx_pane // effects.slide.west
  849. , defs.fxSettings || {} // options.defaults.fxSettings
  850. , defs[sSettings] || {} // options.defaults.fxSettings_open
  851. , o.fxSettings // options.west.fxSettings
  852. , o[sSettings] // options.west.fxSettings_open
  853. , opts.defaults.fxSettings // opts.defaults.fxSettings
  854. , opts.defaults[sSettings] || {} // opts.defaults.fxSettings_open
  855. , opts[pane].fxSettings // opts.west.fxSettings
  856. , opts[pane][sSettings] || {} // opts.west.fxSettings_open
  857. );
  858. // recalculate fxSpeed according to specificity rules
  859. o[sSpeed] =
  860. opts[pane][sSpeed] // opts.west.fxSpeed_open
  861. || opts[pane].fxSpeed // opts.west.fxSpeed (pane-default)
  862. || opts.defaults[sSpeed] // opts.defaults.fxSpeed_open
  863. || opts.defaults.fxSpeed // opts.defaults.fxSpeed
  864. || o[sSpeed] // options.west.fxSpeed_open
  865. || o[sSettings].duration // options.west.fxSettings_open.duration
  866. || o.fxSpeed // options.west.fxSpeed
  867. || o.fxSettings.duration // options.west.fxSettings.duration
  868. || defs.fxSpeed // options.defaults.fxSpeed
  869. || defs.fxSettings.duration// options.defaults.fxSettings.duration
  870. || fx_pane.duration // effects.slide.west.duration
  871. || fx_all.duration // effects.slide.all.duration
  872. || "normal" // DEFAULT
  873. ;
  874. // DEBUG: if (pane=="east") debugData( $.extend({}, {speed: o[sSpeed], fxSettings_duration: o[sSettings].duration}, o[sSettings]), pane+"."+sName+" = "+fxName );
  875. });
  876. });
  877. };
  878. /**
  879. * initPanes
  880. *
  881. * Initialize module objects, styling, size and position for all panes
  882. *
  883. * @callers create()
  884. */
  885. var initPanes = function () {
  886. // NOTE: do north & south FIRST so we can measure their height - do center LAST
  887. $.each(c.allPanes.split(","), function() {
  888. var
  889. pane = str(this)
  890. , o = options[pane]
  891. , s = state[pane]
  892. , fx = s.fx
  893. , dir = c[pane].dir
  894. // if o.size is not > 0, then we will use MEASURE the pane and use that as it's 'size'
  895. , size = o.size=="auto" || isNaN(o.size) ? 0 : o.size
  896. , minSize = o.minSize || 1
  897. , maxSize = o.maxSize || 9999
  898. , spacing = o.spacing_open || 0
  899. , sel = o.paneSelector
  900. , isIE6 = ($.browser.msie && $.browser.version < 7)
  901. , CSS = {}
  902. , $P, $C
  903. ;
  904. $Cs[pane] = false; // init
  905. if (sel.substr(0,1)==="#") // ID selector
  906. // NOTE: elements selected 'by ID' DO NOT have to be 'children'
  907. $P = $Ps[pane] = $Container.find(sel+":first");
  908. else { // class or other selector
  909. $P = $Ps[pane] = $Container.children(sel+":first");
  910. // look for the pane nested inside a 'form' element
  911. if (!$P.length) $P = $Ps[pane] = $Container.children("form:first").children(sel+":first");
  912. }
  913. if (!$P.length) {
  914. $Ps[pane] = false; // logic
  915. return true; // SKIP to next
  916. }
  917. // add basic classes & attributes
  918. $P
  919. .attr("pane", pane) // add pane-identifier
  920. .addClass( o.paneClass +" "+ o.paneClass+"-"+pane ) // default = "ui-layout-pane ui-layout-pane-west" - may be a dupe of 'paneSelector'
  921. ;
  922. // init pane-logic vars, etc.
  923. if (pane != "center") {
  924. s.isClosed = false; // true = pane is closed
  925. s.isSliding = false; // true = pane is currently open by 'sliding' over adjacent panes
  926. s.isResizing= false; // true = pane is in process of being resized
  927. s.isHidden = false; // true = pane is hidden - no spacing, resizer or toggler is visible!
  928. s.noRoom = false; // true = pane 'automatically' hidden due to insufficient room - will unhide automatically
  929. // create special keys for internal use
  930. c[pane].pins = []; // used to track and sync 'pin-buttons' for border-panes
  931. }
  932. CSS = $.extend({ visibility: "visible", display: "block" }, c.defaults.cssReq, c[pane].cssReq );
  933. if (o.applyDefaultStyles) $.extend( CSS, c.defaults.cssDef, c[pane].cssDef ); // cosmetic defaults
  934. $P.css(CSS); // add base-css BEFORE 'measuring' to calc size & position
  935. CSS = {}; // reset var
  936. // set css-position to account for container borders & padding
  937. switch (pane) {
  938. case "north": CSS.top = cDims.top;
  939. CSS.left = cDims.left;
  940. CSS.right = cDims.right;
  941. break;
  942. case "south": CSS.bottom = cDims.bottom;
  943. CSS.left = cDims.left;
  944. CSS.right = cDims.right;
  945. break;
  946. case "west": CSS.left = cDims.left; // top, bottom & height set by sizeMidPanes()
  947. break;
  948. case "east": CSS.right = cDims.right; // ditto
  949. break;
  950. case "center": // top, left, width & height set by sizeMidPanes()
  951. }
  952. if (dir == "horz") { // north or south pane
  953. if (size === 0 || size == "auto") {
  954. $P.css({ height: "auto" });
  955. size = $P.outerHeight();
  956. }
  957. size = max(size, minSize);
  958. size = min(size, maxSize);
  959. size = min(size, cDims.innerHeight - spacing);
  960. CSS.height = max(1, cssH(pane, size));
  961. s.size = size; // update state
  962. // make sure minSize is sufficient to avoid errors
  963. s.maxSize = maxSize; // init value
  964. s.minSize = max(minSize, size - CSS.height + 1); // = pane.outerHeight when css.height = 1px
  965. // handle IE6
  966. //if (isIE6) CSS.width = cssW($P, cDims.innerWidth);
  967. $P.css(CSS); // apply size & position
  968. }
  969. else if (dir == "vert") { // east or west pane
  970. if (size === 0 || size == "auto") {
  971. $P.css({ width: "auto", float: "left" }); // float = FORCE pane to auto-size
  972. size = $P.outerWidth();
  973. $P.css({ float: "none" }); // RESET
  974. }
  975. size = max(size, minSize);
  976. size = min(size, maxSize);
  977. size = min(size, cDims.innerWidth - spacing);
  978. CSS.width = max(1, cssW(pane, size));
  979. s.size = size; // update state
  980. s.maxSize = maxSize; // init value
  981. // make sure minSize is sufficient to avoid errors
  982. s.minSize = max(minSize, size - CSS.width + 1); // = pane.outerWidth when css.width = 1px
  983. $P.css(CSS); // apply size - top, bottom & height set by sizeMidPanes
  984. sizeMidPanes(pane, null, true); // true = onInit
  985. }
  986. else if (pane == "center") {
  987. $P.css(CSS); // top, left, width & height set by sizeMidPanes...
  988. sizeMidPanes("center", null, true); // true = onInit
  989. }
  990. // close or hide the pane if specified in settings
  991. if (o.initClosed && o.closable) {
  992. $P.hide().addClass("closed");
  993. s.isClosed = true;
  994. }
  995. else if (o.initHidden || o.initClosed) {
  996. hide(pane, true); // will be completely invisible - no resizer or spacing
  997. s.isHidden = true;
  998. }
  999. else
  1000. $P.addClass("open");
  1001. // check option for auto-handling of pop-ups & drop-downs
  1002. if (o.showOverflowOnHover)
  1003. $P.hover( allowOverflow, resetOverflow );
  1004. /*
  1005. * see if this pane has a 'content element' that we need to auto-size
  1006. */
  1007. if (o.contentSelector) {
  1008. $C = $Cs[pane] = $P.children(o.contentSelector+":first"); // match 1-element only
  1009. if (!$C.length) {
  1010. $Cs[pane] = false;
  1011. return true; // SKIP to next
  1012. }
  1013. $C.css( c.content.cssReq );
  1014. if (o.applyDefaultStyles) $C.css( c.content.cssDef ); // cosmetic defaults
  1015. // NO PANE-SCROLLING when there is a content-div
  1016. $P.css({ overflow: "hidden" });
  1017. }
  1018. });
  1019. };
  1020. /**
  1021. * initHandles
  1022. *
  1023. * Initialize module objects, styling, size and position for all resize bars and toggler buttons
  1024. *
  1025. * @callers create()
  1026. */
  1027. var initHandles = function () {
  1028. // create toggler DIVs for each pane, and set object pointers for them, eg: $R.north = north toggler DIV
  1029. $.each(c.borderPanes.split(","), function() {
  1030. var
  1031. pane = str(this)
  1032. , o = options[pane]
  1033. , s = state[pane]
  1034. , rClass = o.resizerClass
  1035. , tClass = o.togglerClass
  1036. , $P = $Ps[pane]
  1037. ;
  1038. $Rs[pane] = false; // INIT
  1039. $Ts[pane] = false;
  1040. if (!$P || (!o.closable && !o.resizable)) return; // pane does not exist - skip
  1041. var
  1042. edge = c[pane].edge
  1043. , isOpen = $P.is(":visible")
  1044. , spacing = (isOpen ? o.spacing_open : o.spacing_closed)
  1045. , _pane = "-"+ pane // used for classNames
  1046. , _state = (isOpen ? "-open" : "-closed") // used for classNames
  1047. , $R, $T
  1048. ;
  1049. // INIT RESIZER BAR
  1050. $R = $Rs[pane] = $("<span></span>");
  1051. if (isOpen && o.resizable)
  1052. ; // this is handled by initResizable
  1053. else if (!isOpen && o.slidable)
  1054. $R.attr("title", o.sliderTip).css("cursor", o.sliderCursor);
  1055. $R
  1056. // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "paneLeft-resizer"
  1057. .attr("id", (o.paneSelector.substr(0,1)=="#" ? o.paneSelector.substr(1) + "-resizer" : ""))
  1058. .attr("resizer", pane) // so we can read this from the resizer
  1059. .css(c.resizers.cssReq) // add base/required styles
  1060. // POSITION of resizer bar - allow for container border & padding
  1061. .css(edge, cDims[edge] + getPaneSize(pane))
  1062. // ADD CLASSNAMES - eg: class="resizer resizer-west resizer-open"
  1063. .addClass( rClass +" "+ rClass+_pane +" "+ rClass+_state +" "+ rClass+_pane+_state )
  1064. .appendTo($Container) // append DIV to container
  1065. ;
  1066. // ADD VISUAL STYLES
  1067. if (o.applyDefaultStyles)
  1068. $R.css(c.resizers.cssDef);
  1069. if (o.closable) {
  1070. // INIT COLLAPSER BUTTON
  1071. $T = $Ts[pane] = $("<div></div>");
  1072. $T
  1073. // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "paneLeft-toggler"
  1074. .attr("id", (o.paneSelector.substr(0,1)=="#" ? o.paneSelector.substr(1) + "-toggler" : ""))
  1075. .css(c.togglers.cssReq) // add base/required styles
  1076. .attr("title", (isOpen ? o.togglerTip_open : o.togglerTip_closed))
  1077. .click(function(evt){ toggle(pane); evt.stopPropagation(); })
  1078. .mouseover(function(evt){ evt.stopPropagation(); }) // prevent resizer event
  1079. // ADD CLASSNAMES - eg: class="toggler toggler-west toggler-west-open"
  1080. .addClass( tClass +" "+ tClass+_pane +" "+ tClass+_state +" "+ tClass+_pane+_state )
  1081. .appendTo($R) // append SPAN to resizer DIV
  1082. ;
  1083. // ADD INNER-SPANS TO TOGGLER
  1084. if (o.togglerContent_open) // ui-layout-open
  1085. $("<span>"+ o.togglerContent_open +"</span>")
  1086. .addClass("content content-open")
  1087. .css("display", s.isClosed ? "none" : "block")
  1088. .appendTo( $T )
  1089. ;
  1090. if (o.togglerContent_closed) // ui-layout-closed
  1091. $("<span>"+ o.togglerContent_closed +"</span>")
  1092. .addClass("content content-closed")
  1093. .css("display", s.isClosed ? "block" : "none")
  1094. .appendTo( $T )
  1095. ;
  1096. // ADD BASIC VISUAL STYLES
  1097. if (o.applyDefaultStyles)
  1098. $T.css(c.togglers.cssDef);
  1099. if (!isOpen) bindStartSlidingEvent(pane, true); // will enable if state.PANE.isSliding = true
  1100. }
  1101. });
  1102. // SET ALL HANDLE SIZES & LENGTHS
  1103. sizeHandles("all", true); // true = onInit
  1104. };
  1105. /**
  1106. * initResizable
  1107. *
  1108. * Add resize-bars to all panes that specify it in options
  1109. *
  1110. * @dependancies $.fn.resizable - will abort if not found
  1111. * @callers create()
  1112. */
  1113. var initResizable = function () {
  1114. var
  1115. draggingAvailable = (typeof $.fn.draggable == "function")
  1116. , minPosition, maxPosition, edge // set in start()
  1117. ;
  1118. $.each(c.borderPanes.split(","), function() {
  1119. var
  1120. pane = str(this)
  1121. , o = options[pane]
  1122. , s = state[pane]
  1123. ;
  1124. if (!draggingAvailable || !$Ps[pane] || !o.resizable) {
  1125. o.resizable = false;
  1126. return true; // skip to next
  1127. }
  1128. var
  1129. rClass = o.resizerClass
  1130. // 'drag' classes are applied to the ORIGINAL resizer-bar while dragging is in process
  1131. , dragClass = rClass+"-drag" // resizer-drag
  1132. , dragPaneClass = rClass+"-"+pane+"-drag" // resizer-north-drag
  1133. // 'dragging' class is applied to the CLONED resizer-bar while it is being dragged
  1134. , draggingClass = rClass+"-dragging" // resizer-dragging
  1135. , draggingPaneClass = rClass+"-"+pane+"-dragging" // resizer-north-dragging
  1136. , draggingClassSet = false // logic var
  1137. , $P = $Ps[pane]
  1138. , $R = $Rs[pane]
  1139. ;
  1140. if (!s.isClosed)
  1141. $R
  1142. .attr("title", o.resizerTip)
  1143. .css("cursor", o.resizerCursor) // n-resize, s-resize, etc
  1144. ;
  1145. $R.draggable({
  1146. containment: $Container[0] // limit resizing to layout container
  1147. , axis: (c[pane].dir=="horz" ? "y" : "x") // limit resizing to horz or vert axis
  1148. , delay: 200
  1149. , distance: 1
  1150. // basic format for helper - style it using class: .ui-draggable-dragging
  1151. , helper: "clone"
  1152. , opacity: o.resizerDragOpacity
  1153. //, iframeFix: o.draggableIframeFix // TODO: consider using when bug is fixed
  1154. , zIndex: c.zIndex.resizing
  1155. , start: function (e, ui) {
  1156. // onresize_start callback - will CANCEL hide if returns false
  1157. // TODO: CONFIRM that dragging can be cancelled like this???
  1158. if (false === execUserCallback(pane, o.onresize_start)) return false;
  1159. s.isResizing = true; // prevent pane from closing while resizing
  1160. clearTimer(pane, "closeSlider"); // just in case already triggered
  1161. $R.addClass( dragClass +" "+ dragPaneClass ); // add drag classes
  1162. draggingClassSet = false; // reset logic var - see drag()
  1163. // SET RESIZING LIMITS - used in drag()
  1164. var resizerWidth = (pane=="east" || pane=="south" ? o.spacing_open : 0);
  1165. setPaneMinMaxSizes(pane); // update pane-state
  1166. s.minPosition -= resizerWidth;
  1167. s.maxPosition -= resizerWidth;
  1168. edge = (c[pane].dir=="horz" ? "top" : "left");
  1169. // MASK PANES WITH IFRAMES OR OTHER TROUBLESOME ELEMENTS
  1170. $(o.maskIframesOnResize === true ? "iframe" : o.maskIframesOnResize).each(function() {
  1171. $('<div class="ui-layout-mask"/>')
  1172. .css({
  1173. background: "#fff"
  1174. , opacity: "0.001"
  1175. , zIndex: 9
  1176. , position: "absolute"
  1177. , width: this.offsetWidth+"px"
  1178. , height: this.offsetHeight+"px"
  1179. })
  1180. .css($(this).offset()) // top & left
  1181. .appendTo(this.parentNode) // put div INSIDE pane to avoid zIndex issues
  1182. ;
  1183. });
  1184. }
  1185. , drag: function (e, ui) {
  1186. if (!draggingClassSet) { // can only add classes after clone has been added to the DOM
  1187. $(".ui-draggable-dragging")
  1188. .addClass( draggingClass +" "+ draggingPaneClass ) // add dragging classes
  1189. .children().css("visibility","hidden") // hide toggler inside dragged resizer-bar
  1190. ;
  1191. draggingClassSet = true;
  1192. // draggable bug!? RE-SET zIndex to prevent E/W resize-bar showing through N/S pane!
  1193. if (s.isSliding) $Ps[pane].css("zIndex", c.zIndex.sliding);
  1194. }
  1195. // CONTAIN RESIZER-BAR TO RESIZING LIMITS
  1196. if (ui.position[edge] < s.minPosition) ui.position[edge] = s.minPosition;
  1197. else if (ui.position[edge] > s.maxPosition) ui.position[edge] = s.maxPosition;
  1198. }
  1199. , stop: function (e, ui) {
  1200. var
  1201. dragPos = ui.position
  1202. , resizerPos
  1203. , newSize
  1204. ;
  1205. $R.removeClass( dragClass +" "+ dragPaneClass ); // remove drag classes
  1206. switch (pane) {
  1207. case "north": resizerPos = dragPos.top; break;
  1208. case "west": resizerPos = dragPos.left; break;
  1209. case "south": resizerPos = cDims.outerHeight - dragPos.top - $R.outerHeight(); break;
  1210. case "east": resizerPos = cDims.outerWidth - dragPos.left - $R.outerWidth(); break;
  1211. }
  1212. // remove container margin from resizer position to get the pane size
  1213. newSize = resizerPos - cDims[ c[pane].edge ];
  1214. sizePane(pane, newSize);
  1215. // UN-MASK PANES MASKED IN drag.start
  1216. $("div.ui-layout-mask").remove(); // Remove iframe masks
  1217. s.isResizing = false;
  1218. }
  1219. });
  1220. });
  1221. };
  1222. /*
  1223. * ###########################
  1224. * ACTION METHODS
  1225. * ###########################
  1226. */
  1227. /**
  1228. * hide / show
  1229. *
  1230. * Completely 'hides' a pane, including its spacing - as if it does not exist
  1231. * The pane is not actually 'removed' from the source, so can use 'show' to un-hide it
  1232. *
  1233. * @param String pane The pane being hidden, ie: north, south, east, or west
  1234. */
  1235. var hide = function (pane, onInit) {
  1236. var
  1237. o = options[pane]
  1238. , s = state[pane]
  1239. , $P = $Ps[pane]
  1240. , $R = $Rs[pane]
  1241. ;
  1242. if (!$P || s.isHidden) return; // pane does not exist OR is already hidden
  1243. // onhide_start callback - will CANCEL hide if returns false
  1244. if (false === execUserCallback(pane, o.onhide_start)) return;
  1245. s.isSliding = false; // just in case
  1246. // now hide the elements
  1247. if ($R) $R.hide(); // hide resizer-bar
  1248. if (onInit || s.isClosed) {
  1249. s.isClosed = true; // to trigger open-animation on show()
  1250. s.isHidden = true;
  1251. $P.hide(); // no animation when loading page
  1252. sizeMidPanes(c[pane].dir == "horz" ? "all" : "center");
  1253. execUserCallback(pane, o.onhide_end || o.onhide);
  1254. }
  1255. else {
  1256. s.isHiding = true; // used by onclose
  1257. close(pane, false); // adjust all panes to fit
  1258. //s.isHidden = true; - will be set by close - if not cancelled
  1259. }
  1260. };
  1261. var show = function (pane, openPane) {
  1262. var
  1263. o = options[pane]
  1264. , s = state[pane]
  1265. , $P = $Ps[pane]
  1266. , $R = $Rs[pane]
  1267. ;
  1268. if (!$P || !s.isHidden) return; // pane does not exist OR is not hidden
  1269. // onhide_start callback - will CANCEL hide if returns false
  1270. if (false === execUserCallback(pane, o.onshow_start)) return;
  1271. s.isSliding = false; // just in case
  1272. s.isShowing = true; // used by onopen/onclose
  1273. //s.isHidden = false; - will be set by open/close - if not cancelled
  1274. // now show the elements
  1275. if ($R && o.spacing_open > 0) $R.show();
  1276. if (openPane === false)
  1277. close(pane, true); // true = force
  1278. else
  1279. open(pane); // adjust all panes to fit
  1280. };
  1281. /**
  1282. * toggle
  1283. *
  1284. * Toggles a pane open/closed by calling either open or close
  1285. *
  1286. * @param String pane The pane being toggled, ie: north, south, east, or west
  1287. */
  1288. var toggle = function (pane) {
  1289. var s = state[pane];
  1290. if (s.isHidden)
  1291. show(pane); // will call 'open' after unhiding it
  1292. else if (s.isClosed)
  1293. open(pane);
  1294. else
  1295. close(pane);
  1296. };
  1297. /**
  1298. * close
  1299. *
  1300. * Close the specified pane (animation optional), and resize all other panes as needed
  1301. *
  1302. * @param String pane The pane being closed, ie: north, south, east, or west
  1303. */
  1304. var close = function (pane, force, noAnimation) {
  1305. var
  1306. $P = $Ps[pane]
  1307. , $R = $Rs[pane]
  1308. , $T = $Ts[pane]
  1309. , o = options[pane]
  1310. , s = state[pane]
  1311. , doFX = !noAnimation && !s.isClosed && (o.fxName_close != "none")
  1312. , edge = c[pane].edge
  1313. , rClass = o.resizerClass
  1314. , tClass = o.togglerClass
  1315. , _pane = "-"+ pane // used for classNames
  1316. , _open = "-open"
  1317. , _sliding= "-sliding"
  1318. , _closed = "-closed"
  1319. // transfer logic vars to temp vars
  1320. , isShowing = s.isShowing
  1321. , isHiding = s.isHiding
  1322. ;
  1323. // now clear the logic vars
  1324. delete s.isShowing;
  1325. delete s.isHiding;
  1326. if (!$P || (!o.resizable && !o.closable)) return; // invalid request
  1327. else if (!force && s.isClosed && !isShowing) return; // already closed
  1328. if (c.isLayoutBusy) { // layout is 'busy' - probably with an animation
  1329. setFlowCallback("close", pane, force); // set a callback for this action, if possible
  1330. return; // ABORT
  1331. }
  1332. // onclose_start callback - will CANCEL hide if returns false
  1333. // SKIP if just 'showing' a hidden pane as 'closed'
  1334. if (!isShowing && false === execUserCallback(pane, o.onclose_start)) return;
  1335. // SET flow-control flags
  1336. c[pane].isMoving = true;
  1337. c.isLayoutBusy = true;
  1338. s.isClosed = true;
  1339. // update isHidden BEFORE sizing panes
  1340. if (isHiding) s.isHidden = true;
  1341. else if (isShowing) s.isHidden = false;
  1342. // sync any 'pin buttons'
  1343. syncPinBtns(pane, false);
  1344. // resize panes adjacent to this one
  1345. if (!s.isSliding) sizeMidPanes(c[pane].dir == "horz" ? "all" : "center");
  1346. // if this pane has a resizer bar, move it now
  1347. if ($R) {
  1348. $R
  1349. .css(edge, cDims[edge]) // move the resizer bar
  1350. .removeClass( rClass+_open +" "+ rClass+_pane+_open )
  1351. .removeClass( rClass+_sliding +" "+ rClass+_pane+_sliding )
  1352. .addClass( rClass+_closed +" "+ rClass+_pane+_closed )
  1353. ;
  1354. // DISABLE 'resizing' when closed - do this BEFORE bindStartSlidingEvent
  1355. if (o.resizable)
  1356. $R
  1357. .draggable("disable")
  1358. .css("cursor", "default")
  1359. .attr("title","")
  1360. ;
  1361. // if pane has a toggler button, adjust that too
  1362. if ($T) {
  1363. $T
  1364. .removeClass( tClass+_open +" "+ tClass+_pane+_open )
  1365. .addClass( tClass+_closed +" "+ tClass+_pane+_closed )
  1366. .attr("title", o.togglerTip_closed) // may be blank
  1367. ;
  1368. }
  1369. sizeHandles(); // resize 'length' and position togglers for adjacent panes
  1370. }
  1371. // ANIMATE 'CLOSE' - if no animation, then was ALREADY shown above
  1372. if (doFX) {
  1373. lockPaneForFX(pane, true); // need to set left/top so animation will work
  1374. $P.hide( o.fxName_close, o.fxSettings_close, o.fxSpeed_close, function () {
  1375. lockPaneForFX(pane, false); // undo
  1376. if (!s.isClosed) return; // pane was opened before animation finished!
  1377. close_2();
  1378. });
  1379. }
  1380. else {
  1381. $P.hide(); // just hide pane NOW
  1382. close_2();
  1383. }
  1384. // SUBROUTINE
  1385. function close_2 () {
  1386. bindStartSlidingEvent(pane, true); // will enable if state.PANE.isSliding = true
  1387. // onclose callback - UNLESS just 'showing' a hidden pane as 'closed'
  1388. if (!isShowing) execUserCallback(pane, o.onclose_end || o.onclose);
  1389. // onhide OR onshow callback
  1390. if (isShowing) execUserCallback(pane, o.onshow_end || o.onshow);
  1391. if (isHiding) execUserCallback(pane, o.onhide_end || o.onhide);
  1392. // internal flow-control callback
  1393. execFlowCallback(pane);
  1394. }
  1395. };
  1396. /**
  1397. * open
  1398. *
  1399. * Open the specified pane (animation optional), and resize all other panes as needed
  1400. *
  1401. * @param String pane The pane being opened, ie: north, south, east, or west
  1402. */
  1403. var open = function (pane, slide, noAnimation) {
  1404. var
  1405. $P = $Ps[pane]
  1406. , $R = $Rs[pane]
  1407. , $T = $Ts[pane]
  1408. , o = options[pane]
  1409. , s = state[pane]
  1410. , doFX = !noAnimation && s.isClosed && (o.fxName_open != "none")
  1411. , edge = c[pane].edge
  1412. , rClass = o.resizerClass
  1413. , tClass = o.togglerClass
  1414. , _pane = "-"+ pane // used for classNames
  1415. , _open = "-open"
  1416. , _closed = "-closed"
  1417. , _sliding= "-sliding"
  1418. // transfer logic var to temp var
  1419. , isShowing = s.isShowing
  1420. ;
  1421. // now clear the logic var
  1422. delete s.isShowing;
  1423. if (!$P || (!o.resizable && !o.closable)) return; // invalid request
  1424. else if (!s.isClosed && !s.isSliding) return; // already open
  1425. // pane can ALSO be unhidden by just calling show(), so handle this scenario
  1426. if (s.isHidden && !isShowing) {
  1427. show(pane, true);
  1428. return;
  1429. }
  1430. if (c.isLayoutBusy) { // layout is 'busy' - probably with an animation
  1431. setFlowCallback("open", pane, slide); // set a callback for this action, if possible
  1432. return; // ABORT
  1433. }
  1434. // onopen_start callback - will CANCEL hide if returns false
  1435. if (false === execUserCallback(pane, o.onopen_start)) return;
  1436. // SET flow-control flags
  1437. c[pane].isMoving = true;
  1438. c.isLayoutBusy = true;
  1439. // 'PIN PANE' - stop sliding
  1440. if (s.isSliding && !slide) // !slide = 'open pane normally' - NOT sliding
  1441. bindStopSlidingEvents(pane, false); // will set isSliding=false
  1442. s.isClosed = false;
  1443. // update isHidden BEFORE sizing panes
  1444. if (isShowing) s.isHidden = false;
  1445. // Container size may have changed - shrink the pane if now 'too big'
  1446. setPaneMinMaxSizes(pane); // update pane-state
  1447. if (s.size > s.maxSize) // pane is too big! resize it before opening
  1448. $P.css( c[pane].sizeType, max(1, cssSize(pane, s.maxSize)) );
  1449. bindStartSlidingEvent(pane, false); // remove trigger event from resizer-bar
  1450. if (doFX) { // ANIMATE
  1451. lockPaneForFX(pane, true); // need to set left/top so animation will work
  1452. $P.show( o.fxName_open, o.fxSettings_open, o.fxSpeed_open, function() {
  1453. lockPaneForFX(pane, false); // undo
  1454. if (s.isClosed) return; // pane was closed before animation finished!
  1455. open_2(); // continue
  1456. });
  1457. }
  1458. else {// no animation
  1459. $P.show(); // just show pane and...
  1460. open_2(); // continue
  1461. }
  1462. // SUBROUTINE
  1463. function open_2 () {
  1464. // NOTE: if isSliding, then other panes are NOT 'resized'
  1465. if (!s.isSliding) // resize all panes adjacent to this one
  1466. sizeMidPanes(c[pane].dir=="vert" ? "center" : "all");
  1467. // if this pane has a toggler, move it now
  1468. if ($R) {
  1469. $R
  1470. .css(edge, cDims[edge] + getPaneSize(pane)) // move the toggler
  1471. .removeClass( rClass+_closed +" "+ rClass+_pane+_closed )
  1472. .addClass( rClass+_open +" "+ rClass+_pane+_open )
  1473. .addClass( !s.isSliding ? "" : rClass+_sliding +" "+ rClass+_pane+_sliding )
  1474. ;
  1475. if (o.resizable)
  1476. $R
  1477. .draggable("enable")
  1478. .css("cursor", o.resizerCursor)
  1479. .attr("title", o.resizerTip)
  1480. ;
  1481. else
  1482. $R.css("cursor", "default"); // n-resize, s-resize, etc
  1483. // if pane also has a toggler button, adjust that too
  1484. if ($T) {
  1485. $T
  1486. .removeClass( tClass+_closed +" "+ tClass+_pane+_closed )
  1487. .addClass( tClass+_open +" "+ tClass+_pane+_open )
  1488. .attr("title", o.togglerTip_open) // may be blank
  1489. ;
  1490. }
  1491. sizeHandles("all"); // resize resizer & toggler sizes for all panes
  1492. }
  1493. // resize content every time pane opens - to be sure
  1494. sizeContent(pane);
  1495. // sync any 'pin buttons'
  1496. syncPinBtns(pane, !s.isSliding);
  1497. // onopen callback
  1498. execUserCallback(pane, o.onopen_end || o.onopen);
  1499. // onshow callback
  1500. if (isShowing) execUserCallback(pane, o.onshow_end || o.onshow);
  1501. // internal flow-control callback
  1502. execFlowCallback(pane);
  1503. }
  1504. };
  1505. /**
  1506. * lockPaneForFX
  1507. *
  1508. * Must set left/top on East/South panes so animation will work properly
  1509. *
  1510. * @param String pane The pane to lock, 'east' or 'south' - any other is ignored!
  1511. * @param Boolean doLock true = set left/top, false = remove
  1512. */
  1513. var lockPaneForFX = function (pane, doLock) {
  1514. var $P = $Ps[pane];
  1515. if (doLock) {
  1516. $P.css({ zIndex: c.zIndex.animation }); // overlay all elements during animation
  1517. if (pane=="south")
  1518. $P.css({ top: cDims.top + cDims.innerHeight - $P.outerHeight() });
  1519. else if (pane=="east")
  1520. $P.css({ left: cDims.left + cDims.innerWidth - $P.outerWidth() });
  1521. }
  1522. else {
  1523. if (!state[pane].isSliding) $P.css({ zIndex: c.zIndex.pane_normal });
  1524. if (pane=="south")
  1525. $P.css({ top: "auto" });
  1526. else if (pane=="east")
  1527. $P.css({ left: "auto" });
  1528. }
  1529. };
  1530. /**
  1531. * bindStartSlidingEvent
  1532. *
  1533. * Toggle sliding functionality of a specific pane on/off by adding removing 'slide open' trigger
  1534. *
  1535. * @callers open(), close()
  1536. * @param String pane The pane to enable/disable, 'north', 'south', etc.
  1537. * @param Boolean enable Enable or Disable sliding?
  1538. */
  1539. var bindStartSlidingEvent = function (pane, enable) {
  1540. var
  1541. o = options[pane]
  1542. , $R = $Rs[pane]
  1543. , trigger = o.slideTrigger_open
  1544. ;
  1545. if (!$R || !o.slidable) return;
  1546. // make sure we have a valid event
  1547. if (trigger != "click" && trigger != "dblclick" && trigger != "mouseover") trigger = "click";
  1548. $R
  1549. // add or remove trigger event
  1550. [enable ? "bind" : "unbind"](trigger, slideOpen)
  1551. // set the appropriate cursor & title/tip
  1552. .css("cursor", (enable ? o.sliderCursor: "default"))
  1553. .attr("title", (enable ? o.sliderTip : ""))
  1554. ;
  1555. };
  1556. /**
  1557. * bindStopSlidingEvents
  1558. *
  1559. * Add or remove 'mouseout' events to 'slide close' when pane is 'sliding' open or closed
  1560. * Also increases zIndex when pane is sliding open
  1561. * See bindStartSlidingEvent for code to control 'slide open'
  1562. *
  1563. * @callers slideOpen(), slideClosed()
  1564. * @param String pane The pane to process, 'north', 'south', etc.
  1565. * @param Boolean isOpen Is pane open or closed?
  1566. */
  1567. var bindStopSlidingEvents = function (pane, enable) {
  1568. var
  1569. o = options[pane]
  1570. , s = state[pane]
  1571. , trigger = o.slideTrigger_close
  1572. , action = (enable ? "bind" : "unbind") // can't make 'unbind' work! - see disabled code below
  1573. , $P = $Ps[pane]
  1574. , $R = $Rs[pane]
  1575. ;
  1576. s.isSliding = enable; // logic
  1577. clearTimer(pane, "closeSlider"); // just in case
  1578. // raise z-index when sliding
  1579. $P.css({ zIndex: (enable ? c.zIndex.sliding : c.zIndex.pane_normal) });
  1580. $R.css({ zIndex: (enable ? c.zIndex.sliding : c.zIndex.resizer_normal) });
  1581. // make sure we have a valid event
  1582. if (trigger != "click" && trigger != "mouseout") trigger = "mouseout";
  1583. // when trigger is 'mouseout', must cancel timer when mouse moves between 'pane' and 'resizer'
  1584. if (enable) { // BIND trigger events
  1585. $P.bind(trigger, slideClosed );
  1586. $R.bind(trigger, slideClosed );
  1587. if (trigger = "mouseout") {
  1588. $P.bind("mouseover", cancelMouseOut );
  1589. $R.bind("mouseover", cancelMouseOut );
  1590. }
  1591. }
  1592. else { // UNBIND trigger events
  1593. // TODO: why does unbind of a 'single function' not work reliably?
  1594. //$P[action](trigger, slideClosed );
  1595. $P.unbind(trigger);
  1596. $R.unbind(trigger);
  1597. if (trigger = "mouseout") {
  1598. //$P[action]("mouseover", cancelMouseOut );
  1599. $P.unbind("mouseover");
  1600. $R.unbind("mouseover");
  1601. clearTimer(pane, "closeSlider");
  1602. }
  1603. }
  1604. // SUBROUTINE for mouseout timer clearing
  1605. function cancelMouseOut (evt) {
  1606. clearTimer(pane, "closeSlider");
  1607. evt.stopPropagation();
  1608. }
  1609. };
  1610. var slideOpen = function () {
  1611. var pane = $(this).attr("resizer"); // attr added by initHandles
  1612. if (state[pane].isClosed) { // skip if already open!
  1613. bindStopSlidingEvents(pane, true); // pane is opening, so BIND trigger events to close it
  1614. open(pane, true); // true = slide - ie, called from here!
  1615. }
  1616. };
  1617. var slideClosed = function () {
  1618. var
  1619. $E = $(this)
  1620. , pane = $E.attr("pane") || $E.attr("resizer")
  1621. , o = options[pane]
  1622. , s = state[pane]
  1623. ;
  1624. if (s.isClosed || s.isResizing)
  1625. return; // skip if already closed OR in process of resizing
  1626. else if (o.slideTrigger_close == "click")
  1627. close_NOW(); // close immediately onClick
  1628. else // trigger = mouseout - use a delay
  1629. setTimer(pane, "closeSlider", close_NOW, 300); // .3 sec delay
  1630. // SUBROUTINE for timed close
  1631. function close_NOW () {
  1632. bindStopSlidingEvents(pane, false); // pane is being closed, so UNBIND trigger events
  1633. if (!s.isClosed) close(pane); // skip if already closed!
  1634. }
  1635. };
  1636. /**
  1637. * sizePane
  1638. *
  1639. * @callers initResizable.stop()
  1640. * @param String pane The pane being resized - usually west or east, but potentially north or south
  1641. * @param Integer newSize The new size for this pane - will be validated
  1642. */
  1643. var sizePane = function (pane, size) {
  1644. // TODO: accept "auto" as size, and size-to-fit pane content
  1645. var
  1646. edge = c[pane].edge
  1647. , dir = c[pane].dir
  1648. , o = options[pane]
  1649. , s = state[pane]
  1650. , $P = $Ps[pane]
  1651. , $R = $Rs[pane]
  1652. ;
  1653. // calculate 'current' min/max sizes
  1654. setPaneMinMaxSizes(pane); // update pane-state
  1655. // compare/update calculated min/max to user-options
  1656. s.minSize = max(s.minSize, o.minSize);
  1657. if (o.maxSize > 0) s.maxSize = min(s.maxSize, o.maxSize);
  1658. // validate passed size
  1659. size = max(size, s.minSize);
  1660. size = min(size, s.maxSize);
  1661. s.size = size; // update state
  1662. // move the resizer bar and resize the pane
  1663. $R.css( edge, size + cDims[edge] );
  1664. $P.css( c[pane].sizeType, max(1, cssSize(pane, size)) );
  1665. // resize all the adjacent panes, and adjust their toggler buttons
  1666. if (!s.isSliding) sizeMidPanes(dir=="horz" ? "all" : "center");
  1667. sizeHandles();
  1668. sizeContent(pane);
  1669. execUserCallback(pane, o.onresize_end || o.onresize);
  1670. };
  1671. /**
  1672. * sizeMidPanes
  1673. *
  1674. * @callers create(), open(), close(), onWindowResize()
  1675. */
  1676. var sizeMidPanes = function (panes, overrideDims, onInit) {
  1677. if (!panes || panes == "all") panes = "east,west,center";
  1678. var d = getPaneDims();
  1679. if (overrideDims) $.extend( d, overrideDims );
  1680. $.each(panes.split(","), function() {
  1681. if (!$Ps[this]) return; // NO PANE - skip
  1682. var
  1683. pane = str(this)
  1684. , o = options[pane]
  1685. , s = state[pane]
  1686. , $P = $Ps[pane]
  1687. , $R = $Rs[pane]
  1688. , hasRoom = true
  1689. , CSS = {}
  1690. ;
  1691. if (pane == "center") {
  1692. d = getPaneDims(); // REFRESH Dims because may have just 'unhidden' East or West pane after a 'resize'
  1693. CSS = $.extend( {}, d ); // COPY ALL of the paneDims
  1694. CSS.width = max(1, cssW(pane, CSS.width));
  1695. CSS.height = max(1, cssH(pane, CSS.height));
  1696. hasRoom = (CSS.width > 1 && CSS.height > 1);
  1697. /*
  1698. * Extra CSS for IE6 or IE7 in Quirks-mode - add 'width' to NORTH/SOUTH panes
  1699. * Normally these panes have only 'left' & 'right' positions so pane auto-sizes
  1700. */
  1701. if ($.browser.msie && (!$.boxModel || $.browser.version < 7)) {
  1702. if ($Ps.north) $Ps.north.css({ width: cssW($Ps.north, cDims.innerWidth) });
  1703. if ($Ps.south) $Ps.south.css({ width: cssW($Ps.south, cDims.innerWidth) });
  1704. }
  1705. }
  1706. else { // for east and west, set only the height
  1707. CSS.top = d.top;
  1708. CSS.bottom = d.bottom;
  1709. CSS.height = max(1, cssH(pane, d.height));
  1710. hasRoom = (CSS.height > 1);
  1711. }
  1712. if (hasRoom) {
  1713. $P.css(CSS);
  1714. if (s.noRoom) {
  1715. s.noRoom = false;
  1716. if (s.isHidden) return;
  1717. else show(pane, !s.isClosed);
  1718. /* OLD CODE - keep until sure line above works right!
  1719. if (!s.isClosed) $P.show(); // in case was previously hidden due to NOT hasRoom
  1720. if ($R) $R.show();
  1721. */
  1722. }
  1723. if (!onInit) {
  1724. sizeContent(pane);
  1725. execUserCallback(pane, o.onresize_end || o.onresize);
  1726. }
  1727. }
  1728. else if (!s.noRoom) { // no room for pane, so just hide it (if not already)
  1729. s.noRoom = true; // update state
  1730. if (s.isHidden) return;
  1731. if (onInit) { // skip onhide callback and other logic onLoad
  1732. $P.hide();
  1733. if ($R) $R.hide();
  1734. }
  1735. else hide(pane);
  1736. }
  1737. });
  1738. };
  1739. var sizeContent = function (panes) {
  1740. if (!panes || panes == "all") panes = c.allPanes;
  1741. $.each(panes.split(","), function() {
  1742. if (!$Cs[this]) return; // NO CONTENT - skip
  1743. var
  1744. pane = str(this)
  1745. , ignore = options[pane].contentIgnoreSelector
  1746. , $P = $Ps[pane]
  1747. , $C = $Cs[pane]
  1748. , e_C = $C[0] // DOM element
  1749. , height = cssH($P); // init to pane.innerHeight
  1750. ;
  1751. $P.children().each(function() {
  1752. if (this == e_C) return; // Content elem - skip
  1753. var $E = $(this);
  1754. if (!ignore || !$E.is(ignore))
  1755. height -= $E.outerHeight();
  1756. });
  1757. if (height > 0)
  1758. height = cssH($C, height);
  1759. if (height < 1)
  1760. $C.hide(); // no room for content!
  1761. else
  1762. $C.css({ height: height }).show();
  1763. });
  1764. };
  1765. /**
  1766. * sizeHandles
  1767. *
  1768. * Called every time a pane is opened, closed, or resized to slide the togglers to 'center' and adjust their length if necessary
  1769. *
  1770. * @callers initHandles(), open(), close(), resizeAll()
  1771. */
  1772. var sizeHandles = function (panes, onInit) {
  1773. if (!panes || panes == "all") panes = c.borderPanes;
  1774. $.each(panes.split(","), function() {
  1775. var
  1776. pane = str(this)
  1777. , o = options[pane]
  1778. , s = state[pane]
  1779. , $P = $Ps[pane]
  1780. , $R = $Rs[pane]
  1781. , $T = $Ts[pane]
  1782. ;
  1783. if (!$P || !$R || (!o.resizable && !o.closable)) return; // skip
  1784. var
  1785. dir = c[pane].dir
  1786. , _state = (s.isClosed ? "_closed" : "_open")
  1787. , spacing = o["spacing"+ _state]
  1788. , togAlign = o["togglerAlign"+ _state]
  1789. , togLen = o["togglerLength"+ _state]
  1790. , paneLen
  1791. , offset
  1792. , CSS = {}
  1793. ;
  1794. if (spacing == 0) {
  1795. $R.hide();
  1796. return;
  1797. }
  1798. else if (!s.noRoom && !s.isHidden) // skip if resizer was hidden for any reason
  1799. $R.show(); // in case was previously hidden
  1800. // Resizer Bar is ALWAYS same width/height of pane it is attached to
  1801. if (dir == "horz") { // north/south
  1802. paneLen = $P.outerWidth();
  1803. $R.css({
  1804. width: max(1, cssW($R, paneLen)) // account for borders & padding
  1805. , height: max(1, cssH($R, spacing)) // ditto
  1806. , left: cssNum($P, "left")
  1807. });
  1808. }
  1809. else { // east/west
  1810. paneLen = $P.outerHeight();
  1811. $R.css({
  1812. height: max(1, cssH($R, paneLen)) // account for borders & padding
  1813. , width: max(1, cssW($R, spacing)) // ditto
  1814. , top: cDims.top + getPaneSize("north", true)
  1815. //, top: cssNum($Ps["center"], "top")
  1816. });
  1817. }
  1818. if ($T) {
  1819. if (togLen == 0 || (s.isSliding && o.hideTogglerOnSlide)) {
  1820. $T.hide(); // always HIDE the toggler when 'sliding'
  1821. return;
  1822. }
  1823. else
  1824. $T.show(); // in case was previously hidden
  1825. if (!(togLen > 0) || togLen == "100%" || togLen > paneLen) {
  1826. togLen = paneLen;
  1827. offset = 0;
  1828. }
  1829. else { // calculate 'offset' based on options.PANE.togglerAlign_open/closed
  1830. if (typeof togAlign == "string") {
  1831. switch (togAlign) {
  1832. case "top":
  1833. case "left": offset = 0;
  1834. break;
  1835. case "bottom":
  1836. case "right": offset = paneLen - togLen;
  1837. break;
  1838. case "middle":
  1839. case "center":
  1840. default: offset = Math.floor((paneLen - togLen) / 2); // 'default' catches typos
  1841. }
  1842. }
  1843. else { // togAlign = number
  1844. var x = parseInt(togAlign); //
  1845. if (togAlign >= 0) offset = x;
  1846. else offset = paneLen - togLen + x; // NOTE: x is negative!
  1847. }
  1848. }
  1849. var
  1850. $TC_o = (o.togglerContent_open ? $T.children(".content-open") : false)
  1851. , $TC_c = (o.togglerContent_closed ? $T.children(".content-closed") : false)
  1852. , $TC = (s.isClosed ? $TC_c : $TC_o)
  1853. ;
  1854. if ($TC_o) $TC_o.css("display", s.isClosed ? "none" : "block");
  1855. if ($TC_c) $TC_c.css("display", s.isClosed ? "block" : "none");
  1856. if (dir == "horz") { // north/south
  1857. var width = cssW($T, togLen);
  1858. $T.css({
  1859. width: max(0, width) // account for borders & padding
  1860. , height: max(1, cssH($T, spacing)) // ditto
  1861. , left: offset // TODO: VERIFY that toggler positions correctly for ALL values
  1862. });
  1863. if ($TC) // CENTER the toggler content SPAN
  1864. $TC.css("marginLeft", Math.floor((width-$TC.outerWidth())/2)); // could be negative
  1865. }
  1866. else { // east/west
  1867. var height = cssH($T, togLen);
  1868. $T.css({
  1869. height: max(0, height) // account for borders & padding
  1870. , width: max(1, cssW($T, spacing)) // ditto
  1871. , top: offset // POSITION the toggler
  1872. });
  1873. if ($TC) // CENTER the toggler content SPAN
  1874. $TC.css("marginTop", Math.floor((height-$TC.outerHeight())/2)); // could be negative
  1875. }
  1876. }
  1877. // DONE measuring and sizing this resizer/toggler, so can be 'hidden' now
  1878. if (onInit && o.initHidden) {
  1879. $R.hide();
  1880. if ($T) $T.hide();
  1881. }
  1882. });
  1883. };
  1884. /**
  1885. * resizeAll
  1886. *
  1887. * @callers window.onresize(), callbacks or custom code
  1888. */
  1889. var resizeAll = function () {
  1890. var
  1891. oldW = cDims.innerWidth
  1892. , oldH = cDims.innerHeight
  1893. ;
  1894. cDims = state.container = getElemDims($Container); // UPDATE container dimensions
  1895. var
  1896. checkH = (cDims.innerHeight < oldH)
  1897. , checkW = (cDims.innerWidth < oldW)
  1898. , s, dir
  1899. ;
  1900. if (checkH || checkW)
  1901. // NOTE special order for sizing: S-N-E-W
  1902. $.each(["south","north","east","west"], function(i,pane) {
  1903. s = state[pane];
  1904. dir = c[pane].dir;
  1905. if (!s.isClosed && ((checkH && dir=="horz") || (checkW && dir=="vert"))) {
  1906. setPaneMinMaxSizes(pane); // update pane-state
  1907. // shrink pane if 'too big' to fit
  1908. if (s.size > s.maxSize)
  1909. sizePane(pane, s.maxSize);
  1910. }
  1911. });
  1912. sizeMidPanes("all");
  1913. sizeHandles("all"); // reposition the toggler elements
  1914. };
  1915. /**
  1916. * keyDown
  1917. *
  1918. * Capture keys when enableCursorHotkey - toggle pane if hotkey pressed
  1919. *
  1920. * @callers document.keydown()
  1921. */
  1922. function keyDown (evt) {
  1923. if (!evt) return true;
  1924. var code = evt.keyCode;
  1925. if (code < 33) return true; // ignore special keys: ENTER, TAB, etc
  1926. var
  1927. PANE = {
  1928. 38: "north" // Up Cursor
  1929. , 40: "south" // Down Cursor
  1930. , 37: "west" // Left Cursor
  1931. , 39: "east" // Right Cursor
  1932. }
  1933. , isCursorKey = (code >= 37 && code <= 40)
  1934. , ALT = evt.altKey // no worky!
  1935. , SHIFT = evt.shiftKey
  1936. , CTRL = evt.ctrlKey
  1937. , pane = false
  1938. , s, o, k, m, el
  1939. ;
  1940. if (!CTRL && !SHIFT)
  1941. return true; // no modifier key - abort
  1942. else if (isCursorKey && options[PANE[code]].enableCursorHotkey) // valid cursor-hotkey
  1943. pane = PANE[code];
  1944. else // check to see if this matches a custom-hotkey
  1945. $.each(c.borderPanes.split(","), function(i,p) { // loop each pane to check its hotkey
  1946. o = options[p];
  1947. k = o.customHotkey;
  1948. m = o.customHotkeyModifier; // if missing or invalid, treated as "CTRL+SHIFT"
  1949. if ((SHIFT && m=="SHIFT") || (CTRL && m=="CTRL") || (CTRL && SHIFT)) { // Modifier matches
  1950. if (k && code == (isNaN(k) || k <= 9 ? k.toUpperCase().charCodeAt(0) : k)) { // Key matches
  1951. pane = p;
  1952. return false; // BREAK
  1953. }
  1954. }
  1955. });
  1956. if (!pane) return true; // no hotkey - abort
  1957. // validate pane
  1958. o = options[pane]; // get pane options
  1959. s = state[pane]; // get pane options
  1960. if (!o.enableCursorHotkey || s.isHidden || !$Ps[pane]) return true;
  1961. // see if user is in a 'form field' because may be 'selecting text'!
  1962. el = evt.target || evt.srcElement;
  1963. if (el && SHIFT && isCursorKey && (el.tagName=="TEXTAREA" || (el.tagName=="INPUT" && (code==37 || code==39))))
  1964. return true; // allow text-selection
  1965. // SYNTAX NOTES
  1966. // use "returnValue=false" to abort keystroke but NOT abort function - can run another command afterwards
  1967. // use "return false" to abort keystroke AND abort function
  1968. toggle(pane);
  1969. evt.stopPropagation();
  1970. evt.returnValue = false; // CANCEL key
  1971. return false;
  1972. };
  1973. /*
  1974. * ###########################
  1975. * UTILITY METHODS
  1976. * called externally only
  1977. * ###########################
  1978. */
  1979. function allowOverflow (elem) {
  1980. if (this && this.tagName) elem = this; // BOUND to element
  1981. var $P;
  1982. if (typeof elem=="string")
  1983. $P = $Ps[elem];
  1984. else {
  1985. if ($(elem).attr("pane")) $P = $(elem);
  1986. else $P = $(elem).parents("div[pane]:first");
  1987. }
  1988. if (!$P.length) return; // INVALID
  1989. var
  1990. pane = $P.attr("pane")
  1991. , s = state[pane]
  1992. ;
  1993. // if pane is already raised, then reset it before doing it again!
  1994. // this would happen if allowOverflow is attached to BOTH the pane and an element
  1995. if (s.cssSaved)
  1996. resetOverflow(pane); // reset previous CSS before continuing
  1997. // if pane is raised by sliding or resizing, or it's closed, then abort
  1998. if (s.isSliding || s.isResizing || s.isClosed) {
  1999. s.cssSaved = false;
  2000. return;
  2001. }
  2002. var
  2003. newCSS = { zIndex: (c.zIndex.pane_normal + 1) }
  2004. , curCSS = {}
  2005. , of = $P.css("overflow")
  2006. , ofX = $P.css("overflowX")
  2007. , ofY = $P.css("overflowY")
  2008. ;
  2009. // determine which, if any, overflow settings need to be changed
  2010. if (of != "visible") {
  2011. curCSS.overflow = of;
  2012. newCSS.overflow = "visible";
  2013. }
  2014. if (ofX && ofX != "visible" && ofX != "auto") {
  2015. curCSS.overflowX = ofX;
  2016. newCSS.overflowX = "visible";
  2017. }
  2018. if (ofY && ofY != "visible" && ofY != "auto") {
  2019. curCSS.overflowY = ofX;
  2020. newCSS.overflowY = "visible";
  2021. }
  2022. // save the current overflow settings - even if blank!
  2023. s.cssSaved = curCSS;
  2024. // apply new CSS to raise zIndex and, if necessary, make overflow 'visible'
  2025. $P.css( newCSS );
  2026. // make sure the zIndex of all other panes is normal
  2027. $.each(c.allPanes.split(","), function(i, p) {
  2028. if (p != pane) resetOverflow(p);
  2029. });
  2030. };
  2031. function resetOverflow (elem) {
  2032. if (this && this.tagName) elem = this; // BOUND to element
  2033. var $P;
  2034. if (typeof elem=="string")
  2035. $P = $Ps[elem];
  2036. else {
  2037. if ($(elem).hasClass("ui-layout-pane")) $P = $(elem);
  2038. else $P = $(elem).parents("div[pane]:first");
  2039. }
  2040. if (!$P.length) return; // INVALID
  2041. var
  2042. pane = $P.attr("pane")
  2043. , s = state[pane]
  2044. , CSS = s.cssSaved || {}
  2045. ;
  2046. // reset the zIndex
  2047. if (!s.isSliding && !s.isResizing)
  2048. $P.css("zIndex", c.zIndex.pane_normal);
  2049. // reset Overflow - if necessary
  2050. $P.css( CSS );
  2051. // clear var
  2052. s.cssSaved = false;
  2053. };
  2054. /**
  2055. * getBtn
  2056. *
  2057. * Helper function to validate params received by addButton utilities
  2058. *
  2059. * @param String selector jQuery selector for button, eg: ".ui-layout-north .toggle-button"
  2060. * @param String pane Name of the pane the button is for: 'north', 'south', etc.
  2061. * @returns If both params valid, the element matching 'selector' in a jQuery wrapper - otherwise 'false'
  2062. */
  2063. function getBtn(selector, pane, action) {
  2064. var
  2065. $E = $(selector)
  2066. , err = "Error Adding Button \n\nInvalid "
  2067. ;
  2068. if (!$E.length){ // element not found
  2069. //alert(err+"selector: "+ selector);
  2070. }
  2071. else if (c.borderPanes.indexOf(pane) == -1){// invalid 'pane' sepecified
  2072. //alert(err+"pane: "+ pane);
  2073. }
  2074. else { // VALID
  2075. var btn = options[pane].buttonClass +"-"+ action;
  2076. $E.addClass( btn +" "+ btn +"-"+ pane );
  2077. return $E;
  2078. }
  2079. return false; // INVALID
  2080. };
  2081. /**
  2082. * addToggleBtn
  2083. *
  2084. * Add a custom Toggler button for a pane
  2085. *
  2086. * @param String selector jQuery selector for button, eg: ".ui-layout-north .toggle-button"
  2087. * @param String pane Name of the pane the button is for: 'north', 'south', etc.
  2088. */
  2089. function addToggleBtn (selector, pane) {
  2090. var $E = getBtn(selector, pane, "toggle");
  2091. if ($E)
  2092. $E
  2093. .attr("title", state[pane].isClosed ? "Open" : "Close")
  2094. .click(function (evt) {
  2095. toggle(pane);
  2096. evt.stopPropagation();
  2097. })
  2098. ;
  2099. };
  2100. /**
  2101. * addOpenBtn
  2102. *
  2103. * Add a custom Open button for a pane
  2104. *
  2105. * @param String selector jQuery selector for button, eg: ".ui-layout-north .open-button"
  2106. * @param String pane Name of the pane the button is for: 'north', 'south', etc.
  2107. */
  2108. function addOpenBtn (selector, pane) {
  2109. var $E = getBtn(selector, pane, "open");
  2110. if ($E)
  2111. $E
  2112. .attr("title", "Open")
  2113. .click(function (evt) {
  2114. open(pane);
  2115. evt.stopPropagation();
  2116. })
  2117. ;
  2118. };
  2119. /**
  2120. * addCloseBtn
  2121. *
  2122. * Add a custom Close button for a pane
  2123. *
  2124. * @param String selector jQuery selector for button, eg: ".ui-layout-north .close-button"
  2125. * @param String pane Name of the pane the button is for: 'north', 'south', etc.
  2126. */
  2127. function addCloseBtn (selector, pane) {
  2128. var $E = getBtn(selector, pane, "close");
  2129. if ($E)
  2130. $E
  2131. .attr("title", "Close")
  2132. .click(function (evt) {
  2133. close(pane);
  2134. evt.stopPropagation();
  2135. })
  2136. ;
  2137. };
  2138. /**
  2139. * addPinBtn
  2140. *
  2141. * Add a custom Pin button for a pane
  2142. *
  2143. * Four classes are added to the element, based on the paneClass for the associated pane...
  2144. * Assuming the default paneClass and the pin is 'up', these classes are added for a west-pane pin:
  2145. * - ui-layout-pane-pin
  2146. * - ui-layout-pane-west-pin
  2147. * - ui-layout-pane-pin-up
  2148. * - ui-layout-pane-west-pin-up
  2149. *
  2150. * @param String selector jQuery selector for button, eg: ".ui-layout-north .ui-layout-pin"
  2151. * @param String pane Name of the pane the pin is for: 'north', 'south', etc.
  2152. */
  2153. function addPinBtn (selector, pane) {
  2154. var $E = getBtn(selector, pane, "pin");
  2155. if ($E) {
  2156. var s = state[pane];
  2157. $E.click(function (evt) {
  2158. setPinState($(this), pane, (s.isSliding || s.isClosed));
  2159. if (s.isSliding || s.isClosed) open( pane ); // change from sliding to open
  2160. else close( pane ); // slide-closed
  2161. evt.stopPropagation();
  2162. });
  2163. // add up/down pin attributes and classes
  2164. setPinState ($E, pane, (!s.isClosed && !s.isSliding));
  2165. // add this pin to the pane data so we can 'sync it' automatically
  2166. // PANE.pins key is an array so we can store multiple pins for each pane
  2167. c[pane].pins.push( selector ); // just save the selector string
  2168. }
  2169. };
  2170. /**
  2171. * syncPinBtns
  2172. *
  2173. * INTERNAL function to sync 'pin buttons' when pane is opened or closed
  2174. * Unpinned means the pane is 'sliding' - ie, over-top of the adjacent panes
  2175. *
  2176. * @callers open(), close()
  2177. * @params pane These are the params returned to callbacks by layout()
  2178. * @params doPin True means set the pin 'down', False means 'up'
  2179. */
  2180. function syncPinBtns (pane, doPin) {
  2181. $.each(c[pane].pins, function (i, selector) {
  2182. setPinState($(selector), pane, doPin);
  2183. });
  2184. };
  2185. /**
  2186. * setPinState
  2187. *
  2188. * Change the class of the pin button to make it look 'up' or 'down'
  2189. *
  2190. * @callers addPinBtn(), syncPinBtns()
  2191. * @param Element $Pin The pin-span element in a jQuery wrapper
  2192. * @param Boolean doPin True = set the pin 'down', False = set it 'up'
  2193. * @param String pinClass The root classname for pins - will add '-up' or '-down' suffix
  2194. */
  2195. function setPinState ($Pin, pane, doPin) {
  2196. var updown = $Pin.attr("pin");
  2197. if (updown && doPin == (updown=="down")) return; // already in correct state
  2198. var
  2199. root = options[pane].buttonClass
  2200. , class1 = root +"-pin"
  2201. , class2 = class1 +"-"+ pane
  2202. , UP1 = class1 + "-up"
  2203. , UP2 = class2 + "-up"
  2204. , DN1 = class1 + "-down"
  2205. , DN2 = class2 + "-down"
  2206. ;
  2207. $Pin
  2208. .attr("pin", doPin ? "down" : "up") // logic
  2209. .attr("title", doPin ? "Un-Pin" : "Pin")
  2210. .removeClass( doPin ? UP1 : DN1 )
  2211. .removeClass( doPin ? UP2 : DN2 )
  2212. .addClass( doPin ? DN1 : UP1 )
  2213. .addClass( doPin ? DN2 : UP2 )
  2214. ;
  2215. };
  2216. /*
  2217. * ###########################
  2218. * CREATE/RETURN BORDER-LAYOUT
  2219. * ###########################
  2220. */
  2221. // init global vars
  2222. var
  2223. $Container = $(this).css({ overflow: "hidden" }) // Container elem
  2224. , $Ps = {} // Panes x4 - set in initPanes()
  2225. , $Cs = {} // Content x4 - set in initPanes()
  2226. , $Rs = {} // Resizers x4 - set in initHandles()
  2227. , $Ts = {} // Togglers x4 - set in initHandles()
  2228. // object aliases
  2229. , c = config // alias for config hash
  2230. , cDims = state.container // alias for easy access to 'container dimensions'
  2231. ;
  2232. // create the border layout NOW
  2233. create();
  2234. // return object pointers to expose data & option Properties, and primary action Methods
  2235. return {
  2236. options: options // property - options hash
  2237. , state: state // property - dimensions hash
  2238. , panes: $Ps // property - object pointers for ALL panes: panes.north, panes.center
  2239. , toggle: toggle // method - pass a 'pane' ("north", "west", etc)
  2240. , open: open // method - ditto
  2241. , close: close // method - ditto
  2242. , hide: hide // method - ditto
  2243. , show: show // method - ditto
  2244. , resizeContent: sizeContent // method - ditto
  2245. , sizePane: sizePane // method - pass a 'pane' AND a 'size' in pixels
  2246. , resizeAll: resizeAll // method - no parameters
  2247. , addToggleBtn: addToggleBtn // utility - pass element selector and 'pane'
  2248. , addOpenBtn: addOpenBtn // utility - ditto
  2249. , addCloseBtn: addCloseBtn // utility - ditto
  2250. , addPinBtn: addPinBtn // utility - ditto
  2251. , allowOverflow: allowOverflow // utility - pass calling element
  2252. , resetOverflow: resetOverflow // utility - ditto
  2253. , cssWidth: cssW
  2254. , cssHeight: cssH
  2255. };
  2256. }
  2257. })( jQuery );