jquery.layout_and_plugins.js 199 KB

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