jquery.layout.js 172 KB

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