jquery.layout.js 203 KB

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