jquery.fancytree-all-deps.js 355 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045
  1. /*! jQuery Fancytree Plugin - 2.26.0 - 2017-11-04T17:52:53Z
  2. * https://github.com/mar10/fancytree
  3. * Copyright (c) 2017 Martin Wendt; Licensed MIT
  4. */
  5. /*! jQuery UI - v1.12.1 - 2017-02-23
  6. * http://jqueryui.com
  7. * Includes: widget.js, position.js, keycode.js, scroll-parent.js, unique-id.js, effect.js, effects/effect-blind.js
  8. * Copyright jQuery Foundation and other contributors; Licensed MIT */
  9. /*
  10. NOTE: Original jQuery UI wrapper was replaced with a simple IIFE.
  11. See README-Fancytree.md
  12. */
  13. (function( $ ) {
  14. $.ui = $.ui || {};
  15. var version = $.ui.version = "1.12.1";
  16. /*!
  17. * jQuery UI Widget 1.12.1
  18. * http://jqueryui.com
  19. *
  20. * Copyright jQuery Foundation and other contributors
  21. * Released under the MIT license.
  22. * http://jquery.org/license
  23. */
  24. //>>label: Widget
  25. //>>group: Core
  26. //>>description: Provides a factory for creating stateful widgets with a common API.
  27. //>>docs: http://api.jqueryui.com/jQuery.widget/
  28. //>>demos: http://jqueryui.com/widget/
  29. var widgetUuid = 0;
  30. var widgetSlice = Array.prototype.slice;
  31. $.cleanData = ( function( orig ) {
  32. return function( elems ) {
  33. var events, elem, i;
  34. for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {
  35. try {
  36. // Only trigger remove when necessary to save time
  37. events = $._data( elem, "events" );
  38. if ( events && events.remove ) {
  39. $( elem ).triggerHandler( "remove" );
  40. }
  41. // Http://bugs.jquery.com/ticket/8235
  42. } catch ( e ) {}
  43. }
  44. orig( elems );
  45. };
  46. } )( $.cleanData );
  47. $.widget = function( name, base, prototype ) {
  48. var existingConstructor, constructor, basePrototype;
  49. // ProxiedPrototype allows the provided prototype to remain unmodified
  50. // so that it can be used as a mixin for multiple widgets (#8876)
  51. var proxiedPrototype = {};
  52. var namespace = name.split( "." )[ 0 ];
  53. name = name.split( "." )[ 1 ];
  54. var fullName = namespace + "-" + name;
  55. if ( !prototype ) {
  56. prototype = base;
  57. base = $.Widget;
  58. }
  59. if ( $.isArray( prototype ) ) {
  60. prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
  61. }
  62. // Create selector for plugin
  63. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  64. return !!$.data( elem, fullName );
  65. };
  66. $[ namespace ] = $[ namespace ] || {};
  67. existingConstructor = $[ namespace ][ name ];
  68. constructor = $[ namespace ][ name ] = function( options, element ) {
  69. // Allow instantiation without "new" keyword
  70. if ( !this._createWidget ) {
  71. return new constructor( options, element );
  72. }
  73. // Allow instantiation without initializing for simple inheritance
  74. // must use "new" keyword (the code above always passes args)
  75. if ( arguments.length ) {
  76. this._createWidget( options, element );
  77. }
  78. };
  79. // Extend with the existing constructor to carry over any static properties
  80. $.extend( constructor, existingConstructor, {
  81. version: prototype.version,
  82. // Copy the object used to create the prototype in case we need to
  83. // redefine the widget later
  84. _proto: $.extend( {}, prototype ),
  85. // Track widgets that inherit from this widget in case this widget is
  86. // redefined after a widget inherits from it
  87. _childConstructors: []
  88. } );
  89. basePrototype = new base();
  90. // We need to make the options hash a property directly on the new instance
  91. // otherwise we'll modify the options hash on the prototype that we're
  92. // inheriting from
  93. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  94. $.each( prototype, function( prop, value ) {
  95. if ( !$.isFunction( value ) ) {
  96. proxiedPrototype[ prop ] = value;
  97. return;
  98. }
  99. proxiedPrototype[ prop ] = ( function() {
  100. function _super() {
  101. return base.prototype[ prop ].apply( this, arguments );
  102. }
  103. function _superApply( args ) {
  104. return base.prototype[ prop ].apply( this, args );
  105. }
  106. return function() {
  107. var __super = this._super;
  108. var __superApply = this._superApply;
  109. var returnValue;
  110. this._super = _super;
  111. this._superApply = _superApply;
  112. returnValue = value.apply( this, arguments );
  113. this._super = __super;
  114. this._superApply = __superApply;
  115. return returnValue;
  116. };
  117. } )();
  118. } );
  119. constructor.prototype = $.widget.extend( basePrototype, {
  120. // TODO: remove support for widgetEventPrefix
  121. // always use the name + a colon as the prefix, e.g., draggable:start
  122. // don't prefix for widgets that aren't DOM-based
  123. widgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name
  124. }, proxiedPrototype, {
  125. constructor: constructor,
  126. namespace: namespace,
  127. widgetName: name,
  128. widgetFullName: fullName
  129. } );
  130. // If this widget is being redefined then we need to find all widgets that
  131. // are inheriting from it and redefine all of them so that they inherit from
  132. // the new version of this widget. We're essentially trying to replace one
  133. // level in the prototype chain.
  134. if ( existingConstructor ) {
  135. $.each( existingConstructor._childConstructors, function( i, child ) {
  136. var childPrototype = child.prototype;
  137. // Redefine the child widget using the same prototype that was
  138. // originally used, but inherit from the new version of the base
  139. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor,
  140. child._proto );
  141. } );
  142. // Remove the list of existing child constructors from the old constructor
  143. // so the old child constructors can be garbage collected
  144. delete existingConstructor._childConstructors;
  145. } else {
  146. base._childConstructors.push( constructor );
  147. }
  148. $.widget.bridge( name, constructor );
  149. return constructor;
  150. };
  151. $.widget.extend = function( target ) {
  152. var input = widgetSlice.call( arguments, 1 );
  153. var inputIndex = 0;
  154. var inputLength = input.length;
  155. var key;
  156. var value;
  157. for ( ; inputIndex < inputLength; inputIndex++ ) {
  158. for ( key in input[ inputIndex ] ) {
  159. value = input[ inputIndex ][ key ];
  160. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  161. // Clone objects
  162. if ( $.isPlainObject( value ) ) {
  163. target[ key ] = $.isPlainObject( target[ key ] ) ?
  164. $.widget.extend( {}, target[ key ], value ) :
  165. // Don't extend strings, arrays, etc. with objects
  166. $.widget.extend( {}, value );
  167. // Copy everything else by reference
  168. } else {
  169. target[ key ] = value;
  170. }
  171. }
  172. }
  173. }
  174. return target;
  175. };
  176. $.widget.bridge = function( name, object ) {
  177. var fullName = object.prototype.widgetFullName || name;
  178. $.fn[ name ] = function( options ) {
  179. var isMethodCall = typeof options === "string";
  180. var args = widgetSlice.call( arguments, 1 );
  181. var returnValue = this;
  182. if ( isMethodCall ) {
  183. // If this is an empty collection, we need to have the instance method
  184. // return undefined instead of the jQuery instance
  185. if ( !this.length && options === "instance" ) {
  186. returnValue = undefined;
  187. } else {
  188. this.each( function() {
  189. var methodValue;
  190. var instance = $.data( this, fullName );
  191. if ( options === "instance" ) {
  192. returnValue = instance;
  193. return false;
  194. }
  195. if ( !instance ) {
  196. return $.error( "cannot call methods on " + name +
  197. " prior to initialization; " +
  198. "attempted to call method '" + options + "'" );
  199. }
  200. if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
  201. return $.error( "no such method '" + options + "' for " + name +
  202. " widget instance" );
  203. }
  204. methodValue = instance[ options ].apply( instance, args );
  205. if ( methodValue !== instance && methodValue !== undefined ) {
  206. returnValue = methodValue && methodValue.jquery ?
  207. returnValue.pushStack( methodValue.get() ) :
  208. methodValue;
  209. return false;
  210. }
  211. } );
  212. }
  213. } else {
  214. // Allow multiple hashes to be passed on init
  215. if ( args.length ) {
  216. options = $.widget.extend.apply( null, [ options ].concat( args ) );
  217. }
  218. this.each( function() {
  219. var instance = $.data( this, fullName );
  220. if ( instance ) {
  221. instance.option( options || {} );
  222. if ( instance._init ) {
  223. instance._init();
  224. }
  225. } else {
  226. $.data( this, fullName, new object( options, this ) );
  227. }
  228. } );
  229. }
  230. return returnValue;
  231. };
  232. };
  233. $.Widget = function( /* options, element */ ) {};
  234. $.Widget._childConstructors = [];
  235. $.Widget.prototype = {
  236. widgetName: "widget",
  237. widgetEventPrefix: "",
  238. defaultElement: "<div>",
  239. options: {
  240. classes: {},
  241. disabled: false,
  242. // Callbacks
  243. create: null
  244. },
  245. _createWidget: function( options, element ) {
  246. element = $( element || this.defaultElement || this )[ 0 ];
  247. this.element = $( element );
  248. this.uuid = widgetUuid++;
  249. this.eventNamespace = "." + this.widgetName + this.uuid;
  250. this.bindings = $();
  251. this.hoverable = $();
  252. this.focusable = $();
  253. this.classesElementLookup = {};
  254. if ( element !== this ) {
  255. $.data( element, this.widgetFullName, this );
  256. this._on( true, this.element, {
  257. remove: function( event ) {
  258. if ( event.target === element ) {
  259. this.destroy();
  260. }
  261. }
  262. } );
  263. this.document = $( element.style ?
  264. // Element within the document
  265. element.ownerDocument :
  266. // Element is window or document
  267. element.document || element );
  268. this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );
  269. }
  270. this.options = $.widget.extend( {},
  271. this.options,
  272. this._getCreateOptions(),
  273. options );
  274. this._create();
  275. if ( this.options.disabled ) {
  276. this._setOptionDisabled( this.options.disabled );
  277. }
  278. this._trigger( "create", null, this._getCreateEventData() );
  279. this._init();
  280. },
  281. _getCreateOptions: function() {
  282. return {};
  283. },
  284. _getCreateEventData: $.noop,
  285. _create: $.noop,
  286. _init: $.noop,
  287. destroy: function() {
  288. var that = this;
  289. this._destroy();
  290. $.each( this.classesElementLookup, function( key, value ) {
  291. that._removeClass( value, key );
  292. } );
  293. // We can probably remove the unbind calls in 2.0
  294. // all event bindings should go through this._on()
  295. this.element
  296. .off( this.eventNamespace )
  297. .removeData( this.widgetFullName );
  298. this.widget()
  299. .off( this.eventNamespace )
  300. .removeAttr( "aria-disabled" );
  301. // Clean up events and states
  302. this.bindings.off( this.eventNamespace );
  303. },
  304. _destroy: $.noop,
  305. widget: function() {
  306. return this.element;
  307. },
  308. option: function( key, value ) {
  309. var options = key;
  310. var parts;
  311. var curOption;
  312. var i;
  313. if ( arguments.length === 0 ) {
  314. // Don't return a reference to the internal hash
  315. return $.widget.extend( {}, this.options );
  316. }
  317. if ( typeof key === "string" ) {
  318. // Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  319. options = {};
  320. parts = key.split( "." );
  321. key = parts.shift();
  322. if ( parts.length ) {
  323. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  324. for ( i = 0; i < parts.length - 1; i++ ) {
  325. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  326. curOption = curOption[ parts[ i ] ];
  327. }
  328. key = parts.pop();
  329. if ( arguments.length === 1 ) {
  330. return curOption[ key ] === undefined ? null : curOption[ key ];
  331. }
  332. curOption[ key ] = value;
  333. } else {
  334. if ( arguments.length === 1 ) {
  335. return this.options[ key ] === undefined ? null : this.options[ key ];
  336. }
  337. options[ key ] = value;
  338. }
  339. }
  340. this._setOptions( options );
  341. return this;
  342. },
  343. _setOptions: function( options ) {
  344. var key;
  345. for ( key in options ) {
  346. this._setOption( key, options[ key ] );
  347. }
  348. return this;
  349. },
  350. _setOption: function( key, value ) {
  351. if ( key === "classes" ) {
  352. this._setOptionClasses( value );
  353. }
  354. this.options[ key ] = value;
  355. if ( key === "disabled" ) {
  356. this._setOptionDisabled( value );
  357. }
  358. return this;
  359. },
  360. _setOptionClasses: function( value ) {
  361. var classKey, elements, currentElements;
  362. for ( classKey in value ) {
  363. currentElements = this.classesElementLookup[ classKey ];
  364. if ( value[ classKey ] === this.options.classes[ classKey ] ||
  365. !currentElements ||
  366. !currentElements.length ) {
  367. continue;
  368. }
  369. // We are doing this to create a new jQuery object because the _removeClass() call
  370. // on the next line is going to destroy the reference to the current elements being
  371. // tracked. We need to save a copy of this collection so that we can add the new classes
  372. // below.
  373. elements = $( currentElements.get() );
  374. this._removeClass( currentElements, classKey );
  375. // We don't use _addClass() here, because that uses this.options.classes
  376. // for generating the string of classes. We want to use the value passed in from
  377. // _setOption(), this is the new value of the classes option which was passed to
  378. // _setOption(). We pass this value directly to _classes().
  379. elements.addClass( this._classes( {
  380. element: elements,
  381. keys: classKey,
  382. classes: value,
  383. add: true
  384. } ) );
  385. }
  386. },
  387. _setOptionDisabled: function( value ) {
  388. this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
  389. // If the widget is becoming disabled, then nothing is interactive
  390. if ( value ) {
  391. this._removeClass( this.hoverable, null, "ui-state-hover" );
  392. this._removeClass( this.focusable, null, "ui-state-focus" );
  393. }
  394. },
  395. enable: function() {
  396. return this._setOptions( { disabled: false } );
  397. },
  398. disable: function() {
  399. return this._setOptions( { disabled: true } );
  400. },
  401. _classes: function( options ) {
  402. var full = [];
  403. var that = this;
  404. options = $.extend( {
  405. element: this.element,
  406. classes: this.options.classes || {}
  407. }, options );
  408. function processClassString( classes, checkOption ) {
  409. var current, i;
  410. for ( i = 0; i < classes.length; i++ ) {
  411. current = that.classesElementLookup[ classes[ i ] ] || $();
  412. if ( options.add ) {
  413. current = $( $.unique( current.get().concat( options.element.get() ) ) );
  414. } else {
  415. current = $( current.not( options.element ).get() );
  416. }
  417. that.classesElementLookup[ classes[ i ] ] = current;
  418. full.push( classes[ i ] );
  419. if ( checkOption && options.classes[ classes[ i ] ] ) {
  420. full.push( options.classes[ classes[ i ] ] );
  421. }
  422. }
  423. }
  424. this._on( options.element, {
  425. "remove": "_untrackClassesElement"
  426. } );
  427. if ( options.keys ) {
  428. processClassString( options.keys.match( /\S+/g ) || [], true );
  429. }
  430. if ( options.extra ) {
  431. processClassString( options.extra.match( /\S+/g ) || [] );
  432. }
  433. return full.join( " " );
  434. },
  435. _untrackClassesElement: function( event ) {
  436. var that = this;
  437. $.each( that.classesElementLookup, function( key, value ) {
  438. if ( $.inArray( event.target, value ) !== -1 ) {
  439. that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
  440. }
  441. } );
  442. },
  443. _removeClass: function( element, keys, extra ) {
  444. return this._toggleClass( element, keys, extra, false );
  445. },
  446. _addClass: function( element, keys, extra ) {
  447. return this._toggleClass( element, keys, extra, true );
  448. },
  449. _toggleClass: function( element, keys, extra, add ) {
  450. add = ( typeof add === "boolean" ) ? add : extra;
  451. var shift = ( typeof element === "string" || element === null ),
  452. options = {
  453. extra: shift ? keys : extra,
  454. keys: shift ? element : keys,
  455. element: shift ? this.element : element,
  456. add: add
  457. };
  458. options.element.toggleClass( this._classes( options ), add );
  459. return this;
  460. },
  461. _on: function( suppressDisabledCheck, element, handlers ) {
  462. var delegateElement;
  463. var instance = this;
  464. // No suppressDisabledCheck flag, shuffle arguments
  465. if ( typeof suppressDisabledCheck !== "boolean" ) {
  466. handlers = element;
  467. element = suppressDisabledCheck;
  468. suppressDisabledCheck = false;
  469. }
  470. // No element argument, shuffle and use this.element
  471. if ( !handlers ) {
  472. handlers = element;
  473. element = this.element;
  474. delegateElement = this.widget();
  475. } else {
  476. element = delegateElement = $( element );
  477. this.bindings = this.bindings.add( element );
  478. }
  479. $.each( handlers, function( event, handler ) {
  480. function handlerProxy() {
  481. // Allow widgets to customize the disabled handling
  482. // - disabled as an array instead of boolean
  483. // - disabled class as method for disabling individual parts
  484. if ( !suppressDisabledCheck &&
  485. ( instance.options.disabled === true ||
  486. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  487. return;
  488. }
  489. return ( typeof handler === "string" ? instance[ handler ] : handler )
  490. .apply( instance, arguments );
  491. }
  492. // Copy the guid so direct unbinding works
  493. if ( typeof handler !== "string" ) {
  494. handlerProxy.guid = handler.guid =
  495. handler.guid || handlerProxy.guid || $.guid++;
  496. }
  497. var match = event.match( /^([\w:-]*)\s*(.*)$/ );
  498. var eventName = match[ 1 ] + instance.eventNamespace;
  499. var selector = match[ 2 ];
  500. if ( selector ) {
  501. delegateElement.on( eventName, selector, handlerProxy );
  502. } else {
  503. element.on( eventName, handlerProxy );
  504. }
  505. } );
  506. },
  507. _off: function( element, eventName ) {
  508. eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
  509. this.eventNamespace;
  510. element.off( eventName ).off( eventName );
  511. // Clear the stack to avoid memory leaks (#10056)
  512. this.bindings = $( this.bindings.not( element ).get() );
  513. this.focusable = $( this.focusable.not( element ).get() );
  514. this.hoverable = $( this.hoverable.not( element ).get() );
  515. },
  516. _delay: function( handler, delay ) {
  517. function handlerProxy() {
  518. return ( typeof handler === "string" ? instance[ handler ] : handler )
  519. .apply( instance, arguments );
  520. }
  521. var instance = this;
  522. return setTimeout( handlerProxy, delay || 0 );
  523. },
  524. _hoverable: function( element ) {
  525. this.hoverable = this.hoverable.add( element );
  526. this._on( element, {
  527. mouseenter: function( event ) {
  528. this._addClass( $( event.currentTarget ), null, "ui-state-hover" );
  529. },
  530. mouseleave: function( event ) {
  531. this._removeClass( $( event.currentTarget ), null, "ui-state-hover" );
  532. }
  533. } );
  534. },
  535. _focusable: function( element ) {
  536. this.focusable = this.focusable.add( element );
  537. this._on( element, {
  538. focusin: function( event ) {
  539. this._addClass( $( event.currentTarget ), null, "ui-state-focus" );
  540. },
  541. focusout: function( event ) {
  542. this._removeClass( $( event.currentTarget ), null, "ui-state-focus" );
  543. }
  544. } );
  545. },
  546. _trigger: function( type, event, data ) {
  547. var prop, orig;
  548. var callback = this.options[ type ];
  549. data = data || {};
  550. event = $.Event( event );
  551. event.type = ( type === this.widgetEventPrefix ?
  552. type :
  553. this.widgetEventPrefix + type ).toLowerCase();
  554. // The original event may come from any element
  555. // so we need to reset the target on the new event
  556. event.target = this.element[ 0 ];
  557. // Copy original event properties over to the new event
  558. orig = event.originalEvent;
  559. if ( orig ) {
  560. for ( prop in orig ) {
  561. if ( !( prop in event ) ) {
  562. event[ prop ] = orig[ prop ];
  563. }
  564. }
  565. }
  566. this.element.trigger( event, data );
  567. return !( $.isFunction( callback ) &&
  568. callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
  569. event.isDefaultPrevented() );
  570. }
  571. };
  572. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  573. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  574. if ( typeof options === "string" ) {
  575. options = { effect: options };
  576. }
  577. var hasOptions;
  578. var effectName = !options ?
  579. method :
  580. options === true || typeof options === "number" ?
  581. defaultEffect :
  582. options.effect || defaultEffect;
  583. options = options || {};
  584. if ( typeof options === "number" ) {
  585. options = { duration: options };
  586. }
  587. hasOptions = !$.isEmptyObject( options );
  588. options.complete = callback;
  589. if ( options.delay ) {
  590. element.delay( options.delay );
  591. }
  592. if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
  593. element[ method ]( options );
  594. } else if ( effectName !== method && element[ effectName ] ) {
  595. element[ effectName ]( options.duration, options.easing, callback );
  596. } else {
  597. element.queue( function( next ) {
  598. $( this )[ method ]();
  599. if ( callback ) {
  600. callback.call( element[ 0 ] );
  601. }
  602. next();
  603. } );
  604. }
  605. };
  606. } );
  607. var widget = $.widget;
  608. /*!
  609. * jQuery UI Position 1.12.1
  610. * http://jqueryui.com
  611. *
  612. * Copyright jQuery Foundation and other contributors
  613. * Released under the MIT license.
  614. * http://jquery.org/license
  615. *
  616. * http://api.jqueryui.com/position/
  617. */
  618. //>>label: Position
  619. //>>group: Core
  620. //>>description: Positions elements relative to other elements.
  621. //>>docs: http://api.jqueryui.com/position/
  622. //>>demos: http://jqueryui.com/position/
  623. ( function() {
  624. var cachedScrollbarWidth,
  625. max = Math.max,
  626. abs = Math.abs,
  627. rhorizontal = /left|center|right/,
  628. rvertical = /top|center|bottom/,
  629. roffset = /[\+\-]\d+(\.[\d]+)?%?/,
  630. rposition = /^\w+/,
  631. rpercent = /%$/,
  632. _position = $.fn.position;
  633. function getOffsets( offsets, width, height ) {
  634. return [
  635. parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  636. parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  637. ];
  638. }
  639. function parseCss( element, property ) {
  640. return parseInt( $.css( element, property ), 10 ) || 0;
  641. }
  642. function getDimensions( elem ) {
  643. var raw = elem[ 0 ];
  644. if ( raw.nodeType === 9 ) {
  645. return {
  646. width: elem.width(),
  647. height: elem.height(),
  648. offset: { top: 0, left: 0 }
  649. };
  650. }
  651. if ( $.isWindow( raw ) ) {
  652. return {
  653. width: elem.width(),
  654. height: elem.height(),
  655. offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
  656. };
  657. }
  658. if ( raw.preventDefault ) {
  659. return {
  660. width: 0,
  661. height: 0,
  662. offset: { top: raw.pageY, left: raw.pageX }
  663. };
  664. }
  665. return {
  666. width: elem.outerWidth(),
  667. height: elem.outerHeight(),
  668. offset: elem.offset()
  669. };
  670. }
  671. $.position = {
  672. scrollbarWidth: function() {
  673. if ( cachedScrollbarWidth !== undefined ) {
  674. return cachedScrollbarWidth;
  675. }
  676. var w1, w2,
  677. div = $( "<div " +
  678. "style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'>" +
  679. "<div style='height:100px;width:auto;'></div></div>" ),
  680. innerDiv = div.children()[ 0 ];
  681. $( "body" ).append( div );
  682. w1 = innerDiv.offsetWidth;
  683. div.css( "overflow", "scroll" );
  684. w2 = innerDiv.offsetWidth;
  685. if ( w1 === w2 ) {
  686. w2 = div[ 0 ].clientWidth;
  687. }
  688. div.remove();
  689. return ( cachedScrollbarWidth = w1 - w2 );
  690. },
  691. getScrollInfo: function( within ) {
  692. var overflowX = within.isWindow || within.isDocument ? "" :
  693. within.element.css( "overflow-x" ),
  694. overflowY = within.isWindow || within.isDocument ? "" :
  695. within.element.css( "overflow-y" ),
  696. hasOverflowX = overflowX === "scroll" ||
  697. ( overflowX === "auto" && within.width < within.element[ 0 ].scrollWidth ),
  698. hasOverflowY = overflowY === "scroll" ||
  699. ( overflowY === "auto" && within.height < within.element[ 0 ].scrollHeight );
  700. return {
  701. width: hasOverflowY ? $.position.scrollbarWidth() : 0,
  702. height: hasOverflowX ? $.position.scrollbarWidth() : 0
  703. };
  704. },
  705. getWithinInfo: function( element ) {
  706. var withinElement = $( element || window ),
  707. isWindow = $.isWindow( withinElement[ 0 ] ),
  708. isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
  709. hasOffset = !isWindow && !isDocument;
  710. return {
  711. element: withinElement,
  712. isWindow: isWindow,
  713. isDocument: isDocument,
  714. offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
  715. scrollLeft: withinElement.scrollLeft(),
  716. scrollTop: withinElement.scrollTop(),
  717. width: withinElement.outerWidth(),
  718. height: withinElement.outerHeight()
  719. };
  720. }
  721. };
  722. $.fn.position = function( options ) {
  723. if ( !options || !options.of ) {
  724. return _position.apply( this, arguments );
  725. }
  726. // Make a copy, we don't want to modify arguments
  727. options = $.extend( {}, options );
  728. var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
  729. target = $( options.of ),
  730. within = $.position.getWithinInfo( options.within ),
  731. scrollInfo = $.position.getScrollInfo( within ),
  732. collision = ( options.collision || "flip" ).split( " " ),
  733. offsets = {};
  734. dimensions = getDimensions( target );
  735. if ( target[ 0 ].preventDefault ) {
  736. // Force left top to allow flipping
  737. options.at = "left top";
  738. }
  739. targetWidth = dimensions.width;
  740. targetHeight = dimensions.height;
  741. targetOffset = dimensions.offset;
  742. // Clone to reuse original targetOffset later
  743. basePosition = $.extend( {}, targetOffset );
  744. // Force my and at to have valid horizontal and vertical positions
  745. // if a value is missing or invalid, it will be converted to center
  746. $.each( [ "my", "at" ], function() {
  747. var pos = ( options[ this ] || "" ).split( " " ),
  748. horizontalOffset,
  749. verticalOffset;
  750. if ( pos.length === 1 ) {
  751. pos = rhorizontal.test( pos[ 0 ] ) ?
  752. pos.concat( [ "center" ] ) :
  753. rvertical.test( pos[ 0 ] ) ?
  754. [ "center" ].concat( pos ) :
  755. [ "center", "center" ];
  756. }
  757. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  758. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  759. // Calculate offsets
  760. horizontalOffset = roffset.exec( pos[ 0 ] );
  761. verticalOffset = roffset.exec( pos[ 1 ] );
  762. offsets[ this ] = [
  763. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  764. verticalOffset ? verticalOffset[ 0 ] : 0
  765. ];
  766. // Reduce to just the positions without the offsets
  767. options[ this ] = [
  768. rposition.exec( pos[ 0 ] )[ 0 ],
  769. rposition.exec( pos[ 1 ] )[ 0 ]
  770. ];
  771. } );
  772. // Normalize collision option
  773. if ( collision.length === 1 ) {
  774. collision[ 1 ] = collision[ 0 ];
  775. }
  776. if ( options.at[ 0 ] === "right" ) {
  777. basePosition.left += targetWidth;
  778. } else if ( options.at[ 0 ] === "center" ) {
  779. basePosition.left += targetWidth / 2;
  780. }
  781. if ( options.at[ 1 ] === "bottom" ) {
  782. basePosition.top += targetHeight;
  783. } else if ( options.at[ 1 ] === "center" ) {
  784. basePosition.top += targetHeight / 2;
  785. }
  786. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  787. basePosition.left += atOffset[ 0 ];
  788. basePosition.top += atOffset[ 1 ];
  789. return this.each( function() {
  790. var collisionPosition, using,
  791. elem = $( this ),
  792. elemWidth = elem.outerWidth(),
  793. elemHeight = elem.outerHeight(),
  794. marginLeft = parseCss( this, "marginLeft" ),
  795. marginTop = parseCss( this, "marginTop" ),
  796. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) +
  797. scrollInfo.width,
  798. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) +
  799. scrollInfo.height,
  800. position = $.extend( {}, basePosition ),
  801. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  802. if ( options.my[ 0 ] === "right" ) {
  803. position.left -= elemWidth;
  804. } else if ( options.my[ 0 ] === "center" ) {
  805. position.left -= elemWidth / 2;
  806. }
  807. if ( options.my[ 1 ] === "bottom" ) {
  808. position.top -= elemHeight;
  809. } else if ( options.my[ 1 ] === "center" ) {
  810. position.top -= elemHeight / 2;
  811. }
  812. position.left += myOffset[ 0 ];
  813. position.top += myOffset[ 1 ];
  814. collisionPosition = {
  815. marginLeft: marginLeft,
  816. marginTop: marginTop
  817. };
  818. $.each( [ "left", "top" ], function( i, dir ) {
  819. if ( $.ui.position[ collision[ i ] ] ) {
  820. $.ui.position[ collision[ i ] ][ dir ]( position, {
  821. targetWidth: targetWidth,
  822. targetHeight: targetHeight,
  823. elemWidth: elemWidth,
  824. elemHeight: elemHeight,
  825. collisionPosition: collisionPosition,
  826. collisionWidth: collisionWidth,
  827. collisionHeight: collisionHeight,
  828. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  829. my: options.my,
  830. at: options.at,
  831. within: within,
  832. elem: elem
  833. } );
  834. }
  835. } );
  836. if ( options.using ) {
  837. // Adds feedback as second argument to using callback, if present
  838. using = function( props ) {
  839. var left = targetOffset.left - position.left,
  840. right = left + targetWidth - elemWidth,
  841. top = targetOffset.top - position.top,
  842. bottom = top + targetHeight - elemHeight,
  843. feedback = {
  844. target: {
  845. element: target,
  846. left: targetOffset.left,
  847. top: targetOffset.top,
  848. width: targetWidth,
  849. height: targetHeight
  850. },
  851. element: {
  852. element: elem,
  853. left: position.left,
  854. top: position.top,
  855. width: elemWidth,
  856. height: elemHeight
  857. },
  858. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  859. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  860. };
  861. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  862. feedback.horizontal = "center";
  863. }
  864. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  865. feedback.vertical = "middle";
  866. }
  867. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  868. feedback.important = "horizontal";
  869. } else {
  870. feedback.important = "vertical";
  871. }
  872. options.using.call( this, props, feedback );
  873. };
  874. }
  875. elem.offset( $.extend( position, { using: using } ) );
  876. } );
  877. };
  878. $.ui.position = {
  879. fit: {
  880. left: function( position, data ) {
  881. var within = data.within,
  882. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  883. outerWidth = within.width,
  884. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  885. overLeft = withinOffset - collisionPosLeft,
  886. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  887. newOverRight;
  888. // Element is wider than within
  889. if ( data.collisionWidth > outerWidth ) {
  890. // Element is initially over the left side of within
  891. if ( overLeft > 0 && overRight <= 0 ) {
  892. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth -
  893. withinOffset;
  894. position.left += overLeft - newOverRight;
  895. // Element is initially over right side of within
  896. } else if ( overRight > 0 && overLeft <= 0 ) {
  897. position.left = withinOffset;
  898. // Element is initially over both left and right sides of within
  899. } else {
  900. if ( overLeft > overRight ) {
  901. position.left = withinOffset + outerWidth - data.collisionWidth;
  902. } else {
  903. position.left = withinOffset;
  904. }
  905. }
  906. // Too far left -> align with left edge
  907. } else if ( overLeft > 0 ) {
  908. position.left += overLeft;
  909. // Too far right -> align with right edge
  910. } else if ( overRight > 0 ) {
  911. position.left -= overRight;
  912. // Adjust based on position and margin
  913. } else {
  914. position.left = max( position.left - collisionPosLeft, position.left );
  915. }
  916. },
  917. top: function( position, data ) {
  918. var within = data.within,
  919. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  920. outerHeight = data.within.height,
  921. collisionPosTop = position.top - data.collisionPosition.marginTop,
  922. overTop = withinOffset - collisionPosTop,
  923. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  924. newOverBottom;
  925. // Element is taller than within
  926. if ( data.collisionHeight > outerHeight ) {
  927. // Element is initially over the top of within
  928. if ( overTop > 0 && overBottom <= 0 ) {
  929. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight -
  930. withinOffset;
  931. position.top += overTop - newOverBottom;
  932. // Element is initially over bottom of within
  933. } else if ( overBottom > 0 && overTop <= 0 ) {
  934. position.top = withinOffset;
  935. // Element is initially over both top and bottom of within
  936. } else {
  937. if ( overTop > overBottom ) {
  938. position.top = withinOffset + outerHeight - data.collisionHeight;
  939. } else {
  940. position.top = withinOffset;
  941. }
  942. }
  943. // Too far up -> align with top
  944. } else if ( overTop > 0 ) {
  945. position.top += overTop;
  946. // Too far down -> align with bottom edge
  947. } else if ( overBottom > 0 ) {
  948. position.top -= overBottom;
  949. // Adjust based on position and margin
  950. } else {
  951. position.top = max( position.top - collisionPosTop, position.top );
  952. }
  953. }
  954. },
  955. flip: {
  956. left: function( position, data ) {
  957. var within = data.within,
  958. withinOffset = within.offset.left + within.scrollLeft,
  959. outerWidth = within.width,
  960. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  961. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  962. overLeft = collisionPosLeft - offsetLeft,
  963. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  964. myOffset = data.my[ 0 ] === "left" ?
  965. -data.elemWidth :
  966. data.my[ 0 ] === "right" ?
  967. data.elemWidth :
  968. 0,
  969. atOffset = data.at[ 0 ] === "left" ?
  970. data.targetWidth :
  971. data.at[ 0 ] === "right" ?
  972. -data.targetWidth :
  973. 0,
  974. offset = -2 * data.offset[ 0 ],
  975. newOverRight,
  976. newOverLeft;
  977. if ( overLeft < 0 ) {
  978. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth -
  979. outerWidth - withinOffset;
  980. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  981. position.left += myOffset + atOffset + offset;
  982. }
  983. } else if ( overRight > 0 ) {
  984. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset +
  985. atOffset + offset - offsetLeft;
  986. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  987. position.left += myOffset + atOffset + offset;
  988. }
  989. }
  990. },
  991. top: function( position, data ) {
  992. var within = data.within,
  993. withinOffset = within.offset.top + within.scrollTop,
  994. outerHeight = within.height,
  995. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  996. collisionPosTop = position.top - data.collisionPosition.marginTop,
  997. overTop = collisionPosTop - offsetTop,
  998. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  999. top = data.my[ 1 ] === "top",
  1000. myOffset = top ?
  1001. -data.elemHeight :
  1002. data.my[ 1 ] === "bottom" ?
  1003. data.elemHeight :
  1004. 0,
  1005. atOffset = data.at[ 1 ] === "top" ?
  1006. data.targetHeight :
  1007. data.at[ 1 ] === "bottom" ?
  1008. -data.targetHeight :
  1009. 0,
  1010. offset = -2 * data.offset[ 1 ],
  1011. newOverTop,
  1012. newOverBottom;
  1013. if ( overTop < 0 ) {
  1014. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight -
  1015. outerHeight - withinOffset;
  1016. if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) {
  1017. position.top += myOffset + atOffset + offset;
  1018. }
  1019. } else if ( overBottom > 0 ) {
  1020. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset +
  1021. offset - offsetTop;
  1022. if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) {
  1023. position.top += myOffset + atOffset + offset;
  1024. }
  1025. }
  1026. }
  1027. },
  1028. flipfit: {
  1029. left: function() {
  1030. $.ui.position.flip.left.apply( this, arguments );
  1031. $.ui.position.fit.left.apply( this, arguments );
  1032. },
  1033. top: function() {
  1034. $.ui.position.flip.top.apply( this, arguments );
  1035. $.ui.position.fit.top.apply( this, arguments );
  1036. }
  1037. }
  1038. };
  1039. } )();
  1040. var position = $.ui.position;
  1041. /*!
  1042. * jQuery UI Keycode 1.12.1
  1043. * http://jqueryui.com
  1044. *
  1045. * Copyright jQuery Foundation and other contributors
  1046. * Released under the MIT license.
  1047. * http://jquery.org/license
  1048. */
  1049. //>>label: Keycode
  1050. //>>group: Core
  1051. //>>description: Provide keycodes as keynames
  1052. //>>docs: http://api.jqueryui.com/jQuery.ui.keyCode/
  1053. var keycode = $.ui.keyCode = {
  1054. BACKSPACE: 8,
  1055. COMMA: 188,
  1056. DELETE: 46,
  1057. DOWN: 40,
  1058. END: 35,
  1059. ENTER: 13,
  1060. ESCAPE: 27,
  1061. HOME: 36,
  1062. LEFT: 37,
  1063. PAGE_DOWN: 34,
  1064. PAGE_UP: 33,
  1065. PERIOD: 190,
  1066. RIGHT: 39,
  1067. SPACE: 32,
  1068. TAB: 9,
  1069. UP: 38
  1070. };
  1071. /*!
  1072. * jQuery UI Scroll Parent 1.12.1
  1073. * http://jqueryui.com
  1074. *
  1075. * Copyright jQuery Foundation and other contributors
  1076. * Released under the MIT license.
  1077. * http://jquery.org/license
  1078. */
  1079. //>>label: scrollParent
  1080. //>>group: Core
  1081. //>>description: Get the closest ancestor element that is scrollable.
  1082. //>>docs: http://api.jqueryui.com/scrollParent/
  1083. var scrollParent = $.fn.scrollParent = function( includeHidden ) {
  1084. var position = this.css( "position" ),
  1085. excludeStaticParent = position === "absolute",
  1086. overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,
  1087. scrollParent = this.parents().filter( function() {
  1088. var parent = $( this );
  1089. if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
  1090. return false;
  1091. }
  1092. return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) +
  1093. parent.css( "overflow-x" ) );
  1094. } ).eq( 0 );
  1095. return position === "fixed" || !scrollParent.length ?
  1096. $( this[ 0 ].ownerDocument || document ) :
  1097. scrollParent;
  1098. };
  1099. /*!
  1100. * jQuery UI Unique ID 1.12.1
  1101. * http://jqueryui.com
  1102. *
  1103. * Copyright jQuery Foundation and other contributors
  1104. * Released under the MIT license.
  1105. * http://jquery.org/license
  1106. */
  1107. //>>label: uniqueId
  1108. //>>group: Core
  1109. //>>description: Functions to generate and remove uniqueId's
  1110. //>>docs: http://api.jqueryui.com/uniqueId/
  1111. var uniqueId = $.fn.extend( {
  1112. uniqueId: ( function() {
  1113. var uuid = 0;
  1114. return function() {
  1115. return this.each( function() {
  1116. if ( !this.id ) {
  1117. this.id = "ui-id-" + ( ++uuid );
  1118. }
  1119. } );
  1120. };
  1121. } )(),
  1122. removeUniqueId: function() {
  1123. return this.each( function() {
  1124. if ( /^ui-id-\d+$/.test( this.id ) ) {
  1125. $( this ).removeAttr( "id" );
  1126. }
  1127. } );
  1128. }
  1129. } );
  1130. /*!
  1131. * jQuery UI Effects 1.12.1
  1132. * http://jqueryui.com
  1133. *
  1134. * Copyright jQuery Foundation and other contributors
  1135. * Released under the MIT license.
  1136. * http://jquery.org/license
  1137. */
  1138. //>>label: Effects Core
  1139. //>>group: Effects
  1140. // jscs:disable maximumLineLength
  1141. //>>description: Extends the internal jQuery effects. Includes morphing and easing. Required by all other effects.
  1142. // jscs:enable maximumLineLength
  1143. //>>docs: http://api.jqueryui.com/category/effects-core/
  1144. //>>demos: http://jqueryui.com/effect/
  1145. var dataSpace = "ui-effects-",
  1146. dataSpaceStyle = "ui-effects-style",
  1147. dataSpaceAnimated = "ui-effects-animated",
  1148. // Create a local jQuery because jQuery Color relies on it and the
  1149. // global may not exist with AMD and a custom build (#10199)
  1150. jQuery = $;
  1151. $.effects = {
  1152. effect: {}
  1153. };
  1154. /*!
  1155. * jQuery Color Animations v2.1.2
  1156. * https://github.com/jquery/jquery-color
  1157. *
  1158. * Copyright 2014 jQuery Foundation and other contributors
  1159. * Released under the MIT license.
  1160. * http://jquery.org/license
  1161. *
  1162. * Date: Wed Jan 16 08:47:09 2013 -0600
  1163. */
  1164. ( function( jQuery, undefined ) {
  1165. var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor " +
  1166. "borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
  1167. // Plusequals test for += 100 -= 100
  1168. rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
  1169. // A set of RE's that can match strings and generate color tuples.
  1170. stringParsers = [ {
  1171. re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
  1172. parse: function( execResult ) {
  1173. return [
  1174. execResult[ 1 ],
  1175. execResult[ 2 ],
  1176. execResult[ 3 ],
  1177. execResult[ 4 ]
  1178. ];
  1179. }
  1180. }, {
  1181. re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
  1182. parse: function( execResult ) {
  1183. return [
  1184. execResult[ 1 ] * 2.55,
  1185. execResult[ 2 ] * 2.55,
  1186. execResult[ 3 ] * 2.55,
  1187. execResult[ 4 ]
  1188. ];
  1189. }
  1190. }, {
  1191. // This regex ignores A-F because it's compared against an already lowercased string
  1192. re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
  1193. parse: function( execResult ) {
  1194. return [
  1195. parseInt( execResult[ 1 ], 16 ),
  1196. parseInt( execResult[ 2 ], 16 ),
  1197. parseInt( execResult[ 3 ], 16 )
  1198. ];
  1199. }
  1200. }, {
  1201. // This regex ignores A-F because it's compared against an already lowercased string
  1202. re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
  1203. parse: function( execResult ) {
  1204. return [
  1205. parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
  1206. parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
  1207. parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
  1208. ];
  1209. }
  1210. }, {
  1211. re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
  1212. space: "hsla",
  1213. parse: function( execResult ) {
  1214. return [
  1215. execResult[ 1 ],
  1216. execResult[ 2 ] / 100,
  1217. execResult[ 3 ] / 100,
  1218. execResult[ 4 ]
  1219. ];
  1220. }
  1221. } ],
  1222. // JQuery.Color( )
  1223. color = jQuery.Color = function( color, green, blue, alpha ) {
  1224. return new jQuery.Color.fn.parse( color, green, blue, alpha );
  1225. },
  1226. spaces = {
  1227. rgba: {
  1228. props: {
  1229. red: {
  1230. idx: 0,
  1231. type: "byte"
  1232. },
  1233. green: {
  1234. idx: 1,
  1235. type: "byte"
  1236. },
  1237. blue: {
  1238. idx: 2,
  1239. type: "byte"
  1240. }
  1241. }
  1242. },
  1243. hsla: {
  1244. props: {
  1245. hue: {
  1246. idx: 0,
  1247. type: "degrees"
  1248. },
  1249. saturation: {
  1250. idx: 1,
  1251. type: "percent"
  1252. },
  1253. lightness: {
  1254. idx: 2,
  1255. type: "percent"
  1256. }
  1257. }
  1258. }
  1259. },
  1260. propTypes = {
  1261. "byte": {
  1262. floor: true,
  1263. max: 255
  1264. },
  1265. "percent": {
  1266. max: 1
  1267. },
  1268. "degrees": {
  1269. mod: 360,
  1270. floor: true
  1271. }
  1272. },
  1273. support = color.support = {},
  1274. // Element for support tests
  1275. supportElem = jQuery( "<p>" )[ 0 ],
  1276. // Colors = jQuery.Color.names
  1277. colors,
  1278. // Local aliases of functions called often
  1279. each = jQuery.each;
  1280. // Determine rgba support immediately
  1281. supportElem.style.cssText = "background-color:rgba(1,1,1,.5)";
  1282. support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1;
  1283. // Define cache name and alpha properties
  1284. // for rgba and hsla spaces
  1285. each( spaces, function( spaceName, space ) {
  1286. space.cache = "_" + spaceName;
  1287. space.props.alpha = {
  1288. idx: 3,
  1289. type: "percent",
  1290. def: 1
  1291. };
  1292. } );
  1293. function clamp( value, prop, allowEmpty ) {
  1294. var type = propTypes[ prop.type ] || {};
  1295. if ( value == null ) {
  1296. return ( allowEmpty || !prop.def ) ? null : prop.def;
  1297. }
  1298. // ~~ is an short way of doing floor for positive numbers
  1299. value = type.floor ? ~~value : parseFloat( value );
  1300. // IE will pass in empty strings as value for alpha,
  1301. // which will hit this case
  1302. if ( isNaN( value ) ) {
  1303. return prop.def;
  1304. }
  1305. if ( type.mod ) {
  1306. // We add mod before modding to make sure that negatives values
  1307. // get converted properly: -10 -> 350
  1308. return ( value + type.mod ) % type.mod;
  1309. }
  1310. // For now all property types without mod have min and max
  1311. return 0 > value ? 0 : type.max < value ? type.max : value;
  1312. }
  1313. function stringParse( string ) {
  1314. var inst = color(),
  1315. rgba = inst._rgba = [];
  1316. string = string.toLowerCase();
  1317. each( stringParsers, function( i, parser ) {
  1318. var parsed,
  1319. match = parser.re.exec( string ),
  1320. values = match && parser.parse( match ),
  1321. spaceName = parser.space || "rgba";
  1322. if ( values ) {
  1323. parsed = inst[ spaceName ]( values );
  1324. // If this was an rgba parse the assignment might happen twice
  1325. // oh well....
  1326. inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];
  1327. rgba = inst._rgba = parsed._rgba;
  1328. // Exit each( stringParsers ) here because we matched
  1329. return false;
  1330. }
  1331. } );
  1332. // Found a stringParser that handled it
  1333. if ( rgba.length ) {
  1334. // If this came from a parsed string, force "transparent" when alpha is 0
  1335. // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
  1336. if ( rgba.join() === "0,0,0,0" ) {
  1337. jQuery.extend( rgba, colors.transparent );
  1338. }
  1339. return inst;
  1340. }
  1341. // Named colors
  1342. return colors[ string ];
  1343. }
  1344. color.fn = jQuery.extend( color.prototype, {
  1345. parse: function( red, green, blue, alpha ) {
  1346. if ( red === undefined ) {
  1347. this._rgba = [ null, null, null, null ];
  1348. return this;
  1349. }
  1350. if ( red.jquery || red.nodeType ) {
  1351. red = jQuery( red ).css( green );
  1352. green = undefined;
  1353. }
  1354. var inst = this,
  1355. type = jQuery.type( red ),
  1356. rgba = this._rgba = [];
  1357. // More than 1 argument specified - assume ( red, green, blue, alpha )
  1358. if ( green !== undefined ) {
  1359. red = [ red, green, blue, alpha ];
  1360. type = "array";
  1361. }
  1362. if ( type === "string" ) {
  1363. return this.parse( stringParse( red ) || colors._default );
  1364. }
  1365. if ( type === "array" ) {
  1366. each( spaces.rgba.props, function( key, prop ) {
  1367. rgba[ prop.idx ] = clamp( red[ prop.idx ], prop );
  1368. } );
  1369. return this;
  1370. }
  1371. if ( type === "object" ) {
  1372. if ( red instanceof color ) {
  1373. each( spaces, function( spaceName, space ) {
  1374. if ( red[ space.cache ] ) {
  1375. inst[ space.cache ] = red[ space.cache ].slice();
  1376. }
  1377. } );
  1378. } else {
  1379. each( spaces, function( spaceName, space ) {
  1380. var cache = space.cache;
  1381. each( space.props, function( key, prop ) {
  1382. // If the cache doesn't exist, and we know how to convert
  1383. if ( !inst[ cache ] && space.to ) {
  1384. // If the value was null, we don't need to copy it
  1385. // if the key was alpha, we don't need to copy it either
  1386. if ( key === "alpha" || red[ key ] == null ) {
  1387. return;
  1388. }
  1389. inst[ cache ] = space.to( inst._rgba );
  1390. }
  1391. // This is the only case where we allow nulls for ALL properties.
  1392. // call clamp with alwaysAllowEmpty
  1393. inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );
  1394. } );
  1395. // Everything defined but alpha?
  1396. if ( inst[ cache ] &&
  1397. jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
  1398. // Use the default of 1
  1399. inst[ cache ][ 3 ] = 1;
  1400. if ( space.from ) {
  1401. inst._rgba = space.from( inst[ cache ] );
  1402. }
  1403. }
  1404. } );
  1405. }
  1406. return this;
  1407. }
  1408. },
  1409. is: function( compare ) {
  1410. var is = color( compare ),
  1411. same = true,
  1412. inst = this;
  1413. each( spaces, function( _, space ) {
  1414. var localCache,
  1415. isCache = is[ space.cache ];
  1416. if ( isCache ) {
  1417. localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];
  1418. each( space.props, function( _, prop ) {
  1419. if ( isCache[ prop.idx ] != null ) {
  1420. same = ( isCache[ prop.idx ] === localCache[ prop.idx ] );
  1421. return same;
  1422. }
  1423. } );
  1424. }
  1425. return same;
  1426. } );
  1427. return same;
  1428. },
  1429. _space: function() {
  1430. var used = [],
  1431. inst = this;
  1432. each( spaces, function( spaceName, space ) {
  1433. if ( inst[ space.cache ] ) {
  1434. used.push( spaceName );
  1435. }
  1436. } );
  1437. return used.pop();
  1438. },
  1439. transition: function( other, distance ) {
  1440. var end = color( other ),
  1441. spaceName = end._space(),
  1442. space = spaces[ spaceName ],
  1443. startColor = this.alpha() === 0 ? color( "transparent" ) : this,
  1444. start = startColor[ space.cache ] || space.to( startColor._rgba ),
  1445. result = start.slice();
  1446. end = end[ space.cache ];
  1447. each( space.props, function( key, prop ) {
  1448. var index = prop.idx,
  1449. startValue = start[ index ],
  1450. endValue = end[ index ],
  1451. type = propTypes[ prop.type ] || {};
  1452. // If null, don't override start value
  1453. if ( endValue === null ) {
  1454. return;
  1455. }
  1456. // If null - use end
  1457. if ( startValue === null ) {
  1458. result[ index ] = endValue;
  1459. } else {
  1460. if ( type.mod ) {
  1461. if ( endValue - startValue > type.mod / 2 ) {
  1462. startValue += type.mod;
  1463. } else if ( startValue - endValue > type.mod / 2 ) {
  1464. startValue -= type.mod;
  1465. }
  1466. }
  1467. result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );
  1468. }
  1469. } );
  1470. return this[ spaceName ]( result );
  1471. },
  1472. blend: function( opaque ) {
  1473. // If we are already opaque - return ourself
  1474. if ( this._rgba[ 3 ] === 1 ) {
  1475. return this;
  1476. }
  1477. var rgb = this._rgba.slice(),
  1478. a = rgb.pop(),
  1479. blend = color( opaque )._rgba;
  1480. return color( jQuery.map( rgb, function( v, i ) {
  1481. return ( 1 - a ) * blend[ i ] + a * v;
  1482. } ) );
  1483. },
  1484. toRgbaString: function() {
  1485. var prefix = "rgba(",
  1486. rgba = jQuery.map( this._rgba, function( v, i ) {
  1487. return v == null ? ( i > 2 ? 1 : 0 ) : v;
  1488. } );
  1489. if ( rgba[ 3 ] === 1 ) {
  1490. rgba.pop();
  1491. prefix = "rgb(";
  1492. }
  1493. return prefix + rgba.join() + ")";
  1494. },
  1495. toHslaString: function() {
  1496. var prefix = "hsla(",
  1497. hsla = jQuery.map( this.hsla(), function( v, i ) {
  1498. if ( v == null ) {
  1499. v = i > 2 ? 1 : 0;
  1500. }
  1501. // Catch 1 and 2
  1502. if ( i && i < 3 ) {
  1503. v = Math.round( v * 100 ) + "%";
  1504. }
  1505. return v;
  1506. } );
  1507. if ( hsla[ 3 ] === 1 ) {
  1508. hsla.pop();
  1509. prefix = "hsl(";
  1510. }
  1511. return prefix + hsla.join() + ")";
  1512. },
  1513. toHexString: function( includeAlpha ) {
  1514. var rgba = this._rgba.slice(),
  1515. alpha = rgba.pop();
  1516. if ( includeAlpha ) {
  1517. rgba.push( ~~( alpha * 255 ) );
  1518. }
  1519. return "#" + jQuery.map( rgba, function( v ) {
  1520. // Default to 0 when nulls exist
  1521. v = ( v || 0 ).toString( 16 );
  1522. return v.length === 1 ? "0" + v : v;
  1523. } ).join( "" );
  1524. },
  1525. toString: function() {
  1526. return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
  1527. }
  1528. } );
  1529. color.fn.parse.prototype = color.fn;
  1530. // Hsla conversions adapted from:
  1531. // https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
  1532. function hue2rgb( p, q, h ) {
  1533. h = ( h + 1 ) % 1;
  1534. if ( h * 6 < 1 ) {
  1535. return p + ( q - p ) * h * 6;
  1536. }
  1537. if ( h * 2 < 1 ) {
  1538. return q;
  1539. }
  1540. if ( h * 3 < 2 ) {
  1541. return p + ( q - p ) * ( ( 2 / 3 ) - h ) * 6;
  1542. }
  1543. return p;
  1544. }
  1545. spaces.hsla.to = function( rgba ) {
  1546. if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {
  1547. return [ null, null, null, rgba[ 3 ] ];
  1548. }
  1549. var r = rgba[ 0 ] / 255,
  1550. g = rgba[ 1 ] / 255,
  1551. b = rgba[ 2 ] / 255,
  1552. a = rgba[ 3 ],
  1553. max = Math.max( r, g, b ),
  1554. min = Math.min( r, g, b ),
  1555. diff = max - min,
  1556. add = max + min,
  1557. l = add * 0.5,
  1558. h, s;
  1559. if ( min === max ) {
  1560. h = 0;
  1561. } else if ( r === max ) {
  1562. h = ( 60 * ( g - b ) / diff ) + 360;
  1563. } else if ( g === max ) {
  1564. h = ( 60 * ( b - r ) / diff ) + 120;
  1565. } else {
  1566. h = ( 60 * ( r - g ) / diff ) + 240;
  1567. }
  1568. // Chroma (diff) == 0 means greyscale which, by definition, saturation = 0%
  1569. // otherwise, saturation is based on the ratio of chroma (diff) to lightness (add)
  1570. if ( diff === 0 ) {
  1571. s = 0;
  1572. } else if ( l <= 0.5 ) {
  1573. s = diff / add;
  1574. } else {
  1575. s = diff / ( 2 - add );
  1576. }
  1577. return [ Math.round( h ) % 360, s, l, a == null ? 1 : a ];
  1578. };
  1579. spaces.hsla.from = function( hsla ) {
  1580. if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {
  1581. return [ null, null, null, hsla[ 3 ] ];
  1582. }
  1583. var h = hsla[ 0 ] / 360,
  1584. s = hsla[ 1 ],
  1585. l = hsla[ 2 ],
  1586. a = hsla[ 3 ],
  1587. q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,
  1588. p = 2 * l - q;
  1589. return [
  1590. Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),
  1591. Math.round( hue2rgb( p, q, h ) * 255 ),
  1592. Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),
  1593. a
  1594. ];
  1595. };
  1596. each( spaces, function( spaceName, space ) {
  1597. var props = space.props,
  1598. cache = space.cache,
  1599. to = space.to,
  1600. from = space.from;
  1601. // Makes rgba() and hsla()
  1602. color.fn[ spaceName ] = function( value ) {
  1603. // Generate a cache for this space if it doesn't exist
  1604. if ( to && !this[ cache ] ) {
  1605. this[ cache ] = to( this._rgba );
  1606. }
  1607. if ( value === undefined ) {
  1608. return this[ cache ].slice();
  1609. }
  1610. var ret,
  1611. type = jQuery.type( value ),
  1612. arr = ( type === "array" || type === "object" ) ? value : arguments,
  1613. local = this[ cache ].slice();
  1614. each( props, function( key, prop ) {
  1615. var val = arr[ type === "object" ? key : prop.idx ];
  1616. if ( val == null ) {
  1617. val = local[ prop.idx ];
  1618. }
  1619. local[ prop.idx ] = clamp( val, prop );
  1620. } );
  1621. if ( from ) {
  1622. ret = color( from( local ) );
  1623. ret[ cache ] = local;
  1624. return ret;
  1625. } else {
  1626. return color( local );
  1627. }
  1628. };
  1629. // Makes red() green() blue() alpha() hue() saturation() lightness()
  1630. each( props, function( key, prop ) {
  1631. // Alpha is included in more than one space
  1632. if ( color.fn[ key ] ) {
  1633. return;
  1634. }
  1635. color.fn[ key ] = function( value ) {
  1636. var vtype = jQuery.type( value ),
  1637. fn = ( key === "alpha" ? ( this._hsla ? "hsla" : "rgba" ) : spaceName ),
  1638. local = this[ fn ](),
  1639. cur = local[ prop.idx ],
  1640. match;
  1641. if ( vtype === "undefined" ) {
  1642. return cur;
  1643. }
  1644. if ( vtype === "function" ) {
  1645. value = value.call( this, cur );
  1646. vtype = jQuery.type( value );
  1647. }
  1648. if ( value == null && prop.empty ) {
  1649. return this;
  1650. }
  1651. if ( vtype === "string" ) {
  1652. match = rplusequals.exec( value );
  1653. if ( match ) {
  1654. value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 );
  1655. }
  1656. }
  1657. local[ prop.idx ] = value;
  1658. return this[ fn ]( local );
  1659. };
  1660. } );
  1661. } );
  1662. // Add cssHook and .fx.step function for each named hook.
  1663. // accept a space separated string of properties
  1664. color.hook = function( hook ) {
  1665. var hooks = hook.split( " " );
  1666. each( hooks, function( i, hook ) {
  1667. jQuery.cssHooks[ hook ] = {
  1668. set: function( elem, value ) {
  1669. var parsed, curElem,
  1670. backgroundColor = "";
  1671. if ( value !== "transparent" && ( jQuery.type( value ) !== "string" ||
  1672. ( parsed = stringParse( value ) ) ) ) {
  1673. value = color( parsed || value );
  1674. if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
  1675. curElem = hook === "backgroundColor" ? elem.parentNode : elem;
  1676. while (
  1677. ( backgroundColor === "" || backgroundColor === "transparent" ) &&
  1678. curElem && curElem.style
  1679. ) {
  1680. try {
  1681. backgroundColor = jQuery.css( curElem, "backgroundColor" );
  1682. curElem = curElem.parentNode;
  1683. } catch ( e ) {
  1684. }
  1685. }
  1686. value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
  1687. backgroundColor :
  1688. "_default" );
  1689. }
  1690. value = value.toRgbaString();
  1691. }
  1692. try {
  1693. elem.style[ hook ] = value;
  1694. } catch ( e ) {
  1695. // Wrapped to prevent IE from throwing errors on "invalid" values like
  1696. // 'auto' or 'inherit'
  1697. }
  1698. }
  1699. };
  1700. jQuery.fx.step[ hook ] = function( fx ) {
  1701. if ( !fx.colorInit ) {
  1702. fx.start = color( fx.elem, hook );
  1703. fx.end = color( fx.end );
  1704. fx.colorInit = true;
  1705. }
  1706. jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
  1707. };
  1708. } );
  1709. };
  1710. color.hook( stepHooks );
  1711. jQuery.cssHooks.borderColor = {
  1712. expand: function( value ) {
  1713. var expanded = {};
  1714. each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) {
  1715. expanded[ "border" + part + "Color" ] = value;
  1716. } );
  1717. return expanded;
  1718. }
  1719. };
  1720. // Basic color names only.
  1721. // Usage of any of the other color names requires adding yourself or including
  1722. // jquery.color.svg-names.js.
  1723. colors = jQuery.Color.names = {
  1724. // 4.1. Basic color keywords
  1725. aqua: "#00ffff",
  1726. black: "#000000",
  1727. blue: "#0000ff",
  1728. fuchsia: "#ff00ff",
  1729. gray: "#808080",
  1730. green: "#008000",
  1731. lime: "#00ff00",
  1732. maroon: "#800000",
  1733. navy: "#000080",
  1734. olive: "#808000",
  1735. purple: "#800080",
  1736. red: "#ff0000",
  1737. silver: "#c0c0c0",
  1738. teal: "#008080",
  1739. white: "#ffffff",
  1740. yellow: "#ffff00",
  1741. // 4.2.3. "transparent" color keyword
  1742. transparent: [ null, null, null, 0 ],
  1743. _default: "#ffffff"
  1744. };
  1745. } )( jQuery );
  1746. /******************************************************************************/
  1747. /****************************** CLASS ANIMATIONS ******************************/
  1748. /******************************************************************************/
  1749. ( function() {
  1750. var classAnimationActions = [ "add", "remove", "toggle" ],
  1751. shorthandStyles = {
  1752. border: 1,
  1753. borderBottom: 1,
  1754. borderColor: 1,
  1755. borderLeft: 1,
  1756. borderRight: 1,
  1757. borderTop: 1,
  1758. borderWidth: 1,
  1759. margin: 1,
  1760. padding: 1
  1761. };
  1762. $.each(
  1763. [ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ],
  1764. function( _, prop ) {
  1765. $.fx.step[ prop ] = function( fx ) {
  1766. if ( fx.end !== "none" && !fx.setAttr || fx.pos === 1 && !fx.setAttr ) {
  1767. jQuery.style( fx.elem, prop, fx.end );
  1768. fx.setAttr = true;
  1769. }
  1770. };
  1771. }
  1772. );
  1773. function getElementStyles( elem ) {
  1774. var key, len,
  1775. style = elem.ownerDocument.defaultView ?
  1776. elem.ownerDocument.defaultView.getComputedStyle( elem, null ) :
  1777. elem.currentStyle,
  1778. styles = {};
  1779. if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) {
  1780. len = style.length;
  1781. while ( len-- ) {
  1782. key = style[ len ];
  1783. if ( typeof style[ key ] === "string" ) {
  1784. styles[ $.camelCase( key ) ] = style[ key ];
  1785. }
  1786. }
  1787. // Support: Opera, IE <9
  1788. } else {
  1789. for ( key in style ) {
  1790. if ( typeof style[ key ] === "string" ) {
  1791. styles[ key ] = style[ key ];
  1792. }
  1793. }
  1794. }
  1795. return styles;
  1796. }
  1797. function styleDifference( oldStyle, newStyle ) {
  1798. var diff = {},
  1799. name, value;
  1800. for ( name in newStyle ) {
  1801. value = newStyle[ name ];
  1802. if ( oldStyle[ name ] !== value ) {
  1803. if ( !shorthandStyles[ name ] ) {
  1804. if ( $.fx.step[ name ] || !isNaN( parseFloat( value ) ) ) {
  1805. diff[ name ] = value;
  1806. }
  1807. }
  1808. }
  1809. }
  1810. return diff;
  1811. }
  1812. // Support: jQuery <1.8
  1813. if ( !$.fn.addBack ) {
  1814. $.fn.addBack = function( selector ) {
  1815. return this.add( selector == null ?
  1816. this.prevObject : this.prevObject.filter( selector )
  1817. );
  1818. };
  1819. }
  1820. $.effects.animateClass = function( value, duration, easing, callback ) {
  1821. var o = $.speed( duration, easing, callback );
  1822. return this.queue( function() {
  1823. var animated = $( this ),
  1824. baseClass = animated.attr( "class" ) || "",
  1825. applyClassChange,
  1826. allAnimations = o.children ? animated.find( "*" ).addBack() : animated;
  1827. // Map the animated objects to store the original styles.
  1828. allAnimations = allAnimations.map( function() {
  1829. var el = $( this );
  1830. return {
  1831. el: el,
  1832. start: getElementStyles( this )
  1833. };
  1834. } );
  1835. // Apply class change
  1836. applyClassChange = function() {
  1837. $.each( classAnimationActions, function( i, action ) {
  1838. if ( value[ action ] ) {
  1839. animated[ action + "Class" ]( value[ action ] );
  1840. }
  1841. } );
  1842. };
  1843. applyClassChange();
  1844. // Map all animated objects again - calculate new styles and diff
  1845. allAnimations = allAnimations.map( function() {
  1846. this.end = getElementStyles( this.el[ 0 ] );
  1847. this.diff = styleDifference( this.start, this.end );
  1848. return this;
  1849. } );
  1850. // Apply original class
  1851. animated.attr( "class", baseClass );
  1852. // Map all animated objects again - this time collecting a promise
  1853. allAnimations = allAnimations.map( function() {
  1854. var styleInfo = this,
  1855. dfd = $.Deferred(),
  1856. opts = $.extend( {}, o, {
  1857. queue: false,
  1858. complete: function() {
  1859. dfd.resolve( styleInfo );
  1860. }
  1861. } );
  1862. this.el.animate( this.diff, opts );
  1863. return dfd.promise();
  1864. } );
  1865. // Once all animations have completed:
  1866. $.when.apply( $, allAnimations.get() ).done( function() {
  1867. // Set the final class
  1868. applyClassChange();
  1869. // For each animated element,
  1870. // clear all css properties that were animated
  1871. $.each( arguments, function() {
  1872. var el = this.el;
  1873. $.each( this.diff, function( key ) {
  1874. el.css( key, "" );
  1875. } );
  1876. } );
  1877. // This is guarnteed to be there if you use jQuery.speed()
  1878. // it also handles dequeuing the next anim...
  1879. o.complete.call( animated[ 0 ] );
  1880. } );
  1881. } );
  1882. };
  1883. $.fn.extend( {
  1884. addClass: ( function( orig ) {
  1885. return function( classNames, speed, easing, callback ) {
  1886. return speed ?
  1887. $.effects.animateClass.call( this,
  1888. { add: classNames }, speed, easing, callback ) :
  1889. orig.apply( this, arguments );
  1890. };
  1891. } )( $.fn.addClass ),
  1892. removeClass: ( function( orig ) {
  1893. return function( classNames, speed, easing, callback ) {
  1894. return arguments.length > 1 ?
  1895. $.effects.animateClass.call( this,
  1896. { remove: classNames }, speed, easing, callback ) :
  1897. orig.apply( this, arguments );
  1898. };
  1899. } )( $.fn.removeClass ),
  1900. toggleClass: ( function( orig ) {
  1901. return function( classNames, force, speed, easing, callback ) {
  1902. if ( typeof force === "boolean" || force === undefined ) {
  1903. if ( !speed ) {
  1904. // Without speed parameter
  1905. return orig.apply( this, arguments );
  1906. } else {
  1907. return $.effects.animateClass.call( this,
  1908. ( force ? { add: classNames } : { remove: classNames } ),
  1909. speed, easing, callback );
  1910. }
  1911. } else {
  1912. // Without force parameter
  1913. return $.effects.animateClass.call( this,
  1914. { toggle: classNames }, force, speed, easing );
  1915. }
  1916. };
  1917. } )( $.fn.toggleClass ),
  1918. switchClass: function( remove, add, speed, easing, callback ) {
  1919. return $.effects.animateClass.call( this, {
  1920. add: add,
  1921. remove: remove
  1922. }, speed, easing, callback );
  1923. }
  1924. } );
  1925. } )();
  1926. /******************************************************************************/
  1927. /*********************************** EFFECTS **********************************/
  1928. /******************************************************************************/
  1929. ( function() {
  1930. if ( $.expr && $.expr.filters && $.expr.filters.animated ) {
  1931. $.expr.filters.animated = ( function( orig ) {
  1932. return function( elem ) {
  1933. return !!$( elem ).data( dataSpaceAnimated ) || orig( elem );
  1934. };
  1935. } )( $.expr.filters.animated );
  1936. }
  1937. if ( $.uiBackCompat !== false ) {
  1938. $.extend( $.effects, {
  1939. // Saves a set of properties in a data storage
  1940. save: function( element, set ) {
  1941. var i = 0, length = set.length;
  1942. for ( ; i < length; i++ ) {
  1943. if ( set[ i ] !== null ) {
  1944. element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );
  1945. }
  1946. }
  1947. },
  1948. // Restores a set of previously saved properties from a data storage
  1949. restore: function( element, set ) {
  1950. var val, i = 0, length = set.length;
  1951. for ( ; i < length; i++ ) {
  1952. if ( set[ i ] !== null ) {
  1953. val = element.data( dataSpace + set[ i ] );
  1954. element.css( set[ i ], val );
  1955. }
  1956. }
  1957. },
  1958. setMode: function( el, mode ) {
  1959. if ( mode === "toggle" ) {
  1960. mode = el.is( ":hidden" ) ? "show" : "hide";
  1961. }
  1962. return mode;
  1963. },
  1964. // Wraps the element around a wrapper that copies position properties
  1965. createWrapper: function( element ) {
  1966. // If the element is already wrapped, return it
  1967. if ( element.parent().is( ".ui-effects-wrapper" ) ) {
  1968. return element.parent();
  1969. }
  1970. // Wrap the element
  1971. var props = {
  1972. width: element.outerWidth( true ),
  1973. height: element.outerHeight( true ),
  1974. "float": element.css( "float" )
  1975. },
  1976. wrapper = $( "<div></div>" )
  1977. .addClass( "ui-effects-wrapper" )
  1978. .css( {
  1979. fontSize: "100%",
  1980. background: "transparent",
  1981. border: "none",
  1982. margin: 0,
  1983. padding: 0
  1984. } ),
  1985. // Store the size in case width/height are defined in % - Fixes #5245
  1986. size = {
  1987. width: element.width(),
  1988. height: element.height()
  1989. },
  1990. active = document.activeElement;
  1991. // Support: Firefox
  1992. // Firefox incorrectly exposes anonymous content
  1993. // https://bugzilla.mozilla.org/show_bug.cgi?id=561664
  1994. try {
  1995. active.id;
  1996. } catch ( e ) {
  1997. active = document.body;
  1998. }
  1999. element.wrap( wrapper );
  2000. // Fixes #7595 - Elements lose focus when wrapped.
  2001. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  2002. $( active ).trigger( "focus" );
  2003. }
  2004. // Hotfix for jQuery 1.4 since some change in wrap() seems to actually
  2005. // lose the reference to the wrapped element
  2006. wrapper = element.parent();
  2007. // Transfer positioning properties to the wrapper
  2008. if ( element.css( "position" ) === "static" ) {
  2009. wrapper.css( { position: "relative" } );
  2010. element.css( { position: "relative" } );
  2011. } else {
  2012. $.extend( props, {
  2013. position: element.css( "position" ),
  2014. zIndex: element.css( "z-index" )
  2015. } );
  2016. $.each( [ "top", "left", "bottom", "right" ], function( i, pos ) {
  2017. props[ pos ] = element.css( pos );
  2018. if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
  2019. props[ pos ] = "auto";
  2020. }
  2021. } );
  2022. element.css( {
  2023. position: "relative",
  2024. top: 0,
  2025. left: 0,
  2026. right: "auto",
  2027. bottom: "auto"
  2028. } );
  2029. }
  2030. element.css( size );
  2031. return wrapper.css( props ).show();
  2032. },
  2033. removeWrapper: function( element ) {
  2034. var active = document.activeElement;
  2035. if ( element.parent().is( ".ui-effects-wrapper" ) ) {
  2036. element.parent().replaceWith( element );
  2037. // Fixes #7595 - Elements lose focus when wrapped.
  2038. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  2039. $( active ).trigger( "focus" );
  2040. }
  2041. }
  2042. return element;
  2043. }
  2044. } );
  2045. }
  2046. $.extend( $.effects, {
  2047. version: "1.12.1",
  2048. define: function( name, mode, effect ) {
  2049. if ( !effect ) {
  2050. effect = mode;
  2051. mode = "effect";
  2052. }
  2053. $.effects.effect[ name ] = effect;
  2054. $.effects.effect[ name ].mode = mode;
  2055. return effect;
  2056. },
  2057. scaledDimensions: function( element, percent, direction ) {
  2058. if ( percent === 0 ) {
  2059. return {
  2060. height: 0,
  2061. width: 0,
  2062. outerHeight: 0,
  2063. outerWidth: 0
  2064. };
  2065. }
  2066. var x = direction !== "horizontal" ? ( ( percent || 100 ) / 100 ) : 1,
  2067. y = direction !== "vertical" ? ( ( percent || 100 ) / 100 ) : 1;
  2068. return {
  2069. height: element.height() * y,
  2070. width: element.width() * x,
  2071. outerHeight: element.outerHeight() * y,
  2072. outerWidth: element.outerWidth() * x
  2073. };
  2074. },
  2075. clipToBox: function( animation ) {
  2076. return {
  2077. width: animation.clip.right - animation.clip.left,
  2078. height: animation.clip.bottom - animation.clip.top,
  2079. left: animation.clip.left,
  2080. top: animation.clip.top
  2081. };
  2082. },
  2083. // Injects recently queued functions to be first in line (after "inprogress")
  2084. unshift: function( element, queueLength, count ) {
  2085. var queue = element.queue();
  2086. if ( queueLength > 1 ) {
  2087. queue.splice.apply( queue,
  2088. [ 1, 0 ].concat( queue.splice( queueLength, count ) ) );
  2089. }
  2090. element.dequeue();
  2091. },
  2092. saveStyle: function( element ) {
  2093. element.data( dataSpaceStyle, element[ 0 ].style.cssText );
  2094. },
  2095. restoreStyle: function( element ) {
  2096. element[ 0 ].style.cssText = element.data( dataSpaceStyle ) || "";
  2097. element.removeData( dataSpaceStyle );
  2098. },
  2099. mode: function( element, mode ) {
  2100. var hidden = element.is( ":hidden" );
  2101. if ( mode === "toggle" ) {
  2102. mode = hidden ? "show" : "hide";
  2103. }
  2104. if ( hidden ? mode === "hide" : mode === "show" ) {
  2105. mode = "none";
  2106. }
  2107. return mode;
  2108. },
  2109. // Translates a [top,left] array into a baseline value
  2110. getBaseline: function( origin, original ) {
  2111. var y, x;
  2112. switch ( origin[ 0 ] ) {
  2113. case "top":
  2114. y = 0;
  2115. break;
  2116. case "middle":
  2117. y = 0.5;
  2118. break;
  2119. case "bottom":
  2120. y = 1;
  2121. break;
  2122. default:
  2123. y = origin[ 0 ] / original.height;
  2124. }
  2125. switch ( origin[ 1 ] ) {
  2126. case "left":
  2127. x = 0;
  2128. break;
  2129. case "center":
  2130. x = 0.5;
  2131. break;
  2132. case "right":
  2133. x = 1;
  2134. break;
  2135. default:
  2136. x = origin[ 1 ] / original.width;
  2137. }
  2138. return {
  2139. x: x,
  2140. y: y
  2141. };
  2142. },
  2143. // Creates a placeholder element so that the original element can be made absolute
  2144. createPlaceholder: function( element ) {
  2145. var placeholder,
  2146. cssPosition = element.css( "position" ),
  2147. position = element.position();
  2148. // Lock in margins first to account for form elements, which
  2149. // will change margin if you explicitly set height
  2150. // see: http://jsfiddle.net/JZSMt/3/ https://bugs.webkit.org/show_bug.cgi?id=107380
  2151. // Support: Safari
  2152. element.css( {
  2153. marginTop: element.css( "marginTop" ),
  2154. marginBottom: element.css( "marginBottom" ),
  2155. marginLeft: element.css( "marginLeft" ),
  2156. marginRight: element.css( "marginRight" )
  2157. } )
  2158. .outerWidth( element.outerWidth() )
  2159. .outerHeight( element.outerHeight() );
  2160. if ( /^(static|relative)/.test( cssPosition ) ) {
  2161. cssPosition = "absolute";
  2162. placeholder = $( "<" + element[ 0 ].nodeName + ">" ).insertAfter( element ).css( {
  2163. // Convert inline to inline block to account for inline elements
  2164. // that turn to inline block based on content (like img)
  2165. display: /^(inline|ruby)/.test( element.css( "display" ) ) ?
  2166. "inline-block" :
  2167. "block",
  2168. visibility: "hidden",
  2169. // Margins need to be set to account for margin collapse
  2170. marginTop: element.css( "marginTop" ),
  2171. marginBottom: element.css( "marginBottom" ),
  2172. marginLeft: element.css( "marginLeft" ),
  2173. marginRight: element.css( "marginRight" ),
  2174. "float": element.css( "float" )
  2175. } )
  2176. .outerWidth( element.outerWidth() )
  2177. .outerHeight( element.outerHeight() )
  2178. .addClass( "ui-effects-placeholder" );
  2179. element.data( dataSpace + "placeholder", placeholder );
  2180. }
  2181. element.css( {
  2182. position: cssPosition,
  2183. left: position.left,
  2184. top: position.top
  2185. } );
  2186. return placeholder;
  2187. },
  2188. removePlaceholder: function( element ) {
  2189. var dataKey = dataSpace + "placeholder",
  2190. placeholder = element.data( dataKey );
  2191. if ( placeholder ) {
  2192. placeholder.remove();
  2193. element.removeData( dataKey );
  2194. }
  2195. },
  2196. // Removes a placeholder if it exists and restores
  2197. // properties that were modified during placeholder creation
  2198. cleanUp: function( element ) {
  2199. $.effects.restoreStyle( element );
  2200. $.effects.removePlaceholder( element );
  2201. },
  2202. setTransition: function( element, list, factor, value ) {
  2203. value = value || {};
  2204. $.each( list, function( i, x ) {
  2205. var unit = element.cssUnit( x );
  2206. if ( unit[ 0 ] > 0 ) {
  2207. value[ x ] = unit[ 0 ] * factor + unit[ 1 ];
  2208. }
  2209. } );
  2210. return value;
  2211. }
  2212. } );
  2213. // Return an effect options object for the given parameters:
  2214. function _normalizeArguments( effect, options, speed, callback ) {
  2215. // Allow passing all options as the first parameter
  2216. if ( $.isPlainObject( effect ) ) {
  2217. options = effect;
  2218. effect = effect.effect;
  2219. }
  2220. // Convert to an object
  2221. effect = { effect: effect };
  2222. // Catch (effect, null, ...)
  2223. if ( options == null ) {
  2224. options = {};
  2225. }
  2226. // Catch (effect, callback)
  2227. if ( $.isFunction( options ) ) {
  2228. callback = options;
  2229. speed = null;
  2230. options = {};
  2231. }
  2232. // Catch (effect, speed, ?)
  2233. if ( typeof options === "number" || $.fx.speeds[ options ] ) {
  2234. callback = speed;
  2235. speed = options;
  2236. options = {};
  2237. }
  2238. // Catch (effect, options, callback)
  2239. if ( $.isFunction( speed ) ) {
  2240. callback = speed;
  2241. speed = null;
  2242. }
  2243. // Add options to effect
  2244. if ( options ) {
  2245. $.extend( effect, options );
  2246. }
  2247. speed = speed || options.duration;
  2248. effect.duration = $.fx.off ? 0 :
  2249. typeof speed === "number" ? speed :
  2250. speed in $.fx.speeds ? $.fx.speeds[ speed ] :
  2251. $.fx.speeds._default;
  2252. effect.complete = callback || options.complete;
  2253. return effect;
  2254. }
  2255. function standardAnimationOption( option ) {
  2256. // Valid standard speeds (nothing, number, named speed)
  2257. if ( !option || typeof option === "number" || $.fx.speeds[ option ] ) {
  2258. return true;
  2259. }
  2260. // Invalid strings - treat as "normal" speed
  2261. if ( typeof option === "string" && !$.effects.effect[ option ] ) {
  2262. return true;
  2263. }
  2264. // Complete callback
  2265. if ( $.isFunction( option ) ) {
  2266. return true;
  2267. }
  2268. // Options hash (but not naming an effect)
  2269. if ( typeof option === "object" && !option.effect ) {
  2270. return true;
  2271. }
  2272. // Didn't match any standard API
  2273. return false;
  2274. }
  2275. $.fn.extend( {
  2276. effect: function( /* effect, options, speed, callback */ ) {
  2277. var args = _normalizeArguments.apply( this, arguments ),
  2278. effectMethod = $.effects.effect[ args.effect ],
  2279. defaultMode = effectMethod.mode,
  2280. queue = args.queue,
  2281. queueName = queue || "fx",
  2282. complete = args.complete,
  2283. mode = args.mode,
  2284. modes = [],
  2285. prefilter = function( next ) {
  2286. var el = $( this ),
  2287. normalizedMode = $.effects.mode( el, mode ) || defaultMode;
  2288. // Sentinel for duck-punching the :animated psuedo-selector
  2289. el.data( dataSpaceAnimated, true );
  2290. // Save effect mode for later use,
  2291. // we can't just call $.effects.mode again later,
  2292. // as the .show() below destroys the initial state
  2293. modes.push( normalizedMode );
  2294. // See $.uiBackCompat inside of run() for removal of defaultMode in 1.13
  2295. if ( defaultMode && ( normalizedMode === "show" ||
  2296. ( normalizedMode === defaultMode && normalizedMode === "hide" ) ) ) {
  2297. el.show();
  2298. }
  2299. if ( !defaultMode || normalizedMode !== "none" ) {
  2300. $.effects.saveStyle( el );
  2301. }
  2302. if ( $.isFunction( next ) ) {
  2303. next();
  2304. }
  2305. };
  2306. if ( $.fx.off || !effectMethod ) {
  2307. // Delegate to the original method (e.g., .show()) if possible
  2308. if ( mode ) {
  2309. return this[ mode ]( args.duration, complete );
  2310. } else {
  2311. return this.each( function() {
  2312. if ( complete ) {
  2313. complete.call( this );
  2314. }
  2315. } );
  2316. }
  2317. }
  2318. function run( next ) {
  2319. var elem = $( this );
  2320. function cleanup() {
  2321. elem.removeData( dataSpaceAnimated );
  2322. $.effects.cleanUp( elem );
  2323. if ( args.mode === "hide" ) {
  2324. elem.hide();
  2325. }
  2326. done();
  2327. }
  2328. function done() {
  2329. if ( $.isFunction( complete ) ) {
  2330. complete.call( elem[ 0 ] );
  2331. }
  2332. if ( $.isFunction( next ) ) {
  2333. next();
  2334. }
  2335. }
  2336. // Override mode option on a per element basis,
  2337. // as toggle can be either show or hide depending on element state
  2338. args.mode = modes.shift();
  2339. if ( $.uiBackCompat !== false && !defaultMode ) {
  2340. if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
  2341. // Call the core method to track "olddisplay" properly
  2342. elem[ mode ]();
  2343. done();
  2344. } else {
  2345. effectMethod.call( elem[ 0 ], args, done );
  2346. }
  2347. } else {
  2348. if ( args.mode === "none" ) {
  2349. // Call the core method to track "olddisplay" properly
  2350. elem[ mode ]();
  2351. done();
  2352. } else {
  2353. effectMethod.call( elem[ 0 ], args, cleanup );
  2354. }
  2355. }
  2356. }
  2357. // Run prefilter on all elements first to ensure that
  2358. // any showing or hiding happens before placeholder creation,
  2359. // which ensures that any layout changes are correctly captured.
  2360. return queue === false ?
  2361. this.each( prefilter ).each( run ) :
  2362. this.queue( queueName, prefilter ).queue( queueName, run );
  2363. },
  2364. show: ( function( orig ) {
  2365. return function( option ) {
  2366. if ( standardAnimationOption( option ) ) {
  2367. return orig.apply( this, arguments );
  2368. } else {
  2369. var args = _normalizeArguments.apply( this, arguments );
  2370. args.mode = "show";
  2371. return this.effect.call( this, args );
  2372. }
  2373. };
  2374. } )( $.fn.show ),
  2375. hide: ( function( orig ) {
  2376. return function( option ) {
  2377. if ( standardAnimationOption( option ) ) {
  2378. return orig.apply( this, arguments );
  2379. } else {
  2380. var args = _normalizeArguments.apply( this, arguments );
  2381. args.mode = "hide";
  2382. return this.effect.call( this, args );
  2383. }
  2384. };
  2385. } )( $.fn.hide ),
  2386. toggle: ( function( orig ) {
  2387. return function( option ) {
  2388. if ( standardAnimationOption( option ) || typeof option === "boolean" ) {
  2389. return orig.apply( this, arguments );
  2390. } else {
  2391. var args = _normalizeArguments.apply( this, arguments );
  2392. args.mode = "toggle";
  2393. return this.effect.call( this, args );
  2394. }
  2395. };
  2396. } )( $.fn.toggle ),
  2397. cssUnit: function( key ) {
  2398. var style = this.css( key ),
  2399. val = [];
  2400. $.each( [ "em", "px", "%", "pt" ], function( i, unit ) {
  2401. if ( style.indexOf( unit ) > 0 ) {
  2402. val = [ parseFloat( style ), unit ];
  2403. }
  2404. } );
  2405. return val;
  2406. },
  2407. cssClip: function( clipObj ) {
  2408. if ( clipObj ) {
  2409. return this.css( "clip", "rect(" + clipObj.top + "px " + clipObj.right + "px " +
  2410. clipObj.bottom + "px " + clipObj.left + "px)" );
  2411. }
  2412. return parseClip( this.css( "clip" ), this );
  2413. },
  2414. transfer: function( options, done ) {
  2415. var element = $( this ),
  2416. target = $( options.to ),
  2417. targetFixed = target.css( "position" ) === "fixed",
  2418. body = $( "body" ),
  2419. fixTop = targetFixed ? body.scrollTop() : 0,
  2420. fixLeft = targetFixed ? body.scrollLeft() : 0,
  2421. endPosition = target.offset(),
  2422. animation = {
  2423. top: endPosition.top - fixTop,
  2424. left: endPosition.left - fixLeft,
  2425. height: target.innerHeight(),
  2426. width: target.innerWidth()
  2427. },
  2428. startPosition = element.offset(),
  2429. transfer = $( "<div class='ui-effects-transfer'></div>" )
  2430. .appendTo( "body" )
  2431. .addClass( options.className )
  2432. .css( {
  2433. top: startPosition.top - fixTop,
  2434. left: startPosition.left - fixLeft,
  2435. height: element.innerHeight(),
  2436. width: element.innerWidth(),
  2437. position: targetFixed ? "fixed" : "absolute"
  2438. } )
  2439. .animate( animation, options.duration, options.easing, function() {
  2440. transfer.remove();
  2441. if ( $.isFunction( done ) ) {
  2442. done();
  2443. }
  2444. } );
  2445. }
  2446. } );
  2447. function parseClip( str, element ) {
  2448. var outerWidth = element.outerWidth(),
  2449. outerHeight = element.outerHeight(),
  2450. clipRegex = /^rect\((-?\d*\.?\d*px|-?\d+%|auto),?\s*(-?\d*\.?\d*px|-?\d+%|auto),?\s*(-?\d*\.?\d*px|-?\d+%|auto),?\s*(-?\d*\.?\d*px|-?\d+%|auto)\)$/,
  2451. values = clipRegex.exec( str ) || [ "", 0, outerWidth, outerHeight, 0 ];
  2452. return {
  2453. top: parseFloat( values[ 1 ] ) || 0,
  2454. right: values[ 2 ] === "auto" ? outerWidth : parseFloat( values[ 2 ] ),
  2455. bottom: values[ 3 ] === "auto" ? outerHeight : parseFloat( values[ 3 ] ),
  2456. left: parseFloat( values[ 4 ] ) || 0
  2457. };
  2458. }
  2459. $.fx.step.clip = function( fx ) {
  2460. if ( !fx.clipInit ) {
  2461. fx.start = $( fx.elem ).cssClip();
  2462. if ( typeof fx.end === "string" ) {
  2463. fx.end = parseClip( fx.end, fx.elem );
  2464. }
  2465. fx.clipInit = true;
  2466. }
  2467. $( fx.elem ).cssClip( {
  2468. top: fx.pos * ( fx.end.top - fx.start.top ) + fx.start.top,
  2469. right: fx.pos * ( fx.end.right - fx.start.right ) + fx.start.right,
  2470. bottom: fx.pos * ( fx.end.bottom - fx.start.bottom ) + fx.start.bottom,
  2471. left: fx.pos * ( fx.end.left - fx.start.left ) + fx.start.left
  2472. } );
  2473. };
  2474. } )();
  2475. /******************************************************************************/
  2476. /*********************************** EASING ***********************************/
  2477. /******************************************************************************/
  2478. ( function() {
  2479. // Based on easing equations from Robert Penner (http://www.robertpenner.com/easing)
  2480. var baseEasings = {};
  2481. $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) {
  2482. baseEasings[ name ] = function( p ) {
  2483. return Math.pow( p, i + 2 );
  2484. };
  2485. } );
  2486. $.extend( baseEasings, {
  2487. Sine: function( p ) {
  2488. return 1 - Math.cos( p * Math.PI / 2 );
  2489. },
  2490. Circ: function( p ) {
  2491. return 1 - Math.sqrt( 1 - p * p );
  2492. },
  2493. Elastic: function( p ) {
  2494. return p === 0 || p === 1 ? p :
  2495. -Math.pow( 2, 8 * ( p - 1 ) ) * Math.sin( ( ( p - 1 ) * 80 - 7.5 ) * Math.PI / 15 );
  2496. },
  2497. Back: function( p ) {
  2498. return p * p * ( 3 * p - 2 );
  2499. },
  2500. Bounce: function( p ) {
  2501. var pow2,
  2502. bounce = 4;
  2503. while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
  2504. return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
  2505. }
  2506. } );
  2507. $.each( baseEasings, function( name, easeIn ) {
  2508. $.easing[ "easeIn" + name ] = easeIn;
  2509. $.easing[ "easeOut" + name ] = function( p ) {
  2510. return 1 - easeIn( 1 - p );
  2511. };
  2512. $.easing[ "easeInOut" + name ] = function( p ) {
  2513. return p < 0.5 ?
  2514. easeIn( p * 2 ) / 2 :
  2515. 1 - easeIn( p * -2 + 2 ) / 2;
  2516. };
  2517. } );
  2518. } )();
  2519. var effect = $.effects;
  2520. /*!
  2521. * jQuery UI Effects Blind 1.12.1
  2522. * http://jqueryui.com
  2523. *
  2524. * Copyright jQuery Foundation and other contributors
  2525. * Released under the MIT license.
  2526. * http://jquery.org/license
  2527. */
  2528. //>>label: Blind Effect
  2529. //>>group: Effects
  2530. //>>description: Blinds the element.
  2531. //>>docs: http://api.jqueryui.com/blind-effect/
  2532. //>>demos: http://jqueryui.com/effect/
  2533. var effectsEffectBlind = $.effects.define( "blind", "hide", function( options, done ) {
  2534. var map = {
  2535. up: [ "bottom", "top" ],
  2536. vertical: [ "bottom", "top" ],
  2537. down: [ "top", "bottom" ],
  2538. left: [ "right", "left" ],
  2539. horizontal: [ "right", "left" ],
  2540. right: [ "left", "right" ]
  2541. },
  2542. element = $( this ),
  2543. direction = options.direction || "up",
  2544. start = element.cssClip(),
  2545. animate = { clip: $.extend( {}, start ) },
  2546. placeholder = $.effects.createPlaceholder( element );
  2547. animate.clip[ map[ direction ][ 0 ] ] = animate.clip[ map[ direction ][ 1 ] ];
  2548. if ( options.mode === "show" ) {
  2549. element.cssClip( animate.clip );
  2550. if ( placeholder ) {
  2551. placeholder.css( $.effects.clipToBox( animate ) );
  2552. }
  2553. animate.clip = start;
  2554. }
  2555. if ( placeholder ) {
  2556. placeholder.animate( $.effects.clipToBox( animate ), options.duration, options.easing );
  2557. }
  2558. element.animate( animate, {
  2559. queue: false,
  2560. duration: options.duration,
  2561. easing: options.easing,
  2562. complete: done
  2563. } );
  2564. } );
  2565. // NOTE: Original jQuery UI wrapper was replaced. See README-Fancytree.md
  2566. // }));
  2567. })(jQuery);
  2568. (function( factory ) {
  2569. if ( typeof define === "function" && define.amd ) {
  2570. // AMD. Register as an anonymous module.
  2571. define( [ "jquery" ], factory );
  2572. } else if ( typeof module === "object" && module.exports ) {
  2573. // Node/CommonJS
  2574. module.exports = factory(require("jquery"));
  2575. } else {
  2576. // Browser globals
  2577. factory( jQuery );
  2578. }
  2579. }(function( $ ) {
  2580. /*! Fancytree Core *//*!
  2581. * jquery.fancytree.js
  2582. * Tree view control with support for lazy loading and much more.
  2583. * https://github.com/mar10/fancytree/
  2584. *
  2585. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  2586. * Released under the MIT license
  2587. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  2588. *
  2589. * @version 2.26.0
  2590. * @date 2017-11-04T17:52:53Z
  2591. */
  2592. /** Core Fancytree module.
  2593. */
  2594. // UMD wrapper for the Fancytree core module
  2595. ;(function( factory ) {
  2596. if ( typeof define === "function" && define.amd ) {
  2597. // AMD. Register as an anonymous module.
  2598. define( [ "jquery", "./jquery.fancytree.ui-deps" ], factory );
  2599. } else if ( typeof module === "object" && module.exports ) {
  2600. // Node/CommonJS
  2601. require("jquery.fancytree.ui-deps");
  2602. module.exports = factory(require("jquery"));
  2603. } else {
  2604. // Browser globals
  2605. factory( jQuery );
  2606. }
  2607. }( function( $ ) {
  2608. "use strict";
  2609. // prevent duplicate loading
  2610. if ( $.ui && $.ui.fancytree ) {
  2611. $.ui.fancytree.warn("Fancytree: ignored duplicate include");
  2612. return;
  2613. }
  2614. /* *****************************************************************************
  2615. * Private functions and variables
  2616. */
  2617. var i, attr,
  2618. FT = null, // initialized below
  2619. TEST_IMG = new RegExp(/\.|\//), // strings are considered image urls if they contain '.' or '/'
  2620. REX_HTML = /[&<>"'\/]/g,
  2621. REX_TOOLTIP = /[<>"'\/]/g,
  2622. RECURSIVE_REQUEST_ERROR = "$recursive_request",
  2623. ENTITY_MAP = {"&": "&amp;", "<": "&lt;", ">": "&gt;", "\"": "&quot;", "'": "&#39;", "/": "&#x2F;"},
  2624. IGNORE_KEYCODES = { 16: true, 17: true, 18: true },
  2625. SPECIAL_KEYCODES = {
  2626. 8: "backspace", 9: "tab", 10: "return", 13: "return",
  2627. // 16: null, 17: null, 18: null, // ignore shift, ctrl, alt
  2628. 19: "pause", 20: "capslock", 27: "esc", 32: "space", 33: "pageup",
  2629. 34: "pagedown", 35: "end", 36: "home", 37: "left", 38: "up",
  2630. 39: "right", 40: "down", 45: "insert", 46: "del", 59: ";", 61: "=",
  2631. 96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6",
  2632. 103: "7", 104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".",
  2633. 111: "/", 112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5",
  2634. 117: "f6", 118: "f7", 119: "f8", 120: "f9", 121: "f10", 122: "f11",
  2635. 123: "f12", 144: "numlock", 145: "scroll", 173: "-", 186: ";", 187: "=",
  2636. 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
  2637. 221: "]", 222: "'"},
  2638. MOUSE_BUTTONS = { 0: "", 1: "left", 2: "middle", 3: "right" },
  2639. // Boolean attributes that can be set with equivalent class names in the LI tags
  2640. // Note: v2.23: checkbox and hideCheckbox are *not* in this list
  2641. CLASS_ATTRS = "active expanded focus folder lazy radiogroup selected unselectable unselectableIgnore".split(" "),
  2642. CLASS_ATTR_MAP = {},
  2643. // Top-level Fancytree node attributes, that can be set by dict
  2644. NODE_ATTRS = "checkbox expanded extraClasses folder icon key lazy radiogroup refKey selected statusNodeType title tooltip unselectable unselectableIgnore unselectableStatus".split(" "),
  2645. NODE_ATTR_MAP = {},
  2646. // Mapping of lowercase -> real name (because HTML5 data-... attribute only supports lowercase)
  2647. NODE_ATTR_LOWERCASE_MAP = {},
  2648. // Attribute names that should NOT be added to node.data
  2649. NONE_NODE_DATA_MAP = {"active": true, "children": true, "data": true, "focus": true};
  2650. for(i=0; i<CLASS_ATTRS.length; i++){ CLASS_ATTR_MAP[CLASS_ATTRS[i]] = true; }
  2651. for(i=0; i<NODE_ATTRS.length; i++) {
  2652. attr = NODE_ATTRS[i];
  2653. NODE_ATTR_MAP[attr] = true;
  2654. if( attr !== attr.toLowerCase() ) {
  2655. NODE_ATTR_LOWERCASE_MAP[attr.toLowerCase()] = attr;
  2656. }
  2657. }
  2658. function _assert(cond, msg){
  2659. // TODO: see qunit.js extractStacktrace()
  2660. if(!cond){
  2661. msg = msg ? ": " + msg : "";
  2662. // consoleApply("assert", [!!cond, msg]);
  2663. $.error("Fancytree assertion failed" + msg);
  2664. }
  2665. }
  2666. _assert($.ui, "Fancytree requires jQuery UI (http://jqueryui.com)");
  2667. function consoleApply(method, args){
  2668. var i, s,
  2669. fn = window.console ? window.console[method] : null;
  2670. if(fn){
  2671. try{
  2672. fn.apply(window.console, args);
  2673. } catch(e) {
  2674. // IE 8?
  2675. s = "";
  2676. for( i=0; i<args.length; i++ ) {
  2677. s += args[i];
  2678. }
  2679. fn(s);
  2680. }
  2681. }
  2682. }
  2683. /*Return true if x is a FancytreeNode.*/
  2684. function _isNode(x){
  2685. return !!(x.tree && x.statusNodeType !== undefined);
  2686. }
  2687. /** Return true if dotted version string is equal or higher than requested version.
  2688. *
  2689. * See http://jsfiddle.net/mar10/FjSAN/
  2690. */
  2691. function isVersionAtLeast(dottedVersion, major, minor, patch){
  2692. var i, v, t,
  2693. verParts = $.map($.trim(dottedVersion).split("."), function(e){ return parseInt(e, 10); }),
  2694. testParts = $.map(Array.prototype.slice.call(arguments, 1), function(e){ return parseInt(e, 10); });
  2695. for( i = 0; i < testParts.length; i++ ){
  2696. v = verParts[i] || 0;
  2697. t = testParts[i] || 0;
  2698. if( v !== t ){
  2699. return ( v > t );
  2700. }
  2701. }
  2702. return true;
  2703. }
  2704. /** Return a wrapper that calls sub.methodName() and exposes
  2705. * this : tree
  2706. * this._local : tree.ext.EXTNAME
  2707. * this._super : base.methodName.call()
  2708. * this._superApply : base.methodName.apply()
  2709. */
  2710. function _makeVirtualFunction(methodName, tree, base, extension, extName){
  2711. // $.ui.fancytree.debug("_makeVirtualFunction", methodName, tree, base, extension, extName);
  2712. // if(rexTestSuper && !rexTestSuper.test(func)){
  2713. // // extension.methodName() doesn't call _super(), so no wrapper required
  2714. // return func;
  2715. // }
  2716. // Use an immediate function as closure
  2717. var proxy = (function(){
  2718. var prevFunc = tree[methodName], // org. tree method or prev. proxy
  2719. baseFunc = extension[methodName], //
  2720. _local = tree.ext[extName],
  2721. _super = function(){
  2722. return prevFunc.apply(tree, arguments);
  2723. },
  2724. _superApply = function(args){
  2725. return prevFunc.apply(tree, args);
  2726. };
  2727. // Return the wrapper function
  2728. return function(){
  2729. var prevLocal = tree._local,
  2730. prevSuper = tree._super,
  2731. prevSuperApply = tree._superApply;
  2732. try{
  2733. tree._local = _local;
  2734. tree._super = _super;
  2735. tree._superApply = _superApply;
  2736. return baseFunc.apply(tree, arguments);
  2737. }finally{
  2738. tree._local = prevLocal;
  2739. tree._super = prevSuper;
  2740. tree._superApply = prevSuperApply;
  2741. }
  2742. };
  2743. })(); // end of Immediate Function
  2744. return proxy;
  2745. }
  2746. /**
  2747. * Subclass `base` by creating proxy functions
  2748. */
  2749. function _subclassObject(tree, base, extension, extName){
  2750. // $.ui.fancytree.debug("_subclassObject", tree, base, extension, extName);
  2751. for(var attrName in extension){
  2752. if(typeof extension[attrName] === "function"){
  2753. if(typeof tree[attrName] === "function"){
  2754. // override existing method
  2755. tree[attrName] = _makeVirtualFunction(attrName, tree, base, extension, extName);
  2756. }else if(attrName.charAt(0) === "_"){
  2757. // Create private methods in tree.ext.EXTENSION namespace
  2758. tree.ext[extName][attrName] = _makeVirtualFunction(attrName, tree, base, extension, extName);
  2759. }else{
  2760. $.error("Could not override tree." + attrName + ". Use prefix '_' to create tree." + extName + "._" + attrName);
  2761. }
  2762. }else{
  2763. // Create member variables in tree.ext.EXTENSION namespace
  2764. if(attrName !== "options"){
  2765. tree.ext[extName][attrName] = extension[attrName];
  2766. }
  2767. }
  2768. }
  2769. }
  2770. function _getResolvedPromise(context, argArray){
  2771. if(context === undefined){
  2772. return $.Deferred(function(){this.resolve();}).promise();
  2773. }else{
  2774. return $.Deferred(function(){this.resolveWith(context, argArray);}).promise();
  2775. }
  2776. }
  2777. function _getRejectedPromise(context, argArray){
  2778. if(context === undefined){
  2779. return $.Deferred(function(){this.reject();}).promise();
  2780. }else{
  2781. return $.Deferred(function(){this.rejectWith(context, argArray);}).promise();
  2782. }
  2783. }
  2784. function _makeResolveFunc(deferred, context){
  2785. return function(){
  2786. deferred.resolveWith(context);
  2787. };
  2788. }
  2789. function _getElementDataAsDict($el){
  2790. // Evaluate 'data-NAME' attributes with special treatment for 'data-json'.
  2791. var d = $.extend({}, $el.data()),
  2792. json = d.json;
  2793. delete d.fancytree; // added to container by widget factory (old jQuery UI)
  2794. delete d.uiFancytree; // added to container by widget factory
  2795. if( json ) {
  2796. delete d.json;
  2797. // <li data-json='...'> is already returned as object (http://api.jquery.com/data/#data-html5)
  2798. d = $.extend(d, json);
  2799. }
  2800. return d;
  2801. }
  2802. function _escapeTooltip(s){
  2803. return ("" + s).replace(REX_TOOLTIP, function(s) {
  2804. return ENTITY_MAP[s];
  2805. });
  2806. }
  2807. // TODO: use currying
  2808. function _makeNodeTitleMatcher(s){
  2809. s = s.toLowerCase();
  2810. return function(node){
  2811. return node.title.toLowerCase().indexOf(s) >= 0;
  2812. };
  2813. }
  2814. function _makeNodeTitleStartMatcher(s){
  2815. var reMatch = new RegExp("^" + s, "i");
  2816. return function(node){
  2817. return reMatch.test(node.title);
  2818. };
  2819. }
  2820. /* *****************************************************************************
  2821. * FancytreeNode
  2822. */
  2823. /**
  2824. * Creates a new FancytreeNode
  2825. *
  2826. * @class FancytreeNode
  2827. * @classdesc A FancytreeNode represents the hierarchical data model and operations.
  2828. *
  2829. * @param {FancytreeNode} parent
  2830. * @param {NodeData} obj
  2831. *
  2832. * @property {Fancytree} tree The tree instance
  2833. * @property {FancytreeNode} parent The parent node
  2834. * @property {string} key Node id (must be unique inside the tree)
  2835. * @property {string} title Display name (may contain HTML)
  2836. * @property {object} data Contains all extra data that was passed on node creation
  2837. * @property {FancytreeNode[] | null | undefined} children Array of child nodes.<br>
  2838. * For lazy nodes, null or undefined means 'not yet loaded'. Use an empty array
  2839. * to define a node that has no children.
  2840. * @property {boolean} expanded Use isExpanded(), setExpanded() to access this property.
  2841. * @property {string} extraClasses Additional CSS classes, added to the node's `&lt;span>`.<br>
  2842. * Note: use `node.add/remove/toggleClass()` to modify.
  2843. * @property {boolean} folder Folder nodes have different default icons and click behavior.<br>
  2844. * Note: Also non-folders may have children.
  2845. * @property {string} statusNodeType null for standard nodes. Otherwise type of special system node: 'error', 'loading', 'nodata', or 'paging'.
  2846. * @property {boolean} lazy True if this node is loaded on demand, i.e. on first expansion.
  2847. * @property {boolean} selected Use isSelected(), setSelected() to access this property.
  2848. * @property {string} tooltip Alternative description used as hover popup
  2849. */
  2850. function FancytreeNode(parent, obj){
  2851. var i, l, name, cl;
  2852. this.parent = parent;
  2853. this.tree = parent.tree;
  2854. this.ul = null;
  2855. this.li = null; // <li id='key' ftnode=this> tag
  2856. this.statusNodeType = null; // if this is a temp. node to display the status of its parent
  2857. this._isLoading = false; // if this node itself is loading
  2858. this._error = null; // {message: '...'} if a load error occurred
  2859. this.data = {};
  2860. // TODO: merge this code with node.toDict()
  2861. // copy attributes from obj object
  2862. for(i=0, l=NODE_ATTRS.length; i<l; i++){
  2863. name = NODE_ATTRS[i];
  2864. this[name] = obj[name];
  2865. }
  2866. // unselectableIgnore and unselectableStatus imply unselectable
  2867. if( this.unselectableIgnore != null || this.unselectableStatus != null ) {
  2868. this.unselectable = true;
  2869. }
  2870. if( obj.hideCheckbox ) {
  2871. $.error("'hideCheckbox' node option was removed in v2.23.0: use 'checkbox: false'");
  2872. }
  2873. // node.data += obj.data
  2874. if(obj.data){
  2875. $.extend(this.data, obj.data);
  2876. }
  2877. // copy all other attributes to this.data.NAME
  2878. for(name in obj){
  2879. if(!NODE_ATTR_MAP[name] && !$.isFunction(obj[name]) && !NONE_NODE_DATA_MAP[name]){
  2880. // node.data.NAME = obj.NAME
  2881. this.data[name] = obj[name];
  2882. }
  2883. }
  2884. // Fix missing key
  2885. if( this.key == null ){ // test for null OR undefined
  2886. if( this.tree.options.defaultKey ) {
  2887. this.key = this.tree.options.defaultKey(this);
  2888. _assert(this.key, "defaultKey() must return a unique key");
  2889. } else {
  2890. this.key = "_" + (FT._nextNodeKey++);
  2891. }
  2892. } else {
  2893. this.key = "" + this.key; // Convert to string (#217)
  2894. }
  2895. // Fix tree.activeNode
  2896. // TODO: not elegant: we use obj.active as marker to set tree.activeNode
  2897. // when loading from a dictionary.
  2898. if(obj.active){
  2899. _assert(this.tree.activeNode === null, "only one active node allowed");
  2900. this.tree.activeNode = this;
  2901. }
  2902. if( obj.selected ){ // #186
  2903. this.tree.lastSelectedNode = this;
  2904. }
  2905. // TODO: handle obj.focus = true
  2906. // Create child nodes
  2907. cl = obj.children;
  2908. if( cl ){
  2909. if( cl.length ){
  2910. this._setChildren(cl);
  2911. } else {
  2912. // if an empty array was passed for a lazy node, keep it, in order to mark it 'loaded'
  2913. this.children = this.lazy ? [] : null;
  2914. }
  2915. } else {
  2916. this.children = null;
  2917. }
  2918. // Add to key/ref map (except for root node)
  2919. // if( parent ) {
  2920. this.tree._callHook("treeRegisterNode", this.tree, true, this);
  2921. // }
  2922. }
  2923. FancytreeNode.prototype = /** @lends FancytreeNode# */{
  2924. /* Return the direct child FancytreeNode with a given key, index. */
  2925. _findDirectChild: function(ptr){
  2926. var i, l,
  2927. cl = this.children;
  2928. if(cl){
  2929. if(typeof ptr === "string"){
  2930. for(i=0, l=cl.length; i<l; i++){
  2931. if(cl[i].key === ptr){
  2932. return cl[i];
  2933. }
  2934. }
  2935. }else if(typeof ptr === "number"){
  2936. return this.children[ptr];
  2937. }else if(ptr.parent === this){
  2938. return ptr;
  2939. }
  2940. }
  2941. return null;
  2942. },
  2943. // TODO: activate()
  2944. // TODO: activateSilently()
  2945. /* Internal helper called in recursive addChildren sequence.*/
  2946. _setChildren: function(children){
  2947. _assert(children && (!this.children || this.children.length === 0), "only init supported");
  2948. this.children = [];
  2949. for(var i=0, l=children.length; i<l; i++){
  2950. this.children.push(new FancytreeNode(this, children[i]));
  2951. }
  2952. },
  2953. /**
  2954. * Append (or insert) a list of child nodes.
  2955. *
  2956. * @param {NodeData[]} children array of child node definitions (also single child accepted)
  2957. * @param {FancytreeNode | string | Integer} [insertBefore] child node (or key or index of such).
  2958. * If omitted, the new children are appended.
  2959. * @returns {FancytreeNode} first child added
  2960. *
  2961. * @see FancytreeNode#applyPatch
  2962. */
  2963. addChildren: function(children, insertBefore){
  2964. var i, l, pos,
  2965. origFirstChild = this.getFirstChild(),
  2966. origLastChild = this.getLastChild(),
  2967. firstNode = null,
  2968. nodeList = [];
  2969. if($.isPlainObject(children) ){
  2970. children = [children];
  2971. }
  2972. if(!this.children){
  2973. this.children = [];
  2974. }
  2975. for(i=0, l=children.length; i<l; i++){
  2976. nodeList.push(new FancytreeNode(this, children[i]));
  2977. }
  2978. firstNode = nodeList[0];
  2979. if(insertBefore == null){
  2980. this.children = this.children.concat(nodeList);
  2981. }else{
  2982. insertBefore = this._findDirectChild(insertBefore);
  2983. pos = $.inArray(insertBefore, this.children);
  2984. _assert(pos >= 0, "insertBefore must be an existing child");
  2985. // insert nodeList after children[pos]
  2986. this.children.splice.apply(this.children, [pos, 0].concat(nodeList));
  2987. }
  2988. if ( origFirstChild && !insertBefore ) {
  2989. // #708: Fast path -- don't render every child of root, just the new ones!
  2990. // #723, #729: but only if it's appended to an existing child list
  2991. for(i=0, l=nodeList.length; i<l; i++) {
  2992. nodeList[i].render(); // New nodes were never rendered before
  2993. }
  2994. // Adjust classes where status may have changed
  2995. // Has a first child
  2996. if (origFirstChild !== this.getFirstChild()) {
  2997. // Different first child -- recompute classes
  2998. origFirstChild.renderStatus();
  2999. }
  3000. if (origLastChild !== this.getLastChild()) {
  3001. // Different last child -- recompute classes
  3002. origLastChild.renderStatus();
  3003. }
  3004. } else if( !this.parent || this.parent.ul || this.tr ){
  3005. // render if the parent was rendered (or this is a root node)
  3006. this.render();
  3007. }
  3008. if( this.tree.options.selectMode === 3 ){
  3009. this.fixSelection3FromEndNodes();
  3010. }
  3011. this.triggerModifyChild("add", nodeList.length === 1 ? nodeList[0] : null);
  3012. return firstNode;
  3013. },
  3014. /**
  3015. * Add class to node's span tag and to .extraClasses.
  3016. *
  3017. * @param {string} className class name
  3018. *
  3019. * @since 2.17
  3020. */
  3021. addClass: function(className){
  3022. return this.toggleClass(className, true);
  3023. },
  3024. /**
  3025. * Append or prepend a node, or append a child node.
  3026. *
  3027. * This a convenience function that calls addChildren()
  3028. *
  3029. * @param {NodeData} node node definition
  3030. * @param {string} [mode=child] 'before', 'after', 'firstChild', or 'child' ('over' is a synonym for 'child')
  3031. * @returns {FancytreeNode} new node
  3032. */
  3033. addNode: function(node, mode){
  3034. if(mode === undefined || mode === "over"){
  3035. mode = "child";
  3036. }
  3037. switch(mode){
  3038. case "after":
  3039. return this.getParent().addChildren(node, this.getNextSibling());
  3040. case "before":
  3041. return this.getParent().addChildren(node, this);
  3042. case "firstChild":
  3043. // Insert before the first child if any
  3044. var insertBefore = (this.children ? this.children[0] : null);
  3045. return this.addChildren(node, insertBefore);
  3046. case "child":
  3047. case "over":
  3048. return this.addChildren(node);
  3049. }
  3050. _assert(false, "Invalid mode: " + mode);
  3051. },
  3052. /**Add child status nodes that indicate 'More...', etc.
  3053. *
  3054. * This also maintains the node's `partload` property.
  3055. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  3056. * @param {string} [mode='child'] 'child'|firstChild'
  3057. * @since 2.15
  3058. */
  3059. addPagingNode: function(node, mode){
  3060. var i, n;
  3061. mode = mode || "child";
  3062. if( node === false ) {
  3063. for(i=this.children.length-1; i >= 0; i--) {
  3064. n = this.children[i];
  3065. if( n.statusNodeType === "paging" ) {
  3066. this.removeChild(n);
  3067. }
  3068. }
  3069. this.partload = false;
  3070. return;
  3071. }
  3072. node = $.extend({
  3073. title: this.tree.options.strings.moreData,
  3074. statusNodeType: "paging",
  3075. icon: false
  3076. }, node);
  3077. this.partload = true;
  3078. return this.addNode(node, mode);
  3079. },
  3080. /**
  3081. * Append new node after this.
  3082. *
  3083. * This a convenience function that calls addNode(node, 'after')
  3084. *
  3085. * @param {NodeData} node node definition
  3086. * @returns {FancytreeNode} new node
  3087. */
  3088. appendSibling: function(node){
  3089. return this.addNode(node, "after");
  3090. },
  3091. /**
  3092. * Modify existing child nodes.
  3093. *
  3094. * @param {NodePatch} patch
  3095. * @returns {$.Promise}
  3096. * @see FancytreeNode#addChildren
  3097. */
  3098. applyPatch: function(patch) {
  3099. // patch [key, null] means 'remove'
  3100. if(patch === null){
  3101. this.remove();
  3102. return _getResolvedPromise(this);
  3103. }
  3104. // TODO: make sure that root node is not collapsed or modified
  3105. // copy (most) attributes to node.ATTR or node.data.ATTR
  3106. var name, promise, v,
  3107. IGNORE_MAP = { children: true, expanded: true, parent: true }; // TODO: should be global
  3108. for(name in patch){
  3109. v = patch[name];
  3110. if( !IGNORE_MAP[name] && !$.isFunction(v)){
  3111. if(NODE_ATTR_MAP[name]){
  3112. this[name] = v;
  3113. }else{
  3114. this.data[name] = v;
  3115. }
  3116. }
  3117. }
  3118. // Remove and/or create children
  3119. if(patch.hasOwnProperty("children")){
  3120. this.removeChildren();
  3121. if(patch.children){ // only if not null and not empty list
  3122. // TODO: addChildren instead?
  3123. this._setChildren(patch.children);
  3124. }
  3125. // TODO: how can we APPEND or INSERT child nodes?
  3126. }
  3127. if(this.isVisible()){
  3128. this.renderTitle();
  3129. this.renderStatus();
  3130. }
  3131. // Expand collapse (final step, since this may be async)
  3132. if(patch.hasOwnProperty("expanded")){
  3133. promise = this.setExpanded(patch.expanded);
  3134. }else{
  3135. promise = _getResolvedPromise(this);
  3136. }
  3137. return promise;
  3138. },
  3139. /** Collapse all sibling nodes.
  3140. * @returns {$.Promise}
  3141. */
  3142. collapseSiblings: function() {
  3143. return this.tree._callHook("nodeCollapseSiblings", this);
  3144. },
  3145. /** Copy this node as sibling or child of `node`.
  3146. *
  3147. * @param {FancytreeNode} node source node
  3148. * @param {string} [mode=child] 'before' | 'after' | 'child'
  3149. * @param {Function} [map] callback function(NodeData) that could modify the new node
  3150. * @returns {FancytreeNode} new
  3151. */
  3152. copyTo: function(node, mode, map) {
  3153. return node.addNode(this.toDict(true, map), mode);
  3154. },
  3155. /** Count direct and indirect children.
  3156. *
  3157. * @param {boolean} [deep=true] pass 'false' to only count direct children
  3158. * @returns {int} number of child nodes
  3159. */
  3160. countChildren: function(deep) {
  3161. var cl = this.children, i, l, n;
  3162. if( !cl ){
  3163. return 0;
  3164. }
  3165. n = cl.length;
  3166. if(deep !== false){
  3167. for(i=0, l=n; i<l; i++){
  3168. n += cl[i].countChildren();
  3169. }
  3170. }
  3171. return n;
  3172. },
  3173. // TODO: deactivate()
  3174. /** Write to browser console if debugLevel >= 2 (prepending node info)
  3175. *
  3176. * @param {*} msg string or object or array of such
  3177. */
  3178. debug: function(msg){
  3179. if( this.tree.options.debugLevel >= 2 ) {
  3180. Array.prototype.unshift.call(arguments, this.toString());
  3181. consoleApply("log", arguments);
  3182. }
  3183. },
  3184. /** Deprecated.
  3185. * @deprecated since 2014-02-16. Use resetLazy() instead.
  3186. */
  3187. discard: function(){
  3188. this.warn("FancytreeNode.discard() is deprecated since 2014-02-16. Use .resetLazy() instead.");
  3189. return this.resetLazy();
  3190. },
  3191. /** Remove DOM elements for all descendents. May be called on .collapse event
  3192. * to keep the DOM small.
  3193. * @param {boolean} [includeSelf=false]
  3194. */
  3195. discardMarkup: function(includeSelf){
  3196. var fn = includeSelf ? "nodeRemoveMarkup" : "nodeRemoveChildMarkup";
  3197. this.tree._callHook(fn, this);
  3198. },
  3199. /**Find all nodes that match condition (excluding self).
  3200. *
  3201. * @param {string | function(node)} match title string to search for, or a
  3202. * callback function that returns `true` if a node is matched.
  3203. * @returns {FancytreeNode[]} array of nodes (may be empty)
  3204. */
  3205. findAll: function(match) {
  3206. match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
  3207. var res = [];
  3208. this.visit(function(n){
  3209. if(match(n)){
  3210. res.push(n);
  3211. }
  3212. });
  3213. return res;
  3214. },
  3215. /**Find first node that matches condition (excluding self).
  3216. *
  3217. * @param {string | function(node)} match title string to search for, or a
  3218. * callback function that returns `true` if a node is matched.
  3219. * @returns {FancytreeNode} matching node or null
  3220. * @see FancytreeNode#findAll
  3221. */
  3222. findFirst: function(match) {
  3223. match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
  3224. var res = null;
  3225. this.visit(function(n){
  3226. if(match(n)){
  3227. res = n;
  3228. return false;
  3229. }
  3230. });
  3231. return res;
  3232. },
  3233. /* Apply selection state (internal use only) */
  3234. _changeSelectStatusAttrs: function(state) {
  3235. var changed = false,
  3236. opts = this.tree.options,
  3237. unselectable = FT.evalOption("unselectable", this, this, opts, false),
  3238. unselectableStatus = FT.evalOption("unselectableStatus", this, this, opts, undefined);
  3239. if( unselectable && unselectableStatus != null ) {
  3240. state = unselectableStatus;
  3241. }
  3242. switch(state){
  3243. case false:
  3244. changed = ( this.selected || this.partsel );
  3245. this.selected = false;
  3246. this.partsel = false;
  3247. break;
  3248. case true:
  3249. changed = ( !this.selected || !this.partsel );
  3250. this.selected = true;
  3251. this.partsel = true;
  3252. break;
  3253. case undefined:
  3254. changed = ( this.selected || !this.partsel );
  3255. this.selected = false;
  3256. this.partsel = true;
  3257. break;
  3258. default:
  3259. _assert(false, "invalid state: " + state);
  3260. }
  3261. // this.debug("fixSelection3AfterLoad() _changeSelectStatusAttrs()", state, changed);
  3262. if( changed ){
  3263. this.renderStatus();
  3264. }
  3265. return changed;
  3266. },
  3267. /**
  3268. * Fix selection status, after this node was (de)selected in multi-hier mode.
  3269. * This includes (de)selecting all children.
  3270. */
  3271. fixSelection3AfterClick: function(callOpts) {
  3272. var flag = this.isSelected();
  3273. // this.debug("fixSelection3AfterClick()");
  3274. this.visit(function(node){
  3275. node._changeSelectStatusAttrs(flag);
  3276. });
  3277. this.fixSelection3FromEndNodes(callOpts);
  3278. },
  3279. /**
  3280. * Fix selection status for multi-hier mode.
  3281. * Only end-nodes are considered to update the descendants branch and parents.
  3282. * Should be called after this node has loaded new children or after
  3283. * children have been modified using the API.
  3284. */
  3285. fixSelection3FromEndNodes: function(callOpts) {
  3286. var opts = this.tree.options;
  3287. // this.debug("fixSelection3FromEndNodes()");
  3288. _assert(opts.selectMode === 3, "expected selectMode 3");
  3289. // Visit all end nodes and adjust their parent's `selected` and `partsel`
  3290. // attributes. Return selection state true, false, or undefined.
  3291. function _walk(node){
  3292. var i, l, child, s, state, allSelected, someSelected, unselIgnore, unselState,
  3293. children = node.children;
  3294. if( children && children.length ){
  3295. // check all children recursively
  3296. allSelected = true;
  3297. someSelected = false;
  3298. for( i=0, l=children.length; i<l; i++ ){
  3299. child = children[i];
  3300. // the selection state of a node is not relevant; we need the end-nodes
  3301. s = _walk(child);
  3302. // if( !child.unselectableIgnore ) {
  3303. unselIgnore = FT.evalOption("unselectableIgnore", child, child, opts, false);
  3304. if( !unselIgnore ) {
  3305. if( s !== false ) {
  3306. someSelected = true;
  3307. }
  3308. if( s !== true ) {
  3309. allSelected = false;
  3310. }
  3311. }
  3312. }
  3313. state = allSelected ? true : (someSelected ? undefined : false);
  3314. }else{
  3315. // This is an end-node: simply report the status
  3316. unselState = FT.evalOption("unselectableStatus", node, node, opts, undefined);
  3317. state = ( unselState == null ) ? !!node.selected : !!unselState;
  3318. }
  3319. node._changeSelectStatusAttrs(state);
  3320. return state;
  3321. }
  3322. _walk(this);
  3323. // Update parent's state
  3324. this.visitParents(function(node){
  3325. var i, l, child, state, unselIgnore, unselState,
  3326. children = node.children,
  3327. allSelected = true,
  3328. someSelected = false;
  3329. for( i=0, l=children.length; i<l; i++ ){
  3330. child = children[i];
  3331. unselIgnore = FT.evalOption("unselectableIgnore", child, child, opts, false);
  3332. if( !unselIgnore ) {
  3333. unselState = FT.evalOption("unselectableStatus", child, child, opts, undefined);
  3334. state = ( unselState == null ) ? !!child.selected : !!unselState;
  3335. // When fixing the parents, we trust the sibling status (i.e.
  3336. // we don't recurse)
  3337. if( state || child.partsel ) {
  3338. someSelected = true;
  3339. }
  3340. if( !state ) {
  3341. allSelected = false;
  3342. }
  3343. }
  3344. }
  3345. state = allSelected ? true : (someSelected ? undefined : false);
  3346. node._changeSelectStatusAttrs(state);
  3347. });
  3348. },
  3349. // TODO: focus()
  3350. /**
  3351. * Update node data. If dict contains 'children', then also replace
  3352. * the hole sub tree.
  3353. * @param {NodeData} dict
  3354. *
  3355. * @see FancytreeNode#addChildren
  3356. * @see FancytreeNode#applyPatch
  3357. */
  3358. fromDict: function(dict) {
  3359. // copy all other attributes to this.data.xxx
  3360. for(var name in dict){
  3361. if(NODE_ATTR_MAP[name]){
  3362. // node.NAME = dict.NAME
  3363. this[name] = dict[name];
  3364. }else if(name === "data"){
  3365. // node.data += dict.data
  3366. $.extend(this.data, dict.data);
  3367. }else if(!$.isFunction(dict[name]) && !NONE_NODE_DATA_MAP[name]){
  3368. // node.data.NAME = dict.NAME
  3369. this.data[name] = dict[name];
  3370. }
  3371. }
  3372. if(dict.children){
  3373. // recursively set children and render
  3374. this.removeChildren();
  3375. this.addChildren(dict.children);
  3376. }
  3377. this.renderTitle();
  3378. /*
  3379. var children = dict.children;
  3380. if(children === undefined){
  3381. this.data = $.extend(this.data, dict);
  3382. this.render();
  3383. return;
  3384. }
  3385. dict = $.extend({}, dict);
  3386. dict.children = undefined;
  3387. this.data = $.extend(this.data, dict);
  3388. this.removeChildren();
  3389. this.addChild(children);
  3390. */
  3391. },
  3392. /** Return the list of child nodes (undefined for unexpanded lazy nodes).
  3393. * @returns {FancytreeNode[] | undefined}
  3394. */
  3395. getChildren: function() {
  3396. if(this.hasChildren() === undefined){ // TODO: only required for lazy nodes?
  3397. return undefined; // Lazy node: unloaded, currently loading, or load error
  3398. }
  3399. return this.children;
  3400. },
  3401. /** Return the first child node or null.
  3402. * @returns {FancytreeNode | null}
  3403. */
  3404. getFirstChild: function() {
  3405. return this.children ? this.children[0] : null;
  3406. },
  3407. /** Return the 0-based child index.
  3408. * @returns {int}
  3409. */
  3410. getIndex: function() {
  3411. // return this.parent.children.indexOf(this);
  3412. return $.inArray(this, this.parent.children); // indexOf doesn't work in IE7
  3413. },
  3414. /** Return the hierarchical child index (1-based, e.g. '3.2.4').
  3415. * @param {string} [separator="."]
  3416. * @param {int} [digits=1]
  3417. * @returns {string}
  3418. */
  3419. getIndexHier: function(separator, digits) {
  3420. separator = separator || ".";
  3421. var s,
  3422. res = [];
  3423. $.each(this.getParentList(false, true), function(i, o){
  3424. s = "" + (o.getIndex() + 1);
  3425. if( digits ){
  3426. // prepend leading zeroes
  3427. s = ("0000000" + s).substr(-digits);
  3428. }
  3429. res.push(s);
  3430. });
  3431. return res.join(separator);
  3432. },
  3433. /** Return the parent keys separated by options.keyPathSeparator, e.g. "id_1/id_17/id_32".
  3434. * @param {boolean} [excludeSelf=false]
  3435. * @returns {string}
  3436. */
  3437. getKeyPath: function(excludeSelf) {
  3438. var path = [],
  3439. sep = this.tree.options.keyPathSeparator;
  3440. this.visitParents(function(n){
  3441. if(n.parent){
  3442. path.unshift(n.key);
  3443. }
  3444. }, !excludeSelf);
  3445. return sep + path.join(sep);
  3446. },
  3447. /** Return the last child of this node or null.
  3448. * @returns {FancytreeNode | null}
  3449. */
  3450. getLastChild: function() {
  3451. return this.children ? this.children[this.children.length - 1] : null;
  3452. },
  3453. /** Return node depth. 0: System root node, 1: visible top-level node, 2: first sub-level, ... .
  3454. * @returns {int}
  3455. */
  3456. getLevel: function() {
  3457. var level = 0,
  3458. dtn = this.parent;
  3459. while( dtn ) {
  3460. level++;
  3461. dtn = dtn.parent;
  3462. }
  3463. return level;
  3464. },
  3465. /** Return the successor node (under the same parent) or null.
  3466. * @returns {FancytreeNode | null}
  3467. */
  3468. getNextSibling: function() {
  3469. // TODO: use indexOf, if available: (not in IE6)
  3470. if( this.parent ){
  3471. var i, l,
  3472. ac = this.parent.children;
  3473. for(i=0, l=ac.length-1; i<l; i++){ // up to length-2, so next(last) = null
  3474. if( ac[i] === this ){
  3475. return ac[i+1];
  3476. }
  3477. }
  3478. }
  3479. return null;
  3480. },
  3481. /** Return the parent node (null for the system root node).
  3482. * @returns {FancytreeNode | null}
  3483. */
  3484. getParent: function() {
  3485. // TODO: return null for top-level nodes?
  3486. return this.parent;
  3487. },
  3488. /** Return an array of all parent nodes (top-down).
  3489. * @param {boolean} [includeRoot=false] Include the invisible system root node.
  3490. * @param {boolean} [includeSelf=false] Include the node itself.
  3491. * @returns {FancytreeNode[]}
  3492. */
  3493. getParentList: function(includeRoot, includeSelf) {
  3494. var l = [],
  3495. dtn = includeSelf ? this : this.parent;
  3496. while( dtn ) {
  3497. if( includeRoot || dtn.parent ){
  3498. l.unshift(dtn);
  3499. }
  3500. dtn = dtn.parent;
  3501. }
  3502. return l;
  3503. },
  3504. /** Return the predecessor node (under the same parent) or null.
  3505. * @returns {FancytreeNode | null}
  3506. */
  3507. getPrevSibling: function() {
  3508. if( this.parent ){
  3509. var i, l,
  3510. ac = this.parent.children;
  3511. for(i=1, l=ac.length; i<l; i++){ // start with 1, so prev(first) = null
  3512. if( ac[i] === this ){
  3513. return ac[i-1];
  3514. }
  3515. }
  3516. }
  3517. return null;
  3518. },
  3519. /**
  3520. * Return an array of selected descendant nodes.
  3521. * @param {boolean} [stopOnParents=false] only return the topmost selected
  3522. * node (useful with selectMode 3)
  3523. * @returns {FancytreeNode[]}
  3524. */
  3525. getSelectedNodes: function(stopOnParents) {
  3526. var nodeList = [];
  3527. this.visit(function(node){
  3528. if( node.selected ) {
  3529. nodeList.push(node);
  3530. if( stopOnParents === true ){
  3531. return "skip"; // stop processing this branch
  3532. }
  3533. }
  3534. });
  3535. return nodeList;
  3536. },
  3537. /** Return true if node has children. Return undefined if not sure, i.e. the node is lazy and not yet loaded).
  3538. * @returns {boolean | undefined}
  3539. */
  3540. hasChildren: function() {
  3541. if(this.lazy){
  3542. if(this.children == null ){
  3543. // null or undefined: Not yet loaded
  3544. return undefined;
  3545. }else if(this.children.length === 0){
  3546. // Loaded, but response was empty
  3547. return false;
  3548. }else if(this.children.length === 1 && this.children[0].isStatusNode() ){
  3549. // Currently loading or load error
  3550. return undefined;
  3551. }
  3552. return true;
  3553. }
  3554. return !!( this.children && this.children.length );
  3555. },
  3556. /** Return true if node has keyboard focus.
  3557. * @returns {boolean}
  3558. */
  3559. hasFocus: function() {
  3560. return (this.tree.hasFocus() && this.tree.focusNode === this);
  3561. },
  3562. /** Write to browser console if debugLevel >= 1 (prepending node info)
  3563. *
  3564. * @param {*} msg string or object or array of such
  3565. */
  3566. info: function(msg){
  3567. if( this.tree.options.debugLevel >= 1 ) {
  3568. Array.prototype.unshift.call(arguments, this.toString());
  3569. consoleApply("info", arguments);
  3570. }
  3571. },
  3572. /** Return true if node is active (see also FancytreeNode#isSelected).
  3573. * @returns {boolean}
  3574. */
  3575. isActive: function() {
  3576. return (this.tree.activeNode === this);
  3577. },
  3578. /** Return true if node is a direct child of otherNode.
  3579. * @param {FancytreeNode} otherNode
  3580. * @returns {boolean}
  3581. */
  3582. isChildOf: function(otherNode) {
  3583. return (this.parent && this.parent === otherNode);
  3584. },
  3585. /** Return true, if node is a direct or indirect sub node of otherNode.
  3586. * @param {FancytreeNode} otherNode
  3587. * @returns {boolean}
  3588. */
  3589. isDescendantOf: function(otherNode) {
  3590. if(!otherNode || otherNode.tree !== this.tree){
  3591. return false;
  3592. }
  3593. var p = this.parent;
  3594. while( p ) {
  3595. if( p === otherNode ){
  3596. return true;
  3597. }
  3598. if( p === p.parent ) { $.error("Recursive parent link: " + p); }
  3599. p = p.parent;
  3600. }
  3601. return false;
  3602. },
  3603. /** Return true if node is expanded.
  3604. * @returns {boolean}
  3605. */
  3606. isExpanded: function() {
  3607. return !!this.expanded;
  3608. },
  3609. /** Return true if node is the first node of its parent's children.
  3610. * @returns {boolean}
  3611. */
  3612. isFirstSibling: function() {
  3613. var p = this.parent;
  3614. return !p || p.children[0] === this;
  3615. },
  3616. /** Return true if node is a folder, i.e. has the node.folder attribute set.
  3617. * @returns {boolean}
  3618. */
  3619. isFolder: function() {
  3620. return !!this.folder;
  3621. },
  3622. /** Return true if node is the last node of its parent's children.
  3623. * @returns {boolean}
  3624. */
  3625. isLastSibling: function() {
  3626. var p = this.parent;
  3627. return !p || p.children[p.children.length-1] === this;
  3628. },
  3629. /** Return true if node is lazy (even if data was already loaded)
  3630. * @returns {boolean}
  3631. */
  3632. isLazy: function() {
  3633. return !!this.lazy;
  3634. },
  3635. /** Return true if node is lazy and loaded. For non-lazy nodes always return true.
  3636. * @returns {boolean}
  3637. */
  3638. isLoaded: function() {
  3639. return !this.lazy || this.hasChildren() !== undefined; // Also checks if the only child is a status node
  3640. },
  3641. /** Return true if children are currently beeing loaded, i.e. a Ajax request is pending.
  3642. * @returns {boolean}
  3643. */
  3644. isLoading: function() {
  3645. return !!this._isLoading;
  3646. },
  3647. /*
  3648. * @deprecated since v2.4.0: Use isRootNode() instead
  3649. */
  3650. isRoot: function() {
  3651. return this.isRootNode();
  3652. },
  3653. /** Return true if node is partially selected (tri-state).
  3654. * @returns {boolean}
  3655. * @since 2.23
  3656. */
  3657. isPartsel: function() {
  3658. return !this.selected && !!this.partsel;
  3659. },
  3660. /** (experimental) Return true if this is partially loaded.
  3661. * @returns {boolean}
  3662. * @since 2.15
  3663. */
  3664. isPartload: function() {
  3665. return !!this.partload;
  3666. },
  3667. /** Return true if this is the (invisible) system root node.
  3668. * @returns {boolean}
  3669. * @since 2.4
  3670. */
  3671. isRootNode: function() {
  3672. return (this.tree.rootNode === this);
  3673. },
  3674. /** Return true if node is selected, i.e. has a checkmark set (see also FancytreeNode#isActive).
  3675. * @returns {boolean}
  3676. */
  3677. isSelected: function() {
  3678. return !!this.selected;
  3679. },
  3680. /** Return true if this node is a temporarily generated system node like
  3681. * 'loading', 'paging', or 'error' (node.statusNodeType contains the type).
  3682. * @returns {boolean}
  3683. */
  3684. isStatusNode: function() {
  3685. return !!this.statusNodeType;
  3686. },
  3687. /** Return true if this node is a status node of type 'paging'.
  3688. * @returns {boolean}
  3689. * @since 2.15
  3690. */
  3691. isPagingNode: function() {
  3692. return this.statusNodeType === "paging";
  3693. },
  3694. /** Return true if this a top level node, i.e. a direct child of the (invisible) system root node.
  3695. * @returns {boolean}
  3696. * @since 2.4
  3697. */
  3698. isTopLevel: function() {
  3699. return (this.tree.rootNode === this.parent);
  3700. },
  3701. /** Return true if node is lazy and not yet loaded. For non-lazy nodes always return false.
  3702. * @returns {boolean}
  3703. */
  3704. isUndefined: function() {
  3705. return this.hasChildren() === undefined; // also checks if the only child is a status node
  3706. },
  3707. /** Return true if all parent nodes are expanded. Note: this does not check
  3708. * whether the node is scrolled into the visible part of the screen.
  3709. * @returns {boolean}
  3710. */
  3711. isVisible: function() {
  3712. var i, l,
  3713. parents = this.getParentList(false, false);
  3714. for(i=0, l=parents.length; i<l; i++){
  3715. if( ! parents[i].expanded ){ return false; }
  3716. }
  3717. return true;
  3718. },
  3719. /** Deprecated.
  3720. * @deprecated since 2014-02-16: use load() instead.
  3721. */
  3722. lazyLoad: function(discard) {
  3723. this.warn("FancytreeNode.lazyLoad() is deprecated since 2014-02-16. Use .load() instead.");
  3724. return this.load(discard);
  3725. },
  3726. /**
  3727. * Load all children of a lazy node if neccessary. The <i>expanded</i> state is maintained.
  3728. * @param {boolean} [forceReload=false] Pass true to discard any existing nodes before. Otherwise this method does nothing if the node was already loaded.
  3729. * @returns {$.Promise}
  3730. */
  3731. load: function(forceReload) {
  3732. var res, source,
  3733. that = this,
  3734. wasExpanded = this.isExpanded();
  3735. _assert( this.isLazy(), "load() requires a lazy node" );
  3736. // _assert( forceReload || this.isUndefined(), "Pass forceReload=true to re-load a lazy node" );
  3737. if( !forceReload && !this.isUndefined() ) {
  3738. return _getResolvedPromise(this);
  3739. }
  3740. if( this.isLoaded() ){
  3741. this.resetLazy(); // also collapses
  3742. }
  3743. // This method is also called by setExpanded() and loadKeyPath(), so we
  3744. // have to avoid recursion.
  3745. source = this.tree._triggerNodeEvent("lazyLoad", this);
  3746. if( source === false ) { // #69
  3747. return _getResolvedPromise(this);
  3748. }
  3749. _assert(typeof source !== "boolean", "lazyLoad event must return source in data.result");
  3750. res = this.tree._callHook("nodeLoadChildren", this, source);
  3751. if( wasExpanded ) {
  3752. this.expanded = true;
  3753. res.always(function(){
  3754. that.render();
  3755. });
  3756. } else {
  3757. res.always(function(){
  3758. that.renderStatus(); // fix expander icon to 'loaded'
  3759. });
  3760. }
  3761. return res;
  3762. },
  3763. /** Expand all parents and optionally scroll into visible area as neccessary.
  3764. * Promise is resolved, when lazy loading and animations are done.
  3765. * @param {object} [opts] passed to `setExpanded()`.
  3766. * Defaults to {noAnimation: false, noEvents: false, scrollIntoView: true}
  3767. * @returns {$.Promise}
  3768. */
  3769. makeVisible: function(opts) {
  3770. var i,
  3771. that = this,
  3772. deferreds = [],
  3773. dfd = new $.Deferred(),
  3774. parents = this.getParentList(false, false),
  3775. len = parents.length,
  3776. effects = !(opts && opts.noAnimation === true),
  3777. scroll = !(opts && opts.scrollIntoView === false);
  3778. // Expand bottom-up, so only the top node is animated
  3779. for(i = len - 1; i >= 0; i--){
  3780. // that.debug("pushexpand" + parents[i]);
  3781. deferreds.push(parents[i].setExpanded(true, opts));
  3782. }
  3783. $.when.apply($, deferreds).done(function(){
  3784. // All expands have finished
  3785. // that.debug("expand DONE", scroll);
  3786. if( scroll ){
  3787. that.scrollIntoView(effects).done(function(){
  3788. // that.debug("scroll DONE");
  3789. dfd.resolve();
  3790. });
  3791. } else {
  3792. dfd.resolve();
  3793. }
  3794. });
  3795. return dfd.promise();
  3796. },
  3797. /** Move this node to targetNode.
  3798. * @param {FancytreeNode} targetNode
  3799. * @param {string} mode <pre>
  3800. * 'child': append this node as last child of targetNode.
  3801. * This is the default. To be compatble with the D'n'd
  3802. * hitMode, we also accept 'over'.
  3803. * 'firstChild': add this node as first child of targetNode.
  3804. * 'before': add this node as sibling before targetNode.
  3805. * 'after': add this node as sibling after targetNode.</pre>
  3806. * @param {function} [map] optional callback(FancytreeNode) to allow modifcations
  3807. */
  3808. moveTo: function(targetNode, mode, map) {
  3809. if(mode === undefined || mode === "over"){
  3810. mode = "child";
  3811. } else if ( mode === "firstChild" ) {
  3812. if( targetNode.children && targetNode.children.length ) {
  3813. mode = "before";
  3814. targetNode = targetNode.children[0];
  3815. } else {
  3816. mode = "child";
  3817. }
  3818. }
  3819. var pos,
  3820. prevParent = this.parent,
  3821. targetParent = (mode === "child") ? targetNode : targetNode.parent;
  3822. if(this === targetNode){
  3823. return;
  3824. }else if( !this.parent ){
  3825. $.error("Cannot move system root");
  3826. }else if( targetParent.isDescendantOf(this) ){
  3827. $.error("Cannot move a node to its own descendant");
  3828. }
  3829. if( targetParent !== prevParent ) {
  3830. prevParent.triggerModifyChild("remove", this);
  3831. }
  3832. // Unlink this node from current parent
  3833. if( this.parent.children.length === 1 ) {
  3834. if( this.parent === targetParent ){
  3835. return; // #258
  3836. }
  3837. this.parent.children = this.parent.lazy ? [] : null;
  3838. this.parent.expanded = false;
  3839. } else {
  3840. pos = $.inArray(this, this.parent.children);
  3841. _assert(pos >= 0, "invalid source parent");
  3842. this.parent.children.splice(pos, 1);
  3843. }
  3844. // Remove from source DOM parent
  3845. // if(this.parent.ul){
  3846. // this.parent.ul.removeChild(this.li);
  3847. // }
  3848. // Insert this node to target parent's child list
  3849. this.parent = targetParent;
  3850. if( targetParent.hasChildren() ) {
  3851. switch(mode) {
  3852. case "child":
  3853. // Append to existing target children
  3854. targetParent.children.push(this);
  3855. break;
  3856. case "before":
  3857. // Insert this node before target node
  3858. pos = $.inArray(targetNode, targetParent.children);
  3859. _assert(pos >= 0, "invalid target parent");
  3860. targetParent.children.splice(pos, 0, this);
  3861. break;
  3862. case "after":
  3863. // Insert this node after target node
  3864. pos = $.inArray(targetNode, targetParent.children);
  3865. _assert(pos >= 0, "invalid target parent");
  3866. targetParent.children.splice(pos+1, 0, this);
  3867. break;
  3868. default:
  3869. $.error("Invalid mode " + mode);
  3870. }
  3871. } else {
  3872. targetParent.children = [ this ];
  3873. }
  3874. // Parent has no <ul> tag yet:
  3875. // if( !targetParent.ul ) {
  3876. // // This is the parent's first child: create UL tag
  3877. // // (Hidden, because it will be
  3878. // targetParent.ul = document.createElement("ul");
  3879. // targetParent.ul.style.display = "none";
  3880. // targetParent.li.appendChild(targetParent.ul);
  3881. // }
  3882. // // Issue 319: Add to target DOM parent (only if node was already rendered(expanded))
  3883. // if(this.li){
  3884. // targetParent.ul.appendChild(this.li);
  3885. // }^
  3886. // Let caller modify the nodes
  3887. if( map ){
  3888. targetNode.visit(map, true);
  3889. }
  3890. if( targetParent === prevParent ) {
  3891. targetParent.triggerModifyChild("move", this);
  3892. } else {
  3893. // prevParent.triggerModifyChild("remove", this);
  3894. targetParent.triggerModifyChild("add", this);
  3895. }
  3896. // Handle cross-tree moves
  3897. if( this.tree !== targetNode.tree ) {
  3898. // Fix node.tree for all source nodes
  3899. // _assert(false, "Cross-tree move is not yet implemented.");
  3900. this.warn("Cross-tree moveTo is experimantal!");
  3901. this.visit(function(n){
  3902. // TODO: fix selection state and activation, ...
  3903. n.tree = targetNode.tree;
  3904. }, true);
  3905. }
  3906. // A collaposed node won't re-render children, so we have to remove it manually
  3907. // if( !targetParent.expanded ){
  3908. // prevParent.ul.removeChild(this.li);
  3909. // }
  3910. // Update HTML markup
  3911. if( !prevParent.isDescendantOf(targetParent)) {
  3912. prevParent.render();
  3913. }
  3914. if( !targetParent.isDescendantOf(prevParent) && targetParent !== prevParent) {
  3915. targetParent.render();
  3916. }
  3917. // TODO: fix selection state
  3918. // TODO: fix active state
  3919. /*
  3920. var tree = this.tree;
  3921. var opts = tree.options;
  3922. var pers = tree.persistence;
  3923. // Always expand, if it's below minExpandLevel
  3924. // tree.logDebug ("%s._addChildNode(%o), l=%o", this, ftnode, ftnode.getLevel());
  3925. if ( opts.minExpandLevel >= ftnode.getLevel() ) {
  3926. // tree.logDebug ("Force expand for %o", ftnode);
  3927. this.bExpanded = true;
  3928. }
  3929. // In multi-hier mode, update the parents selection state
  3930. // DT issue #82: only if not initializing, because the children may not exist yet
  3931. // if( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing )
  3932. // ftnode._fixSelectionState();
  3933. // In multi-hier mode, update the parents selection state
  3934. if( ftnode.bSelected && opts.selectMode==3 ) {
  3935. var p = this;
  3936. while( p ) {
  3937. if( !p.hasSubSel )
  3938. p._setSubSel(true);
  3939. p = p.parent;
  3940. }
  3941. }
  3942. // render this node and the new child
  3943. if ( tree.bEnableUpdate )
  3944. this.render();
  3945. return ftnode;
  3946. */
  3947. },
  3948. /** Set focus relative to this node and optionally activate.
  3949. *
  3950. * @param {number} where The keyCode that would normally trigger this move,
  3951. * e.g. `$.ui.keyCode.LEFT` would collapse the node if it
  3952. * is expanded or move to the parent oterwise.
  3953. * @param {boolean} [activate=true]
  3954. * @returns {$.Promise}
  3955. */
  3956. navigate: function(where, activate) {
  3957. var i, parents, res,
  3958. handled = true,
  3959. KC = $.ui.keyCode,
  3960. sib = null;
  3961. // Navigate to node
  3962. function _goto(n){
  3963. if( n ){
  3964. // setFocus/setActive will scroll later (if autoScroll is specified)
  3965. try { n.makeVisible({scrollIntoView: false}); } catch(e) {} // #272
  3966. // Node may still be hidden by a filter
  3967. if( ! $(n.span).is(":visible") ) {
  3968. n.debug("Navigate: skipping hidden node");
  3969. n.navigate(where, activate);
  3970. return;
  3971. }
  3972. return activate === false ? n.setFocus() : n.setActive();
  3973. }
  3974. }
  3975. switch( where ) {
  3976. case KC.BACKSPACE:
  3977. if( this.parent && this.parent.parent ) {
  3978. res = _goto(this.parent);
  3979. }
  3980. break;
  3981. case KC.HOME:
  3982. this.tree.visit(function(n){ // goto first visible node
  3983. if( $(n.span).is(":visible") ) {
  3984. res = _goto(n);
  3985. return false;
  3986. }
  3987. });
  3988. break;
  3989. case KC.END:
  3990. this.tree.visit(function(n){ // goto last visible node
  3991. if( $(n.span).is(":visible") ) {
  3992. res = n;
  3993. }
  3994. });
  3995. if( res ) {
  3996. res = _goto(res);
  3997. }
  3998. break;
  3999. case KC.LEFT:
  4000. if( this.expanded ) {
  4001. this.setExpanded(false);
  4002. res = _goto(this);
  4003. } else if( this.parent && this.parent.parent ) {
  4004. res = _goto(this.parent);
  4005. }
  4006. break;
  4007. case KC.RIGHT:
  4008. if( !this.expanded && (this.children || this.lazy) ) {
  4009. this.setExpanded();
  4010. res = _goto(this);
  4011. } else if( this.children && this.children.length ) {
  4012. res = _goto(this.children[0]);
  4013. }
  4014. break;
  4015. case KC.UP:
  4016. sib = this.getPrevSibling();
  4017. // #359: skip hidden sibling nodes, preventing a _goto() recursion
  4018. while( sib && !$(sib.span).is(":visible") ) {
  4019. sib = sib.getPrevSibling();
  4020. }
  4021. while( sib && sib.expanded && sib.children && sib.children.length ) {
  4022. sib = sib.children[sib.children.length - 1];
  4023. }
  4024. if( !sib && this.parent && this.parent.parent ){
  4025. sib = this.parent;
  4026. }
  4027. res = _goto(sib);
  4028. break;
  4029. case KC.DOWN:
  4030. if( this.expanded && this.children && this.children.length ) {
  4031. sib = this.children[0];
  4032. } else {
  4033. parents = this.getParentList(false, true);
  4034. for(i=parents.length-1; i>=0; i--) {
  4035. sib = parents[i].getNextSibling();
  4036. // #359: skip hidden sibling nodes, preventing a _goto() recursion
  4037. while( sib && !$(sib.span).is(":visible") ) {
  4038. sib = sib.getNextSibling();
  4039. }
  4040. if( sib ){ break; }
  4041. }
  4042. }
  4043. res = _goto(sib);
  4044. break;
  4045. default:
  4046. handled = false;
  4047. }
  4048. return res || _getResolvedPromise();
  4049. },
  4050. /**
  4051. * Remove this node (not allowed for system root).
  4052. */
  4053. remove: function() {
  4054. return this.parent.removeChild(this);
  4055. },
  4056. /**
  4057. * Remove childNode from list of direct children.
  4058. * @param {FancytreeNode} childNode
  4059. */
  4060. removeChild: function(childNode) {
  4061. return this.tree._callHook("nodeRemoveChild", this, childNode);
  4062. },
  4063. /**
  4064. * Remove all child nodes and descendents. This converts the node into a leaf.<br>
  4065. * If this was a lazy node, it is still considered 'loaded'; call node.resetLazy()
  4066. * in order to trigger lazyLoad on next expand.
  4067. */
  4068. removeChildren: function() {
  4069. return this.tree._callHook("nodeRemoveChildren", this);
  4070. },
  4071. /**
  4072. * Remove class from node's span tag and .extraClasses.
  4073. *
  4074. * @param {string} className class name
  4075. *
  4076. * @since 2.17
  4077. */
  4078. removeClass: function(className){
  4079. return this.toggleClass(className, false);
  4080. },
  4081. /**
  4082. * This method renders and updates all HTML markup that is required
  4083. * to display this node in its current state.<br>
  4084. * Note:
  4085. * <ul>
  4086. * <li>It should only be neccessary to call this method after the node object
  4087. * was modified by direct access to its properties, because the common
  4088. * API methods (node.setTitle(), moveTo(), addChildren(), remove(), ...)
  4089. * already handle this.
  4090. * <li> {@link FancytreeNode#renderTitle} and {@link FancytreeNode#renderStatus}
  4091. * are implied. If changes are more local, calling only renderTitle() or
  4092. * renderStatus() may be sufficient and faster.
  4093. * </ul>
  4094. *
  4095. * @param {boolean} [force=false] re-render, even if html markup was already created
  4096. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  4097. */
  4098. render: function(force, deep) {
  4099. return this.tree._callHook("nodeRender", this, force, deep);
  4100. },
  4101. /** Create HTML markup for the node's outer &lt;span> (expander, checkbox, icon, and title).
  4102. * Implies {@link FancytreeNode#renderStatus}.
  4103. * @see Fancytree_Hooks#nodeRenderTitle
  4104. */
  4105. renderTitle: function() {
  4106. return this.tree._callHook("nodeRenderTitle", this);
  4107. },
  4108. /** Update element's CSS classes according to node state.
  4109. * @see Fancytree_Hooks#nodeRenderStatus
  4110. */
  4111. renderStatus: function() {
  4112. return this.tree._callHook("nodeRenderStatus", this);
  4113. },
  4114. /**
  4115. * (experimental) Replace this node with `source`.
  4116. * (Currently only available for paging nodes.)
  4117. * @param {NodeData[]} source List of child node definitions
  4118. * @since 2.15
  4119. */
  4120. replaceWith: function(source) {
  4121. var res,
  4122. parent = this.parent,
  4123. pos = $.inArray(this, parent.children),
  4124. that = this;
  4125. _assert( this.isPagingNode(), "replaceWith() currently requires a paging status node" );
  4126. res = this.tree._callHook("nodeLoadChildren", this, source);
  4127. res.done(function(data){
  4128. // New nodes are currently children of `this`.
  4129. var children = that.children;
  4130. // Prepend newly loaded child nodes to `this`
  4131. // Move new children after self
  4132. for( i=0; i<children.length; i++ ) {
  4133. children[i].parent = parent;
  4134. }
  4135. parent.children.splice.apply(parent.children, [pos + 1, 0].concat(children));
  4136. // Remove self
  4137. that.children = null;
  4138. that.remove();
  4139. // Redraw new nodes
  4140. parent.render();
  4141. // TODO: set node.partload = false if this was tha last paging node?
  4142. // parent.addPagingNode(false);
  4143. }).fail(function(){
  4144. that.setExpanded();
  4145. });
  4146. return res;
  4147. // $.error("Not implemented: replaceWith()");
  4148. },
  4149. /**
  4150. * Remove all children, collapse, and set the lazy-flag, so that the lazyLoad
  4151. * event is triggered on next expand.
  4152. */
  4153. resetLazy: function() {
  4154. this.removeChildren();
  4155. this.expanded = false;
  4156. this.lazy = true;
  4157. this.children = undefined;
  4158. this.renderStatus();
  4159. },
  4160. /** Schedule activity for delayed execution (cancel any pending request).
  4161. * scheduleAction('cancel') will only cancel a pending request (if any).
  4162. * @param {string} mode
  4163. * @param {number} ms
  4164. */
  4165. scheduleAction: function(mode, ms) {
  4166. if( this.tree.timer ) {
  4167. clearTimeout(this.tree.timer);
  4168. // this.tree.debug("clearTimeout(%o)", this.tree.timer);
  4169. }
  4170. this.tree.timer = null;
  4171. var self = this; // required for closures
  4172. switch (mode) {
  4173. case "cancel":
  4174. // Simply made sure that timer was cleared
  4175. break;
  4176. case "expand":
  4177. this.tree.timer = setTimeout(function(){
  4178. self.tree.debug("setTimeout: trigger expand");
  4179. self.setExpanded(true);
  4180. }, ms);
  4181. break;
  4182. case "activate":
  4183. this.tree.timer = setTimeout(function(){
  4184. self.tree.debug("setTimeout: trigger activate");
  4185. self.setActive(true);
  4186. }, ms);
  4187. break;
  4188. default:
  4189. $.error("Invalid mode " + mode);
  4190. }
  4191. // this.tree.debug("setTimeout(%s, %s): %s", mode, ms, this.tree.timer);
  4192. },
  4193. /**
  4194. *
  4195. * @param {boolean | PlainObject} [effects=false] animation options.
  4196. * @param {object} [options=null] {topNode: null, effects: ..., parent: ...} this node will remain visible in
  4197. * any case, even if `this` is outside the scroll pane.
  4198. * @returns {$.Promise}
  4199. */
  4200. scrollIntoView: function(effects, options) {
  4201. if( options !== undefined && _isNode(options) ) {
  4202. this.warn("scrollIntoView() with 'topNode' option is deprecated since 2014-05-08. Use 'options.topNode' instead.");
  4203. options = {topNode: options};
  4204. }
  4205. // this.$scrollParent = (this.options.scrollParent === "auto") ? $ul.scrollParent() : $(this.options.scrollParent);
  4206. // this.$scrollParent = this.$scrollParent.length ? this.$scrollParent || this.$container;
  4207. var topNodeY, nodeY, horzScrollbarHeight, containerOffsetTop,
  4208. opts = $.extend({
  4209. effects: (effects === true) ? {duration: 200, queue: false} : effects,
  4210. scrollOfs: this.tree.options.scrollOfs,
  4211. scrollParent: this.tree.options.scrollParent || this.tree.$container,
  4212. topNode: null
  4213. }, options),
  4214. dfd = new $.Deferred(),
  4215. that = this,
  4216. nodeHeight = $(this.span).height(),
  4217. $container = $(opts.scrollParent),
  4218. topOfs = opts.scrollOfs.top || 0,
  4219. bottomOfs = opts.scrollOfs.bottom || 0,
  4220. containerHeight = $container.height(),// - topOfs - bottomOfs,
  4221. scrollTop = $container.scrollTop(),
  4222. $animateTarget = $container,
  4223. isParentWindow = $container[0] === window,
  4224. topNode = opts.topNode || null,
  4225. newScrollTop = null;
  4226. // this.debug("scrollIntoView(), scrollTop=" + scrollTop, opts.scrollOfs);
  4227. // _assert($(this.span).is(":visible"), "scrollIntoView node is invisible"); // otherwise we cannot calc offsets
  4228. if( !$(this.span).is(":visible") ) {
  4229. // We cannot calc offsets for hidden elements
  4230. this.warn("scrollIntoView(): node is invisible.");
  4231. return _getResolvedPromise();
  4232. }
  4233. if( isParentWindow ) {
  4234. nodeY = $(this.span).offset().top;
  4235. topNodeY = (topNode && topNode.span) ? $(topNode.span).offset().top : 0;
  4236. $animateTarget = $("html,body");
  4237. } else {
  4238. _assert($container[0] !== document && $container[0] !== document.body,
  4239. "scrollParent should be a simple element or `window`, not document or body.");
  4240. containerOffsetTop = $container.offset().top,
  4241. nodeY = $(this.span).offset().top - containerOffsetTop + scrollTop; // relative to scroll parent
  4242. topNodeY = topNode ? $(topNode.span).offset().top - containerOffsetTop + scrollTop : 0;
  4243. horzScrollbarHeight = Math.max(0, ($container.innerHeight() - $container[0].clientHeight));
  4244. containerHeight -= horzScrollbarHeight;
  4245. }
  4246. // this.debug(" scrollIntoView(), nodeY=" + nodeY + ", containerHeight=" + containerHeight);
  4247. if( nodeY < (scrollTop + topOfs) ){
  4248. // Node is above visible container area
  4249. newScrollTop = nodeY - topOfs;
  4250. // this.debug(" scrollIntoView(), UPPER newScrollTop=" + newScrollTop);
  4251. }else if((nodeY + nodeHeight) > (scrollTop + containerHeight - bottomOfs)){
  4252. newScrollTop = nodeY + nodeHeight - containerHeight + bottomOfs;
  4253. // this.debug(" scrollIntoView(), LOWER newScrollTop=" + newScrollTop);
  4254. // If a topNode was passed, make sure that it is never scrolled
  4255. // outside the upper border
  4256. if(topNode){
  4257. _assert(topNode.isRootNode() || $(topNode.span).is(":visible"), "topNode must be visible");
  4258. if( topNodeY < newScrollTop ){
  4259. newScrollTop = topNodeY - topOfs;
  4260. // this.debug(" scrollIntoView(), TOP newScrollTop=" + newScrollTop);
  4261. }
  4262. }
  4263. }
  4264. if(newScrollTop !== null){
  4265. // this.debug(" scrollIntoView(), SET newScrollTop=" + newScrollTop);
  4266. if(opts.effects){
  4267. opts.effects.complete = function(){
  4268. dfd.resolveWith(that);
  4269. };
  4270. $animateTarget.stop(true).animate({
  4271. scrollTop: newScrollTop
  4272. }, opts.effects);
  4273. }else{
  4274. $animateTarget[0].scrollTop = newScrollTop;
  4275. dfd.resolveWith(this);
  4276. }
  4277. }else{
  4278. dfd.resolveWith(this);
  4279. }
  4280. return dfd.promise();
  4281. },
  4282. /**Activate this node.
  4283. * @param {boolean} [flag=true] pass false to deactivate
  4284. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  4285. * @returns {$.Promise}
  4286. */
  4287. setActive: function(flag, opts){
  4288. return this.tree._callHook("nodeSetActive", this, flag, opts);
  4289. },
  4290. /**Expand or collapse this node. Promise is resolved, when lazy loading and animations are done.
  4291. * @param {boolean} [flag=true] pass false to collapse
  4292. * @param {object} [opts] additional options. Defaults to {noAnimation: false, noEvents: false}
  4293. * @returns {$.Promise}
  4294. */
  4295. setExpanded: function(flag, opts){
  4296. return this.tree._callHook("nodeSetExpanded", this, flag, opts);
  4297. },
  4298. /**Set keyboard focus to this node.
  4299. * @param {boolean} [flag=true] pass false to blur
  4300. * @see Fancytree#setFocus
  4301. */
  4302. setFocus: function(flag){
  4303. return this.tree._callHook("nodeSetFocus", this, flag);
  4304. },
  4305. /**Select this node, i.e. check the checkbox.
  4306. * @param {boolean} [flag=true] pass false to deselect
  4307. * @param {object} [opts] additional options. Defaults to {noEvents: false, p
  4308. * propagateDown: null, propagateUp: null, callback: null }
  4309. */
  4310. setSelected: function(flag, opts){
  4311. return this.tree._callHook("nodeSetSelected", this, flag, opts);
  4312. },
  4313. /**Mark a lazy node as 'error', 'loading', 'nodata', or 'ok'.
  4314. * @param {string} status 'error'|'empty'|'ok'
  4315. * @param {string} [message]
  4316. * @param {string} [details]
  4317. */
  4318. setStatus: function(status, message, details){
  4319. return this.tree._callHook("nodeSetStatus", this, status, message, details);
  4320. },
  4321. /**Rename this node.
  4322. * @param {string} title
  4323. */
  4324. setTitle: function(title){
  4325. this.title = title;
  4326. this.renderTitle();
  4327. this.triggerModify("rename");
  4328. },
  4329. /**Sort child list by title.
  4330. * @param {function} [cmp] custom compare function(a, b) that returns -1, 0, or 1 (defaults to sort by title).
  4331. * @param {boolean} [deep=false] pass true to sort all descendant nodes
  4332. */
  4333. sortChildren: function(cmp, deep) {
  4334. var i,l,
  4335. cl = this.children;
  4336. if( !cl ){
  4337. return;
  4338. }
  4339. cmp = cmp || function(a, b) {
  4340. var x = a.title.toLowerCase(),
  4341. y = b.title.toLowerCase();
  4342. return x === y ? 0 : x > y ? 1 : -1;
  4343. };
  4344. cl.sort(cmp);
  4345. if( deep ){
  4346. for(i=0, l=cl.length; i<l; i++){
  4347. if( cl[i].children ){
  4348. cl[i].sortChildren(cmp, "$norender$");
  4349. }
  4350. }
  4351. }
  4352. if( deep !== "$norender$" ){
  4353. this.render();
  4354. }
  4355. this.triggerModifyChild("sort");
  4356. },
  4357. /** Convert node (or whole branch) into a plain object.
  4358. *
  4359. * The result is compatible with node.addChildren().
  4360. *
  4361. * @param {boolean} [recursive=false] include child nodes
  4362. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications
  4363. * @returns {NodeData}
  4364. */
  4365. toDict: function(recursive, callback) {
  4366. var i, l, node,
  4367. dict = {},
  4368. self = this;
  4369. $.each(NODE_ATTRS, function(i, a){
  4370. if(self[a] || self[a] === false){
  4371. dict[a] = self[a];
  4372. }
  4373. });
  4374. if(!$.isEmptyObject(this.data)){
  4375. dict.data = $.extend({}, this.data);
  4376. if($.isEmptyObject(dict.data)){
  4377. delete dict.data;
  4378. }
  4379. }
  4380. if( callback ){
  4381. callback(dict, self);
  4382. }
  4383. if( recursive ) {
  4384. if(this.hasChildren()){
  4385. dict.children = [];
  4386. for(i=0, l=this.children.length; i<l; i++ ){
  4387. node = this.children[i];
  4388. if( !node.isStatusNode() ){
  4389. dict.children.push(node.toDict(true, callback));
  4390. }
  4391. }
  4392. }else{
  4393. // dict.children = null;
  4394. }
  4395. }
  4396. return dict;
  4397. },
  4398. /**
  4399. * Set, clear, or toggle class of node's span tag and .extraClasses.
  4400. *
  4401. * @param {string} className class name (separate multiple classes by space)
  4402. * @param {boolean} [flag] true/false to add/remove class. If omitted, class is toggled.
  4403. * @returns {boolean} true if a class was added
  4404. *
  4405. * @since 2.17
  4406. */
  4407. toggleClass: function(value, flag){
  4408. var className, hasClass,
  4409. rnotwhite = ( /\S+/g ),
  4410. classNames = value.match( rnotwhite ) || [],
  4411. i = 0,
  4412. wasAdded = false,
  4413. statusElem = this[this.tree.statusClassPropName],
  4414. curClasses = (" " + (this.extraClasses || "") + " ");
  4415. // this.info("toggleClass('" + value + "', " + flag + ")", curClasses);
  4416. // Modify DOM element directly if it already exists
  4417. if( statusElem ) {
  4418. $(statusElem).toggleClass(value, flag);
  4419. }
  4420. // Modify node.extraClasses to make this change persistent
  4421. // Toggle if flag was not passed
  4422. while ( className = classNames[ i++ ] ) {
  4423. hasClass = curClasses.indexOf(" " + className + " ") >= 0;
  4424. flag = (flag === undefined) ? (!hasClass) : !!flag;
  4425. if ( flag ) {
  4426. if( !hasClass ) {
  4427. curClasses += className + " ";
  4428. wasAdded = true;
  4429. }
  4430. } else {
  4431. while ( curClasses.indexOf( " " + className + " " ) > -1 ) {
  4432. curClasses = curClasses.replace( " " + className + " ", " " );
  4433. }
  4434. }
  4435. }
  4436. this.extraClasses = $.trim(curClasses);
  4437. // this.info("-> toggleClass('" + value + "', " + flag + "): '" + this.extraClasses + "'");
  4438. return wasAdded;
  4439. },
  4440. /** Flip expanded status. */
  4441. toggleExpanded: function(){
  4442. return this.tree._callHook("nodeToggleExpanded", this);
  4443. },
  4444. /** Flip selection status. */
  4445. toggleSelected: function(){
  4446. return this.tree._callHook("nodeToggleSelected", this);
  4447. },
  4448. toString: function() {
  4449. return "<FancytreeNode(#" + this.key + ", '" + this.title + "')>";
  4450. },
  4451. /**
  4452. * Trigger `modifyChild` event on a parent to signal that a child was modified.
  4453. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  4454. * @param {FancytreeNode} [childNode]
  4455. * @param {object} [extra]
  4456. */
  4457. triggerModifyChild: function(operation, childNode, extra){
  4458. var data,
  4459. modifyChild = this.tree.options.modifyChild;
  4460. if ( modifyChild ){
  4461. if( childNode && childNode.parent !== this ) {
  4462. $.error("childNode " + childNode + " is not a child of " + this);
  4463. }
  4464. data = {
  4465. node: this,
  4466. tree: this.tree,
  4467. operation: operation,
  4468. childNode: childNode || null
  4469. };
  4470. if( extra ) {
  4471. $.extend(data, extra);
  4472. }
  4473. modifyChild({type: "modifyChild"}, data);
  4474. }
  4475. },
  4476. /**
  4477. * Trigger `modifyChild` event on node.parent(!).
  4478. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  4479. * @param {object} [extra]
  4480. */
  4481. triggerModify: function(operation, extra){
  4482. this.parent.triggerModifyChild(operation, this, extra);
  4483. },
  4484. /** Call fn(node) for all child nodes.<br>
  4485. * Stop iteration, if fn() returns false. Skip current branch, if fn() returns "skip".<br>
  4486. * Return false if iteration was stopped.
  4487. *
  4488. * @param {function} fn the callback function.
  4489. * Return false to stop iteration, return "skip" to skip this node and
  4490. * its children only.
  4491. * @param {boolean} [includeSelf=false]
  4492. * @returns {boolean}
  4493. */
  4494. visit: function(fn, includeSelf) {
  4495. var i, l,
  4496. res = true,
  4497. children = this.children;
  4498. if( includeSelf === true ) {
  4499. res = fn(this);
  4500. if( res === false || res === "skip" ){
  4501. return res;
  4502. }
  4503. }
  4504. if(children){
  4505. for(i=0, l=children.length; i<l; i++){
  4506. res = children[i].visit(fn, true);
  4507. if( res === false ){
  4508. break;
  4509. }
  4510. }
  4511. }
  4512. return res;
  4513. },
  4514. /** Call fn(node) for all child nodes and recursively load lazy children.<br>
  4515. * <b>Note:</b> If you need this method, you probably should consider to review
  4516. * your architecture! Recursivley loading nodes is a perfect way for lazy
  4517. * programmers to flood the server with requests ;-)
  4518. *
  4519. * @param {function} [fn] optional callback function.
  4520. * Return false to stop iteration, return "skip" to skip this node and
  4521. * its children only.
  4522. * @param {boolean} [includeSelf=false]
  4523. * @returns {$.Promise}
  4524. * @since 2.4
  4525. */
  4526. visitAndLoad: function(fn, includeSelf, _recursion) {
  4527. var dfd, res, loaders,
  4528. node = this;
  4529. // node.debug("visitAndLoad");
  4530. if( fn && includeSelf === true ) {
  4531. res = fn(node);
  4532. if( res === false || res === "skip" ) {
  4533. return _recursion ? res : _getResolvedPromise();
  4534. }
  4535. }
  4536. if( !node.children && !node.lazy ) {
  4537. return _getResolvedPromise();
  4538. }
  4539. dfd = new $.Deferred();
  4540. loaders = [];
  4541. // node.debug("load()...");
  4542. node.load().done(function(){
  4543. // node.debug("load()... done.");
  4544. for(var i=0, l=node.children.length; i<l; i++){
  4545. res = node.children[i].visitAndLoad(fn, true, true);
  4546. if( res === false ) {
  4547. dfd.reject();
  4548. break;
  4549. } else if ( res !== "skip" ) {
  4550. loaders.push(res); // Add promise to the list
  4551. }
  4552. }
  4553. $.when.apply(this, loaders).then(function(){
  4554. dfd.resolve();
  4555. });
  4556. });
  4557. return dfd.promise();
  4558. },
  4559. /** Call fn(node) for all parent nodes, bottom-up, including invisible system root.<br>
  4560. * Stop iteration, if fn() returns false.<br>
  4561. * Return false if iteration was stopped.
  4562. *
  4563. * @param {function} fn the callback function.
  4564. * Return false to stop iteration, return "skip" to skip this node and children only.
  4565. * @param {boolean} [includeSelf=false]
  4566. * @returns {boolean}
  4567. */
  4568. visitParents: function(fn, includeSelf) {
  4569. // Visit parent nodes (bottom up)
  4570. if(includeSelf && fn(this) === false){
  4571. return false;
  4572. }
  4573. var p = this.parent;
  4574. while( p ) {
  4575. if(fn(p) === false){
  4576. return false;
  4577. }
  4578. p = p.parent;
  4579. }
  4580. return true;
  4581. },
  4582. /** Call fn(node) for all sibling nodes.<br>
  4583. * Stop iteration, if fn() returns false.<br>
  4584. * Return false if iteration was stopped.
  4585. *
  4586. * @param {function} fn the callback function.
  4587. * Return false to stop iteration.
  4588. * @param {boolean} [includeSelf=false]
  4589. * @returns {boolean}
  4590. */
  4591. visitSiblings: function(fn, includeSelf) {
  4592. var i, l, n,
  4593. ac = this.parent.children;
  4594. for (i=0, l=ac.length; i<l; i++) {
  4595. n = ac[i];
  4596. if ( includeSelf || n !== this ){
  4597. if( fn(n) === false ) {
  4598. return false;
  4599. }
  4600. }
  4601. }
  4602. return true;
  4603. },
  4604. /** Write warning to browser console (prepending node info)
  4605. *
  4606. * @param {*} msg string or object or array of such
  4607. */
  4608. warn: function(msg){
  4609. Array.prototype.unshift.call(arguments, this.toString());
  4610. consoleApply("warn", arguments);
  4611. }
  4612. };
  4613. /* *****************************************************************************
  4614. * Fancytree
  4615. */
  4616. /**
  4617. * Construct a new tree object.
  4618. *
  4619. * @class Fancytree
  4620. * @classdesc The controller behind a fancytree.
  4621. * This class also contains 'hook methods': see {@link Fancytree_Hooks}.
  4622. *
  4623. * @param {Widget} widget
  4624. *
  4625. * @property {string} _id Automatically generated unique tree instance ID, e.g. "1".
  4626. * @property {string} _ns Automatically generated unique tree namespace, e.g. ".fancytree-1".
  4627. * @property {FancytreeNode} activeNode Currently active node or null.
  4628. * @property {string} ariaPropName Property name of FancytreeNode that contains the element which will receive the aria attributes.
  4629. * Typically "li", but "tr" for table extension.
  4630. * @property {jQueryObject} $container Outer &lt;ul> element (or &lt;table> element for ext-table).
  4631. * @property {jQueryObject} $div A jQuery object containing the element used to instantiate the tree widget (`widget.element`)
  4632. * @property {object} data Metadata, i.e. properties that may be passed to `source` in addition to a children array.
  4633. * @property {object} ext Hash of all active plugin instances.
  4634. * @property {FancytreeNode} focusNode Currently focused node or null.
  4635. * @property {FancytreeNode} lastSelectedNode Used to implement selectMode 1 (single select)
  4636. * @property {string} nodeContainerAttrName Property name of FancytreeNode that contains the outer element of single nodes.
  4637. * Typically "li", but "tr" for table extension.
  4638. * @property {FancytreeOptions} options Current options, i.e. default options + options passed to constructor.
  4639. * @property {FancytreeNode} rootNode Invisible system root node.
  4640. * @property {string} statusClassPropName Property name of FancytreeNode that contains the element which will receive the status classes.
  4641. * Typically "span", but "tr" for table extension.
  4642. * @property {object} widget Base widget instance.
  4643. */
  4644. function Fancytree(widget) {
  4645. this.widget = widget;
  4646. this.$div = widget.element;
  4647. this.options = widget.options;
  4648. if( this.options ) {
  4649. if( $.isFunction(this.options.lazyload ) && !$.isFunction(this.options.lazyLoad) ) {
  4650. this.options.lazyLoad = function() {
  4651. FT.warn("The 'lazyload' event is deprecated since 2014-02-25. Use 'lazyLoad' (with uppercase L) instead.");
  4652. return widget.options.lazyload.apply(this, arguments);
  4653. };
  4654. }
  4655. if( $.isFunction(this.options.loaderror) ) {
  4656. $.error("The 'loaderror' event was renamed since 2014-07-03. Use 'loadError' (with uppercase E) instead.");
  4657. }
  4658. if( this.options.fx !== undefined ) {
  4659. FT.warn("The 'fx' option was replaced by 'toggleEffect' since 2014-11-30.");
  4660. }
  4661. if( this.options.removeNode !== undefined ) {
  4662. $.error("The 'removeNode' event was replaced by 'modifyChild' since 2.20 (2016-09-10).");
  4663. }
  4664. }
  4665. this.ext = {}; // Active extension instances
  4666. // allow to init tree.data.foo from <div data-foo=''>
  4667. this.data = _getElementDataAsDict(this.$div);
  4668. // TODO: use widget.uuid instead?
  4669. this._id = $.ui.fancytree._nextId++;
  4670. // TODO: use widget.eventNamespace instead?
  4671. this._ns = ".fancytree-" + this._id; // append for namespaced events
  4672. this.activeNode = null;
  4673. this.focusNode = null;
  4674. this._hasFocus = null;
  4675. this._tempCache = {};
  4676. this._lastMousedownNode = null;
  4677. this._enableUpdate = true;
  4678. // this._dirtyRoots = null;
  4679. this.lastSelectedNode = null;
  4680. this.systemFocusElement = null;
  4681. this.lastQuicksearchTerm = "";
  4682. this.lastQuicksearchTime = 0;
  4683. this.statusClassPropName = "span";
  4684. this.ariaPropName = "li";
  4685. this.nodeContainerAttrName = "li";
  4686. // Remove previous markup if any
  4687. this.$div.find(">ul.fancytree-container").remove();
  4688. // Create a node without parent.
  4689. var fakeParent = { tree: this },
  4690. $ul;
  4691. this.rootNode = new FancytreeNode(fakeParent, {
  4692. title: "root",
  4693. key: "root_" + this._id,
  4694. children: null,
  4695. expanded: true
  4696. });
  4697. this.rootNode.parent = null;
  4698. // Create root markup
  4699. $ul = $("<ul>", {
  4700. "class": "ui-fancytree fancytree-container fancytree-plain"
  4701. }).appendTo(this.$div);
  4702. this.$container = $ul;
  4703. this.rootNode.ul = $ul[0];
  4704. if(this.options.debugLevel == null){
  4705. this.options.debugLevel = FT.debugLevel;
  4706. }
  4707. // // Add container to the TAB chain
  4708. // // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  4709. // // #577: Allow to set tabindex to "0", "-1" and ""
  4710. // this.$container.attr("tabindex", this.options.tabindex);
  4711. // if( this.options.rtl ) {
  4712. // this.$container.attr("DIR", "RTL").addClass("fancytree-rtl");
  4713. // // }else{
  4714. // // this.$container.attr("DIR", null).removeClass("fancytree-rtl");
  4715. // }
  4716. // if(this.options.aria){
  4717. // this.$container.attr("role", "tree");
  4718. // if( this.options.selectMode !== 1 ) {
  4719. // this.$container.attr("aria-multiselectable", true);
  4720. // }
  4721. // }
  4722. }
  4723. Fancytree.prototype = /** @lends Fancytree# */{
  4724. /* Return a context object that can be re-used for _callHook().
  4725. * @param {Fancytree | FancytreeNode | EventData} obj
  4726. * @param {Event} originalEvent
  4727. * @param {Object} extra
  4728. * @returns {EventData}
  4729. */
  4730. _makeHookContext: function(obj, originalEvent, extra) {
  4731. var ctx, tree;
  4732. if(obj.node !== undefined){
  4733. // obj is already a context object
  4734. if(originalEvent && obj.originalEvent !== originalEvent){
  4735. $.error("invalid args");
  4736. }
  4737. ctx = obj;
  4738. }else if(obj.tree){
  4739. // obj is a FancytreeNode
  4740. tree = obj.tree;
  4741. ctx = { node: obj, tree: tree, widget: tree.widget, options: tree.widget.options, originalEvent: originalEvent };
  4742. }else if(obj.widget){
  4743. // obj is a Fancytree
  4744. ctx = { node: null, tree: obj, widget: obj.widget, options: obj.widget.options, originalEvent: originalEvent };
  4745. }else{
  4746. $.error("invalid args");
  4747. }
  4748. if(extra){
  4749. $.extend(ctx, extra);
  4750. }
  4751. return ctx;
  4752. },
  4753. /* Trigger a hook function: funcName(ctx, [...]).
  4754. *
  4755. * @param {string} funcName
  4756. * @param {Fancytree|FancytreeNode|EventData} contextObject
  4757. * @param {any} [_extraArgs] optional additional arguments
  4758. * @returns {any}
  4759. */
  4760. _callHook: function(funcName, contextObject, _extraArgs) {
  4761. var ctx = this._makeHookContext(contextObject),
  4762. fn = this[funcName],
  4763. args = Array.prototype.slice.call(arguments, 2);
  4764. if(!$.isFunction(fn)){
  4765. $.error("_callHook('" + funcName + "') is not a function");
  4766. }
  4767. args.unshift(ctx);
  4768. // this.debug("_hook", funcName, ctx.node && ctx.node.toString() || ctx.tree.toString(), args);
  4769. return fn.apply(this, args);
  4770. },
  4771. _setExpiringValue: function(key, value, ms){
  4772. this._tempCache[key] = {value: value, expire: Date.now() + (+ms || 50)};
  4773. },
  4774. _getExpiringValue: function(key){
  4775. var entry = this._tempCache[key];
  4776. if( entry && entry.expire < Date.now() ) {
  4777. return entry.value;
  4778. }
  4779. delete this._tempCache[key];
  4780. return null;
  4781. },
  4782. /* Check if current extensions dependencies are met and throw an error if not.
  4783. *
  4784. * This method may be called inside the `treeInit` hook for custom extensions.
  4785. *
  4786. * @param {string} extension name of the required extension
  4787. * @param {boolean} [required=true] pass `false` if the extension is optional, but we want to check for order if it is present
  4788. * @param {boolean} [before] `true` if `name` must be included before this, `false` otherwise (use `null` if order doesn't matter)
  4789. * @param {string} [message] optional error message (defaults to a descriptve error message)
  4790. */
  4791. _requireExtension: function(name, required, before, message) {
  4792. before = !!before;
  4793. var thisName = this._local.name,
  4794. extList = this.options.extensions,
  4795. isBefore = $.inArray(name, extList) < $.inArray(thisName, extList),
  4796. isMissing = required && this.ext[name] == null,
  4797. badOrder = !isMissing && before != null && (before !== isBefore);
  4798. _assert(thisName && thisName !== name, "invalid or same name");
  4799. if( isMissing || badOrder ){
  4800. if( !message ){
  4801. if( isMissing || required ){
  4802. message = "'" + thisName + "' extension requires '" + name + "'";
  4803. if( badOrder ){
  4804. message += " to be registered " + (before ? "before" : "after") + " itself";
  4805. }
  4806. }else{
  4807. message = "If used together, `" + name + "` must be registered " + (before ? "before" : "after") + " `" + thisName + "`";
  4808. }
  4809. }
  4810. $.error(message);
  4811. return false;
  4812. }
  4813. return true;
  4814. },
  4815. /** Activate node with a given key and fire focus and activate events.
  4816. *
  4817. * A previously activated node will be deactivated.
  4818. * If activeVisible option is set, all parents will be expanded as necessary.
  4819. * Pass key = false, to deactivate the current node only.
  4820. * @param {string} key
  4821. * @returns {FancytreeNode} activated node (null, if not found)
  4822. */
  4823. activateKey: function(key) {
  4824. var node = this.getNodeByKey(key);
  4825. if(node){
  4826. node.setActive();
  4827. }else if(this.activeNode){
  4828. this.activeNode.setActive(false);
  4829. }
  4830. return node;
  4831. },
  4832. /** (experimental) Add child status nodes that indicate 'More...', ....
  4833. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  4834. * @param {string} [mode='append'] 'child'|firstChild'
  4835. * @since 2.15
  4836. */
  4837. addPagingNode: function(node, mode){
  4838. return this.rootNode.addPagingNode(node, mode);
  4839. },
  4840. /** (experimental) Modify existing data model.
  4841. *
  4842. * @param {Array} patchList array of [key, NodePatch] arrays
  4843. * @returns {$.Promise} resolved, when all patches have been applied
  4844. * @see TreePatch
  4845. */
  4846. applyPatch: function(patchList) {
  4847. var dfd, i, p2, key, patch, node,
  4848. patchCount = patchList.length,
  4849. deferredList = [];
  4850. for(i=0; i<patchCount; i++){
  4851. p2 = patchList[i];
  4852. _assert(p2.length === 2, "patchList must be an array of length-2-arrays");
  4853. key = p2[0];
  4854. patch = p2[1];
  4855. node = (key === null) ? this.rootNode : this.getNodeByKey(key);
  4856. if(node){
  4857. dfd = new $.Deferred();
  4858. deferredList.push(dfd);
  4859. node.applyPatch(patch).always(_makeResolveFunc(dfd, node));
  4860. }else{
  4861. this.warn("could not find node with key '" + key + "'");
  4862. }
  4863. }
  4864. // Return a promise that is resolved, when ALL patches were applied
  4865. return $.when.apply($, deferredList).promise();
  4866. },
  4867. /* TODO: implement in dnd extension
  4868. cancelDrag: function() {
  4869. var dd = $.ui.ddmanager.current;
  4870. if(dd){
  4871. dd.cancel();
  4872. }
  4873. },
  4874. */
  4875. /** Remove all nodes.
  4876. * @since 2.14
  4877. */
  4878. clear: function(source) {
  4879. this._callHook("treeClear", this);
  4880. },
  4881. /** Return the number of nodes.
  4882. * @returns {integer}
  4883. */
  4884. count: function() {
  4885. return this.rootNode.countChildren();
  4886. },
  4887. /** Write to browser console if debugLevel >= 2 (prepending tree name)
  4888. *
  4889. * @param {*} msg string or object or array of such
  4890. */
  4891. debug: function(msg){
  4892. if( this.options.debugLevel >= 2 ) {
  4893. Array.prototype.unshift.call(arguments, this.toString());
  4894. consoleApply("log", arguments);
  4895. }
  4896. },
  4897. // TODO: disable()
  4898. // TODO: enable()
  4899. /** Temporarily suppress rendering to improve performance on bulk-updates.
  4900. *
  4901. * @param {boolean} flag
  4902. * @returns {boolean} previous status
  4903. * @since 2.19
  4904. */
  4905. enableUpdate: function(flag) {
  4906. flag = ( flag !== false );
  4907. /*jshint -W018 */ // Confusing use of '!'
  4908. if ( !!this._enableUpdate === !!flag ) {
  4909. return flag;
  4910. }
  4911. /*jshint +W018 */
  4912. this._enableUpdate = flag;
  4913. if ( flag ) {
  4914. this.debug("enableUpdate(true): redraw "); //, this._dirtyRoots);
  4915. this.render();
  4916. } else {
  4917. // this._dirtyRoots = null;
  4918. this.debug("enableUpdate(false)...");
  4919. }
  4920. return !flag; // return previous value
  4921. },
  4922. /**Find all nodes that matches condition.
  4923. *
  4924. * @param {string | function(node)} match title string to search for, or a
  4925. * callback function that returns `true` if a node is matched.
  4926. * @returns {FancytreeNode[]} array of nodes (may be empty)
  4927. * @see FancytreeNode#findAll
  4928. * @since 2.12
  4929. */
  4930. findAll: function(match) {
  4931. return this.rootNode.findAll(match);
  4932. },
  4933. /**Find first node that matches condition.
  4934. *
  4935. * @param {string | function(node)} match title string to search for, or a
  4936. * callback function that returns `true` if a node is matched.
  4937. * @returns {FancytreeNode} matching node or null
  4938. * @see FancytreeNode#findFirst
  4939. * @since 2.12
  4940. */
  4941. findFirst: function(match) {
  4942. return this.rootNode.findFirst(match);
  4943. },
  4944. /** Find the next visible node that starts with `match`, starting at `startNode`
  4945. * and wrap-around at the end.
  4946. *
  4947. * @param {string|function} match
  4948. * @param {FancytreeNode} [startNode] defaults to first node
  4949. * @returns {FancytreeNode} matching node or null
  4950. */
  4951. findNextNode: function(match, startNode, visibleOnly) {
  4952. var stopNode = null,
  4953. parentChildren = startNode.parent.children,
  4954. matchingNode = null,
  4955. walkVisible = function(parent, idx, fn) {
  4956. var i, grandParent,
  4957. parentChildren = parent.children,
  4958. siblingCount = parentChildren.length,
  4959. node = parentChildren[idx];
  4960. // visit node itself
  4961. if( node && fn(node) === false ) {
  4962. return false;
  4963. }
  4964. // visit descendants
  4965. if( node && node.children && node.expanded ) {
  4966. if( walkVisible(node, 0, fn) === false ) {
  4967. return false;
  4968. }
  4969. }
  4970. // visit subsequent siblings
  4971. for( i = idx + 1; i < siblingCount; i++ ) {
  4972. if( walkVisible(parent, i, fn) === false ) {
  4973. return false;
  4974. }
  4975. }
  4976. // visit parent's subsequent siblings
  4977. grandParent = parent.parent;
  4978. if( grandParent ) {
  4979. return walkVisible(grandParent, grandParent.children.indexOf(parent) + 1, fn);
  4980. } else {
  4981. // wrap-around: restart with first node
  4982. return walkVisible(parent, 0, fn);
  4983. }
  4984. };
  4985. match = (typeof match === "string") ? _makeNodeTitleStartMatcher(match) : match;
  4986. startNode = startNode || this.getFirstChild();
  4987. walkVisible(startNode.parent, parentChildren.indexOf(startNode), function(node){
  4988. // Stop iteration if we see the start node a second time
  4989. if( node === stopNode ) {
  4990. return false;
  4991. }
  4992. stopNode = stopNode || node;
  4993. // Ignore nodes hidden by a filter
  4994. if( ! $(node.span).is(":visible") ) {
  4995. node.debug("quicksearch: skipping hidden node");
  4996. return;
  4997. }
  4998. // Test if we found a match, but search for a second match if this
  4999. // was the currently active node
  5000. if( match(node) ) {
  5001. // node.debug("quicksearch match " + node.title, startNode);
  5002. matchingNode = node;
  5003. if( matchingNode !== startNode ) {
  5004. return false;
  5005. }
  5006. }
  5007. });
  5008. return matchingNode;
  5009. },
  5010. // TODO: fromDict
  5011. /**
  5012. * Generate INPUT elements that can be submitted with html forms.
  5013. *
  5014. * In selectMode 3 only the topmost selected nodes are considered, unless
  5015. * `opts.stopOnParents: false` is passed.
  5016. *
  5017. * @example
  5018. * // Generate input elements for active and selected nodes
  5019. * tree.generateFormElements();
  5020. * // Generate input elements selected nodes, using a custom `name` attribute
  5021. * tree.generateFormElements("cust_sel", false);
  5022. * // Generate input elements using a custom filter
  5023. * tree.generateFormElements(true, true, { filter: function(node) {
  5024. * return node.isSelected() && node.data.yes;
  5025. * }});
  5026. *
  5027. * @param {boolean | string} [selected=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID[]')
  5028. * @param {boolean | string} [active=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID_active')
  5029. * @param {object} [opts] default { filter: null, stopOnParents: true }
  5030. */
  5031. generateFormElements: function(selected, active, opts) {
  5032. opts = opts || {};
  5033. var nodeList,
  5034. selectedName = (typeof selected === "string") ? selected : "ft_" + this._id + "[]",
  5035. activeName = (typeof active === "string") ? active : "ft_" + this._id + "_active",
  5036. id = "fancytree_result_" + this._id,
  5037. $result = $("#" + id),
  5038. stopOnParents = this.options.selectMode === 3 && opts.stopOnParents !== false;
  5039. if($result.length){
  5040. $result.empty();
  5041. }else{
  5042. $result = $("<div>", {
  5043. id: id
  5044. }).hide().insertAfter(this.$container);
  5045. }
  5046. if(active !== false && this.activeNode){
  5047. $result.append($("<input>", {
  5048. type: "radio",
  5049. name: activeName,
  5050. value: this.activeNode.key,
  5051. checked: true
  5052. }));
  5053. }
  5054. function _appender( node ) {
  5055. $result.append($("<input>", {
  5056. type: "checkbox",
  5057. name: selectedName,
  5058. value: node.key,
  5059. checked: true
  5060. }));
  5061. }
  5062. if ( opts.filter ) {
  5063. this.visit(function(node) {
  5064. var res = opts.filter(node);
  5065. if( res === "skip" ) { return res; }
  5066. if ( res !== false ) {
  5067. _appender(node);
  5068. }
  5069. });
  5070. } else if ( selected !== false ) {
  5071. nodeList = this.getSelectedNodes(stopOnParents);
  5072. $.each(nodeList, function(idx, node) {
  5073. _appender(node);
  5074. });
  5075. }
  5076. },
  5077. /**
  5078. * Return the currently active node or null.
  5079. * @returns {FancytreeNode}
  5080. */
  5081. getActiveNode: function() {
  5082. return this.activeNode;
  5083. },
  5084. /** Return the first top level node if any (not the invisible root node).
  5085. * @returns {FancytreeNode | null}
  5086. */
  5087. getFirstChild: function() {
  5088. return this.rootNode.getFirstChild();
  5089. },
  5090. /**
  5091. * Return node that has keyboard focus or null.
  5092. * @returns {FancytreeNode}
  5093. */
  5094. getFocusNode: function() {
  5095. return this.focusNode;
  5096. },
  5097. /**
  5098. * Return node with a given key or null if not found.
  5099. * @param {string} key
  5100. * @param {FancytreeNode} [searchRoot] only search below this node
  5101. * @returns {FancytreeNode | null}
  5102. */
  5103. getNodeByKey: function(key, searchRoot) {
  5104. // Search the DOM by element ID (assuming this is faster than traversing all nodes).
  5105. // $("#...") has problems, if the key contains '.', so we use getElementById()
  5106. var el, match;
  5107. if(!searchRoot){
  5108. el = document.getElementById(this.options.idPrefix + key);
  5109. if( el ){
  5110. return el.ftnode ? el.ftnode : null;
  5111. }
  5112. }
  5113. // Not found in the DOM, but still may be in an unrendered part of tree
  5114. // TODO: optimize with specialized loop
  5115. // TODO: consider keyMap?
  5116. searchRoot = searchRoot || this.rootNode;
  5117. match = null;
  5118. searchRoot.visit(function(node){
  5119. // window.console.log("getNodeByKey(" + key + "): ", node.key);
  5120. if(node.key === key) {
  5121. match = node;
  5122. return false;
  5123. }
  5124. }, true);
  5125. return match;
  5126. },
  5127. /** Return the invisible system root node.
  5128. * @returns {FancytreeNode}
  5129. */
  5130. getRootNode: function() {
  5131. return this.rootNode;
  5132. },
  5133. /**
  5134. * Return an array of selected nodes.
  5135. * @param {boolean} [stopOnParents=false] only return the topmost selected
  5136. * node (useful with selectMode 3)
  5137. * @returns {FancytreeNode[]}
  5138. */
  5139. getSelectedNodes: function(stopOnParents) {
  5140. return this.rootNode.getSelectedNodes(stopOnParents);
  5141. },
  5142. /** Return true if the tree control has keyboard focus
  5143. * @returns {boolean}
  5144. */
  5145. hasFocus: function(){
  5146. return !!this._hasFocus;
  5147. },
  5148. /** Write to browser console if debugLevel >= 1 (prepending tree name)
  5149. * @param {*} msg string or object or array of such
  5150. */
  5151. info: function(msg){
  5152. if( this.options.debugLevel >= 1 ) {
  5153. Array.prototype.unshift.call(arguments, this.toString());
  5154. consoleApply("info", arguments);
  5155. }
  5156. },
  5157. /*
  5158. TODO: isInitializing: function() {
  5159. return ( this.phase=="init" || this.phase=="postInit" );
  5160. },
  5161. TODO: isReloading: function() {
  5162. return ( this.phase=="init" || this.phase=="postInit" ) && this.options.persist && this.persistence.cookiesFound;
  5163. },
  5164. TODO: isUserEvent: function() {
  5165. return ( this.phase=="userEvent" );
  5166. },
  5167. */
  5168. /**
  5169. * Make sure that a node with a given ID is loaded, by traversing - and
  5170. * loading - its parents. This method is ment for lazy hierarchies.
  5171. * A callback is executed for every node as we go.
  5172. * @example
  5173. * tree.loadKeyPath("/_3/_23/_26/_27", function(node, status){
  5174. * if(status === "loaded") {
  5175. * console.log("loaded intermiediate node " + node);
  5176. * }else if(status === "ok") {
  5177. * node.activate();
  5178. * }
  5179. * });
  5180. *
  5181. * @param {string | string[]} keyPathList one or more key paths (e.g. '/3/2_1/7')
  5182. * @param {function} callback callback(node, status) is called for every visited node ('loading', 'loaded', 'ok', 'error')
  5183. * @returns {$.Promise}
  5184. */
  5185. loadKeyPath: function(keyPathList, callback, _rootNode) {
  5186. var deferredList, dfd, i, path, key, loadMap, node, root, segList,
  5187. sep = this.options.keyPathSeparator,
  5188. self = this;
  5189. callback = callback || $.noop;
  5190. if(!$.isArray(keyPathList)){
  5191. keyPathList = [keyPathList];
  5192. }
  5193. // Pass 1: handle all path segments for nodes that are already loaded
  5194. // Collect distinct top-most lazy nodes in a map
  5195. loadMap = {};
  5196. for(i=0; i<keyPathList.length; i++){
  5197. root = _rootNode || this.rootNode;
  5198. path = keyPathList[i];
  5199. // strip leading slash
  5200. if(path.charAt(0) === sep){
  5201. path = path.substr(1);
  5202. }
  5203. // traverse and strip keys, until we hit a lazy, unloaded node
  5204. segList = path.split(sep);
  5205. while(segList.length){
  5206. key = segList.shift();
  5207. // node = _findDirectChild(root, key);
  5208. node = root._findDirectChild(key);
  5209. if(!node){
  5210. this.warn("loadKeyPath: key not found: " + key + " (parent: " + root + ")");
  5211. callback.call(this, key, "error");
  5212. break;
  5213. }else if(segList.length === 0){
  5214. callback.call(this, node, "ok");
  5215. break;
  5216. }else if(!node.lazy || (node.hasChildren() !== undefined )){
  5217. callback.call(this, node, "loaded");
  5218. root = node;
  5219. }else{
  5220. callback.call(this, node, "loaded");
  5221. // segList.unshift(key);
  5222. if(loadMap[key]){
  5223. loadMap[key].push(segList.join(sep));
  5224. }else{
  5225. loadMap[key] = [segList.join(sep)];
  5226. }
  5227. break;
  5228. }
  5229. }
  5230. }
  5231. // alert("loadKeyPath: loadMap=" + JSON.stringify(loadMap));
  5232. // Now load all lazy nodes and continue itearation for remaining paths
  5233. deferredList = [];
  5234. // Avoid jshint warning 'Don't make functions within a loop.':
  5235. function __lazyload(key, node, dfd){
  5236. callback.call(self, node, "loading");
  5237. node.load().done(function(){
  5238. self.loadKeyPath.call(self, loadMap[key], callback, node).always(_makeResolveFunc(dfd, self));
  5239. }).fail(function(errMsg){
  5240. self.warn("loadKeyPath: error loading: " + key + " (parent: " + root + ")");
  5241. callback.call(self, node, "error");
  5242. dfd.reject();
  5243. });
  5244. }
  5245. for(key in loadMap){
  5246. node = root._findDirectChild(key);
  5247. if (node == null) { // #576
  5248. node = self.getNodeByKey(key);
  5249. }
  5250. dfd = new $.Deferred();
  5251. deferredList.push(dfd);
  5252. __lazyload(key, node, dfd);
  5253. }
  5254. // Return a promise that is resolved, when ALL paths were loaded
  5255. return $.when.apply($, deferredList).promise();
  5256. },
  5257. /** Re-fire beforeActivate, activate, and (optional) focus events.
  5258. * Calling this method in the `init` event, will activate the node that
  5259. * was marked 'active' in the source data, and optionally set the keyboard
  5260. * focus.
  5261. * @param [setFocus=false]
  5262. */
  5263. reactivate: function(setFocus) {
  5264. var res,
  5265. node = this.activeNode;
  5266. if( !node ) {
  5267. return _getResolvedPromise();
  5268. }
  5269. this.activeNode = null; // Force re-activating
  5270. res = node.setActive(true, {noFocus: true});
  5271. if( setFocus ){
  5272. node.setFocus();
  5273. }
  5274. return res;
  5275. },
  5276. /** Reload tree from source and return a promise.
  5277. * @param [source] optional new source (defaults to initial source data)
  5278. * @returns {$.Promise}
  5279. */
  5280. reload: function(source) {
  5281. this._callHook("treeClear", this);
  5282. return this._callHook("treeLoad", this, source);
  5283. },
  5284. /**Render tree (i.e. create DOM elements for all top-level nodes).
  5285. * @param {boolean} [force=false] create DOM elemnts, even if parent is collapsed
  5286. * @param {boolean} [deep=false]
  5287. */
  5288. render: function(force, deep) {
  5289. return this.rootNode.render(force, deep);
  5290. },
  5291. // TODO: selectKey: function(key, select)
  5292. // TODO: serializeArray: function(stopOnParents)
  5293. /**
  5294. * @param {boolean} [flag=true]
  5295. */
  5296. setFocus: function(flag) {
  5297. return this._callHook("treeSetFocus", this, flag);
  5298. },
  5299. /**
  5300. * Return all nodes as nested list of {@link NodeData}.
  5301. *
  5302. * @param {boolean} [includeRoot=false] Returns the hidden system root node (and its children)
  5303. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications
  5304. * @returns {Array | object}
  5305. * @see FancytreeNode#toDict
  5306. */
  5307. toDict: function(includeRoot, callback){
  5308. var res = this.rootNode.toDict(true, callback);
  5309. return includeRoot ? res : res.children;
  5310. },
  5311. /* Implicitly called for string conversions.
  5312. * @returns {string}
  5313. */
  5314. toString: function(){
  5315. return "<Fancytree(#" + this._id + ")>";
  5316. },
  5317. /* _trigger a widget event with additional node ctx.
  5318. * @see EventData
  5319. */
  5320. _triggerNodeEvent: function(type, node, originalEvent, extra) {
  5321. // this.debug("_trigger(" + type + "): '" + ctx.node.title + "'", ctx);
  5322. var ctx = this._makeHookContext(node, originalEvent, extra),
  5323. res = this.widget._trigger(type, originalEvent, ctx);
  5324. if(res !== false && ctx.result !== undefined){
  5325. return ctx.result;
  5326. }
  5327. return res;
  5328. },
  5329. /* _trigger a widget event with additional tree data. */
  5330. _triggerTreeEvent: function(type, originalEvent, extra) {
  5331. // this.debug("_trigger(" + type + ")", ctx);
  5332. var ctx = this._makeHookContext(this, originalEvent, extra),
  5333. res = this.widget._trigger(type, originalEvent, ctx);
  5334. if(res !== false && ctx.result !== undefined){
  5335. return ctx.result;
  5336. }
  5337. return res;
  5338. },
  5339. /** Call fn(node) for all nodes.
  5340. *
  5341. * @param {function} fn the callback function.
  5342. * Return false to stop iteration, return "skip" to skip this node and children only.
  5343. * @returns {boolean} false, if the iterator was stopped.
  5344. */
  5345. visit: function(fn) {
  5346. return this.rootNode.visit(fn, false);
  5347. },
  5348. /** Write warning to browser console (prepending tree info)
  5349. *
  5350. * @param {*} msg string or object or array of such
  5351. */
  5352. warn: function(msg){
  5353. Array.prototype.unshift.call(arguments, this.toString());
  5354. consoleApply("warn", arguments);
  5355. }
  5356. };
  5357. /**
  5358. * These additional methods of the {@link Fancytree} class are 'hook functions'
  5359. * that can be used and overloaded by extensions.
  5360. * (See <a href="https://github.com/mar10/fancytree/wiki/TutorialExtensions">writing extensions</a>.)
  5361. * @mixin Fancytree_Hooks
  5362. */
  5363. $.extend(Fancytree.prototype,
  5364. /** @lends Fancytree_Hooks# */
  5365. {
  5366. /** Default handling for mouse click events.
  5367. *
  5368. * @param {EventData} ctx
  5369. */
  5370. nodeClick: function(ctx) {
  5371. var activate, expand,
  5372. // event = ctx.originalEvent,
  5373. targetType = ctx.targetType,
  5374. node = ctx.node;
  5375. // this.debug("ftnode.onClick(" + event.type + "): ftnode:" + this + ", button:" + event.button + ", which: " + event.which, ctx);
  5376. // TODO: use switch
  5377. // TODO: make sure clicks on embedded <input> doesn't steal focus (see table sample)
  5378. if( targetType === "expander" ) {
  5379. if( node.isLoading() ) {
  5380. // #495: we probably got a click event while a lazy load is pending.
  5381. // The 'expanded' state is not yet set, so 'toggle' would expand
  5382. // and trigger lazyLoad again.
  5383. // It would be better to allow to collapse/expand the status node
  5384. // while loading (instead of ignoring), but that would require some
  5385. // more work.
  5386. node.debug("Got 2nd click while loading: ignored");
  5387. return;
  5388. }
  5389. // Clicking the expander icon always expands/collapses
  5390. this._callHook("nodeToggleExpanded", ctx);
  5391. } else if( targetType === "checkbox" ) {
  5392. // Clicking the checkbox always (de)selects
  5393. this._callHook("nodeToggleSelected", ctx);
  5394. if( ctx.options.focusOnSelect ) { // #358
  5395. this._callHook("nodeSetFocus", ctx, true);
  5396. }
  5397. } else {
  5398. // Honor `clickFolderMode` for
  5399. expand = false;
  5400. activate = true;
  5401. if( node.folder ) {
  5402. switch( ctx.options.clickFolderMode ) {
  5403. case 2: // expand only
  5404. expand = true;
  5405. activate = false;
  5406. break;
  5407. case 3: // expand and activate
  5408. activate = true;
  5409. expand = true; //!node.isExpanded();
  5410. break;
  5411. // else 1 or 4: just activate
  5412. }
  5413. }
  5414. if( activate ) {
  5415. this.nodeSetFocus(ctx);
  5416. this._callHook("nodeSetActive", ctx, true);
  5417. }
  5418. if( expand ) {
  5419. if(!activate){
  5420. // this._callHook("nodeSetFocus", ctx);
  5421. }
  5422. // this._callHook("nodeSetExpanded", ctx, true);
  5423. this._callHook("nodeToggleExpanded", ctx);
  5424. }
  5425. }
  5426. // Make sure that clicks stop, otherwise <a href='#'> jumps to the top
  5427. // if(event.target.localName === "a" && event.target.className === "fancytree-title"){
  5428. // event.preventDefault();
  5429. // }
  5430. // TODO: return promise?
  5431. },
  5432. /** Collapse all other children of same parent.
  5433. *
  5434. * @param {EventData} ctx
  5435. * @param {object} callOpts
  5436. */
  5437. nodeCollapseSiblings: function(ctx, callOpts) {
  5438. // TODO: return promise?
  5439. var ac, i, l,
  5440. node = ctx.node;
  5441. if( node.parent ){
  5442. ac = node.parent.children;
  5443. for (i=0, l=ac.length; i<l; i++) {
  5444. if ( ac[i] !== node && ac[i].expanded ){
  5445. this._callHook("nodeSetExpanded", ac[i], false, callOpts);
  5446. }
  5447. }
  5448. }
  5449. },
  5450. /** Default handling for mouse douleclick events.
  5451. * @param {EventData} ctx
  5452. */
  5453. nodeDblclick: function(ctx) {
  5454. // TODO: return promise?
  5455. if( ctx.targetType === "title" && ctx.options.clickFolderMode === 4) {
  5456. // this.nodeSetFocus(ctx);
  5457. // this._callHook("nodeSetActive", ctx, true);
  5458. this._callHook("nodeToggleExpanded", ctx);
  5459. }
  5460. // TODO: prevent text selection on dblclicks
  5461. if( ctx.targetType === "title" ) {
  5462. ctx.originalEvent.preventDefault();
  5463. }
  5464. },
  5465. /** Default handling for mouse keydown events.
  5466. *
  5467. * NOTE: this may be called with node == null if tree (but no node) has focus.
  5468. * @param {EventData} ctx
  5469. */
  5470. nodeKeydown: function(ctx) {
  5471. // TODO: return promise?
  5472. var matchNode, stamp, res, focusNode,
  5473. event = ctx.originalEvent,
  5474. node = ctx.node,
  5475. tree = ctx.tree,
  5476. opts = ctx.options,
  5477. which = event.which,
  5478. whichChar = String.fromCharCode(which),
  5479. clean = !(event.altKey || event.ctrlKey || event.metaKey || event.shiftKey),
  5480. $target = $(event.target),
  5481. handled = true,
  5482. activate = !(event.ctrlKey || !opts.autoActivate );
  5483. // (node || FT).debug("ftnode.nodeKeydown(" + event.type + "): ftnode:" + this + ", charCode:" + event.charCode + ", keyCode: " + event.keyCode + ", which: " + event.which);
  5484. // FT.debug("eventToString", which, '"' + String.fromCharCode(which) + '"', '"' + FT.eventToString(event) + '"');
  5485. // Set focus to active (or first node) if no other node has the focus yet
  5486. if( !node ){
  5487. focusNode = (this.getActiveNode() || this.getFirstChild());
  5488. if (focusNode){
  5489. focusNode.setFocus();
  5490. node = ctx.node = this.focusNode;
  5491. node.debug("Keydown force focus on active node");
  5492. }
  5493. }
  5494. if( opts.quicksearch && clean && /\w/.test(whichChar) &&
  5495. !SPECIAL_KEYCODES[which] && // #659
  5496. !$target.is(":input:enabled") ) {
  5497. // Allow to search for longer streaks if typed in quickly
  5498. stamp = new Date().getTime();
  5499. if( stamp - tree.lastQuicksearchTime > 500 ) {
  5500. tree.lastQuicksearchTerm = "";
  5501. }
  5502. tree.lastQuicksearchTime = stamp;
  5503. tree.lastQuicksearchTerm += whichChar;
  5504. // tree.debug("quicksearch find", tree.lastQuicksearchTerm);
  5505. matchNode = tree.findNextNode(tree.lastQuicksearchTerm, tree.getActiveNode());
  5506. if( matchNode ) {
  5507. matchNode.setActive();
  5508. }
  5509. event.preventDefault();
  5510. return;
  5511. }
  5512. switch( FT.eventToString(event) ) {
  5513. case "+":
  5514. case "=": // 187: '+' @ Chrome, Safari
  5515. tree.nodeSetExpanded(ctx, true);
  5516. break;
  5517. case "-":
  5518. tree.nodeSetExpanded(ctx, false);
  5519. break;
  5520. case "space":
  5521. if( node.isPagingNode() ) {
  5522. tree._triggerNodeEvent("clickPaging", ctx, event);
  5523. } else if( FT.evalOption("checkbox", node, node, opts, false) ) { // #768
  5524. tree.nodeToggleSelected(ctx);
  5525. }else{
  5526. tree.nodeSetActive(ctx, true);
  5527. }
  5528. break;
  5529. case "return":
  5530. tree.nodeSetActive(ctx, true);
  5531. break;
  5532. case "home":
  5533. case "end":
  5534. case "backspace":
  5535. case "left":
  5536. case "right":
  5537. case "up":
  5538. case "down":
  5539. res = node.navigate(event.which, activate, true);
  5540. break;
  5541. default:
  5542. handled = false;
  5543. }
  5544. if(handled){
  5545. event.preventDefault();
  5546. }
  5547. },
  5548. // /** Default handling for mouse keypress events. */
  5549. // nodeKeypress: function(ctx) {
  5550. // var event = ctx.originalEvent;
  5551. // },
  5552. // /** Trigger lazyLoad event (async). */
  5553. // nodeLazyLoad: function(ctx) {
  5554. // var node = ctx.node;
  5555. // if(this._triggerNodeEvent())
  5556. // },
  5557. /** Load child nodes (async).
  5558. *
  5559. * @param {EventData} ctx
  5560. * @param {object[]|object|string|$.Promise|function} source
  5561. * @returns {$.Promise} The deferred will be resolved as soon as the (ajax)
  5562. * data was rendered.
  5563. */
  5564. nodeLoadChildren: function(ctx, source) {
  5565. var ajax, delay, dfd,
  5566. tree = ctx.tree,
  5567. node = ctx.node,
  5568. requestId = new Date().getTime();
  5569. if($.isFunction(source)){
  5570. source = source.call(tree, {type: "source"}, ctx);
  5571. _assert(!$.isFunction(source), "source callback must not return another function");
  5572. }
  5573. if(source.url){
  5574. if( node._requestId ) {
  5575. node.warn("Recursive load request #" + requestId + " while #" + node._requestId + " is pending.");
  5576. // } else {
  5577. // node.debug("Send load request #" + requestId);
  5578. }
  5579. // `source` is an Ajax options object
  5580. ajax = $.extend({}, ctx.options.ajax, source);
  5581. node._requestId = requestId;
  5582. if(ajax.debugDelay){
  5583. // simulate a slow server
  5584. delay = ajax.debugDelay;
  5585. if($.isArray(delay)){ // random delay range [min..max]
  5586. delay = delay[0] + Math.random() * (delay[1] - delay[0]);
  5587. }
  5588. node.warn("nodeLoadChildren waiting debugDelay " + Math.round(delay) + " ms ...");
  5589. ajax.debugDelay = false;
  5590. dfd = $.Deferred(function (dfd) {
  5591. setTimeout(function () {
  5592. $.ajax(ajax)
  5593. .done(function () { dfd.resolveWith(this, arguments); })
  5594. .fail(function () { dfd.rejectWith(this, arguments); });
  5595. }, delay);
  5596. });
  5597. }else{
  5598. dfd = $.ajax(ajax);
  5599. }
  5600. // Defer the deferred: we want to be able to reject, even if ajax
  5601. // resolved ok.
  5602. source = new $.Deferred();
  5603. dfd.done(function (data, textStatus, jqXHR) {
  5604. var errorObj, res;
  5605. if((this.dataType === "json" || this.dataType === "jsonp") && typeof data === "string"){
  5606. $.error("Ajax request returned a string (did you get the JSON dataType wrong?).");
  5607. }
  5608. if( node._requestId && node._requestId > requestId ) {
  5609. // The expected request time stamp is later than `requestId`
  5610. // (which was kept as as closure variable to this handler function)
  5611. // node.warn("Ignored load response for obsolete request #" + requestId + " (expected #" + node._requestId + ")");
  5612. source.rejectWith(this, [RECURSIVE_REQUEST_ERROR]);
  5613. return;
  5614. // } else {
  5615. // node.debug("Response returned for load request #" + requestId);
  5616. }
  5617. // postProcess is similar to the standard ajax dataFilter hook,
  5618. // but it is also called for JSONP
  5619. if( ctx.options.postProcess ){
  5620. try {
  5621. res = tree._triggerNodeEvent("postProcess", ctx, ctx.originalEvent, {
  5622. response: data, error: null, dataType: this.dataType
  5623. });
  5624. } catch(e) {
  5625. res = { error: e, message: "" + e, details: "postProcess failed"};
  5626. }
  5627. if( res.error ) {
  5628. errorObj = $.isPlainObject(res.error) ? res.error : {message: res.error};
  5629. errorObj = tree._makeHookContext(node, null, errorObj);
  5630. source.rejectWith(this, [errorObj]);
  5631. return;
  5632. }
  5633. data = $.isArray(res) ? res : data;
  5634. } else if (data && data.hasOwnProperty("d") && ctx.options.enableAspx ) {
  5635. // Process ASPX WebMethod JSON object inside "d" property
  5636. data = (typeof data.d === "string") ? $.parseJSON(data.d) : data.d;
  5637. }
  5638. source.resolveWith(this, [data]);
  5639. }).fail(function (jqXHR, textStatus, errorThrown) {
  5640. var errorObj = tree._makeHookContext(node, null, {
  5641. error: jqXHR,
  5642. args: Array.prototype.slice.call(arguments),
  5643. message: errorThrown,
  5644. details: jqXHR.status + ": " + errorThrown
  5645. });
  5646. source.rejectWith(this, [errorObj]);
  5647. });
  5648. }
  5649. // #383: accept and convert ECMAScript 6 Promise
  5650. if( $.isFunction(source.then) && $.isFunction(source["catch"]) ) {
  5651. dfd = source;
  5652. source = new $.Deferred();
  5653. dfd.then(function(value){
  5654. source.resolve(value);
  5655. }, function(reason){
  5656. source.reject(reason);
  5657. });
  5658. }
  5659. if($.isFunction(source.promise)){
  5660. // `source` is a deferred, i.e. ajax request
  5661. // _assert(!node.isLoading(), "recursive load");
  5662. tree.nodeSetStatus(ctx, "loading");
  5663. source.done(function (children) {
  5664. tree.nodeSetStatus(ctx, "ok");
  5665. node._requestId = null;
  5666. }).fail(function(error){
  5667. var ctxErr;
  5668. if ( error === RECURSIVE_REQUEST_ERROR ) {
  5669. node.warn("Ignored response for obsolete load request #" + requestId + " (expected #" + node._requestId + ")");
  5670. return;
  5671. } else if (error.node && error.error && error.message) {
  5672. // error is already a context object
  5673. ctxErr = error;
  5674. } else {
  5675. ctxErr = tree._makeHookContext(node, null, {
  5676. error: error, // it can be jqXHR or any custom error
  5677. args: Array.prototype.slice.call(arguments),
  5678. message: error ? (error.message || error.toString()) : ""
  5679. });
  5680. if( ctxErr.message === "[object Object]" ) {
  5681. ctxErr.message = "";
  5682. }
  5683. }
  5684. node.warn("Load children failed (" + ctxErr.message + ")", ctxErr);
  5685. if( tree._triggerNodeEvent("loadError", ctxErr, null) !== false ) {
  5686. tree.nodeSetStatus(ctx, "error", ctxErr.message, ctxErr.details);
  5687. }
  5688. });
  5689. } else {
  5690. if( ctx.options.postProcess ){
  5691. // #792: Call postProcess for non-deferred source
  5692. tree._triggerNodeEvent("postProcess", ctx, ctx.originalEvent, {
  5693. response: source, error: null, dataType: typeof source
  5694. });
  5695. }
  5696. }
  5697. // $.when(source) resolves also for non-deferreds
  5698. return $.when(source).done(function(children){
  5699. var metaData;
  5700. if( $.isPlainObject(children) ){
  5701. // We got {foo: 'abc', children: [...]}
  5702. // Copy extra properties to tree.data.foo
  5703. _assert(node.isRootNode(), "source may only be an object for root nodes (expecting an array of child objects otherwise)");
  5704. _assert($.isArray(children.children), "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')");
  5705. metaData = children;
  5706. children = children.children;
  5707. delete metaData.children;
  5708. $.extend(tree.data, metaData);
  5709. }
  5710. _assert($.isArray(children), "expected array of children");
  5711. node._setChildren(children);
  5712. // trigger fancytreeloadchildren
  5713. tree._triggerNodeEvent("loadChildren", node);
  5714. });
  5715. },
  5716. /** [Not Implemented] */
  5717. nodeLoadKeyPath: function(ctx, keyPathList) {
  5718. // TODO: implement and improve
  5719. // http://code.google.com/p/dynatree/issues/detail?id=222
  5720. },
  5721. /**
  5722. * Remove a single direct child of ctx.node.
  5723. * @param {EventData} ctx
  5724. * @param {FancytreeNode} childNode dircect child of ctx.node
  5725. */
  5726. nodeRemoveChild: function(ctx, childNode) {
  5727. var idx,
  5728. node = ctx.node,
  5729. // opts = ctx.options,
  5730. subCtx = $.extend({}, ctx, {node: childNode}),
  5731. children = node.children;
  5732. // FT.debug("nodeRemoveChild()", node.toString(), childNode.toString());
  5733. if( children.length === 1 ) {
  5734. _assert(childNode === children[0], "invalid single child");
  5735. return this.nodeRemoveChildren(ctx);
  5736. }
  5737. if( this.activeNode && (childNode === this.activeNode || this.activeNode.isDescendantOf(childNode))){
  5738. this.activeNode.setActive(false); // TODO: don't fire events
  5739. }
  5740. if( this.focusNode && (childNode === this.focusNode || this.focusNode.isDescendantOf(childNode))){
  5741. this.focusNode = null;
  5742. }
  5743. // TODO: persist must take care to clear select and expand cookies
  5744. this.nodeRemoveMarkup(subCtx);
  5745. this.nodeRemoveChildren(subCtx);
  5746. idx = $.inArray(childNode, children);
  5747. _assert(idx >= 0, "invalid child");
  5748. // Notify listeners
  5749. node.triggerModifyChild("remove", childNode);
  5750. // Unlink to support GC
  5751. childNode.visit(function(n){
  5752. n.parent = null;
  5753. }, true);
  5754. this._callHook("treeRegisterNode", this, false, childNode);
  5755. // remove from child list
  5756. children.splice(idx, 1);
  5757. },
  5758. /**Remove HTML markup for all descendents of ctx.node.
  5759. * @param {EventData} ctx
  5760. */
  5761. nodeRemoveChildMarkup: function(ctx) {
  5762. var node = ctx.node;
  5763. // FT.debug("nodeRemoveChildMarkup()", node.toString());
  5764. // TODO: Unlink attr.ftnode to support GC
  5765. if(node.ul){
  5766. if( node.isRootNode() ) {
  5767. $(node.ul).empty();
  5768. } else {
  5769. $(node.ul).remove();
  5770. node.ul = null;
  5771. }
  5772. node.visit(function(n){
  5773. n.li = n.ul = null;
  5774. });
  5775. }
  5776. },
  5777. /**Remove all descendants of ctx.node.
  5778. * @param {EventData} ctx
  5779. */
  5780. nodeRemoveChildren: function(ctx) {
  5781. var subCtx,
  5782. tree = ctx.tree,
  5783. node = ctx.node,
  5784. children = node.children;
  5785. // opts = ctx.options;
  5786. // FT.debug("nodeRemoveChildren()", node.toString());
  5787. if(!children){
  5788. return;
  5789. }
  5790. if( this.activeNode && this.activeNode.isDescendantOf(node)){
  5791. this.activeNode.setActive(false); // TODO: don't fire events
  5792. }
  5793. if( this.focusNode && this.focusNode.isDescendantOf(node)){
  5794. this.focusNode = null;
  5795. }
  5796. // TODO: persist must take care to clear select and expand cookies
  5797. this.nodeRemoveChildMarkup(ctx);
  5798. // Unlink children to support GC
  5799. // TODO: also delete this.children (not possible using visit())
  5800. subCtx = $.extend({}, ctx);
  5801. node.triggerModifyChild("remove", null);
  5802. node.visit(function(n){
  5803. n.parent = null;
  5804. tree._callHook("treeRegisterNode", tree, false, n);
  5805. });
  5806. if( node.lazy ){
  5807. // 'undefined' would be interpreted as 'not yet loaded' for lazy nodes
  5808. node.children = [];
  5809. } else{
  5810. node.children = null;
  5811. }
  5812. if( !node.isRootNode() ) {
  5813. node.expanded = false; // #449, #459
  5814. }
  5815. this.nodeRenderStatus(ctx);
  5816. },
  5817. /**Remove HTML markup for ctx.node and all its descendents.
  5818. * @param {EventData} ctx
  5819. */
  5820. nodeRemoveMarkup: function(ctx) {
  5821. var node = ctx.node;
  5822. // FT.debug("nodeRemoveMarkup()", node.toString());
  5823. // TODO: Unlink attr.ftnode to support GC
  5824. if(node.li){
  5825. $(node.li).remove();
  5826. node.li = null;
  5827. }
  5828. this.nodeRemoveChildMarkup(ctx);
  5829. },
  5830. /**
  5831. * Create `&lt;li>&lt;span>..&lt;/span> .. &lt;/li>` tags for this node.
  5832. *
  5833. * This method takes care that all HTML markup is created that is required
  5834. * to display this node in its current state.
  5835. *
  5836. * Call this method to create new nodes, or after the strucuture
  5837. * was changed (e.g. after moving this node or adding/removing children)
  5838. * nodeRenderTitle() and nodeRenderStatus() are implied.
  5839. *
  5840. * &lt;code>
  5841. * &lt;li id='KEY' ftnode=NODE>
  5842. * &lt;span class='fancytree-node fancytree-expanded fancytree-has-children fancytree-lastsib fancytree-exp-el fancytree-ico-e'>
  5843. * &lt;span class="fancytree-expander">&lt;/span>
  5844. * &lt;span class="fancytree-checkbox">&lt;/span> // only present in checkbox mode
  5845. * &lt;span class="fancytree-icon">&lt;/span>
  5846. * &lt;a href="#" class="fancytree-title"> Node 1 &lt;/a>
  5847. * &lt;/span>
  5848. * &lt;ul> // only present if node has children
  5849. * &lt;li id='KEY' ftnode=NODE> child1 ... &lt;/li>
  5850. * &lt;li id='KEY' ftnode=NODE> child2 ... &lt;/li>
  5851. * &lt;/ul>
  5852. * &lt;/li>
  5853. * &lt;/code>
  5854. *
  5855. * @param {EventData} ctx
  5856. * @param {boolean} [force=false] re-render, even if html markup was already created
  5857. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  5858. * @param {boolean} [collapsed=false] force root node to be collapsed, so we can apply animated expand later
  5859. */
  5860. nodeRender: function(ctx, force, deep, collapsed, _recursive) {
  5861. /* This method must take care of all cases where the current data mode
  5862. * (i.e. node hierarchy) does not match the current markup.
  5863. *
  5864. * - node was not yet rendered:
  5865. * create markup
  5866. * - node was rendered: exit fast
  5867. * - children have been added
  5868. * - children have been removed
  5869. */
  5870. var childLI, childNode1, childNode2, i, l, next, subCtx,
  5871. node = ctx.node,
  5872. tree = ctx.tree,
  5873. opts = ctx.options,
  5874. aria = opts.aria,
  5875. firstTime = false,
  5876. parent = node.parent,
  5877. isRootNode = !parent,
  5878. children = node.children,
  5879. successorLi = null;
  5880. // FT.debug("nodeRender(" + !!force + ", " + !!deep + ")", node.toString());
  5881. if( tree._enableUpdate === false ) {
  5882. // tree.debug("no render", tree._enableUpdate);
  5883. return;
  5884. }
  5885. if( ! isRootNode && ! parent.ul ) {
  5886. // Calling node.collapse on a deep, unrendered node
  5887. return;
  5888. }
  5889. _assert(isRootNode || parent.ul, "parent UL must exist");
  5890. // Render the node
  5891. if( !isRootNode ){
  5892. // Discard markup on force-mode, or if it is not linked to parent <ul>
  5893. if(node.li && (force || (node.li.parentNode !== node.parent.ul) ) ){
  5894. if( node.li.parentNode === node.parent.ul ){
  5895. // #486: store following node, so we can insert the new markup there later
  5896. successorLi = node.li.nextSibling;
  5897. }else{
  5898. // May happen, when a top-level node was dropped over another
  5899. this.debug("Unlinking " + node + " (must be child of " + node.parent + ")");
  5900. }
  5901. // this.debug("nodeRemoveMarkup...");
  5902. this.nodeRemoveMarkup(ctx);
  5903. }
  5904. // Create <li><span /> </li>
  5905. // node.debug("render...");
  5906. if( !node.li ) {
  5907. // node.debug("render... really");
  5908. firstTime = true;
  5909. node.li = document.createElement("li");
  5910. node.li.ftnode = node;
  5911. if( node.key && opts.generateIds ){
  5912. node.li.id = opts.idPrefix + node.key;
  5913. }
  5914. node.span = document.createElement("span");
  5915. node.span.className = "fancytree-node";
  5916. if( aria && !node.tr ) {
  5917. $(node.li).attr("role", "treeitem");
  5918. }
  5919. node.li.appendChild(node.span);
  5920. // Create inner HTML for the <span> (expander, checkbox, icon, and title)
  5921. this.nodeRenderTitle(ctx);
  5922. // Allow tweaking and binding, after node was created for the first time
  5923. if ( opts.createNode ){
  5924. opts.createNode.call(tree, {type: "createNode"}, ctx);
  5925. }
  5926. }else{
  5927. // this.nodeRenderTitle(ctx);
  5928. this.nodeRenderStatus(ctx);
  5929. }
  5930. // Allow tweaking after node state was rendered
  5931. if ( opts.renderNode ){
  5932. opts.renderNode.call(tree, {type: "renderNode"}, ctx);
  5933. }
  5934. }
  5935. // Visit child nodes
  5936. if( children ){
  5937. if( isRootNode || node.expanded || deep === true ) {
  5938. // Create a UL to hold the children
  5939. if( !node.ul ){
  5940. node.ul = document.createElement("ul");
  5941. if((collapsed === true && !_recursive) || !node.expanded){
  5942. // hide top UL, so we can use an animation to show it later
  5943. node.ul.style.display = "none";
  5944. }
  5945. if(aria){
  5946. $(node.ul).attr("role", "group");
  5947. }
  5948. if ( node.li ) { // issue #67
  5949. node.li.appendChild(node.ul);
  5950. } else {
  5951. node.tree.$div.append(node.ul);
  5952. }
  5953. }
  5954. // Add child markup
  5955. for(i=0, l=children.length; i<l; i++) {
  5956. subCtx = $.extend({}, ctx, {node: children[i]});
  5957. this.nodeRender(subCtx, force, deep, false, true);
  5958. }
  5959. // Remove <li> if nodes have moved to another parent
  5960. childLI = node.ul.firstChild;
  5961. while( childLI ){
  5962. childNode2 = childLI.ftnode;
  5963. if( childNode2 && childNode2.parent !== node ) {
  5964. node.debug("_fixParent: remove missing " + childNode2, childLI);
  5965. next = childLI.nextSibling;
  5966. childLI.parentNode.removeChild(childLI);
  5967. childLI = next;
  5968. }else{
  5969. childLI = childLI.nextSibling;
  5970. }
  5971. }
  5972. // Make sure, that <li> order matches node.children order.
  5973. childLI = node.ul.firstChild;
  5974. for(i=0, l=children.length-1; i<l; i++) {
  5975. childNode1 = children[i];
  5976. childNode2 = childLI.ftnode;
  5977. if( childNode1 !== childNode2 ) {
  5978. // node.debug("_fixOrder: mismatch at index " + i + ": " + childNode1 + " != " + childNode2);
  5979. node.ul.insertBefore(childNode1.li, childNode2.li);
  5980. } else {
  5981. childLI = childLI.nextSibling;
  5982. }
  5983. }
  5984. }
  5985. }else{
  5986. // No children: remove markup if any
  5987. if( node.ul ){
  5988. // alert("remove child markup for " + node);
  5989. this.warn("remove child markup for " + node);
  5990. this.nodeRemoveChildMarkup(ctx);
  5991. }
  5992. }
  5993. if( !isRootNode ){
  5994. // Update element classes according to node state
  5995. // this.nodeRenderStatus(ctx);
  5996. // Finally add the whole structure to the DOM, so the browser can render
  5997. if( firstTime ){
  5998. // #486: successorLi is set, if we re-rendered (i.e. discarded)
  5999. // existing markup, which we want to insert at the same position.
  6000. // (null is equivalent to append)
  6001. // parent.ul.appendChild(node.li);
  6002. parent.ul.insertBefore(node.li, successorLi);
  6003. }
  6004. }
  6005. },
  6006. /** Create HTML inside the node's outer &lt;span> (i.e. expander, checkbox,
  6007. * icon, and title).
  6008. *
  6009. * nodeRenderStatus() is implied.
  6010. * @param {EventData} ctx
  6011. * @param {string} [title] optinal new title
  6012. */
  6013. nodeRenderTitle: function(ctx, title) {
  6014. // set node connector images, links and text
  6015. var checkbox, className, icon, nodeTitle, role, tabindex, tooltip,
  6016. node = ctx.node,
  6017. tree = ctx.tree,
  6018. opts = ctx.options,
  6019. aria = opts.aria,
  6020. level = node.getLevel(),
  6021. ares = [];
  6022. if(title !== undefined){
  6023. node.title = title;
  6024. }
  6025. if ( !node.span || tree._enableUpdate === false ) {
  6026. // Silently bail out if node was not rendered yet, assuming
  6027. // node.render() will be called as the node becomes visible
  6028. return;
  6029. }
  6030. // Connector (expanded, expandable or simple)
  6031. role = (aria && node.hasChildren() !== false) ? " role='button'" : "";
  6032. if( level < opts.minExpandLevel ) {
  6033. if( !node.lazy ) {
  6034. node.expanded = true;
  6035. }
  6036. if(level > 1){
  6037. ares.push("<span " + role + " class='fancytree-expander fancytree-expander-fixed'></span>");
  6038. }
  6039. // .. else (i.e. for root level) skip expander/connector alltogether
  6040. } else {
  6041. ares.push("<span " + role + " class='fancytree-expander'></span>");
  6042. }
  6043. // Checkbox mode
  6044. checkbox = FT.evalOption("checkbox", node, node, opts, false);
  6045. if( checkbox && !node.isStatusNode() ) {
  6046. role = aria ? " role='checkbox'" : "";
  6047. className = "fancytree-checkbox";
  6048. if( checkbox === "radio" || (node.parent && node.parent.radiogroup) ) {
  6049. className += " fancytree-radio";
  6050. }
  6051. ares.push("<span " + role + " class='" + className + "'></span>");
  6052. }
  6053. // Folder or doctype icon
  6054. if( node.data.iconClass !== undefined ) { // 2015-11-16
  6055. // Handle / warn about backward compatibility
  6056. if( node.icon ) {
  6057. $.error("'iconClass' node option is deprecated since v2.14.0: use 'icon' only instead");
  6058. } else {
  6059. node.warn("'iconClass' node option is deprecated since v2.14.0: use 'icon' instead");
  6060. node.icon = node.data.iconClass;
  6061. }
  6062. }
  6063. // If opts.icon is a callback and returns something other than undefined, use that
  6064. // else if node.icon is a boolean or string, use that
  6065. // else if opts.icon is a boolean or string, use that
  6066. // else show standard icon (which may be different for folders or documents)
  6067. icon = FT.evalOption("icon", node, node, opts, true);
  6068. if( typeof icon !== "boolean" ) {
  6069. // icon is defined, but not true/false: must be a string
  6070. icon = "" + icon;
  6071. }
  6072. if( icon !== false ) {
  6073. role = aria ? " role='presentation'" : "";
  6074. if ( typeof icon === "string" ) {
  6075. if( TEST_IMG.test(icon) ) {
  6076. // node.icon is an image url. Prepend imagePath
  6077. icon = (icon.charAt(0) === "/") ? icon : ((opts.imagePath || "") + icon);
  6078. ares.push("<img src='" + icon + "' class='fancytree-icon' alt='' />");
  6079. } else {
  6080. ares.push("<span " + role + " class='fancytree-custom-icon " + icon + "'></span>");
  6081. }
  6082. } else {
  6083. // standard icon: theme css will take care of this
  6084. ares.push("<span " + role + " class='fancytree-icon'></span>");
  6085. }
  6086. }
  6087. // Node title
  6088. nodeTitle = "";
  6089. if ( opts.renderTitle ){
  6090. nodeTitle = opts.renderTitle.call(tree, {type: "renderTitle"}, ctx) || "";
  6091. }
  6092. if ( !nodeTitle ) {
  6093. tooltip = FT.evalOption("tooltip", node, node, opts, null);
  6094. if( tooltip === true ) {
  6095. tooltip = node.title;
  6096. }
  6097. // if( node.tooltip ) {
  6098. // tooltip = node.tooltip;
  6099. // } else if ( opts.tooltip ) {
  6100. // tooltip = opts.tooltip === true ? node.title : opts.tooltip.call(tree, node);
  6101. // }
  6102. tooltip = tooltip ? " title='" + _escapeTooltip(tooltip) + "'" : "";
  6103. tabindex = opts.titlesTabbable ? " tabindex='0'" : "";
  6104. nodeTitle = "<span class='fancytree-title'" +
  6105. tooltip + tabindex + ">" +
  6106. (opts.escapeTitles ? FT.escapeHtml(node.title) : node.title) +
  6107. "</span>";
  6108. }
  6109. ares.push(nodeTitle);
  6110. // Note: this will trigger focusout, if node had the focus
  6111. //$(node.span).html(ares.join("")); // it will cleanup the jQuery data currently associated with SPAN (if any), but it executes more slowly
  6112. node.span.innerHTML = ares.join("");
  6113. // Update CSS classes
  6114. this.nodeRenderStatus(ctx);
  6115. if ( opts.enhanceTitle ){
  6116. ctx.$title = $(">span.fancytree-title", node.span);
  6117. nodeTitle = opts.enhanceTitle.call(tree, {type: "enhanceTitle"}, ctx) || "";
  6118. }
  6119. },
  6120. /** Update element classes according to node state.
  6121. * @param {EventData} ctx
  6122. */
  6123. nodeRenderStatus: function(ctx) {
  6124. // Set classes for current status
  6125. var $ariaElem,
  6126. node = ctx.node,
  6127. tree = ctx.tree,
  6128. opts = ctx.options,
  6129. // nodeContainer = node[tree.nodeContainerAttrName],
  6130. hasChildren = node.hasChildren(),
  6131. isLastSib = node.isLastSibling(),
  6132. aria = opts.aria,
  6133. cn = opts._classNames,
  6134. cnList = [],
  6135. statusElem = node[tree.statusClassPropName];
  6136. if( !statusElem || tree._enableUpdate === false ){
  6137. // if this function is called for an unrendered node, ignore it (will be updated on nect render anyway)
  6138. return;
  6139. }
  6140. if( aria ) {
  6141. $ariaElem = $(node.tr || node.li);
  6142. }
  6143. // Build a list of class names that we will add to the node <span>
  6144. cnList.push(cn.node);
  6145. if( tree.activeNode === node ){
  6146. cnList.push(cn.active);
  6147. // $(">span.fancytree-title", statusElem).attr("tabindex", "0");
  6148. // tree.$container.removeAttr("tabindex");
  6149. // }else{
  6150. // $(">span.fancytree-title", statusElem).removeAttr("tabindex");
  6151. // tree.$container.attr("tabindex", "0");
  6152. }
  6153. if( tree.focusNode === node ){
  6154. cnList.push(cn.focused);
  6155. }
  6156. if( node.expanded ){
  6157. cnList.push(cn.expanded);
  6158. }
  6159. if( aria ){
  6160. if (hasChildren !== false) {
  6161. $ariaElem.attr("aria-expanded", Boolean(node.expanded));
  6162. }
  6163. else {
  6164. $ariaElem.removeAttr("aria-expanded");
  6165. }
  6166. }
  6167. if( node.folder ){
  6168. cnList.push(cn.folder);
  6169. }
  6170. if( hasChildren !== false ){
  6171. cnList.push(cn.hasChildren);
  6172. }
  6173. // TODO: required?
  6174. if( isLastSib ){
  6175. cnList.push(cn.lastsib);
  6176. }
  6177. if( node.lazy && node.children == null ){
  6178. cnList.push(cn.lazy);
  6179. }
  6180. if( node.partload ){
  6181. cnList.push(cn.partload);
  6182. }
  6183. if( node.partsel ){
  6184. cnList.push(cn.partsel);
  6185. }
  6186. if( FT.evalOption("unselectable", node, node, opts, false) ){
  6187. cnList.push(cn.unselectable);
  6188. }
  6189. if( node._isLoading ){
  6190. cnList.push(cn.loading);
  6191. }
  6192. if( node._error ){
  6193. cnList.push(cn.error);
  6194. }
  6195. if( node.statusNodeType ) {
  6196. cnList.push(cn.statusNodePrefix + node.statusNodeType);
  6197. }
  6198. if( node.selected ){
  6199. cnList.push(cn.selected);
  6200. if(aria){
  6201. $ariaElem.attr("aria-selected", true);
  6202. }
  6203. }else if(aria){
  6204. $ariaElem.attr("aria-selected", false);
  6205. }
  6206. if( node.extraClasses ){
  6207. cnList.push(node.extraClasses);
  6208. }
  6209. // IE6 doesn't correctly evaluate multiple class names,
  6210. // so we create combined class names that can be used in the CSS
  6211. if( hasChildren === false ){
  6212. cnList.push(cn.combinedExpanderPrefix + "n" +
  6213. (isLastSib ? "l" : "")
  6214. );
  6215. }else{
  6216. cnList.push(cn.combinedExpanderPrefix +
  6217. (node.expanded ? "e" : "c") +
  6218. (node.lazy && node.children == null ? "d" : "") +
  6219. (isLastSib ? "l" : "")
  6220. );
  6221. }
  6222. cnList.push(cn.combinedIconPrefix +
  6223. (node.expanded ? "e" : "c") +
  6224. (node.folder ? "f" : "")
  6225. );
  6226. // node.span.className = cnList.join(" ");
  6227. statusElem.className = cnList.join(" ");
  6228. // TODO: we should not set this in the <span> tag also, if we set it here:
  6229. // Maybe most (all) of the classes should be set in LI instead of SPAN?
  6230. if(node.li){
  6231. // #719: we have to consider that there may be already other classes:
  6232. $(node.li).toggleClass(cn.lastsib, isLastSib);
  6233. }
  6234. },
  6235. /** Activate node.
  6236. * flag defaults to true.
  6237. * If flag is true, the node is activated (must be a synchronous operation)
  6238. * If flag is false, the node is deactivated (must be a synchronous operation)
  6239. * @param {EventData} ctx
  6240. * @param {boolean} [flag=true]
  6241. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  6242. * @returns {$.Promise}
  6243. */
  6244. nodeSetActive: function(ctx, flag, callOpts) {
  6245. // Handle user click / [space] / [enter], according to clickFolderMode.
  6246. callOpts = callOpts || {};
  6247. var subCtx,
  6248. node = ctx.node,
  6249. tree = ctx.tree,
  6250. opts = ctx.options,
  6251. noEvents = (callOpts.noEvents === true),
  6252. noFocus = (callOpts.noFocus === true),
  6253. isActive = (node === tree.activeNode);
  6254. // flag defaults to true
  6255. flag = (flag !== false);
  6256. // node.debug("nodeSetActive", flag);
  6257. if(isActive === flag){
  6258. // Nothing to do
  6259. return _getResolvedPromise(node);
  6260. }else if(flag && !noEvents && this._triggerNodeEvent("beforeActivate", node, ctx.originalEvent) === false ){
  6261. // Callback returned false
  6262. return _getRejectedPromise(node, ["rejected"]);
  6263. }
  6264. if(flag){
  6265. if(tree.activeNode){
  6266. _assert(tree.activeNode !== node, "node was active (inconsistency)");
  6267. subCtx = $.extend({}, ctx, {node: tree.activeNode});
  6268. tree.nodeSetActive(subCtx, false);
  6269. _assert(tree.activeNode === null, "deactivate was out of sync?");
  6270. }
  6271. if(opts.activeVisible){
  6272. // If no focus is set (noFocus: true) and there is no focused node, this node is made visible.
  6273. node.makeVisible({scrollIntoView: noFocus && tree.focusNode == null});
  6274. }
  6275. tree.activeNode = node;
  6276. tree.nodeRenderStatus(ctx);
  6277. if( !noFocus ) {
  6278. tree.nodeSetFocus(ctx);
  6279. }
  6280. if( !noEvents ) {
  6281. tree._triggerNodeEvent("activate", node, ctx.originalEvent);
  6282. }
  6283. }else{
  6284. _assert(tree.activeNode === node, "node was not active (inconsistency)");
  6285. tree.activeNode = null;
  6286. this.nodeRenderStatus(ctx);
  6287. if( !noEvents ) {
  6288. ctx.tree._triggerNodeEvent("deactivate", node, ctx.originalEvent);
  6289. }
  6290. }
  6291. return _getResolvedPromise(node);
  6292. },
  6293. /** Expand or collapse node, return Deferred.promise.
  6294. *
  6295. * @param {EventData} ctx
  6296. * @param {boolean} [flag=true]
  6297. * @param {object} [opts] additional options. Defaults to {noAnimation: false, noEvents: false}
  6298. * @returns {$.Promise} The deferred will be resolved as soon as the (lazy)
  6299. * data was retrieved, rendered, and the expand animation finshed.
  6300. */
  6301. nodeSetExpanded: function(ctx, flag, callOpts) {
  6302. callOpts = callOpts || {};
  6303. var _afterLoad, dfd, i, l, parents, prevAC,
  6304. node = ctx.node,
  6305. tree = ctx.tree,
  6306. opts = ctx.options,
  6307. noAnimation = (callOpts.noAnimation === true),
  6308. noEvents = (callOpts.noEvents === true);
  6309. // flag defaults to true
  6310. flag = (flag !== false);
  6311. // node.debug("nodeSetExpanded(" + flag + ")");
  6312. if((node.expanded && flag) || (!node.expanded && !flag)){
  6313. // Nothing to do
  6314. // node.debug("nodeSetExpanded(" + flag + "): nothing to do");
  6315. return _getResolvedPromise(node);
  6316. }else if(flag && !node.lazy && !node.hasChildren() ){
  6317. // Prevent expanding of empty nodes
  6318. // return _getRejectedPromise(node, ["empty"]);
  6319. return _getResolvedPromise(node);
  6320. }else if( !flag && node.getLevel() < opts.minExpandLevel ) {
  6321. // Prevent collapsing locked levels
  6322. return _getRejectedPromise(node, ["locked"]);
  6323. }else if ( !noEvents && this._triggerNodeEvent("beforeExpand", node, ctx.originalEvent) === false ){
  6324. // Callback returned false
  6325. return _getRejectedPromise(node, ["rejected"]);
  6326. }
  6327. // If this node inside a collpased node, no animation and scrolling is needed
  6328. if( !noAnimation && !node.isVisible() ) {
  6329. noAnimation = callOpts.noAnimation = true;
  6330. }
  6331. dfd = new $.Deferred();
  6332. // Auto-collapse mode: collapse all siblings
  6333. if( flag && !node.expanded && opts.autoCollapse ) {
  6334. parents = node.getParentList(false, true);
  6335. prevAC = opts.autoCollapse;
  6336. try{
  6337. opts.autoCollapse = false;
  6338. for(i=0, l=parents.length; i<l; i++){
  6339. // TODO: should return promise?
  6340. this._callHook("nodeCollapseSiblings", parents[i], callOpts);
  6341. }
  6342. }finally{
  6343. opts.autoCollapse = prevAC;
  6344. }
  6345. }
  6346. // Trigger expand/collapse after expanding
  6347. dfd.done(function(){
  6348. var lastChild = node.getLastChild();
  6349. if( flag && opts.autoScroll && !noAnimation && lastChild ) {
  6350. // Scroll down to last child, but keep current node visible
  6351. lastChild.scrollIntoView(true, {topNode: node}).always(function(){
  6352. if( !noEvents ) {
  6353. ctx.tree._triggerNodeEvent(flag ? "expand" : "collapse", ctx);
  6354. }
  6355. });
  6356. } else {
  6357. if( !noEvents ) {
  6358. ctx.tree._triggerNodeEvent(flag ? "expand" : "collapse", ctx);
  6359. }
  6360. }
  6361. });
  6362. // vvv Code below is executed after loading finished:
  6363. _afterLoad = function(callback){
  6364. var cn = opts._classNames,
  6365. isVisible, isExpanded,
  6366. effect = opts.toggleEffect;
  6367. node.expanded = flag;
  6368. // Create required markup, but make sure the top UL is hidden, so we
  6369. // can animate later
  6370. tree._callHook("nodeRender", ctx, false, false, true);
  6371. // Hide children, if node is collapsed
  6372. if( node.ul ) {
  6373. isVisible = (node.ul.style.display !== "none");
  6374. isExpanded = !!node.expanded;
  6375. if ( isVisible === isExpanded ) {
  6376. node.warn("nodeSetExpanded: UL.style.display already set");
  6377. } else if ( !effect || noAnimation ) {
  6378. node.ul.style.display = ( node.expanded || !parent ) ? "" : "none";
  6379. } else {
  6380. // The UI toggle() effect works with the ext-wide extension,
  6381. // while jQuery.animate() has problems when the title span
  6382. // has positon: absolute.
  6383. // Since jQuery UI 1.12, the blind effect requires the parent
  6384. // element to have 'position: relative'.
  6385. // See #716, #717
  6386. $(node.li).addClass(cn.animating); // #717
  6387. // node.info("fancytree-animating start: " + node.li.className);
  6388. $(node.ul)
  6389. .addClass(cn.animating) // # 716
  6390. .toggle(effect.effect, effect.options, effect.duration, function(){
  6391. // node.info("fancytree-animating end: " + node.li.className);
  6392. $(this).removeClass(cn.animating); // #716
  6393. $(node.li).removeClass(cn.animating); // #717
  6394. callback();
  6395. });
  6396. return;
  6397. }
  6398. }
  6399. callback();
  6400. };
  6401. // ^^^ Code above is executed after loading finshed.
  6402. // Load lazy nodes, if any. Then continue with _afterLoad()
  6403. if(flag && node.lazy && node.hasChildren() === undefined){
  6404. // node.debug("nodeSetExpanded: load start...");
  6405. node.load().done(function(){
  6406. // node.debug("nodeSetExpanded: load done");
  6407. if(dfd.notifyWith){ // requires jQuery 1.6+
  6408. dfd.notifyWith(node, ["loaded"]);
  6409. }
  6410. _afterLoad(function () { dfd.resolveWith(node); });
  6411. }).fail(function(errMsg){
  6412. _afterLoad(function () { dfd.rejectWith(node, ["load failed (" + errMsg + ")"]); });
  6413. });
  6414. /*
  6415. var source = tree._triggerNodeEvent("lazyLoad", node, ctx.originalEvent);
  6416. _assert(typeof source !== "boolean", "lazyLoad event must return source in data.result");
  6417. node.debug("nodeSetExpanded: load start...");
  6418. this._callHook("nodeLoadChildren", ctx, source).done(function(){
  6419. node.debug("nodeSetExpanded: load done");
  6420. if(dfd.notifyWith){ // requires jQuery 1.6+
  6421. dfd.notifyWith(node, ["loaded"]);
  6422. }
  6423. _afterLoad.call(tree);
  6424. }).fail(function(errMsg){
  6425. dfd.rejectWith(node, ["load failed (" + errMsg + ")"]);
  6426. });
  6427. */
  6428. }else{
  6429. _afterLoad(function () { dfd.resolveWith(node); });
  6430. }
  6431. // node.debug("nodeSetExpanded: returns");
  6432. return dfd.promise();
  6433. },
  6434. /** Focus or blur this node.
  6435. * @param {EventData} ctx
  6436. * @param {boolean} [flag=true]
  6437. */
  6438. nodeSetFocus: function(ctx, flag) {
  6439. // ctx.node.debug("nodeSetFocus(" + flag + ")");
  6440. var ctx2,
  6441. tree = ctx.tree,
  6442. node = ctx.node,
  6443. opts = tree.options,
  6444. // et = ctx.originalEvent && ctx.originalEvent.type,
  6445. isInput = ctx.originalEvent ? $(ctx.originalEvent.target).is(":input") : false;
  6446. flag = (flag !== false);
  6447. // (node || tree).debug("nodeSetFocus(" + flag + "), event: " + et + ", isInput: "+ isInput);
  6448. // Blur previous node if any
  6449. if(tree.focusNode){
  6450. if(tree.focusNode === node && flag){
  6451. // node.debug("nodeSetFocus(" + flag + "): nothing to do");
  6452. return;
  6453. }
  6454. ctx2 = $.extend({}, ctx, {node: tree.focusNode});
  6455. tree.focusNode = null;
  6456. this._triggerNodeEvent("blur", ctx2);
  6457. this._callHook("nodeRenderStatus", ctx2);
  6458. }
  6459. // Set focus to container and node
  6460. if(flag){
  6461. if( !this.hasFocus() ){
  6462. node.debug("nodeSetFocus: forcing container focus");
  6463. this._callHook("treeSetFocus", ctx, true, {calledByNode: true});
  6464. }
  6465. node.makeVisible({scrollIntoView: false});
  6466. tree.focusNode = node;
  6467. if( opts.titlesTabbable ) {
  6468. if( !isInput ) { // #621
  6469. $(node.span).find(".fancytree-title").focus();
  6470. }
  6471. } else {
  6472. // We cannot set KB focus to a node, so use the tree container
  6473. // #563, #570: IE scrolls on every call to .focus(), if the container
  6474. // is partially outside the viewport. So do it only, when absolutely
  6475. // neccessary:
  6476. if( $(document.activeElement).closest(".fancytree-container").length === 0 ) {
  6477. $(tree.$container).focus();
  6478. }
  6479. }
  6480. if( opts.aria ){
  6481. // Set active descendant to node's span ID (create one, if needed)
  6482. $(tree.$container).attr("aria-activedescendant",
  6483. $( node.tr || node.li ).uniqueId().attr("id"));
  6484. // "ftal_" + opts.idPrefix + node.key);
  6485. }
  6486. // $(node.span).find(".fancytree-title").focus();
  6487. this._triggerNodeEvent("focus", ctx);
  6488. // if( opts.autoActivate ){
  6489. // tree.nodeSetActive(ctx, true);
  6490. // }
  6491. if( opts.autoScroll ){
  6492. node.scrollIntoView();
  6493. }
  6494. this._callHook("nodeRenderStatus", ctx);
  6495. }
  6496. },
  6497. /** (De)Select node, return new status (sync).
  6498. *
  6499. * @param {EventData} ctx
  6500. * @param {boolean} [flag=true]
  6501. * @param {object} [opts] additional options. Defaults to {noEvents: false,
  6502. * propagateDown: null, propagateUp: null,
  6503. * callback: null,
  6504. * }
  6505. * @returns {boolean} previous status
  6506. */
  6507. nodeSetSelected: function(ctx, flag, callOpts) {
  6508. callOpts = callOpts || {};
  6509. var node = ctx.node,
  6510. tree = ctx.tree,
  6511. opts = ctx.options,
  6512. noEvents = (callOpts.noEvents === true),
  6513. parent = node.parent;
  6514. // flag defaults to true
  6515. flag = (flag !== false);
  6516. // node.debug("nodeSetSelected(" + flag + ")", ctx);
  6517. // Cannot (de)select unselectable nodes directly (only by propagation or
  6518. // by setting the `.selected` property)
  6519. if( FT.evalOption("unselectable", node, node, opts, false) ){
  6520. return;
  6521. }
  6522. // Remember the user's intent, in case down -> up propagation prevents
  6523. // applying it to node.selected
  6524. node._lastSelectIntent = flag;
  6525. // Nothing to do?
  6526. /*jshint -W018 */ // Confusing use of '!'
  6527. if( !!node.selected === flag ){
  6528. if( opts.selectMode === 3 && node.partsel && !flag ){
  6529. // If propagation prevented selecting this node last time, we still
  6530. // want to allow to apply setSelected(false) now
  6531. }else{
  6532. return flag;
  6533. }
  6534. }
  6535. /*jshint +W018 */
  6536. if( !noEvents &&
  6537. this._triggerNodeEvent("beforeSelect", node, ctx.originalEvent) === false ) {
  6538. return !!node.selected;
  6539. }
  6540. if(flag && opts.selectMode === 1){
  6541. // single selection mode (we don't uncheck all tree nodes, for performance reasons)
  6542. if(tree.lastSelectedNode){
  6543. tree.lastSelectedNode.setSelected(false);
  6544. }
  6545. node.selected = flag;
  6546. }else if(opts.selectMode === 3 && parent && !parent.radiogroup && !node.radiogroup){
  6547. // multi-hierarchical selection mode
  6548. node.selected = flag;
  6549. node.fixSelection3AfterClick(callOpts);
  6550. }else if(parent && parent.radiogroup){
  6551. node.visitSiblings(function(n){
  6552. n._changeSelectStatusAttrs(flag && n === node);
  6553. }, true);
  6554. }else{
  6555. // default: selectMode: 2, multi selection mode
  6556. node.selected = flag;
  6557. }
  6558. this.nodeRenderStatus(ctx);
  6559. tree.lastSelectedNode = flag ? node : null;
  6560. if( !noEvents ) {
  6561. tree._triggerNodeEvent("select", ctx);
  6562. }
  6563. },
  6564. /** Show node status (ok, loading, error, nodata) using styles and a dummy child node.
  6565. *
  6566. * @param {EventData} ctx
  6567. * @param status
  6568. * @param message
  6569. * @param details
  6570. * @since 2.3
  6571. */
  6572. nodeSetStatus: function(ctx, status, message, details) {
  6573. var node = ctx.node,
  6574. tree = ctx.tree;
  6575. function _clearStatusNode() {
  6576. // Remove dedicated dummy node, if any
  6577. var firstChild = ( node.children ? node.children[0] : null );
  6578. if ( firstChild && firstChild.isStatusNode() ) {
  6579. try{
  6580. // I've seen exceptions here with loadKeyPath...
  6581. if(node.ul){
  6582. node.ul.removeChild(firstChild.li);
  6583. firstChild.li = null; // avoid leaks (DT issue 215)
  6584. }
  6585. }catch(e){}
  6586. if( node.children.length === 1 ){
  6587. node.children = [];
  6588. }else{
  6589. node.children.shift();
  6590. }
  6591. }
  6592. }
  6593. function _setStatusNode(data, type) {
  6594. // Create/modify the dedicated dummy node for 'loading...' or
  6595. // 'error!' status. (only called for direct child of the invisible
  6596. // system root)
  6597. var firstChild = ( node.children ? node.children[0] : null );
  6598. if ( firstChild && firstChild.isStatusNode() ) {
  6599. $.extend(firstChild, data);
  6600. firstChild.statusNodeType = type;
  6601. tree._callHook("nodeRenderTitle", firstChild);
  6602. } else {
  6603. node._setChildren([data]);
  6604. node.children[0].statusNodeType = type;
  6605. tree.render();
  6606. }
  6607. return node.children[0];
  6608. }
  6609. switch( status ){
  6610. case "ok":
  6611. _clearStatusNode();
  6612. node._isLoading = false;
  6613. node._error = null;
  6614. node.renderStatus();
  6615. break;
  6616. case "loading":
  6617. if( !node.parent ) {
  6618. _setStatusNode({
  6619. title: tree.options.strings.loading + (message ? " (" + message + ")" : ""),
  6620. // icon: true, // needed for 'loding' icon
  6621. checkbox: false,
  6622. tooltip: details
  6623. }, status);
  6624. }
  6625. node._isLoading = true;
  6626. node._error = null;
  6627. node.renderStatus();
  6628. break;
  6629. case "error":
  6630. _setStatusNode({
  6631. title: tree.options.strings.loadError + (message ? " (" + message + ")" : ""),
  6632. // icon: false,
  6633. checkbox: false,
  6634. tooltip: details
  6635. }, status);
  6636. node._isLoading = false;
  6637. node._error = { message: message, details: details };
  6638. node.renderStatus();
  6639. break;
  6640. case "nodata":
  6641. _setStatusNode({
  6642. title: tree.options.strings.noData,
  6643. // icon: false,
  6644. checkbox: false,
  6645. tooltip: details
  6646. }, status);
  6647. node._isLoading = false;
  6648. node._error = null;
  6649. node.renderStatus();
  6650. break;
  6651. default:
  6652. $.error("invalid node status " + status);
  6653. }
  6654. },
  6655. /**
  6656. *
  6657. * @param {EventData} ctx
  6658. */
  6659. nodeToggleExpanded: function(ctx) {
  6660. return this.nodeSetExpanded(ctx, !ctx.node.expanded);
  6661. },
  6662. /**
  6663. * @param {EventData} ctx
  6664. */
  6665. nodeToggleSelected: function(ctx) {
  6666. var node = ctx.node,
  6667. flag = !node.selected;
  6668. // In selectMode: 3 this node may be unselected+partsel, even if
  6669. // setSelected(true) was called before, due to `unselectable` children.
  6670. // In this case, we now toggle as `setSelected(false)`
  6671. if( node.partsel && !node.selected && node._lastSelectIntent === true ) {
  6672. flag = false;
  6673. node.selected = true; // so it is not considered 'nothing to do'
  6674. }
  6675. node._lastSelectIntent = flag;
  6676. return this.nodeSetSelected(ctx, flag);
  6677. },
  6678. /** Remove all nodes.
  6679. * @param {EventData} ctx
  6680. */
  6681. treeClear: function(ctx) {
  6682. var tree = ctx.tree;
  6683. tree.activeNode = null;
  6684. tree.focusNode = null;
  6685. tree.$div.find(">ul.fancytree-container").empty();
  6686. // TODO: call destructors and remove reference loops
  6687. tree.rootNode.children = null;
  6688. },
  6689. /** Widget was created (called only once, even it re-initialized).
  6690. * @param {EventData} ctx
  6691. */
  6692. treeCreate: function(ctx) {
  6693. },
  6694. /** Widget was destroyed.
  6695. * @param {EventData} ctx
  6696. */
  6697. treeDestroy: function(ctx) {
  6698. this.$div.find(">ul.fancytree-container").remove();
  6699. this.$source && this.$source.removeClass("ui-helper-hidden");
  6700. },
  6701. /** Widget was (re-)initialized.
  6702. * @param {EventData} ctx
  6703. */
  6704. treeInit: function(ctx) {
  6705. var tree = ctx.tree,
  6706. opts = tree.options;
  6707. //this.debug("Fancytree.treeInit()");
  6708. // Add container to the TAB chain
  6709. // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  6710. // #577: Allow to set tabindex to "0", "-1" and ""
  6711. tree.$container.attr("tabindex", opts.tabindex);
  6712. if( opts.rtl ) {
  6713. tree.$container.attr("DIR", "RTL").addClass("fancytree-rtl");
  6714. }else{
  6715. tree.$container.removeAttr("DIR").removeClass("fancytree-rtl");
  6716. }
  6717. if( opts.aria ){
  6718. tree.$container.attr("role", "tree");
  6719. if( opts.selectMode !== 1 ) {
  6720. tree.$container.attr("aria-multiselectable", true);
  6721. }
  6722. }
  6723. this.treeLoad(ctx);
  6724. },
  6725. /** Parse Fancytree from source, as configured in the options.
  6726. * @param {EventData} ctx
  6727. * @param {object} [source] optional new source (use last data otherwise)
  6728. */
  6729. treeLoad: function(ctx, source) {
  6730. var metaData, type, $ul,
  6731. tree = ctx.tree,
  6732. $container = ctx.widget.element,
  6733. dfd,
  6734. // calling context for root node
  6735. rootCtx = $.extend({}, ctx, {node: this.rootNode});
  6736. if(tree.rootNode.children){
  6737. this.treeClear(ctx);
  6738. }
  6739. source = source || this.options.source;
  6740. if(!source){
  6741. type = $container.data("type") || "html";
  6742. switch(type){
  6743. case "html":
  6744. $ul = $container.find(">ul:first");
  6745. $ul.addClass("ui-fancytree-source ui-helper-hidden");
  6746. source = $.ui.fancytree.parseHtml($ul);
  6747. // allow to init tree.data.foo from <ul data-foo=''>
  6748. this.data = $.extend(this.data, _getElementDataAsDict($ul));
  6749. break;
  6750. case "json":
  6751. source = $.parseJSON($container.text());
  6752. // $container already contains the <ul>, but we remove the plain (json) text
  6753. // $container.empty();
  6754. $container.contents().filter(function(){
  6755. return (this.nodeType === 3);
  6756. }).remove();
  6757. if( $.isPlainObject(source) ){
  6758. // We got {foo: 'abc', children: [...]}
  6759. // Copy extra properties to tree.data.foo
  6760. _assert($.isArray(source.children), "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')");
  6761. metaData = source;
  6762. source = source.children;
  6763. delete metaData.children;
  6764. $.extend(tree.data, metaData);
  6765. }
  6766. break;
  6767. default:
  6768. $.error("Invalid data-type: " + type);
  6769. }
  6770. }else if(typeof source === "string"){
  6771. // TODO: source is an element ID
  6772. $.error("Not implemented");
  6773. }
  6774. // Trigger fancytreeinit after nodes have been loaded
  6775. dfd = this.nodeLoadChildren(rootCtx, source).done(function(){
  6776. tree.render();
  6777. if( ctx.options.selectMode === 3 ){
  6778. tree.rootNode.fixSelection3FromEndNodes();
  6779. }
  6780. if( tree.activeNode && tree.options.activeVisible ) {
  6781. tree.activeNode.makeVisible();
  6782. }
  6783. tree._triggerTreeEvent("init", null, { status: true });
  6784. }).fail(function(){
  6785. tree.render();
  6786. tree._triggerTreeEvent("init", null, { status: false });
  6787. });
  6788. return dfd;
  6789. },
  6790. /** Node was inserted into or removed from the tree.
  6791. * @param {EventData} ctx
  6792. * @param {boolean} add
  6793. * @param {FancytreeNode} node
  6794. */
  6795. treeRegisterNode: function(ctx, add, node) {
  6796. },
  6797. /** Widget got focus.
  6798. * @param {EventData} ctx
  6799. * @param {boolean} [flag=true]
  6800. */
  6801. treeSetFocus: function(ctx, flag, callOpts) {
  6802. var targetNode;
  6803. flag = (flag !== false);
  6804. // this.debug("treeSetFocus(" + flag + "), callOpts: ", callOpts, this.hasFocus());
  6805. // this.debug(" focusNode: " + this.focusNode);
  6806. // this.debug(" activeNode: " + this.activeNode);
  6807. if( flag !== this.hasFocus() ){
  6808. this._hasFocus = flag;
  6809. if( !flag && this.focusNode ) {
  6810. // Node also looses focus if widget blurs
  6811. this.focusNode.setFocus(false);
  6812. } else if ( flag && (!callOpts || !callOpts.calledByNode) ) {
  6813. $(this.$container).focus();
  6814. }
  6815. this.$container.toggleClass("fancytree-treefocus", flag);
  6816. this._triggerTreeEvent(flag ? "focusTree" : "blurTree");
  6817. if( flag && !this.activeNode ) {
  6818. // #712: Use last mousedowned node ('click' event fires after focusin)
  6819. targetNode = this._lastMousedownNode || this.getFirstChild();
  6820. targetNode && targetNode.setFocus();
  6821. }
  6822. }
  6823. },
  6824. /** Widget option was set using `$().fancytree("option", "foo", "bar")`.
  6825. * @param {EventData} ctx
  6826. * @param {string} key option name
  6827. * @param {any} value option value
  6828. */
  6829. treeSetOption: function(ctx, key, value) {
  6830. var tree = ctx.tree,
  6831. callDefault = true,
  6832. callCreate = false,
  6833. callRender = false;
  6834. switch( key ) {
  6835. case "aria":
  6836. case "checkbox":
  6837. case "icon":
  6838. case "minExpandLevel":
  6839. case "tabindex":
  6840. // tree._callHook("treeCreate", tree);
  6841. callCreate = true;
  6842. callRender = true;
  6843. break;
  6844. case "escapeTitles":
  6845. case "tooltip":
  6846. callRender = true;
  6847. break;
  6848. case "rtl":
  6849. if( value === false ) {
  6850. tree.$container.removeAttr("DIR").removeClass("fancytree-rtl");
  6851. }else{
  6852. tree.$container.attr("DIR", "RTL").addClass("fancytree-rtl");
  6853. }
  6854. callRender = true;
  6855. break;
  6856. case "source":
  6857. callDefault = false;
  6858. tree._callHook("treeLoad", tree, value);
  6859. callRender = true;
  6860. break;
  6861. }
  6862. tree.debug("set option " + key + "=" + value + " <" + typeof(value) + ">");
  6863. if(callDefault){
  6864. if( this.widget._super ) {
  6865. // jQuery UI 1.9+
  6866. this.widget._super.call( this.widget, key, value );
  6867. } else {
  6868. // jQuery UI <= 1.8, we have to manually invoke the _setOption method from the base widget
  6869. $.Widget.prototype._setOption.call(this.widget, key, value);
  6870. }
  6871. }
  6872. if(callCreate){
  6873. tree._callHook("treeCreate", tree);
  6874. }
  6875. if(callRender){
  6876. tree.render(true, false); // force, not-deep
  6877. }
  6878. }
  6879. });
  6880. /* ******************************************************************************
  6881. * jQuery UI widget boilerplate
  6882. */
  6883. /**
  6884. * The plugin (derrived from <a href=" http://api.jqueryui.com/jQuery.widget/">jQuery.Widget</a>).<br>
  6885. * This constructor is not called directly. Use `$(selector).fancytree({})`
  6886. * to initialize the plugin instead.<br>
  6887. * <pre class="sh_javascript sunlight-highlight-javascript">// Access widget methods and members:
  6888. * var tree = $("#tree").fancytree("getTree");
  6889. * var node = $("#tree").fancytree("getActiveNode", "1234");
  6890. * </pre>
  6891. *
  6892. * @mixin Fancytree_Widget
  6893. */
  6894. $.widget("ui.fancytree",
  6895. /** @lends Fancytree_Widget# */
  6896. {
  6897. /**These options will be used as defaults
  6898. * @type {FancytreeOptions}
  6899. */
  6900. options:
  6901. {
  6902. activeVisible: true,
  6903. ajax: {
  6904. type: "GET",
  6905. cache: false, // false: Append random '_' argument to the request url to prevent caching.
  6906. // timeout: 0, // >0: Make sure we get an ajax error if server is unreachable
  6907. dataType: "json" // Expect json format and pass json object to callbacks.
  6908. }, //
  6909. aria: true,
  6910. autoActivate: true,
  6911. autoCollapse: false,
  6912. autoScroll: false,
  6913. checkbox: false,
  6914. clickFolderMode: 4,
  6915. debugLevel: null, // 0..2 (null: use global setting $.ui.fancytree.debugInfo)
  6916. disabled: false, // TODO: required anymore?
  6917. enableAspx: true,
  6918. escapeTitles: false,
  6919. extensions: [],
  6920. // fx: { height: "toggle", duration: 200 },
  6921. // toggleEffect: { effect: "drop", options: {direction: "left"}, duration: 200 },
  6922. // toggleEffect: { effect: "slide", options: {direction: "up"}, duration: 200 },
  6923. toggleEffect: { effect: "blind", options: {direction: "vertical", scale: "box"}, duration: 200 },
  6924. generateIds: false,
  6925. icon: true,
  6926. idPrefix: "ft_",
  6927. focusOnSelect: false,
  6928. keyboard: true,
  6929. keyPathSeparator: "/",
  6930. minExpandLevel: 1,
  6931. quicksearch: false,
  6932. rtl: false,
  6933. scrollOfs: {top: 0, bottom: 0},
  6934. scrollParent: null,
  6935. selectMode: 2,
  6936. strings: {
  6937. loading: "Loading...", // &#8230; would be escaped when escapeTitles is true
  6938. loadError: "Load error!",
  6939. moreData: "More...",
  6940. noData: "No data."
  6941. },
  6942. tabindex: "0",
  6943. titlesTabbable: false,
  6944. tooltip: false,
  6945. _classNames: {
  6946. node: "fancytree-node",
  6947. folder: "fancytree-folder",
  6948. animating: "fancytree-animating",
  6949. combinedExpanderPrefix: "fancytree-exp-",
  6950. combinedIconPrefix: "fancytree-ico-",
  6951. hasChildren: "fancytree-has-children",
  6952. active: "fancytree-active",
  6953. selected: "fancytree-selected",
  6954. expanded: "fancytree-expanded",
  6955. lazy: "fancytree-lazy",
  6956. focused: "fancytree-focused",
  6957. partload: "fancytree-partload",
  6958. partsel: "fancytree-partsel",
  6959. radio: "fancytree-radio",
  6960. // radiogroup: "fancytree-radiogroup",
  6961. unselectable: "fancytree-unselectable",
  6962. lastsib: "fancytree-lastsib",
  6963. loading: "fancytree-loading",
  6964. error: "fancytree-error",
  6965. statusNodePrefix: "fancytree-statusnode-"
  6966. },
  6967. // events
  6968. lazyLoad: null,
  6969. postProcess: null
  6970. },
  6971. /* Set up the widget, Called on first $().fancytree() */
  6972. _create: function() {
  6973. this.tree = new Fancytree(this);
  6974. this.$source = this.source || this.element.data("type") === "json" ? this.element
  6975. : this.element.find(">ul:first");
  6976. // Subclass Fancytree instance with all enabled extensions
  6977. var extension, extName, i,
  6978. opts = this.options,
  6979. extensions = opts.extensions,
  6980. base = this.tree;
  6981. for(i=0; i<extensions.length; i++){
  6982. extName = extensions[i];
  6983. extension = $.ui.fancytree._extensions[extName];
  6984. if(!extension){
  6985. $.error("Could not apply extension '" + extName + "' (it is not registered, did you forget to include it?)");
  6986. }
  6987. // Add extension options as tree.options.EXTENSION
  6988. // _assert(!this.tree.options[extName], "Extension name must not exist as option name: " + extName);
  6989. this.tree.options[extName] = $.extend(true, {}, extension.options, this.tree.options[extName]);
  6990. // Add a namespace tree.ext.EXTENSION, to hold instance data
  6991. _assert(this.tree.ext[extName] === undefined, "Extension name must not exist as Fancytree.ext attribute: '" + extName + "'");
  6992. // this.tree[extName] = extension;
  6993. this.tree.ext[extName] = {};
  6994. // Subclass Fancytree methods using proxies.
  6995. _subclassObject(this.tree, base, extension, extName);
  6996. // current extension becomes base for the next extension
  6997. base = extension;
  6998. }
  6999. //
  7000. if( opts.icons !== undefined ) { // 2015-11-16
  7001. if( opts.icon !== true ) {
  7002. $.error("'icons' tree option is deprecated since v2.14.0: use 'icon' only instead");
  7003. } else {
  7004. this.tree.warn("'icons' tree option is deprecated since v2.14.0: use 'icon' instead");
  7005. opts.icon = opts.icons;
  7006. }
  7007. }
  7008. if( opts.iconClass !== undefined ) { // 2015-11-16
  7009. if( opts.icon ) {
  7010. $.error("'iconClass' tree option is deprecated since v2.14.0: use 'icon' only instead");
  7011. } else {
  7012. this.tree.warn("'iconClass' tree option is deprecated since v2.14.0: use 'icon' instead");
  7013. opts.icon = opts.iconClass;
  7014. }
  7015. }
  7016. if( opts.tabbable !== undefined ) { // 2016-04-04
  7017. opts.tabindex = opts.tabbable ? "0" : "-1";
  7018. this.tree.warn("'tabbable' tree option is deprecated since v2.17.0: use 'tabindex='" + opts.tabindex + "' instead");
  7019. }
  7020. //
  7021. this.tree._callHook("treeCreate", this.tree);
  7022. // Note: 'fancytreecreate' event is fired by widget base class
  7023. // this.tree._triggerTreeEvent("create");
  7024. },
  7025. /* Called on every $().fancytree() */
  7026. _init: function() {
  7027. this.tree._callHook("treeInit", this.tree);
  7028. // TODO: currently we call bind after treeInit, because treeInit
  7029. // might change tree.$container.
  7030. // It would be better, to move ebent binding into hooks altogether
  7031. this._bind();
  7032. },
  7033. /* Use the _setOption method to respond to changes to options */
  7034. _setOption: function(key, value) {
  7035. return this.tree._callHook("treeSetOption", this.tree, key, value);
  7036. },
  7037. /** Use the destroy method to clean up any modifications your widget has made to the DOM */
  7038. destroy: function() {
  7039. this._unbind();
  7040. this.tree._callHook("treeDestroy", this.tree);
  7041. // In jQuery UI 1.8, you must invoke the destroy method from the base widget
  7042. $.Widget.prototype.destroy.call(this);
  7043. // TODO: delete tree and nodes to make garbage collect easier?
  7044. // TODO: In jQuery UI 1.9 and above, you would define _destroy instead of destroy and not call the base method
  7045. },
  7046. // -------------------------------------------------------------------------
  7047. /* Remove all event handlers for our namespace */
  7048. _unbind: function() {
  7049. var ns = this.tree._ns;
  7050. this.element.off(ns);
  7051. this.tree.$container.off(ns);
  7052. $(document).off(ns);
  7053. },
  7054. /* Add mouse and kyboard handlers to the container */
  7055. _bind: function() {
  7056. var that = this,
  7057. opts = this.options,
  7058. tree = this.tree,
  7059. ns = tree._ns
  7060. // selstartEvent = ( $.support.selectstart ? "selectstart" : "mousedown" )
  7061. ;
  7062. // Remove all previuous handlers for this tree
  7063. this._unbind();
  7064. //alert("keydown" + ns + "foc=" + tree.hasFocus() + tree.$container);
  7065. // tree.debug("bind events; container: ", tree.$container);
  7066. tree.$container.on("focusin" + ns + " focusout" + ns, function(event){
  7067. var node = FT.getNode(event),
  7068. flag = (event.type === "focusin");
  7069. // tree.treeOnFocusInOut.call(tree, event);
  7070. // tree.debug("Tree container got event " + event.type, node, event, FT.getEventTarget(event));
  7071. if( flag && tree._getExpiringValue("focusin") ) {
  7072. // #789: IE 11 may send duplicate focusin events
  7073. FT.info("Ignored double focusin.");
  7074. return;
  7075. }
  7076. tree._setExpiringValue("focusin", true, 50);
  7077. if( flag && !node ) {
  7078. // #789: IE 11 may send focusin before mousdown(?)
  7079. node = tree._getExpiringValue("mouseDownNode");
  7080. if( node ) { FT.info("Reconstruct mouse target for focusin from recent event."); }
  7081. }
  7082. if(node){
  7083. // For example clicking into an <input> that is part of a node
  7084. tree._callHook("nodeSetFocus", tree._makeHookContext(node, event), flag);
  7085. }else{
  7086. if( tree.tbody && $(event.target).parents("table.fancytree-container > thead").length ) {
  7087. // #767: ignore events in the table's header
  7088. tree.debug("Ignore focus event outside table body.", event);
  7089. } else {
  7090. tree._callHook("treeSetFocus", tree, flag);
  7091. }
  7092. }
  7093. }).on("selectstart" + ns, "span.fancytree-title", function(event){
  7094. // prevent mouse-drags to select text ranges
  7095. // tree.debug("<span title> got event " + event.type);
  7096. event.preventDefault();
  7097. }).on("keydown" + ns, function(event){
  7098. // TODO: also bind keyup and keypress
  7099. // tree.debug("got event " + event.type + ", hasFocus:" + tree.hasFocus());
  7100. // if(opts.disabled || opts.keyboard === false || !tree.hasFocus() ){
  7101. if(opts.disabled || opts.keyboard === false ){
  7102. return true;
  7103. }
  7104. var res,
  7105. node = tree.focusNode, // node may be null
  7106. ctx = tree._makeHookContext(node || tree, event),
  7107. prevPhase = tree.phase;
  7108. try {
  7109. tree.phase = "userEvent";
  7110. // If a 'fancytreekeydown' handler returns false, skip the default
  7111. // handling (implemented by tree.nodeKeydown()).
  7112. if(node){
  7113. res = tree._triggerNodeEvent("keydown", node, event);
  7114. }else{
  7115. res = tree._triggerTreeEvent("keydown", event);
  7116. }
  7117. if ( res === "preventNav" ){
  7118. res = true; // prevent keyboard navigation, but don't prevent default handling of embedded input controls
  7119. } else if ( res !== false ){
  7120. res = tree._callHook("nodeKeydown", ctx);
  7121. }
  7122. return res;
  7123. } finally {
  7124. tree.phase = prevPhase;
  7125. }
  7126. }).on("mousedown" + ns, function(event){
  7127. var et = FT.getEventTarget(event);
  7128. // that.tree.debug("event(" + event.type + "): node: ", et.node);
  7129. // #712: Store the clicked node, so we can use it when we get a focusin event
  7130. // ('click' event fires after focusin)
  7131. // tree.debug("event(" + event.type + "): node: ", et.node);
  7132. tree._lastMousedownNode = et ? et.node : null;
  7133. // #789: Store the node also for a short period, so we can use it
  7134. // in a *resulting* focusin event
  7135. tree._setExpiringValue("mouseDownNode", tree._lastMousedownNode);
  7136. }).on("click" + ns + " dblclick" + ns, function(event){
  7137. if(opts.disabled){
  7138. return true;
  7139. }
  7140. var ctx,
  7141. et = FT.getEventTarget(event),
  7142. node = et.node,
  7143. tree = that.tree,
  7144. prevPhase = tree.phase;
  7145. // that.tree.debug("event(" + event.type + "): node: ", node);
  7146. if( !node ){
  7147. return true; // Allow bubbling of other events
  7148. }
  7149. ctx = tree._makeHookContext(node, event);
  7150. // that.tree.debug("event(" + event.type + "): node: ", node);
  7151. try {
  7152. tree.phase = "userEvent";
  7153. switch(event.type) {
  7154. case "click":
  7155. ctx.targetType = et.type;
  7156. if( node.isPagingNode() ) {
  7157. return tree._triggerNodeEvent("clickPaging", ctx, event) === true;
  7158. }
  7159. return ( tree._triggerNodeEvent("click", ctx, event) === false ) ? false : tree._callHook("nodeClick", ctx);
  7160. case "dblclick":
  7161. ctx.targetType = et.type;
  7162. return ( tree._triggerNodeEvent("dblclick", ctx, event) === false ) ? false : tree._callHook("nodeDblclick", ctx);
  7163. }
  7164. } finally {
  7165. tree.phase = prevPhase;
  7166. }
  7167. });
  7168. },
  7169. /** Return the active node or null.
  7170. * @returns {FancytreeNode}
  7171. */
  7172. getActiveNode: function() {
  7173. return this.tree.activeNode;
  7174. },
  7175. /** Return the matching node or null.
  7176. * @param {string} key
  7177. * @returns {FancytreeNode}
  7178. */
  7179. getNodeByKey: function(key) {
  7180. return this.tree.getNodeByKey(key);
  7181. },
  7182. /** Return the invisible system root node.
  7183. * @returns {FancytreeNode}
  7184. */
  7185. getRootNode: function() {
  7186. return this.tree.rootNode;
  7187. },
  7188. /** Return the current tree instance.
  7189. * @returns {Fancytree}
  7190. */
  7191. getTree: function() {
  7192. return this.tree;
  7193. }
  7194. });
  7195. // $.ui.fancytree was created by the widget factory. Create a local shortcut:
  7196. FT = $.ui.fancytree;
  7197. /**
  7198. * Static members in the `$.ui.fancytree` namespace.<br>
  7199. * <br>
  7200. * <pre class="sh_javascript sunlight-highlight-javascript">// Access static members:
  7201. * var node = $.ui.fancytree.getNode(element);
  7202. * alert($.ui.fancytree.version);
  7203. * </pre>
  7204. *
  7205. * @mixin Fancytree_Static
  7206. */
  7207. $.extend($.ui.fancytree,
  7208. /** @lends Fancytree_Static# */
  7209. {
  7210. /** @type {string} */
  7211. version: "2.26.0", // Set to semver by 'grunt release'
  7212. /** @type {string} */
  7213. buildType: "production", // Set to 'production' by 'grunt build'
  7214. /** @type {int} */
  7215. debugLevel: 1, // Set to 1 by 'grunt build'
  7216. // Used by $.ui.fancytree.debug() and as default for tree.options.debugLevel
  7217. _nextId: 1,
  7218. _nextNodeKey: 1,
  7219. _extensions: {},
  7220. // focusTree: null,
  7221. /** Expose class object as $.ui.fancytree._FancytreeClass */
  7222. _FancytreeClass: Fancytree,
  7223. /** Expose class object as $.ui.fancytree._FancytreeNodeClass */
  7224. _FancytreeNodeClass: FancytreeNode,
  7225. /* Feature checks to provide backwards compatibility */
  7226. jquerySupports: {
  7227. // http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7228. positionMyOfs: isVersionAtLeast($.ui.version, 1, 9)
  7229. },
  7230. /** Throw an error if condition fails (debug method).
  7231. * @param {boolean} cond
  7232. * @param {string} msg
  7233. */
  7234. assert: function(cond, msg){
  7235. return _assert(cond, msg);
  7236. },
  7237. /** Create a new Fancytree instance on a target element.
  7238. *
  7239. * @param {Element | jQueryObject | string} el Target DOM element or selector
  7240. * @param {FancytreeOptions} [opts] Fancytree options
  7241. * @returns {Fancytree} new tree instance
  7242. * @example
  7243. * var tree = $.ui.fancytree.createTree("#tree", {
  7244. * source: {url: "my/webservice"}
  7245. * }); // Create tree for this matching element
  7246. *
  7247. * @since 2.25
  7248. */
  7249. createTree: function(el, opts){
  7250. var tree = $(el).fancytree(opts).fancytree("getTree");
  7251. return tree;
  7252. },
  7253. /** Return a function that executes *fn* at most every *timeout* ms.
  7254. * @param {integer} timeout
  7255. * @param {function} fn
  7256. * @param {boolean} [invokeAsap=false]
  7257. * @param {any} [ctx]
  7258. */
  7259. debounce: function(timeout, fn, invokeAsap, ctx) {
  7260. var timer;
  7261. if(arguments.length === 3 && typeof invokeAsap !== "boolean") {
  7262. ctx = invokeAsap;
  7263. invokeAsap = false;
  7264. }
  7265. return function() {
  7266. var args = arguments;
  7267. ctx = ctx || this;
  7268. invokeAsap && !timer && fn.apply(ctx, args);
  7269. clearTimeout(timer);
  7270. timer = setTimeout(function() {
  7271. invokeAsap || fn.apply(ctx, args);
  7272. timer = null;
  7273. }, timeout);
  7274. };
  7275. },
  7276. /** Write message to console if debugLevel >= 2
  7277. * @param {string} msg
  7278. */
  7279. debug: function(msg){
  7280. /*jshint expr:true */
  7281. ($.ui.fancytree.debugLevel >= 2) && consoleApply("log", arguments);
  7282. },
  7283. /** Write error message to console.
  7284. * @param {string} msg
  7285. */
  7286. error: function(msg){
  7287. consoleApply("error", arguments);
  7288. },
  7289. /** Convert &lt;, &gt;, &amp;, &quot;, &#39;, &#x2F; to the equivalent entities.
  7290. *
  7291. * @param {string} s
  7292. * @returns {string}
  7293. */
  7294. escapeHtml: function(s){
  7295. return ("" + s).replace(REX_HTML, function(s) {
  7296. return ENTITY_MAP[s];
  7297. });
  7298. },
  7299. /** Make jQuery.position() arguments backwards compatible, i.e. if
  7300. * jQuery UI version <= 1.8, convert
  7301. * { my: "left+3 center", at: "left bottom", of: $target }
  7302. * to
  7303. * { my: "left center", at: "left bottom", of: $target, offset: "3 0" }
  7304. *
  7305. * See http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7306. * and http://jsfiddle.net/mar10/6xtu9a4e/
  7307. */
  7308. fixPositionOptions: function(opts) {
  7309. if( opts.offset || ("" + opts.my + opts.at ).indexOf("%") >= 0 ) {
  7310. $.error("expected new position syntax (but '%' is not supported)");
  7311. }
  7312. if( ! $.ui.fancytree.jquerySupports.positionMyOfs ) {
  7313. var // parse 'left+3 center' into ['left+3 center', 'left', '+3', 'center', undefined]
  7314. myParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(opts.my),
  7315. atParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(opts.at),
  7316. // convert to numbers
  7317. dx = (myParts[2] ? (+myParts[2]) : 0) + (atParts[2] ? (+atParts[2]) : 0),
  7318. dy = (myParts[4] ? (+myParts[4]) : 0) + (atParts[4] ? (+atParts[4]) : 0);
  7319. opts = $.extend({}, opts, { // make a copy and overwrite
  7320. my: myParts[1] + " " + myParts[3],
  7321. at: atParts[1] + " " + atParts[3]
  7322. });
  7323. if( dx || dy ) {
  7324. opts.offset = "" + dx + " " + dy;
  7325. }
  7326. }
  7327. return opts;
  7328. },
  7329. /** Return a {node: FancytreeNode, type: TYPE} object for a mouse event.
  7330. *
  7331. * @param {Event} event Mouse event, e.g. click, ...
  7332. * @returns {object} Return a {node: FancytreeNode, type: TYPE} object
  7333. * TYPE: 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7334. */
  7335. getEventTarget: function(event){
  7336. var tcn = event && event.target ? event.target.className : "",
  7337. res = {node: this.getNode(event.target), type: undefined};
  7338. // We use a fast version of $(res.node).hasClass()
  7339. // See http://jsperf.com/test-for-classname/2
  7340. if( /\bfancytree-title\b/.test(tcn) ){
  7341. res.type = "title";
  7342. }else if( /\bfancytree-expander\b/.test(tcn) ){
  7343. res.type = (res.node.hasChildren() === false ? "prefix" : "expander");
  7344. // }else if( /\bfancytree-checkbox\b/.test(tcn) || /\bfancytree-radio\b/.test(tcn) ){
  7345. }else if( /\bfancytree-checkbox\b/.test(tcn) ){
  7346. res.type = "checkbox";
  7347. }else if( /\bfancytree(-custom)?-icon\b/.test(tcn) ){
  7348. res.type = "icon";
  7349. }else if( /\bfancytree-node\b/.test(tcn) ){
  7350. // Somewhere near the title
  7351. res.type = "title";
  7352. }else if( event && $(event.target).is("ul[role=group]") ) {
  7353. // #nnn: Clicking right to a node may hit the surrounding UL
  7354. FT.info("Ignoring click on outer UL.");
  7355. res.node = null;
  7356. }else if( event && event.target && $(event.target).closest(".fancytree-title").length ) {
  7357. // #228: clicking an embedded element inside a title
  7358. res.type = "title";
  7359. }
  7360. return res;
  7361. },
  7362. /** Return a string describing the affected node region for a mouse event.
  7363. *
  7364. * @param {Event} event Mouse event, e.g. click, mousemove, ...
  7365. * @returns {string} 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7366. */
  7367. getEventTargetType: function(event){
  7368. return this.getEventTarget(event).type;
  7369. },
  7370. /** Return a FancytreeNode instance from element, event, or jQuery object.
  7371. *
  7372. * @param {Element | jQueryObject | Event} el
  7373. * @returns {FancytreeNode} matching node or null
  7374. */
  7375. getNode: function(el){
  7376. if(el instanceof FancytreeNode){
  7377. return el; // el already was a FancytreeNode
  7378. }else if( el instanceof $ ){
  7379. el = el[0]; // el was a jQuery object: use the DOM element
  7380. }else if(el.originalEvent !== undefined){
  7381. el = el.target; // el was an Event
  7382. }
  7383. while( el ) {
  7384. if(el.ftnode) {
  7385. return el.ftnode;
  7386. }
  7387. el = el.parentNode;
  7388. }
  7389. return null;
  7390. },
  7391. /** Return a Fancytree instance, from element, index, event, or jQueryObject.
  7392. *
  7393. * @param {Element | jQueryObject | Event | integer | string} [el]
  7394. * @returns {Fancytree} matching tree or null
  7395. * @example
  7396. * $.ui.fancytree.getTree(); // Get first Fancytree instance on page
  7397. * $.ui.fancytree.getTree(1); // Get second Fancytree instance on page
  7398. * $.ui.fancytree.getTree("#tree"); // Get tree for this matching element
  7399. *
  7400. * @since 2.13
  7401. */
  7402. getTree: function(el){
  7403. var widget;
  7404. if( el instanceof Fancytree ) {
  7405. return el; // el already was a Fancytree
  7406. }
  7407. if( el === undefined ) {
  7408. el = 0; // get first tree
  7409. }
  7410. if( typeof el === "number" ) {
  7411. el = $(".fancytree-container").eq(el); // el was an integer: return nth instance
  7412. } else if( typeof el === "string" ) {
  7413. el = $(el).eq(0); // el was a selector: use first match
  7414. } else if( el.selector !== undefined ) {
  7415. el = el.eq(0); // el was a jQuery object: use the first DOM element
  7416. } else if( el.originalEvent !== undefined ) {
  7417. el = $(el.target); // el was an Event
  7418. }
  7419. el = el.closest(":ui-fancytree");
  7420. widget = el.data("ui-fancytree") || el.data("fancytree"); // the latter is required by jQuery <= 1.8
  7421. return widget ? widget.tree : null;
  7422. },
  7423. /** Return an option value that has a default, but may be overridden by a
  7424. * callback or a node instance attribute.
  7425. *
  7426. * Evaluation sequence:<br>
  7427. *
  7428. * If tree.options.<optionName> is a callback that returns something, use that.<br>
  7429. * Else if node.<optionName> is defined, use that.<br>
  7430. * Else if tree.options.<optionName> is a value, use that.<br>
  7431. * Else use `defaultValue`.
  7432. *
  7433. * @param {string} optionName name of the option property (on node and tree)
  7434. * @param {FancytreeNode} node passed to the callback
  7435. * @param {object} nodeObject where to look for the local option property, e.g. `node` or `node.data`
  7436. * @param {object} treeOption where to look for the tree option, e.g. `tree.options` or `tree.options.dnd5`
  7437. * @param {any} [defaultValue]
  7438. * @returns {any}
  7439. *
  7440. * @example
  7441. * // Check for node.foo, tree,options.foo(), and tree.options.foo:
  7442. * $.ui.fancytree.evalOption("foo", node, node, tree.options);
  7443. * // Check for node.data.bar, tree,options.qux.bar(), and tree.options.qux.bar:
  7444. * $.ui.fancytree.evalOption("bar", node, node.data, tree.options.qux);
  7445. *
  7446. * @since 2.22
  7447. */
  7448. evalOption: function(optionName, node, nodeObject, treeOptions, defaultValue) {
  7449. var ctx, res,
  7450. tree = node.tree,
  7451. treeOpt = treeOptions[optionName],
  7452. nodeOpt = nodeObject[optionName];
  7453. if( $.isFunction(treeOpt) ) {
  7454. ctx = { node: node, tree: tree, widget: tree.widget, options: tree.widget.options };
  7455. res = treeOpt.call(tree, {type: optionName}, ctx);
  7456. if( res == null ) {
  7457. res = nodeOpt;
  7458. }
  7459. } else {
  7460. res = (nodeOpt != null) ? nodeOpt : treeOpt;
  7461. }
  7462. if( res == null ) {
  7463. res = defaultValue; // no option set at all: return default
  7464. }
  7465. return res;
  7466. },
  7467. /** Convert a keydown or mouse event to a canonical string like 'ctrl+a',
  7468. * 'ctrl+shift+f2', 'shift+leftdblclick'.
  7469. *
  7470. * This is especially handy for switch-statements in event handlers.
  7471. *
  7472. * @param {event}
  7473. * @returns {string}
  7474. *
  7475. * @example
  7476. switch( $.ui.fancytree.eventToString(event) ) {
  7477. case "-":
  7478. tree.nodeSetExpanded(ctx, false);
  7479. break;
  7480. case "shift+return":
  7481. tree.nodeSetActive(ctx, true);
  7482. break;
  7483. case "down":
  7484. res = node.navigate(event.which, activate, true);
  7485. break;
  7486. default:
  7487. handled = false;
  7488. }
  7489. if( handled ){
  7490. event.preventDefault();
  7491. }
  7492. */
  7493. eventToString: function(event) {
  7494. // Poor-man's hotkeys. See here for a complete implementation:
  7495. // https://github.com/jeresig/jquery.hotkeys
  7496. var which = event.which,
  7497. et = event.type,
  7498. s = [];
  7499. if( event.altKey ) { s.push("alt"); }
  7500. if( event.ctrlKey ) { s.push("ctrl"); }
  7501. if( event.metaKey ) { s.push("meta"); }
  7502. if( event.shiftKey ) { s.push("shift"); }
  7503. if( et === "click" || et === "dblclick" ) {
  7504. s.push(MOUSE_BUTTONS[event.button] + et);
  7505. } else {
  7506. if( !IGNORE_KEYCODES[which] ) {
  7507. s.push( SPECIAL_KEYCODES[which] || String.fromCharCode(which).toLowerCase() );
  7508. }
  7509. }
  7510. return s.join("+");
  7511. },
  7512. /** Write message to console if debugLevel >= 1
  7513. * @param {string} msg
  7514. */
  7515. info: function(msg){
  7516. /*jshint expr:true */
  7517. ($.ui.fancytree.debugLevel >= 1) && consoleApply("info", arguments);
  7518. },
  7519. /* @deprecated: use eventToString(event) instead.
  7520. */
  7521. keyEventToString: function(event) {
  7522. this.warn("keyEventToString() is deprecated: use eventToString()");
  7523. return this.eventToString(event);
  7524. },
  7525. /** Return a wrapped handler method, that provides `this.super`.
  7526. *
  7527. * @example
  7528. // Implement `opts.createNode` event to add the 'draggable' attribute
  7529. $.ui.fancytree.overrideMethod(ctx.options, "createNode", function(event, data) {
  7530. // Default processing if any
  7531. this._super.apply(this, arguments);
  7532. // Add 'draggable' attribute
  7533. data.node.span.draggable = true;
  7534. });
  7535. *
  7536. * @param {object} instance
  7537. * @param {string} methodName
  7538. * @param {function} handler
  7539. */
  7540. overrideMethod: function(instance, methodName, handler){
  7541. var prevSuper,
  7542. _super = instance[methodName] || $.noop;
  7543. // context = context || this;
  7544. instance[methodName] = function() {
  7545. try {
  7546. prevSuper = this._super;
  7547. this._super = _super;
  7548. return handler.apply(this, arguments);
  7549. } finally {
  7550. this._super = prevSuper;
  7551. }
  7552. };
  7553. },
  7554. /**
  7555. * Parse tree data from HTML <ul> markup
  7556. *
  7557. * @param {jQueryObject} $ul
  7558. * @returns {NodeData[]}
  7559. */
  7560. parseHtml: function($ul) {
  7561. // TODO: understand this:
  7562. /*jshint validthis:true */
  7563. var classes, className, extraClasses, i, iPos, l, tmp, tmp2,
  7564. $children = $ul.find(">li"),
  7565. children = [];
  7566. $children.each(function() {
  7567. var allData, lowerCaseAttr,
  7568. $li = $(this),
  7569. $liSpan = $li.find(">span:first", this),
  7570. $liA = $liSpan.length ? null : $li.find(">a:first"),
  7571. d = { tooltip: null, data: {} };
  7572. if( $liSpan.length ) {
  7573. d.title = $liSpan.html();
  7574. } else if( $liA && $liA.length ) {
  7575. // If a <li><a> tag is specified, use it literally and extract href/target.
  7576. d.title = $liA.html();
  7577. d.data.href = $liA.attr("href");
  7578. d.data.target = $liA.attr("target");
  7579. d.tooltip = $liA.attr("title");
  7580. } else {
  7581. // If only a <li> tag is specified, use the trimmed string up to
  7582. // the next child <ul> tag.
  7583. d.title = $li.html();
  7584. iPos = d.title.search(/<ul/i);
  7585. if( iPos >= 0 ){
  7586. d.title = d.title.substring(0, iPos);
  7587. }
  7588. }
  7589. d.title = $.trim(d.title);
  7590. // Make sure all fields exist
  7591. for(i=0, l=CLASS_ATTRS.length; i<l; i++){
  7592. d[CLASS_ATTRS[i]] = undefined;
  7593. }
  7594. // Initialize to `true`, if class is set and collect extraClasses
  7595. classes = this.className.split(" ");
  7596. extraClasses = [];
  7597. for(i=0, l=classes.length; i<l; i++){
  7598. className = classes[i];
  7599. if(CLASS_ATTR_MAP[className]){
  7600. d[className] = true;
  7601. }else{
  7602. extraClasses.push(className);
  7603. }
  7604. }
  7605. d.extraClasses = extraClasses.join(" ");
  7606. // Parse node options from ID, title and class attributes
  7607. tmp = $li.attr("title");
  7608. if( tmp ){
  7609. d.tooltip = tmp; // overrides <a title='...'>
  7610. }
  7611. tmp = $li.attr("id");
  7612. if( tmp ){
  7613. d.key = tmp;
  7614. }
  7615. // Translate hideCheckbox -> checkbox:false
  7616. if( $li.attr("hideCheckbox") ){
  7617. d.checkbox = false;
  7618. }
  7619. // Add <li data-NAME='...'> as node.data.NAME
  7620. allData = _getElementDataAsDict($li);
  7621. if( allData && !$.isEmptyObject(allData) ) {
  7622. // #507: convert data-hidecheckbox (lower case) to hideCheckbox
  7623. for( lowerCaseAttr in NODE_ATTR_LOWERCASE_MAP ) {
  7624. if( allData.hasOwnProperty(lowerCaseAttr) ) {
  7625. allData[NODE_ATTR_LOWERCASE_MAP[lowerCaseAttr]] = allData[lowerCaseAttr];
  7626. delete allData[lowerCaseAttr];
  7627. }
  7628. }
  7629. // #56: Allow to set special node.attributes from data-...
  7630. for(i=0, l=NODE_ATTRS.length; i<l; i++){
  7631. tmp = NODE_ATTRS[i];
  7632. tmp2 = allData[tmp];
  7633. if( tmp2 != null ) {
  7634. delete allData[tmp];
  7635. d[tmp] = tmp2;
  7636. }
  7637. }
  7638. // All other data-... goes to node.data...
  7639. $.extend(d.data, allData);
  7640. }
  7641. // Recursive reading of child nodes, if LI tag contains an UL tag
  7642. $ul = $li.find(">ul:first");
  7643. if( $ul.length ) {
  7644. d.children = $.ui.fancytree.parseHtml($ul);
  7645. }else{
  7646. d.children = d.lazy ? undefined : null;
  7647. }
  7648. children.push(d);
  7649. // FT.debug("parse ", d, children);
  7650. });
  7651. return children;
  7652. },
  7653. /** Add Fancytree extension definition to the list of globally available extensions.
  7654. *
  7655. * @param {object} definition
  7656. */
  7657. registerExtension: function(definition){
  7658. _assert(definition.name != null, "extensions must have a `name` property.");
  7659. _assert(definition.version != null, "extensions must have a `version` property.");
  7660. $.ui.fancytree._extensions[definition.name] = definition;
  7661. },
  7662. /** Inverse of escapeHtml().
  7663. *
  7664. * @param {string} s
  7665. * @returns {string}
  7666. */
  7667. unescapeHtml: function(s){
  7668. var e = document.createElement("div");
  7669. e.innerHTML = s;
  7670. return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
  7671. },
  7672. /** Write warning message to console.
  7673. * @param {string} msg
  7674. */
  7675. warn: function(msg){
  7676. consoleApply("warn", arguments);
  7677. }
  7678. });
  7679. // Value returned by `require('jquery.fancytree')`
  7680. return $.ui.fancytree;
  7681. })); // End of closure
  7682. /*! Extension 'jquery.fancytree.childcounter.js' */// Extending Fancytree
  7683. // ===================
  7684. //
  7685. // See also the [live demo](http://wwwendt.de/tech/fancytree/demo/sample-ext-childcounter.html) of this code.
  7686. //
  7687. // Every extension should have a comment header containing some information
  7688. // about the author, copyright and licensing. Also a pointer to the latest
  7689. // source code.
  7690. // Prefix with `/*!` so the comment is not removed by the minifier.
  7691. /*!
  7692. * jquery.fancytree.childcounter.js
  7693. *
  7694. * Add a child counter bubble to tree nodes.
  7695. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  7696. *
  7697. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  7698. *
  7699. * Released under the MIT license
  7700. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  7701. *
  7702. * @version 2.26.0
  7703. * @date 2017-11-04T17:52:53Z
  7704. */
  7705. // To keep the global namespace clean, we wrap everything in a closure.
  7706. // The UMD wrapper pattern defines the dependencies on jQuery and the
  7707. // Fancytree core module, and makes sure that we can use the `require()`
  7708. // syntax with package loaders.
  7709. ;(function( factory ) {
  7710. if ( typeof define === "function" && define.amd ) {
  7711. // AMD. Register as an anonymous module.
  7712. define( [ "jquery", "./jquery.fancytree" ], factory );
  7713. } else if ( typeof module === "object" && module.exports ) {
  7714. // Node/CommonJS
  7715. require("jquery.fancytree");
  7716. module.exports = factory(require("jquery"));
  7717. } else {
  7718. // Browser globals
  7719. factory( jQuery );
  7720. }
  7721. }( function( $ ) {
  7722. // Consider to use [strict mode](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)
  7723. "use strict";
  7724. // The [coding guidelines](http://contribute.jquery.org/style-guide/js/)
  7725. // require jshint compliance.
  7726. // But for this sample, we want to allow unused variables for demonstration purpose.
  7727. /*jshint unused:false */
  7728. // Adding methods
  7729. // --------------
  7730. // New member functions can be added to the `Fancytree` class.
  7731. // This function will be available for every tree instance:
  7732. //
  7733. // var tree = $("#tree").fancytree("getTree");
  7734. // tree.countSelected(false);
  7735. $.ui.fancytree._FancytreeClass.prototype.countSelected = function(topOnly){
  7736. var tree = this,
  7737. treeOptions = tree.options;
  7738. return tree.getSelectedNodes(topOnly).length;
  7739. };
  7740. // The `FancytreeNode` class can also be easily extended. This would be called
  7741. // like
  7742. // node.updateCounters();
  7743. //
  7744. // It is also good practice to add a docstring comment.
  7745. /**
  7746. * [ext-childcounter] Update counter badges for `node` and its parents.
  7747. * May be called in the `loadChildren` event, to update parents of lazy loaded
  7748. * nodes.
  7749. * @alias FancytreeNode#updateCounters
  7750. * @requires jquery.fancytree.childcounters.js
  7751. */
  7752. $.ui.fancytree._FancytreeNodeClass.prototype.updateCounters = function(){
  7753. var node = this,
  7754. $badge = $("span.fancytree-childcounter", node.span),
  7755. extOpts = node.tree.options.childcounter,
  7756. count = node.countChildren(extOpts.deep);
  7757. node.data.childCounter = count;
  7758. if( (count || !extOpts.hideZeros) && (!node.isExpanded() || !extOpts.hideExpanded) ) {
  7759. if( !$badge.length ) {
  7760. $badge = $("<span class='fancytree-childcounter'/>").appendTo($("span.fancytree-icon", node.span));
  7761. }
  7762. $badge.text(count);
  7763. } else {
  7764. $badge.remove();
  7765. }
  7766. if( extOpts.deep && !node.isTopLevel() && !node.isRoot() ) {
  7767. node.parent.updateCounters();
  7768. }
  7769. };
  7770. // Finally, we can extend the widget API and create functions that are called
  7771. // like so:
  7772. //
  7773. // $("#tree").fancytree("widgetMethod1", "abc");
  7774. $.ui.fancytree.prototype.widgetMethod1 = function(arg1){
  7775. var tree = this.tree;
  7776. return arg1;
  7777. };
  7778. // Register a Fancytree extension
  7779. // ------------------------------
  7780. // A full blown extension, extension is available for all trees and can be
  7781. // enabled like so (see also the [live demo](http://wwwendt.de/tech/fancytree/demo/sample-ext-childcounter.html)):
  7782. //
  7783. // <script src="../src/jquery.fancytree.js"></script>
  7784. // <script src="../src/jquery.fancytree.childcounter.js"></script>
  7785. // ...
  7786. //
  7787. // $("#tree").fancytree({
  7788. // extensions: ["childcounter"],
  7789. // childcounter: {
  7790. // hideExpanded: true
  7791. // },
  7792. // ...
  7793. // });
  7794. //
  7795. /* 'childcounter' extension */
  7796. $.ui.fancytree.registerExtension({
  7797. // Every extension must be registered by a unique name.
  7798. name: "childcounter",
  7799. // Version information should be compliant with [semver](http://semver.org)
  7800. version: "2.26.0",
  7801. // Extension specific options and their defaults.
  7802. // This options will be available as `tree.options.childcounter.hideExpanded`
  7803. options: {
  7804. deep: true,
  7805. hideZeros: true,
  7806. hideExpanded: false
  7807. },
  7808. // Attributes other than `options` (or functions) can be defined here, and
  7809. // will be added to the tree.ext.EXTNAME namespace, in this case `tree.ext.childcounter.foo`.
  7810. // They can also be accessed as `this._local.foo` from within the extension
  7811. // methods.
  7812. foo: 42,
  7813. // Local functions are prefixed with an underscore '_'.
  7814. // Callable as `this._local._appendCounter()`.
  7815. _appendCounter: function(bar){
  7816. var tree = this;
  7817. },
  7818. // **Override virtual methods for this extension.**
  7819. //
  7820. // Fancytree implements a number of 'hook methods', prefixed by 'node...' or 'tree...'.
  7821. // with a `ctx` argument (see [EventData](http://www.wwwendt.de/tech/fancytree/doc/jsdoc/global.html#EventData)
  7822. // for details) and an extended calling context:<br>
  7823. // `this` : the Fancytree instance<br>
  7824. // `this._local`: the namespace that contains extension attributes and private methods (same as this.ext.EXTNAME)<br>
  7825. // `this._super`: the virtual function that was overridden (member of previous extension or Fancytree)
  7826. //
  7827. // See also the [complete list of available hook functions](http://www.wwwendt.de/tech/fancytree/doc/jsdoc/Fancytree_Hooks.html).
  7828. /* Init */
  7829. // `treeInit` is triggered when a tree is initalized. We can set up classes or
  7830. // bind event handlers here...
  7831. treeInit: function(ctx){
  7832. var tree = this, // same as ctx.tree,
  7833. opts = ctx.options,
  7834. extOpts = ctx.options.childcounter;
  7835. // Optionally check for dependencies with other extensions
  7836. /* this._requireExtension("glyph", false, false); */
  7837. // Call the base implementation
  7838. this._superApply(arguments);
  7839. // Add a class to the tree container
  7840. this.$container.addClass("fancytree-ext-childcounter");
  7841. },
  7842. // Destroy this tree instance (we only call the default implementation, so
  7843. // this method could as well be omitted).
  7844. treeDestroy: function(ctx){
  7845. this._superApply(arguments);
  7846. },
  7847. // Overload the `renderTitle` hook, to append a counter badge
  7848. nodeRenderTitle: function(ctx, title) {
  7849. var node = ctx.node,
  7850. extOpts = ctx.options.childcounter,
  7851. count = (node.data.childCounter == null) ? node.countChildren(extOpts.deep) : +node.data.childCounter;
  7852. // Let the base implementation render the title
  7853. // We use `_super()` instead of `_superApply()` here, since it is a little bit
  7854. // more performant when called often
  7855. this._super(ctx, title);
  7856. // Append a counter badge
  7857. if( (count || ! extOpts.hideZeros) && (!node.isExpanded() || !extOpts.hideExpanded) ){
  7858. $("span.fancytree-icon", node.span).append($("<span class='fancytree-childcounter'/>").text(count));
  7859. }
  7860. },
  7861. // Overload the `setExpanded` hook, so the counters are updated
  7862. nodeSetExpanded: function(ctx, flag, callOpts) {
  7863. var tree = ctx.tree,
  7864. node = ctx.node;
  7865. // Let the base implementation expand/collapse the node, then redraw the title
  7866. // after the animation has finished
  7867. return this._superApply(arguments).always(function(){
  7868. tree.nodeRenderTitle(ctx);
  7869. });
  7870. }
  7871. // End of extension definition
  7872. });
  7873. // Value returned by `require('jquery.fancytree..')`
  7874. return $.ui.fancytree;
  7875. })); // End of closure
  7876. /*! Extension 'jquery.fancytree.clones.js' *//*!
  7877. *
  7878. * jquery.fancytree.clones.js
  7879. * Support faster lookup of nodes by key and shared ref-ids.
  7880. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  7881. *
  7882. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  7883. *
  7884. * Released under the MIT license
  7885. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  7886. *
  7887. * @version 2.26.0
  7888. * @date 2017-11-04T17:52:53Z
  7889. */
  7890. ;(function( factory ) {
  7891. if ( typeof define === "function" && define.amd ) {
  7892. // AMD. Register as an anonymous module.
  7893. define( [ "jquery", "./jquery.fancytree" ], factory );
  7894. } else if ( typeof module === "object" && module.exports ) {
  7895. // Node/CommonJS
  7896. require("jquery.fancytree");
  7897. module.exports = factory(require("jquery"));
  7898. } else {
  7899. // Browser globals
  7900. factory( jQuery );
  7901. }
  7902. }( function( $ ) {
  7903. "use strict";
  7904. /*******************************************************************************
  7905. * Private functions and variables
  7906. */
  7907. function _assert(cond, msg){
  7908. // TODO: see qunit.js extractStacktrace()
  7909. if(!cond){
  7910. msg = msg ? ": " + msg : "";
  7911. $.error("Assertion failed" + msg);
  7912. }
  7913. }
  7914. /* Return first occurrence of member from array. */
  7915. function _removeArrayMember(arr, elem) {
  7916. // TODO: use Array.indexOf for IE >= 9
  7917. var i;
  7918. for (i = arr.length - 1; i >= 0; i--) {
  7919. if (arr[i] === elem) {
  7920. arr.splice(i, 1);
  7921. return true;
  7922. }
  7923. }
  7924. return false;
  7925. }
  7926. // /**
  7927. // * Calculate a 32 bit FNV-1a hash
  7928. // * Found here: https://gist.github.com/vaiorabbit/5657561
  7929. // * Ref.: http://isthe.com/chongo/tech/comp/fnv/
  7930. // *
  7931. // * @param {string} str the input value
  7932. // * @param {boolean} [asString=false] set to true to return the hash value as
  7933. // * 8-digit hex string instead of an integer
  7934. // * @param {integer} [seed] optionally pass the hash of the previous chunk
  7935. // * @returns {integer | string}
  7936. // */
  7937. // function hashFnv32a(str, asString, seed) {
  7938. // /*jshint bitwise:false */
  7939. // var i, l,
  7940. // hval = (seed === undefined) ? 0x811c9dc5 : seed;
  7941. // for (i = 0, l = str.length; i < l; i++) {
  7942. // hval ^= str.charCodeAt(i);
  7943. // hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
  7944. // }
  7945. // if( asString ){
  7946. // // Convert to 8 digit hex string
  7947. // return ("0000000" + (hval >>> 0).toString(16)).substr(-8);
  7948. // }
  7949. // return hval >>> 0;
  7950. // }
  7951. /**
  7952. * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)
  7953. *
  7954. * @author <a href="mailto:[email protected]">Gary Court</a>
  7955. * @see http://github.com/garycourt/murmurhash-js
  7956. * @author <a href="mailto:[email protected]">Austin Appleby</a>
  7957. * @see http://sites.google.com/site/murmurhash/
  7958. *
  7959. * @param {string} key ASCII only
  7960. * @param {boolean} [asString=false]
  7961. * @param {number} seed Positive integer only
  7962. * @return {number} 32-bit positive integer hash
  7963. */
  7964. function hashMurmur3(key, asString, seed) {
  7965. /*jshint bitwise:false */
  7966. var h1b, k1,
  7967. remainder = key.length & 3,
  7968. bytes = key.length - remainder,
  7969. h1 = seed,
  7970. c1 = 0xcc9e2d51,
  7971. c2 = 0x1b873593,
  7972. i = 0;
  7973. while (i < bytes) {
  7974. k1 =
  7975. ((key.charCodeAt(i) & 0xff)) |
  7976. ((key.charCodeAt(++i) & 0xff) << 8) |
  7977. ((key.charCodeAt(++i) & 0xff) << 16) |
  7978. ((key.charCodeAt(++i) & 0xff) << 24);
  7979. ++i;
  7980. k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff;
  7981. k1 = (k1 << 15) | (k1 >>> 17);
  7982. k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff;
  7983. h1 ^= k1;
  7984. h1 = (h1 << 13) | (h1 >>> 19);
  7985. h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff;
  7986. h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16));
  7987. }
  7988. k1 = 0;
  7989. switch (remainder) {
  7990. /*jshint -W086:true */
  7991. case 3: k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
  7992. case 2: k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
  7993. case 1: k1 ^= (key.charCodeAt(i) & 0xff);
  7994. k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;
  7995. k1 = (k1 << 15) | (k1 >>> 17);
  7996. k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;
  7997. h1 ^= k1;
  7998. }
  7999. h1 ^= key.length;
  8000. h1 ^= h1 >>> 16;
  8001. h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff;
  8002. h1 ^= h1 >>> 13;
  8003. h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;
  8004. h1 ^= h1 >>> 16;
  8005. if( asString ){
  8006. // Convert to 8 digit hex string
  8007. return ("0000000" + (h1 >>> 0).toString(16)).substr(-8);
  8008. }
  8009. return h1 >>> 0;
  8010. }
  8011. // console.info(hashMurmur3("costarring"));
  8012. // console.info(hashMurmur3("costarring", true));
  8013. // console.info(hashMurmur3("liquid"));
  8014. // console.info(hashMurmur3("liquid", true));
  8015. /*
  8016. * Return a unique key for node by calculationg the hash of the parents refKey-list
  8017. */
  8018. function calcUniqueKey(node) {
  8019. var key,
  8020. path = $.map(node.getParentList(false, true), function(e){ return e.refKey || e.key; });
  8021. path = path.join("/");
  8022. key = "id_" + hashMurmur3(path, true);
  8023. // node.debug(path + " -> " + key);
  8024. return key;
  8025. }
  8026. /**
  8027. * [ext-clones] Return a list of clone-nodes or null.
  8028. * @param {boolean} [includeSelf=false]
  8029. * @returns {FancytreeNode[] | null}
  8030. *
  8031. * @alias FancytreeNode#getCloneList
  8032. * @requires jquery.fancytree.clones.js
  8033. */
  8034. $.ui.fancytree._FancytreeNodeClass.prototype.getCloneList = function(includeSelf){
  8035. var key,
  8036. tree = this.tree,
  8037. refList = tree.refMap[this.refKey] || null,
  8038. keyMap = tree.keyMap;
  8039. if( refList ) {
  8040. key = this.key;
  8041. // Convert key list to node list
  8042. if( includeSelf ) {
  8043. refList = $.map(refList, function(val){ return keyMap[val]; });
  8044. } else {
  8045. refList = $.map(refList, function(val){ return val === key ? null : keyMap[val]; });
  8046. if( refList.length < 1 ) {
  8047. refList = null;
  8048. }
  8049. }
  8050. }
  8051. return refList;
  8052. };
  8053. /**
  8054. * [ext-clones] Return true if this node has at least another clone with same refKey.
  8055. * @returns {boolean}
  8056. *
  8057. * @alias FancytreeNode#isClone
  8058. * @requires jquery.fancytree.clones.js
  8059. */
  8060. $.ui.fancytree._FancytreeNodeClass.prototype.isClone = function(){
  8061. var refKey = this.refKey || null,
  8062. refList = refKey && this.tree.refMap[refKey] || null;
  8063. return !!(refList && refList.length > 1);
  8064. };
  8065. /**
  8066. * [ext-clones] Update key and/or refKey for an existing node.
  8067. * @param {string} key
  8068. * @param {string} refKey
  8069. * @returns {boolean}
  8070. *
  8071. * @alias FancytreeNode#reRegister
  8072. * @requires jquery.fancytree.clones.js
  8073. */
  8074. $.ui.fancytree._FancytreeNodeClass.prototype.reRegister = function(key, refKey){
  8075. key = (key == null) ? null : "" + key;
  8076. refKey = (refKey == null) ? null : "" + refKey;
  8077. // this.debug("reRegister", key, refKey);
  8078. var tree = this.tree,
  8079. prevKey = this.key,
  8080. prevRefKey = this.refKey,
  8081. keyMap = tree.keyMap,
  8082. refMap = tree.refMap,
  8083. refList = refMap[prevRefKey] || null,
  8084. // curCloneKeys = refList ? node.getCloneList(true),
  8085. modified = false;
  8086. // Key has changed: update all references
  8087. if( key != null && key !== this.key ) {
  8088. if( keyMap[key] ) {
  8089. $.error("[ext-clones] reRegister(" + key + "): already exists: " + this);
  8090. }
  8091. // Update keyMap
  8092. delete keyMap[prevKey];
  8093. keyMap[key] = this;
  8094. // Update refMap
  8095. if( refList ) {
  8096. refMap[prevRefKey] = $.map(refList, function(e){
  8097. return e === prevKey ? key : e;
  8098. });
  8099. }
  8100. this.key = key;
  8101. modified = true;
  8102. }
  8103. // refKey has changed
  8104. if( refKey != null && refKey !== this.refKey ) {
  8105. // Remove previous refKeys
  8106. if( refList ){
  8107. if( refList.length === 1 ){
  8108. delete refMap[prevRefKey];
  8109. }else{
  8110. refMap[prevRefKey] = $.map(refList, function(e){
  8111. return e === prevKey ? null : e;
  8112. });
  8113. }
  8114. }
  8115. // Add refKey
  8116. if( refMap[refKey] ) {
  8117. refMap[refKey].append(key);
  8118. }else{
  8119. refMap[refKey] = [ this.key ];
  8120. }
  8121. this.refKey = refKey;
  8122. modified = true;
  8123. }
  8124. return modified;
  8125. };
  8126. /**
  8127. * [ext-clones] Define a refKey for an existing node.
  8128. * @param {string} refKey
  8129. * @returns {boolean}
  8130. *
  8131. * @alias FancytreeNode#setRefKey
  8132. * @requires jquery.fancytree.clones.js
  8133. * @since 2.16
  8134. */
  8135. $.ui.fancytree._FancytreeNodeClass.prototype.setRefKey = function(refKey){
  8136. return this.reRegister(null, refKey);
  8137. };
  8138. /**
  8139. * [ext-clones] Return all nodes with a given refKey (null if not found).
  8140. * @param {string} refKey
  8141. * @param {FancytreeNode} [rootNode] optionally restrict results to descendants of this node
  8142. * @returns {FancytreeNode[] | null}
  8143. * @alias Fancytree#getNodesByRef
  8144. * @requires jquery.fancytree.clones.js
  8145. */
  8146. $.ui.fancytree._FancytreeClass.prototype.getNodesByRef = function(refKey, rootNode){
  8147. var keyMap = this.keyMap,
  8148. refList = this.refMap[refKey] || null;
  8149. if( refList ) {
  8150. // Convert key list to node list
  8151. if( rootNode ) {
  8152. refList = $.map(refList, function(val){
  8153. var node = keyMap[val];
  8154. return node.isDescendantOf(rootNode) ? node : null;
  8155. });
  8156. }else{
  8157. refList = $.map(refList, function(val){ return keyMap[val]; });
  8158. }
  8159. if( refList.length < 1 ) {
  8160. refList = null;
  8161. }
  8162. }
  8163. return refList;
  8164. };
  8165. /**
  8166. * [ext-clones] Replace a refKey with a new one.
  8167. * @param {string} oldRefKey
  8168. * @param {string} newRefKey
  8169. * @alias Fancytree#changeRefKey
  8170. * @requires jquery.fancytree.clones.js
  8171. */
  8172. $.ui.fancytree._FancytreeClass.prototype.changeRefKey = function(oldRefKey, newRefKey) {
  8173. var i, node,
  8174. keyMap = this.keyMap,
  8175. refList = this.refMap[oldRefKey] || null;
  8176. if (refList) {
  8177. for (i = 0; i < refList.length; i++) {
  8178. node = keyMap[refList[i]];
  8179. node.refKey = newRefKey;
  8180. }
  8181. delete this.refMap[oldRefKey];
  8182. this.refMap[newRefKey] = refList;
  8183. }
  8184. };
  8185. /*******************************************************************************
  8186. * Extension code
  8187. */
  8188. $.ui.fancytree.registerExtension({
  8189. name: "clones",
  8190. version: "2.26.0",
  8191. // Default options for this extension.
  8192. options: {
  8193. highlightActiveClones: true, // set 'fancytree-active-clone' on active clones and all peers
  8194. highlightClones: false // set 'fancytree-clone' class on any node that has at least one clone
  8195. },
  8196. treeCreate: function(ctx){
  8197. this._superApply(arguments);
  8198. ctx.tree.refMap = {};
  8199. ctx.tree.keyMap = {};
  8200. },
  8201. treeInit: function(ctx){
  8202. this.$container.addClass("fancytree-ext-clones");
  8203. _assert(ctx.options.defaultKey == null);
  8204. // Generate unique / reproducible default keys
  8205. ctx.options.defaultKey = function(node){
  8206. return calcUniqueKey(node);
  8207. };
  8208. // The default implementation loads initial data
  8209. this._superApply(arguments);
  8210. },
  8211. treeClear: function(ctx){
  8212. ctx.tree.refMap = {};
  8213. ctx.tree.keyMap = {};
  8214. return this._superApply(arguments);
  8215. },
  8216. treeRegisterNode: function(ctx, add, node) {
  8217. var refList, len,
  8218. tree = ctx.tree,
  8219. keyMap = tree.keyMap,
  8220. refMap = tree.refMap,
  8221. key = node.key,
  8222. refKey = (node && node.refKey != null) ? "" + node.refKey : null;
  8223. // ctx.tree.debug("clones.treeRegisterNode", add, node);
  8224. if( node.isStatusNode() ){
  8225. return this._super(ctx, add, node);
  8226. }
  8227. if( add ) {
  8228. if( keyMap[node.key] != null ) {
  8229. $.error("clones.treeRegisterNode: node.key already exists: " + node);
  8230. }
  8231. keyMap[key] = node;
  8232. if( refKey ) {
  8233. refList = refMap[refKey];
  8234. if( refList ) {
  8235. refList.push(key);
  8236. if( refList.length === 2 && ctx.options.clones.highlightClones ) {
  8237. // Mark peer node, if it just became a clone (no need to
  8238. // mark current node, since it will be rendered later anyway)
  8239. keyMap[refList[0]].renderStatus();
  8240. }
  8241. } else {
  8242. refMap[refKey] = [key];
  8243. }
  8244. // node.debug("clones.treeRegisterNode: add clone =>", refMap[refKey]);
  8245. }
  8246. }else {
  8247. if( keyMap[key] == null ) {
  8248. $.error("clones.treeRegisterNode: node.key not registered: " + node.key);
  8249. }
  8250. delete keyMap[key];
  8251. if( refKey ) {
  8252. refList = refMap[refKey];
  8253. // node.debug("clones.treeRegisterNode: remove clone BEFORE =>", refMap[refKey]);
  8254. if( refList ) {
  8255. len = refList.length;
  8256. if( len <= 1 ){
  8257. _assert(len === 1);
  8258. _assert(refList[0] === key);
  8259. delete refMap[refKey];
  8260. }else{
  8261. _removeArrayMember(refList, key);
  8262. // Unmark peer node, if this was the only clone
  8263. if( len === 2 && ctx.options.clones.highlightClones ) {
  8264. // node.debug("clones.treeRegisterNode: last =>", node.getCloneList());
  8265. keyMap[refList[0]].renderStatus();
  8266. }
  8267. }
  8268. // node.debug("clones.treeRegisterNode: remove clone =>", refMap[refKey]);
  8269. }
  8270. }
  8271. }
  8272. return this._super(ctx, add, node);
  8273. },
  8274. nodeRenderStatus: function(ctx) {
  8275. var $span, res,
  8276. node = ctx.node;
  8277. res = this._super(ctx);
  8278. if( ctx.options.clones.highlightClones ) {
  8279. $span = $(node[ctx.tree.statusClassPropName]);
  8280. // Only if span already exists
  8281. if( $span.length && node.isClone() ){
  8282. // node.debug("clones.nodeRenderStatus: ", ctx.options.clones.highlightClones);
  8283. $span.addClass("fancytree-clone");
  8284. }
  8285. }
  8286. return res;
  8287. },
  8288. nodeSetActive: function(ctx, flag, callOpts) {
  8289. var res,
  8290. scpn = ctx.tree.statusClassPropName,
  8291. node = ctx.node;
  8292. res = this._superApply(arguments);
  8293. if( ctx.options.clones.highlightActiveClones && node.isClone() ) {
  8294. $.each(node.getCloneList(true), function(idx, n){
  8295. // n.debug("clones.nodeSetActive: ", flag !== false);
  8296. $(n[scpn]).toggleClass("fancytree-active-clone", flag !== false);
  8297. });
  8298. }
  8299. return res;
  8300. }
  8301. });
  8302. // Value returned by `require('jquery.fancytree..')`
  8303. return $.ui.fancytree;
  8304. })); // End of closure
  8305. /*! Extension 'jquery.fancytree.dnd5.js' *//*!
  8306. * jquery.fancytree.dnd5.js
  8307. *
  8308. * Drag-and-drop support (native HTML5).
  8309. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8310. *
  8311. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  8312. *
  8313. * Released under the MIT license
  8314. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8315. *
  8316. * @version 2.26.0
  8317. * @date 2017-11-04T17:52:53Z
  8318. */
  8319. /*
  8320. #TODO
  8321. Compatiblity when dragging between *separate* windows:
  8322. Drag from Chrome Edge FF IE11 Safari
  8323. To Chrome ok ok ok NO ?
  8324. Edge ok ok ok NO ?
  8325. FF ok ok ok NO ?
  8326. IE 11 ok ok ok ok ?
  8327. Safari ? ? ? ? ok
  8328. */
  8329. ;(function( factory ) {
  8330. if ( typeof define === "function" && define.amd ) {
  8331. // AMD. Register as an anonymous module.
  8332. define( [ "jquery", "./jquery.fancytree" ], factory );
  8333. } else if ( typeof module === "object" && module.exports ) {
  8334. // Node/CommonJS
  8335. require("jquery.fancytree");
  8336. module.exports = factory(require("jquery"));
  8337. } else {
  8338. // Browser globals
  8339. factory( jQuery );
  8340. }
  8341. }( function( $ ) {
  8342. "use strict";
  8343. /* *****************************************************************************
  8344. * Private functions and variables
  8345. */
  8346. var
  8347. classDragSource = "fancytree-drag-source",
  8348. classDragRemove = "fancytree-drag-remove",
  8349. classDropAccept = "fancytree-drop-accept",
  8350. classDropAfter = "fancytree-drop-after",
  8351. classDropBefore = "fancytree-drop-before",
  8352. classDropOver = "fancytree-drop-over",
  8353. classDropReject = "fancytree-drop-reject",
  8354. classDropTarget = "fancytree-drop-target",
  8355. nodeMimeType = "application/x-fancytree-node",
  8356. $dropMarker = null,
  8357. SOURCE_NODE = null,
  8358. DRAG_ENTER_RESPONSE = null,
  8359. LAST_HIT_MODE = null;
  8360. /* Convert number to string and prepend +/-; return empty string for 0.*/
  8361. function offsetString(n){
  8362. return n === 0 ? "" : (( n > 0 ) ? ("+" + n) : ("" + n));
  8363. }
  8364. /* Convert a dragEnter() or dragOver() response to a canonical form.
  8365. * Return false or plain object
  8366. * @param {string|object|boolean} r
  8367. * @return {object|false}
  8368. */
  8369. function normalizeDragEnterResponse(r) {
  8370. var res;
  8371. if( !r ){
  8372. return false;
  8373. }
  8374. if ( $.isPlainObject(r) ) {
  8375. res = {
  8376. over: !!r.over,
  8377. before: !!r.before,
  8378. after: !!r.after
  8379. };
  8380. }else if ( $.isArray(r) ) {
  8381. res = {
  8382. over: ($.inArray("over", r) >= 0),
  8383. before: ($.inArray("before", r) >= 0),
  8384. after: ($.inArray("after", r) >= 0)
  8385. };
  8386. }else{
  8387. res = {
  8388. over: ((r === true) || (r === "over")),
  8389. before: ((r === true) || (r === "before")),
  8390. after: ((r === true) || (r === "after"))
  8391. };
  8392. }
  8393. if( Object.keys(res).length === 0 ) {
  8394. return false;
  8395. }
  8396. // if( Object.keys(res).length === 1 ) {
  8397. // res.unique = res[0];
  8398. // }
  8399. return res;
  8400. }
  8401. /* Implement auto scrolling when drag cursor is in top/bottom area of scroll parent. */
  8402. function autoScroll(tree, event) {
  8403. var spOfs, scrollTop, delta,
  8404. dndOpts = tree.options.dnd5,
  8405. sp = tree.$scrollParent[0],
  8406. sensitivity = dndOpts.scrollSensitivity,
  8407. speed = dndOpts.scrollSpeed,
  8408. scrolled = 0;
  8409. if ( sp !== document && sp.tagName !== "HTML" ) {
  8410. spOfs = tree.$scrollParent.offset();
  8411. scrollTop = sp.scrollTop;
  8412. if ( spOfs.top + sp.offsetHeight - event.pageY < sensitivity ) {
  8413. delta = (sp.scrollHeight - tree.$scrollParent.innerHeight() - scrollTop);
  8414. // console.log ("sp.offsetHeight: " + sp.offsetHeight
  8415. // + ", spOfs.top: " + spOfs.top
  8416. // + ", scrollTop: " + scrollTop
  8417. // + ", innerHeight: " + tree.$scrollParent.innerHeight()
  8418. // + ", scrollHeight: " + sp.scrollHeight
  8419. // + ", delta: " + delta
  8420. // );
  8421. if( delta > 0 ) {
  8422. sp.scrollTop = scrolled = scrollTop + speed;
  8423. }
  8424. } else if ( scrollTop > 0 && event.pageY - spOfs.top < sensitivity ) {
  8425. sp.scrollTop = scrolled = scrollTop - speed;
  8426. }
  8427. } else {
  8428. scrollTop = $(document).scrollTop();
  8429. if (scrollTop > 0 && event.pageY - scrollTop < sensitivity) {
  8430. scrolled = scrollTop - speed;
  8431. $(document).scrollTop(scrolled);
  8432. } else if ($(window).height() - (event.pageY - scrollTop) < sensitivity) {
  8433. scrolled = scrollTop + speed;
  8434. $(document).scrollTop(scrolled);
  8435. }
  8436. }
  8437. if( scrolled ) {
  8438. tree.debug("autoScroll: " + scrolled + "px");
  8439. }
  8440. return scrolled;
  8441. }
  8442. /* Handle dragover event (fired every x ms) and return hitMode. */
  8443. function handleDragOver(event, data) {
  8444. // Implement auto-scrolling
  8445. if ( data.options.dnd5.scroll ) {
  8446. autoScroll(data.tree, event);
  8447. }
  8448. // Bail out with previous response if we get an invalid dragover
  8449. if( !data.node ) {
  8450. data.tree.warn("Ignore dragover for non-node"); //, event, data);
  8451. return LAST_HIT_MODE;
  8452. }
  8453. var markerOffsetX, nodeOfs, relPosY, //res,
  8454. // eventHash = getEventHash(event),
  8455. hitMode = null,
  8456. tree = data.tree,
  8457. options = tree.options,
  8458. dndOpts = options.dnd5,
  8459. targetNode = data.node,
  8460. sourceNode = data.otherNode,
  8461. markerAt = "center",
  8462. // $source = sourceNode ? $(sourceNode.span) : null,
  8463. $target = $(targetNode.span),
  8464. $targetTitle = $target.find("span.fancytree-title");
  8465. if(DRAG_ENTER_RESPONSE === false){
  8466. tree.info("Ignore dragover, since dragenter returned false"); //, event, data);
  8467. // $.error("assert failed: dragenter returned false");
  8468. return false;
  8469. } else if(typeof DRAG_ENTER_RESPONSE === "string") {
  8470. $.error("assert failed: dragenter returned string");
  8471. // Use hitMode from onEnter if provided.
  8472. // hitMode = DRAG_ENTER_RESPONSE;
  8473. } else {
  8474. // Calculate hitMode from relative cursor position.
  8475. nodeOfs = $target.offset();
  8476. relPosY = (event.pageY - nodeOfs.top) / $target.height();
  8477. if( DRAG_ENTER_RESPONSE.after && relPosY > 0.75 ){
  8478. hitMode = "after";
  8479. } else if(!DRAG_ENTER_RESPONSE.over && DRAG_ENTER_RESPONSE.after && relPosY > 0.5 ){
  8480. hitMode = "after";
  8481. } else if(DRAG_ENTER_RESPONSE.before && relPosY <= 0.25) {
  8482. hitMode = "before";
  8483. } else if(!DRAG_ENTER_RESPONSE.over && DRAG_ENTER_RESPONSE.before && relPosY <= 0.5) {
  8484. hitMode = "before";
  8485. } else if(DRAG_ENTER_RESPONSE.over) {
  8486. hitMode = "over";
  8487. }
  8488. // Prevent no-ops like 'before source node'
  8489. // TODO: these are no-ops when moving nodes, but not in copy mode
  8490. if( dndOpts.preventVoidMoves ){
  8491. if(targetNode === sourceNode){
  8492. targetNode.debug("drop over source node prevented");
  8493. hitMode = null;
  8494. }else if(hitMode === "before" && sourceNode && targetNode === sourceNode.getNextSibling()){
  8495. targetNode.debug("drop after source node prevented");
  8496. hitMode = null;
  8497. }else if(hitMode === "after" && sourceNode && targetNode === sourceNode.getPrevSibling()){
  8498. targetNode.debug("drop before source node prevented");
  8499. hitMode = null;
  8500. }else if(hitMode === "over" && sourceNode && sourceNode.parent === targetNode && sourceNode.isLastSibling() ){
  8501. targetNode.debug("drop last child over own parent prevented");
  8502. hitMode = null;
  8503. }
  8504. }
  8505. }
  8506. // Let callback modify the calculated hitMode
  8507. data.hitMode = hitMode;
  8508. if(hitMode && dndOpts.dragOver){
  8509. // TODO: http://code.google.com/p/dynatree/source/detail?r=625
  8510. dndOpts.dragOver(targetNode, data);
  8511. hitMode = data.hitMode;
  8512. }
  8513. // LAST_DROP_EFFECT = data.dataTransfer.dropEffect;
  8514. // LAST_EFFECT_ALLOWED = data.dataTransfer.effectAllowed;
  8515. LAST_HIT_MODE = hitMode;
  8516. //
  8517. if( hitMode === "after" || hitMode === "before" || hitMode === "over" ){
  8518. markerOffsetX = dndOpts.dropMarkerOffsetX || 0;
  8519. switch(hitMode){
  8520. case "before":
  8521. markerAt = "top";
  8522. markerOffsetX += (dndOpts.dropMarkerInsertOffsetX || 0);
  8523. break;
  8524. case "after":
  8525. markerAt = "bottom";
  8526. markerOffsetX += (dndOpts.dropMarkerInsertOffsetX || 0);
  8527. break;
  8528. }
  8529. $dropMarker
  8530. .toggleClass(classDropAfter, hitMode === "after")
  8531. .toggleClass(classDropOver, hitMode === "over")
  8532. .toggleClass(classDropBefore, hitMode === "before")
  8533. .show()
  8534. .position($.ui.fancytree.fixPositionOptions({
  8535. my: "left" + offsetString(markerOffsetX) + " center",
  8536. at: "left " + markerAt,
  8537. of: $targetTitle
  8538. }));
  8539. } else {
  8540. $dropMarker.hide();
  8541. // console.log("hide dropmarker")
  8542. }
  8543. // if( $source ){
  8544. // $source.toggleClass(classDragRemove, isMove);
  8545. // }
  8546. $(targetNode.span)
  8547. .toggleClass(classDropTarget, hitMode === "after" || hitMode === "before" || hitMode === "over")
  8548. .toggleClass(classDropAfter, hitMode === "after")
  8549. .toggleClass(classDropBefore, hitMode === "before")
  8550. .toggleClass(classDropAccept, hitMode === "over")
  8551. .toggleClass(classDropReject, hitMode === false);
  8552. return hitMode;
  8553. }
  8554. /* *****************************************************************************
  8555. *
  8556. */
  8557. $.ui.fancytree.registerExtension({
  8558. name: "dnd5",
  8559. version: "2.26.0",
  8560. // Default options for this extension.
  8561. options: {
  8562. autoExpandMS: 1500, // Expand nodes after n milliseconds of hovering
  8563. setTextTypeJson: false, // Allow dragging of nodes to different IE windows
  8564. preventForeignNodes: false, // Prevent dropping nodes from different Fancytrees
  8565. preventNonNodes: false, // Prevent dropping items other than Fancytree nodes
  8566. preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
  8567. preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
  8568. scroll: true, // Enable auto-scrolling while dragging
  8569. scrollSensitivity: 20, // Active top/bottom margin in pixel
  8570. scrollSpeed: 5, // Pixel per event
  8571. dropMarkerOffsetX: -24, // absolute position offset for .fancytree-drop-marker relatively to ..fancytree-title (icon/img near a node accepting drop)
  8572. dropMarkerInsertOffsetX: -16,// additional offset for drop-marker with hitMode = "before"/"after"
  8573. // Events (drag support)
  8574. dragStart: null, // Callback(sourceNode, data), return true, to enable dnd drag
  8575. dragDrag: $.noop, // Callback(sourceNode, data)
  8576. dragEnd: $.noop, // Callback(sourceNode, data)
  8577. // Events (drop support)
  8578. dragEnter: null, // Callback(targetNode, data), return true, to enable dnd drop
  8579. dragOver: $.noop, // Callback(targetNode, data)
  8580. dragExpand: $.noop, // Callback(targetNode, data), return false to prevent autoExpand
  8581. dragDrop: $.noop, // Callback(targetNode, data)
  8582. dragLeave: $.noop // Callback(targetNode, data)
  8583. },
  8584. treeInit: function(ctx){
  8585. var $temp,
  8586. tree = ctx.tree,
  8587. opts = ctx.options,
  8588. glyph = opts.glyph || null,
  8589. dndOpts = opts.dnd5,
  8590. getNode = $.ui.fancytree.getNode;
  8591. if( $.inArray("dnd", opts.extensions) >= 0 ) {
  8592. $.error("Extensions 'dnd' and 'dnd5' are mutually exclusive.");
  8593. }
  8594. if( dndOpts.dragStop ) {
  8595. $.error("dragStop is not used by ext-dnd5. Use dragEnd instead.");
  8596. }
  8597. // Implement `opts.createNode` event to add the 'draggable' attribute
  8598. // #680: this must happen before calling super.treeInit()
  8599. if( dndOpts.dragStart ) {
  8600. $.ui.fancytree.overrideMethod(ctx.options, "createNode", function(event, data) {
  8601. // Default processing if any
  8602. this._super.apply(this, arguments);
  8603. data.node.span.draggable = true;
  8604. });
  8605. }
  8606. this._superApply(arguments);
  8607. this.$container.addClass("fancytree-ext-dnd5");
  8608. // Store the current scroll parent, which may be the tree
  8609. // container, any enclosing div, or the document.
  8610. // #761: scrollParent() always needs a container child
  8611. $temp = $("<span>").appendTo(this.$container);
  8612. this.$scrollParent = $temp.scrollParent();
  8613. $temp.remove();
  8614. $dropMarker = $("#fancytree-drop-marker");
  8615. if( !$dropMarker.length ) {
  8616. $dropMarker = $("<div id='fancytree-drop-marker'></div>")
  8617. .hide()
  8618. .css({
  8619. "z-index": 1000,
  8620. // Drop marker should not steal dragenter/dragover events:
  8621. "pointer-events": "none"
  8622. }).prependTo("body");
  8623. if( glyph ) {
  8624. $dropMarker.addClass(glyph.map.dropMarker);
  8625. }
  8626. }
  8627. // Enable drag support if dragStart() is specified:
  8628. if( dndOpts.dragStart ) {
  8629. // Bind drag event handlers
  8630. tree.$container.on("dragstart drag dragend", function(event){
  8631. var json,
  8632. node = getNode(event),
  8633. dataTransfer = event.dataTransfer || event.originalEvent.dataTransfer,
  8634. isMove = dataTransfer.dropEffect === "move",
  8635. $source = node ? $(node.span) : null,
  8636. data = {
  8637. node: node,
  8638. tree: tree,
  8639. options: tree.options,
  8640. originalEvent: event,
  8641. dataTransfer: dataTransfer,
  8642. // dropEffect: undefined, // set by dragend
  8643. isCancelled: undefined // set by dragend
  8644. };
  8645. switch( event.type ) {
  8646. case "dragstart":
  8647. $(node.span).addClass(classDragSource);
  8648. // Store current source node in different formats
  8649. SOURCE_NODE = node;
  8650. // Set payload
  8651. // Note:
  8652. // Transfer data is only accessible on dragstart and drop!
  8653. // For all other events the formats and kinds in the drag
  8654. // data store list of items representing dragged data can be
  8655. // enumerated, but the data itself is unavailable and no new
  8656. // data can be added.
  8657. json = JSON.stringify(node.toDict());
  8658. try {
  8659. dataTransfer.setData(nodeMimeType, json);
  8660. dataTransfer.setData("text/html", $(node.span).html());
  8661. dataTransfer.setData("text/plain", node.title);
  8662. } catch(ex) {
  8663. // IE only accepts 'text' type
  8664. tree.warn("Could not set data (IE only accepts 'text') - " + ex);
  8665. }
  8666. // We always need to set the 'text' type if we want to drag
  8667. // Because IE 11 only accepts this single type.
  8668. // If we pass JSON here, IE can can access all node properties,
  8669. // even when the source lives in another window. (D'n'd inside
  8670. // the same window will always work.)
  8671. // The drawback is, that in this case ALL browsers will see
  8672. // the JSON representation as 'text', so dragging
  8673. // to a text field will insert the JSON string instead of
  8674. // the node title.
  8675. if( dndOpts.setTextTypeJson ) {
  8676. dataTransfer.setData("text", json);
  8677. } else {
  8678. dataTransfer.setData("text", node.title);
  8679. }
  8680. // Set the allowed and current drag mode (move, copy, or link)
  8681. dataTransfer.effectAllowed = "all"; // "copyMove"
  8682. // dataTransfer.dropEffect = "move";
  8683. // Set the title as drag image (otherwise it would contain the expander)
  8684. if( dataTransfer.setDragImage ) {
  8685. // IE 11 does not support this
  8686. dataTransfer.setDragImage($(node.span).find(".fancytree-title")[0], -10, -10);
  8687. // dataTransfer.setDragImage($(node.span)[0], -10, -10);
  8688. }
  8689. // Let user modify above settings
  8690. return dndOpts.dragStart(node, data) !== false;
  8691. case "drag":
  8692. // Called every few miliseconds
  8693. $source.toggleClass(classDragRemove, isMove);
  8694. dndOpts.dragDrag(node, data);
  8695. break;
  8696. case "dragend":
  8697. $(node.span).removeClass(classDragSource + " " + classDragRemove);
  8698. SOURCE_NODE = null;
  8699. DRAG_ENTER_RESPONSE = null;
  8700. // data.dropEffect = dataTransfer.dropEffect;
  8701. data.isCancelled = (dataTransfer.dropEffect === "none");
  8702. $dropMarker.hide();
  8703. dndOpts.dragEnd(node, data);
  8704. break;
  8705. }
  8706. });
  8707. }
  8708. // Enable drop support if dragEnter() is specified:
  8709. if( dndOpts.dragEnter ) {
  8710. // Bind drop event handlers
  8711. tree.$container.on("dragenter dragover dragleave drop", function(event){
  8712. var json, nodeData, r, res,
  8713. allowDrop = null,
  8714. node = getNode(event),
  8715. dataTransfer = event.dataTransfer || event.originalEvent.dataTransfer,
  8716. data = {
  8717. node: node,
  8718. tree: tree,
  8719. options: tree.options,
  8720. hitMode: DRAG_ENTER_RESPONSE,
  8721. originalEvent: event,
  8722. dataTransfer: dataTransfer,
  8723. otherNode: SOURCE_NODE || null,
  8724. otherNodeData: null, // set by drop event
  8725. dropEffect: undefined, // set by drop event
  8726. isCancelled: undefined // set by drop event
  8727. };
  8728. switch( event.type ) {
  8729. case "dragenter":
  8730. // The dragenter event is fired when a dragged element or
  8731. // text selection enters a valid drop target.
  8732. if( !node ) {
  8733. // Sometimes we get dragenter for the container element
  8734. tree.debug("Ignore non-node " + event.type + ": " + event.target.tagName + "." + event.target.className);
  8735. DRAG_ENTER_RESPONSE = false;
  8736. break;
  8737. }
  8738. $(node.span)
  8739. .addClass(classDropOver)
  8740. .removeClass(classDropAccept + " " + classDropReject);
  8741. if( dndOpts.preventNonNodes && !nodeData ) {
  8742. node.debug("Reject dropping a non-node");
  8743. DRAG_ENTER_RESPONSE = false;
  8744. break;
  8745. } else if( dndOpts.preventForeignNodes && (!SOURCE_NODE || SOURCE_NODE.tree !== node.tree ) ) {
  8746. node.debug("Reject dropping a foreign node");
  8747. DRAG_ENTER_RESPONSE = false;
  8748. break;
  8749. }
  8750. // NOTE: dragenter is fired BEFORE the dragleave event
  8751. // of the previous element!
  8752. // https://www.w3.org/Bugs/Public/show_bug.cgi?id=19041
  8753. setTimeout(function(){
  8754. // node.info("DELAYED " + event.type, event.target, DRAG_ENTER_RESPONSE);
  8755. // Auto-expand node (only when 'over' the node, not 'before', or 'after')
  8756. if( dndOpts.autoExpandMS &&
  8757. node.hasChildren() !== false && !node.expanded &&
  8758. (!dndOpts.dragExpand || dndOpts.dragExpand(node, data) !== false)
  8759. ) {
  8760. node.scheduleAction("expand", dndOpts.autoExpandMS);
  8761. }
  8762. }, 0);
  8763. $dropMarker.show();
  8764. // Call dragEnter() to figure out if (and where) dropping is allowed
  8765. if( dndOpts.preventRecursiveMoves && node.isDescendantOf(data.otherNode) ){
  8766. res = false;
  8767. }else{
  8768. r = dndOpts.dragEnter(node, data);
  8769. res = normalizeDragEnterResponse(r);
  8770. }
  8771. DRAG_ENTER_RESPONSE = res;
  8772. allowDrop = res && ( res.over || res.before || res.after );
  8773. break;
  8774. case "dragover":
  8775. // The dragover event is fired when an element or text
  8776. // selection is being dragged over a valid drop target
  8777. // (every few hundred milliseconds).
  8778. LAST_HIT_MODE = handleDragOver(event, data);
  8779. allowDrop = !!LAST_HIT_MODE;
  8780. break;
  8781. case "dragleave":
  8782. // NOTE: dragleave is fired AFTER the dragenter event of the
  8783. // FOLLOWING element.
  8784. if( !node ) {
  8785. tree.debug("Ignore non-node " + event.type + ": " + event.target.tagName + "." + event.target.className);
  8786. break;
  8787. }
  8788. if( !$(node.span).hasClass(classDropOver) ) {
  8789. node.debug("Ignore dragleave (multi)"); //, event.currentTarget);
  8790. break;
  8791. }
  8792. $(node.span).removeClass(classDropOver + " " + classDropAccept + " " + classDropReject);
  8793. node.scheduleAction("cancel");
  8794. dndOpts.dragLeave(node, data);
  8795. $dropMarker.hide();
  8796. break;
  8797. case "drop":
  8798. // Data is only readable in the (dragenter and) drop event:
  8799. if( $.inArray(nodeMimeType, dataTransfer.types) >= 0 ) {
  8800. nodeData = dataTransfer.getData(nodeMimeType);
  8801. tree.info(event.type + ": getData('application/x-fancytree-node'): '" + nodeData + "'");
  8802. }
  8803. if( !nodeData ) {
  8804. // 1. Source is not a Fancytree node, or
  8805. // 2. If the FT mime type was set, but returns '', this
  8806. // is probably IE 11 (which only supports 'text')
  8807. nodeData = dataTransfer.getData("text");
  8808. tree.info(event.type + ": getData('text'): '" + nodeData + "'");
  8809. }
  8810. if( nodeData ) {
  8811. try {
  8812. // 'text' type may contain JSON if IE is involved
  8813. // and setTextTypeJson option was set
  8814. json = JSON.parse(nodeData);
  8815. if( json.title !== undefined ) {
  8816. data.otherNodeData = json;
  8817. }
  8818. } catch(ex) {
  8819. // assume 'text' type contains plain text, so `otherNodeData`
  8820. // should not be set
  8821. }
  8822. }
  8823. tree.debug(event.type + ": nodeData: '" + nodeData + "', otherNodeData: ", data.otherNodeData);
  8824. $(node.span).removeClass(classDropOver + " " + classDropAccept + " " + classDropReject);
  8825. $dropMarker.hide();
  8826. data.hitMode = LAST_HIT_MODE;
  8827. data.dropEffect = dataTransfer.dropEffect;
  8828. data.isCancelled = data.dropEffect === "none";
  8829. // Let user implement the actual drop operation
  8830. dndOpts.dragDrop(node, data);
  8831. // Prevent browser's default drop handling
  8832. event.preventDefault();
  8833. break;
  8834. }
  8835. // Dnd API madness: we must PREVENT default handling to enable dropping
  8836. if( allowDrop ) {
  8837. event.preventDefault();
  8838. return false;
  8839. }
  8840. });
  8841. }
  8842. }
  8843. });
  8844. // Value returned by `require('jquery.fancytree..')`
  8845. return $.ui.fancytree;
  8846. })); // End of closure
  8847. /*! Extension 'jquery.fancytree.edit.js' *//*!
  8848. * jquery.fancytree.edit.js
  8849. *
  8850. * Make node titles editable.
  8851. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8852. *
  8853. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  8854. *
  8855. * Released under the MIT license
  8856. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8857. *
  8858. * @version 2.26.0
  8859. * @date 2017-11-04T17:52:53Z
  8860. */
  8861. ;(function( factory ) {
  8862. if ( typeof define === "function" && define.amd ) {
  8863. // AMD. Register as an anonymous module.
  8864. define( [ "jquery", "./jquery.fancytree" ], factory );
  8865. } else if ( typeof module === "object" && module.exports ) {
  8866. // Node/CommonJS
  8867. require("jquery.fancytree");
  8868. module.exports = factory(require("jquery"));
  8869. } else {
  8870. // Browser globals
  8871. factory( jQuery );
  8872. }
  8873. }( function( $ ) {
  8874. "use strict";
  8875. /*******************************************************************************
  8876. * Private functions and variables
  8877. */
  8878. var isMac = /Mac/.test(navigator.platform),
  8879. escapeHtml = $.ui.fancytree.escapeHtml,
  8880. unescapeHtml = $.ui.fancytree.unescapeHtml;
  8881. /**
  8882. * [ext-edit] Start inline editing of current node title.
  8883. *
  8884. * @alias FancytreeNode#editStart
  8885. * @requires Fancytree
  8886. */
  8887. $.ui.fancytree._FancytreeNodeClass.prototype.editStart = function(){
  8888. var $input,
  8889. node = this,
  8890. tree = this.tree,
  8891. local = tree.ext.edit,
  8892. instOpts = tree.options.edit,
  8893. $title = $(".fancytree-title", node.span),
  8894. eventData = {
  8895. node: node,
  8896. tree: tree,
  8897. options: tree.options,
  8898. isNew: $(node[tree.statusClassPropName]).hasClass("fancytree-edit-new"),
  8899. orgTitle: node.title,
  8900. input: null,
  8901. dirty: false
  8902. };
  8903. // beforeEdit may want to modify the title before editing
  8904. if( instOpts.beforeEdit.call(node, {type: "beforeEdit"}, eventData) === false ) {
  8905. return false;
  8906. }
  8907. $.ui.fancytree.assert(!local.currentNode, "recursive edit");
  8908. local.currentNode = this;
  8909. local.eventData = eventData;
  8910. // Disable standard Fancytree mouse- and key handling
  8911. tree.widget._unbind();
  8912. // #116: ext-dnd prevents the blur event, so we have to catch outer clicks
  8913. $(document).on("mousedown.fancytree-edit", function(event){
  8914. if( ! $(event.target).hasClass("fancytree-edit-input") ){
  8915. node.editEnd(true, event);
  8916. }
  8917. });
  8918. // Replace node with <input>
  8919. $input = $("<input />", {
  8920. "class": "fancytree-edit-input",
  8921. type: "text",
  8922. value: tree.options.escapeTitles ? eventData.orgTitle : unescapeHtml(eventData.orgTitle)
  8923. });
  8924. local.eventData.input = $input;
  8925. if ( instOpts.adjustWidthOfs != null ) {
  8926. $input.width($title.width() + instOpts.adjustWidthOfs);
  8927. }
  8928. if ( instOpts.inputCss != null ) {
  8929. $input.css(instOpts.inputCss);
  8930. }
  8931. $title.html($input);
  8932. // Focus <input> and bind keyboard handler
  8933. $input
  8934. .focus()
  8935. .change(function(event){
  8936. $input.addClass("fancytree-edit-dirty");
  8937. }).keydown(function(event){
  8938. switch( event.which ) {
  8939. case $.ui.keyCode.ESCAPE:
  8940. node.editEnd(false, event);
  8941. break;
  8942. case $.ui.keyCode.ENTER:
  8943. node.editEnd(true, event);
  8944. return false; // so we don't start editmode on Mac
  8945. }
  8946. event.stopPropagation();
  8947. }).blur(function(event){
  8948. return node.editEnd(true, event);
  8949. });
  8950. instOpts.edit.call(node, {type: "edit"}, eventData);
  8951. };
  8952. /**
  8953. * [ext-edit] Stop inline editing.
  8954. * @param {Boolean} [applyChanges=false] false: cancel edit, true: save (if modified)
  8955. * @alias FancytreeNode#editEnd
  8956. * @requires jquery.fancytree.edit.js
  8957. */
  8958. $.ui.fancytree._FancytreeNodeClass.prototype.editEnd = function(applyChanges, _event){
  8959. var newVal,
  8960. node = this,
  8961. tree = this.tree,
  8962. local = tree.ext.edit,
  8963. eventData = local.eventData,
  8964. instOpts = tree.options.edit,
  8965. $title = $(".fancytree-title", node.span),
  8966. $input = $title.find("input.fancytree-edit-input");
  8967. if( instOpts.trim ) {
  8968. $input.val($.trim($input.val()));
  8969. }
  8970. newVal = $input.val();
  8971. eventData.dirty = ( newVal !== node.title );
  8972. eventData.originalEvent = _event;
  8973. // Find out, if saving is required
  8974. if( applyChanges === false ) {
  8975. // If true/false was passed, honor this (except in rename mode, if unchanged)
  8976. eventData.save = false;
  8977. } else if( eventData.isNew ) {
  8978. // In create mode, we save everyting, except for empty text
  8979. eventData.save = (newVal !== "");
  8980. } else {
  8981. // In rename mode, we save everyting, except for empty or unchanged text
  8982. eventData.save = eventData.dirty && (newVal !== "");
  8983. }
  8984. // Allow to break (keep editor open), modify input, or re-define data.save
  8985. if( instOpts.beforeClose.call(node, {type: "beforeClose"}, eventData) === false){
  8986. return false;
  8987. }
  8988. if( eventData.save && instOpts.save.call(node, {type: "save"}, eventData) === false){
  8989. return false;
  8990. }
  8991. $input
  8992. .removeClass("fancytree-edit-dirty")
  8993. .off();
  8994. // Unbind outer-click handler
  8995. $(document).off(".fancytree-edit");
  8996. if( eventData.save ) {
  8997. // # 171: escape user input (not required if global escaping is on)
  8998. node.setTitle( tree.options.escapeTitles ? newVal : escapeHtml(newVal) );
  8999. node.setFocus();
  9000. }else{
  9001. if( eventData.isNew ) {
  9002. node.remove();
  9003. node = eventData.node = null;
  9004. local.relatedNode.setFocus();
  9005. } else {
  9006. node.renderTitle();
  9007. node.setFocus();
  9008. }
  9009. }
  9010. local.eventData = null;
  9011. local.currentNode = null;
  9012. local.relatedNode = null;
  9013. // Re-enable mouse and keyboard handling
  9014. tree.widget._bind();
  9015. // Set keyboard focus, even if setFocus() claims 'nothing to do'
  9016. $(tree.$container).focus();
  9017. eventData.input = null;
  9018. instOpts.close.call(node, {type: "close"}, eventData);
  9019. return true;
  9020. };
  9021. /**
  9022. * [ext-edit] Create a new child or sibling node and start edit mode.
  9023. *
  9024. * @param {String} [mode='child'] 'before', 'after', or 'child'
  9025. * @param {Object} [init] NodeData (or simple title string)
  9026. * @alias FancytreeNode#editCreateNode
  9027. * @requires jquery.fancytree.edit.js
  9028. * @since 2.4
  9029. */
  9030. $.ui.fancytree._FancytreeNodeClass.prototype.editCreateNode = function(mode, init){
  9031. var newNode,
  9032. tree = this.tree,
  9033. self = this;
  9034. mode = mode || "child";
  9035. if( init == null ) {
  9036. init = { title: "" };
  9037. } else if( typeof init === "string" ) {
  9038. init = { title: init };
  9039. } else {
  9040. $.ui.fancytree.assert($.isPlainObject(init));
  9041. }
  9042. // Make sure node is expanded (and loaded) in 'child' mode
  9043. if( mode === "child" && !this.isExpanded() && this.hasChildren() !== false ) {
  9044. this.setExpanded().done(function(){
  9045. self.editCreateNode(mode, init);
  9046. });
  9047. return;
  9048. }
  9049. newNode = this.addNode(init, mode);
  9050. // #644: Don't filter new nodes.
  9051. newNode.match = true;
  9052. $(newNode[tree.statusClassPropName])
  9053. .removeClass("fancytree-hide")
  9054. .addClass("fancytree-match");
  9055. newNode.makeVisible(/*{noAnimation: true}*/).done(function(){
  9056. $(newNode[tree.statusClassPropName]).addClass("fancytree-edit-new");
  9057. self.tree.ext.edit.relatedNode = self;
  9058. newNode.editStart();
  9059. });
  9060. };
  9061. /**
  9062. * [ext-edit] Check if any node in this tree in edit mode.
  9063. *
  9064. * @returns {FancytreeNode | null}
  9065. * @alias Fancytree#isEditing
  9066. * @requires jquery.fancytree.edit.js
  9067. */
  9068. $.ui.fancytree._FancytreeClass.prototype.isEditing = function(){
  9069. return this.ext.edit ? this.ext.edit.currentNode : null;
  9070. };
  9071. /**
  9072. * [ext-edit] Check if this node is in edit mode.
  9073. * @returns {Boolean} true if node is currently beeing edited
  9074. * @alias FancytreeNode#isEditing
  9075. * @requires jquery.fancytree.edit.js
  9076. */
  9077. $.ui.fancytree._FancytreeNodeClass.prototype.isEditing = function(){
  9078. return this.tree.ext.edit ? this.tree.ext.edit.currentNode === this : false;
  9079. };
  9080. /*******************************************************************************
  9081. * Extension code
  9082. */
  9083. $.ui.fancytree.registerExtension({
  9084. name: "edit",
  9085. version: "2.26.0",
  9086. // Default options for this extension.
  9087. options: {
  9088. adjustWidthOfs: 4, // null: don't adjust input size to content
  9089. allowEmpty: false, // Prevent empty input
  9090. inputCss: {minWidth: "3em"},
  9091. // triggerCancel: ["esc", "tab", "click"],
  9092. // triggerStart: ["f2", "dblclick", "shift+click", "mac+enter"],
  9093. triggerStart: ["f2", "shift+click", "mac+enter"],
  9094. trim: true, // Trim whitespace before save
  9095. // Events:
  9096. beforeClose: $.noop, // Return false to prevent cancel/save (data.input is available)
  9097. beforeEdit: $.noop, // Return false to prevent edit mode
  9098. close: $.noop, // Editor was removed
  9099. edit: $.noop, // Editor was opened (available as data.input)
  9100. // keypress: $.noop, // Not yet implemented
  9101. save: $.noop // Save data.input.val() or return false to keep editor open
  9102. },
  9103. // Local attributes
  9104. currentNode: null,
  9105. treeInit: function(ctx){
  9106. this._superApply(arguments);
  9107. this.$container.addClass("fancytree-ext-edit");
  9108. },
  9109. nodeClick: function(ctx) {
  9110. if( $.inArray("shift+click", ctx.options.edit.triggerStart) >= 0 ){
  9111. if( ctx.originalEvent.shiftKey ){
  9112. ctx.node.editStart();
  9113. return false;
  9114. }
  9115. }
  9116. return this._superApply(arguments);
  9117. },
  9118. nodeDblclick: function(ctx) {
  9119. if( $.inArray("dblclick", ctx.options.edit.triggerStart) >= 0 ){
  9120. ctx.node.editStart();
  9121. return false;
  9122. }
  9123. return this._superApply(arguments);
  9124. },
  9125. nodeKeydown: function(ctx) {
  9126. switch( ctx.originalEvent.which ) {
  9127. case 113: // [F2]
  9128. if( $.inArray("f2", ctx.options.edit.triggerStart) >= 0 ){
  9129. ctx.node.editStart();
  9130. return false;
  9131. }
  9132. break;
  9133. case $.ui.keyCode.ENTER:
  9134. if( $.inArray("mac+enter", ctx.options.edit.triggerStart) >= 0 && isMac ){
  9135. ctx.node.editStart();
  9136. return false;
  9137. }
  9138. break;
  9139. }
  9140. return this._superApply(arguments);
  9141. }
  9142. });
  9143. // Value returned by `require('jquery.fancytree..')`
  9144. return $.ui.fancytree;
  9145. })); // End of closure
  9146. /*! Extension 'jquery.fancytree.filter.js' *//*!
  9147. * jquery.fancytree.filter.js
  9148. *
  9149. * Remove or highlight tree nodes, based on a filter.
  9150. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  9151. *
  9152. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  9153. *
  9154. * Released under the MIT license
  9155. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  9156. *
  9157. * @version 2.26.0
  9158. * @date 2017-11-04T17:52:53Z
  9159. */
  9160. ;(function( factory ) {
  9161. if ( typeof define === "function" && define.amd ) {
  9162. // AMD. Register as an anonymous module.
  9163. define( [ "jquery", "./jquery.fancytree" ], factory );
  9164. } else if ( typeof module === "object" && module.exports ) {
  9165. // Node/CommonJS
  9166. require("jquery.fancytree");
  9167. module.exports = factory(require("jquery"));
  9168. } else {
  9169. // Browser globals
  9170. factory( jQuery );
  9171. }
  9172. }( function( $ ) {
  9173. "use strict";
  9174. /*******************************************************************************
  9175. * Private functions and variables
  9176. */
  9177. var KeyNoData = "__not_found__",
  9178. escapeHtml = $.ui.fancytree.escapeHtml;
  9179. function _escapeRegex(str){
  9180. /*jshint regexdash:true */
  9181. return (str + "").replace(/([.?*+\^\$\[\]\\(){}|-])/g, "\\$1");
  9182. }
  9183. function extractHtmlText(s){
  9184. if( s.indexOf(">") >= 0 ) {
  9185. return $("<div/>").html(s).text();
  9186. }
  9187. return s;
  9188. }
  9189. $.ui.fancytree._FancytreeClass.prototype._applyFilterImpl = function(filter, branchMode, _opts){
  9190. var match, statusNode, re, reHighlight, temp,
  9191. count = 0,
  9192. treeOpts = this.options,
  9193. escapeTitles = treeOpts.escapeTitles,
  9194. prevAutoCollapse = treeOpts.autoCollapse,
  9195. opts = $.extend({}, treeOpts.filter, _opts),
  9196. hideMode = opts.mode === "hide",
  9197. leavesOnly = !!opts.leavesOnly && !branchMode;
  9198. // Default to 'match title substring (not case sensitive)'
  9199. if(typeof filter === "string"){
  9200. if( filter === "" ) {
  9201. this.warn("Fancytree passing an empty string as a filter is handled as clearFilter().");
  9202. this.clearFilter();
  9203. return;
  9204. }
  9205. if( opts.fuzzy ) {
  9206. // See https://codereview.stackexchange.com/questions/23899/faster-javascript-fuzzy-string-matching-function/23905#23905
  9207. // and http://www.quora.com/How-is-the-fuzzy-search-algorithm-in-Sublime-Text-designed
  9208. // and http://www.dustindiaz.com/autocomplete-fuzzy-matching
  9209. match = filter.split("").reduce(function(a, b) {
  9210. return a + "[^" + b + "]*" + b;
  9211. });
  9212. } else {
  9213. match = _escapeRegex(filter); // make sure a '.' is treated literally
  9214. }
  9215. re = new RegExp(".*" + match + ".*", "i");
  9216. reHighlight = new RegExp(_escapeRegex(filter), "gi");
  9217. filter = function(node){
  9218. var text = escapeTitles ? node.title : extractHtmlText(node.title),
  9219. res = !!re.test(text);
  9220. if( res && opts.highlight ) {
  9221. if( escapeTitles ) {
  9222. // #740: we must not apply the marks to escaped entity names, e.g. `&quot;`
  9223. // Use some exotic characters to mark matches:
  9224. temp = text.replace(reHighlight, function(s){
  9225. return "\uFFF7" + s + "\uFFF8";
  9226. });
  9227. // now we can escape the title...
  9228. node.titleWithHighlight = escapeHtml(temp)
  9229. // ... and finally insert the desired `<mark>` tags
  9230. .replace(/\uFFF7/g, "<mark>")
  9231. .replace(/\uFFF8/g, "</mark>");
  9232. } else {
  9233. node.titleWithHighlight = text.replace(reHighlight, function(s){
  9234. return "<mark>" + s + "</mark>";
  9235. });
  9236. }
  9237. // node.debug("filter", escapeTitles, text, node.titleWithHighlight);
  9238. }
  9239. return res;
  9240. };
  9241. }
  9242. this.enableFilter = true;
  9243. this.lastFilterArgs = arguments;
  9244. this.$div.addClass("fancytree-ext-filter");
  9245. if( hideMode ){
  9246. this.$div.addClass("fancytree-ext-filter-hide");
  9247. } else {
  9248. this.$div.addClass("fancytree-ext-filter-dimm");
  9249. }
  9250. this.$div.toggleClass("fancytree-ext-filter-hide-expanders", !!opts.hideExpanders);
  9251. // Reset current filter
  9252. this.visit(function(node){
  9253. delete node.match;
  9254. delete node.titleWithHighlight;
  9255. node.subMatchCount = 0;
  9256. });
  9257. statusNode = this.getRootNode()._findDirectChild(KeyNoData);
  9258. if( statusNode ) {
  9259. statusNode.remove();
  9260. }
  9261. // Adjust node.hide, .match, and .subMatchCount properties
  9262. treeOpts.autoCollapse = false; // #528
  9263. this.visit(function(node){
  9264. if ( leavesOnly && node.children != null ) {
  9265. return;
  9266. }
  9267. var res = filter(node),
  9268. matchedByBranch = false;
  9269. if( res === "skip" ) {
  9270. node.visit(function(c){
  9271. c.match = false;
  9272. }, true);
  9273. return "skip";
  9274. }
  9275. if( !res && (branchMode || res === "branch") && node.parent.match ) {
  9276. res = true;
  9277. matchedByBranch = true;
  9278. }
  9279. if( res ) {
  9280. count++;
  9281. node.match = true;
  9282. node.visitParents(function(p){
  9283. p.subMatchCount += 1;
  9284. // Expand match (unless this is no real match, but only a node in a matched branch)
  9285. if( opts.autoExpand && !matchedByBranch && !p.expanded ) {
  9286. p.setExpanded(true, {noAnimation: true, noEvents: true, scrollIntoView: false});
  9287. p._filterAutoExpanded = true;
  9288. }
  9289. });
  9290. }
  9291. });
  9292. treeOpts.autoCollapse = prevAutoCollapse;
  9293. if( count === 0 && opts.nodata && hideMode ) {
  9294. statusNode = opts.nodata;
  9295. if( $.isFunction(statusNode) ) {
  9296. statusNode = statusNode();
  9297. }
  9298. if( statusNode === true ) {
  9299. statusNode = {};
  9300. } else if( typeof statusNode === "string" ) {
  9301. statusNode = { title: statusNode };
  9302. }
  9303. statusNode = $.extend({
  9304. statusNodeType: "nodata",
  9305. key: KeyNoData,
  9306. title: this.options.strings.noData
  9307. }, statusNode);
  9308. this.getRootNode().addNode(statusNode).match = true;
  9309. }
  9310. // Redraw whole tree
  9311. this.render();
  9312. return count;
  9313. };
  9314. /**
  9315. * [ext-filter] Dimm or hide nodes.
  9316. *
  9317. * @param {function | string} filter
  9318. * @param {boolean} [opts={autoExpand: false, leavesOnly: false}]
  9319. * @returns {integer} count
  9320. * @alias Fancytree#filterNodes
  9321. * @requires jquery.fancytree.filter.js
  9322. */
  9323. $.ui.fancytree._FancytreeClass.prototype.filterNodes = function(filter, opts) {
  9324. if( typeof opts === "boolean" ) {
  9325. opts = { leavesOnly: opts };
  9326. this.warn("Fancytree.filterNodes() leavesOnly option is deprecated since 2.9.0 / 2015-04-19. Use opts.leavesOnly instead.");
  9327. }
  9328. return this._applyFilterImpl(filter, false, opts);
  9329. };
  9330. /**
  9331. * @deprecated
  9332. */
  9333. $.ui.fancytree._FancytreeClass.prototype.applyFilter = function(filter){
  9334. this.warn("Fancytree.applyFilter() is deprecated since 2.1.0 / 2014-05-29. Use .filterNodes() instead.");
  9335. return this.filterNodes.apply(this, arguments);
  9336. };
  9337. /**
  9338. * [ext-filter] Dimm or hide whole branches.
  9339. *
  9340. * @param {function | string} filter
  9341. * @param {boolean} [opts={autoExpand: false}]
  9342. * @returns {integer} count
  9343. * @alias Fancytree#filterBranches
  9344. * @requires jquery.fancytree.filter.js
  9345. */
  9346. $.ui.fancytree._FancytreeClass.prototype.filterBranches = function(filter, opts){
  9347. return this._applyFilterImpl(filter, true, opts);
  9348. };
  9349. /**
  9350. * [ext-filter] Reset the filter.
  9351. *
  9352. * @alias Fancytree#clearFilter
  9353. * @requires jquery.fancytree.filter.js
  9354. */
  9355. $.ui.fancytree._FancytreeClass.prototype.clearFilter = function(){
  9356. var $title,
  9357. statusNode = this.getRootNode()._findDirectChild(KeyNoData),
  9358. escapeTitles = this.options.escapeTitles,
  9359. enhanceTitle = this.options.enhanceTitle;
  9360. if( statusNode ) {
  9361. statusNode.remove();
  9362. }
  9363. this.visit(function(node){
  9364. if( node.match && node.span ) { // #491, #601
  9365. $title = $(node.span).find(">span.fancytree-title");
  9366. if( escapeTitles ) {
  9367. $title.text(node.title);
  9368. } else {
  9369. $title.html(node.title);
  9370. }
  9371. if( enhanceTitle ) {
  9372. enhanceTitle({type: "enhanceTitle"}, {node: node, $title: $title});
  9373. }
  9374. }
  9375. delete node.match;
  9376. delete node.subMatchCount;
  9377. delete node.titleWithHighlight;
  9378. if ( node.$subMatchBadge ) {
  9379. node.$subMatchBadge.remove();
  9380. delete node.$subMatchBadge;
  9381. }
  9382. if( node._filterAutoExpanded && node.expanded ) {
  9383. node.setExpanded(false, {noAnimation: true, noEvents: true, scrollIntoView: false});
  9384. }
  9385. delete node._filterAutoExpanded;
  9386. });
  9387. this.enableFilter = false;
  9388. this.lastFilterArgs = null;
  9389. this.$div.removeClass("fancytree-ext-filter fancytree-ext-filter-dimm fancytree-ext-filter-hide");
  9390. this.render();
  9391. };
  9392. /**
  9393. * [ext-filter] Return true if a filter is currently applied.
  9394. *
  9395. * @returns {Boolean}
  9396. * @alias Fancytree#isFilterActive
  9397. * @requires jquery.fancytree.filter.js
  9398. * @since 2.13
  9399. */
  9400. $.ui.fancytree._FancytreeClass.prototype.isFilterActive = function(){
  9401. return !!this.enableFilter;
  9402. };
  9403. /**
  9404. * [ext-filter] Return true if this node is matched by current filter (or no filter is active).
  9405. *
  9406. * @returns {Boolean}
  9407. * @alias FancytreeNode#isMatched
  9408. * @requires jquery.fancytree.filter.js
  9409. * @since 2.13
  9410. */
  9411. $.ui.fancytree._FancytreeNodeClass.prototype.isMatched = function(){
  9412. return !(this.tree.enableFilter && !this.match);
  9413. };
  9414. /*******************************************************************************
  9415. * Extension code
  9416. */
  9417. $.ui.fancytree.registerExtension({
  9418. name: "filter",
  9419. version: "2.26.0",
  9420. // Default options for this extension.
  9421. options: {
  9422. autoApply: true, // Re-apply last filter if lazy data is loaded
  9423. autoExpand: false, // Expand all branches that contain matches while filtered
  9424. counter: true, // Show a badge with number of matching child nodes near parent icons
  9425. fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar'
  9426. hideExpandedCounter: true, // Hide counter badge if parent is expanded
  9427. hideExpanders: false, // Hide expanders if all child nodes are hidden by filter
  9428. highlight: true, // Highlight matches by wrapping inside <mark> tags
  9429. leavesOnly: false, // Match end nodes only
  9430. nodata: true, // Display a 'no data' status node if result is empty
  9431. mode: "dimm" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
  9432. },
  9433. nodeLoadChildren: function(ctx, source) {
  9434. return this._superApply(arguments).done(function() {
  9435. if( ctx.tree.enableFilter && ctx.tree.lastFilterArgs && ctx.options.filter.autoApply ) {
  9436. ctx.tree._applyFilterImpl.apply(ctx.tree, ctx.tree.lastFilterArgs);
  9437. }
  9438. });
  9439. },
  9440. nodeSetExpanded: function(ctx, flag, callOpts) {
  9441. delete ctx.node._filterAutoExpanded;
  9442. // Make sure counter badge is displayed again, when node is beeing collapsed
  9443. if( !flag && ctx.options.filter.hideExpandedCounter && ctx.node.$subMatchBadge ) {
  9444. ctx.node.$subMatchBadge.show();
  9445. }
  9446. return this._superApply(arguments);
  9447. },
  9448. nodeRenderStatus: function(ctx) {
  9449. // Set classes for current status
  9450. var res,
  9451. node = ctx.node,
  9452. tree = ctx.tree,
  9453. opts = ctx.options.filter,
  9454. $title = $(node.span).find("span.fancytree-title"),
  9455. $span = $(node[tree.statusClassPropName]),
  9456. enhanceTitle = ctx.options.enhanceTitle,
  9457. escapeTitles = ctx.options.escapeTitles;
  9458. res = this._super(ctx);
  9459. // nothing to do, if node was not yet rendered
  9460. if( !$span.length || !tree.enableFilter ) {
  9461. return res;
  9462. }
  9463. $span
  9464. .toggleClass("fancytree-match", !!node.match)
  9465. .toggleClass("fancytree-submatch", !!node.subMatchCount)
  9466. .toggleClass("fancytree-hide", !(node.match || node.subMatchCount));
  9467. // Add/update counter badge
  9468. if( opts.counter && node.subMatchCount && (!node.isExpanded() || !opts.hideExpandedCounter) ) {
  9469. if( !node.$subMatchBadge ) {
  9470. node.$subMatchBadge = $("<span class='fancytree-childcounter'/>");
  9471. $("span.fancytree-icon, span.fancytree-custom-icon", node.span).append(node.$subMatchBadge);
  9472. }
  9473. node.$subMatchBadge.show().text(node.subMatchCount);
  9474. } else if ( node.$subMatchBadge ) {
  9475. node.$subMatchBadge.hide();
  9476. }
  9477. // node.debug("nodeRenderStatus", node.titleWithHighlight, node.title)
  9478. // #601: also chek for $title.length, because we don't need to render
  9479. // if node.span is null (i.e. not rendered)
  9480. if( node.span && (!node.isEditing || !node.isEditing.call(node)) ) {
  9481. if( node.titleWithHighlight ) {
  9482. $title.html(node.titleWithHighlight);
  9483. } else if ( escapeTitles ) {
  9484. $title.text(node.title);
  9485. } else {
  9486. $title.html(node.title);
  9487. }
  9488. if( enhanceTitle ) {
  9489. enhanceTitle({type: "enhanceTitle"}, {node: node, $title: $title});
  9490. }
  9491. }
  9492. return res;
  9493. }
  9494. });
  9495. // Value returned by `require('jquery.fancytree..')`
  9496. return $.ui.fancytree;
  9497. })); // End of closure
  9498. /*! Extension 'jquery.fancytree.glyph.js' *//*!
  9499. * jquery.fancytree.glyph.js
  9500. *
  9501. * Use glyph fonts as instead of icon sprites.
  9502. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  9503. *
  9504. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  9505. *
  9506. * Released under the MIT license
  9507. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  9508. *
  9509. * @version 2.26.0
  9510. * @date 2017-11-04T17:52:53Z
  9511. */
  9512. ;(function( factory ) {
  9513. if ( typeof define === "function" && define.amd ) {
  9514. // AMD. Register as an anonymous module.
  9515. define( [ "jquery", "./jquery.fancytree" ], factory );
  9516. } else if ( typeof module === "object" && module.exports ) {
  9517. // Node/CommonJS
  9518. require("jquery.fancytree");
  9519. module.exports = factory(require("jquery"));
  9520. } else {
  9521. // Browser globals
  9522. factory( jQuery );
  9523. }
  9524. }( function( $ ) {
  9525. "use strict";
  9526. /* *****************************************************************************
  9527. * Private functions and variables
  9528. */
  9529. var FT = $.ui.fancytree,
  9530. PRESETS = {
  9531. "awesome3": {
  9532. checkbox: "icon-check-empty",
  9533. checkboxSelected: "icon-check",
  9534. checkboxUnknown: "icon-check icon-muted",
  9535. radio: "icon-circle-blank",
  9536. radioSelected: "icon-circle",
  9537. radioUnknown: "icon-circle icon-muted",
  9538. // radioUnknown: "icon-remove-circle-blank",
  9539. dragHelper: "icon-caret-right",
  9540. dropMarker: "icon-caret-right",
  9541. error: "icon-exclamation-sign",
  9542. expanderClosed: "icon-caret-right",
  9543. expanderLazy: "icon-angle-right",
  9544. expanderOpen: "icon-caret-down",
  9545. loading: "icon-refresh icon-spin",
  9546. nodata: "icon-meh",
  9547. noExpander: "",
  9548. // Default node icons.
  9549. // (Use tree.options.icon callback to define custom icons based on node data)
  9550. doc: "icon-file-alt",
  9551. docOpen: "icon-file-alt",
  9552. folder: "icon-folder-close-alt",
  9553. folderOpen: "icon-folder-open-alt"
  9554. },
  9555. "awesome4": {
  9556. checkbox: "fa fa-square-o",
  9557. checkboxSelected: "fa fa-check-square-o",
  9558. // checkboxUnknown: "fa fa-window-close-o",
  9559. checkboxUnknown: "fa fa-square",
  9560. radio: "fa fa-circle-o",
  9561. radioSelected: "fa fa-circle",
  9562. radioUnknown: "fa fa-dot-circle-o",
  9563. dragHelper: "fa fa-arrow-right",
  9564. dropMarker: "fa fa-long-arrow-right",
  9565. error: "fa fa-warning",
  9566. expanderClosed: "fa fa-caret-right",
  9567. expanderLazy: "fa fa-angle-right",
  9568. expanderOpen: "fa fa-caret-down",
  9569. loading: "fa fa-spinner fa-pulse",
  9570. nodata: "fa fa-meh-o",
  9571. noExpander: "",
  9572. // Default node icons.
  9573. // (Use tree.options.icon callback to define custom icons based on node data)
  9574. doc: "fa fa-file-o",
  9575. docOpen: "fa fa-file-o",
  9576. folder: "fa fa-folder-o",
  9577. folderOpen: "fa fa-folder-open-o"
  9578. },
  9579. "bootstrap3": {
  9580. checkbox: "glyphicon glyphicon-unchecked",
  9581. checkboxSelected: "glyphicon glyphicon-check",
  9582. checkboxUnknown: "glyphicon glyphicon-expand",
  9583. radio: "glyphicon glyphicon-remove-circle",
  9584. radioSelected: "glyphicon glyphicon-ok-circle",
  9585. radioUnknown: "glyphicon glyphicon-ban-circle",
  9586. dragHelper: "glyphicon glyphicon-play",
  9587. dropMarker: "glyphicon glyphicon-arrow-right",
  9588. error: "glyphicon glyphicon-warning-sign",
  9589. expanderClosed: "glyphicon glyphicon-menu-right", // glyphicon-plus-sign
  9590. expanderLazy: "glyphicon glyphicon-menu-right", // glyphicon-plus-sign
  9591. expanderOpen: "glyphicon glyphicon-menu-down", // glyphicon-minus-sign
  9592. loading: "glyphicon glyphicon-refresh glyphicon-spin",
  9593. nodata: "glyphicon glyphicon-info-sign",
  9594. noExpander: "",
  9595. // Default node icons.
  9596. // (Use tree.options.icon callback to define custom icons based on node data)
  9597. doc: "glyphicon glyphicon-file",
  9598. docOpen: "glyphicon glyphicon-file",
  9599. folder: "glyphicon glyphicon-folder-close",
  9600. folderOpen: "glyphicon glyphicon-folder-open"
  9601. }
  9602. };
  9603. function _getIcon(opts, type){
  9604. return opts.map[type];
  9605. }
  9606. $.ui.fancytree.registerExtension({
  9607. name: "glyph",
  9608. version: "2.26.0",
  9609. // Default options for this extension.
  9610. options: {
  9611. preset: null, // 'awesome3', 'awesome4', 'bootstrap3'
  9612. map: {
  9613. }
  9614. },
  9615. treeInit: function(ctx){
  9616. var tree = ctx.tree,
  9617. opts = ctx.options.glyph;
  9618. if( opts.preset ) {
  9619. FT.assert( !!PRESETS[opts.preset],
  9620. "Invalid value for `options.glyph.preset`: " + opts.preset);
  9621. opts.map = $.extend({}, PRESETS[opts.preset], opts.map);
  9622. } else {
  9623. tree.warn("ext-glyph: missing `preset` option.");
  9624. }
  9625. this._superApply(arguments);
  9626. tree.$container.addClass("fancytree-ext-glyph");
  9627. },
  9628. nodeRenderStatus: function(ctx) {
  9629. var checkbox, className, icon, res, span,
  9630. node = ctx.node,
  9631. $span = $(node.span),
  9632. opts = ctx.options.glyph,
  9633. map = opts.map;
  9634. res = this._super(ctx);
  9635. if( node.isRoot() ){
  9636. return res;
  9637. }
  9638. span = $span.children("span.fancytree-expander").get(0);
  9639. if( span ){
  9640. // if( node.isLoading() ){
  9641. // icon = "loading";
  9642. if( node.expanded && node.hasChildren() ){
  9643. icon = "expanderOpen";
  9644. }else if( node.isUndefined() ){
  9645. icon = "expanderLazy";
  9646. }else if( node.hasChildren() ){
  9647. icon = "expanderClosed";
  9648. }else{
  9649. icon = "noExpander";
  9650. }
  9651. span.className = "fancytree-expander " + map[icon];
  9652. }
  9653. if( node.tr ){
  9654. span = $("td", node.tr).find("span.fancytree-checkbox").get(0);
  9655. }else{
  9656. span = $span.children("span.fancytree-checkbox").get(0);
  9657. }
  9658. if( span ){
  9659. checkbox = FT.evalOption("checkbox", node, node, ctx.options, false);
  9660. if( checkbox && !node.isStatusNode() ) {
  9661. className = "fancytree-checkbox ";
  9662. if( checkbox === "radio" || (node.parent && node.parent.radiogroup) ) {
  9663. className += "fancytree-radio ";
  9664. icon = node.selected ? "radioSelected" : (node.partsel ? "radioUnknown" : "radio");
  9665. } else {
  9666. icon = node.selected ? "checkboxSelected" : (node.partsel ? "checkboxUnknown" : "checkbox");
  9667. }
  9668. span.className = className + map[icon];
  9669. }
  9670. }
  9671. // Standard icon (note that this does not match .fancytree-custom-icon,
  9672. // that might be set by opts.icon callbacks)
  9673. span = $span.children("span.fancytree-icon").get(0);
  9674. if( span ){
  9675. if( node.statusNodeType ){
  9676. icon = _getIcon(opts, node.statusNodeType); // loading, error
  9677. }else if( node.folder ){
  9678. icon = node.expanded && node.hasChildren() ? _getIcon(opts, "folderOpen") : _getIcon(opts, "folder");
  9679. }else{
  9680. icon = node.expanded ? _getIcon(opts, "docOpen") : _getIcon(opts, "doc");
  9681. }
  9682. span.className = "fancytree-icon " + icon;
  9683. }
  9684. return res;
  9685. },
  9686. nodeSetStatus: function(ctx, status, message, details) {
  9687. var res, span,
  9688. opts = ctx.options.glyph,
  9689. node = ctx.node;
  9690. res = this._superApply(arguments);
  9691. if( status === "error" || status === "loading" || status === "nodata" ){
  9692. if(node.parent){
  9693. span = $("span.fancytree-expander", node.span).get(0);
  9694. if( span ) {
  9695. span.className = "fancytree-expander " + _getIcon(opts, status);
  9696. }
  9697. }else{ //
  9698. span = $(".fancytree-statusnode-" + status, node[this.nodeContainerAttrName])
  9699. .find("span.fancytree-icon").get(0);
  9700. if( span ) {
  9701. span.className = "fancytree-icon " + _getIcon(opts, status);
  9702. }
  9703. }
  9704. }
  9705. return res;
  9706. }
  9707. });
  9708. // Value returned by `require('jquery.fancytree..')`
  9709. return $.ui.fancytree;
  9710. })); // End of closure
  9711. /*! Extension 'jquery.fancytree.gridnav.js' *//*!
  9712. * jquery.fancytree.gridnav.js
  9713. *
  9714. * Support keyboard navigation for trees with embedded input controls.
  9715. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  9716. *
  9717. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  9718. *
  9719. * Released under the MIT license
  9720. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  9721. *
  9722. * @version 2.26.0
  9723. * @date 2017-11-04T17:52:53Z
  9724. */
  9725. ;(function( factory ) {
  9726. if ( typeof define === "function" && define.amd ) {
  9727. // AMD. Register as an anonymous module.
  9728. define([
  9729. "jquery",
  9730. "./jquery.fancytree",
  9731. "./jquery.fancytree.table"
  9732. ], factory );
  9733. } else if ( typeof module === "object" && module.exports ) {
  9734. // Node/CommonJS
  9735. require("jquery.fancytree.table"); // core + table
  9736. module.exports = factory(require("jquery"));
  9737. } else {
  9738. // Browser globals
  9739. factory( jQuery );
  9740. }
  9741. }( function( $ ) {
  9742. "use strict";
  9743. /*******************************************************************************
  9744. * Private functions and variables
  9745. */
  9746. // Allow these navigation keys even when input controls are focused
  9747. var KC = $.ui.keyCode,
  9748. // which keys are *not* handled by embedded control, but passed to tree
  9749. // navigation handler:
  9750. NAV_KEYS = {
  9751. "text": [KC.UP, KC.DOWN],
  9752. "checkbox": [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  9753. "link": [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  9754. "radiobutton": [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  9755. "select-one": [KC.LEFT, KC.RIGHT],
  9756. "select-multiple": [KC.LEFT, KC.RIGHT]
  9757. };
  9758. /* Calculate TD column index (considering colspans).*/
  9759. function getColIdx($tr, $td) {
  9760. var colspan,
  9761. td = $td.get(0),
  9762. idx = 0;
  9763. $tr.children().each(function () {
  9764. if( this === td ) {
  9765. return false;
  9766. }
  9767. colspan = $(this).prop("colspan");
  9768. idx += colspan ? colspan : 1;
  9769. });
  9770. return idx;
  9771. }
  9772. /* Find TD at given column index (considering colspans).*/
  9773. function findTdAtColIdx($tr, colIdx) {
  9774. var colspan,
  9775. res = null,
  9776. idx = 0;
  9777. $tr.children().each(function () {
  9778. if( idx >= colIdx ) {
  9779. res = $(this);
  9780. return false;
  9781. }
  9782. colspan = $(this).prop("colspan");
  9783. idx += colspan ? colspan : 1;
  9784. });
  9785. return res;
  9786. }
  9787. /* Find adjacent cell for a given direction. Skip empty cells and consider merged cells */
  9788. function findNeighbourTd($target, keyCode){
  9789. var $tr, colIdx,
  9790. $td = $target.closest("td"),
  9791. $tdNext = null;
  9792. switch( keyCode ){
  9793. case KC.LEFT:
  9794. $tdNext = $td.prev();
  9795. break;
  9796. case KC.RIGHT:
  9797. $tdNext = $td.next();
  9798. break;
  9799. case KC.UP:
  9800. case KC.DOWN:
  9801. $tr = $td.parent();
  9802. colIdx = getColIdx($tr, $td);
  9803. while( true ) {
  9804. $tr = (keyCode === KC.UP) ? $tr.prev() : $tr.next();
  9805. if( !$tr.length ) {
  9806. break;
  9807. }
  9808. // Skip hidden rows
  9809. if( $tr.is(":hidden") ) {
  9810. continue;
  9811. }
  9812. // Find adjacent cell in the same column
  9813. $tdNext = findTdAtColIdx($tr, colIdx);
  9814. // Skip cells that don't conatain a focusable element
  9815. if( $tdNext && $tdNext.find(":input,a").length ) {
  9816. break;
  9817. }
  9818. }
  9819. break;
  9820. }
  9821. return $tdNext;
  9822. }
  9823. /*******************************************************************************
  9824. * Extension code
  9825. */
  9826. $.ui.fancytree.registerExtension({
  9827. name: "gridnav",
  9828. version: "2.26.0",
  9829. // Default options for this extension.
  9830. options: {
  9831. autofocusInput: false, // Focus first embedded input if node gets activated
  9832. handleCursorKeys: true // Allow UP/DOWN in inputs to move to prev/next node
  9833. },
  9834. treeInit: function(ctx){
  9835. // gridnav requires the table extension to be loaded before itself
  9836. this._requireExtension("table", true, true);
  9837. this._superApply(arguments);
  9838. this.$container.addClass("fancytree-ext-gridnav");
  9839. // Activate node if embedded input gets focus (due to a click)
  9840. this.$container.on("focusin", function(event){
  9841. var ctx2,
  9842. node = $.ui.fancytree.getNode(event.target);
  9843. if( node && !node.isActive() ){
  9844. // Call node.setActive(), but also pass the event
  9845. ctx2 = ctx.tree._makeHookContext(node, event);
  9846. ctx.tree._callHook("nodeSetActive", ctx2, true);
  9847. }
  9848. });
  9849. },
  9850. nodeSetActive: function(ctx, flag, callOpts) {
  9851. var $outer,
  9852. opts = ctx.options.gridnav,
  9853. node = ctx.node,
  9854. event = ctx.originalEvent || {},
  9855. triggeredByInput = $(event.target).is(":input");
  9856. flag = (flag !== false);
  9857. this._superApply(arguments);
  9858. if( flag ){
  9859. if( ctx.options.titlesTabbable ){
  9860. if( !triggeredByInput ) {
  9861. $(node.span).find("span.fancytree-title").focus();
  9862. node.setFocus();
  9863. }
  9864. // If one node is tabbable, the container no longer needs to be
  9865. ctx.tree.$container.attr("tabindex", "-1");
  9866. // ctx.tree.$container.removeAttr("tabindex");
  9867. } else if( opts.autofocusInput && !triggeredByInput ){
  9868. // Set focus to input sub input (if node was clicked, but not
  9869. // when TAB was pressed )
  9870. $outer = $(node.tr || node.span);
  9871. $outer.find(":input:enabled:first").focus();
  9872. }
  9873. }
  9874. },
  9875. nodeKeydown: function(ctx) {
  9876. var inputType, handleKeys, $td,
  9877. opts = ctx.options.gridnav,
  9878. event = ctx.originalEvent,
  9879. $target = $(event.target);
  9880. if( $target.is(":input:enabled") ) {
  9881. inputType = $target.prop("type");
  9882. } else if( $target.is("a") ) {
  9883. inputType = "link";
  9884. }
  9885. // ctx.tree.debug("ext-gridnav nodeKeydown", event, inputType);
  9886. if( inputType && opts.handleCursorKeys ){
  9887. handleKeys = NAV_KEYS[inputType];
  9888. if( handleKeys && $.inArray(event.which, handleKeys) >= 0 ){
  9889. $td = findNeighbourTd($target, event.which);
  9890. if( $td && $td.length ) {
  9891. // ctx.node.debug("ignore keydown in input", event.which, handleKeys);
  9892. $td.find(":input:enabled,a").focus();
  9893. // Prevent Fancytree default navigation
  9894. return false;
  9895. }
  9896. }
  9897. return true;
  9898. }
  9899. // ctx.tree.debug("ext-gridnav NOT HANDLED", event, inputType);
  9900. return this._superApply(arguments);
  9901. }
  9902. });
  9903. // Value returned by `require('jquery.fancytree..')`
  9904. return $.ui.fancytree;
  9905. })); // End of closure
  9906. /*! Extension 'jquery.fancytree.persist.js' *//*!
  9907. * jquery.fancytree.persist.js
  9908. *
  9909. * Persist tree status in cookiesRemove or highlight tree nodes, based on a filter.
  9910. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  9911. *
  9912. * @depends: js-cookie or jquery-cookie
  9913. *
  9914. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  9915. *
  9916. * Released under the MIT license
  9917. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  9918. *
  9919. * @version 2.26.0
  9920. * @date 2017-11-04T17:52:53Z
  9921. */
  9922. ;(function( factory ) {
  9923. if ( typeof define === "function" && define.amd ) {
  9924. // AMD. Register as an anonymous module.
  9925. define( [ "jquery", "./jquery.fancytree" ], factory );
  9926. } else if ( typeof module === "object" && module.exports ) {
  9927. // Node/CommonJS
  9928. require("jquery.fancytree");
  9929. module.exports = factory(require("jquery"));
  9930. } else {
  9931. // Browser globals
  9932. factory( jQuery );
  9933. }
  9934. }( function( $ ) {
  9935. "use strict";
  9936. /* global Cookies:false */
  9937. /*******************************************************************************
  9938. * Private functions and variables
  9939. */
  9940. var cookieGetter, cookieRemover, cookieSetter,
  9941. _assert = $.ui.fancytree.assert,
  9942. ACTIVE = "active",
  9943. EXPANDED = "expanded",
  9944. FOCUS = "focus",
  9945. SELECTED = "selected";
  9946. if( typeof Cookies === "function" ) {
  9947. // Assume https://github.com/js-cookie/js-cookie
  9948. cookieSetter = Cookies.set;
  9949. cookieGetter = Cookies.get;
  9950. cookieRemover = Cookies.remove;
  9951. } else {
  9952. // Fall back to https://github.com/carhartl/jquery-cookie
  9953. cookieSetter = cookieGetter = $.cookie;
  9954. cookieRemover = $.removeCookie;
  9955. }
  9956. /* Recursively load lazy nodes
  9957. * @param {string} mode 'load', 'expand', false
  9958. */
  9959. function _loadLazyNodes(tree, local, keyList, mode, dfd) {
  9960. var i, key, l, node,
  9961. foundOne = false,
  9962. expandOpts = tree.options.persist.expandOpts,
  9963. deferredList = [],
  9964. missingKeyList = [];
  9965. keyList = keyList || [];
  9966. dfd = dfd || $.Deferred();
  9967. for( i=0, l=keyList.length; i<l; i++ ) {
  9968. key = keyList[i];
  9969. node = tree.getNodeByKey(key);
  9970. if( node ) {
  9971. if( mode && node.isUndefined() ) {
  9972. foundOne = true;
  9973. tree.debug("_loadLazyNodes: " + node + " is lazy: loading...");
  9974. if( mode === "expand" ) {
  9975. deferredList.push(node.setExpanded(true, expandOpts));
  9976. } else {
  9977. deferredList.push(node.load());
  9978. }
  9979. } else {
  9980. tree.debug("_loadLazyNodes: " + node + " already loaded.");
  9981. node.setExpanded(true, expandOpts);
  9982. }
  9983. } else {
  9984. missingKeyList.push(key);
  9985. tree.debug("_loadLazyNodes: " + node + " was not yet found.");
  9986. }
  9987. }
  9988. $.when.apply($, deferredList).always(function(){
  9989. // All lazy-expands have finished
  9990. if( foundOne && missingKeyList.length > 0 ) {
  9991. // If we read new nodes from server, try to resolve yet-missing keys
  9992. _loadLazyNodes(tree, local, missingKeyList, mode, dfd);
  9993. } else {
  9994. if( missingKeyList.length ) {
  9995. tree.warn("_loadLazyNodes: could not load those keys: ", missingKeyList);
  9996. for( i=0, l=missingKeyList.length; i<l; i++ ) {
  9997. key = keyList[i];
  9998. local._appendKey(EXPANDED, keyList[i], false);
  9999. }
  10000. }
  10001. dfd.resolve();
  10002. }
  10003. });
  10004. return dfd;
  10005. }
  10006. /**
  10007. * [ext-persist] Remove persistence cookies of the given type(s).
  10008. * Called like
  10009. * $("#tree").fancytree("getTree").clearCookies("active expanded focus selected");
  10010. *
  10011. * @alias Fancytree#clearCookies
  10012. * @requires jquery.fancytree.persist.js
  10013. */
  10014. $.ui.fancytree._FancytreeClass.prototype.clearCookies = function(types){
  10015. var local = this.ext.persist,
  10016. prefix = local.cookiePrefix;
  10017. types = types || "active expanded focus selected";
  10018. if(types.indexOf(ACTIVE) >= 0){
  10019. local._data(prefix + ACTIVE, null);
  10020. }
  10021. if(types.indexOf(EXPANDED) >= 0){
  10022. local._data(prefix + EXPANDED, null);
  10023. }
  10024. if(types.indexOf(FOCUS) >= 0){
  10025. local._data(prefix + FOCUS, null);
  10026. }
  10027. if(types.indexOf(SELECTED) >= 0){
  10028. local._data(prefix + SELECTED, null);
  10029. }
  10030. };
  10031. /**
  10032. * [ext-persist] Return persistence information from cookies
  10033. *
  10034. * Called like
  10035. * $("#tree").fancytree("getTree").getPersistData();
  10036. *
  10037. * @alias Fancytree#getPersistData
  10038. * @requires jquery.fancytree.persist.js
  10039. */
  10040. $.ui.fancytree._FancytreeClass.prototype.getPersistData = function(){
  10041. var local = this.ext.persist,
  10042. prefix = local.cookiePrefix,
  10043. delim = local.cookieDelimiter,
  10044. res = {};
  10045. res[ACTIVE] = local._data(prefix + ACTIVE);
  10046. res[EXPANDED] = (local._data(prefix + EXPANDED) || "").split(delim);
  10047. res[SELECTED] = (local._data(prefix + SELECTED) || "").split(delim);
  10048. res[FOCUS] = local._data(prefix + FOCUS);
  10049. return res;
  10050. };
  10051. /* *****************************************************************************
  10052. * Extension code
  10053. */
  10054. $.ui.fancytree.registerExtension({
  10055. name: "persist",
  10056. version: "2.26.0",
  10057. // Default options for this extension.
  10058. options: {
  10059. cookieDelimiter: "~",
  10060. cookiePrefix: undefined, // 'fancytree-<treeId>-' by default
  10061. cookie: {
  10062. raw: false,
  10063. expires: "",
  10064. path: "",
  10065. domain: "",
  10066. secure: false
  10067. },
  10068. expandLazy: false, // true: recursively expand and load lazy nodes
  10069. expandOpts: undefined, // optional `opts` argument passed to setExpanded()
  10070. fireActivate: true, // false: suppress `activate` event after active node was restored
  10071. overrideSource: true, // true: cookie takes precedence over `source` data attributes.
  10072. store: "auto", // 'cookie': force cookie, 'local': force localStore, 'session': force sessionStore
  10073. types: "active expanded focus selected"
  10074. },
  10075. /* Generic read/write string data to cookie, sessionStorage or localStorage. */
  10076. _data: function(key, value){
  10077. var ls = this._local.localStorage; // null, sessionStorage, or localStorage
  10078. if( value === undefined ) {
  10079. return ls ? ls.getItem(key) : cookieGetter(key);
  10080. } else if ( value === null ) {
  10081. if( ls ) {
  10082. ls.removeItem(key);
  10083. } else {
  10084. cookieRemover(key);
  10085. }
  10086. } else {
  10087. if( ls ) {
  10088. ls.setItem(key, value);
  10089. } else {
  10090. cookieSetter(key, value, this.options.persist.cookie);
  10091. }
  10092. }
  10093. },
  10094. /* Append `key` to a cookie. */
  10095. _appendKey: function(type, key, flag){
  10096. key = "" + key; // #90
  10097. var local = this._local,
  10098. instOpts = this.options.persist,
  10099. delim = instOpts.cookieDelimiter,
  10100. cookieName = local.cookiePrefix + type,
  10101. data = local._data(cookieName),
  10102. keyList = data ? data.split(delim) : [],
  10103. idx = $.inArray(key, keyList);
  10104. // Remove, even if we add a key, so the key is always the last entry
  10105. if(idx >= 0){
  10106. keyList.splice(idx, 1);
  10107. }
  10108. // Append key to cookie
  10109. if(flag){
  10110. keyList.push(key);
  10111. }
  10112. local._data(cookieName, keyList.join(delim));
  10113. },
  10114. treeInit: function(ctx){
  10115. var tree = ctx.tree,
  10116. opts = ctx.options,
  10117. local = this._local,
  10118. instOpts = this.options.persist;
  10119. // For 'auto' or 'cookie' mode, the cookie plugin must be available
  10120. _assert((instOpts.store !== "auto" && instOpts.store !== "cookie") || cookieGetter,
  10121. "Missing required plugin for 'persist' extension: js.cookie.js or jquery.cookie.js");
  10122. local.cookiePrefix = instOpts.cookiePrefix || ("fancytree-" + tree._id + "-");
  10123. local.storeActive = instOpts.types.indexOf(ACTIVE) >= 0;
  10124. local.storeExpanded = instOpts.types.indexOf(EXPANDED) >= 0;
  10125. local.storeSelected = instOpts.types.indexOf(SELECTED) >= 0;
  10126. local.storeFocus = instOpts.types.indexOf(FOCUS) >= 0;
  10127. if( instOpts.store === "cookie" || !window.localStorage ) {
  10128. local.localStorage = null;
  10129. } else {
  10130. local.localStorage = (instOpts.store === "local") ? window.localStorage : window.sessionStorage;
  10131. }
  10132. // Bind init-handler to apply cookie state
  10133. tree.$div.on("fancytreeinit", function(event){
  10134. if ( tree._triggerTreeEvent("beforeRestore", null, {}) === false ) {
  10135. return;
  10136. }
  10137. var cookie, dfd, i, keyList, node,
  10138. prevFocus = local._data(local.cookiePrefix + FOCUS), // record this before node.setActive() overrides it;
  10139. noEvents = instOpts.fireActivate === false;
  10140. // tree.debug("document.cookie:", document.cookie);
  10141. cookie = local._data(local.cookiePrefix + EXPANDED);
  10142. keyList = cookie && cookie.split(instOpts.cookieDelimiter);
  10143. if( local.storeExpanded ) {
  10144. // Recursively load nested lazy nodes if expandLazy is 'expand' or 'load'
  10145. // Also remove expand-cookies for unmatched nodes
  10146. dfd = _loadLazyNodes(tree, local, keyList, instOpts.expandLazy ? "expand" : false , null);
  10147. } else {
  10148. // nothing to do
  10149. dfd = new $.Deferred().resolve();
  10150. }
  10151. dfd.done(function(){
  10152. if(local.storeSelected){
  10153. cookie = local._data(local.cookiePrefix + SELECTED);
  10154. if(cookie){
  10155. keyList = cookie.split(instOpts.cookieDelimiter);
  10156. for(i=0; i<keyList.length; i++){
  10157. node = tree.getNodeByKey(keyList[i]);
  10158. if(node){
  10159. if(node.selected === undefined || instOpts.overrideSource && (node.selected === false)){
  10160. // node.setSelected();
  10161. node.selected = true;
  10162. node.renderStatus();
  10163. }
  10164. }else{
  10165. // node is no longer member of the tree: remove from cookie also
  10166. local._appendKey(SELECTED, keyList[i], false);
  10167. }
  10168. }
  10169. }
  10170. // In selectMode 3 we have to fix the child nodes, since we
  10171. // only stored the selected *top* nodes
  10172. if( tree.options.selectMode === 3 ){
  10173. tree.visit(function(n){
  10174. if( n.selected ) {
  10175. n.fixSelection3AfterClick();
  10176. return "skip";
  10177. }
  10178. });
  10179. }
  10180. }
  10181. if(local.storeActive){
  10182. cookie = local._data(local.cookiePrefix + ACTIVE);
  10183. if(cookie && (opts.persist.overrideSource || !tree.activeNode)){
  10184. node = tree.getNodeByKey(cookie);
  10185. if(node){
  10186. node.debug("persist: set active", cookie);
  10187. // We only want to set the focus if the container
  10188. // had the keyboard focus before
  10189. node.setActive(true, {
  10190. noFocus: true,
  10191. noEvents: noEvents
  10192. });
  10193. }
  10194. }
  10195. }
  10196. if(local.storeFocus && prevFocus){
  10197. node = tree.getNodeByKey(prevFocus);
  10198. if(node){
  10199. // node.debug("persist: set focus", cookie);
  10200. if( tree.options.titlesTabbable ) {
  10201. $(node.span).find(".fancytree-title").focus();
  10202. } else {
  10203. $(tree.$container).focus();
  10204. }
  10205. // node.setFocus();
  10206. }
  10207. }
  10208. tree._triggerTreeEvent("restore", null, {});
  10209. });
  10210. });
  10211. // Init the tree
  10212. return this._superApply(arguments);
  10213. },
  10214. nodeSetActive: function(ctx, flag, callOpts) {
  10215. var res,
  10216. local = this._local;
  10217. flag = (flag !== false);
  10218. res = this._superApply(arguments);
  10219. if(local.storeActive){
  10220. local._data(local.cookiePrefix + ACTIVE, this.activeNode ? this.activeNode.key : null);
  10221. }
  10222. return res;
  10223. },
  10224. nodeSetExpanded: function(ctx, flag, callOpts) {
  10225. var res,
  10226. node = ctx.node,
  10227. local = this._local;
  10228. flag = (flag !== false);
  10229. res = this._superApply(arguments);
  10230. if(local.storeExpanded){
  10231. local._appendKey(EXPANDED, node.key, flag);
  10232. }
  10233. return res;
  10234. },
  10235. nodeSetFocus: function(ctx, flag) {
  10236. var res,
  10237. local = this._local;
  10238. flag = (flag !== false);
  10239. res = this._superApply(arguments);
  10240. if( local.storeFocus ) {
  10241. local._data(local.cookiePrefix + FOCUS, this.focusNode ? this.focusNode.key : null);
  10242. }
  10243. return res;
  10244. },
  10245. nodeSetSelected: function(ctx, flag, callOpts) {
  10246. var res, selNodes,
  10247. tree = ctx.tree,
  10248. node = ctx.node,
  10249. local = this._local;
  10250. flag = (flag !== false);
  10251. res = this._superApply(arguments);
  10252. if(local.storeSelected){
  10253. if( tree.options.selectMode === 3 ){
  10254. // In selectMode 3 we only store the the selected *top* nodes.
  10255. // De-selecting a node may also de-select some parents, so we
  10256. // calculate the current status again
  10257. selNodes = $.map(tree.getSelectedNodes(true), function(n){
  10258. return n.key;
  10259. });
  10260. selNodes = selNodes.join(ctx.options.persist.cookieDelimiter);
  10261. local._data(local.cookiePrefix + SELECTED, selNodes);
  10262. } else {
  10263. // beforeSelect can prevent the change - flag doesn't reflect the node.selected state
  10264. local._appendKey(SELECTED, node.key, node.selected);
  10265. }
  10266. }
  10267. return res;
  10268. }
  10269. });
  10270. // Value returned by `require('jquery.fancytree..')`
  10271. return $.ui.fancytree;
  10272. })); // End of closure
  10273. /*! Extension 'jquery.fancytree.table.js' *//*!
  10274. * jquery.fancytree.table.js
  10275. *
  10276. * Render tree as table (aka 'tree grid', 'table tree').
  10277. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10278. *
  10279. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  10280. *
  10281. * Released under the MIT license
  10282. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10283. *
  10284. * @version 2.26.0
  10285. * @date 2017-11-04T17:52:53Z
  10286. */
  10287. ;(function( factory ) {
  10288. if ( typeof define === "function" && define.amd ) {
  10289. // AMD. Register as an anonymous module.
  10290. define( [ "jquery", "./jquery.fancytree" ], factory );
  10291. } else if ( typeof module === "object" && module.exports ) {
  10292. // Node/CommonJS
  10293. require("jquery.fancytree");
  10294. module.exports = factory(require("jquery"));
  10295. } else {
  10296. // Browser globals
  10297. factory( jQuery );
  10298. }
  10299. }( function( $ ) {
  10300. "use strict";
  10301. /* *****************************************************************************
  10302. * Private functions and variables
  10303. */
  10304. function _assert(cond, msg){
  10305. msg = msg || "";
  10306. if(!cond){
  10307. $.error("Assertion failed " + msg);
  10308. }
  10309. }
  10310. function insertFirstChild(referenceNode, newNode) {
  10311. referenceNode.insertBefore(newNode, referenceNode.firstChild);
  10312. }
  10313. function insertSiblingAfter(referenceNode, newNode) {
  10314. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  10315. }
  10316. /* Show/hide all rows that are structural descendants of `parent`. */
  10317. function setChildRowVisibility(parent, flag) {
  10318. parent.visit(function(node){
  10319. var tr = node.tr;
  10320. // currentFlag = node.hide ? false : flag; // fix for ext-filter
  10321. if(tr){
  10322. tr.style.display = (node.hide || !flag) ? "none" : "";
  10323. }
  10324. if(!node.expanded){
  10325. return "skip";
  10326. }
  10327. });
  10328. }
  10329. /* Find node that is rendered in previous row. */
  10330. function findPrevRowNode(node){
  10331. var i, last, prev,
  10332. parent = node.parent,
  10333. siblings = parent ? parent.children : null;
  10334. if(siblings && siblings.length > 1 && siblings[0] !== node){
  10335. // use the lowest descendant of the preceeding sibling
  10336. i = $.inArray(node, siblings);
  10337. prev = siblings[i - 1];
  10338. _assert(prev.tr);
  10339. // descend to lowest child (with a <tr> tag)
  10340. while(prev.children && prev.children.length){
  10341. last = prev.children[prev.children.length - 1];
  10342. if(!last.tr){
  10343. break;
  10344. }
  10345. prev = last;
  10346. }
  10347. }else{
  10348. // if there is no preceding sibling, use the direct parent
  10349. prev = parent;
  10350. }
  10351. return prev;
  10352. }
  10353. /* Render callback for 'wide' mode. */
  10354. // function _renderStatusNodeWide(event, data) {
  10355. // var node = data.node,
  10356. // nodeColumnIdx = data.options.table.nodeColumnIdx,
  10357. // $tdList = $(node.tr).find(">td");
  10358. // $tdList.eq(nodeColumnIdx).attr("colspan", data.tree.columnCount);
  10359. // $tdList.not(":eq(" + nodeColumnIdx + ")").remove();
  10360. // }
  10361. $.ui.fancytree.registerExtension({
  10362. name: "table",
  10363. version: "2.26.0",
  10364. // Default options for this extension.
  10365. options: {
  10366. checkboxColumnIdx: null, // render the checkboxes into the this column index (default: nodeColumnIdx)
  10367. // customStatus: false, // true: generate renderColumns events for status nodes
  10368. indentation: 16, // indent every node level by 16px
  10369. nodeColumnIdx: 0 // render node expander, icon, and title to this column (default: #0)
  10370. },
  10371. // Overide virtual methods for this extension.
  10372. // `this` : is this extension object
  10373. // `this._super`: the virtual function that was overriden (member of prev. extension or Fancytree)
  10374. treeInit: function(ctx){
  10375. var i, columnCount, n, $row, $tbody,
  10376. tree = ctx.tree,
  10377. opts = ctx.options,
  10378. tableOpts = opts.table,
  10379. $table = tree.widget.element;
  10380. if( tableOpts.customStatus != null ) {
  10381. if( opts.renderStatusColumns != null) {
  10382. $.error("The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' only instead.");
  10383. } else {
  10384. tree.warn("The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' instead.");
  10385. opts.renderStatusColumns = tableOpts.customStatus;
  10386. }
  10387. }
  10388. if( opts.renderStatusColumns ) {
  10389. if( opts.renderStatusColumns === true ) {
  10390. opts.renderStatusColumns = opts.renderColumns;
  10391. // } else if( opts.renderStatusColumns === "wide" ) {
  10392. // opts.renderStatusColumns = _renderStatusNodeWide;
  10393. }
  10394. }
  10395. $table.addClass("fancytree-container fancytree-ext-table");
  10396. tree.tbody = $table.find(">tbody")[0];
  10397. $tbody = $(tree.tbody);
  10398. // Prepare row templates:
  10399. // Determine column count from table header if any
  10400. columnCount = $("thead >tr:last >th", $table).length;
  10401. // Read TR templates from tbody if any
  10402. $row = $tbody.children("tr:first");
  10403. if( $row.length ) {
  10404. n = $row.children("td").length;
  10405. if( columnCount && n !== columnCount ) {
  10406. tree.warn("Column count mismatch between thead (" + columnCount + ") and tbody (" + n + "): using tbody.");
  10407. columnCount = n;
  10408. }
  10409. $row = $row.clone();
  10410. } else {
  10411. // Only thead is defined: create default row markup
  10412. _assert(columnCount >= 1, "Need either <thead> or <tbody> with <td> elements to determine column count.");
  10413. $row = $("<tr />");
  10414. for(i=0; i<columnCount; i++) {
  10415. $row.append("<td />");
  10416. }
  10417. }
  10418. $row.find(">td").eq(tableOpts.nodeColumnIdx)
  10419. .html("<span class='fancytree-node' />");
  10420. if( opts.aria ) {
  10421. $row.attr("role", "row");
  10422. $row.find("td").attr("role", "gridcell");
  10423. }
  10424. tree.rowFragment = document.createDocumentFragment();
  10425. tree.rowFragment.appendChild($row.get(0));
  10426. // // If tbody contains a second row, use this as status node template
  10427. // $row = $tbody.children("tr:eq(1)");
  10428. // if( $row.length === 0 ) {
  10429. // tree.statusRowFragment = tree.rowFragment;
  10430. // } else {
  10431. // $row = $row.clone();
  10432. // tree.statusRowFragment = document.createDocumentFragment();
  10433. // tree.statusRowFragment.appendChild($row.get(0));
  10434. // }
  10435. //
  10436. $tbody.empty();
  10437. // Make sure that status classes are set on the node's <tr> elements
  10438. tree.statusClassPropName = "tr";
  10439. tree.ariaPropName = "tr";
  10440. this.nodeContainerAttrName = "tr";
  10441. // #489: make sure $container is set to <table>, even if ext-dnd is listed before ext-table
  10442. tree.$container = $table;
  10443. this._superApply(arguments);
  10444. // standard Fancytree created a root UL
  10445. $(tree.rootNode.ul).remove();
  10446. tree.rootNode.ul = null;
  10447. // Add container to the TAB chain
  10448. // #577: Allow to set tabindex to "0", "-1" and ""
  10449. this.$container.attr("tabindex", opts.tabindex);
  10450. // this.$container.attr("tabindex", opts.tabbable ? "0" : "-1");
  10451. if(opts.aria) {
  10452. tree.$container
  10453. .attr("role", "treegrid")
  10454. .attr("aria-readonly", true);
  10455. }
  10456. },
  10457. nodeRemoveChildMarkup: function(ctx) {
  10458. var node = ctx.node;
  10459. // node.debug("nodeRemoveChildMarkup()");
  10460. node.visit(function(n){
  10461. if(n.tr){
  10462. $(n.tr).remove();
  10463. n.tr = null;
  10464. }
  10465. });
  10466. },
  10467. nodeRemoveMarkup: function(ctx) {
  10468. var node = ctx.node;
  10469. // node.debug("nodeRemoveMarkup()");
  10470. if(node.tr){
  10471. $(node.tr).remove();
  10472. node.tr = null;
  10473. }
  10474. this.nodeRemoveChildMarkup(ctx);
  10475. },
  10476. /* Override standard render. */
  10477. nodeRender: function(ctx, force, deep, collapsed, _recursive) {
  10478. var children, firstTr, i, l, newRow, prevNode, prevTr, subCtx,
  10479. tree = ctx.tree,
  10480. node = ctx.node,
  10481. opts = ctx.options,
  10482. isRootNode = !node.parent;
  10483. if( tree._enableUpdate === false ) {
  10484. // $.ui.fancytree.debug("*** nodeRender _enableUpdate: false");
  10485. return;
  10486. }
  10487. if( !_recursive ){
  10488. ctx.hasCollapsedParents = node.parent && !node.parent.expanded;
  10489. }
  10490. // $.ui.fancytree.debug("*** nodeRender " + node + ", isRoot=" + isRootNode, "tr=" + node.tr, "hcp=" + ctx.hasCollapsedParents, "parent.tr=" + (node.parent && node.parent.tr));
  10491. if( !isRootNode ){
  10492. if( node.tr && force ) {
  10493. this.nodeRemoveMarkup(ctx);
  10494. }
  10495. if( !node.tr ) {
  10496. if( ctx.hasCollapsedParents && !deep ) {
  10497. // #166: we assume that the parent will be (recursively) rendered
  10498. // later anyway.
  10499. // node.debug("nodeRender ignored due to unrendered parent");
  10500. return;
  10501. }
  10502. // Create new <tr> after previous row
  10503. // if( node.isStatusNode() ) {
  10504. // newRow = tree.statusRowFragment.firstChild.cloneNode(true);
  10505. // } else {
  10506. newRow = tree.rowFragment.firstChild.cloneNode(true);
  10507. // }
  10508. prevNode = findPrevRowNode(node);
  10509. // $.ui.fancytree.debug("*** nodeRender " + node + ": prev: " + prevNode.key);
  10510. _assert(prevNode);
  10511. if(collapsed === true && _recursive){
  10512. // hide all child rows, so we can use an animation to show it later
  10513. newRow.style.display = "none";
  10514. }else if(deep && ctx.hasCollapsedParents){
  10515. // also hide this row if deep === true but any parent is collapsed
  10516. newRow.style.display = "none";
  10517. // newRow.style.color = "red";
  10518. }
  10519. if(!prevNode.tr){
  10520. _assert(!prevNode.parent, "prev. row must have a tr, or be system root");
  10521. // tree.tbody.appendChild(newRow);
  10522. insertFirstChild(tree.tbody, newRow); // #675
  10523. }else{
  10524. insertSiblingAfter(prevNode.tr, newRow);
  10525. }
  10526. node.tr = newRow;
  10527. if( node.key && opts.generateIds ){
  10528. node.tr.id = opts.idPrefix + node.key;
  10529. }
  10530. node.tr.ftnode = node;
  10531. // if(opts.aria){
  10532. // $(node.tr).attr("aria-labelledby", "ftal_" + opts.idPrefix + node.key);
  10533. // }
  10534. node.span = $("span.fancytree-node", node.tr).get(0);
  10535. // Set icon, link, and title (normally this is only required on initial render)
  10536. this.nodeRenderTitle(ctx);
  10537. // Allow tweaking, binding, after node was created for the first time
  10538. // tree._triggerNodeEvent("createNode", ctx);
  10539. if ( opts.createNode ){
  10540. opts.createNode.call(tree, {type: "createNode"}, ctx);
  10541. }
  10542. } else {
  10543. if( force ) {
  10544. // Set icon, link, and title (normally this is only required on initial render)
  10545. this.nodeRenderTitle(ctx); // triggers renderColumns()
  10546. } else {
  10547. // Update element classes according to node state
  10548. this.nodeRenderStatus(ctx);
  10549. }
  10550. }
  10551. }
  10552. // Allow tweaking after node state was rendered
  10553. // tree._triggerNodeEvent("renderNode", ctx);
  10554. if ( opts.renderNode ){
  10555. opts.renderNode.call(tree, {type: "renderNode"}, ctx);
  10556. }
  10557. // Visit child nodes
  10558. // Add child markup
  10559. children = node.children;
  10560. if(children && (isRootNode || deep || node.expanded)){
  10561. for(i=0, l=children.length; i<l; i++) {
  10562. subCtx = $.extend({}, ctx, {node: children[i]});
  10563. subCtx.hasCollapsedParents = subCtx.hasCollapsedParents || !node.expanded;
  10564. this.nodeRender(subCtx, force, deep, collapsed, true);
  10565. }
  10566. }
  10567. // Make sure, that <tr> order matches node.children order.
  10568. if(children && !_recursive){ // we only have to do it once, for the root branch
  10569. prevTr = node.tr || null;
  10570. firstTr = tree.tbody.firstChild;
  10571. // Iterate over all descendants
  10572. node.visit(function(n){
  10573. if(n.tr){
  10574. if(!n.parent.expanded && n.tr.style.display !== "none"){
  10575. // fix after a node was dropped over a collapsed
  10576. n.tr.style.display = "none";
  10577. setChildRowVisibility(n, false);
  10578. }
  10579. if(n.tr.previousSibling !== prevTr){
  10580. node.debug("_fixOrder: mismatch at node: " + n);
  10581. var nextTr = prevTr ? prevTr.nextSibling : firstTr;
  10582. tree.tbody.insertBefore(n.tr, nextTr);
  10583. }
  10584. prevTr = n.tr;
  10585. }
  10586. });
  10587. }
  10588. // Update element classes according to node state
  10589. // if(!isRootNode){
  10590. // this.nodeRenderStatus(ctx);
  10591. // }
  10592. },
  10593. nodeRenderTitle: function(ctx, title) {
  10594. var $cb, res,
  10595. node = ctx.node,
  10596. opts = ctx.options,
  10597. isStatusNode = node.isStatusNode();
  10598. res = this._super(ctx, title);
  10599. if( node.isRootNode() ) {
  10600. return res;
  10601. }
  10602. // Move checkbox to custom column
  10603. if(opts.checkbox && !isStatusNode && opts.table.checkboxColumnIdx != null ){
  10604. $cb = $("span.fancytree-checkbox", node.span); //.detach();
  10605. $(node.tr).find("td").eq(+opts.table.checkboxColumnIdx).html($cb);
  10606. }
  10607. // Update element classes according to node state
  10608. this.nodeRenderStatus(ctx);
  10609. if( isStatusNode ) {
  10610. if( opts.renderStatusColumns ) {
  10611. // Let user code write column content
  10612. opts.renderStatusColumns.call(ctx.tree, {type: "renderStatusColumns"}, ctx);
  10613. } // else: default rendering for status node: leave other cells empty
  10614. } else if ( opts.renderColumns ) {
  10615. opts.renderColumns.call(ctx.tree, {type: "renderColumns"}, ctx);
  10616. }
  10617. return res;
  10618. },
  10619. nodeRenderStatus: function(ctx) {
  10620. var indent,
  10621. node = ctx.node,
  10622. opts = ctx.options;
  10623. this._super(ctx);
  10624. $(node.tr).removeClass("fancytree-node");
  10625. // indent
  10626. indent = (node.getLevel() - 1) * opts.table.indentation;
  10627. $(node.span).css({paddingLeft: indent + "px"}); // #460
  10628. // $(node.span).css({marginLeft: indent + "px"});
  10629. },
  10630. /* Expand node, return Deferred.promise. */
  10631. nodeSetExpanded: function(ctx, flag, callOpts) {
  10632. // flag defaults to true
  10633. flag = (flag !== false);
  10634. if((ctx.node.expanded && flag) || (!ctx.node.expanded && !flag)) {
  10635. // Expanded state isn't changed - just call base implementation
  10636. return this._superApply(arguments);
  10637. }
  10638. var dfd = new $.Deferred(),
  10639. subOpts = $.extend({}, callOpts, {noEvents: true, noAnimation: true});
  10640. callOpts = callOpts || {};
  10641. function _afterExpand(ok) {
  10642. setChildRowVisibility(ctx.node, flag);
  10643. if( ok ) {
  10644. if( flag && ctx.options.autoScroll && !callOpts.noAnimation && ctx.node.hasChildren() ) {
  10645. // Scroll down to last child, but keep current node visible
  10646. ctx.node.getLastChild().scrollIntoView(true, {topNode: ctx.node}).always(function(){
  10647. if( !callOpts.noEvents ) {
  10648. ctx.tree._triggerNodeEvent(flag ? "expand" : "collapse", ctx);
  10649. }
  10650. dfd.resolveWith(ctx.node);
  10651. });
  10652. } else {
  10653. if( !callOpts.noEvents ) {
  10654. ctx.tree._triggerNodeEvent(flag ? "expand" : "collapse", ctx);
  10655. }
  10656. dfd.resolveWith(ctx.node);
  10657. }
  10658. } else {
  10659. if( !callOpts.noEvents ) {
  10660. ctx.tree._triggerNodeEvent(flag ? "expand" : "collapse", ctx);
  10661. }
  10662. dfd.rejectWith(ctx.node);
  10663. }
  10664. }
  10665. // Call base-expand with disabled events and animation
  10666. this._super(ctx, flag, subOpts).done(function () {
  10667. _afterExpand(true);
  10668. }).fail(function () {
  10669. _afterExpand(false);
  10670. });
  10671. return dfd.promise();
  10672. },
  10673. nodeSetStatus: function(ctx, status, message, details) {
  10674. if(status === "ok"){
  10675. var node = ctx.node,
  10676. firstChild = ( node.children ? node.children[0] : null );
  10677. if ( firstChild && firstChild.isStatusNode() ) {
  10678. $(firstChild.tr).remove();
  10679. }
  10680. }
  10681. return this._superApply(arguments);
  10682. },
  10683. treeClear: function(ctx) {
  10684. this.nodeRemoveChildMarkup(this._makeHookContext(this.rootNode));
  10685. return this._superApply(arguments);
  10686. },
  10687. treeDestroy: function(ctx) {
  10688. this.$container.find("tbody").empty();
  10689. this.$source && this.$source.removeClass("ui-helper-hidden");
  10690. return this._superApply(arguments);
  10691. }
  10692. /*,
  10693. treeSetFocus: function(ctx, flag) {
  10694. // alert("treeSetFocus" + ctx.tree.$container);
  10695. ctx.tree.$container.focus();
  10696. $.ui.fancytree.focusTree = ctx.tree;
  10697. }*/
  10698. });
  10699. // Value returned by `require('jquery.fancytree..')`
  10700. return $.ui.fancytree;
  10701. })); // End of closure
  10702. /*! Extension 'jquery.fancytree.themeroller.js' *//*!
  10703. * jquery.fancytree.themeroller.js
  10704. *
  10705. * Enable jQuery UI ThemeRoller styles.
  10706. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10707. *
  10708. * @see http://jqueryui.com/themeroller/
  10709. *
  10710. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  10711. *
  10712. * Released under the MIT license
  10713. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10714. *
  10715. * @version 2.26.0
  10716. * @date 2017-11-04T17:52:53Z
  10717. */
  10718. ;(function( factory ) {
  10719. if ( typeof define === "function" && define.amd ) {
  10720. // AMD. Register as an anonymous module.
  10721. define( [ "jquery", "./jquery.fancytree" ], factory );
  10722. } else if ( typeof module === "object" && module.exports ) {
  10723. // Node/CommonJS
  10724. require("jquery.fancytree");
  10725. module.exports = factory(require("jquery"));
  10726. } else {
  10727. // Browser globals
  10728. factory( jQuery );
  10729. }
  10730. }( function( $ ) {
  10731. "use strict";
  10732. /*******************************************************************************
  10733. * Extension code
  10734. */
  10735. $.ui.fancytree.registerExtension({
  10736. name: "themeroller",
  10737. version: "2.26.0",
  10738. // Default options for this extension.
  10739. options: {
  10740. activeClass: "ui-state-active", // Class added to active node
  10741. // activeClass: "ui-state-highlight",
  10742. addClass: "ui-corner-all", // Class added to all nodes
  10743. focusClass: "ui-state-focus", // Class added to focused node
  10744. hoverClass: "ui-state-hover", // Class added to hovered node
  10745. selectedClass: "ui-state-highlight" // Class added to selected nodes
  10746. // selectedClass: "ui-state-active"
  10747. },
  10748. treeInit: function(ctx){
  10749. var $el = ctx.widget.element,
  10750. opts = ctx.options.themeroller;
  10751. this._superApply(arguments);
  10752. if($el[0].nodeName === "TABLE"){
  10753. $el.addClass("ui-widget ui-corner-all");
  10754. $el.find(">thead tr").addClass("ui-widget-header");
  10755. $el.find(">tbody").addClass("ui-widget-conent");
  10756. }else{
  10757. $el.addClass("ui-widget ui-widget-content ui-corner-all");
  10758. }
  10759. $el.delegate(".fancytree-node", "mouseenter mouseleave", function(event){
  10760. var node = $.ui.fancytree.getNode(event.target),
  10761. flag = (event.type === "mouseenter");
  10762. $(node.tr ? node.tr : node.span)
  10763. .toggleClass(opts.hoverClass + " " + opts.addClass, flag);
  10764. });
  10765. },
  10766. treeDestroy: function(ctx){
  10767. this._superApply(arguments);
  10768. ctx.widget.element.removeClass("ui-widget ui-widget-content ui-corner-all");
  10769. },
  10770. nodeRenderStatus: function(ctx){
  10771. var classes = {},
  10772. node = ctx.node,
  10773. $el = $(node.tr ? node.tr : node.span),
  10774. opts = ctx.options.themeroller;
  10775. this._super(ctx);
  10776. /*
  10777. .ui-state-highlight: Class to be applied to highlighted or selected elements. Applies "highlight" container styles to an element and its child text, links, and icons.
  10778. .ui-state-error: Class to be applied to error messaging container elements. Applies "error" container styles to an element and its child text, links, and icons.
  10779. .ui-state-error-text: An additional class that applies just the error text color without background. Can be used on form labels for instance. Also applies error icon color to child icons.
  10780. .ui-state-default: Class to be applied to clickable button-like elements. Applies "clickable default" container styles to an element and its child text, links, and icons.
  10781. .ui-state-hover: Class to be applied on mouseover to clickable button-like elements. Applies "clickable hover" container styles to an element and its child text, links, and icons.
  10782. .ui-state-focus: Class to be applied on keyboard focus to clickable button-like elements. Applies "clickable hover" container styles to an element and its child text, links, and icons.
  10783. .ui-state-active: Class to be applied on mousedown to clickable button-like elements. Applies "clickable active" container styles to an element and its child text, links, and icons.
  10784. */
  10785. // Set ui-state-* class (handle the case that the same class is assigned
  10786. // to different states)
  10787. classes[opts.activeClass] = false;
  10788. classes[opts.focusClass] = false;
  10789. classes[opts.selectedClass] = false;
  10790. if( node.isActive() ) { classes[opts.activeClass] = true; }
  10791. if( node.hasFocus() ) { classes[opts.focusClass] = true; }
  10792. // activeClass takes precedence before selectedClass:
  10793. if( node.isSelected() && !node.isActive() ) { classes[opts.selectedClass] = true; }
  10794. $el.toggleClass(opts.activeClass, classes[opts.activeClass]);
  10795. $el.toggleClass(opts.focusClass, classes[opts.focusClass]);
  10796. $el.toggleClass(opts.selectedClass, classes[opts.selectedClass]);
  10797. // Additional classes (e.g. 'ui-corner-all')
  10798. $el.addClass(opts.addClass);
  10799. }
  10800. });
  10801. // Value returned by `require('jquery.fancytree..')`
  10802. return $.ui.fancytree;
  10803. })); // End of closure
  10804. /*! Extension 'jquery.fancytree.wide.js' *//*!
  10805. * jquery.fancytree.wide.js
  10806. * Support for 100% wide selection bars.
  10807. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10808. *
  10809. * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
  10810. *
  10811. * Released under the MIT license
  10812. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10813. *
  10814. * @version 2.26.0
  10815. * @date 2017-11-04T17:52:53Z
  10816. */
  10817. ;(function( factory ) {
  10818. if ( typeof define === "function" && define.amd ) {
  10819. // AMD. Register as an anonymous module.
  10820. define( [ "jquery", "./jquery.fancytree" ], factory );
  10821. } else if ( typeof module === "object" && module.exports ) {
  10822. // Node/CommonJS
  10823. require("jquery.fancytree");
  10824. module.exports = factory(require("jquery"));
  10825. } else {
  10826. // Browser globals
  10827. factory( jQuery );
  10828. }
  10829. }( function( $ ) {
  10830. "use strict";
  10831. var reNumUnit = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/; // split "1.5em" to ["1.5", "em"]
  10832. /*******************************************************************************
  10833. * Private functions and variables
  10834. */
  10835. // var _assert = $.ui.fancytree.assert;
  10836. /* Calculate inner width without scrollbar */
  10837. // function realInnerWidth($el) {
  10838. // // http://blog.jquery.com/2012/08/16/jquery-1-8-box-sizing-width-csswidth-and-outerwidth/
  10839. // // inst.contWidth = parseFloat(this.$container.css("width"), 10);
  10840. // // 'Client width without scrollbar' - 'padding'
  10841. // return $el[0].clientWidth - ($el.innerWidth() - parseFloat($el.css("width"), 10));
  10842. // }
  10843. /* Create a global embedded CSS style for the tree. */
  10844. function defineHeadStyleElement(id, cssText) {
  10845. id = "fancytree-style-" + id;
  10846. var $headStyle = $("#" + id);
  10847. if( !cssText ) {
  10848. $headStyle.remove();
  10849. return null;
  10850. }
  10851. if( !$headStyle.length ) {
  10852. $headStyle = $("<style />")
  10853. .attr("id", id)
  10854. .addClass("fancytree-style")
  10855. .prop("type", "text/css")
  10856. .appendTo("head");
  10857. }
  10858. try {
  10859. $headStyle.html(cssText);
  10860. } catch ( e ) {
  10861. // fix for IE 6-8
  10862. $headStyle[0].styleSheet.cssText = cssText;
  10863. }
  10864. return $headStyle;
  10865. }
  10866. /* Calculate the CSS rules that indent title spans. */
  10867. function renderLevelCss(containerId, depth, levelOfs, lineOfs, labelOfs, measureUnit)
  10868. {
  10869. var i,
  10870. prefix = "#" + containerId + " span.fancytree-level-",
  10871. rules = [];
  10872. for(i = 0; i < depth; i++) {
  10873. rules.push(prefix + (i + 1) + " span.fancytree-title { padding-left: " +
  10874. (i * levelOfs + lineOfs) + measureUnit + "; }");
  10875. }
  10876. // Some UI animations wrap the UL inside a DIV and set position:relative on both.
  10877. // This breaks the left:0 and padding-left:nn settings of the title
  10878. rules.push(
  10879. "#" + containerId + " div.ui-effects-wrapper ul li span.fancytree-title, " +
  10880. "#" + containerId + " ul.fancytree-animating span.fancytree-title " + // #716
  10881. "{ padding-left: " + labelOfs + measureUnit + "; position: static; width: auto; }");
  10882. return rules.join("\n");
  10883. }
  10884. // /**
  10885. // * [ext-wide] Recalculate the width of the selection bar after the tree container
  10886. // * was resized.<br>
  10887. // * May be called explicitly on container resize, since there is no resize event
  10888. // * for DIV tags.
  10889. // *
  10890. // * @alias Fancytree#wideUpdate
  10891. // * @requires jquery.fancytree.wide.js
  10892. // */
  10893. // $.ui.fancytree._FancytreeClass.prototype.wideUpdate = function(){
  10894. // var inst = this.ext.wide,
  10895. // prevCw = inst.contWidth,
  10896. // prevLo = inst.lineOfs;
  10897. // inst.contWidth = realInnerWidth(this.$container);
  10898. // // Each title is precceeded by 2 or 3 icons (16px + 3 margin)
  10899. // // + 1px title border and 3px title padding
  10900. // // TODO: use code from treeInit() below
  10901. // inst.lineOfs = (this.options.checkbox ? 3 : 2) * 19;
  10902. // if( prevCw !== inst.contWidth || prevLo !== inst.lineOfs ) {
  10903. // this.debug("wideUpdate: " + inst.contWidth);
  10904. // this.visit(function(node){
  10905. // node.tree._callHook("nodeRenderTitle", node);
  10906. // });
  10907. // }
  10908. // };
  10909. /*******************************************************************************
  10910. * Extension code
  10911. */
  10912. $.ui.fancytree.registerExtension({
  10913. name: "wide",
  10914. version: "2.26.0",
  10915. // Default options for this extension.
  10916. options: {
  10917. iconWidth: null, // Adjust this if @fancy-icon-width != "16px"
  10918. iconSpacing: null, // Adjust this if @fancy-icon-spacing != "3px"
  10919. labelSpacing: null, // Adjust this if padding between icon and label != "3px"
  10920. levelOfs: null // Adjust this if ul padding != "16px"
  10921. },
  10922. treeCreate: function(ctx){
  10923. this._superApply(arguments);
  10924. this.$container.addClass("fancytree-ext-wide");
  10925. var containerId, cssText, iconSpacingUnit, labelSpacingUnit, iconWidthUnit, levelOfsUnit,
  10926. instOpts = ctx.options.wide,
  10927. // css sniffing
  10928. $dummyLI = $("<li id='fancytreeTemp'><span class='fancytree-node'><span class='fancytree-icon' /><span class='fancytree-title' /></span><ul />")
  10929. .appendTo(ctx.tree.$container),
  10930. $dummyIcon = $dummyLI.find(".fancytree-icon"),
  10931. $dummyUL = $dummyLI.find("ul"),
  10932. // $dummyTitle = $dummyLI.find(".fancytree-title"),
  10933. iconSpacing = instOpts.iconSpacing || $dummyIcon.css("margin-left"),
  10934. iconWidth = instOpts.iconWidth || $dummyIcon.css("width"),
  10935. labelSpacing = instOpts.labelSpacing || "3px",
  10936. levelOfs = instOpts.levelOfs || $dummyUL.css("padding-left");
  10937. $dummyLI.remove();
  10938. iconSpacingUnit = iconSpacing.match(reNumUnit)[2];
  10939. iconSpacing = parseFloat(iconSpacing, 10);
  10940. labelSpacingUnit = labelSpacing.match(reNumUnit)[2];
  10941. labelSpacing = parseFloat(labelSpacing, 10);
  10942. iconWidthUnit = iconWidth.match(reNumUnit)[2];
  10943. iconWidth = parseFloat(iconWidth, 10);
  10944. levelOfsUnit = levelOfs.match(reNumUnit)[2];
  10945. if( iconSpacingUnit !== iconWidthUnit || levelOfsUnit !== iconWidthUnit || labelSpacingUnit !== iconWidthUnit ) {
  10946. $.error("iconWidth, iconSpacing, and levelOfs must have the same css measure unit");
  10947. }
  10948. this._local.measureUnit = iconWidthUnit;
  10949. this._local.levelOfs = parseFloat(levelOfs);
  10950. this._local.lineOfs = (1 + (ctx.options.checkbox ? 1 : 0) +
  10951. (ctx.options.icon === false ? 0 : 1)) * (iconWidth + iconSpacing) +
  10952. iconSpacing;
  10953. this._local.labelOfs = labelSpacing;
  10954. this._local.maxDepth = 10;
  10955. // Get/Set a unique Id on the container (if not already exists)
  10956. containerId = this.$container.uniqueId().attr("id");
  10957. // Generated css rules for some levels (extended on demand)
  10958. cssText = renderLevelCss(containerId, this._local.maxDepth,
  10959. this._local.levelOfs, this._local.lineOfs, this._local.labelOfs,
  10960. this._local.measureUnit);
  10961. defineHeadStyleElement(containerId, cssText);
  10962. },
  10963. treeDestroy: function(ctx){
  10964. // Remove generated css rules
  10965. defineHeadStyleElement(this.$container.attr("id"), null);
  10966. return this._superApply(arguments);
  10967. },
  10968. nodeRenderStatus: function(ctx) {
  10969. var containerId, cssText, res,
  10970. node = ctx.node,
  10971. level = node.getLevel();
  10972. res = this._super(ctx);
  10973. // Generate some more level-n rules if required
  10974. if( level > this._local.maxDepth ) {
  10975. containerId = this.$container.attr("id");
  10976. this._local.maxDepth *= 2;
  10977. node.debug("Define global ext-wide css up to level " + this._local.maxDepth);
  10978. cssText = renderLevelCss(containerId, this._local.maxDepth,
  10979. this._local.levelOfs, this._local.lineOfs, this._local.labelSpacing,
  10980. this._local.measureUnit);
  10981. defineHeadStyleElement(containerId, cssText);
  10982. }
  10983. // Add level-n class to apply indentation padding.
  10984. // (Setting element style would not work, since it cannot easily be
  10985. // overriden while animations run)
  10986. $(node.span).addClass("fancytree-level-" + level);
  10987. return res;
  10988. }
  10989. });
  10990. // Value returned by `require('jquery.fancytree..')`
  10991. return $.ui.fancytree;
  10992. })); // End of closure
  10993. // Value returned by `require('jquery.fancytree')`
  10994. return $.ui.fancytree;
  10995. })); // End of closure