jquery.fancytree-all-deps.js 392 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728
  1. /*! jQuery Fancytree Plugin - 2.38.0 - 2021-02-09T20:03:49Z
  2. * https://github.com/mar10/fancytree
  3. * Copyright (c) 2021 Martin Wendt; Licensed MIT
  4. */
  5. /*! jQuery UI - v1.12.1 - 2018-05-20
  6. * http://jqueryui.com
  7. * Includes: widget.js, position.js, keycode.js, scroll-parent.js, unique-id.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. // NOTE: Original jQuery UI wrapper was replaced. See README-Fancytree.md
  1131. // }));
  1132. })(jQuery);
  1133. (function( factory ) {
  1134. if ( typeof define === "function" && define.amd ) {
  1135. // AMD. Register as an anonymous module.
  1136. define( [ "jquery" ], factory );
  1137. } else if ( typeof module === "object" && module.exports ) {
  1138. // Node/CommonJS
  1139. module.exports = factory(require("jquery"));
  1140. } else {
  1141. // Browser globals
  1142. factory( jQuery );
  1143. }
  1144. }(function( $ ) {
  1145. /*! Fancytree Core *//*!
  1146. * jquery.fancytree.js
  1147. * Tree view control with support for lazy loading and much more.
  1148. * https://github.com/mar10/fancytree/
  1149. *
  1150. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  1151. * Released under the MIT license
  1152. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  1153. *
  1154. * @version 2.38.0
  1155. * @date 2021-02-09T20:03:49Z
  1156. */
  1157. /** Core Fancytree module.
  1158. */
  1159. // UMD wrapper for the Fancytree core module
  1160. (function(factory) {
  1161. if (typeof define === "function" && define.amd) {
  1162. // AMD. Register as an anonymous module.
  1163. define(["jquery", "./jquery.fancytree.ui-deps"], factory);
  1164. } else if (typeof module === "object" && module.exports) {
  1165. // Node/CommonJS
  1166. require("./jquery.fancytree.ui-deps");
  1167. module.exports = factory(require("jquery"));
  1168. } else {
  1169. // Browser globals
  1170. factory(jQuery);
  1171. }
  1172. })(function($) {
  1173. "use strict";
  1174. // prevent duplicate loading
  1175. if ($.ui && $.ui.fancytree) {
  1176. $.ui.fancytree.warn("Fancytree: ignored duplicate include");
  1177. return;
  1178. }
  1179. /******************************************************************************
  1180. * Private functions and variables
  1181. */
  1182. var i,
  1183. attr,
  1184. FT = null, // initialized below
  1185. TEST_IMG = new RegExp(/\.|\//), // strings are considered image urls if they contain '.' or '/'
  1186. REX_HTML = /[&<>"'/]/g, // Escape those characters
  1187. REX_TOOLTIP = /[<>"'/]/g, // Don't escape `&` in tooltips
  1188. RECURSIVE_REQUEST_ERROR = "$recursive_request",
  1189. INVALID_REQUEST_TARGET_ERROR = "$request_target_invalid",
  1190. ENTITY_MAP = {
  1191. "&": "&amp;",
  1192. "<": "&lt;",
  1193. ">": "&gt;",
  1194. '"': "&quot;",
  1195. "'": "&#39;",
  1196. "/": "&#x2F;",
  1197. },
  1198. IGNORE_KEYCODES = { 16: true, 17: true, 18: true },
  1199. SPECIAL_KEYCODES = {
  1200. 8: "backspace",
  1201. 9: "tab",
  1202. 10: "return",
  1203. 13: "return",
  1204. // 16: null, 17: null, 18: null, // ignore shift, ctrl, alt
  1205. 19: "pause",
  1206. 20: "capslock",
  1207. 27: "esc",
  1208. 32: "space",
  1209. 33: "pageup",
  1210. 34: "pagedown",
  1211. 35: "end",
  1212. 36: "home",
  1213. 37: "left",
  1214. 38: "up",
  1215. 39: "right",
  1216. 40: "down",
  1217. 45: "insert",
  1218. 46: "del",
  1219. 59: ";",
  1220. 61: "=",
  1221. // 91: null, 93: null, // ignore left and right meta
  1222. 96: "0",
  1223. 97: "1",
  1224. 98: "2",
  1225. 99: "3",
  1226. 100: "4",
  1227. 101: "5",
  1228. 102: "6",
  1229. 103: "7",
  1230. 104: "8",
  1231. 105: "9",
  1232. 106: "*",
  1233. 107: "+",
  1234. 109: "-",
  1235. 110: ".",
  1236. 111: "/",
  1237. 112: "f1",
  1238. 113: "f2",
  1239. 114: "f3",
  1240. 115: "f4",
  1241. 116: "f5",
  1242. 117: "f6",
  1243. 118: "f7",
  1244. 119: "f8",
  1245. 120: "f9",
  1246. 121: "f10",
  1247. 122: "f11",
  1248. 123: "f12",
  1249. 144: "numlock",
  1250. 145: "scroll",
  1251. 173: "-",
  1252. 186: ";",
  1253. 187: "=",
  1254. 188: ",",
  1255. 189: "-",
  1256. 190: ".",
  1257. 191: "/",
  1258. 192: "`",
  1259. 219: "[",
  1260. 220: "\\",
  1261. 221: "]",
  1262. 222: "'",
  1263. },
  1264. MODIFIERS = {
  1265. 16: "shift",
  1266. 17: "ctrl",
  1267. 18: "alt",
  1268. 91: "meta",
  1269. 93: "meta",
  1270. },
  1271. MOUSE_BUTTONS = { 0: "", 1: "left", 2: "middle", 3: "right" },
  1272. // Boolean attributes that can be set with equivalent class names in the LI tags
  1273. // Note: v2.23: checkbox and hideCheckbox are *not* in this list
  1274. CLASS_ATTRS = "active expanded focus folder lazy radiogroup selected unselectable unselectableIgnore".split(
  1275. " "
  1276. ),
  1277. CLASS_ATTR_MAP = {},
  1278. // Top-level Fancytree attributes, that can be set by dict
  1279. TREE_ATTRS = "columns types".split(" "),
  1280. // TREE_ATTR_MAP = {},
  1281. // Top-level FancytreeNode attributes, that can be set by dict
  1282. NODE_ATTRS = "checkbox expanded extraClasses folder icon iconTooltip key lazy partsel radiogroup refKey selected statusNodeType title tooltip type unselectable unselectableIgnore unselectableStatus".split(
  1283. " "
  1284. ),
  1285. NODE_ATTR_MAP = {},
  1286. // Mapping of lowercase -> real name (because HTML5 data-... attribute only supports lowercase)
  1287. NODE_ATTR_LOWERCASE_MAP = {},
  1288. // Attribute names that should NOT be added to node.data
  1289. NONE_NODE_DATA_MAP = {
  1290. active: true,
  1291. children: true,
  1292. data: true,
  1293. focus: true,
  1294. };
  1295. for (i = 0; i < CLASS_ATTRS.length; i++) {
  1296. CLASS_ATTR_MAP[CLASS_ATTRS[i]] = true;
  1297. }
  1298. for (i = 0; i < NODE_ATTRS.length; i++) {
  1299. attr = NODE_ATTRS[i];
  1300. NODE_ATTR_MAP[attr] = true;
  1301. if (attr !== attr.toLowerCase()) {
  1302. NODE_ATTR_LOWERCASE_MAP[attr.toLowerCase()] = attr;
  1303. }
  1304. }
  1305. // for(i=0; i<TREE_ATTRS.length; i++) {
  1306. // TREE_ATTR_MAP[TREE_ATTRS[i]] = true;
  1307. // }
  1308. function _assert(cond, msg) {
  1309. // TODO: see qunit.js extractStacktrace()
  1310. if (!cond) {
  1311. msg = msg ? ": " + msg : "";
  1312. msg = "Fancytree assertion failed" + msg;
  1313. // consoleApply("assert", [!!cond, msg]);
  1314. // #1041: Raised exceptions may not be visible in the browser
  1315. // console if inside promise chains, so we also print directly:
  1316. $.ui.fancytree.error(msg);
  1317. // Throw exception:
  1318. $.error(msg);
  1319. }
  1320. }
  1321. _assert($.ui, "Fancytree requires jQuery UI (http://jqueryui.com)");
  1322. function consoleApply(method, args) {
  1323. var i,
  1324. s,
  1325. fn = window.console ? window.console[method] : null;
  1326. if (fn) {
  1327. try {
  1328. fn.apply(window.console, args);
  1329. } catch (e) {
  1330. // IE 8?
  1331. s = "";
  1332. for (i = 0; i < args.length; i++) {
  1333. s += args[i];
  1334. }
  1335. fn(s);
  1336. }
  1337. }
  1338. }
  1339. /* support: IE8 Polyfil for Date.now() */
  1340. if (!Date.now) {
  1341. Date.now = function now() {
  1342. return new Date().getTime();
  1343. };
  1344. }
  1345. /*Return true if x is a FancytreeNode.*/
  1346. function _isNode(x) {
  1347. return !!(x.tree && x.statusNodeType !== undefined);
  1348. }
  1349. /** Return true if dotted version string is equal or higher than requested version.
  1350. *
  1351. * See http://jsfiddle.net/mar10/FjSAN/
  1352. */
  1353. function isVersionAtLeast(dottedVersion, major, minor, patch) {
  1354. var i,
  1355. v,
  1356. t,
  1357. verParts = $.map($.trim(dottedVersion).split("."), function(e) {
  1358. return parseInt(e, 10);
  1359. }),
  1360. testParts = $.map(
  1361. Array.prototype.slice.call(arguments, 1),
  1362. function(e) {
  1363. return parseInt(e, 10);
  1364. }
  1365. );
  1366. for (i = 0; i < testParts.length; i++) {
  1367. v = verParts[i] || 0;
  1368. t = testParts[i] || 0;
  1369. if (v !== t) {
  1370. return v > t;
  1371. }
  1372. }
  1373. return true;
  1374. }
  1375. /**
  1376. * Deep-merge a list of objects (but replace array-type options).
  1377. *
  1378. * jQuery's $.extend(true, ...) method does a deep merge, that also merges Arrays.
  1379. * This variant is used to merge extension defaults with user options, and should
  1380. * merge objects, but override arrays (for example the `triggerStart: [...]` option
  1381. * of ext-edit). Also `null` values are copied over and not skipped.
  1382. *
  1383. * See issue #876
  1384. *
  1385. * Example:
  1386. * _simpleDeepMerge({}, o1, o2);
  1387. */
  1388. function _simpleDeepMerge() {
  1389. var options,
  1390. name,
  1391. src,
  1392. copy,
  1393. clone,
  1394. target = arguments[0] || {},
  1395. i = 1,
  1396. length = arguments.length;
  1397. // Handle case when target is a string or something (possible in deep copy)
  1398. if (typeof target !== "object" && !$.isFunction(target)) {
  1399. target = {};
  1400. }
  1401. if (i === length) {
  1402. throw Error("need at least two args");
  1403. }
  1404. for (; i < length; i++) {
  1405. // Only deal with non-null/undefined values
  1406. if ((options = arguments[i]) != null) {
  1407. // Extend the base object
  1408. for (name in options) {
  1409. if (options.hasOwnProperty(name)) {
  1410. src = target[name];
  1411. copy = options[name];
  1412. // Prevent never-ending loop
  1413. if (target === copy) {
  1414. continue;
  1415. }
  1416. // Recurse if we're merging plain objects
  1417. // (NOTE: unlike $.extend, we don't merge arrays, but replace them)
  1418. if (copy && $.isPlainObject(copy)) {
  1419. clone = src && $.isPlainObject(src) ? src : {};
  1420. // Never move original objects, clone them
  1421. target[name] = _simpleDeepMerge(clone, copy);
  1422. // Don't bring in undefined values
  1423. } else if (copy !== undefined) {
  1424. target[name] = copy;
  1425. }
  1426. }
  1427. }
  1428. }
  1429. }
  1430. // Return the modified object
  1431. return target;
  1432. }
  1433. /** Return a wrapper that calls sub.methodName() and exposes
  1434. * this : tree
  1435. * this._local : tree.ext.EXTNAME
  1436. * this._super : base.methodName.call()
  1437. * this._superApply : base.methodName.apply()
  1438. */
  1439. function _makeVirtualFunction(methodName, tree, base, extension, extName) {
  1440. // $.ui.fancytree.debug("_makeVirtualFunction", methodName, tree, base, extension, extName);
  1441. // if(rexTestSuper && !rexTestSuper.test(func)){
  1442. // // extension.methodName() doesn't call _super(), so no wrapper required
  1443. // return func;
  1444. // }
  1445. // Use an immediate function as closure
  1446. var proxy = (function() {
  1447. var prevFunc = tree[methodName], // org. tree method or prev. proxy
  1448. baseFunc = extension[methodName], //
  1449. _local = tree.ext[extName],
  1450. _super = function() {
  1451. return prevFunc.apply(tree, arguments);
  1452. },
  1453. _superApply = function(args) {
  1454. return prevFunc.apply(tree, args);
  1455. };
  1456. // Return the wrapper function
  1457. return function() {
  1458. var prevLocal = tree._local,
  1459. prevSuper = tree._super,
  1460. prevSuperApply = tree._superApply;
  1461. try {
  1462. tree._local = _local;
  1463. tree._super = _super;
  1464. tree._superApply = _superApply;
  1465. return baseFunc.apply(tree, arguments);
  1466. } finally {
  1467. tree._local = prevLocal;
  1468. tree._super = prevSuper;
  1469. tree._superApply = prevSuperApply;
  1470. }
  1471. };
  1472. })(); // end of Immediate Function
  1473. return proxy;
  1474. }
  1475. /**
  1476. * Subclass `base` by creating proxy functions
  1477. */
  1478. function _subclassObject(tree, base, extension, extName) {
  1479. // $.ui.fancytree.debug("_subclassObject", tree, base, extension, extName);
  1480. for (var attrName in extension) {
  1481. if (typeof extension[attrName] === "function") {
  1482. if (typeof tree[attrName] === "function") {
  1483. // override existing method
  1484. tree[attrName] = _makeVirtualFunction(
  1485. attrName,
  1486. tree,
  1487. base,
  1488. extension,
  1489. extName
  1490. );
  1491. } else if (attrName.charAt(0) === "_") {
  1492. // Create private methods in tree.ext.EXTENSION namespace
  1493. tree.ext[extName][attrName] = _makeVirtualFunction(
  1494. attrName,
  1495. tree,
  1496. base,
  1497. extension,
  1498. extName
  1499. );
  1500. } else {
  1501. $.error(
  1502. "Could not override tree." +
  1503. attrName +
  1504. ". Use prefix '_' to create tree." +
  1505. extName +
  1506. "._" +
  1507. attrName
  1508. );
  1509. }
  1510. } else {
  1511. // Create member variables in tree.ext.EXTENSION namespace
  1512. if (attrName !== "options") {
  1513. tree.ext[extName][attrName] = extension[attrName];
  1514. }
  1515. }
  1516. }
  1517. }
  1518. function _getResolvedPromise(context, argArray) {
  1519. if (context === undefined) {
  1520. return $.Deferred(function() {
  1521. this.resolve();
  1522. }).promise();
  1523. }
  1524. return $.Deferred(function() {
  1525. this.resolveWith(context, argArray);
  1526. }).promise();
  1527. }
  1528. function _getRejectedPromise(context, argArray) {
  1529. if (context === undefined) {
  1530. return $.Deferred(function() {
  1531. this.reject();
  1532. }).promise();
  1533. }
  1534. return $.Deferred(function() {
  1535. this.rejectWith(context, argArray);
  1536. }).promise();
  1537. }
  1538. function _makeResolveFunc(deferred, context) {
  1539. return function() {
  1540. deferred.resolveWith(context);
  1541. };
  1542. }
  1543. function _getElementDataAsDict($el) {
  1544. // Evaluate 'data-NAME' attributes with special treatment for 'data-json'.
  1545. var d = $.extend({}, $el.data()),
  1546. json = d.json;
  1547. delete d.fancytree; // added to container by widget factory (old jQuery UI)
  1548. delete d.uiFancytree; // added to container by widget factory
  1549. if (json) {
  1550. delete d.json;
  1551. // <li data-json='...'> is already returned as object (http://api.jquery.com/data/#data-html5)
  1552. d = $.extend(d, json);
  1553. }
  1554. return d;
  1555. }
  1556. function _escapeTooltip(s) {
  1557. return ("" + s).replace(REX_TOOLTIP, function(s) {
  1558. return ENTITY_MAP[s];
  1559. });
  1560. }
  1561. // TODO: use currying
  1562. function _makeNodeTitleMatcher(s) {
  1563. s = s.toLowerCase();
  1564. return function(node) {
  1565. return node.title.toLowerCase().indexOf(s) >= 0;
  1566. };
  1567. }
  1568. function _makeNodeTitleStartMatcher(s) {
  1569. var reMatch = new RegExp("^" + s, "i");
  1570. return function(node) {
  1571. return reMatch.test(node.title);
  1572. };
  1573. }
  1574. /******************************************************************************
  1575. * FancytreeNode
  1576. */
  1577. /**
  1578. * Creates a new FancytreeNode
  1579. *
  1580. * @class FancytreeNode
  1581. * @classdesc A FancytreeNode represents the hierarchical data model and operations.
  1582. *
  1583. * @param {FancytreeNode} parent
  1584. * @param {NodeData} obj
  1585. *
  1586. * @property {Fancytree} tree The tree instance
  1587. * @property {FancytreeNode} parent The parent node
  1588. * @property {string} key Node id (must be unique inside the tree)
  1589. * @property {string} title Display name (may contain HTML)
  1590. * @property {object} data Contains all extra data that was passed on node creation
  1591. * @property {FancytreeNode[] | null | undefined} children Array of child nodes.<br>
  1592. * For lazy nodes, null or undefined means 'not yet loaded'. Use an empty array
  1593. * to define a node that has no children.
  1594. * @property {boolean} expanded Use isExpanded(), setExpanded() to access this property.
  1595. * @property {string} extraClasses Additional CSS classes, added to the node's `<span>`.<br>
  1596. * Note: use `node.add/remove/toggleClass()` to modify.
  1597. * @property {boolean} folder Folder nodes have different default icons and click behavior.<br>
  1598. * Note: Also non-folders may have children.
  1599. * @property {string} statusNodeType null for standard nodes. Otherwise type of special system node: 'error', 'loading', 'nodata', or 'paging'.
  1600. * @property {boolean} lazy True if this node is loaded on demand, i.e. on first expansion.
  1601. * @property {boolean} selected Use isSelected(), setSelected() to access this property.
  1602. * @property {string} tooltip Alternative description used as hover popup
  1603. * @property {string} iconTooltip Description used as hover popup for icon. @since 2.27
  1604. * @property {string} type Node type, used with tree.types map. @since 2.27
  1605. */
  1606. function FancytreeNode(parent, obj) {
  1607. var i, l, name, cl;
  1608. this.parent = parent;
  1609. this.tree = parent.tree;
  1610. this.ul = null;
  1611. this.li = null; // <li id='key' ftnode=this> tag
  1612. this.statusNodeType = null; // if this is a temp. node to display the status of its parent
  1613. this._isLoading = false; // if this node itself is loading
  1614. this._error = null; // {message: '...'} if a load error occurred
  1615. this.data = {};
  1616. // TODO: merge this code with node.toDict()
  1617. // copy attributes from obj object
  1618. for (i = 0, l = NODE_ATTRS.length; i < l; i++) {
  1619. name = NODE_ATTRS[i];
  1620. this[name] = obj[name];
  1621. }
  1622. // unselectableIgnore and unselectableStatus imply unselectable
  1623. if (
  1624. this.unselectableIgnore != null ||
  1625. this.unselectableStatus != null
  1626. ) {
  1627. this.unselectable = true;
  1628. }
  1629. if (obj.hideCheckbox) {
  1630. $.error(
  1631. "'hideCheckbox' node option was removed in v2.23.0: use 'checkbox: false'"
  1632. );
  1633. }
  1634. // node.data += obj.data
  1635. if (obj.data) {
  1636. $.extend(this.data, obj.data);
  1637. }
  1638. // Copy all other attributes to this.data.NAME
  1639. for (name in obj) {
  1640. if (
  1641. !NODE_ATTR_MAP[name] &&
  1642. (this.tree.options.copyFunctionsToData ||
  1643. !$.isFunction(obj[name])) &&
  1644. !NONE_NODE_DATA_MAP[name]
  1645. ) {
  1646. // node.data.NAME = obj.NAME
  1647. this.data[name] = obj[name];
  1648. }
  1649. }
  1650. // Fix missing key
  1651. if (this.key == null) {
  1652. // test for null OR undefined
  1653. if (this.tree.options.defaultKey) {
  1654. this.key = "" + this.tree.options.defaultKey(this);
  1655. _assert(this.key, "defaultKey() must return a unique key");
  1656. } else {
  1657. this.key = "_" + FT._nextNodeKey++;
  1658. }
  1659. } else {
  1660. this.key = "" + this.key; // Convert to string (#217)
  1661. }
  1662. // Fix tree.activeNode
  1663. // TODO: not elegant: we use obj.active as marker to set tree.activeNode
  1664. // when loading from a dictionary.
  1665. if (obj.active) {
  1666. _assert(
  1667. this.tree.activeNode === null,
  1668. "only one active node allowed"
  1669. );
  1670. this.tree.activeNode = this;
  1671. }
  1672. if (obj.selected) {
  1673. // #186
  1674. this.tree.lastSelectedNode = this;
  1675. }
  1676. // TODO: handle obj.focus = true
  1677. // Create child nodes
  1678. cl = obj.children;
  1679. if (cl) {
  1680. if (cl.length) {
  1681. this._setChildren(cl);
  1682. } else {
  1683. // if an empty array was passed for a lazy node, keep it, in order to mark it 'loaded'
  1684. this.children = this.lazy ? [] : null;
  1685. }
  1686. } else {
  1687. this.children = null;
  1688. }
  1689. // Add to key/ref map (except for root node)
  1690. // if( parent ) {
  1691. this.tree._callHook("treeRegisterNode", this.tree, true, this);
  1692. // }
  1693. }
  1694. FancytreeNode.prototype = /** @lends FancytreeNode# */ {
  1695. /* Return the direct child FancytreeNode with a given key, index. */
  1696. _findDirectChild: function(ptr) {
  1697. var i,
  1698. l,
  1699. cl = this.children;
  1700. if (cl) {
  1701. if (typeof ptr === "string") {
  1702. for (i = 0, l = cl.length; i < l; i++) {
  1703. if (cl[i].key === ptr) {
  1704. return cl[i];
  1705. }
  1706. }
  1707. } else if (typeof ptr === "number") {
  1708. return this.children[ptr];
  1709. } else if (ptr.parent === this) {
  1710. return ptr;
  1711. }
  1712. }
  1713. return null;
  1714. },
  1715. // TODO: activate()
  1716. // TODO: activateSilently()
  1717. /* Internal helper called in recursive addChildren sequence.*/
  1718. _setChildren: function(children) {
  1719. _assert(
  1720. children && (!this.children || this.children.length === 0),
  1721. "only init supported"
  1722. );
  1723. this.children = [];
  1724. for (var i = 0, l = children.length; i < l; i++) {
  1725. this.children.push(new FancytreeNode(this, children[i]));
  1726. }
  1727. this.tree._callHook(
  1728. "treeStructureChanged",
  1729. this.tree,
  1730. "setChildren"
  1731. );
  1732. },
  1733. /**
  1734. * Append (or insert) a list of child nodes.
  1735. *
  1736. * @param {NodeData[]} children array of child node definitions (also single child accepted)
  1737. * @param {FancytreeNode | string | Integer} [insertBefore] child node (or key or index of such).
  1738. * If omitted, the new children are appended.
  1739. * @returns {FancytreeNode} first child added
  1740. *
  1741. * @see FancytreeNode#applyPatch
  1742. */
  1743. addChildren: function(children, insertBefore) {
  1744. var i,
  1745. l,
  1746. pos,
  1747. origFirstChild = this.getFirstChild(),
  1748. origLastChild = this.getLastChild(),
  1749. firstNode = null,
  1750. nodeList = [];
  1751. if ($.isPlainObject(children)) {
  1752. children = [children];
  1753. }
  1754. if (!this.children) {
  1755. this.children = [];
  1756. }
  1757. for (i = 0, l = children.length; i < l; i++) {
  1758. nodeList.push(new FancytreeNode(this, children[i]));
  1759. }
  1760. firstNode = nodeList[0];
  1761. if (insertBefore == null) {
  1762. this.children = this.children.concat(nodeList);
  1763. } else {
  1764. // Returns null if insertBefore is not a direct child:
  1765. insertBefore = this._findDirectChild(insertBefore);
  1766. pos = $.inArray(insertBefore, this.children);
  1767. _assert(pos >= 0, "insertBefore must be an existing child");
  1768. // insert nodeList after children[pos]
  1769. this.children.splice.apply(
  1770. this.children,
  1771. [pos, 0].concat(nodeList)
  1772. );
  1773. }
  1774. if (origFirstChild && !insertBefore) {
  1775. // #708: Fast path -- don't render every child of root, just the new ones!
  1776. // #723, #729: but only if it's appended to an existing child list
  1777. for (i = 0, l = nodeList.length; i < l; i++) {
  1778. nodeList[i].render(); // New nodes were never rendered before
  1779. }
  1780. // Adjust classes where status may have changed
  1781. // Has a first child
  1782. if (origFirstChild !== this.getFirstChild()) {
  1783. // Different first child -- recompute classes
  1784. origFirstChild.renderStatus();
  1785. }
  1786. if (origLastChild !== this.getLastChild()) {
  1787. // Different last child -- recompute classes
  1788. origLastChild.renderStatus();
  1789. }
  1790. } else if (!this.parent || this.parent.ul || this.tr) {
  1791. // render if the parent was rendered (or this is a root node)
  1792. this.render();
  1793. }
  1794. if (this.tree.options.selectMode === 3) {
  1795. this.fixSelection3FromEndNodes();
  1796. }
  1797. this.triggerModifyChild(
  1798. "add",
  1799. nodeList.length === 1 ? nodeList[0] : null
  1800. );
  1801. return firstNode;
  1802. },
  1803. /**
  1804. * Add class to node's span tag and to .extraClasses.
  1805. *
  1806. * @param {string} className class name
  1807. *
  1808. * @since 2.17
  1809. */
  1810. addClass: function(className) {
  1811. return this.toggleClass(className, true);
  1812. },
  1813. /**
  1814. * Append or prepend a node, or append a child node.
  1815. *
  1816. * This a convenience function that calls addChildren()
  1817. *
  1818. * @param {NodeData} node node definition
  1819. * @param {string} [mode=child] 'before', 'after', 'firstChild', or 'child' ('over' is a synonym for 'child')
  1820. * @returns {FancytreeNode} new node
  1821. */
  1822. addNode: function(node, mode) {
  1823. if (mode === undefined || mode === "over") {
  1824. mode = "child";
  1825. }
  1826. switch (mode) {
  1827. case "after":
  1828. return this.getParent().addChildren(
  1829. node,
  1830. this.getNextSibling()
  1831. );
  1832. case "before":
  1833. return this.getParent().addChildren(node, this);
  1834. case "firstChild":
  1835. // Insert before the first child if any
  1836. var insertBefore = this.children ? this.children[0] : null;
  1837. return this.addChildren(node, insertBefore);
  1838. case "child":
  1839. case "over":
  1840. return this.addChildren(node);
  1841. }
  1842. _assert(false, "Invalid mode: " + mode);
  1843. },
  1844. /**Add child status nodes that indicate 'More...', etc.
  1845. *
  1846. * This also maintains the node's `partload` property.
  1847. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  1848. * @param {string} [mode='child'] 'child'|firstChild'
  1849. * @since 2.15
  1850. */
  1851. addPagingNode: function(node, mode) {
  1852. var i, n;
  1853. mode = mode || "child";
  1854. if (node === false) {
  1855. for (i = this.children.length - 1; i >= 0; i--) {
  1856. n = this.children[i];
  1857. if (n.statusNodeType === "paging") {
  1858. this.removeChild(n);
  1859. }
  1860. }
  1861. this.partload = false;
  1862. return;
  1863. }
  1864. node = $.extend(
  1865. {
  1866. title: this.tree.options.strings.moreData,
  1867. statusNodeType: "paging",
  1868. icon: false,
  1869. },
  1870. node
  1871. );
  1872. this.partload = true;
  1873. return this.addNode(node, mode);
  1874. },
  1875. /**
  1876. * Append new node after this.
  1877. *
  1878. * This a convenience function that calls addNode(node, 'after')
  1879. *
  1880. * @param {NodeData} node node definition
  1881. * @returns {FancytreeNode} new node
  1882. */
  1883. appendSibling: function(node) {
  1884. return this.addNode(node, "after");
  1885. },
  1886. /**
  1887. * (experimental) Apply a modification (or navigation) operation.
  1888. *
  1889. * @param {string} cmd
  1890. * @param {object} [opts]
  1891. * @see Fancytree#applyCommand
  1892. * @since 2.32
  1893. */
  1894. applyCommand: function(cmd, opts) {
  1895. return this.tree.applyCommand(cmd, this, opts);
  1896. },
  1897. /**
  1898. * Modify existing child nodes.
  1899. *
  1900. * @param {NodePatch} patch
  1901. * @returns {$.Promise}
  1902. * @see FancytreeNode#addChildren
  1903. */
  1904. applyPatch: function(patch) {
  1905. // patch [key, null] means 'remove'
  1906. if (patch === null) {
  1907. this.remove();
  1908. return _getResolvedPromise(this);
  1909. }
  1910. // TODO: make sure that root node is not collapsed or modified
  1911. // copy (most) attributes to node.ATTR or node.data.ATTR
  1912. var name,
  1913. promise,
  1914. v,
  1915. IGNORE_MAP = { children: true, expanded: true, parent: true }; // TODO: should be global
  1916. for (name in patch) {
  1917. if (patch.hasOwnProperty(name)) {
  1918. v = patch[name];
  1919. if (!IGNORE_MAP[name] && !$.isFunction(v)) {
  1920. if (NODE_ATTR_MAP[name]) {
  1921. this[name] = v;
  1922. } else {
  1923. this.data[name] = v;
  1924. }
  1925. }
  1926. }
  1927. }
  1928. // Remove and/or create children
  1929. if (patch.hasOwnProperty("children")) {
  1930. this.removeChildren();
  1931. if (patch.children) {
  1932. // only if not null and not empty list
  1933. // TODO: addChildren instead?
  1934. this._setChildren(patch.children);
  1935. }
  1936. // TODO: how can we APPEND or INSERT child nodes?
  1937. }
  1938. if (this.isVisible()) {
  1939. this.renderTitle();
  1940. this.renderStatus();
  1941. }
  1942. // Expand collapse (final step, since this may be async)
  1943. if (patch.hasOwnProperty("expanded")) {
  1944. promise = this.setExpanded(patch.expanded);
  1945. } else {
  1946. promise = _getResolvedPromise(this);
  1947. }
  1948. return promise;
  1949. },
  1950. /** Collapse all sibling nodes.
  1951. * @returns {$.Promise}
  1952. */
  1953. collapseSiblings: function() {
  1954. return this.tree._callHook("nodeCollapseSiblings", this);
  1955. },
  1956. /** Copy this node as sibling or child of `node`.
  1957. *
  1958. * @param {FancytreeNode} node source node
  1959. * @param {string} [mode=child] 'before' | 'after' | 'child'
  1960. * @param {Function} [map] callback function(NodeData, FancytreeNode) that could modify the new node
  1961. * @returns {FancytreeNode} new
  1962. */
  1963. copyTo: function(node, mode, map) {
  1964. return node.addNode(this.toDict(true, map), mode);
  1965. },
  1966. /** Count direct and indirect children.
  1967. *
  1968. * @param {boolean} [deep=true] pass 'false' to only count direct children
  1969. * @returns {int} number of child nodes
  1970. */
  1971. countChildren: function(deep) {
  1972. var cl = this.children,
  1973. i,
  1974. l,
  1975. n;
  1976. if (!cl) {
  1977. return 0;
  1978. }
  1979. n = cl.length;
  1980. if (deep !== false) {
  1981. for (i = 0, l = n; i < l; i++) {
  1982. n += cl[i].countChildren();
  1983. }
  1984. }
  1985. return n;
  1986. },
  1987. // TODO: deactivate()
  1988. /** Write to browser console if debugLevel >= 4 (prepending node info)
  1989. *
  1990. * @param {*} msg string or object or array of such
  1991. */
  1992. debug: function(msg) {
  1993. if (this.tree.options.debugLevel >= 4) {
  1994. Array.prototype.unshift.call(arguments, this.toString());
  1995. consoleApply("log", arguments);
  1996. }
  1997. },
  1998. /** Deprecated.
  1999. * @deprecated since 2014-02-16. Use resetLazy() instead.
  2000. */
  2001. discard: function() {
  2002. this.warn(
  2003. "FancytreeNode.discard() is deprecated since 2014-02-16. Use .resetLazy() instead."
  2004. );
  2005. return this.resetLazy();
  2006. },
  2007. /** Remove DOM elements for all descendents. May be called on .collapse event
  2008. * to keep the DOM small.
  2009. * @param {boolean} [includeSelf=false]
  2010. */
  2011. discardMarkup: function(includeSelf) {
  2012. var fn = includeSelf ? "nodeRemoveMarkup" : "nodeRemoveChildMarkup";
  2013. this.tree._callHook(fn, this);
  2014. },
  2015. /** Write error to browser console if debugLevel >= 1 (prepending tree info)
  2016. *
  2017. * @param {*} msg string or object or array of such
  2018. */
  2019. error: function(msg) {
  2020. if (this.tree.options.debugLevel >= 1) {
  2021. Array.prototype.unshift.call(arguments, this.toString());
  2022. consoleApply("error", arguments);
  2023. }
  2024. },
  2025. /**Find all nodes that match condition (excluding self).
  2026. *
  2027. * @param {string | function(node)} match title string to search for, or a
  2028. * callback function that returns `true` if a node is matched.
  2029. * @returns {FancytreeNode[]} array of nodes (may be empty)
  2030. */
  2031. findAll: function(match) {
  2032. match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
  2033. var res = [];
  2034. this.visit(function(n) {
  2035. if (match(n)) {
  2036. res.push(n);
  2037. }
  2038. });
  2039. return res;
  2040. },
  2041. /**Find first node that matches condition (excluding self).
  2042. *
  2043. * @param {string | function(node)} match title string to search for, or a
  2044. * callback function that returns `true` if a node is matched.
  2045. * @returns {FancytreeNode} matching node or null
  2046. * @see FancytreeNode#findAll
  2047. */
  2048. findFirst: function(match) {
  2049. match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
  2050. var res = null;
  2051. this.visit(function(n) {
  2052. if (match(n)) {
  2053. res = n;
  2054. return false;
  2055. }
  2056. });
  2057. return res;
  2058. },
  2059. /** Find a node relative to self.
  2060. *
  2061. * @param {number|string} where The keyCode that would normally trigger this move,
  2062. * or a keyword ('down', 'first', 'last', 'left', 'parent', 'right', 'up').
  2063. * @returns {FancytreeNode}
  2064. * @since v2.31
  2065. */
  2066. findRelatedNode: function(where, includeHidden) {
  2067. return this.tree.findRelatedNode(this, where, includeHidden);
  2068. },
  2069. /* Apply selection state (internal use only) */
  2070. _changeSelectStatusAttrs: function(state) {
  2071. var changed = false,
  2072. opts = this.tree.options,
  2073. unselectable = FT.evalOption(
  2074. "unselectable",
  2075. this,
  2076. this,
  2077. opts,
  2078. false
  2079. ),
  2080. unselectableStatus = FT.evalOption(
  2081. "unselectableStatus",
  2082. this,
  2083. this,
  2084. opts,
  2085. undefined
  2086. );
  2087. if (unselectable && unselectableStatus != null) {
  2088. state = unselectableStatus;
  2089. }
  2090. switch (state) {
  2091. case false:
  2092. changed = this.selected || this.partsel;
  2093. this.selected = false;
  2094. this.partsel = false;
  2095. break;
  2096. case true:
  2097. changed = !this.selected || !this.partsel;
  2098. this.selected = true;
  2099. this.partsel = true;
  2100. break;
  2101. case undefined:
  2102. changed = this.selected || !this.partsel;
  2103. this.selected = false;
  2104. this.partsel = true;
  2105. break;
  2106. default:
  2107. _assert(false, "invalid state: " + state);
  2108. }
  2109. // this.debug("fixSelection3AfterLoad() _changeSelectStatusAttrs()", state, changed);
  2110. if (changed) {
  2111. this.renderStatus();
  2112. }
  2113. return changed;
  2114. },
  2115. /**
  2116. * Fix selection status, after this node was (de)selected in multi-hier mode.
  2117. * This includes (de)selecting all children.
  2118. */
  2119. fixSelection3AfterClick: function(callOpts) {
  2120. var flag = this.isSelected();
  2121. // this.debug("fixSelection3AfterClick()");
  2122. this.visit(function(node) {
  2123. node._changeSelectStatusAttrs(flag);
  2124. if (node.radiogroup) {
  2125. // #931: don't (de)select this branch
  2126. return "skip";
  2127. }
  2128. });
  2129. this.fixSelection3FromEndNodes(callOpts);
  2130. },
  2131. /**
  2132. * Fix selection status for multi-hier mode.
  2133. * Only end-nodes are considered to update the descendants branch and parents.
  2134. * Should be called after this node has loaded new children or after
  2135. * children have been modified using the API.
  2136. */
  2137. fixSelection3FromEndNodes: function(callOpts) {
  2138. var opts = this.tree.options;
  2139. // this.debug("fixSelection3FromEndNodes()");
  2140. _assert(opts.selectMode === 3, "expected selectMode 3");
  2141. // Visit all end nodes and adjust their parent's `selected` and `partsel`
  2142. // attributes. Return selection state true, false, or undefined.
  2143. function _walk(node) {
  2144. var i,
  2145. l,
  2146. child,
  2147. s,
  2148. state,
  2149. allSelected,
  2150. someSelected,
  2151. unselIgnore,
  2152. unselState,
  2153. children = node.children;
  2154. if (children && children.length) {
  2155. // check all children recursively
  2156. allSelected = true;
  2157. someSelected = false;
  2158. for (i = 0, l = children.length; i < l; i++) {
  2159. child = children[i];
  2160. // the selection state of a node is not relevant; we need the end-nodes
  2161. s = _walk(child);
  2162. // if( !child.unselectableIgnore ) {
  2163. unselIgnore = FT.evalOption(
  2164. "unselectableIgnore",
  2165. child,
  2166. child,
  2167. opts,
  2168. false
  2169. );
  2170. if (!unselIgnore) {
  2171. if (s !== false) {
  2172. someSelected = true;
  2173. }
  2174. if (s !== true) {
  2175. allSelected = false;
  2176. }
  2177. }
  2178. }
  2179. // eslint-disable-next-line no-nested-ternary
  2180. state = allSelected
  2181. ? true
  2182. : someSelected
  2183. ? undefined
  2184. : false;
  2185. } else {
  2186. // This is an end-node: simply report the status
  2187. unselState = FT.evalOption(
  2188. "unselectableStatus",
  2189. node,
  2190. node,
  2191. opts,
  2192. undefined
  2193. );
  2194. state = unselState == null ? !!node.selected : !!unselState;
  2195. }
  2196. // #939: Keep a `partsel` flag that was explicitly set on a lazy node
  2197. if (
  2198. node.partsel &&
  2199. !node.selected &&
  2200. node.lazy &&
  2201. node.children == null
  2202. ) {
  2203. state = undefined;
  2204. }
  2205. node._changeSelectStatusAttrs(state);
  2206. return state;
  2207. }
  2208. _walk(this);
  2209. // Update parent's state
  2210. this.visitParents(function(node) {
  2211. var i,
  2212. l,
  2213. child,
  2214. state,
  2215. unselIgnore,
  2216. unselState,
  2217. children = node.children,
  2218. allSelected = true,
  2219. someSelected = false;
  2220. for (i = 0, l = children.length; i < l; i++) {
  2221. child = children[i];
  2222. unselIgnore = FT.evalOption(
  2223. "unselectableIgnore",
  2224. child,
  2225. child,
  2226. opts,
  2227. false
  2228. );
  2229. if (!unselIgnore) {
  2230. unselState = FT.evalOption(
  2231. "unselectableStatus",
  2232. child,
  2233. child,
  2234. opts,
  2235. undefined
  2236. );
  2237. state =
  2238. unselState == null
  2239. ? !!child.selected
  2240. : !!unselState;
  2241. // When fixing the parents, we trust the sibling status (i.e.
  2242. // we don't recurse)
  2243. if (state || child.partsel) {
  2244. someSelected = true;
  2245. }
  2246. if (!state) {
  2247. allSelected = false;
  2248. }
  2249. }
  2250. }
  2251. // eslint-disable-next-line no-nested-ternary
  2252. state = allSelected ? true : someSelected ? undefined : false;
  2253. node._changeSelectStatusAttrs(state);
  2254. });
  2255. },
  2256. // TODO: focus()
  2257. /**
  2258. * Update node data. If dict contains 'children', then also replace
  2259. * the hole sub tree.
  2260. * @param {NodeData} dict
  2261. *
  2262. * @see FancytreeNode#addChildren
  2263. * @see FancytreeNode#applyPatch
  2264. */
  2265. fromDict: function(dict) {
  2266. // copy all other attributes to this.data.xxx
  2267. for (var name in dict) {
  2268. if (NODE_ATTR_MAP[name]) {
  2269. // node.NAME = dict.NAME
  2270. this[name] = dict[name];
  2271. } else if (name === "data") {
  2272. // node.data += dict.data
  2273. $.extend(this.data, dict.data);
  2274. } else if (
  2275. !$.isFunction(dict[name]) &&
  2276. !NONE_NODE_DATA_MAP[name]
  2277. ) {
  2278. // node.data.NAME = dict.NAME
  2279. this.data[name] = dict[name];
  2280. }
  2281. }
  2282. if (dict.children) {
  2283. // recursively set children and render
  2284. this.removeChildren();
  2285. this.addChildren(dict.children);
  2286. }
  2287. this.renderTitle();
  2288. /*
  2289. var children = dict.children;
  2290. if(children === undefined){
  2291. this.data = $.extend(this.data, dict);
  2292. this.render();
  2293. return;
  2294. }
  2295. dict = $.extend({}, dict);
  2296. dict.children = undefined;
  2297. this.data = $.extend(this.data, dict);
  2298. this.removeChildren();
  2299. this.addChild(children);
  2300. */
  2301. },
  2302. /** Return the list of child nodes (undefined for unexpanded lazy nodes).
  2303. * @returns {FancytreeNode[] | undefined}
  2304. */
  2305. getChildren: function() {
  2306. if (this.hasChildren() === undefined) {
  2307. // TODO: only required for lazy nodes?
  2308. return undefined; // Lazy node: unloaded, currently loading, or load error
  2309. }
  2310. return this.children;
  2311. },
  2312. /** Return the first child node or null.
  2313. * @returns {FancytreeNode | null}
  2314. */
  2315. getFirstChild: function() {
  2316. return this.children ? this.children[0] : null;
  2317. },
  2318. /** Return the 0-based child index.
  2319. * @returns {int}
  2320. */
  2321. getIndex: function() {
  2322. // return this.parent.children.indexOf(this);
  2323. return $.inArray(this, this.parent.children); // indexOf doesn't work in IE7
  2324. },
  2325. /** Return the hierarchical child index (1-based, e.g. '3.2.4').
  2326. * @param {string} [separator="."]
  2327. * @param {int} [digits=1]
  2328. * @returns {string}
  2329. */
  2330. getIndexHier: function(separator, digits) {
  2331. separator = separator || ".";
  2332. var s,
  2333. res = [];
  2334. $.each(this.getParentList(false, true), function(i, o) {
  2335. s = "" + (o.getIndex() + 1);
  2336. if (digits) {
  2337. // prepend leading zeroes
  2338. s = ("0000000" + s).substr(-digits);
  2339. }
  2340. res.push(s);
  2341. });
  2342. return res.join(separator);
  2343. },
  2344. /** Return the parent keys separated by options.keyPathSeparator, e.g. "/id_1/id_17/id_32".
  2345. *
  2346. * (Unlike `node.getPath()`, this method prepends a "/" and inverts the first argument.)
  2347. *
  2348. * @see FancytreeNode#getPath
  2349. * @param {boolean} [excludeSelf=false]
  2350. * @returns {string}
  2351. */
  2352. getKeyPath: function(excludeSelf) {
  2353. var sep = this.tree.options.keyPathSeparator;
  2354. return sep + this.getPath(!excludeSelf, "key", sep);
  2355. },
  2356. /** Return the last child of this node or null.
  2357. * @returns {FancytreeNode | null}
  2358. */
  2359. getLastChild: function() {
  2360. return this.children
  2361. ? this.children[this.children.length - 1]
  2362. : null;
  2363. },
  2364. /** Return node depth. 0: System root node, 1: visible top-level node, 2: first sub-level, ... .
  2365. * @returns {int}
  2366. */
  2367. getLevel: function() {
  2368. var level = 0,
  2369. dtn = this.parent;
  2370. while (dtn) {
  2371. level++;
  2372. dtn = dtn.parent;
  2373. }
  2374. return level;
  2375. },
  2376. /** Return the successor node (under the same parent) or null.
  2377. * @returns {FancytreeNode | null}
  2378. */
  2379. getNextSibling: function() {
  2380. // TODO: use indexOf, if available: (not in IE6)
  2381. if (this.parent) {
  2382. var i,
  2383. l,
  2384. ac = this.parent.children;
  2385. for (i = 0, l = ac.length - 1; i < l; i++) {
  2386. // up to length-2, so next(last) = null
  2387. if (ac[i] === this) {
  2388. return ac[i + 1];
  2389. }
  2390. }
  2391. }
  2392. return null;
  2393. },
  2394. /** Return the parent node (null for the system root node).
  2395. * @returns {FancytreeNode | null}
  2396. */
  2397. getParent: function() {
  2398. // TODO: return null for top-level nodes?
  2399. return this.parent;
  2400. },
  2401. /** Return an array of all parent nodes (top-down).
  2402. * @param {boolean} [includeRoot=false] Include the invisible system root node.
  2403. * @param {boolean} [includeSelf=false] Include the node itself.
  2404. * @returns {FancytreeNode[]}
  2405. */
  2406. getParentList: function(includeRoot, includeSelf) {
  2407. var l = [],
  2408. dtn = includeSelf ? this : this.parent;
  2409. while (dtn) {
  2410. if (includeRoot || dtn.parent) {
  2411. l.unshift(dtn);
  2412. }
  2413. dtn = dtn.parent;
  2414. }
  2415. return l;
  2416. },
  2417. /** Return a string representing the hierachical node path, e.g. "a/b/c".
  2418. * @param {boolean} [includeSelf=true]
  2419. * @param {string | function} [part="title"] node property name or callback
  2420. * @param {string} [separator="/"]
  2421. * @returns {string}
  2422. * @since v2.31
  2423. */
  2424. getPath: function(includeSelf, part, separator) {
  2425. includeSelf = includeSelf !== false;
  2426. part = part || "title";
  2427. separator = separator || "/";
  2428. var val,
  2429. path = [],
  2430. isFunc = $.isFunction(part);
  2431. this.visitParents(function(n) {
  2432. if (n.parent) {
  2433. val = isFunc ? part(n) : n[part];
  2434. path.unshift(val);
  2435. }
  2436. }, includeSelf);
  2437. return path.join(separator);
  2438. },
  2439. /** Return the predecessor node (under the same parent) or null.
  2440. * @returns {FancytreeNode | null}
  2441. */
  2442. getPrevSibling: function() {
  2443. if (this.parent) {
  2444. var i,
  2445. l,
  2446. ac = this.parent.children;
  2447. for (i = 1, l = ac.length; i < l; i++) {
  2448. // start with 1, so prev(first) = null
  2449. if (ac[i] === this) {
  2450. return ac[i - 1];
  2451. }
  2452. }
  2453. }
  2454. return null;
  2455. },
  2456. /**
  2457. * Return an array of selected descendant nodes.
  2458. * @param {boolean} [stopOnParents=false] only return the topmost selected
  2459. * node (useful with selectMode 3)
  2460. * @returns {FancytreeNode[]}
  2461. */
  2462. getSelectedNodes: function(stopOnParents) {
  2463. var nodeList = [];
  2464. this.visit(function(node) {
  2465. if (node.selected) {
  2466. nodeList.push(node);
  2467. if (stopOnParents === true) {
  2468. return "skip"; // stop processing this branch
  2469. }
  2470. }
  2471. });
  2472. return nodeList;
  2473. },
  2474. /** Return true if node has children. Return undefined if not sure, i.e. the node is lazy and not yet loaded).
  2475. * @returns {boolean | undefined}
  2476. */
  2477. hasChildren: function() {
  2478. if (this.lazy) {
  2479. if (this.children == null) {
  2480. // null or undefined: Not yet loaded
  2481. return undefined;
  2482. } else if (this.children.length === 0) {
  2483. // Loaded, but response was empty
  2484. return false;
  2485. } else if (
  2486. this.children.length === 1 &&
  2487. this.children[0].isStatusNode()
  2488. ) {
  2489. // Currently loading or load error
  2490. return undefined;
  2491. }
  2492. return true;
  2493. }
  2494. return !!(this.children && this.children.length);
  2495. },
  2496. /**
  2497. * Return true if node has `className` defined in .extraClasses.
  2498. *
  2499. * @param {string} className class name (separate multiple classes by space)
  2500. * @returns {boolean}
  2501. *
  2502. * @since 2.32
  2503. */
  2504. hasClass: function(className) {
  2505. return (
  2506. (" " + (this.extraClasses || "") + " ").indexOf(
  2507. " " + className + " "
  2508. ) >= 0
  2509. );
  2510. },
  2511. /** Return true if node has keyboard focus.
  2512. * @returns {boolean}
  2513. */
  2514. hasFocus: function() {
  2515. return this.tree.hasFocus() && this.tree.focusNode === this;
  2516. },
  2517. /** Write to browser console if debugLevel >= 3 (prepending node info)
  2518. *
  2519. * @param {*} msg string or object or array of such
  2520. */
  2521. info: function(msg) {
  2522. if (this.tree.options.debugLevel >= 3) {
  2523. Array.prototype.unshift.call(arguments, this.toString());
  2524. consoleApply("info", arguments);
  2525. }
  2526. },
  2527. /** Return true if node is active (see also FancytreeNode#isSelected).
  2528. * @returns {boolean}
  2529. */
  2530. isActive: function() {
  2531. return this.tree.activeNode === this;
  2532. },
  2533. /** Return true if node is vertically below `otherNode`, i.e. rendered in a subsequent row.
  2534. * @param {FancytreeNode} otherNode
  2535. * @returns {boolean}
  2536. * @since 2.28
  2537. */
  2538. isBelowOf: function(otherNode) {
  2539. return this.getIndexHier(".", 5) > otherNode.getIndexHier(".", 5);
  2540. },
  2541. /** Return true if node is a direct child of otherNode.
  2542. * @param {FancytreeNode} otherNode
  2543. * @returns {boolean}
  2544. */
  2545. isChildOf: function(otherNode) {
  2546. return this.parent && this.parent === otherNode;
  2547. },
  2548. /** Return true, if node is a direct or indirect sub node of otherNode.
  2549. * @param {FancytreeNode} otherNode
  2550. * @returns {boolean}
  2551. */
  2552. isDescendantOf: function(otherNode) {
  2553. if (!otherNode || otherNode.tree !== this.tree) {
  2554. return false;
  2555. }
  2556. var p = this.parent;
  2557. while (p) {
  2558. if (p === otherNode) {
  2559. return true;
  2560. }
  2561. if (p === p.parent) {
  2562. $.error("Recursive parent link: " + p);
  2563. }
  2564. p = p.parent;
  2565. }
  2566. return false;
  2567. },
  2568. /** Return true if node is expanded.
  2569. * @returns {boolean}
  2570. */
  2571. isExpanded: function() {
  2572. return !!this.expanded;
  2573. },
  2574. /** Return true if node is the first node of its parent's children.
  2575. * @returns {boolean}
  2576. */
  2577. isFirstSibling: function() {
  2578. var p = this.parent;
  2579. return !p || p.children[0] === this;
  2580. },
  2581. /** Return true if node is a folder, i.e. has the node.folder attribute set.
  2582. * @returns {boolean}
  2583. */
  2584. isFolder: function() {
  2585. return !!this.folder;
  2586. },
  2587. /** Return true if node is the last node of its parent's children.
  2588. * @returns {boolean}
  2589. */
  2590. isLastSibling: function() {
  2591. var p = this.parent;
  2592. return !p || p.children[p.children.length - 1] === this;
  2593. },
  2594. /** Return true if node is lazy (even if data was already loaded)
  2595. * @returns {boolean}
  2596. */
  2597. isLazy: function() {
  2598. return !!this.lazy;
  2599. },
  2600. /** Return true if node is lazy and loaded. For non-lazy nodes always return true.
  2601. * @returns {boolean}
  2602. */
  2603. isLoaded: function() {
  2604. return !this.lazy || this.hasChildren() !== undefined; // Also checks if the only child is a status node
  2605. },
  2606. /** Return true if children are currently beeing loaded, i.e. a Ajax request is pending.
  2607. * @returns {boolean}
  2608. */
  2609. isLoading: function() {
  2610. return !!this._isLoading;
  2611. },
  2612. /*
  2613. * @deprecated since v2.4.0: Use isRootNode() instead
  2614. */
  2615. isRoot: function() {
  2616. return this.isRootNode();
  2617. },
  2618. /** Return true if node is partially selected (tri-state).
  2619. * @returns {boolean}
  2620. * @since 2.23
  2621. */
  2622. isPartsel: function() {
  2623. return !this.selected && !!this.partsel;
  2624. },
  2625. /** (experimental) Return true if this is partially loaded.
  2626. * @returns {boolean}
  2627. * @since 2.15
  2628. */
  2629. isPartload: function() {
  2630. return !!this.partload;
  2631. },
  2632. /** Return true if this is the (invisible) system root node.
  2633. * @returns {boolean}
  2634. * @since 2.4
  2635. */
  2636. isRootNode: function() {
  2637. return this.tree.rootNode === this;
  2638. },
  2639. /** Return true if node is selected, i.e. has a checkmark set (see also FancytreeNode#isActive).
  2640. * @returns {boolean}
  2641. */
  2642. isSelected: function() {
  2643. return !!this.selected;
  2644. },
  2645. /** Return true if this node is a temporarily generated system node like
  2646. * 'loading', 'paging', or 'error' (node.statusNodeType contains the type).
  2647. * @returns {boolean}
  2648. */
  2649. isStatusNode: function() {
  2650. return !!this.statusNodeType;
  2651. },
  2652. /** Return true if this node is a status node of type 'paging'.
  2653. * @returns {boolean}
  2654. * @since 2.15
  2655. */
  2656. isPagingNode: function() {
  2657. return this.statusNodeType === "paging";
  2658. },
  2659. /** Return true if this a top level node, i.e. a direct child of the (invisible) system root node.
  2660. * @returns {boolean}
  2661. * @since 2.4
  2662. */
  2663. isTopLevel: function() {
  2664. return this.tree.rootNode === this.parent;
  2665. },
  2666. /** Return true if node is lazy and not yet loaded. For non-lazy nodes always return false.
  2667. * @returns {boolean}
  2668. */
  2669. isUndefined: function() {
  2670. return this.hasChildren() === undefined; // also checks if the only child is a status node
  2671. },
  2672. /** Return true if all parent nodes are expanded. Note: this does not check
  2673. * whether the node is scrolled into the visible part of the screen.
  2674. * @returns {boolean}
  2675. */
  2676. isVisible: function() {
  2677. var i,
  2678. l,
  2679. n,
  2680. hasFilter = this.tree.enableFilter,
  2681. parents = this.getParentList(false, false);
  2682. // TODO: check $(n.span).is(":visible")
  2683. // i.e. return false for nodes (but not parents) that are hidden
  2684. // by a filter
  2685. if (hasFilter && !this.match && !this.subMatchCount) {
  2686. // this.debug( "isVisible: HIDDEN (" + hasFilter + ", " + this.match + ", " + this.match + ")" );
  2687. return false;
  2688. }
  2689. for (i = 0, l = parents.length; i < l; i++) {
  2690. n = parents[i];
  2691. if (!n.expanded) {
  2692. // this.debug("isVisible: HIDDEN (parent collapsed)");
  2693. return false;
  2694. }
  2695. // if (hasFilter && !n.match && !n.subMatchCount) {
  2696. // this.debug("isVisible: HIDDEN (" + hasFilter + ", " + this.match + ", " + this.match + ")");
  2697. // return false;
  2698. // }
  2699. }
  2700. // this.debug("isVisible: VISIBLE");
  2701. return true;
  2702. },
  2703. /** Deprecated.
  2704. * @deprecated since 2014-02-16: use load() instead.
  2705. */
  2706. lazyLoad: function(discard) {
  2707. $.error(
  2708. "FancytreeNode.lazyLoad() is deprecated since 2014-02-16. Use .load() instead."
  2709. );
  2710. },
  2711. /**
  2712. * Load all children of a lazy node if neccessary. The <i>expanded</i> state is maintained.
  2713. * @param {boolean} [forceReload=false] Pass true to discard any existing nodes before. Otherwise this method does nothing if the node was already loaded.
  2714. * @returns {$.Promise}
  2715. */
  2716. load: function(forceReload) {
  2717. var res,
  2718. source,
  2719. self = this,
  2720. wasExpanded = this.isExpanded();
  2721. _assert(this.isLazy(), "load() requires a lazy node");
  2722. // _assert( forceReload || this.isUndefined(), "Pass forceReload=true to re-load a lazy node" );
  2723. if (!forceReload && !this.isUndefined()) {
  2724. return _getResolvedPromise(this);
  2725. }
  2726. if (this.isLoaded()) {
  2727. this.resetLazy(); // also collapses
  2728. }
  2729. // This method is also called by setExpanded() and loadKeyPath(), so we
  2730. // have to avoid recursion.
  2731. source = this.tree._triggerNodeEvent("lazyLoad", this);
  2732. if (source === false) {
  2733. // #69
  2734. return _getResolvedPromise(this);
  2735. }
  2736. _assert(
  2737. typeof source !== "boolean",
  2738. "lazyLoad event must return source in data.result"
  2739. );
  2740. res = this.tree._callHook("nodeLoadChildren", this, source);
  2741. if (wasExpanded) {
  2742. this.expanded = true;
  2743. res.always(function() {
  2744. self.render();
  2745. });
  2746. } else {
  2747. res.always(function() {
  2748. self.renderStatus(); // fix expander icon to 'loaded'
  2749. });
  2750. }
  2751. return res;
  2752. },
  2753. /** Expand all parents and optionally scroll into visible area as neccessary.
  2754. * Promise is resolved, when lazy loading and animations are done.
  2755. * @param {object} [opts] passed to `setExpanded()`.
  2756. * Defaults to {noAnimation: false, noEvents: false, scrollIntoView: true}
  2757. * @returns {$.Promise}
  2758. */
  2759. makeVisible: function(opts) {
  2760. var i,
  2761. self = this,
  2762. deferreds = [],
  2763. dfd = new $.Deferred(),
  2764. parents = this.getParentList(false, false),
  2765. len = parents.length,
  2766. effects = !(opts && opts.noAnimation === true),
  2767. scroll = !(opts && opts.scrollIntoView === false);
  2768. // Expand bottom-up, so only the top node is animated
  2769. for (i = len - 1; i >= 0; i--) {
  2770. // self.debug("pushexpand" + parents[i]);
  2771. deferreds.push(parents[i].setExpanded(true, opts));
  2772. }
  2773. $.when.apply($, deferreds).done(function() {
  2774. // All expands have finished
  2775. // self.debug("expand DONE", scroll);
  2776. if (scroll) {
  2777. self.scrollIntoView(effects).done(function() {
  2778. // self.debug("scroll DONE");
  2779. dfd.resolve();
  2780. });
  2781. } else {
  2782. dfd.resolve();
  2783. }
  2784. });
  2785. return dfd.promise();
  2786. },
  2787. /** Move this node to targetNode.
  2788. * @param {FancytreeNode} targetNode
  2789. * @param {string} mode <pre>
  2790. * 'child': append this node as last child of targetNode.
  2791. * This is the default. To be compatble with the D'n'd
  2792. * hitMode, we also accept 'over'.
  2793. * 'firstChild': add this node as first child of targetNode.
  2794. * 'before': add this node as sibling before targetNode.
  2795. * 'after': add this node as sibling after targetNode.</pre>
  2796. * @param {function} [map] optional callback(FancytreeNode) to allow modifcations
  2797. */
  2798. moveTo: function(targetNode, mode, map) {
  2799. if (mode === undefined || mode === "over") {
  2800. mode = "child";
  2801. } else if (mode === "firstChild") {
  2802. if (targetNode.children && targetNode.children.length) {
  2803. mode = "before";
  2804. targetNode = targetNode.children[0];
  2805. } else {
  2806. mode = "child";
  2807. }
  2808. }
  2809. var pos,
  2810. tree = this.tree,
  2811. prevParent = this.parent,
  2812. targetParent =
  2813. mode === "child" ? targetNode : targetNode.parent;
  2814. if (this === targetNode) {
  2815. return;
  2816. } else if (!this.parent) {
  2817. $.error("Cannot move system root");
  2818. } else if (targetParent.isDescendantOf(this)) {
  2819. $.error("Cannot move a node to its own descendant");
  2820. }
  2821. if (targetParent !== prevParent) {
  2822. prevParent.triggerModifyChild("remove", this);
  2823. }
  2824. // Unlink this node from current parent
  2825. if (this.parent.children.length === 1) {
  2826. if (this.parent === targetParent) {
  2827. return; // #258
  2828. }
  2829. this.parent.children = this.parent.lazy ? [] : null;
  2830. this.parent.expanded = false;
  2831. } else {
  2832. pos = $.inArray(this, this.parent.children);
  2833. _assert(pos >= 0, "invalid source parent");
  2834. this.parent.children.splice(pos, 1);
  2835. }
  2836. // Remove from source DOM parent
  2837. // if(this.parent.ul){
  2838. // this.parent.ul.removeChild(this.li);
  2839. // }
  2840. // Insert this node to target parent's child list
  2841. this.parent = targetParent;
  2842. if (targetParent.hasChildren()) {
  2843. switch (mode) {
  2844. case "child":
  2845. // Append to existing target children
  2846. targetParent.children.push(this);
  2847. break;
  2848. case "before":
  2849. // Insert this node before target node
  2850. pos = $.inArray(targetNode, targetParent.children);
  2851. _assert(pos >= 0, "invalid target parent");
  2852. targetParent.children.splice(pos, 0, this);
  2853. break;
  2854. case "after":
  2855. // Insert this node after target node
  2856. pos = $.inArray(targetNode, targetParent.children);
  2857. _assert(pos >= 0, "invalid target parent");
  2858. targetParent.children.splice(pos + 1, 0, this);
  2859. break;
  2860. default:
  2861. $.error("Invalid mode " + mode);
  2862. }
  2863. } else {
  2864. targetParent.children = [this];
  2865. }
  2866. // Parent has no <ul> tag yet:
  2867. // if( !targetParent.ul ) {
  2868. // // This is the parent's first child: create UL tag
  2869. // // (Hidden, because it will be
  2870. // targetParent.ul = document.createElement("ul");
  2871. // targetParent.ul.style.display = "none";
  2872. // targetParent.li.appendChild(targetParent.ul);
  2873. // }
  2874. // // Issue 319: Add to target DOM parent (only if node was already rendered(expanded))
  2875. // if(this.li){
  2876. // targetParent.ul.appendChild(this.li);
  2877. // }
  2878. // Let caller modify the nodes
  2879. if (map) {
  2880. targetNode.visit(map, true);
  2881. }
  2882. if (targetParent === prevParent) {
  2883. targetParent.triggerModifyChild("move", this);
  2884. } else {
  2885. // prevParent.triggerModifyChild("remove", this);
  2886. targetParent.triggerModifyChild("add", this);
  2887. }
  2888. // Handle cross-tree moves
  2889. if (tree !== targetNode.tree) {
  2890. // Fix node.tree for all source nodes
  2891. // _assert(false, "Cross-tree move is not yet implemented.");
  2892. this.warn("Cross-tree moveTo is experimental!");
  2893. this.visit(function(n) {
  2894. // TODO: fix selection state and activation, ...
  2895. n.tree = targetNode.tree;
  2896. }, true);
  2897. }
  2898. // A collaposed node won't re-render children, so we have to remove it manually
  2899. // if( !targetParent.expanded ){
  2900. // prevParent.ul.removeChild(this.li);
  2901. // }
  2902. tree._callHook("treeStructureChanged", tree, "moveTo");
  2903. // Update HTML markup
  2904. if (!prevParent.isDescendantOf(targetParent)) {
  2905. prevParent.render();
  2906. }
  2907. if (
  2908. !targetParent.isDescendantOf(prevParent) &&
  2909. targetParent !== prevParent
  2910. ) {
  2911. targetParent.render();
  2912. }
  2913. // TODO: fix selection state
  2914. // TODO: fix active state
  2915. /*
  2916. var tree = this.tree;
  2917. var opts = tree.options;
  2918. var pers = tree.persistence;
  2919. // Always expand, if it's below minExpandLevel
  2920. // tree.logDebug ("%s._addChildNode(%o), l=%o", this, ftnode, ftnode.getLevel());
  2921. if ( opts.minExpandLevel >= ftnode.getLevel() ) {
  2922. // tree.logDebug ("Force expand for %o", ftnode);
  2923. this.bExpanded = true;
  2924. }
  2925. // In multi-hier mode, update the parents selection state
  2926. // DT issue #82: only if not initializing, because the children may not exist yet
  2927. // if( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing )
  2928. // ftnode._fixSelectionState();
  2929. // In multi-hier mode, update the parents selection state
  2930. if( ftnode.bSelected && opts.selectMode==3 ) {
  2931. var p = this;
  2932. while( p ) {
  2933. if( !p.hasSubSel )
  2934. p._setSubSel(true);
  2935. p = p.parent;
  2936. }
  2937. }
  2938. // render this node and the new child
  2939. if ( tree.bEnableUpdate )
  2940. this.render();
  2941. return ftnode;
  2942. */
  2943. },
  2944. /** Set focus relative to this node and optionally activate.
  2945. *
  2946. * 'left' collapses the node if it is expanded, or move to the parent
  2947. * otherwise.
  2948. * 'right' expands the node if it is collapsed, or move to the first
  2949. * child otherwise.
  2950. *
  2951. * @param {string|number} where 'down', 'first', 'last', 'left', 'parent', 'right', or 'up'.
  2952. * (Alternatively the keyCode that would normally trigger this move,
  2953. * e.g. `$.ui.keyCode.LEFT` = 'left'.
  2954. * @param {boolean} [activate=true]
  2955. * @returns {$.Promise}
  2956. */
  2957. navigate: function(where, activate) {
  2958. var node,
  2959. KC = $.ui.keyCode;
  2960. // Handle optional expand/collapse action for LEFT/RIGHT
  2961. switch (where) {
  2962. case "left":
  2963. case KC.LEFT:
  2964. if (this.expanded) {
  2965. return this.setExpanded(false);
  2966. }
  2967. break;
  2968. case "right":
  2969. case KC.RIGHT:
  2970. if (!this.expanded && (this.children || this.lazy)) {
  2971. return this.setExpanded();
  2972. }
  2973. break;
  2974. }
  2975. // Otherwise activate or focus the related node
  2976. node = this.findRelatedNode(where);
  2977. if (node) {
  2978. // setFocus/setActive will scroll later (if autoScroll is specified)
  2979. try {
  2980. node.makeVisible({ scrollIntoView: false });
  2981. } catch (e) {} // #272
  2982. if (activate === false) {
  2983. node.setFocus();
  2984. return _getResolvedPromise();
  2985. }
  2986. return node.setActive();
  2987. }
  2988. this.warn("Could not find related node '" + where + "'.");
  2989. return _getResolvedPromise();
  2990. },
  2991. /**
  2992. * Remove this node (not allowed for system root).
  2993. */
  2994. remove: function() {
  2995. return this.parent.removeChild(this);
  2996. },
  2997. /**
  2998. * Remove childNode from list of direct children.
  2999. * @param {FancytreeNode} childNode
  3000. */
  3001. removeChild: function(childNode) {
  3002. return this.tree._callHook("nodeRemoveChild", this, childNode);
  3003. },
  3004. /**
  3005. * Remove all child nodes and descendents. This converts the node into a leaf.<br>
  3006. * If this was a lazy node, it is still considered 'loaded'; call node.resetLazy()
  3007. * in order to trigger lazyLoad on next expand.
  3008. */
  3009. removeChildren: function() {
  3010. return this.tree._callHook("nodeRemoveChildren", this);
  3011. },
  3012. /**
  3013. * Remove class from node's span tag and .extraClasses.
  3014. *
  3015. * @param {string} className class name
  3016. *
  3017. * @since 2.17
  3018. */
  3019. removeClass: function(className) {
  3020. return this.toggleClass(className, false);
  3021. },
  3022. /**
  3023. * This method renders and updates all HTML markup that is required
  3024. * to display this node in its current state.<br>
  3025. * Note:
  3026. * <ul>
  3027. * <li>It should only be neccessary to call this method after the node object
  3028. * was modified by direct access to its properties, because the common
  3029. * API methods (node.setTitle(), moveTo(), addChildren(), remove(), ...)
  3030. * already handle this.
  3031. * <li> {@link FancytreeNode#renderTitle} and {@link FancytreeNode#renderStatus}
  3032. * are implied. If changes are more local, calling only renderTitle() or
  3033. * renderStatus() may be sufficient and faster.
  3034. * </ul>
  3035. *
  3036. * @param {boolean} [force=false] re-render, even if html markup was already created
  3037. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  3038. */
  3039. render: function(force, deep) {
  3040. return this.tree._callHook("nodeRender", this, force, deep);
  3041. },
  3042. /** Create HTML markup for the node's outer `<span>` (expander, checkbox, icon, and title).
  3043. * Implies {@link FancytreeNode#renderStatus}.
  3044. * @see Fancytree_Hooks#nodeRenderTitle
  3045. */
  3046. renderTitle: function() {
  3047. return this.tree._callHook("nodeRenderTitle", this);
  3048. },
  3049. /** Update element's CSS classes according to node state.
  3050. * @see Fancytree_Hooks#nodeRenderStatus
  3051. */
  3052. renderStatus: function() {
  3053. return this.tree._callHook("nodeRenderStatus", this);
  3054. },
  3055. /**
  3056. * (experimental) Replace this node with `source`.
  3057. * (Currently only available for paging nodes.)
  3058. * @param {NodeData[]} source List of child node definitions
  3059. * @since 2.15
  3060. */
  3061. replaceWith: function(source) {
  3062. var res,
  3063. parent = this.parent,
  3064. pos = $.inArray(this, parent.children),
  3065. self = this;
  3066. _assert(
  3067. this.isPagingNode(),
  3068. "replaceWith() currently requires a paging status node"
  3069. );
  3070. res = this.tree._callHook("nodeLoadChildren", this, source);
  3071. res.done(function(data) {
  3072. // New nodes are currently children of `this`.
  3073. var children = self.children;
  3074. // Prepend newly loaded child nodes to `this`
  3075. // Move new children after self
  3076. for (i = 0; i < children.length; i++) {
  3077. children[i].parent = parent;
  3078. }
  3079. parent.children.splice.apply(
  3080. parent.children,
  3081. [pos + 1, 0].concat(children)
  3082. );
  3083. // Remove self
  3084. self.children = null;
  3085. self.remove();
  3086. // Redraw new nodes
  3087. parent.render();
  3088. // TODO: set node.partload = false if this was tha last paging node?
  3089. // parent.addPagingNode(false);
  3090. }).fail(function() {
  3091. self.setExpanded();
  3092. });
  3093. return res;
  3094. // $.error("Not implemented: replaceWith()");
  3095. },
  3096. /**
  3097. * Remove all children, collapse, and set the lazy-flag, so that the lazyLoad
  3098. * event is triggered on next expand.
  3099. */
  3100. resetLazy: function() {
  3101. this.removeChildren();
  3102. this.expanded = false;
  3103. this.lazy = true;
  3104. this.children = undefined;
  3105. this.renderStatus();
  3106. },
  3107. /** Schedule activity for delayed execution (cancel any pending request).
  3108. * scheduleAction('cancel') will only cancel a pending request (if any).
  3109. * @param {string} mode
  3110. * @param {number} ms
  3111. */
  3112. scheduleAction: function(mode, ms) {
  3113. if (this.tree.timer) {
  3114. clearTimeout(this.tree.timer);
  3115. this.tree.debug("clearTimeout(%o)", this.tree.timer);
  3116. }
  3117. this.tree.timer = null;
  3118. var self = this; // required for closures
  3119. switch (mode) {
  3120. case "cancel":
  3121. // Simply made sure that timer was cleared
  3122. break;
  3123. case "expand":
  3124. this.tree.timer = setTimeout(function() {
  3125. self.tree.debug("setTimeout: trigger expand");
  3126. self.setExpanded(true);
  3127. }, ms);
  3128. break;
  3129. case "activate":
  3130. this.tree.timer = setTimeout(function() {
  3131. self.tree.debug("setTimeout: trigger activate");
  3132. self.setActive(true);
  3133. }, ms);
  3134. break;
  3135. default:
  3136. $.error("Invalid mode " + mode);
  3137. }
  3138. // this.tree.debug("setTimeout(%s, %s): %s", mode, ms, this.tree.timer);
  3139. },
  3140. /**
  3141. *
  3142. * @param {boolean | PlainObject} [effects=false] animation options.
  3143. * @param {object} [options=null] {topNode: null, effects: ..., parent: ...} this node will remain visible in
  3144. * any case, even if `this` is outside the scroll pane.
  3145. * @returns {$.Promise}
  3146. */
  3147. scrollIntoView: function(effects, options) {
  3148. if (options !== undefined && _isNode(options)) {
  3149. throw Error(
  3150. "scrollIntoView() with 'topNode' option is deprecated since 2014-05-08. Use 'options.topNode' instead."
  3151. );
  3152. }
  3153. // The scroll parent is typically the plain tree's <UL> container.
  3154. // For ext-table, we choose the nearest parent that has `position: relative`
  3155. // and `overflow` set.
  3156. // (This default can be overridden by the local or global `scrollParent` option.)
  3157. var opts = $.extend(
  3158. {
  3159. effects:
  3160. effects === true
  3161. ? { duration: 200, queue: false }
  3162. : effects,
  3163. scrollOfs: this.tree.options.scrollOfs,
  3164. scrollParent: this.tree.options.scrollParent,
  3165. topNode: null,
  3166. },
  3167. options
  3168. ),
  3169. $scrollParent = opts.scrollParent,
  3170. $container = this.tree.$container,
  3171. overflowY = $container.css("overflow-y");
  3172. if (!$scrollParent) {
  3173. if (this.tree.tbody) {
  3174. $scrollParent = $container.scrollParent();
  3175. } else if (overflowY === "scroll" || overflowY === "auto") {
  3176. $scrollParent = $container;
  3177. } else {
  3178. // #922 plain tree in a non-fixed-sized UL scrolls inside its parent
  3179. $scrollParent = $container.scrollParent();
  3180. }
  3181. } else if (!$scrollParent.jquery) {
  3182. // Make sure we have a jQuery object
  3183. $scrollParent = $($scrollParent);
  3184. }
  3185. if (
  3186. $scrollParent[0] === document ||
  3187. $scrollParent[0] === document.body
  3188. ) {
  3189. // `document` may be returned by $().scrollParent(), if nothing is found,
  3190. // but would not work: (see #894)
  3191. this.debug(
  3192. "scrollIntoView(): normalizing scrollParent to 'window':",
  3193. $scrollParent[0]
  3194. );
  3195. $scrollParent = $(window);
  3196. }
  3197. // eslint-disable-next-line one-var
  3198. var topNodeY,
  3199. nodeY,
  3200. horzScrollbarHeight,
  3201. containerOffsetTop,
  3202. dfd = new $.Deferred(),
  3203. self = this,
  3204. nodeHeight = $(this.span).height(),
  3205. topOfs = opts.scrollOfs.top || 0,
  3206. bottomOfs = opts.scrollOfs.bottom || 0,
  3207. containerHeight = $scrollParent.height(),
  3208. scrollTop = $scrollParent.scrollTop(),
  3209. $animateTarget = $scrollParent,
  3210. isParentWindow = $scrollParent[0] === window,
  3211. topNode = opts.topNode || null,
  3212. newScrollTop = null;
  3213. // this.debug("scrollIntoView(), scrollTop=" + scrollTop, opts.scrollOfs);
  3214. // _assert($(this.span).is(":visible"), "scrollIntoView node is invisible"); // otherwise we cannot calc offsets
  3215. if (this.isRootNode() || !this.isVisible()) {
  3216. // We cannot calc offsets for hidden elements
  3217. this.info("scrollIntoView(): node is invisible.");
  3218. return _getResolvedPromise();
  3219. }
  3220. if (isParentWindow) {
  3221. nodeY = $(this.span).offset().top;
  3222. topNodeY =
  3223. topNode && topNode.span ? $(topNode.span).offset().top : 0;
  3224. $animateTarget = $("html,body");
  3225. } else {
  3226. _assert(
  3227. $scrollParent[0] !== document &&
  3228. $scrollParent[0] !== document.body,
  3229. "scrollParent should be a simple element or `window`, not document or body."
  3230. );
  3231. containerOffsetTop = $scrollParent.offset().top;
  3232. nodeY =
  3233. $(this.span).offset().top - containerOffsetTop + scrollTop; // relative to scroll parent
  3234. topNodeY = topNode
  3235. ? $(topNode.span).offset().top -
  3236. containerOffsetTop +
  3237. scrollTop
  3238. : 0;
  3239. horzScrollbarHeight = Math.max(
  3240. 0,
  3241. $scrollParent.innerHeight() - $scrollParent[0].clientHeight
  3242. );
  3243. containerHeight -= horzScrollbarHeight;
  3244. }
  3245. // this.debug(" scrollIntoView(), nodeY=" + nodeY + ", containerHeight=" + containerHeight);
  3246. if (nodeY < scrollTop + topOfs) {
  3247. // Node is above visible container area
  3248. newScrollTop = nodeY - topOfs;
  3249. // this.debug(" scrollIntoView(), UPPER newScrollTop=" + newScrollTop);
  3250. } else if (
  3251. nodeY + nodeHeight >
  3252. scrollTop + containerHeight - bottomOfs
  3253. ) {
  3254. newScrollTop = nodeY + nodeHeight - containerHeight + bottomOfs;
  3255. // this.debug(" scrollIntoView(), LOWER newScrollTop=" + newScrollTop);
  3256. // If a topNode was passed, make sure that it is never scrolled
  3257. // outside the upper border
  3258. if (topNode) {
  3259. _assert(
  3260. topNode.isRootNode() || topNode.isVisible(),
  3261. "topNode must be visible"
  3262. );
  3263. if (topNodeY < newScrollTop) {
  3264. newScrollTop = topNodeY - topOfs;
  3265. // this.debug(" scrollIntoView(), TOP newScrollTop=" + newScrollTop);
  3266. }
  3267. }
  3268. }
  3269. if (newScrollTop === null) {
  3270. dfd.resolveWith(this);
  3271. } else {
  3272. // this.debug(" scrollIntoView(), SET newScrollTop=" + newScrollTop);
  3273. if (opts.effects) {
  3274. opts.effects.complete = function() {
  3275. dfd.resolveWith(self);
  3276. };
  3277. $animateTarget.stop(true).animate(
  3278. {
  3279. scrollTop: newScrollTop,
  3280. },
  3281. opts.effects
  3282. );
  3283. } else {
  3284. $animateTarget[0].scrollTop = newScrollTop;
  3285. dfd.resolveWith(this);
  3286. }
  3287. }
  3288. return dfd.promise();
  3289. },
  3290. /**Activate this node.
  3291. *
  3292. * The `cell` option requires the ext-table and ext-ariagrid extensions.
  3293. *
  3294. * @param {boolean} [flag=true] pass false to deactivate
  3295. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false, cell: null}
  3296. * @returns {$.Promise}
  3297. */
  3298. setActive: function(flag, opts) {
  3299. return this.tree._callHook("nodeSetActive", this, flag, opts);
  3300. },
  3301. /**Expand or collapse this node. Promise is resolved, when lazy loading and animations are done.
  3302. * @param {boolean} [flag=true] pass false to collapse
  3303. * @param {object} [opts] additional options. Defaults to {noAnimation: false, noEvents: false}
  3304. * @returns {$.Promise}
  3305. */
  3306. setExpanded: function(flag, opts) {
  3307. return this.tree._callHook("nodeSetExpanded", this, flag, opts);
  3308. },
  3309. /**Set keyboard focus to this node.
  3310. * @param {boolean} [flag=true] pass false to blur
  3311. * @see Fancytree#setFocus
  3312. */
  3313. setFocus: function(flag) {
  3314. return this.tree._callHook("nodeSetFocus", this, flag);
  3315. },
  3316. /**Select this node, i.e. check the checkbox.
  3317. * @param {boolean} [flag=true] pass false to deselect
  3318. * @param {object} [opts] additional options. Defaults to {noEvents: false, p
  3319. * propagateDown: null, propagateUp: null, callback: null }
  3320. */
  3321. setSelected: function(flag, opts) {
  3322. return this.tree._callHook("nodeSetSelected", this, flag, opts);
  3323. },
  3324. /**Mark a lazy node as 'error', 'loading', 'nodata', or 'ok'.
  3325. * @param {string} status 'error'|'loading'|'nodata'|'ok'
  3326. * @param {string} [message]
  3327. * @param {string} [details]
  3328. */
  3329. setStatus: function(status, message, details) {
  3330. return this.tree._callHook(
  3331. "nodeSetStatus",
  3332. this,
  3333. status,
  3334. message,
  3335. details
  3336. );
  3337. },
  3338. /**Rename this node.
  3339. * @param {string} title
  3340. */
  3341. setTitle: function(title) {
  3342. this.title = title;
  3343. this.renderTitle();
  3344. this.triggerModify("rename");
  3345. },
  3346. /**Sort child list by title.
  3347. * @param {function} [cmp] custom compare function(a, b) that returns -1, 0, or 1 (defaults to sort by title).
  3348. * @param {boolean} [deep=false] pass true to sort all descendant nodes
  3349. */
  3350. sortChildren: function(cmp, deep) {
  3351. var i,
  3352. l,
  3353. cl = this.children;
  3354. if (!cl) {
  3355. return;
  3356. }
  3357. cmp =
  3358. cmp ||
  3359. function(a, b) {
  3360. var x = a.title.toLowerCase(),
  3361. y = b.title.toLowerCase();
  3362. // eslint-disable-next-line no-nested-ternary
  3363. return x === y ? 0 : x > y ? 1 : -1;
  3364. };
  3365. cl.sort(cmp);
  3366. if (deep) {
  3367. for (i = 0, l = cl.length; i < l; i++) {
  3368. if (cl[i].children) {
  3369. cl[i].sortChildren(cmp, "$norender$");
  3370. }
  3371. }
  3372. }
  3373. if (deep !== "$norender$") {
  3374. this.render();
  3375. }
  3376. this.triggerModifyChild("sort");
  3377. },
  3378. /** Convert node (or whole branch) into a plain object.
  3379. *
  3380. * The result is compatible with node.addChildren().
  3381. *
  3382. * @param {boolean} [recursive=false] include child nodes
  3383. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications.
  3384. * Return `false` to ignore this node or `"skip"` to include this node without its children.
  3385. * @returns {NodeData}
  3386. */
  3387. toDict: function(recursive, callback) {
  3388. var i,
  3389. l,
  3390. node,
  3391. res,
  3392. dict = {},
  3393. self = this;
  3394. $.each(NODE_ATTRS, function(i, a) {
  3395. if (self[a] || self[a] === false) {
  3396. dict[a] = self[a];
  3397. }
  3398. });
  3399. if (!$.isEmptyObject(this.data)) {
  3400. dict.data = $.extend({}, this.data);
  3401. if ($.isEmptyObject(dict.data)) {
  3402. delete dict.data;
  3403. }
  3404. }
  3405. if (callback) {
  3406. res = callback(dict, self);
  3407. if (res === false) {
  3408. return false; // Don't include this node nor its children
  3409. }
  3410. if (res === "skip") {
  3411. recursive = false; // Include this node, but not the children
  3412. }
  3413. }
  3414. if (recursive) {
  3415. if ($.isArray(this.children)) {
  3416. dict.children = [];
  3417. for (i = 0, l = this.children.length; i < l; i++) {
  3418. node = this.children[i];
  3419. if (!node.isStatusNode()) {
  3420. res = node.toDict(true, callback);
  3421. if (res !== false) {
  3422. dict.children.push(res);
  3423. }
  3424. }
  3425. }
  3426. }
  3427. }
  3428. return dict;
  3429. },
  3430. /**
  3431. * Set, clear, or toggle class of node's span tag and .extraClasses.
  3432. *
  3433. * @param {string} className class name (separate multiple classes by space)
  3434. * @param {boolean} [flag] true/false to add/remove class. If omitted, class is toggled.
  3435. * @returns {boolean} true if a class was added
  3436. *
  3437. * @since 2.17
  3438. */
  3439. toggleClass: function(value, flag) {
  3440. var className,
  3441. hasClass,
  3442. rnotwhite = /\S+/g,
  3443. classNames = value.match(rnotwhite) || [],
  3444. i = 0,
  3445. wasAdded = false,
  3446. statusElem = this[this.tree.statusClassPropName],
  3447. curClasses = " " + (this.extraClasses || "") + " ";
  3448. // this.info("toggleClass('" + value + "', " + flag + ")", curClasses);
  3449. // Modify DOM element directly if it already exists
  3450. if (statusElem) {
  3451. $(statusElem).toggleClass(value, flag);
  3452. }
  3453. // Modify node.extraClasses to make this change persistent
  3454. // Toggle if flag was not passed
  3455. while ((className = classNames[i++])) {
  3456. hasClass = curClasses.indexOf(" " + className + " ") >= 0;
  3457. flag = flag === undefined ? !hasClass : !!flag;
  3458. if (flag) {
  3459. if (!hasClass) {
  3460. curClasses += className + " ";
  3461. wasAdded = true;
  3462. }
  3463. } else {
  3464. while (curClasses.indexOf(" " + className + " ") > -1) {
  3465. curClasses = curClasses.replace(
  3466. " " + className + " ",
  3467. " "
  3468. );
  3469. }
  3470. }
  3471. }
  3472. this.extraClasses = $.trim(curClasses);
  3473. // this.info("-> toggleClass('" + value + "', " + flag + "): '" + this.extraClasses + "'");
  3474. return wasAdded;
  3475. },
  3476. /** Flip expanded status. */
  3477. toggleExpanded: function() {
  3478. return this.tree._callHook("nodeToggleExpanded", this);
  3479. },
  3480. /** Flip selection status. */
  3481. toggleSelected: function() {
  3482. return this.tree._callHook("nodeToggleSelected", this);
  3483. },
  3484. toString: function() {
  3485. return "FancytreeNode@" + this.key + "[title='" + this.title + "']";
  3486. // return "<FancytreeNode(#" + this.key + ", '" + this.title + "')>";
  3487. },
  3488. /**
  3489. * Trigger `modifyChild` event on a parent to signal that a child was modified.
  3490. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  3491. * @param {FancytreeNode} [childNode]
  3492. * @param {object} [extra]
  3493. */
  3494. triggerModifyChild: function(operation, childNode, extra) {
  3495. var data,
  3496. modifyChild = this.tree.options.modifyChild;
  3497. if (modifyChild) {
  3498. if (childNode && childNode.parent !== this) {
  3499. $.error(
  3500. "childNode " + childNode + " is not a child of " + this
  3501. );
  3502. }
  3503. data = {
  3504. node: this,
  3505. tree: this.tree,
  3506. operation: operation,
  3507. childNode: childNode || null,
  3508. };
  3509. if (extra) {
  3510. $.extend(data, extra);
  3511. }
  3512. modifyChild({ type: "modifyChild" }, data);
  3513. }
  3514. },
  3515. /**
  3516. * Trigger `modifyChild` event on node.parent(!).
  3517. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  3518. * @param {object} [extra]
  3519. */
  3520. triggerModify: function(operation, extra) {
  3521. this.parent.triggerModifyChild(operation, this, extra);
  3522. },
  3523. /** Call fn(node) for all child nodes in hierarchical order (depth-first).<br>
  3524. * Stop iteration, if fn() returns false. Skip current branch, if fn() returns "skip".<br>
  3525. * Return false if iteration was stopped.
  3526. *
  3527. * @param {function} fn the callback function.
  3528. * Return false to stop iteration, return "skip" to skip this node and
  3529. * its children only.
  3530. * @param {boolean} [includeSelf=false]
  3531. * @returns {boolean}
  3532. */
  3533. visit: function(fn, includeSelf) {
  3534. var i,
  3535. l,
  3536. res = true,
  3537. children = this.children;
  3538. if (includeSelf === true) {
  3539. res = fn(this);
  3540. if (res === false || res === "skip") {
  3541. return res;
  3542. }
  3543. }
  3544. if (children) {
  3545. for (i = 0, l = children.length; i < l; i++) {
  3546. res = children[i].visit(fn, true);
  3547. if (res === false) {
  3548. break;
  3549. }
  3550. }
  3551. }
  3552. return res;
  3553. },
  3554. /** Call fn(node) for all child nodes and recursively load lazy children.<br>
  3555. * <b>Note:</b> If you need this method, you probably should consider to review
  3556. * your architecture! Recursivley loading nodes is a perfect way for lazy
  3557. * programmers to flood the server with requests ;-)
  3558. *
  3559. * @param {function} [fn] optional callback function.
  3560. * Return false to stop iteration, return "skip" to skip this node and
  3561. * its children only.
  3562. * @param {boolean} [includeSelf=false]
  3563. * @returns {$.Promise}
  3564. * @since 2.4
  3565. */
  3566. visitAndLoad: function(fn, includeSelf, _recursion) {
  3567. var dfd,
  3568. res,
  3569. loaders,
  3570. node = this;
  3571. // node.debug("visitAndLoad");
  3572. if (fn && includeSelf === true) {
  3573. res = fn(node);
  3574. if (res === false || res === "skip") {
  3575. return _recursion ? res : _getResolvedPromise();
  3576. }
  3577. }
  3578. if (!node.children && !node.lazy) {
  3579. return _getResolvedPromise();
  3580. }
  3581. dfd = new $.Deferred();
  3582. loaders = [];
  3583. // node.debug("load()...");
  3584. node.load().done(function() {
  3585. // node.debug("load()... done.");
  3586. for (var i = 0, l = node.children.length; i < l; i++) {
  3587. res = node.children[i].visitAndLoad(fn, true, true);
  3588. if (res === false) {
  3589. dfd.reject();
  3590. break;
  3591. } else if (res !== "skip") {
  3592. loaders.push(res); // Add promise to the list
  3593. }
  3594. }
  3595. $.when.apply(this, loaders).then(function() {
  3596. dfd.resolve();
  3597. });
  3598. });
  3599. return dfd.promise();
  3600. },
  3601. /** Call fn(node) for all parent nodes, bottom-up, including invisible system root.<br>
  3602. * Stop iteration, if fn() returns false.<br>
  3603. * Return false if iteration was stopped.
  3604. *
  3605. * @param {function} fn the callback function.
  3606. * Return false to stop iteration, return "skip" to skip this node and children only.
  3607. * @param {boolean} [includeSelf=false]
  3608. * @returns {boolean}
  3609. */
  3610. visitParents: function(fn, includeSelf) {
  3611. // Visit parent nodes (bottom up)
  3612. if (includeSelf && fn(this) === false) {
  3613. return false;
  3614. }
  3615. var p = this.parent;
  3616. while (p) {
  3617. if (fn(p) === false) {
  3618. return false;
  3619. }
  3620. p = p.parent;
  3621. }
  3622. return true;
  3623. },
  3624. /** Call fn(node) for all sibling nodes.<br>
  3625. * Stop iteration, if fn() returns false.<br>
  3626. * Return false if iteration was stopped.
  3627. *
  3628. * @param {function} fn the callback function.
  3629. * Return false to stop iteration.
  3630. * @param {boolean} [includeSelf=false]
  3631. * @returns {boolean}
  3632. */
  3633. visitSiblings: function(fn, includeSelf) {
  3634. var i,
  3635. l,
  3636. n,
  3637. ac = this.parent.children;
  3638. for (i = 0, l = ac.length; i < l; i++) {
  3639. n = ac[i];
  3640. if (includeSelf || n !== this) {
  3641. if (fn(n) === false) {
  3642. return false;
  3643. }
  3644. }
  3645. }
  3646. return true;
  3647. },
  3648. /** Write warning to browser console if debugLevel >= 2 (prepending node info)
  3649. *
  3650. * @param {*} msg string or object or array of such
  3651. */
  3652. warn: function(msg) {
  3653. if (this.tree.options.debugLevel >= 2) {
  3654. Array.prototype.unshift.call(arguments, this.toString());
  3655. consoleApply("warn", arguments);
  3656. }
  3657. },
  3658. };
  3659. /******************************************************************************
  3660. * Fancytree
  3661. */
  3662. /**
  3663. * Construct a new tree object.
  3664. *
  3665. * @class Fancytree
  3666. * @classdesc The controller behind a fancytree.
  3667. * This class also contains 'hook methods': see {@link Fancytree_Hooks}.
  3668. *
  3669. * @param {Widget} widget
  3670. *
  3671. * @property {string} _id Automatically generated unique tree instance ID, e.g. "1".
  3672. * @property {string} _ns Automatically generated unique tree namespace, e.g. ".fancytree-1".
  3673. * @property {FancytreeNode} activeNode Currently active node or null.
  3674. * @property {string} ariaPropName Property name of FancytreeNode that contains the element which will receive the aria attributes.
  3675. * Typically "li", but "tr" for table extension.
  3676. * @property {jQueryObject} $container Outer `<ul>` element (or `<table>` element for ext-table).
  3677. * @property {jQueryObject} $div A jQuery object containing the element used to instantiate the tree widget (`widget.element`)
  3678. * @property {object|array} columns Recommended place to store shared column meta data. @since 2.27
  3679. * @property {object} data Metadata, i.e. properties that may be passed to `source` in addition to a children array.
  3680. * @property {object} ext Hash of all active plugin instances.
  3681. * @property {FancytreeNode} focusNode Currently focused node or null.
  3682. * @property {FancytreeNode} lastSelectedNode Used to implement selectMode 1 (single select)
  3683. * @property {string} nodeContainerAttrName Property name of FancytreeNode that contains the outer element of single nodes.
  3684. * Typically "li", but "tr" for table extension.
  3685. * @property {FancytreeOptions} options Current options, i.e. default options + options passed to constructor.
  3686. * @property {FancytreeNode} rootNode Invisible system root node.
  3687. * @property {string} statusClassPropName Property name of FancytreeNode that contains the element which will receive the status classes.
  3688. * Typically "span", but "tr" for table extension.
  3689. * @property {object} types Map for shared type specific meta data, used with node.type attribute. @since 2.27
  3690. * @property {object} viewport See ext-vieport. @since v2.31
  3691. * @property {object} widget Base widget instance.
  3692. */
  3693. function Fancytree(widget) {
  3694. this.widget = widget;
  3695. this.$div = widget.element;
  3696. this.options = widget.options;
  3697. if (this.options) {
  3698. if (this.options.lazyload !== undefined) {
  3699. $.error(
  3700. "The 'lazyload' event is deprecated since 2014-02-25. Use 'lazyLoad' (with uppercase L) instead."
  3701. );
  3702. }
  3703. if (this.options.loaderror !== undefined) {
  3704. $.error(
  3705. "The 'loaderror' event was renamed since 2014-07-03. Use 'loadError' (with uppercase E) instead."
  3706. );
  3707. }
  3708. if (this.options.fx !== undefined) {
  3709. $.error(
  3710. "The 'fx' option was replaced by 'toggleEffect' since 2014-11-30."
  3711. );
  3712. }
  3713. if (this.options.removeNode !== undefined) {
  3714. $.error(
  3715. "The 'removeNode' event was replaced by 'modifyChild' since 2.20 (2016-09-10)."
  3716. );
  3717. }
  3718. }
  3719. this.ext = {}; // Active extension instances
  3720. this.types = {};
  3721. this.columns = {};
  3722. // allow to init tree.data.foo from <div data-foo=''>
  3723. this.data = _getElementDataAsDict(this.$div);
  3724. // TODO: use widget.uuid instead?
  3725. this._id = "" + (this.options.treeId || $.ui.fancytree._nextId++);
  3726. // TODO: use widget.eventNamespace instead?
  3727. this._ns = ".fancytree-" + this._id; // append for namespaced events
  3728. this.activeNode = null;
  3729. this.focusNode = null;
  3730. this._hasFocus = null;
  3731. this._tempCache = {};
  3732. this._lastMousedownNode = null;
  3733. this._enableUpdate = true;
  3734. this.lastSelectedNode = null;
  3735. this.systemFocusElement = null;
  3736. this.lastQuicksearchTerm = "";
  3737. this.lastQuicksearchTime = 0;
  3738. this.viewport = null; // ext-grid
  3739. this.statusClassPropName = "span";
  3740. this.ariaPropName = "li";
  3741. this.nodeContainerAttrName = "li";
  3742. // Remove previous markup if any
  3743. this.$div.find(">ul.fancytree-container").remove();
  3744. // Create a node without parent.
  3745. var fakeParent = { tree: this },
  3746. $ul;
  3747. this.rootNode = new FancytreeNode(fakeParent, {
  3748. title: "root",
  3749. key: "root_" + this._id,
  3750. children: null,
  3751. expanded: true,
  3752. });
  3753. this.rootNode.parent = null;
  3754. // Create root markup
  3755. $ul = $("<ul>", {
  3756. id: "ft-id-" + this._id,
  3757. class: "ui-fancytree fancytree-container fancytree-plain",
  3758. }).appendTo(this.$div);
  3759. this.$container = $ul;
  3760. this.rootNode.ul = $ul[0];
  3761. if (this.options.debugLevel == null) {
  3762. this.options.debugLevel = FT.debugLevel;
  3763. }
  3764. // // Add container to the TAB chain
  3765. // // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  3766. // // #577: Allow to set tabindex to "0", "-1" and ""
  3767. // this.$container.attr("tabindex", this.options.tabindex);
  3768. // if( this.options.rtl ) {
  3769. // this.$container.attr("DIR", "RTL").addClass("fancytree-rtl");
  3770. // // }else{
  3771. // // this.$container.attr("DIR", null).removeClass("fancytree-rtl");
  3772. // }
  3773. // if(this.options.aria){
  3774. // this.$container.attr("role", "tree");
  3775. // if( this.options.selectMode !== 1 ) {
  3776. // this.$container.attr("aria-multiselectable", true);
  3777. // }
  3778. // }
  3779. }
  3780. Fancytree.prototype = /** @lends Fancytree# */ {
  3781. /* Return a context object that can be re-used for _callHook().
  3782. * @param {Fancytree | FancytreeNode | EventData} obj
  3783. * @param {Event} originalEvent
  3784. * @param {Object} extra
  3785. * @returns {EventData}
  3786. */
  3787. _makeHookContext: function(obj, originalEvent, extra) {
  3788. var ctx, tree;
  3789. if (obj.node !== undefined) {
  3790. // obj is already a context object
  3791. if (originalEvent && obj.originalEvent !== originalEvent) {
  3792. $.error("invalid args");
  3793. }
  3794. ctx = obj;
  3795. } else if (obj.tree) {
  3796. // obj is a FancytreeNode
  3797. tree = obj.tree;
  3798. ctx = {
  3799. node: obj,
  3800. tree: tree,
  3801. widget: tree.widget,
  3802. options: tree.widget.options,
  3803. originalEvent: originalEvent,
  3804. typeInfo: tree.types[obj.type] || {},
  3805. };
  3806. } else if (obj.widget) {
  3807. // obj is a Fancytree
  3808. ctx = {
  3809. node: null,
  3810. tree: obj,
  3811. widget: obj.widget,
  3812. options: obj.widget.options,
  3813. originalEvent: originalEvent,
  3814. };
  3815. } else {
  3816. $.error("invalid args");
  3817. }
  3818. if (extra) {
  3819. $.extend(ctx, extra);
  3820. }
  3821. return ctx;
  3822. },
  3823. /* Trigger a hook function: funcName(ctx, [...]).
  3824. *
  3825. * @param {string} funcName
  3826. * @param {Fancytree|FancytreeNode|EventData} contextObject
  3827. * @param {any} [_extraArgs] optional additional arguments
  3828. * @returns {any}
  3829. */
  3830. _callHook: function(funcName, contextObject, _extraArgs) {
  3831. var ctx = this._makeHookContext(contextObject),
  3832. fn = this[funcName],
  3833. args = Array.prototype.slice.call(arguments, 2);
  3834. if (!$.isFunction(fn)) {
  3835. $.error("_callHook('" + funcName + "') is not a function");
  3836. }
  3837. args.unshift(ctx);
  3838. // this.debug("_hook", funcName, ctx.node && ctx.node.toString() || ctx.tree.toString(), args);
  3839. return fn.apply(this, args);
  3840. },
  3841. _setExpiringValue: function(key, value, ms) {
  3842. this._tempCache[key] = {
  3843. value: value,
  3844. expire: Date.now() + (+ms || 50),
  3845. };
  3846. },
  3847. _getExpiringValue: function(key) {
  3848. var entry = this._tempCache[key];
  3849. if (entry && entry.expire > Date.now()) {
  3850. return entry.value;
  3851. }
  3852. delete this._tempCache[key];
  3853. return null;
  3854. },
  3855. /* Check if this tree has extension `name` enabled.
  3856. *
  3857. * @param {string} name name of the required extension
  3858. */
  3859. _usesExtension: function(name) {
  3860. return $.inArray(name, this.options.extensions) >= 0;
  3861. },
  3862. /* Check if current extensions dependencies are met and throw an error if not.
  3863. *
  3864. * This method may be called inside the `treeInit` hook for custom extensions.
  3865. *
  3866. * @param {string} name name of the required extension
  3867. * @param {boolean} [required=true] pass `false` if the extension is optional, but we want to check for order if it is present
  3868. * @param {boolean} [before] `true` if `name` must be included before this, `false` otherwise (use `null` if order doesn't matter)
  3869. * @param {string} [message] optional error message (defaults to a descriptve error message)
  3870. */
  3871. _requireExtension: function(name, required, before, message) {
  3872. if (before != null) {
  3873. before = !!before;
  3874. }
  3875. var thisName = this._local.name,
  3876. extList = this.options.extensions,
  3877. isBefore =
  3878. $.inArray(name, extList) < $.inArray(thisName, extList),
  3879. isMissing = required && this.ext[name] == null,
  3880. badOrder = !isMissing && before != null && before !== isBefore;
  3881. _assert(
  3882. thisName && thisName !== name,
  3883. "invalid or same name '" + thisName + "' (require yourself?)"
  3884. );
  3885. if (isMissing || badOrder) {
  3886. if (!message) {
  3887. if (isMissing || required) {
  3888. message =
  3889. "'" +
  3890. thisName +
  3891. "' extension requires '" +
  3892. name +
  3893. "'";
  3894. if (badOrder) {
  3895. message +=
  3896. " to be registered " +
  3897. (before ? "before" : "after") +
  3898. " itself";
  3899. }
  3900. } else {
  3901. message =
  3902. "If used together, `" +
  3903. name +
  3904. "` must be registered " +
  3905. (before ? "before" : "after") +
  3906. " `" +
  3907. thisName +
  3908. "`";
  3909. }
  3910. }
  3911. $.error(message);
  3912. return false;
  3913. }
  3914. return true;
  3915. },
  3916. /** Activate node with a given key and fire focus and activate events.
  3917. *
  3918. * A previously activated node will be deactivated.
  3919. * If activeVisible option is set, all parents will be expanded as necessary.
  3920. * Pass key = false, to deactivate the current node only.
  3921. * @param {string} key
  3922. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  3923. * @returns {FancytreeNode} activated node (null, if not found)
  3924. */
  3925. activateKey: function(key, opts) {
  3926. var node = this.getNodeByKey(key);
  3927. if (node) {
  3928. node.setActive(true, opts);
  3929. } else if (this.activeNode) {
  3930. this.activeNode.setActive(false, opts);
  3931. }
  3932. return node;
  3933. },
  3934. /** (experimental) Add child status nodes that indicate 'More...', ....
  3935. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  3936. * @param {string} [mode='append'] 'child'|firstChild'
  3937. * @since 2.15
  3938. */
  3939. addPagingNode: function(node, mode) {
  3940. return this.rootNode.addPagingNode(node, mode);
  3941. },
  3942. /**
  3943. * (experimental) Apply a modification (or navigation) operation.
  3944. *
  3945. * Valid commands:
  3946. * - 'moveUp', 'moveDown'
  3947. * - 'indent', 'outdent'
  3948. * - 'remove'
  3949. * - 'edit', 'addChild', 'addSibling': (reqires ext-edit extension)
  3950. * - 'cut', 'copy', 'paste': (use an internal singleton 'clipboard')
  3951. * - 'down', 'first', 'last', 'left', 'parent', 'right', 'up': navigate
  3952. *
  3953. * @param {string} cmd
  3954. * @param {FancytreeNode} [node=active_node]
  3955. * @param {object} [opts] Currently unused
  3956. *
  3957. * @since 2.32
  3958. */
  3959. applyCommand: function(cmd, node, opts_) {
  3960. var // clipboard,
  3961. refNode;
  3962. // opts = $.extend(
  3963. // { setActive: true, clipboard: CLIPBOARD },
  3964. // opts_
  3965. // );
  3966. node = node || this.getActiveNode();
  3967. // clipboard = opts.clipboard;
  3968. switch (cmd) {
  3969. // Sorting and indentation:
  3970. case "moveUp":
  3971. refNode = node.getPrevSibling();
  3972. if (refNode) {
  3973. node.moveTo(refNode, "before");
  3974. node.setActive();
  3975. }
  3976. break;
  3977. case "moveDown":
  3978. refNode = node.getNextSibling();
  3979. if (refNode) {
  3980. node.moveTo(refNode, "after");
  3981. node.setActive();
  3982. }
  3983. break;
  3984. case "indent":
  3985. refNode = node.getPrevSibling();
  3986. if (refNode) {
  3987. node.moveTo(refNode, "child");
  3988. refNode.setExpanded();
  3989. node.setActive();
  3990. }
  3991. break;
  3992. case "outdent":
  3993. if (!node.isTopLevel()) {
  3994. node.moveTo(node.getParent(), "after");
  3995. node.setActive();
  3996. }
  3997. break;
  3998. // Remove:
  3999. case "remove":
  4000. refNode = node.getPrevSibling() || node.getParent();
  4001. node.remove();
  4002. if (refNode) {
  4003. refNode.setActive();
  4004. }
  4005. break;
  4006. // Add, edit (requires ext-edit):
  4007. case "addChild":
  4008. node.editCreateNode("child", "");
  4009. break;
  4010. case "addSibling":
  4011. node.editCreateNode("after", "");
  4012. break;
  4013. case "rename":
  4014. node.editStart();
  4015. break;
  4016. // Simple clipboard simulation:
  4017. // case "cut":
  4018. // clipboard = { mode: cmd, data: node };
  4019. // break;
  4020. // case "copy":
  4021. // clipboard = {
  4022. // mode: cmd,
  4023. // data: node.toDict(function(d, n) {
  4024. // delete d.key;
  4025. // }),
  4026. // };
  4027. // break;
  4028. // case "clear":
  4029. // clipboard = null;
  4030. // break;
  4031. // case "paste":
  4032. // if (clipboard.mode === "cut") {
  4033. // // refNode = node.getPrevSibling();
  4034. // clipboard.data.moveTo(node, "child");
  4035. // clipboard.data.setActive();
  4036. // } else if (clipboard.mode === "copy") {
  4037. // node.addChildren(clipboard.data).setActive();
  4038. // }
  4039. // break;
  4040. // Navigation commands:
  4041. case "down":
  4042. case "first":
  4043. case "last":
  4044. case "left":
  4045. case "parent":
  4046. case "right":
  4047. case "up":
  4048. return node.navigate(cmd);
  4049. default:
  4050. $.error("Unhandled command: '" + cmd + "'");
  4051. }
  4052. },
  4053. /** (experimental) Modify existing data model.
  4054. *
  4055. * @param {Array} patchList array of [key, NodePatch] arrays
  4056. * @returns {$.Promise} resolved, when all patches have been applied
  4057. * @see TreePatch
  4058. */
  4059. applyPatch: function(patchList) {
  4060. var dfd,
  4061. i,
  4062. p2,
  4063. key,
  4064. patch,
  4065. node,
  4066. patchCount = patchList.length,
  4067. deferredList = [];
  4068. for (i = 0; i < patchCount; i++) {
  4069. p2 = patchList[i];
  4070. _assert(
  4071. p2.length === 2,
  4072. "patchList must be an array of length-2-arrays"
  4073. );
  4074. key = p2[0];
  4075. patch = p2[1];
  4076. node = key === null ? this.rootNode : this.getNodeByKey(key);
  4077. if (node) {
  4078. dfd = new $.Deferred();
  4079. deferredList.push(dfd);
  4080. node.applyPatch(patch).always(_makeResolveFunc(dfd, node));
  4081. } else {
  4082. this.warn("could not find node with key '" + key + "'");
  4083. }
  4084. }
  4085. // Return a promise that is resolved, when ALL patches were applied
  4086. return $.when.apply($, deferredList).promise();
  4087. },
  4088. /* TODO: implement in dnd extension
  4089. cancelDrag: function() {
  4090. var dd = $.ui.ddmanager.current;
  4091. if(dd){
  4092. dd.cancel();
  4093. }
  4094. },
  4095. */
  4096. /** Remove all nodes.
  4097. * @since 2.14
  4098. */
  4099. clear: function(source) {
  4100. this._callHook("treeClear", this);
  4101. },
  4102. /** Return the number of nodes.
  4103. * @returns {integer}
  4104. */
  4105. count: function() {
  4106. return this.rootNode.countChildren();
  4107. },
  4108. /** Write to browser console if debugLevel >= 4 (prepending tree name)
  4109. *
  4110. * @param {*} msg string or object or array of such
  4111. */
  4112. debug: function(msg) {
  4113. if (this.options.debugLevel >= 4) {
  4114. Array.prototype.unshift.call(arguments, this.toString());
  4115. consoleApply("log", arguments);
  4116. }
  4117. },
  4118. /** Destroy this widget, restore previous markup and cleanup resources.
  4119. *
  4120. * @since 2.34
  4121. */
  4122. destroy: function() {
  4123. this.widget.destroy();
  4124. },
  4125. /** Enable (or disable) the tree control.
  4126. *
  4127. * @param {boolean} [flag=true] pass false to disable
  4128. * @since 2.30
  4129. */
  4130. enable: function(flag) {
  4131. if (flag === false) {
  4132. this.widget.disable();
  4133. } else {
  4134. this.widget.enable();
  4135. }
  4136. },
  4137. /** Temporarily suppress rendering to improve performance on bulk-updates.
  4138. *
  4139. * @param {boolean} flag
  4140. * @returns {boolean} previous status
  4141. * @since 2.19
  4142. */
  4143. enableUpdate: function(flag) {
  4144. flag = flag !== false;
  4145. if (!!this._enableUpdate === !!flag) {
  4146. return flag;
  4147. }
  4148. this._enableUpdate = flag;
  4149. if (flag) {
  4150. this.debug("enableUpdate(true): redraw "); //, this._dirtyRoots);
  4151. this._callHook("treeStructureChanged", this, "enableUpdate");
  4152. this.render();
  4153. } else {
  4154. // this._dirtyRoots = null;
  4155. this.debug("enableUpdate(false)...");
  4156. }
  4157. return !flag; // return previous value
  4158. },
  4159. /** Write error to browser console if debugLevel >= 1 (prepending tree info)
  4160. *
  4161. * @param {*} msg string or object or array of such
  4162. */
  4163. error: function(msg) {
  4164. if (this.options.debugLevel >= 1) {
  4165. Array.prototype.unshift.call(arguments, this.toString());
  4166. consoleApply("error", arguments);
  4167. }
  4168. },
  4169. /** Expand (or collapse) all parent nodes.
  4170. *
  4171. * This convenience method uses `tree.visit()` and `tree.setExpanded()`
  4172. * internally.
  4173. *
  4174. * @param {boolean} [flag=true] pass false to collapse
  4175. * @param {object} [opts] passed to setExpanded()
  4176. * @since 2.30
  4177. */
  4178. expandAll: function(flag, opts) {
  4179. var prev = this.enableUpdate(false);
  4180. flag = flag !== false;
  4181. this.visit(function(node) {
  4182. if (
  4183. node.hasChildren() !== false &&
  4184. node.isExpanded() !== flag
  4185. ) {
  4186. node.setExpanded(flag, opts);
  4187. }
  4188. });
  4189. this.enableUpdate(prev);
  4190. },
  4191. /**Find all nodes that matches condition.
  4192. *
  4193. * @param {string | function(node)} match title string to search for, or a
  4194. * callback function that returns `true` if a node is matched.
  4195. * @returns {FancytreeNode[]} array of nodes (may be empty)
  4196. * @see FancytreeNode#findAll
  4197. * @since 2.12
  4198. */
  4199. findAll: function(match) {
  4200. return this.rootNode.findAll(match);
  4201. },
  4202. /**Find first node that matches condition.
  4203. *
  4204. * @param {string | function(node)} match title string to search for, or a
  4205. * callback function that returns `true` if a node is matched.
  4206. * @returns {FancytreeNode} matching node or null
  4207. * @see FancytreeNode#findFirst
  4208. * @since 2.12
  4209. */
  4210. findFirst: function(match) {
  4211. return this.rootNode.findFirst(match);
  4212. },
  4213. /** Find the next visible node that starts with `match`, starting at `startNode`
  4214. * and wrap-around at the end.
  4215. *
  4216. * @param {string|function} match
  4217. * @param {FancytreeNode} [startNode] defaults to first node
  4218. * @returns {FancytreeNode} matching node or null
  4219. */
  4220. findNextNode: function(match, startNode) {
  4221. //, visibleOnly) {
  4222. var res = null,
  4223. firstNode = this.getFirstChild();
  4224. match =
  4225. typeof match === "string"
  4226. ? _makeNodeTitleStartMatcher(match)
  4227. : match;
  4228. startNode = startNode || firstNode;
  4229. function _checkNode(n) {
  4230. // console.log("_check " + n)
  4231. if (match(n)) {
  4232. res = n;
  4233. }
  4234. if (res || n === startNode) {
  4235. return false;
  4236. }
  4237. }
  4238. this.visitRows(_checkNode, {
  4239. start: startNode,
  4240. includeSelf: false,
  4241. });
  4242. // Wrap around search
  4243. if (!res && startNode !== firstNode) {
  4244. this.visitRows(_checkNode, {
  4245. start: firstNode,
  4246. includeSelf: true,
  4247. });
  4248. }
  4249. return res;
  4250. },
  4251. /** Find a node relative to another node.
  4252. *
  4253. * @param {FancytreeNode} node
  4254. * @param {string|number} where 'down', 'first', 'last', 'left', 'parent', 'right', or 'up'.
  4255. * (Alternatively the keyCode that would normally trigger this move,
  4256. * e.g. `$.ui.keyCode.LEFT` = 'left'.
  4257. * @param {boolean} [includeHidden=false] Not yet implemented
  4258. * @returns {FancytreeNode|null}
  4259. * @since v2.31
  4260. */
  4261. findRelatedNode: function(node, where, includeHidden) {
  4262. var res = null,
  4263. KC = $.ui.keyCode;
  4264. switch (where) {
  4265. case "parent":
  4266. case KC.BACKSPACE:
  4267. if (node.parent && node.parent.parent) {
  4268. res = node.parent;
  4269. }
  4270. break;
  4271. case "first":
  4272. case KC.HOME:
  4273. // First visible node
  4274. this.visit(function(n) {
  4275. if (n.isVisible()) {
  4276. res = n;
  4277. return false;
  4278. }
  4279. });
  4280. break;
  4281. case "last":
  4282. case KC.END:
  4283. this.visit(function(n) {
  4284. // last visible node
  4285. if (n.isVisible()) {
  4286. res = n;
  4287. }
  4288. });
  4289. break;
  4290. case "left":
  4291. case KC.LEFT:
  4292. if (node.expanded) {
  4293. node.setExpanded(false);
  4294. } else if (node.parent && node.parent.parent) {
  4295. res = node.parent;
  4296. }
  4297. break;
  4298. case "right":
  4299. case KC.RIGHT:
  4300. if (!node.expanded && (node.children || node.lazy)) {
  4301. node.setExpanded();
  4302. res = node;
  4303. } else if (node.children && node.children.length) {
  4304. res = node.children[0];
  4305. }
  4306. break;
  4307. case "up":
  4308. case KC.UP:
  4309. this.visitRows(
  4310. function(n) {
  4311. res = n;
  4312. return false;
  4313. },
  4314. { start: node, reverse: true, includeSelf: false }
  4315. );
  4316. break;
  4317. case "down":
  4318. case KC.DOWN:
  4319. this.visitRows(
  4320. function(n) {
  4321. res = n;
  4322. return false;
  4323. },
  4324. { start: node, includeSelf: false }
  4325. );
  4326. break;
  4327. default:
  4328. this.tree.warn("Unknown relation '" + where + "'.");
  4329. }
  4330. return res;
  4331. },
  4332. // TODO: fromDict
  4333. /**
  4334. * Generate INPUT elements that can be submitted with html forms.
  4335. *
  4336. * In selectMode 3 only the topmost selected nodes are considered, unless
  4337. * `opts.stopOnParents: false` is passed.
  4338. *
  4339. * @example
  4340. * // Generate input elements for active and selected nodes
  4341. * tree.generateFormElements();
  4342. * // Generate input elements selected nodes, using a custom `name` attribute
  4343. * tree.generateFormElements("cust_sel", false);
  4344. * // Generate input elements using a custom filter
  4345. * tree.generateFormElements(true, true, { filter: function(node) {
  4346. * return node.isSelected() && node.data.yes;
  4347. * }});
  4348. *
  4349. * @param {boolean | string} [selected=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID[]')
  4350. * @param {boolean | string} [active=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID_active')
  4351. * @param {object} [opts] default { filter: null, stopOnParents: true }
  4352. */
  4353. generateFormElements: function(selected, active, opts) {
  4354. opts = opts || {};
  4355. var nodeList,
  4356. selectedName =
  4357. typeof selected === "string"
  4358. ? selected
  4359. : "ft_" + this._id + "[]",
  4360. activeName =
  4361. typeof active === "string"
  4362. ? active
  4363. : "ft_" + this._id + "_active",
  4364. id = "fancytree_result_" + this._id,
  4365. $result = $("#" + id),
  4366. stopOnParents =
  4367. this.options.selectMode === 3 &&
  4368. opts.stopOnParents !== false;
  4369. if ($result.length) {
  4370. $result.empty();
  4371. } else {
  4372. $result = $("<div>", {
  4373. id: id,
  4374. })
  4375. .hide()
  4376. .insertAfter(this.$container);
  4377. }
  4378. if (active !== false && this.activeNode) {
  4379. $result.append(
  4380. $("<input>", {
  4381. type: "radio",
  4382. name: activeName,
  4383. value: this.activeNode.key,
  4384. checked: true,
  4385. })
  4386. );
  4387. }
  4388. function _appender(node) {
  4389. $result.append(
  4390. $("<input>", {
  4391. type: "checkbox",
  4392. name: selectedName,
  4393. value: node.key,
  4394. checked: true,
  4395. })
  4396. );
  4397. }
  4398. if (opts.filter) {
  4399. this.visit(function(node) {
  4400. var res = opts.filter(node);
  4401. if (res === "skip") {
  4402. return res;
  4403. }
  4404. if (res !== false) {
  4405. _appender(node);
  4406. }
  4407. });
  4408. } else if (selected !== false) {
  4409. nodeList = this.getSelectedNodes(stopOnParents);
  4410. $.each(nodeList, function(idx, node) {
  4411. _appender(node);
  4412. });
  4413. }
  4414. },
  4415. /**
  4416. * Return the currently active node or null.
  4417. * @returns {FancytreeNode}
  4418. */
  4419. getActiveNode: function() {
  4420. return this.activeNode;
  4421. },
  4422. /** Return the first top level node if any (not the invisible root node).
  4423. * @returns {FancytreeNode | null}
  4424. */
  4425. getFirstChild: function() {
  4426. return this.rootNode.getFirstChild();
  4427. },
  4428. /**
  4429. * Return node that has keyboard focus or null.
  4430. * @returns {FancytreeNode}
  4431. */
  4432. getFocusNode: function() {
  4433. return this.focusNode;
  4434. },
  4435. /**
  4436. * Return current option value.
  4437. * (Note: this is the preferred variant of `$().fancytree("option", "KEY")`)
  4438. *
  4439. * @param {string} name option name (may contain '.')
  4440. * @returns {any}
  4441. */
  4442. getOption: function(optionName) {
  4443. return this.widget.option(optionName);
  4444. },
  4445. /**
  4446. * Return node with a given key or null if not found.
  4447. *
  4448. * @param {string} key
  4449. * @param {FancytreeNode} [searchRoot] only search below this node
  4450. * @returns {FancytreeNode | null}
  4451. */
  4452. getNodeByKey: function(key, searchRoot) {
  4453. // Search the DOM by element ID (assuming this is faster than traversing all nodes).
  4454. var el, match;
  4455. // TODO: use tree.keyMap if available
  4456. // TODO: check opts.generateIds === true
  4457. if (!searchRoot) {
  4458. el = document.getElementById(this.options.idPrefix + key);
  4459. if (el) {
  4460. return el.ftnode ? el.ftnode : null;
  4461. }
  4462. }
  4463. // Not found in the DOM, but still may be in an unrendered part of tree
  4464. searchRoot = searchRoot || this.rootNode;
  4465. match = null;
  4466. key = "" + key; // Convert to string (#1005)
  4467. searchRoot.visit(function(node) {
  4468. if (node.key === key) {
  4469. match = node;
  4470. return false; // Stop iteration
  4471. }
  4472. }, true);
  4473. return match;
  4474. },
  4475. /** Return the invisible system root node.
  4476. * @returns {FancytreeNode}
  4477. */
  4478. getRootNode: function() {
  4479. return this.rootNode;
  4480. },
  4481. /**
  4482. * Return an array of selected nodes.
  4483. *
  4484. * Note: you cannot send this result via Ajax directly. Instead the
  4485. * node object need to be converted to plain objects, for example
  4486. * by using `$.map()` and `node.toDict()`.
  4487. * @param {boolean} [stopOnParents=false] only return the topmost selected
  4488. * node (useful with selectMode 3)
  4489. * @returns {FancytreeNode[]}
  4490. */
  4491. getSelectedNodes: function(stopOnParents) {
  4492. return this.rootNode.getSelectedNodes(stopOnParents);
  4493. },
  4494. /** Return true if the tree control has keyboard focus
  4495. * @returns {boolean}
  4496. */
  4497. hasFocus: function() {
  4498. // var ae = document.activeElement,
  4499. // hasFocus = !!(
  4500. // ae && $(ae).closest(".fancytree-container").length
  4501. // );
  4502. // if (hasFocus !== !!this._hasFocus) {
  4503. // this.warn(
  4504. // "hasFocus(): fix inconsistent container state, now: " +
  4505. // hasFocus
  4506. // );
  4507. // this._hasFocus = hasFocus;
  4508. // this.$container.toggleClass("fancytree-treefocus", hasFocus);
  4509. // }
  4510. // return hasFocus;
  4511. return !!this._hasFocus;
  4512. },
  4513. /** Write to browser console if debugLevel >= 3 (prepending tree name)
  4514. * @param {*} msg string or object or array of such
  4515. */
  4516. info: function(msg) {
  4517. if (this.options.debugLevel >= 3) {
  4518. Array.prototype.unshift.call(arguments, this.toString());
  4519. consoleApply("info", arguments);
  4520. }
  4521. },
  4522. /** Return true if any node is currently beeing loaded, i.e. a Ajax request is pending.
  4523. * @returns {boolean}
  4524. * @since 2.32
  4525. */
  4526. isLoading: function() {
  4527. var res = false;
  4528. this.rootNode.visit(function(n) {
  4529. // also visit rootNode
  4530. if (n._isLoading || n._requestId) {
  4531. res = true;
  4532. return false;
  4533. }
  4534. }, true);
  4535. return res;
  4536. },
  4537. /*
  4538. TODO: isInitializing: function() {
  4539. return ( this.phase=="init" || this.phase=="postInit" );
  4540. },
  4541. TODO: isReloading: function() {
  4542. return ( this.phase=="init" || this.phase=="postInit" ) && this.options.persist && this.persistence.cookiesFound;
  4543. },
  4544. TODO: isUserEvent: function() {
  4545. return ( this.phase=="userEvent" );
  4546. },
  4547. */
  4548. /**
  4549. * Make sure that a node with a given ID is loaded, by traversing - and
  4550. * loading - its parents. This method is meant for lazy hierarchies.
  4551. * A callback is executed for every node as we go.
  4552. * @example
  4553. * // Resolve using node.key:
  4554. * tree.loadKeyPath("/_3/_23/_26/_27", function(node, status){
  4555. * if(status === "loaded") {
  4556. * console.log("loaded intermediate node " + node);
  4557. * }else if(status === "ok") {
  4558. * node.activate();
  4559. * }
  4560. * });
  4561. * // Use deferred promise:
  4562. * tree.loadKeyPath("/_3/_23/_26/_27").progress(function(data){
  4563. * if(data.status === "loaded") {
  4564. * console.log("loaded intermediate node " + data.node);
  4565. * }else if(data.status === "ok") {
  4566. * node.activate();
  4567. * }
  4568. * }).done(function(){
  4569. * ...
  4570. * });
  4571. * // Custom path segment resolver:
  4572. * tree.loadKeyPath("/321/431/21/2", {
  4573. * matchKey: function(node, key){
  4574. * return node.data.refKey === key;
  4575. * },
  4576. * callback: function(node, status){
  4577. * if(status === "loaded") {
  4578. * console.log("loaded intermediate node " + node);
  4579. * }else if(status === "ok") {
  4580. * node.activate();
  4581. * }
  4582. * }
  4583. * });
  4584. * @param {string | string[]} keyPathList one or more key paths (e.g. '/3/2_1/7')
  4585. * @param {function | object} optsOrCallback callback(node, status) is called for every visited node ('loading', 'loaded', 'ok', 'error').
  4586. * Pass an object to define custom key matchers for the path segments: {callback: function, matchKey: function}.
  4587. * @returns {$.Promise}
  4588. */
  4589. loadKeyPath: function(keyPathList, optsOrCallback) {
  4590. var callback,
  4591. i,
  4592. path,
  4593. self = this,
  4594. dfd = new $.Deferred(),
  4595. parent = this.getRootNode(),
  4596. sep = this.options.keyPathSeparator,
  4597. pathSegList = [],
  4598. opts = $.extend({}, optsOrCallback);
  4599. // Prepare options
  4600. if (typeof optsOrCallback === "function") {
  4601. callback = optsOrCallback;
  4602. } else if (optsOrCallback && optsOrCallback.callback) {
  4603. callback = optsOrCallback.callback;
  4604. }
  4605. opts.callback = function(ctx, node, status) {
  4606. if (callback) {
  4607. callback.call(ctx, node, status);
  4608. }
  4609. dfd.notifyWith(ctx, [{ node: node, status: status }]);
  4610. };
  4611. if (opts.matchKey == null) {
  4612. opts.matchKey = function(node, key) {
  4613. return node.key === key;
  4614. };
  4615. }
  4616. // Convert array of path strings to array of segment arrays
  4617. if (!$.isArray(keyPathList)) {
  4618. keyPathList = [keyPathList];
  4619. }
  4620. for (i = 0; i < keyPathList.length; i++) {
  4621. path = keyPathList[i];
  4622. // strip leading slash
  4623. if (path.charAt(0) === sep) {
  4624. path = path.substr(1);
  4625. }
  4626. // segListMap[path] = { parent: parent, segList: path.split(sep) };
  4627. pathSegList.push(path.split(sep));
  4628. // targetList.push({ parent: parent, segList: path.split(sep)/* , path: path*/});
  4629. }
  4630. // The timeout forces async behavior always (even if nodes are all loaded)
  4631. // This way a potential progress() event will fire.
  4632. setTimeout(function() {
  4633. self._loadKeyPathImpl(dfd, opts, parent, pathSegList).done(
  4634. function() {
  4635. dfd.resolve();
  4636. }
  4637. );
  4638. }, 0);
  4639. return dfd.promise();
  4640. },
  4641. /*
  4642. * Resolve a list of paths, relative to one parent node.
  4643. */
  4644. _loadKeyPathImpl: function(dfd, opts, parent, pathSegList) {
  4645. var deferredList,
  4646. i,
  4647. key,
  4648. node,
  4649. nodeKey,
  4650. remain,
  4651. remainMap,
  4652. tmpParent,
  4653. segList,
  4654. subDfd,
  4655. self = this;
  4656. function __findChild(parent, key) {
  4657. // console.log("__findChild", key, parent);
  4658. var i,
  4659. l,
  4660. cl = parent.children;
  4661. if (cl) {
  4662. for (i = 0, l = cl.length; i < l; i++) {
  4663. if (opts.matchKey(cl[i], key)) {
  4664. return cl[i];
  4665. }
  4666. }
  4667. }
  4668. return null;
  4669. }
  4670. // console.log("_loadKeyPathImpl, parent=", parent, ", pathSegList=", pathSegList);
  4671. // Pass 1:
  4672. // Handle all path segments for nodes that are already loaded.
  4673. // Collect distinct top-most lazy nodes in a map.
  4674. // Note that we can use node.key to de-dupe entries, even if a custom matcher would
  4675. // look for other node attributes.
  4676. // map[node.key] => {node: node, pathList: [list of remaining rest-paths]}
  4677. remainMap = {};
  4678. for (i = 0; i < pathSegList.length; i++) {
  4679. segList = pathSegList[i];
  4680. // target = targetList[i];
  4681. // Traverse and pop path segments (i.e. keys), until we hit a lazy, unloaded node
  4682. tmpParent = parent;
  4683. while (segList.length) {
  4684. key = segList.shift();
  4685. node = __findChild(tmpParent, key);
  4686. if (!node) {
  4687. this.warn(
  4688. "loadKeyPath: key not found: " +
  4689. key +
  4690. " (parent: " +
  4691. tmpParent +
  4692. ")"
  4693. );
  4694. opts.callback(this, key, "error");
  4695. break;
  4696. } else if (segList.length === 0) {
  4697. opts.callback(this, node, "ok");
  4698. break;
  4699. } else if (!node.lazy || node.hasChildren() !== undefined) {
  4700. opts.callback(this, node, "loaded");
  4701. tmpParent = node;
  4702. } else {
  4703. opts.callback(this, node, "loaded");
  4704. key = node.key; //target.segList.join(sep);
  4705. if (remainMap[key]) {
  4706. remainMap[key].pathSegList.push(segList);
  4707. } else {
  4708. remainMap[key] = {
  4709. parent: node,
  4710. pathSegList: [segList],
  4711. };
  4712. }
  4713. break;
  4714. }
  4715. }
  4716. }
  4717. // console.log("_loadKeyPathImpl AFTER pass 1, remainMap=", remainMap);
  4718. // Now load all lazy nodes and continue iteration for remaining paths
  4719. deferredList = [];
  4720. // Avoid jshint warning 'Don't make functions within a loop.':
  4721. function __lazyload(dfd, parent, pathSegList) {
  4722. // console.log("__lazyload", parent, "pathSegList=", pathSegList);
  4723. opts.callback(self, parent, "loading");
  4724. parent
  4725. .load()
  4726. .done(function() {
  4727. self._loadKeyPathImpl
  4728. .call(self, dfd, opts, parent, pathSegList)
  4729. .always(_makeResolveFunc(dfd, self));
  4730. })
  4731. .fail(function(errMsg) {
  4732. self.warn("loadKeyPath: error loading lazy " + parent);
  4733. opts.callback(self, node, "error");
  4734. dfd.rejectWith(self);
  4735. });
  4736. }
  4737. // remainMap contains parent nodes, each with a list of relative sub-paths.
  4738. // We start loading all of them now, and pass the the list to each loader.
  4739. for (nodeKey in remainMap) {
  4740. if (remainMap.hasOwnProperty(nodeKey)) {
  4741. remain = remainMap[nodeKey];
  4742. // console.log("for(): remain=", remain, "remainMap=", remainMap);
  4743. // key = remain.segList.shift();
  4744. // node = __findChild(remain.parent, key);
  4745. // if (node == null) { // #576
  4746. // // Issue #576, refactored for v2.27:
  4747. // // The root cause was, that sometimes the wrong parent was used here
  4748. // // to find the next segment.
  4749. // // Falling back to getNodeByKey() was a hack that no longer works if a custom
  4750. // // matcher is used, because we cannot assume that a single segment-key is unique
  4751. // // throughout the tree.
  4752. // self.error("loadKeyPath: error loading child by key '" + key + "' (parent: " + target.parent + ")", target);
  4753. // // node = self.getNodeByKey(key);
  4754. // continue;
  4755. // }
  4756. subDfd = new $.Deferred();
  4757. deferredList.push(subDfd);
  4758. __lazyload(subDfd, remain.parent, remain.pathSegList);
  4759. }
  4760. }
  4761. // Return a promise that is resolved, when ALL paths were loaded
  4762. return $.when.apply($, deferredList).promise();
  4763. },
  4764. /** Re-fire beforeActivate, activate, and (optional) focus events.
  4765. * Calling this method in the `init` event, will activate the node that
  4766. * was marked 'active' in the source data, and optionally set the keyboard
  4767. * focus.
  4768. * @param [setFocus=false]
  4769. */
  4770. reactivate: function(setFocus) {
  4771. var res,
  4772. node = this.activeNode;
  4773. if (!node) {
  4774. return _getResolvedPromise();
  4775. }
  4776. this.activeNode = null; // Force re-activating
  4777. res = node.setActive(true, { noFocus: true });
  4778. if (setFocus) {
  4779. node.setFocus();
  4780. }
  4781. return res;
  4782. },
  4783. /** Reload tree from source and return a promise.
  4784. * @param [source] optional new source (defaults to initial source data)
  4785. * @returns {$.Promise}
  4786. */
  4787. reload: function(source) {
  4788. this._callHook("treeClear", this);
  4789. return this._callHook("treeLoad", this, source);
  4790. },
  4791. /**Render tree (i.e. create DOM elements for all top-level nodes).
  4792. * @param {boolean} [force=false] create DOM elemnts, even if parent is collapsed
  4793. * @param {boolean} [deep=false]
  4794. */
  4795. render: function(force, deep) {
  4796. return this.rootNode.render(force, deep);
  4797. },
  4798. /**(De)select all nodes.
  4799. * @param {boolean} [flag=true]
  4800. * @since 2.28
  4801. */
  4802. selectAll: function(flag) {
  4803. this.visit(function(node) {
  4804. node.setSelected(flag);
  4805. });
  4806. },
  4807. // TODO: selectKey: function(key, select)
  4808. // TODO: serializeArray: function(stopOnParents)
  4809. /**
  4810. * @param {boolean} [flag=true]
  4811. */
  4812. setFocus: function(flag) {
  4813. return this._callHook("treeSetFocus", this, flag);
  4814. },
  4815. /**
  4816. * Set current option value.
  4817. * (Note: this is the preferred variant of `$().fancytree("option", "KEY", VALUE)`)
  4818. * @param {string} name option name (may contain '.')
  4819. * @param {any} new value
  4820. */
  4821. setOption: function(optionName, value) {
  4822. return this.widget.option(optionName, value);
  4823. },
  4824. /**
  4825. * Call console.time() when in debug mode (verbose >= 4).
  4826. *
  4827. * @param {string} label
  4828. */
  4829. debugTime: function(label) {
  4830. if (this.options.debugLevel >= 4) {
  4831. window.console.time(this + " - " + label);
  4832. }
  4833. },
  4834. /**
  4835. * Call console.timeEnd() when in debug mode (verbose >= 4).
  4836. *
  4837. * @param {string} label
  4838. */
  4839. debugTimeEnd: function(label) {
  4840. if (this.options.debugLevel >= 4) {
  4841. window.console.timeEnd(this + " - " + label);
  4842. }
  4843. },
  4844. /**
  4845. * Return all nodes as nested list of {@link NodeData}.
  4846. *
  4847. * @param {boolean} [includeRoot=false] Returns the hidden system root node (and its children)
  4848. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications.
  4849. * Return `false` to ignore this node or "skip" to include this node without its children.
  4850. * @returns {Array | object}
  4851. * @see FancytreeNode#toDict
  4852. */
  4853. toDict: function(includeRoot, callback) {
  4854. var res = this.rootNode.toDict(true, callback);
  4855. return includeRoot ? res : res.children;
  4856. },
  4857. /* Implicitly called for string conversions.
  4858. * @returns {string}
  4859. */
  4860. toString: function() {
  4861. return "Fancytree@" + this._id;
  4862. // return "<Fancytree(#" + this._id + ")>";
  4863. },
  4864. /* _trigger a widget event with additional node ctx.
  4865. * @see EventData
  4866. */
  4867. _triggerNodeEvent: function(type, node, originalEvent, extra) {
  4868. // this.debug("_trigger(" + type + "): '" + ctx.node.title + "'", ctx);
  4869. var ctx = this._makeHookContext(node, originalEvent, extra),
  4870. res = this.widget._trigger(type, originalEvent, ctx);
  4871. if (res !== false && ctx.result !== undefined) {
  4872. return ctx.result;
  4873. }
  4874. return res;
  4875. },
  4876. /* _trigger a widget event with additional tree data. */
  4877. _triggerTreeEvent: function(type, originalEvent, extra) {
  4878. // this.debug("_trigger(" + type + ")", ctx);
  4879. var ctx = this._makeHookContext(this, originalEvent, extra),
  4880. res = this.widget._trigger(type, originalEvent, ctx);
  4881. if (res !== false && ctx.result !== undefined) {
  4882. return ctx.result;
  4883. }
  4884. return res;
  4885. },
  4886. /** Call fn(node) for all nodes in hierarchical order (depth-first).
  4887. *
  4888. * @param {function} fn the callback function.
  4889. * Return false to stop iteration, return "skip" to skip this node and children only.
  4890. * @returns {boolean} false, if the iterator was stopped.
  4891. */
  4892. visit: function(fn) {
  4893. return this.rootNode.visit(fn, false);
  4894. },
  4895. /** Call fn(node) for all nodes in vertical order, top down (or bottom up).<br>
  4896. * Stop iteration, if fn() returns false.<br>
  4897. * Return false if iteration was stopped.
  4898. *
  4899. * @param {function} fn the callback function.
  4900. * Return false to stop iteration, return "skip" to skip this node and children only.
  4901. * @param {object} [options]
  4902. * Defaults:
  4903. * {start: First top node, reverse: false, includeSelf: true, includeHidden: false}
  4904. * @returns {boolean} false if iteration was cancelled
  4905. * @since 2.28
  4906. */
  4907. visitRows: function(fn, opts) {
  4908. if (!this.rootNode.hasChildren()) {
  4909. return false;
  4910. }
  4911. if (opts && opts.reverse) {
  4912. delete opts.reverse;
  4913. return this._visitRowsUp(fn, opts);
  4914. }
  4915. opts = opts || {};
  4916. var i,
  4917. nextIdx,
  4918. parent,
  4919. res,
  4920. siblings,
  4921. siblingOfs = 0,
  4922. skipFirstNode = opts.includeSelf === false,
  4923. includeHidden = !!opts.includeHidden,
  4924. checkFilter = !includeHidden && this.enableFilter,
  4925. node = opts.start || this.rootNode.children[0];
  4926. parent = node.parent;
  4927. while (parent) {
  4928. // visit siblings
  4929. siblings = parent.children;
  4930. nextIdx = siblings.indexOf(node) + siblingOfs;
  4931. _assert(
  4932. nextIdx >= 0,
  4933. "Could not find " +
  4934. node +
  4935. " in parent's children: " +
  4936. parent
  4937. );
  4938. for (i = nextIdx; i < siblings.length; i++) {
  4939. node = siblings[i];
  4940. if (checkFilter && !node.match && !node.subMatchCount) {
  4941. continue;
  4942. }
  4943. if (!skipFirstNode && fn(node) === false) {
  4944. return false;
  4945. }
  4946. skipFirstNode = false;
  4947. // Dive into node's child nodes
  4948. if (
  4949. node.children &&
  4950. node.children.length &&
  4951. (includeHidden || node.expanded)
  4952. ) {
  4953. // Disable warning: Functions declared within loops referencing an outer
  4954. // scoped variable may lead to confusing semantics:
  4955. /*jshint -W083 */
  4956. res = node.visit(function(n) {
  4957. if (checkFilter && !n.match && !n.subMatchCount) {
  4958. return "skip";
  4959. }
  4960. if (fn(n) === false) {
  4961. return false;
  4962. }
  4963. if (!includeHidden && n.children && !n.expanded) {
  4964. return "skip";
  4965. }
  4966. }, false);
  4967. /*jshint +W083 */
  4968. if (res === false) {
  4969. return false;
  4970. }
  4971. }
  4972. }
  4973. // Visit parent nodes (bottom up)
  4974. node = parent;
  4975. parent = parent.parent;
  4976. siblingOfs = 1; //
  4977. }
  4978. return true;
  4979. },
  4980. /* Call fn(node) for all nodes in vertical order, bottom up.
  4981. */
  4982. _visitRowsUp: function(fn, opts) {
  4983. var children,
  4984. idx,
  4985. parent,
  4986. includeHidden = !!opts.includeHidden,
  4987. node = opts.start || this.rootNode.children[0];
  4988. while (true) {
  4989. parent = node.parent;
  4990. children = parent.children;
  4991. if (children[0] === node) {
  4992. // If this is already the first sibling, goto parent
  4993. node = parent;
  4994. if (!node.parent) {
  4995. break; // first node of the tree
  4996. }
  4997. children = parent.children;
  4998. } else {
  4999. // Otherwise, goto prev. sibling
  5000. idx = children.indexOf(node);
  5001. node = children[idx - 1];
  5002. // If the prev. sibling has children, follow down to last descendant
  5003. while (
  5004. // See: https://github.com/eslint/eslint/issues/11302
  5005. // eslint-disable-next-line no-unmodified-loop-condition
  5006. (includeHidden || node.expanded) &&
  5007. node.children &&
  5008. node.children.length
  5009. ) {
  5010. children = node.children;
  5011. parent = node;
  5012. node = children[children.length - 1];
  5013. }
  5014. }
  5015. // Skip invisible
  5016. if (!includeHidden && !node.isVisible()) {
  5017. continue;
  5018. }
  5019. if (fn(node) === false) {
  5020. return false;
  5021. }
  5022. }
  5023. },
  5024. /** Write warning to browser console if debugLevel >= 2 (prepending tree info)
  5025. *
  5026. * @param {*} msg string or object or array of such
  5027. */
  5028. warn: function(msg) {
  5029. if (this.options.debugLevel >= 2) {
  5030. Array.prototype.unshift.call(arguments, this.toString());
  5031. consoleApply("warn", arguments);
  5032. }
  5033. },
  5034. };
  5035. /**
  5036. * These additional methods of the {@link Fancytree} class are 'hook functions'
  5037. * that can be used and overloaded by extensions.
  5038. *
  5039. * @see [writing extensions](https://github.com/mar10/fancytree/wiki/TutorialExtensions)
  5040. * @mixin Fancytree_Hooks
  5041. */
  5042. $.extend(
  5043. Fancytree.prototype,
  5044. /** @lends Fancytree_Hooks# */
  5045. {
  5046. /** Default handling for mouse click events.
  5047. *
  5048. * @param {EventData} ctx
  5049. */
  5050. nodeClick: function(ctx) {
  5051. var activate,
  5052. expand,
  5053. // event = ctx.originalEvent,
  5054. targetType = ctx.targetType,
  5055. node = ctx.node;
  5056. // this.debug("ftnode.onClick(" + event.type + "): ftnode:" + this + ", button:" + event.button + ", which: " + event.which, ctx);
  5057. // TODO: use switch
  5058. // TODO: make sure clicks on embedded <input> doesn't steal focus (see table sample)
  5059. if (targetType === "expander") {
  5060. if (node.isLoading()) {
  5061. // #495: we probably got a click event while a lazy load is pending.
  5062. // The 'expanded' state is not yet set, so 'toggle' would expand
  5063. // and trigger lazyLoad again.
  5064. // It would be better to allow to collapse/expand the status node
  5065. // while loading (instead of ignoring), but that would require some
  5066. // more work.
  5067. node.debug("Got 2nd click while loading: ignored");
  5068. return;
  5069. }
  5070. // Clicking the expander icon always expands/collapses
  5071. this._callHook("nodeToggleExpanded", ctx);
  5072. } else if (targetType === "checkbox") {
  5073. // Clicking the checkbox always (de)selects
  5074. this._callHook("nodeToggleSelected", ctx);
  5075. if (ctx.options.focusOnSelect) {
  5076. // #358
  5077. this._callHook("nodeSetFocus", ctx, true);
  5078. }
  5079. } else {
  5080. // Honor `clickFolderMode` for
  5081. expand = false;
  5082. activate = true;
  5083. if (node.folder) {
  5084. switch (ctx.options.clickFolderMode) {
  5085. case 2: // expand only
  5086. expand = true;
  5087. activate = false;
  5088. break;
  5089. case 3: // expand and activate
  5090. activate = true;
  5091. expand = true; //!node.isExpanded();
  5092. break;
  5093. // else 1 or 4: just activate
  5094. }
  5095. }
  5096. if (activate) {
  5097. this.nodeSetFocus(ctx);
  5098. this._callHook("nodeSetActive", ctx, true);
  5099. }
  5100. if (expand) {
  5101. if (!activate) {
  5102. // this._callHook("nodeSetFocus", ctx);
  5103. }
  5104. // this._callHook("nodeSetExpanded", ctx, true);
  5105. this._callHook("nodeToggleExpanded", ctx);
  5106. }
  5107. }
  5108. // Make sure that clicks stop, otherwise <a href='#'> jumps to the top
  5109. // if(event.target.localName === "a" && event.target.className === "fancytree-title"){
  5110. // event.preventDefault();
  5111. // }
  5112. // TODO: return promise?
  5113. },
  5114. /** Collapse all other children of same parent.
  5115. *
  5116. * @param {EventData} ctx
  5117. * @param {object} callOpts
  5118. */
  5119. nodeCollapseSiblings: function(ctx, callOpts) {
  5120. // TODO: return promise?
  5121. var ac,
  5122. i,
  5123. l,
  5124. node = ctx.node;
  5125. if (node.parent) {
  5126. ac = node.parent.children;
  5127. for (i = 0, l = ac.length; i < l; i++) {
  5128. if (ac[i] !== node && ac[i].expanded) {
  5129. this._callHook(
  5130. "nodeSetExpanded",
  5131. ac[i],
  5132. false,
  5133. callOpts
  5134. );
  5135. }
  5136. }
  5137. }
  5138. },
  5139. /** Default handling for mouse douleclick events.
  5140. * @param {EventData} ctx
  5141. */
  5142. nodeDblclick: function(ctx) {
  5143. // TODO: return promise?
  5144. if (
  5145. ctx.targetType === "title" &&
  5146. ctx.options.clickFolderMode === 4
  5147. ) {
  5148. // this.nodeSetFocus(ctx);
  5149. // this._callHook("nodeSetActive", ctx, true);
  5150. this._callHook("nodeToggleExpanded", ctx);
  5151. }
  5152. // TODO: prevent text selection on dblclicks
  5153. if (ctx.targetType === "title") {
  5154. ctx.originalEvent.preventDefault();
  5155. }
  5156. },
  5157. /** Default handling for mouse keydown events.
  5158. *
  5159. * NOTE: this may be called with node == null if tree (but no node) has focus.
  5160. * @param {EventData} ctx
  5161. */
  5162. nodeKeydown: function(ctx) {
  5163. // TODO: return promise?
  5164. var matchNode,
  5165. stamp,
  5166. _res,
  5167. focusNode,
  5168. event = ctx.originalEvent,
  5169. node = ctx.node,
  5170. tree = ctx.tree,
  5171. opts = ctx.options,
  5172. which = event.which,
  5173. // #909: Use event.key, to get unicode characters.
  5174. // We can't use `/\w/.test(key)`, because that would
  5175. // only detect plain ascii alpha-numerics. But we still need
  5176. // to ignore modifier-only, whitespace, cursor-keys, etc.
  5177. key = event.key || String.fromCharCode(which),
  5178. specialModifiers = !!(
  5179. event.altKey ||
  5180. event.ctrlKey ||
  5181. event.metaKey
  5182. ),
  5183. isAlnum =
  5184. !MODIFIERS[which] &&
  5185. !SPECIAL_KEYCODES[which] &&
  5186. !specialModifiers,
  5187. $target = $(event.target),
  5188. handled = true,
  5189. activate = !(event.ctrlKey || !opts.autoActivate);
  5190. // (node || FT).debug("ftnode.nodeKeydown(" + event.type + "): ftnode:" + this + ", charCode:" + event.charCode + ", keyCode: " + event.keyCode + ", which: " + event.which);
  5191. // FT.debug( "eventToString(): " + FT.eventToString(event) + ", key='" + key + "', isAlnum: " + isAlnum );
  5192. // Set focus to active (or first node) if no other node has the focus yet
  5193. if (!node) {
  5194. focusNode = this.getActiveNode() || this.getFirstChild();
  5195. if (focusNode) {
  5196. focusNode.setFocus();
  5197. node = ctx.node = this.focusNode;
  5198. node.debug("Keydown force focus on active node");
  5199. }
  5200. }
  5201. if (
  5202. opts.quicksearch &&
  5203. isAlnum &&
  5204. !$target.is(":input:enabled")
  5205. ) {
  5206. // Allow to search for longer streaks if typed in quickly
  5207. stamp = Date.now();
  5208. if (stamp - tree.lastQuicksearchTime > 500) {
  5209. tree.lastQuicksearchTerm = "";
  5210. }
  5211. tree.lastQuicksearchTime = stamp;
  5212. tree.lastQuicksearchTerm += key;
  5213. // tree.debug("quicksearch find", tree.lastQuicksearchTerm);
  5214. matchNode = tree.findNextNode(
  5215. tree.lastQuicksearchTerm,
  5216. tree.getActiveNode()
  5217. );
  5218. if (matchNode) {
  5219. matchNode.setActive();
  5220. }
  5221. event.preventDefault();
  5222. return;
  5223. }
  5224. switch (FT.eventToString(event)) {
  5225. case "+":
  5226. case "=": // 187: '+' @ Chrome, Safari
  5227. tree.nodeSetExpanded(ctx, true);
  5228. break;
  5229. case "-":
  5230. tree.nodeSetExpanded(ctx, false);
  5231. break;
  5232. case "space":
  5233. if (node.isPagingNode()) {
  5234. tree._triggerNodeEvent("clickPaging", ctx, event);
  5235. } else if (
  5236. FT.evalOption("checkbox", node, node, opts, false)
  5237. ) {
  5238. // #768
  5239. tree.nodeToggleSelected(ctx);
  5240. } else {
  5241. tree.nodeSetActive(ctx, true);
  5242. }
  5243. break;
  5244. case "return":
  5245. tree.nodeSetActive(ctx, true);
  5246. break;
  5247. case "home":
  5248. case "end":
  5249. case "backspace":
  5250. case "left":
  5251. case "right":
  5252. case "up":
  5253. case "down":
  5254. _res = node.navigate(event.which, activate);
  5255. break;
  5256. default:
  5257. handled = false;
  5258. }
  5259. if (handled) {
  5260. event.preventDefault();
  5261. }
  5262. },
  5263. // /** Default handling for mouse keypress events. */
  5264. // nodeKeypress: function(ctx) {
  5265. // var event = ctx.originalEvent;
  5266. // },
  5267. // /** Trigger lazyLoad event (async). */
  5268. // nodeLazyLoad: function(ctx) {
  5269. // var node = ctx.node;
  5270. // if(this._triggerNodeEvent())
  5271. // },
  5272. /** Load child nodes (async).
  5273. *
  5274. * @param {EventData} ctx
  5275. * @param {object[]|object|string|$.Promise|function} source
  5276. * @returns {$.Promise} The deferred will be resolved as soon as the (ajax)
  5277. * data was rendered.
  5278. */
  5279. nodeLoadChildren: function(ctx, source) {
  5280. var ajax,
  5281. delay,
  5282. ajaxDfd = null,
  5283. resultDfd,
  5284. isAsync = true,
  5285. tree = ctx.tree,
  5286. node = ctx.node,
  5287. nodePrevParent = node.parent,
  5288. tag = "nodeLoadChildren",
  5289. requestId = Date.now();
  5290. // `source` is a callback: use the returned result instead:
  5291. if ($.isFunction(source)) {
  5292. source = source.call(tree, { type: "source" }, ctx);
  5293. _assert(
  5294. !$.isFunction(source),
  5295. "source callback must not return another function"
  5296. );
  5297. }
  5298. // `source` is already a promise:
  5299. if ($.isFunction(source.then)) {
  5300. // _assert($.isFunction(source.always), "Expected jQuery?");
  5301. ajaxDfd = source;
  5302. } else if (source.url) {
  5303. // `source` is an Ajax options object
  5304. ajax = $.extend({}, ctx.options.ajax, source);
  5305. if (ajax.debugDelay) {
  5306. // Simulate a slow server
  5307. delay = ajax.debugDelay;
  5308. delete ajax.debugDelay; // remove debug option
  5309. if ($.isArray(delay)) {
  5310. // random delay range [min..max]
  5311. delay =
  5312. delay[0] +
  5313. Math.random() * (delay[1] - delay[0]);
  5314. }
  5315. node.warn(
  5316. "nodeLoadChildren waiting debugDelay " +
  5317. Math.round(delay) +
  5318. " ms ..."
  5319. );
  5320. ajaxDfd = $.Deferred(function(ajaxDfd) {
  5321. setTimeout(function() {
  5322. $.ajax(ajax)
  5323. .done(function() {
  5324. ajaxDfd.resolveWith(this, arguments);
  5325. })
  5326. .fail(function() {
  5327. ajaxDfd.rejectWith(this, arguments);
  5328. });
  5329. }, delay);
  5330. });
  5331. } else {
  5332. ajaxDfd = $.ajax(ajax);
  5333. }
  5334. } else if ($.isPlainObject(source) || $.isArray(source)) {
  5335. // `source` is already a constant dict or list, but we convert
  5336. // to a thenable for unified processing.
  5337. // 2020-01-03: refactored.
  5338. // `ajaxDfd = $.when(source)` would do the trick, but the returned
  5339. // promise will resolve async, which broke some tests and
  5340. // would probably also break current implementations out there.
  5341. // So we mock-up a thenable that resolves synchronously:
  5342. ajaxDfd = {
  5343. then: function(resolve, reject) {
  5344. resolve(source, null, null);
  5345. },
  5346. };
  5347. isAsync = false;
  5348. } else {
  5349. $.error("Invalid source type: " + source);
  5350. }
  5351. // Check for overlapping requests
  5352. if (node._requestId) {
  5353. node.warn(
  5354. "Recursive load request #" +
  5355. requestId +
  5356. " while #" +
  5357. node._requestId +
  5358. " is pending."
  5359. );
  5360. node._requestId = requestId;
  5361. // node.debug("Send load request #" + requestId);
  5362. }
  5363. if (isAsync) {
  5364. tree.debugTime(tag);
  5365. tree.nodeSetStatus(ctx, "loading");
  5366. }
  5367. // The async Ajax request has now started...
  5368. // Defer the deferred:
  5369. // we want to be able to reject invalid responses, even if
  5370. // the raw HTTP Ajax XHR resolved as Ok.
  5371. // We use the ajaxDfd.then() syntax here, which is compatible with
  5372. // jQuery and ECMA6.
  5373. // However resultDfd is a jQuery deferred, which is currently the
  5374. // expected result type of nodeLoadChildren()
  5375. resultDfd = new $.Deferred();
  5376. ajaxDfd.then(
  5377. function(data, textStatus, jqXHR) {
  5378. // ajaxDfd was resolved, but we reject or resolve resultDfd
  5379. // depending on the response data
  5380. var errorObj, res;
  5381. if (
  5382. (source.dataType === "json" ||
  5383. source.dataType === "jsonp") &&
  5384. typeof data === "string"
  5385. ) {
  5386. $.error(
  5387. "Ajax request returned a string (did you get the JSON dataType wrong?)."
  5388. );
  5389. }
  5390. if (node._requestId && node._requestId > requestId) {
  5391. // The expected request time stamp is later than `requestId`
  5392. // (which was kept as as closure variable to this handler function)
  5393. // node.warn("Ignored load response for obsolete request #" + requestId + " (expected #" + node._requestId + ")");
  5394. resultDfd.rejectWith(this, [
  5395. RECURSIVE_REQUEST_ERROR,
  5396. ]);
  5397. return;
  5398. // } else {
  5399. // node.debug("Response returned for load request #" + requestId);
  5400. }
  5401. if (node.parent === null && nodePrevParent !== null) {
  5402. resultDfd.rejectWith(this, [
  5403. INVALID_REQUEST_TARGET_ERROR,
  5404. ]);
  5405. return;
  5406. }
  5407. // Allow to adjust the received response data in the `postProcess` event.
  5408. if (ctx.options.postProcess) {
  5409. // The handler may either
  5410. // - modify `ctx.response` in-place (and leave `ctx.result` undefined)
  5411. // => res = undefined
  5412. // - return a replacement in `ctx.result`
  5413. // => res = <new data>
  5414. // If res contains an `error` property, an error status is displayed
  5415. try {
  5416. res = tree._triggerNodeEvent(
  5417. "postProcess",
  5418. ctx,
  5419. ctx.originalEvent,
  5420. {
  5421. response: data,
  5422. error: null,
  5423. dataType: source.dataType,
  5424. }
  5425. );
  5426. if (res.error) {
  5427. tree.warn(
  5428. "postProcess returned error:",
  5429. res
  5430. );
  5431. }
  5432. } catch (e) {
  5433. res = {
  5434. error: e,
  5435. message: "" + e,
  5436. details: "postProcess failed",
  5437. };
  5438. }
  5439. if (res.error) {
  5440. // Either postProcess failed with an exception, or the returned
  5441. // result object has an 'error' property attached:
  5442. errorObj = $.isPlainObject(res.error)
  5443. ? res.error
  5444. : { message: res.error };
  5445. errorObj = tree._makeHookContext(
  5446. node,
  5447. null,
  5448. errorObj
  5449. );
  5450. resultDfd.rejectWith(this, [errorObj]);
  5451. return;
  5452. }
  5453. if (
  5454. $.isArray(res) ||
  5455. ($.isPlainObject(res) &&
  5456. $.isArray(res.children))
  5457. ) {
  5458. // Use `ctx.result` if valid
  5459. // (otherwise use existing data, which may have been modified in-place)
  5460. data = res;
  5461. }
  5462. } else if (
  5463. data &&
  5464. data.hasOwnProperty("d") &&
  5465. ctx.options.enableAspx
  5466. ) {
  5467. // Process ASPX WebMethod JSON object inside "d" property
  5468. // (only if no postProcess event was defined)
  5469. if (ctx.options.enableAspx === 42) {
  5470. tree.warn(
  5471. "The default for enableAspx will change to `false` in the fututure. " +
  5472. "Pass `enableAspx: true` or implement postProcess to silence this warning."
  5473. );
  5474. }
  5475. data =
  5476. typeof data.d === "string"
  5477. ? $.parseJSON(data.d)
  5478. : data.d;
  5479. }
  5480. resultDfd.resolveWith(this, [data]);
  5481. },
  5482. function(jqXHR, textStatus, errorThrown) {
  5483. // ajaxDfd was rejected, so we reject resultDfd as well
  5484. var errorObj = tree._makeHookContext(node, null, {
  5485. error: jqXHR,
  5486. args: Array.prototype.slice.call(arguments),
  5487. message: errorThrown,
  5488. details: jqXHR.status + ": " + errorThrown,
  5489. });
  5490. resultDfd.rejectWith(this, [errorObj]);
  5491. }
  5492. );
  5493. // The async Ajax request has now started.
  5494. // resultDfd will be resolved/rejected after the response arrived,
  5495. // was postProcessed, and checked.
  5496. // Now we implement the UI update and add the data to the tree.
  5497. // We also return this promise to the caller.
  5498. resultDfd
  5499. .done(function(data) {
  5500. tree.nodeSetStatus(ctx, "ok");
  5501. var children, metaData, noDataRes;
  5502. if ($.isPlainObject(data)) {
  5503. // We got {foo: 'abc', children: [...]}
  5504. // Copy extra properties to tree.data.foo
  5505. _assert(
  5506. node.isRootNode(),
  5507. "source may only be an object for root nodes (expecting an array of child objects otherwise)"
  5508. );
  5509. _assert(
  5510. $.isArray(data.children),
  5511. "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')"
  5512. );
  5513. metaData = data;
  5514. children = data.children;
  5515. delete metaData.children;
  5516. // Copy some attributes to tree.data
  5517. $.each(TREE_ATTRS, function(i, attr) {
  5518. if (metaData[attr] !== undefined) {
  5519. tree[attr] = metaData[attr];
  5520. delete metaData[attr];
  5521. }
  5522. });
  5523. // Copy all other attributes to tree.data.NAME
  5524. $.extend(tree.data, metaData);
  5525. } else {
  5526. children = data;
  5527. }
  5528. _assert(
  5529. $.isArray(children),
  5530. "expected array of children"
  5531. );
  5532. node._setChildren(children);
  5533. if (tree.options.nodata && children.length === 0) {
  5534. if ($.isFunction(tree.options.nodata)) {
  5535. noDataRes = tree.options.nodata.call(
  5536. tree,
  5537. { type: "nodata" },
  5538. ctx
  5539. );
  5540. } else if (
  5541. tree.options.nodata === true &&
  5542. node.isRootNode()
  5543. ) {
  5544. noDataRes = tree.options.strings.noData;
  5545. } else if (
  5546. typeof tree.options.nodata === "string" &&
  5547. node.isRootNode()
  5548. ) {
  5549. noDataRes = tree.options.nodata;
  5550. }
  5551. if (noDataRes) {
  5552. node.setStatus("nodata", noDataRes);
  5553. }
  5554. }
  5555. // trigger fancytreeloadchildren
  5556. tree._triggerNodeEvent("loadChildren", node);
  5557. })
  5558. .fail(function(error) {
  5559. var ctxErr;
  5560. if (error === RECURSIVE_REQUEST_ERROR) {
  5561. node.warn(
  5562. "Ignored response for obsolete load request #" +
  5563. requestId +
  5564. " (expected #" +
  5565. node._requestId +
  5566. ")"
  5567. );
  5568. return;
  5569. } else if (error === INVALID_REQUEST_TARGET_ERROR) {
  5570. node.warn(
  5571. "Lazy parent node was removed while loading: discarding response."
  5572. );
  5573. return;
  5574. } else if (error.node && error.error && error.message) {
  5575. // error is already a context object
  5576. ctxErr = error;
  5577. } else {
  5578. ctxErr = tree._makeHookContext(node, null, {
  5579. error: error, // it can be jqXHR or any custom error
  5580. args: Array.prototype.slice.call(arguments),
  5581. message: error
  5582. ? error.message || error.toString()
  5583. : "",
  5584. });
  5585. if (ctxErr.message === "[object Object]") {
  5586. ctxErr.message = "";
  5587. }
  5588. }
  5589. node.warn(
  5590. "Load children failed (" + ctxErr.message + ")",
  5591. ctxErr
  5592. );
  5593. if (
  5594. tree._triggerNodeEvent(
  5595. "loadError",
  5596. ctxErr,
  5597. null
  5598. ) !== false
  5599. ) {
  5600. tree.nodeSetStatus(
  5601. ctx,
  5602. "error",
  5603. ctxErr.message,
  5604. ctxErr.details
  5605. );
  5606. }
  5607. })
  5608. .always(function() {
  5609. node._requestId = null;
  5610. if (isAsync) {
  5611. tree.debugTimeEnd(tag);
  5612. }
  5613. });
  5614. return resultDfd.promise();
  5615. },
  5616. /** [Not Implemented] */
  5617. nodeLoadKeyPath: function(ctx, keyPathList) {
  5618. // TODO: implement and improve
  5619. // http://code.google.com/p/dynatree/issues/detail?id=222
  5620. },
  5621. /**
  5622. * Remove a single direct child of ctx.node.
  5623. * @param {EventData} ctx
  5624. * @param {FancytreeNode} childNode dircect child of ctx.node
  5625. */
  5626. nodeRemoveChild: function(ctx, childNode) {
  5627. var idx,
  5628. node = ctx.node,
  5629. // opts = ctx.options,
  5630. subCtx = $.extend({}, ctx, { node: childNode }),
  5631. children = node.children;
  5632. // FT.debug("nodeRemoveChild()", node.toString(), childNode.toString());
  5633. if (children.length === 1) {
  5634. _assert(childNode === children[0], "invalid single child");
  5635. return this.nodeRemoveChildren(ctx);
  5636. }
  5637. if (
  5638. this.activeNode &&
  5639. (childNode === this.activeNode ||
  5640. this.activeNode.isDescendantOf(childNode))
  5641. ) {
  5642. this.activeNode.setActive(false); // TODO: don't fire events
  5643. }
  5644. if (
  5645. this.focusNode &&
  5646. (childNode === this.focusNode ||
  5647. this.focusNode.isDescendantOf(childNode))
  5648. ) {
  5649. this.focusNode = null;
  5650. }
  5651. // TODO: persist must take care to clear select and expand cookies
  5652. this.nodeRemoveMarkup(subCtx);
  5653. this.nodeRemoveChildren(subCtx);
  5654. idx = $.inArray(childNode, children);
  5655. _assert(idx >= 0, "invalid child");
  5656. // Notify listeners
  5657. node.triggerModifyChild("remove", childNode);
  5658. // Unlink to support GC
  5659. childNode.visit(function(n) {
  5660. n.parent = null;
  5661. }, true);
  5662. this._callHook("treeRegisterNode", this, false, childNode);
  5663. // remove from child list
  5664. children.splice(idx, 1);
  5665. },
  5666. /**Remove HTML markup for all descendents of ctx.node.
  5667. * @param {EventData} ctx
  5668. */
  5669. nodeRemoveChildMarkup: function(ctx) {
  5670. var node = ctx.node;
  5671. // FT.debug("nodeRemoveChildMarkup()", node.toString());
  5672. // TODO: Unlink attr.ftnode to support GC
  5673. if (node.ul) {
  5674. if (node.isRootNode()) {
  5675. $(node.ul).empty();
  5676. } else {
  5677. $(node.ul).remove();
  5678. node.ul = null;
  5679. }
  5680. node.visit(function(n) {
  5681. n.li = n.ul = null;
  5682. });
  5683. }
  5684. },
  5685. /**Remove all descendants of ctx.node.
  5686. * @param {EventData} ctx
  5687. */
  5688. nodeRemoveChildren: function(ctx) {
  5689. var //subCtx,
  5690. tree = ctx.tree,
  5691. node = ctx.node,
  5692. children = node.children;
  5693. // opts = ctx.options;
  5694. // FT.debug("nodeRemoveChildren()", node.toString());
  5695. if (!children) {
  5696. return;
  5697. }
  5698. if (this.activeNode && this.activeNode.isDescendantOf(node)) {
  5699. this.activeNode.setActive(false); // TODO: don't fire events
  5700. }
  5701. if (this.focusNode && this.focusNode.isDescendantOf(node)) {
  5702. this.focusNode = null;
  5703. }
  5704. // TODO: persist must take care to clear select and expand cookies
  5705. this.nodeRemoveChildMarkup(ctx);
  5706. // Unlink children to support GC
  5707. // TODO: also delete this.children (not possible using visit())
  5708. // subCtx = $.extend({}, ctx);
  5709. node.triggerModifyChild("remove", null);
  5710. node.visit(function(n) {
  5711. n.parent = null;
  5712. tree._callHook("treeRegisterNode", tree, false, n);
  5713. });
  5714. if (node.lazy) {
  5715. // 'undefined' would be interpreted as 'not yet loaded' for lazy nodes
  5716. node.children = [];
  5717. } else {
  5718. node.children = null;
  5719. }
  5720. if (!node.isRootNode()) {
  5721. node.expanded = false; // #449, #459
  5722. }
  5723. this.nodeRenderStatus(ctx);
  5724. },
  5725. /**Remove HTML markup for ctx.node and all its descendents.
  5726. * @param {EventData} ctx
  5727. */
  5728. nodeRemoveMarkup: function(ctx) {
  5729. var node = ctx.node;
  5730. // FT.debug("nodeRemoveMarkup()", node.toString());
  5731. // TODO: Unlink attr.ftnode to support GC
  5732. if (node.li) {
  5733. $(node.li).remove();
  5734. node.li = null;
  5735. }
  5736. this.nodeRemoveChildMarkup(ctx);
  5737. },
  5738. /**
  5739. * Create `<li><span>..</span> .. </li>` tags for this node.
  5740. *
  5741. * This method takes care that all HTML markup is created that is required
  5742. * to display this node in its current state.
  5743. *
  5744. * Call this method to create new nodes, or after the strucuture
  5745. * was changed (e.g. after moving this node or adding/removing children)
  5746. * nodeRenderTitle() and nodeRenderStatus() are implied.
  5747. *
  5748. * ```html
  5749. * <li id='KEY' ftnode=NODE>
  5750. * <span class='fancytree-node fancytree-expanded fancytree-has-children fancytree-lastsib fancytree-exp-el fancytree-ico-e'>
  5751. * <span class="fancytree-expander"></span>
  5752. * <span class="fancytree-checkbox"></span> // only present in checkbox mode
  5753. * <span class="fancytree-icon"></span>
  5754. * <a href="#" class="fancytree-title"> Node 1 </a>
  5755. * </span>
  5756. * <ul> // only present if node has children
  5757. * <li id='KEY' ftnode=NODE> child1 ... </li>
  5758. * <li id='KEY' ftnode=NODE> child2 ... </li>
  5759. * </ul>
  5760. * </li>
  5761. * ```
  5762. *
  5763. * @param {EventData} ctx
  5764. * @param {boolean} [force=false] re-render, even if html markup was already created
  5765. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  5766. * @param {boolean} [collapsed=false] force root node to be collapsed, so we can apply animated expand later
  5767. */
  5768. nodeRender: function(ctx, force, deep, collapsed, _recursive) {
  5769. /* This method must take care of all cases where the current data mode
  5770. * (i.e. node hierarchy) does not match the current markup.
  5771. *
  5772. * - node was not yet rendered:
  5773. * create markup
  5774. * - node was rendered: exit fast
  5775. * - children have been added
  5776. * - children have been removed
  5777. */
  5778. var childLI,
  5779. childNode1,
  5780. childNode2,
  5781. i,
  5782. l,
  5783. next,
  5784. subCtx,
  5785. node = ctx.node,
  5786. tree = ctx.tree,
  5787. opts = ctx.options,
  5788. aria = opts.aria,
  5789. firstTime = false,
  5790. parent = node.parent,
  5791. isRootNode = !parent,
  5792. children = node.children,
  5793. successorLi = null;
  5794. // FT.debug("nodeRender(" + !!force + ", " + !!deep + ")", node.toString());
  5795. if (tree._enableUpdate === false) {
  5796. // tree.debug("no render", tree._enableUpdate);
  5797. return;
  5798. }
  5799. if (!isRootNode && !parent.ul) {
  5800. // Calling node.collapse on a deep, unrendered node
  5801. return;
  5802. }
  5803. _assert(isRootNode || parent.ul, "parent UL must exist");
  5804. // Render the node
  5805. if (!isRootNode) {
  5806. // Discard markup on force-mode, or if it is not linked to parent <ul>
  5807. if (
  5808. node.li &&
  5809. (force || node.li.parentNode !== node.parent.ul)
  5810. ) {
  5811. if (node.li.parentNode === node.parent.ul) {
  5812. // #486: store following node, so we can insert the new markup there later
  5813. successorLi = node.li.nextSibling;
  5814. } else {
  5815. // May happen, when a top-level node was dropped over another
  5816. this.debug(
  5817. "Unlinking " +
  5818. node +
  5819. " (must be child of " +
  5820. node.parent +
  5821. ")"
  5822. );
  5823. }
  5824. // this.debug("nodeRemoveMarkup...");
  5825. this.nodeRemoveMarkup(ctx);
  5826. }
  5827. // Create <li><span /> </li>
  5828. // node.debug("render...");
  5829. if (node.li) {
  5830. // this.nodeRenderTitle(ctx);
  5831. this.nodeRenderStatus(ctx);
  5832. } else {
  5833. // node.debug("render... really");
  5834. firstTime = true;
  5835. node.li = document.createElement("li");
  5836. node.li.ftnode = node;
  5837. if (node.key && opts.generateIds) {
  5838. node.li.id = opts.idPrefix + node.key;
  5839. }
  5840. node.span = document.createElement("span");
  5841. node.span.className = "fancytree-node";
  5842. if (aria && !node.tr) {
  5843. $(node.li).attr("role", "treeitem");
  5844. }
  5845. node.li.appendChild(node.span);
  5846. // Create inner HTML for the <span> (expander, checkbox, icon, and title)
  5847. this.nodeRenderTitle(ctx);
  5848. // Allow tweaking and binding, after node was created for the first time
  5849. if (opts.createNode) {
  5850. opts.createNode.call(
  5851. tree,
  5852. { type: "createNode" },
  5853. ctx
  5854. );
  5855. }
  5856. }
  5857. // Allow tweaking after node state was rendered
  5858. if (opts.renderNode) {
  5859. opts.renderNode.call(tree, { type: "renderNode" }, ctx);
  5860. }
  5861. }
  5862. // Visit child nodes
  5863. if (children) {
  5864. if (isRootNode || node.expanded || deep === true) {
  5865. // Create a UL to hold the children
  5866. if (!node.ul) {
  5867. node.ul = document.createElement("ul");
  5868. if (
  5869. (collapsed === true && !_recursive) ||
  5870. !node.expanded
  5871. ) {
  5872. // hide top UL, so we can use an animation to show it later
  5873. node.ul.style.display = "none";
  5874. }
  5875. if (aria) {
  5876. $(node.ul).attr("role", "group");
  5877. }
  5878. if (node.li) {
  5879. // issue #67
  5880. node.li.appendChild(node.ul);
  5881. } else {
  5882. node.tree.$div.append(node.ul);
  5883. }
  5884. }
  5885. // Add child markup
  5886. for (i = 0, l = children.length; i < l; i++) {
  5887. subCtx = $.extend({}, ctx, { node: children[i] });
  5888. this.nodeRender(subCtx, force, deep, false, true);
  5889. }
  5890. // Remove <li> if nodes have moved to another parent
  5891. childLI = node.ul.firstChild;
  5892. while (childLI) {
  5893. childNode2 = childLI.ftnode;
  5894. if (childNode2 && childNode2.parent !== node) {
  5895. node.debug(
  5896. "_fixParent: remove missing " + childNode2,
  5897. childLI
  5898. );
  5899. next = childLI.nextSibling;
  5900. childLI.parentNode.removeChild(childLI);
  5901. childLI = next;
  5902. } else {
  5903. childLI = childLI.nextSibling;
  5904. }
  5905. }
  5906. // Make sure, that <li> order matches node.children order.
  5907. childLI = node.ul.firstChild;
  5908. for (i = 0, l = children.length - 1; i < l; i++) {
  5909. childNode1 = children[i];
  5910. childNode2 = childLI.ftnode;
  5911. if (childNode1 === childNode2) {
  5912. childLI = childLI.nextSibling;
  5913. } else {
  5914. // node.debug("_fixOrder: mismatch at index " + i + ": " + childNode1 + " != " + childNode2);
  5915. node.ul.insertBefore(
  5916. childNode1.li,
  5917. childNode2.li
  5918. );
  5919. }
  5920. }
  5921. }
  5922. } else {
  5923. // No children: remove markup if any
  5924. if (node.ul) {
  5925. // alert("remove child markup for " + node);
  5926. this.warn("remove child markup for " + node);
  5927. this.nodeRemoveChildMarkup(ctx);
  5928. }
  5929. }
  5930. if (!isRootNode) {
  5931. // Update element classes according to node state
  5932. // this.nodeRenderStatus(ctx);
  5933. // Finally add the whole structure to the DOM, so the browser can render
  5934. if (firstTime) {
  5935. // #486: successorLi is set, if we re-rendered (i.e. discarded)
  5936. // existing markup, which we want to insert at the same position.
  5937. // (null is equivalent to append)
  5938. // parent.ul.appendChild(node.li);
  5939. parent.ul.insertBefore(node.li, successorLi);
  5940. }
  5941. }
  5942. },
  5943. /** Create HTML inside the node's outer `<span>` (i.e. expander, checkbox,
  5944. * icon, and title).
  5945. *
  5946. * nodeRenderStatus() is implied.
  5947. * @param {EventData} ctx
  5948. * @param {string} [title] optinal new title
  5949. */
  5950. nodeRenderTitle: function(ctx, title) {
  5951. // set node connector images, links and text
  5952. var checkbox,
  5953. className,
  5954. icon,
  5955. nodeTitle,
  5956. role,
  5957. tabindex,
  5958. tooltip,
  5959. iconTooltip,
  5960. node = ctx.node,
  5961. tree = ctx.tree,
  5962. opts = ctx.options,
  5963. aria = opts.aria,
  5964. level = node.getLevel(),
  5965. ares = [];
  5966. if (title !== undefined) {
  5967. node.title = title;
  5968. }
  5969. if (!node.span || tree._enableUpdate === false) {
  5970. // Silently bail out if node was not rendered yet, assuming
  5971. // node.render() will be called as the node becomes visible
  5972. return;
  5973. }
  5974. // Connector (expanded, expandable or simple)
  5975. role =
  5976. aria && node.hasChildren() !== false
  5977. ? " role='button'"
  5978. : "";
  5979. if (level < opts.minExpandLevel) {
  5980. if (!node.lazy) {
  5981. node.expanded = true;
  5982. }
  5983. if (level > 1) {
  5984. ares.push(
  5985. "<span " +
  5986. role +
  5987. " class='fancytree-expander fancytree-expander-fixed'></span>"
  5988. );
  5989. }
  5990. // .. else (i.e. for root level) skip expander/connector alltogether
  5991. } else {
  5992. ares.push(
  5993. "<span " + role + " class='fancytree-expander'></span>"
  5994. );
  5995. }
  5996. // Checkbox mode
  5997. checkbox = FT.evalOption("checkbox", node, node, opts, false);
  5998. if (checkbox && !node.isStatusNode()) {
  5999. role = aria ? " role='checkbox'" : "";
  6000. className = "fancytree-checkbox";
  6001. if (
  6002. checkbox === "radio" ||
  6003. (node.parent && node.parent.radiogroup)
  6004. ) {
  6005. className += " fancytree-radio";
  6006. }
  6007. ares.push(
  6008. "<span " + role + " class='" + className + "'></span>"
  6009. );
  6010. }
  6011. // Folder or doctype icon
  6012. if (node.data.iconClass !== undefined) {
  6013. // 2015-11-16
  6014. // Handle / warn about backward compatibility
  6015. if (node.icon) {
  6016. $.error(
  6017. "'iconClass' node option is deprecated since v2.14.0: use 'icon' only instead"
  6018. );
  6019. } else {
  6020. node.warn(
  6021. "'iconClass' node option is deprecated since v2.14.0: use 'icon' instead"
  6022. );
  6023. node.icon = node.data.iconClass;
  6024. }
  6025. }
  6026. // If opts.icon is a callback and returns something other than undefined, use that
  6027. // else if node.icon is a boolean or string, use that
  6028. // else if opts.icon is a boolean or string, use that
  6029. // else show standard icon (which may be different for folders or documents)
  6030. icon = FT.evalOption("icon", node, node, opts, true);
  6031. // if( typeof icon !== "boolean" ) {
  6032. // // icon is defined, but not true/false: must be a string
  6033. // icon = "" + icon;
  6034. // }
  6035. if (icon !== false) {
  6036. role = aria ? " role='presentation'" : "";
  6037. iconTooltip = FT.evalOption(
  6038. "iconTooltip",
  6039. node,
  6040. node,
  6041. opts,
  6042. null
  6043. );
  6044. iconTooltip = iconTooltip
  6045. ? " title='" + _escapeTooltip(iconTooltip) + "'"
  6046. : "";
  6047. if (typeof icon === "string") {
  6048. if (TEST_IMG.test(icon)) {
  6049. // node.icon is an image url. Prepend imagePath
  6050. icon =
  6051. icon.charAt(0) === "/"
  6052. ? icon
  6053. : (opts.imagePath || "") + icon;
  6054. ares.push(
  6055. "<img src='" +
  6056. icon +
  6057. "' class='fancytree-icon'" +
  6058. iconTooltip +
  6059. " alt='' />"
  6060. );
  6061. } else {
  6062. ares.push(
  6063. "<span " +
  6064. role +
  6065. " class='fancytree-custom-icon " +
  6066. icon +
  6067. "'" +
  6068. iconTooltip +
  6069. "></span>"
  6070. );
  6071. }
  6072. } else if (icon.text) {
  6073. ares.push(
  6074. "<span " +
  6075. role +
  6076. " class='fancytree-custom-icon " +
  6077. (icon.addClass || "") +
  6078. "'" +
  6079. iconTooltip +
  6080. ">" +
  6081. FT.escapeHtml(icon.text) +
  6082. "</span>"
  6083. );
  6084. } else if (icon.html) {
  6085. ares.push(
  6086. "<span " +
  6087. role +
  6088. " class='fancytree-custom-icon " +
  6089. (icon.addClass || "") +
  6090. "'" +
  6091. iconTooltip +
  6092. ">" +
  6093. icon.html +
  6094. "</span>"
  6095. );
  6096. } else {
  6097. // standard icon: theme css will take care of this
  6098. ares.push(
  6099. "<span " +
  6100. role +
  6101. " class='fancytree-icon'" +
  6102. iconTooltip +
  6103. "></span>"
  6104. );
  6105. }
  6106. }
  6107. // Node title
  6108. nodeTitle = "";
  6109. if (opts.renderTitle) {
  6110. nodeTitle =
  6111. opts.renderTitle.call(
  6112. tree,
  6113. { type: "renderTitle" },
  6114. ctx
  6115. ) || "";
  6116. }
  6117. if (!nodeTitle) {
  6118. tooltip = FT.evalOption("tooltip", node, node, opts, null);
  6119. if (tooltip === true) {
  6120. tooltip = node.title;
  6121. }
  6122. // if( node.tooltip ) {
  6123. // tooltip = node.tooltip;
  6124. // } else if ( opts.tooltip ) {
  6125. // tooltip = opts.tooltip === true ? node.title : opts.tooltip.call(tree, node);
  6126. // }
  6127. tooltip = tooltip
  6128. ? " title='" + _escapeTooltip(tooltip) + "'"
  6129. : "";
  6130. tabindex = opts.titlesTabbable ? " tabindex='0'" : "";
  6131. nodeTitle =
  6132. "<span class='fancytree-title'" +
  6133. tooltip +
  6134. tabindex +
  6135. ">" +
  6136. (opts.escapeTitles
  6137. ? FT.escapeHtml(node.title)
  6138. : node.title) +
  6139. "</span>";
  6140. }
  6141. ares.push(nodeTitle);
  6142. // Note: this will trigger focusout, if node had the focus
  6143. //$(node.span).html(ares.join("")); // it will cleanup the jQuery data currently associated with SPAN (if any), but it executes more slowly
  6144. node.span.innerHTML = ares.join("");
  6145. // Update CSS classes
  6146. this.nodeRenderStatus(ctx);
  6147. if (opts.enhanceTitle) {
  6148. ctx.$title = $(">span.fancytree-title", node.span);
  6149. nodeTitle =
  6150. opts.enhanceTitle.call(
  6151. tree,
  6152. { type: "enhanceTitle" },
  6153. ctx
  6154. ) || "";
  6155. }
  6156. },
  6157. /** Update element classes according to node state.
  6158. * @param {EventData} ctx
  6159. */
  6160. nodeRenderStatus: function(ctx) {
  6161. // Set classes for current status
  6162. var $ariaElem,
  6163. node = ctx.node,
  6164. tree = ctx.tree,
  6165. opts = ctx.options,
  6166. // nodeContainer = node[tree.nodeContainerAttrName],
  6167. hasChildren = node.hasChildren(),
  6168. isLastSib = node.isLastSibling(),
  6169. aria = opts.aria,
  6170. cn = opts._classNames,
  6171. cnList = [],
  6172. statusElem = node[tree.statusClassPropName];
  6173. if (!statusElem || tree._enableUpdate === false) {
  6174. // if this function is called for an unrendered node, ignore it (will be updated on nect render anyway)
  6175. return;
  6176. }
  6177. if (aria) {
  6178. $ariaElem = $(node.tr || node.li);
  6179. }
  6180. // Build a list of class names that we will add to the node <span>
  6181. cnList.push(cn.node);
  6182. if (tree.activeNode === node) {
  6183. cnList.push(cn.active);
  6184. // $(">span.fancytree-title", statusElem).attr("tabindex", "0");
  6185. // tree.$container.removeAttr("tabindex");
  6186. // }else{
  6187. // $(">span.fancytree-title", statusElem).removeAttr("tabindex");
  6188. // tree.$container.attr("tabindex", "0");
  6189. }
  6190. if (tree.focusNode === node) {
  6191. cnList.push(cn.focused);
  6192. }
  6193. if (node.expanded) {
  6194. cnList.push(cn.expanded);
  6195. }
  6196. if (aria) {
  6197. if (hasChildren === false) {
  6198. $ariaElem.removeAttr("aria-expanded");
  6199. } else {
  6200. $ariaElem.attr("aria-expanded", Boolean(node.expanded));
  6201. }
  6202. }
  6203. if (node.folder) {
  6204. cnList.push(cn.folder);
  6205. }
  6206. if (hasChildren !== false) {
  6207. cnList.push(cn.hasChildren);
  6208. }
  6209. // TODO: required?
  6210. if (isLastSib) {
  6211. cnList.push(cn.lastsib);
  6212. }
  6213. if (node.lazy && node.children == null) {
  6214. cnList.push(cn.lazy);
  6215. }
  6216. if (node.partload) {
  6217. cnList.push(cn.partload);
  6218. }
  6219. if (node.partsel) {
  6220. cnList.push(cn.partsel);
  6221. }
  6222. if (FT.evalOption("unselectable", node, node, opts, false)) {
  6223. cnList.push(cn.unselectable);
  6224. }
  6225. if (node._isLoading) {
  6226. cnList.push(cn.loading);
  6227. }
  6228. if (node._error) {
  6229. cnList.push(cn.error);
  6230. }
  6231. if (node.statusNodeType) {
  6232. cnList.push(cn.statusNodePrefix + node.statusNodeType);
  6233. }
  6234. if (node.selected) {
  6235. cnList.push(cn.selected);
  6236. if (aria) {
  6237. $ariaElem.attr("aria-selected", true);
  6238. }
  6239. } else if (aria) {
  6240. $ariaElem.attr("aria-selected", false);
  6241. }
  6242. if (node.extraClasses) {
  6243. cnList.push(node.extraClasses);
  6244. }
  6245. // IE6 doesn't correctly evaluate multiple class names,
  6246. // so we create combined class names that can be used in the CSS
  6247. if (hasChildren === false) {
  6248. cnList.push(
  6249. cn.combinedExpanderPrefix + "n" + (isLastSib ? "l" : "")
  6250. );
  6251. } else {
  6252. cnList.push(
  6253. cn.combinedExpanderPrefix +
  6254. (node.expanded ? "e" : "c") +
  6255. (node.lazy && node.children == null ? "d" : "") +
  6256. (isLastSib ? "l" : "")
  6257. );
  6258. }
  6259. cnList.push(
  6260. cn.combinedIconPrefix +
  6261. (node.expanded ? "e" : "c") +
  6262. (node.folder ? "f" : "")
  6263. );
  6264. // node.span.className = cnList.join(" ");
  6265. statusElem.className = cnList.join(" ");
  6266. // TODO: we should not set this in the <span> tag also, if we set it here:
  6267. // Maybe most (all) of the classes should be set in LI instead of SPAN?
  6268. if (node.li) {
  6269. // #719: we have to consider that there may be already other classes:
  6270. $(node.li).toggleClass(cn.lastsib, isLastSib);
  6271. }
  6272. },
  6273. /** Activate node.
  6274. * flag defaults to true.
  6275. * If flag is true, the node is activated (must be a synchronous operation)
  6276. * If flag is false, the node is deactivated (must be a synchronous operation)
  6277. * @param {EventData} ctx
  6278. * @param {boolean} [flag=true]
  6279. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  6280. * @returns {$.Promise}
  6281. */
  6282. nodeSetActive: function(ctx, flag, callOpts) {
  6283. // Handle user click / [space] / [enter], according to clickFolderMode.
  6284. callOpts = callOpts || {};
  6285. var subCtx,
  6286. node = ctx.node,
  6287. tree = ctx.tree,
  6288. opts = ctx.options,
  6289. noEvents = callOpts.noEvents === true,
  6290. noFocus = callOpts.noFocus === true,
  6291. scroll = callOpts.scrollIntoView !== false,
  6292. isActive = node === tree.activeNode;
  6293. // flag defaults to true
  6294. flag = flag !== false;
  6295. // node.debug("nodeSetActive", flag);
  6296. if (isActive === flag) {
  6297. // Nothing to do
  6298. return _getResolvedPromise(node);
  6299. }
  6300. // #1042: don't scroll between mousedown/-up when clicking an embedded link
  6301. if (
  6302. scroll &&
  6303. ctx.originalEvent &&
  6304. $(ctx.originalEvent.target).is("a,:checkbox")
  6305. ) {
  6306. node.info("Not scrolling while clicking an embedded link.");
  6307. scroll = false;
  6308. }
  6309. if (
  6310. flag &&
  6311. !noEvents &&
  6312. this._triggerNodeEvent(
  6313. "beforeActivate",
  6314. node,
  6315. ctx.originalEvent
  6316. ) === false
  6317. ) {
  6318. // Callback returned false
  6319. return _getRejectedPromise(node, ["rejected"]);
  6320. }
  6321. if (flag) {
  6322. if (tree.activeNode) {
  6323. _assert(
  6324. tree.activeNode !== node,
  6325. "node was active (inconsistency)"
  6326. );
  6327. subCtx = $.extend({}, ctx, { node: tree.activeNode });
  6328. tree.nodeSetActive(subCtx, false);
  6329. _assert(
  6330. tree.activeNode === null,
  6331. "deactivate was out of sync?"
  6332. );
  6333. }
  6334. if (opts.activeVisible) {
  6335. // If no focus is set (noFocus: true) and there is no focused node, this node is made visible.
  6336. // scroll = noFocus && tree.focusNode == null;
  6337. // #863: scroll by default (unless `scrollIntoView: false` was passed)
  6338. node.makeVisible({ scrollIntoView: scroll });
  6339. }
  6340. tree.activeNode = node;
  6341. tree.nodeRenderStatus(ctx);
  6342. if (!noFocus) {
  6343. tree.nodeSetFocus(ctx);
  6344. }
  6345. if (!noEvents) {
  6346. tree._triggerNodeEvent(
  6347. "activate",
  6348. node,
  6349. ctx.originalEvent
  6350. );
  6351. }
  6352. } else {
  6353. _assert(
  6354. tree.activeNode === node,
  6355. "node was not active (inconsistency)"
  6356. );
  6357. tree.activeNode = null;
  6358. this.nodeRenderStatus(ctx);
  6359. if (!noEvents) {
  6360. ctx.tree._triggerNodeEvent(
  6361. "deactivate",
  6362. node,
  6363. ctx.originalEvent
  6364. );
  6365. }
  6366. }
  6367. return _getResolvedPromise(node);
  6368. },
  6369. /** Expand or collapse node, return Deferred.promise.
  6370. *
  6371. * @param {EventData} ctx
  6372. * @param {boolean} [flag=true]
  6373. * @param {object} [opts] additional options. Defaults to `{noAnimation: false, noEvents: false}`
  6374. * @returns {$.Promise} The deferred will be resolved as soon as the (lazy)
  6375. * data was retrieved, rendered, and the expand animation finished.
  6376. */
  6377. nodeSetExpanded: function(ctx, flag, callOpts) {
  6378. callOpts = callOpts || {};
  6379. var _afterLoad,
  6380. dfd,
  6381. i,
  6382. l,
  6383. parents,
  6384. prevAC,
  6385. node = ctx.node,
  6386. tree = ctx.tree,
  6387. opts = ctx.options,
  6388. noAnimation = callOpts.noAnimation === true,
  6389. noEvents = callOpts.noEvents === true;
  6390. // flag defaults to true
  6391. flag = flag !== false;
  6392. // node.debug("nodeSetExpanded(" + flag + ")");
  6393. if ($(node.li).hasClass(opts._classNames.animating)) {
  6394. node.warn(
  6395. "setExpanded(" + flag + ") while animating: ignored."
  6396. );
  6397. return _getRejectedPromise(node, ["recursion"]);
  6398. }
  6399. if ((node.expanded && flag) || (!node.expanded && !flag)) {
  6400. // Nothing to do
  6401. // node.debug("nodeSetExpanded(" + flag + "): nothing to do");
  6402. return _getResolvedPromise(node);
  6403. } else if (flag && !node.lazy && !node.hasChildren()) {
  6404. // Prevent expanding of empty nodes
  6405. // return _getRejectedPromise(node, ["empty"]);
  6406. return _getResolvedPromise(node);
  6407. } else if (!flag && node.getLevel() < opts.minExpandLevel) {
  6408. // Prevent collapsing locked levels
  6409. return _getRejectedPromise(node, ["locked"]);
  6410. } else if (
  6411. !noEvents &&
  6412. this._triggerNodeEvent(
  6413. "beforeExpand",
  6414. node,
  6415. ctx.originalEvent
  6416. ) === false
  6417. ) {
  6418. // Callback returned false
  6419. return _getRejectedPromise(node, ["rejected"]);
  6420. }
  6421. // If this node inside a collpased node, no animation and scrolling is needed
  6422. if (!noAnimation && !node.isVisible()) {
  6423. noAnimation = callOpts.noAnimation = true;
  6424. }
  6425. dfd = new $.Deferred();
  6426. // Auto-collapse mode: collapse all siblings
  6427. if (flag && !node.expanded && opts.autoCollapse) {
  6428. parents = node.getParentList(false, true);
  6429. prevAC = opts.autoCollapse;
  6430. try {
  6431. opts.autoCollapse = false;
  6432. for (i = 0, l = parents.length; i < l; i++) {
  6433. // TODO: should return promise?
  6434. this._callHook(
  6435. "nodeCollapseSiblings",
  6436. parents[i],
  6437. callOpts
  6438. );
  6439. }
  6440. } finally {
  6441. opts.autoCollapse = prevAC;
  6442. }
  6443. }
  6444. // Trigger expand/collapse after expanding
  6445. dfd.done(function() {
  6446. var lastChild = node.getLastChild();
  6447. if (
  6448. flag &&
  6449. opts.autoScroll &&
  6450. !noAnimation &&
  6451. lastChild &&
  6452. tree._enableUpdate
  6453. ) {
  6454. // Scroll down to last child, but keep current node visible
  6455. lastChild
  6456. .scrollIntoView(true, { topNode: node })
  6457. .always(function() {
  6458. if (!noEvents) {
  6459. ctx.tree._triggerNodeEvent(
  6460. flag ? "expand" : "collapse",
  6461. ctx
  6462. );
  6463. }
  6464. });
  6465. } else {
  6466. if (!noEvents) {
  6467. ctx.tree._triggerNodeEvent(
  6468. flag ? "expand" : "collapse",
  6469. ctx
  6470. );
  6471. }
  6472. }
  6473. });
  6474. // vvv Code below is executed after loading finished:
  6475. _afterLoad = function(callback) {
  6476. var cn = opts._classNames,
  6477. isVisible,
  6478. isExpanded,
  6479. effect = opts.toggleEffect;
  6480. node.expanded = flag;
  6481. tree._callHook(
  6482. "treeStructureChanged",
  6483. ctx,
  6484. flag ? "expand" : "collapse"
  6485. );
  6486. // Create required markup, but make sure the top UL is hidden, so we
  6487. // can animate later
  6488. tree._callHook("nodeRender", ctx, false, false, true);
  6489. // Hide children, if node is collapsed
  6490. if (node.ul) {
  6491. isVisible = node.ul.style.display !== "none";
  6492. isExpanded = !!node.expanded;
  6493. if (isVisible === isExpanded) {
  6494. node.warn(
  6495. "nodeSetExpanded: UL.style.display already set"
  6496. );
  6497. } else if (!effect || noAnimation) {
  6498. node.ul.style.display =
  6499. node.expanded || !parent ? "" : "none";
  6500. } else {
  6501. // The UI toggle() effect works with the ext-wide extension,
  6502. // while jQuery.animate() has problems when the title span
  6503. // has position: absolute.
  6504. // Since jQuery UI 1.12, the blind effect requires the parent
  6505. // element to have 'position: relative'.
  6506. // See #716, #717
  6507. $(node.li).addClass(cn.animating); // #717
  6508. if ($.isFunction($(node.ul)[effect.effect])) {
  6509. // tree.debug( "use jquery." + effect.effect + " method" );
  6510. $(node.ul)[effect.effect]({
  6511. duration: effect.duration,
  6512. always: function() {
  6513. // node.debug("fancytree-animating end: " + node.li.className);
  6514. $(this).removeClass(cn.animating); // #716
  6515. $(node.li).removeClass(cn.animating); // #717
  6516. callback();
  6517. },
  6518. });
  6519. } else {
  6520. // The UI toggle() effect works with the ext-wide extension,
  6521. // while jQuery.animate() has problems when the title span
  6522. // has positon: absolute.
  6523. // Since jQuery UI 1.12, the blind effect requires the parent
  6524. // element to have 'position: relative'.
  6525. // See #716, #717
  6526. // tree.debug("use specified effect (" + effect.effect + ") with the jqueryui.toggle method");
  6527. // try to stop an animation that might be already in progress
  6528. $(node.ul).stop(true, true); //< does not work after resetLazy has been called for a node whose animation wasn't complete and effect was "blind"
  6529. // dirty fix to remove a defunct animation (effect: "blind") after resetLazy has been called
  6530. $(node.ul)
  6531. .parent()
  6532. .find(".ui-effects-placeholder")
  6533. .remove();
  6534. $(node.ul).toggle(
  6535. effect.effect,
  6536. effect.options,
  6537. effect.duration,
  6538. function() {
  6539. // node.debug("fancytree-animating end: " + node.li.className);
  6540. $(this).removeClass(cn.animating); // #716
  6541. $(node.li).removeClass(cn.animating); // #717
  6542. callback();
  6543. }
  6544. );
  6545. }
  6546. return;
  6547. }
  6548. }
  6549. callback();
  6550. };
  6551. // ^^^ Code above is executed after loading finshed.
  6552. // Load lazy nodes, if any. Then continue with _afterLoad()
  6553. if (flag && node.lazy && node.hasChildren() === undefined) {
  6554. // node.debug("nodeSetExpanded: load start...");
  6555. node.load()
  6556. .done(function() {
  6557. // node.debug("nodeSetExpanded: load done");
  6558. if (dfd.notifyWith) {
  6559. // requires jQuery 1.6+
  6560. dfd.notifyWith(node, ["loaded"]);
  6561. }
  6562. _afterLoad(function() {
  6563. dfd.resolveWith(node);
  6564. });
  6565. })
  6566. .fail(function(errMsg) {
  6567. _afterLoad(function() {
  6568. dfd.rejectWith(node, [
  6569. "load failed (" + errMsg + ")",
  6570. ]);
  6571. });
  6572. });
  6573. /*
  6574. var source = tree._triggerNodeEvent("lazyLoad", node, ctx.originalEvent);
  6575. _assert(typeof source !== "boolean", "lazyLoad event must return source in data.result");
  6576. node.debug("nodeSetExpanded: load start...");
  6577. this._callHook("nodeLoadChildren", ctx, source).done(function(){
  6578. node.debug("nodeSetExpanded: load done");
  6579. if(dfd.notifyWith){ // requires jQuery 1.6+
  6580. dfd.notifyWith(node, ["loaded"]);
  6581. }
  6582. _afterLoad.call(tree);
  6583. }).fail(function(errMsg){
  6584. dfd.rejectWith(node, ["load failed (" + errMsg + ")"]);
  6585. });
  6586. */
  6587. } else {
  6588. _afterLoad(function() {
  6589. dfd.resolveWith(node);
  6590. });
  6591. }
  6592. // node.debug("nodeSetExpanded: returns");
  6593. return dfd.promise();
  6594. },
  6595. /** Focus or blur this node.
  6596. * @param {EventData} ctx
  6597. * @param {boolean} [flag=true]
  6598. */
  6599. nodeSetFocus: function(ctx, flag) {
  6600. // ctx.node.debug("nodeSetFocus(" + flag + ")");
  6601. var ctx2,
  6602. tree = ctx.tree,
  6603. node = ctx.node,
  6604. opts = tree.options,
  6605. // et = ctx.originalEvent && ctx.originalEvent.type,
  6606. isInput = ctx.originalEvent
  6607. ? $(ctx.originalEvent.target).is(":input")
  6608. : false;
  6609. flag = flag !== false;
  6610. // (node || tree).debug("nodeSetFocus(" + flag + "), event: " + et + ", isInput: "+ isInput);
  6611. // Blur previous node if any
  6612. if (tree.focusNode) {
  6613. if (tree.focusNode === node && flag) {
  6614. // node.debug("nodeSetFocus(" + flag + "): nothing to do");
  6615. return;
  6616. }
  6617. ctx2 = $.extend({}, ctx, { node: tree.focusNode });
  6618. tree.focusNode = null;
  6619. this._triggerNodeEvent("blur", ctx2);
  6620. this._callHook("nodeRenderStatus", ctx2);
  6621. }
  6622. // Set focus to container and node
  6623. if (flag) {
  6624. if (!this.hasFocus()) {
  6625. node.debug("nodeSetFocus: forcing container focus");
  6626. this._callHook("treeSetFocus", ctx, true, {
  6627. calledByNode: true,
  6628. });
  6629. }
  6630. node.makeVisible({ scrollIntoView: false });
  6631. tree.focusNode = node;
  6632. if (opts.titlesTabbable) {
  6633. if (!isInput) {
  6634. // #621
  6635. $(node.span)
  6636. .find(".fancytree-title")
  6637. .focus();
  6638. }
  6639. }
  6640. if (opts.aria) {
  6641. // Set active descendant to node's span ID (create one, if needed)
  6642. $(tree.$container).attr(
  6643. "aria-activedescendant",
  6644. $(node.tr || node.li)
  6645. .uniqueId()
  6646. .attr("id")
  6647. );
  6648. // "ftal_" + opts.idPrefix + node.key);
  6649. }
  6650. // $(node.span).find(".fancytree-title").focus();
  6651. this._triggerNodeEvent("focus", ctx);
  6652. // determine if we have focus on or inside tree container
  6653. var hasFancytreeFocus =
  6654. document.activeElement === tree.$container.get(0) ||
  6655. $(document.activeElement, tree.$container).length >= 1;
  6656. if (!hasFancytreeFocus) {
  6657. // We cannot set KB focus to a node, so use the tree container
  6658. // #563, #570: IE scrolls on every call to .focus(), if the container
  6659. // is partially outside the viewport. So do it only, when absolutely
  6660. // necessary.
  6661. $(tree.$container).focus();
  6662. }
  6663. // if( opts.autoActivate ){
  6664. // tree.nodeSetActive(ctx, true);
  6665. // }
  6666. if (opts.autoScroll) {
  6667. node.scrollIntoView();
  6668. }
  6669. this._callHook("nodeRenderStatus", ctx);
  6670. }
  6671. },
  6672. /** (De)Select node, return new status (sync).
  6673. *
  6674. * @param {EventData} ctx
  6675. * @param {boolean} [flag=true]
  6676. * @param {object} [opts] additional options. Defaults to {noEvents: false,
  6677. * propagateDown: null, propagateUp: null,
  6678. * callback: null,
  6679. * }
  6680. * @returns {boolean} previous status
  6681. */
  6682. nodeSetSelected: function(ctx, flag, callOpts) {
  6683. callOpts = callOpts || {};
  6684. var node = ctx.node,
  6685. tree = ctx.tree,
  6686. opts = ctx.options,
  6687. noEvents = callOpts.noEvents === true,
  6688. parent = node.parent;
  6689. // flag defaults to true
  6690. flag = flag !== false;
  6691. // node.debug("nodeSetSelected(" + flag + ")", ctx);
  6692. // Cannot (de)select unselectable nodes directly (only by propagation or
  6693. // by setting the `.selected` property)
  6694. if (FT.evalOption("unselectable", node, node, opts, false)) {
  6695. return;
  6696. }
  6697. // Remember the user's intent, in case down -> up propagation prevents
  6698. // applying it to node.selected
  6699. node._lastSelectIntent = flag; // Confusing use of '!'
  6700. // Nothing to do?
  6701. if (!!node.selected === flag) {
  6702. if (opts.selectMode === 3 && node.partsel && !flag) {
  6703. // If propagation prevented selecting this node last time, we still
  6704. // want to allow to apply setSelected(false) now
  6705. } else {
  6706. return flag;
  6707. }
  6708. }
  6709. if (
  6710. !noEvents &&
  6711. this._triggerNodeEvent(
  6712. "beforeSelect",
  6713. node,
  6714. ctx.originalEvent
  6715. ) === false
  6716. ) {
  6717. return !!node.selected;
  6718. }
  6719. if (flag && opts.selectMode === 1) {
  6720. // single selection mode (we don't uncheck all tree nodes, for performance reasons)
  6721. if (tree.lastSelectedNode) {
  6722. tree.lastSelectedNode.setSelected(false);
  6723. }
  6724. node.selected = flag;
  6725. } else if (
  6726. opts.selectMode === 3 &&
  6727. parent &&
  6728. !parent.radiogroup &&
  6729. !node.radiogroup
  6730. ) {
  6731. // multi-hierarchical selection mode
  6732. node.selected = flag;
  6733. node.fixSelection3AfterClick(callOpts);
  6734. } else if (parent && parent.radiogroup) {
  6735. node.visitSiblings(function(n) {
  6736. n._changeSelectStatusAttrs(flag && n === node);
  6737. }, true);
  6738. } else {
  6739. // default: selectMode: 2, multi selection mode
  6740. node.selected = flag;
  6741. }
  6742. this.nodeRenderStatus(ctx);
  6743. tree.lastSelectedNode = flag ? node : null;
  6744. if (!noEvents) {
  6745. tree._triggerNodeEvent("select", ctx);
  6746. }
  6747. },
  6748. /** Show node status (ok, loading, error, nodata) using styles and a dummy child node.
  6749. *
  6750. * @param {EventData} ctx
  6751. * @param status
  6752. * @param message
  6753. * @param details
  6754. * @since 2.3
  6755. */
  6756. nodeSetStatus: function(ctx, status, message, details) {
  6757. var node = ctx.node,
  6758. tree = ctx.tree;
  6759. function _clearStatusNode() {
  6760. // Remove dedicated dummy node, if any
  6761. var firstChild = node.children ? node.children[0] : null;
  6762. if (firstChild && firstChild.isStatusNode()) {
  6763. try {
  6764. // I've seen exceptions here with loadKeyPath...
  6765. if (node.ul) {
  6766. node.ul.removeChild(firstChild.li);
  6767. firstChild.li = null; // avoid leaks (DT issue 215)
  6768. }
  6769. } catch (e) {}
  6770. if (node.children.length === 1) {
  6771. node.children = [];
  6772. } else {
  6773. node.children.shift();
  6774. }
  6775. tree._callHook(
  6776. "treeStructureChanged",
  6777. ctx,
  6778. "clearStatusNode"
  6779. );
  6780. }
  6781. }
  6782. function _setStatusNode(data, type) {
  6783. // Create/modify the dedicated dummy node for 'loading...' or
  6784. // 'error!' status. (only called for direct child of the invisible
  6785. // system root)
  6786. var firstChild = node.children ? node.children[0] : null;
  6787. if (firstChild && firstChild.isStatusNode()) {
  6788. $.extend(firstChild, data);
  6789. firstChild.statusNodeType = type;
  6790. tree._callHook("nodeRenderTitle", firstChild);
  6791. } else {
  6792. node._setChildren([data]);
  6793. tree._callHook(
  6794. "treeStructureChanged",
  6795. ctx,
  6796. "setStatusNode"
  6797. );
  6798. node.children[0].statusNodeType = type;
  6799. tree.render();
  6800. }
  6801. return node.children[0];
  6802. }
  6803. switch (status) {
  6804. case "ok":
  6805. _clearStatusNode();
  6806. node._isLoading = false;
  6807. node._error = null;
  6808. node.renderStatus();
  6809. break;
  6810. case "loading":
  6811. if (!node.parent) {
  6812. _setStatusNode(
  6813. {
  6814. title:
  6815. tree.options.strings.loading +
  6816. (message ? " (" + message + ")" : ""),
  6817. // icon: true, // needed for 'loding' icon
  6818. checkbox: false,
  6819. tooltip: details,
  6820. },
  6821. status
  6822. );
  6823. }
  6824. node._isLoading = true;
  6825. node._error = null;
  6826. node.renderStatus();
  6827. break;
  6828. case "error":
  6829. _setStatusNode(
  6830. {
  6831. title:
  6832. tree.options.strings.loadError +
  6833. (message ? " (" + message + ")" : ""),
  6834. // icon: false,
  6835. checkbox: false,
  6836. tooltip: details,
  6837. },
  6838. status
  6839. );
  6840. node._isLoading = false;
  6841. node._error = { message: message, details: details };
  6842. node.renderStatus();
  6843. break;
  6844. case "nodata":
  6845. _setStatusNode(
  6846. {
  6847. title: message || tree.options.strings.noData,
  6848. // icon: false,
  6849. checkbox: false,
  6850. tooltip: details,
  6851. },
  6852. status
  6853. );
  6854. node._isLoading = false;
  6855. node._error = null;
  6856. node.renderStatus();
  6857. break;
  6858. default:
  6859. $.error("invalid node status " + status);
  6860. }
  6861. },
  6862. /**
  6863. *
  6864. * @param {EventData} ctx
  6865. */
  6866. nodeToggleExpanded: function(ctx) {
  6867. return this.nodeSetExpanded(ctx, !ctx.node.expanded);
  6868. },
  6869. /**
  6870. * @param {EventData} ctx
  6871. */
  6872. nodeToggleSelected: function(ctx) {
  6873. var node = ctx.node,
  6874. flag = !node.selected;
  6875. // In selectMode: 3 this node may be unselected+partsel, even if
  6876. // setSelected(true) was called before, due to `unselectable` children.
  6877. // In this case, we now toggle as `setSelected(false)`
  6878. if (
  6879. node.partsel &&
  6880. !node.selected &&
  6881. node._lastSelectIntent === true
  6882. ) {
  6883. flag = false;
  6884. node.selected = true; // so it is not considered 'nothing to do'
  6885. }
  6886. node._lastSelectIntent = flag;
  6887. return this.nodeSetSelected(ctx, flag);
  6888. },
  6889. /** Remove all nodes.
  6890. * @param {EventData} ctx
  6891. */
  6892. treeClear: function(ctx) {
  6893. var tree = ctx.tree;
  6894. tree.activeNode = null;
  6895. tree.focusNode = null;
  6896. tree.$div.find(">ul.fancytree-container").empty();
  6897. // TODO: call destructors and remove reference loops
  6898. tree.rootNode.children = null;
  6899. tree._callHook("treeStructureChanged", ctx, "clear");
  6900. },
  6901. /** Widget was created (called only once, even it re-initialized).
  6902. * @param {EventData} ctx
  6903. */
  6904. treeCreate: function(ctx) {},
  6905. /** Widget was destroyed.
  6906. * @param {EventData} ctx
  6907. */
  6908. treeDestroy: function(ctx) {
  6909. this.$div.find(">ul.fancytree-container").remove();
  6910. if (this.$source) {
  6911. this.$source.removeClass("fancytree-helper-hidden");
  6912. }
  6913. },
  6914. /** Widget was (re-)initialized.
  6915. * @param {EventData} ctx
  6916. */
  6917. treeInit: function(ctx) {
  6918. var tree = ctx.tree,
  6919. opts = tree.options;
  6920. //this.debug("Fancytree.treeInit()");
  6921. // Add container to the TAB chain
  6922. // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  6923. // #577: Allow to set tabindex to "0", "-1" and ""
  6924. tree.$container.attr("tabindex", opts.tabindex);
  6925. // Copy some attributes to tree.data
  6926. $.each(TREE_ATTRS, function(i, attr) {
  6927. if (opts[attr] !== undefined) {
  6928. tree.info("Move option " + attr + " to tree");
  6929. tree[attr] = opts[attr];
  6930. delete opts[attr];
  6931. }
  6932. });
  6933. if (opts.checkboxAutoHide) {
  6934. tree.$container.addClass("fancytree-checkbox-auto-hide");
  6935. }
  6936. if (opts.rtl) {
  6937. tree.$container
  6938. .attr("DIR", "RTL")
  6939. .addClass("fancytree-rtl");
  6940. } else {
  6941. tree.$container
  6942. .removeAttr("DIR")
  6943. .removeClass("fancytree-rtl");
  6944. }
  6945. if (opts.aria) {
  6946. tree.$container.attr("role", "tree");
  6947. if (opts.selectMode !== 1) {
  6948. tree.$container.attr("aria-multiselectable", true);
  6949. }
  6950. }
  6951. this.treeLoad(ctx);
  6952. },
  6953. /** Parse Fancytree from source, as configured in the options.
  6954. * @param {EventData} ctx
  6955. * @param {object} [source] optional new source (use last data otherwise)
  6956. */
  6957. treeLoad: function(ctx, source) {
  6958. var metaData,
  6959. type,
  6960. $ul,
  6961. tree = ctx.tree,
  6962. $container = ctx.widget.element,
  6963. dfd,
  6964. // calling context for root node
  6965. rootCtx = $.extend({}, ctx, { node: this.rootNode });
  6966. if (tree.rootNode.children) {
  6967. this.treeClear(ctx);
  6968. }
  6969. source = source || this.options.source;
  6970. if (!source) {
  6971. type = $container.data("type") || "html";
  6972. switch (type) {
  6973. case "html":
  6974. // There should be an embedded `<ul>` with initial nodes,
  6975. // but another `<ul class='fancytree-container'>` is appended
  6976. // to the tree's <div> on startup anyway.
  6977. $ul = $container
  6978. .find(">ul")
  6979. .not(".fancytree-container")
  6980. .first();
  6981. if ($ul.length) {
  6982. $ul.addClass(
  6983. "ui-fancytree-source fancytree-helper-hidden"
  6984. );
  6985. source = $.ui.fancytree.parseHtml($ul);
  6986. // allow to init tree.data.foo from <ul data-foo=''>
  6987. this.data = $.extend(
  6988. this.data,
  6989. _getElementDataAsDict($ul)
  6990. );
  6991. } else {
  6992. FT.warn(
  6993. "No `source` option was passed and container does not contain `<ul>`: assuming `source: []`."
  6994. );
  6995. source = [];
  6996. }
  6997. break;
  6998. case "json":
  6999. source = $.parseJSON($container.text());
  7000. // $container already contains the <ul>, but we remove the plain (json) text
  7001. // $container.empty();
  7002. $container
  7003. .contents()
  7004. .filter(function() {
  7005. return this.nodeType === 3;
  7006. })
  7007. .remove();
  7008. if ($.isPlainObject(source)) {
  7009. // We got {foo: 'abc', children: [...]}
  7010. _assert(
  7011. $.isArray(source.children),
  7012. "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')"
  7013. );
  7014. metaData = source;
  7015. source = source.children;
  7016. delete metaData.children;
  7017. // Copy some attributes to tree.data
  7018. $.each(TREE_ATTRS, function(i, attr) {
  7019. if (metaData[attr] !== undefined) {
  7020. tree[attr] = metaData[attr];
  7021. delete metaData[attr];
  7022. }
  7023. });
  7024. // Copy extra properties to tree.data.foo
  7025. $.extend(tree.data, metaData);
  7026. }
  7027. break;
  7028. default:
  7029. $.error("Invalid data-type: " + type);
  7030. }
  7031. } else if (typeof source === "string") {
  7032. // TODO: source is an element ID
  7033. $.error("Not implemented");
  7034. }
  7035. // preInit is fired when the widget markup is created, but nodes
  7036. // not yet loaded
  7037. tree._triggerTreeEvent("preInit", null);
  7038. // Trigger fancytreeinit after nodes have been loaded
  7039. dfd = this.nodeLoadChildren(rootCtx, source)
  7040. .done(function() {
  7041. tree._callHook(
  7042. "treeStructureChanged",
  7043. ctx,
  7044. "loadChildren"
  7045. );
  7046. tree.render();
  7047. if (ctx.options.selectMode === 3) {
  7048. tree.rootNode.fixSelection3FromEndNodes();
  7049. }
  7050. if (tree.activeNode && tree.options.activeVisible) {
  7051. tree.activeNode.makeVisible();
  7052. }
  7053. tree._triggerTreeEvent("init", null, { status: true });
  7054. })
  7055. .fail(function() {
  7056. tree.render();
  7057. tree._triggerTreeEvent("init", null, { status: false });
  7058. });
  7059. return dfd;
  7060. },
  7061. /** Node was inserted into or removed from the tree.
  7062. * @param {EventData} ctx
  7063. * @param {boolean} add
  7064. * @param {FancytreeNode} node
  7065. */
  7066. treeRegisterNode: function(ctx, add, node) {
  7067. ctx.tree._callHook(
  7068. "treeStructureChanged",
  7069. ctx,
  7070. add ? "addNode" : "removeNode"
  7071. );
  7072. },
  7073. /** Widget got focus.
  7074. * @param {EventData} ctx
  7075. * @param {boolean} [flag=true]
  7076. */
  7077. treeSetFocus: function(ctx, flag, callOpts) {
  7078. var targetNode;
  7079. flag = flag !== false;
  7080. // this.debug("treeSetFocus(" + flag + "), callOpts: ", callOpts, this.hasFocus());
  7081. // this.debug(" focusNode: " + this.focusNode);
  7082. // this.debug(" activeNode: " + this.activeNode);
  7083. if (flag !== this.hasFocus()) {
  7084. this._hasFocus = flag;
  7085. if (!flag && this.focusNode) {
  7086. // Node also looses focus if widget blurs
  7087. this.focusNode.setFocus(false);
  7088. } else if (flag && (!callOpts || !callOpts.calledByNode)) {
  7089. $(this.$container).focus();
  7090. }
  7091. this.$container.toggleClass("fancytree-treefocus", flag);
  7092. this._triggerTreeEvent(flag ? "focusTree" : "blurTree");
  7093. if (flag && !this.activeNode) {
  7094. // #712: Use last mousedowned node ('click' event fires after focusin)
  7095. targetNode =
  7096. this._lastMousedownNode || this.getFirstChild();
  7097. if (targetNode) {
  7098. targetNode.setFocus();
  7099. }
  7100. }
  7101. }
  7102. },
  7103. /** Widget option was set using `$().fancytree("option", "KEY", VALUE)`.
  7104. *
  7105. * Note: `key` may reference a nested option, e.g. 'dnd5.scroll'.
  7106. * In this case `value`contains the complete, modified `dnd5` option hash.
  7107. * We can check for changed values like
  7108. * if( value.scroll !== tree.options.dnd5.scroll ) {...}
  7109. *
  7110. * @param {EventData} ctx
  7111. * @param {string} key option name
  7112. * @param {any} value option value
  7113. */
  7114. treeSetOption: function(ctx, key, value) {
  7115. var tree = ctx.tree,
  7116. callDefault = true,
  7117. callCreate = false,
  7118. callRender = false;
  7119. switch (key) {
  7120. case "aria":
  7121. case "checkbox":
  7122. case "icon":
  7123. case "minExpandLevel":
  7124. case "tabindex":
  7125. // tree._callHook("treeCreate", tree);
  7126. callCreate = true;
  7127. callRender = true;
  7128. break;
  7129. case "checkboxAutoHide":
  7130. tree.$container.toggleClass(
  7131. "fancytree-checkbox-auto-hide",
  7132. !!value
  7133. );
  7134. break;
  7135. case "escapeTitles":
  7136. case "tooltip":
  7137. callRender = true;
  7138. break;
  7139. case "rtl":
  7140. if (value === false) {
  7141. tree.$container
  7142. .removeAttr("DIR")
  7143. .removeClass("fancytree-rtl");
  7144. } else {
  7145. tree.$container
  7146. .attr("DIR", "RTL")
  7147. .addClass("fancytree-rtl");
  7148. }
  7149. callRender = true;
  7150. break;
  7151. case "source":
  7152. callDefault = false;
  7153. tree._callHook("treeLoad", tree, value);
  7154. callRender = true;
  7155. break;
  7156. }
  7157. tree.debug(
  7158. "set option " +
  7159. key +
  7160. "=" +
  7161. value +
  7162. " <" +
  7163. typeof value +
  7164. ">"
  7165. );
  7166. if (callDefault) {
  7167. if (this.widget._super) {
  7168. // jQuery UI 1.9+
  7169. this.widget._super.call(this.widget, key, value);
  7170. } else {
  7171. // jQuery UI <= 1.8, we have to manually invoke the _setOption method from the base widget
  7172. $.Widget.prototype._setOption.call(
  7173. this.widget,
  7174. key,
  7175. value
  7176. );
  7177. }
  7178. }
  7179. if (callCreate) {
  7180. tree._callHook("treeCreate", tree);
  7181. }
  7182. if (callRender) {
  7183. tree.render(true, false); // force, not-deep
  7184. }
  7185. },
  7186. /** A Node was added, removed, moved, or it's visibility changed.
  7187. * @param {EventData} ctx
  7188. */
  7189. treeStructureChanged: function(ctx, type) {},
  7190. }
  7191. );
  7192. /*******************************************************************************
  7193. * jQuery UI widget boilerplate
  7194. */
  7195. /**
  7196. * The plugin (derrived from [jQuery.Widget](http://api.jqueryui.com/jQuery.widget/)).
  7197. *
  7198. * **Note:**
  7199. * These methods implement the standard jQuery UI widget API.
  7200. * It is recommended to use methods of the {Fancytree} instance instead
  7201. *
  7202. * @example
  7203. * // DEPRECATED: Access jQuery UI widget methods and members:
  7204. * var tree = $("#tree").fancytree("getTree", "#myTree");
  7205. * var node = $.ui.fancytree.getTree("#tree").getActiveNode();
  7206. *
  7207. * // RECOMMENDED: Use the Fancytree object API
  7208. * var tree = $.ui.fancytree.getTree("#myTree");
  7209. * var node = tree.getActiveNode();
  7210. *
  7211. * // or you may already have stored the tree instance upon creation:
  7212. * import {createTree, version} from 'jquery.fancytree'
  7213. * const tree = createTree('#tree', { ... });
  7214. * var node = tree.getActiveNode();
  7215. *
  7216. * @see {Fancytree_Static#getTree}
  7217. * @deprecated Use methods of the {Fancytree} instance instead
  7218. * @mixin Fancytree_Widget
  7219. */
  7220. $.widget(
  7221. "ui.fancytree",
  7222. /** @lends Fancytree_Widget# */
  7223. {
  7224. /**These options will be used as defaults
  7225. * @type {FancytreeOptions}
  7226. */
  7227. options: {
  7228. activeVisible: true,
  7229. ajax: {
  7230. type: "GET",
  7231. cache: false, // false: Append random '_' argument to the request url to prevent caching.
  7232. // timeout: 0, // >0: Make sure we get an ajax error if server is unreachable
  7233. dataType: "json", // Expect json format and pass json object to callbacks.
  7234. },
  7235. aria: true,
  7236. autoActivate: true,
  7237. autoCollapse: false,
  7238. autoScroll: false,
  7239. checkbox: false,
  7240. clickFolderMode: 4,
  7241. copyFunctionsToData: false,
  7242. debugLevel: null, // 0..4 (null: use global setting $.ui.fancytree.debugLevel)
  7243. disabled: false, // TODO: required anymore?
  7244. enableAspx: 42, // TODO: this is truethy, but distinguishable from true: default will change to false in the future
  7245. escapeTitles: false,
  7246. extensions: [],
  7247. focusOnSelect: false,
  7248. generateIds: false,
  7249. icon: true,
  7250. idPrefix: "ft_",
  7251. keyboard: true,
  7252. keyPathSeparator: "/",
  7253. minExpandLevel: 1,
  7254. nodata: true, // (bool, string, or callback) display message, when no data available
  7255. quicksearch: false,
  7256. rtl: false,
  7257. scrollOfs: { top: 0, bottom: 0 },
  7258. scrollParent: null,
  7259. selectMode: 2,
  7260. strings: {
  7261. loading: "Loading...", // &#8230; would be escaped when escapeTitles is true
  7262. loadError: "Load error!",
  7263. moreData: "More...",
  7264. noData: "No data.",
  7265. },
  7266. tabindex: "0",
  7267. titlesTabbable: false,
  7268. toggleEffect: { effect: "slideToggle", duration: 200 }, //< "toggle" or "slideToggle" to use jQuery instead of jQueryUI for toggleEffect animation
  7269. tooltip: false,
  7270. treeId: null,
  7271. _classNames: {
  7272. active: "fancytree-active",
  7273. animating: "fancytree-animating",
  7274. combinedExpanderPrefix: "fancytree-exp-",
  7275. combinedIconPrefix: "fancytree-ico-",
  7276. error: "fancytree-error",
  7277. expanded: "fancytree-expanded",
  7278. focused: "fancytree-focused",
  7279. folder: "fancytree-folder",
  7280. hasChildren: "fancytree-has-children",
  7281. lastsib: "fancytree-lastsib",
  7282. lazy: "fancytree-lazy",
  7283. loading: "fancytree-loading",
  7284. node: "fancytree-node",
  7285. partload: "fancytree-partload",
  7286. partsel: "fancytree-partsel",
  7287. radio: "fancytree-radio",
  7288. selected: "fancytree-selected",
  7289. statusNodePrefix: "fancytree-statusnode-",
  7290. unselectable: "fancytree-unselectable",
  7291. },
  7292. // events
  7293. lazyLoad: null,
  7294. postProcess: null,
  7295. },
  7296. _deprecationWarning: function(name) {
  7297. var tree = this.tree;
  7298. if (tree && tree.options.debugLevel >= 3) {
  7299. tree.warn(
  7300. "$().fancytree('" +
  7301. name +
  7302. "') is deprecated (see https://wwwendt.de/tech/fancytree/doc/jsdoc/Fancytree_Widget.html"
  7303. );
  7304. }
  7305. },
  7306. /* Set up the widget, Called on first $().fancytree() */
  7307. _create: function() {
  7308. this.tree = new Fancytree(this);
  7309. this.$source =
  7310. this.source || this.element.data("type") === "json"
  7311. ? this.element
  7312. : this.element.find(">ul").first();
  7313. // Subclass Fancytree instance with all enabled extensions
  7314. var extension,
  7315. extName,
  7316. i,
  7317. opts = this.options,
  7318. extensions = opts.extensions,
  7319. base = this.tree;
  7320. for (i = 0; i < extensions.length; i++) {
  7321. extName = extensions[i];
  7322. extension = $.ui.fancytree._extensions[extName];
  7323. if (!extension) {
  7324. $.error(
  7325. "Could not apply extension '" +
  7326. extName +
  7327. "' (it is not registered, did you forget to include it?)"
  7328. );
  7329. }
  7330. // Add extension options as tree.options.EXTENSION
  7331. // _assert(!this.tree.options[extName], "Extension name must not exist as option name: " + extName);
  7332. // console.info("extend " + extName, extension.options, this.tree.options[extName])
  7333. // issue #876: we want to replace custom array-options, not merge them
  7334. this.tree.options[extName] = _simpleDeepMerge(
  7335. {},
  7336. extension.options,
  7337. this.tree.options[extName]
  7338. );
  7339. // this.tree.options[extName] = $.extend(true, {}, extension.options, this.tree.options[extName]);
  7340. // console.info("extend " + extName + " =>", this.tree.options[extName])
  7341. // console.info("extend " + extName + " org default =>", extension.options)
  7342. // Add a namespace tree.ext.EXTENSION, to hold instance data
  7343. _assert(
  7344. this.tree.ext[extName] === undefined,
  7345. "Extension name must not exist as Fancytree.ext attribute: '" +
  7346. extName +
  7347. "'"
  7348. );
  7349. // this.tree[extName] = extension;
  7350. this.tree.ext[extName] = {};
  7351. // Subclass Fancytree methods using proxies.
  7352. _subclassObject(this.tree, base, extension, extName);
  7353. // current extension becomes base for the next extension
  7354. base = extension;
  7355. }
  7356. //
  7357. if (opts.icons !== undefined) {
  7358. // 2015-11-16
  7359. if (opts.icon === true) {
  7360. this.tree.warn(
  7361. "'icons' tree option is deprecated since v2.14.0: use 'icon' instead"
  7362. );
  7363. opts.icon = opts.icons;
  7364. } else {
  7365. $.error(
  7366. "'icons' tree option is deprecated since v2.14.0: use 'icon' only instead"
  7367. );
  7368. }
  7369. }
  7370. if (opts.iconClass !== undefined) {
  7371. // 2015-11-16
  7372. if (opts.icon) {
  7373. $.error(
  7374. "'iconClass' tree option is deprecated since v2.14.0: use 'icon' only instead"
  7375. );
  7376. } else {
  7377. this.tree.warn(
  7378. "'iconClass' tree option is deprecated since v2.14.0: use 'icon' instead"
  7379. );
  7380. opts.icon = opts.iconClass;
  7381. }
  7382. }
  7383. if (opts.tabbable !== undefined) {
  7384. // 2016-04-04
  7385. opts.tabindex = opts.tabbable ? "0" : "-1";
  7386. this.tree.warn(
  7387. "'tabbable' tree option is deprecated since v2.17.0: use 'tabindex='" +
  7388. opts.tabindex +
  7389. "' instead"
  7390. );
  7391. }
  7392. //
  7393. this.tree._callHook("treeCreate", this.tree);
  7394. // Note: 'fancytreecreate' event is fired by widget base class
  7395. // this.tree._triggerTreeEvent("create");
  7396. },
  7397. /* Called on every $().fancytree() */
  7398. _init: function() {
  7399. this.tree._callHook("treeInit", this.tree);
  7400. // TODO: currently we call bind after treeInit, because treeInit
  7401. // might change tree.$container.
  7402. // It would be better, to move event binding into hooks altogether
  7403. this._bind();
  7404. },
  7405. /* Use the _setOption method to respond to changes to options. */
  7406. _setOption: function(key, value) {
  7407. return this.tree._callHook(
  7408. "treeSetOption",
  7409. this.tree,
  7410. key,
  7411. value
  7412. );
  7413. },
  7414. /** Use the destroy method to clean up any modifications your widget has made to the DOM */
  7415. _destroy: function() {
  7416. this._unbind();
  7417. this.tree._callHook("treeDestroy", this.tree);
  7418. // In jQuery UI 1.8, you must invoke the destroy method from the base widget
  7419. // $.Widget.prototype.destroy.call(this);
  7420. // TODO: delete tree and nodes to make garbage collect easier?
  7421. // TODO: In jQuery UI 1.9 and above, you would define _destroy instead of destroy and not call the base method
  7422. },
  7423. // -------------------------------------------------------------------------
  7424. /* Remove all event handlers for our namespace */
  7425. _unbind: function() {
  7426. var ns = this.tree._ns;
  7427. this.element.off(ns);
  7428. this.tree.$container.off(ns);
  7429. $(document).off(ns);
  7430. },
  7431. /* Add mouse and kyboard handlers to the container */
  7432. _bind: function() {
  7433. var self = this,
  7434. opts = this.options,
  7435. tree = this.tree,
  7436. ns = tree._ns;
  7437. // selstartEvent = ( $.support.selectstart ? "selectstart" : "mousedown" )
  7438. // Remove all previuous handlers for this tree
  7439. this._unbind();
  7440. //alert("keydown" + ns + "foc=" + tree.hasFocus() + tree.$container);
  7441. // tree.debug("bind events; container: ", tree.$container);
  7442. tree.$container
  7443. .on("focusin" + ns + " focusout" + ns, function(event) {
  7444. var node = FT.getNode(event),
  7445. flag = event.type === "focusin";
  7446. if (!flag && node && $(event.target).is("a")) {
  7447. // #764
  7448. node.debug(
  7449. "Ignored focusout on embedded <a> element."
  7450. );
  7451. return;
  7452. }
  7453. // tree.treeOnFocusInOut.call(tree, event);
  7454. // tree.debug("Tree container got event " + event.type, node, event, FT.getEventTarget(event));
  7455. if (flag) {
  7456. if (tree._getExpiringValue("focusin")) {
  7457. // #789: IE 11 may send duplicate focusin events
  7458. tree.debug("Ignored double focusin.");
  7459. return;
  7460. }
  7461. tree._setExpiringValue("focusin", true, 50);
  7462. if (!node) {
  7463. // #789: IE 11 may send focusin before mousdown(?)
  7464. node = tree._getExpiringValue("mouseDownNode");
  7465. if (node) {
  7466. tree.debug(
  7467. "Reconstruct mouse target for focusin from recent event."
  7468. );
  7469. }
  7470. }
  7471. }
  7472. if (node) {
  7473. // For example clicking into an <input> that is part of a node
  7474. tree._callHook(
  7475. "nodeSetFocus",
  7476. tree._makeHookContext(node, event),
  7477. flag
  7478. );
  7479. } else {
  7480. if (
  7481. tree.tbody &&
  7482. $(event.target).parents(
  7483. "table.fancytree-container > thead"
  7484. ).length
  7485. ) {
  7486. // #767: ignore events in the table's header
  7487. tree.debug(
  7488. "Ignore focus event outside table body.",
  7489. event
  7490. );
  7491. } else {
  7492. tree._callHook("treeSetFocus", tree, flag);
  7493. }
  7494. }
  7495. })
  7496. .on("selectstart" + ns, "span.fancytree-title", function(
  7497. event
  7498. ) {
  7499. // prevent mouse-drags to select text ranges
  7500. // tree.debug("<span title> got event " + event.type);
  7501. event.preventDefault();
  7502. })
  7503. .on("keydown" + ns, function(event) {
  7504. // TODO: also bind keyup and keypress
  7505. // tree.debug("got event " + event.type + ", hasFocus:" + tree.hasFocus());
  7506. // if(opts.disabled || opts.keyboard === false || !tree.hasFocus() ){
  7507. if (opts.disabled || opts.keyboard === false) {
  7508. return true;
  7509. }
  7510. var res,
  7511. node = tree.focusNode, // node may be null
  7512. ctx = tree._makeHookContext(node || tree, event),
  7513. prevPhase = tree.phase;
  7514. try {
  7515. tree.phase = "userEvent";
  7516. // If a 'fancytreekeydown' handler returns false, skip the default
  7517. // handling (implemented by tree.nodeKeydown()).
  7518. if (node) {
  7519. res = tree._triggerNodeEvent(
  7520. "keydown",
  7521. node,
  7522. event
  7523. );
  7524. } else {
  7525. res = tree._triggerTreeEvent("keydown", event);
  7526. }
  7527. if (res === "preventNav") {
  7528. res = true; // prevent keyboard navigation, but don't prevent default handling of embedded input controls
  7529. } else if (res !== false) {
  7530. res = tree._callHook("nodeKeydown", ctx);
  7531. }
  7532. return res;
  7533. } finally {
  7534. tree.phase = prevPhase;
  7535. }
  7536. })
  7537. .on("mousedown" + ns, function(event) {
  7538. var et = FT.getEventTarget(event);
  7539. // self.tree.debug("event(" + event.type + "): node: ", et.node);
  7540. // #712: Store the clicked node, so we can use it when we get a focusin event
  7541. // ('click' event fires after focusin)
  7542. // tree.debug("event(" + event.type + "): node: ", et.node);
  7543. tree._lastMousedownNode = et ? et.node : null;
  7544. // #789: Store the node also for a short period, so we can use it
  7545. // in a *resulting* focusin event
  7546. tree._setExpiringValue(
  7547. "mouseDownNode",
  7548. tree._lastMousedownNode
  7549. );
  7550. })
  7551. .on("click" + ns + " dblclick" + ns, function(event) {
  7552. if (opts.disabled) {
  7553. return true;
  7554. }
  7555. var ctx,
  7556. et = FT.getEventTarget(event),
  7557. node = et.node,
  7558. tree = self.tree,
  7559. prevPhase = tree.phase;
  7560. // self.tree.debug("event(" + event.type + "): node: ", node);
  7561. if (!node) {
  7562. return true; // Allow bubbling of other events
  7563. }
  7564. ctx = tree._makeHookContext(node, event);
  7565. // self.tree.debug("event(" + event.type + "): node: ", node);
  7566. try {
  7567. tree.phase = "userEvent";
  7568. switch (event.type) {
  7569. case "click":
  7570. ctx.targetType = et.type;
  7571. if (node.isPagingNode()) {
  7572. return (
  7573. tree._triggerNodeEvent(
  7574. "clickPaging",
  7575. ctx,
  7576. event
  7577. ) === true
  7578. );
  7579. }
  7580. return tree._triggerNodeEvent(
  7581. "click",
  7582. ctx,
  7583. event
  7584. ) === false
  7585. ? false
  7586. : tree._callHook("nodeClick", ctx);
  7587. case "dblclick":
  7588. ctx.targetType = et.type;
  7589. return tree._triggerNodeEvent(
  7590. "dblclick",
  7591. ctx,
  7592. event
  7593. ) === false
  7594. ? false
  7595. : tree._callHook("nodeDblclick", ctx);
  7596. }
  7597. } finally {
  7598. tree.phase = prevPhase;
  7599. }
  7600. });
  7601. },
  7602. /** Return the active node or null.
  7603. * @returns {FancytreeNode}
  7604. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7605. */
  7606. getActiveNode: function() {
  7607. this._deprecationWarning("getActiveNode");
  7608. return this.tree.activeNode;
  7609. },
  7610. /** Return the matching node or null.
  7611. * @param {string} key
  7612. * @returns {FancytreeNode}
  7613. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7614. */
  7615. getNodeByKey: function(key) {
  7616. this._deprecationWarning("getNodeByKey");
  7617. return this.tree.getNodeByKey(key);
  7618. },
  7619. /** Return the invisible system root node.
  7620. * @returns {FancytreeNode}
  7621. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7622. */
  7623. getRootNode: function() {
  7624. this._deprecationWarning("getRootNode");
  7625. return this.tree.rootNode;
  7626. },
  7627. /** Return the current tree instance.
  7628. * @returns {Fancytree}
  7629. * @deprecated Use `$.ui.fancytree.getTree()` instead (<a href="Fancytree_Widget.html">example above</a>).
  7630. */
  7631. getTree: function() {
  7632. this._deprecationWarning("getTree");
  7633. return this.tree;
  7634. },
  7635. }
  7636. );
  7637. // $.ui.fancytree was created by the widget factory. Create a local shortcut:
  7638. FT = $.ui.fancytree;
  7639. /**
  7640. * Static members in the `$.ui.fancytree` namespace.
  7641. * This properties and methods can be accessed without instantiating a concrete
  7642. * Fancytree instance.
  7643. *
  7644. * @example
  7645. * // Access static members:
  7646. * var node = $.ui.fancytree.getNode(element);
  7647. * alert($.ui.fancytree.version);
  7648. *
  7649. * @mixin Fancytree_Static
  7650. */
  7651. $.extend(
  7652. $.ui.fancytree,
  7653. /** @lends Fancytree_Static# */
  7654. {
  7655. /** Version number `"MAJOR.MINOR.PATCH"`
  7656. * @type {string} */
  7657. version: "2.38.0", // Set to semver by 'grunt release'
  7658. /** @type {string}
  7659. * @description `"production" for release builds` */
  7660. buildType: "production", // Set to 'production' by 'grunt build'
  7661. /** @type {int}
  7662. * @description 0: silent .. 5: verbose (default: 3 for release builds). */
  7663. debugLevel: 3, // Set to 3 by 'grunt build'
  7664. // Used by $.ui.fancytree.debug() and as default for tree.options.debugLevel
  7665. _nextId: 1,
  7666. _nextNodeKey: 1,
  7667. _extensions: {},
  7668. // focusTree: null,
  7669. /** Expose class object as `$.ui.fancytree._FancytreeClass`.
  7670. * Useful to extend `$.ui.fancytree._FancytreeClass.prototype`.
  7671. * @type {Fancytree}
  7672. */
  7673. _FancytreeClass: Fancytree,
  7674. /** Expose class object as $.ui.fancytree._FancytreeNodeClass
  7675. * Useful to extend `$.ui.fancytree._FancytreeNodeClass.prototype`.
  7676. * @type {FancytreeNode}
  7677. */
  7678. _FancytreeNodeClass: FancytreeNode,
  7679. /* Feature checks to provide backwards compatibility */
  7680. jquerySupports: {
  7681. // http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7682. positionMyOfs: isVersionAtLeast($.ui.version, 1, 9),
  7683. },
  7684. /** Throw an error if condition fails (debug method).
  7685. * @param {boolean} cond
  7686. * @param {string} msg
  7687. */
  7688. assert: function(cond, msg) {
  7689. return _assert(cond, msg);
  7690. },
  7691. /** Create a new Fancytree instance on a target element.
  7692. *
  7693. * @param {Element | jQueryObject | string} el Target DOM element or selector
  7694. * @param {FancytreeOptions} [opts] Fancytree options
  7695. * @returns {Fancytree} new tree instance
  7696. * @example
  7697. * var tree = $.ui.fancytree.createTree("#tree", {
  7698. * source: {url: "my/webservice"}
  7699. * }); // Create tree for this matching element
  7700. *
  7701. * @since 2.25
  7702. */
  7703. createTree: function(el, opts) {
  7704. var $tree = $(el).fancytree(opts);
  7705. return FT.getTree($tree);
  7706. },
  7707. /** Return a function that executes *fn* at most every *timeout* ms.
  7708. * @param {integer} timeout
  7709. * @param {function} fn
  7710. * @param {boolean} [invokeAsap=false]
  7711. * @param {any} [ctx]
  7712. */
  7713. debounce: function(timeout, fn, invokeAsap, ctx) {
  7714. var timer;
  7715. if (arguments.length === 3 && typeof invokeAsap !== "boolean") {
  7716. ctx = invokeAsap;
  7717. invokeAsap = false;
  7718. }
  7719. return function() {
  7720. var args = arguments;
  7721. ctx = ctx || this;
  7722. // eslint-disable-next-line no-unused-expressions
  7723. invokeAsap && !timer && fn.apply(ctx, args);
  7724. clearTimeout(timer);
  7725. timer = setTimeout(function() {
  7726. // eslint-disable-next-line no-unused-expressions
  7727. invokeAsap || fn.apply(ctx, args);
  7728. timer = null;
  7729. }, timeout);
  7730. };
  7731. },
  7732. /** Write message to console if debugLevel >= 4
  7733. * @param {string} msg
  7734. */
  7735. debug: function(msg) {
  7736. if ($.ui.fancytree.debugLevel >= 4) {
  7737. consoleApply("log", arguments);
  7738. }
  7739. },
  7740. /** Write error message to console if debugLevel >= 1.
  7741. * @param {string} msg
  7742. */
  7743. error: function(msg) {
  7744. if ($.ui.fancytree.debugLevel >= 1) {
  7745. consoleApply("error", arguments);
  7746. }
  7747. },
  7748. /** Convert `<`, `>`, `&`, `"`, `'`, and `/` to the equivalent entities.
  7749. *
  7750. * @param {string} s
  7751. * @returns {string}
  7752. */
  7753. escapeHtml: function(s) {
  7754. return ("" + s).replace(REX_HTML, function(s) {
  7755. return ENTITY_MAP[s];
  7756. });
  7757. },
  7758. /** Make jQuery.position() arguments backwards compatible, i.e. if
  7759. * jQuery UI version <= 1.8, convert
  7760. * { my: "left+3 center", at: "left bottom", of: $target }
  7761. * to
  7762. * { my: "left center", at: "left bottom", of: $target, offset: "3 0" }
  7763. *
  7764. * See http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7765. * and http://jsfiddle.net/mar10/6xtu9a4e/
  7766. *
  7767. * @param {object} opts
  7768. * @returns {object} the (potentially modified) original opts hash object
  7769. */
  7770. fixPositionOptions: function(opts) {
  7771. if (opts.offset || ("" + opts.my + opts.at).indexOf("%") >= 0) {
  7772. $.error(
  7773. "expected new position syntax (but '%' is not supported)"
  7774. );
  7775. }
  7776. if (!$.ui.fancytree.jquerySupports.positionMyOfs) {
  7777. var // parse 'left+3 center' into ['left+3 center', 'left', '+3', 'center', undefined]
  7778. myParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(
  7779. opts.my
  7780. ),
  7781. atParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(
  7782. opts.at
  7783. ),
  7784. // convert to numbers
  7785. dx =
  7786. (myParts[2] ? +myParts[2] : 0) +
  7787. (atParts[2] ? +atParts[2] : 0),
  7788. dy =
  7789. (myParts[4] ? +myParts[4] : 0) +
  7790. (atParts[4] ? +atParts[4] : 0);
  7791. opts = $.extend({}, opts, {
  7792. // make a copy and overwrite
  7793. my: myParts[1] + " " + myParts[3],
  7794. at: atParts[1] + " " + atParts[3],
  7795. });
  7796. if (dx || dy) {
  7797. opts.offset = "" + dx + " " + dy;
  7798. }
  7799. }
  7800. return opts;
  7801. },
  7802. /** Return a {node: FancytreeNode, type: TYPE} object for a mouse event.
  7803. *
  7804. * @param {Event} event Mouse event, e.g. click, ...
  7805. * @returns {object} Return a {node: FancytreeNode, type: TYPE} object
  7806. * TYPE: 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7807. */
  7808. getEventTarget: function(event) {
  7809. var $target,
  7810. tree,
  7811. tcn = event && event.target ? event.target.className : "",
  7812. res = { node: this.getNode(event.target), type: undefined };
  7813. // We use a fast version of $(res.node).hasClass()
  7814. // See http://jsperf.com/test-for-classname/2
  7815. if (/\bfancytree-title\b/.test(tcn)) {
  7816. res.type = "title";
  7817. } else if (/\bfancytree-expander\b/.test(tcn)) {
  7818. res.type =
  7819. res.node.hasChildren() === false
  7820. ? "prefix"
  7821. : "expander";
  7822. // }else if( /\bfancytree-checkbox\b/.test(tcn) || /\bfancytree-radio\b/.test(tcn) ){
  7823. } else if (/\bfancytree-checkbox\b/.test(tcn)) {
  7824. res.type = "checkbox";
  7825. } else if (/\bfancytree(-custom)?-icon\b/.test(tcn)) {
  7826. res.type = "icon";
  7827. } else if (/\bfancytree-node\b/.test(tcn)) {
  7828. // Somewhere near the title
  7829. res.type = "title";
  7830. } else if (event && event.target) {
  7831. $target = $(event.target);
  7832. if ($target.is("ul[role=group]")) {
  7833. // #nnn: Clicking right to a node may hit the surrounding UL
  7834. tree = res.node && res.node.tree;
  7835. (tree || FT).debug("Ignoring click on outer UL.");
  7836. res.node = null;
  7837. } else if ($target.closest(".fancytree-title").length) {
  7838. // #228: clicking an embedded element inside a title
  7839. res.type = "title";
  7840. } else if ($target.closest(".fancytree-checkbox").length) {
  7841. // E.g. <svg> inside checkbox span
  7842. res.type = "checkbox";
  7843. } else if ($target.closest(".fancytree-expander").length) {
  7844. res.type = "expander";
  7845. }
  7846. }
  7847. return res;
  7848. },
  7849. /** Return a string describing the affected node region for a mouse event.
  7850. *
  7851. * @param {Event} event Mouse event, e.g. click, mousemove, ...
  7852. * @returns {string} 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7853. */
  7854. getEventTargetType: function(event) {
  7855. return this.getEventTarget(event).type;
  7856. },
  7857. /** Return a FancytreeNode instance from element, event, or jQuery object.
  7858. *
  7859. * @param {Element | jQueryObject | Event} el
  7860. * @returns {FancytreeNode} matching node or null
  7861. */
  7862. getNode: function(el) {
  7863. if (el instanceof FancytreeNode) {
  7864. return el; // el already was a FancytreeNode
  7865. } else if (el instanceof $) {
  7866. el = el[0]; // el was a jQuery object: use the DOM element
  7867. } else if (el.originalEvent !== undefined) {
  7868. el = el.target; // el was an Event
  7869. }
  7870. while (el) {
  7871. if (el.ftnode) {
  7872. return el.ftnode;
  7873. }
  7874. el = el.parentNode;
  7875. }
  7876. return null;
  7877. },
  7878. /** Return a Fancytree instance, from element, index, event, or jQueryObject.
  7879. *
  7880. * @param {Element | jQueryObject | Event | integer | string} [el]
  7881. * @returns {Fancytree} matching tree or null
  7882. * @example
  7883. * $.ui.fancytree.getTree(); // Get first Fancytree instance on page
  7884. * $.ui.fancytree.getTree(1); // Get second Fancytree instance on page
  7885. * $.ui.fancytree.getTree(event); // Get tree for this mouse- or keyboard event
  7886. * $.ui.fancytree.getTree("foo"); // Get tree for this `opts.treeId`
  7887. * $.ui.fancytree.getTree("#tree"); // Get tree for this matching element
  7888. *
  7889. * @since 2.13
  7890. */
  7891. getTree: function(el) {
  7892. var widget,
  7893. orgEl = el;
  7894. if (el instanceof Fancytree) {
  7895. return el; // el already was a Fancytree
  7896. }
  7897. if (el === undefined) {
  7898. el = 0; // get first tree
  7899. }
  7900. if (typeof el === "number") {
  7901. el = $(".fancytree-container").eq(el); // el was an integer: return nth instance
  7902. } else if (typeof el === "string") {
  7903. // `el` may be a treeId or a selector:
  7904. el = $("#ft-id-" + orgEl).eq(0);
  7905. if (!el.length) {
  7906. el = $(orgEl).eq(0); // el was a selector: use first match
  7907. }
  7908. } else if (
  7909. el instanceof Element ||
  7910. el instanceof HTMLDocument
  7911. ) {
  7912. el = $(el);
  7913. } else if (el instanceof $) {
  7914. el = el.eq(0); // el was a jQuery object: use the first
  7915. } else if (el.originalEvent !== undefined) {
  7916. el = $(el.target); // el was an Event
  7917. }
  7918. // el is a jQuery object wit one element here
  7919. el = el.closest(":ui-fancytree");
  7920. widget = el.data("ui-fancytree") || el.data("fancytree"); // the latter is required by jQuery <= 1.8
  7921. return widget ? widget.tree : null;
  7922. },
  7923. /** Return an option value that has a default, but may be overridden by a
  7924. * callback or a node instance attribute.
  7925. *
  7926. * Evaluation sequence:
  7927. *
  7928. * If `tree.options.<optionName>` is a callback that returns something, use that.
  7929. * Else if `node.<optionName>` is defined, use that.
  7930. * Else if `tree.options.<optionName>` is a value, use that.
  7931. * Else use `defaultValue`.
  7932. *
  7933. * @param {string} optionName name of the option property (on node and tree)
  7934. * @param {FancytreeNode} node passed to the callback
  7935. * @param {object} nodeObject where to look for the local option property, e.g. `node` or `node.data`
  7936. * @param {object} treeOption where to look for the tree option, e.g. `tree.options` or `tree.options.dnd5`
  7937. * @param {any} [defaultValue]
  7938. * @returns {any}
  7939. *
  7940. * @example
  7941. * // Check for node.foo, tree,options.foo(), and tree.options.foo:
  7942. * $.ui.fancytree.evalOption("foo", node, node, tree.options);
  7943. * // Check for node.data.bar, tree,options.qux.bar(), and tree.options.qux.bar:
  7944. * $.ui.fancytree.evalOption("bar", node, node.data, tree.options.qux);
  7945. *
  7946. * @since 2.22
  7947. */
  7948. evalOption: function(
  7949. optionName,
  7950. node,
  7951. nodeObject,
  7952. treeOptions,
  7953. defaultValue
  7954. ) {
  7955. var ctx,
  7956. res,
  7957. tree = node.tree,
  7958. treeOpt = treeOptions[optionName],
  7959. nodeOpt = nodeObject[optionName];
  7960. if ($.isFunction(treeOpt)) {
  7961. ctx = {
  7962. node: node,
  7963. tree: tree,
  7964. widget: tree.widget,
  7965. options: tree.widget.options,
  7966. typeInfo: tree.types[node.type] || {},
  7967. };
  7968. res = treeOpt.call(tree, { type: optionName }, ctx);
  7969. if (res == null) {
  7970. res = nodeOpt;
  7971. }
  7972. } else {
  7973. res = nodeOpt == null ? treeOpt : nodeOpt;
  7974. }
  7975. if (res == null) {
  7976. res = defaultValue; // no option set at all: return default
  7977. }
  7978. return res;
  7979. },
  7980. /** Set expander, checkbox, or node icon, supporting string and object format.
  7981. *
  7982. * @param {Element | jQueryObject} span
  7983. * @param {string} baseClass
  7984. * @param {string | object} icon
  7985. * @since 2.27
  7986. */
  7987. setSpanIcon: function(span, baseClass, icon) {
  7988. var $span = $(span);
  7989. if (typeof icon === "string") {
  7990. $span.attr("class", baseClass + " " + icon);
  7991. } else {
  7992. // support object syntax: { text: ligature, addClasse: classname }
  7993. if (icon.text) {
  7994. $span.text("" + icon.text);
  7995. } else if (icon.html) {
  7996. span.innerHTML = icon.html;
  7997. }
  7998. $span.attr(
  7999. "class",
  8000. baseClass + " " + (icon.addClass || "")
  8001. );
  8002. }
  8003. },
  8004. /** Convert a keydown or mouse event to a canonical string like 'ctrl+a',
  8005. * 'ctrl+shift+f2', 'shift+leftdblclick'.
  8006. *
  8007. * This is especially handy for switch-statements in event handlers.
  8008. *
  8009. * @param {event}
  8010. * @returns {string}
  8011. *
  8012. * @example
  8013. switch( $.ui.fancytree.eventToString(event) ) {
  8014. case "-":
  8015. tree.nodeSetExpanded(ctx, false);
  8016. break;
  8017. case "shift+return":
  8018. tree.nodeSetActive(ctx, true);
  8019. break;
  8020. case "down":
  8021. res = node.navigate(event.which, activate);
  8022. break;
  8023. default:
  8024. handled = false;
  8025. }
  8026. if( handled ){
  8027. event.preventDefault();
  8028. }
  8029. */
  8030. eventToString: function(event) {
  8031. // Poor-man's hotkeys. See here for a complete implementation:
  8032. // https://github.com/jeresig/jquery.hotkeys
  8033. var which = event.which,
  8034. et = event.type,
  8035. s = [];
  8036. if (event.altKey) {
  8037. s.push("alt");
  8038. }
  8039. if (event.ctrlKey) {
  8040. s.push("ctrl");
  8041. }
  8042. if (event.metaKey) {
  8043. s.push("meta");
  8044. }
  8045. if (event.shiftKey) {
  8046. s.push("shift");
  8047. }
  8048. if (et === "click" || et === "dblclick") {
  8049. s.push(MOUSE_BUTTONS[event.button] + et);
  8050. } else if (et === "wheel") {
  8051. s.push(et);
  8052. } else if (!IGNORE_KEYCODES[which]) {
  8053. s.push(
  8054. SPECIAL_KEYCODES[which] ||
  8055. String.fromCharCode(which).toLowerCase()
  8056. );
  8057. }
  8058. return s.join("+");
  8059. },
  8060. /** Write message to console if debugLevel >= 3
  8061. * @param {string} msg
  8062. */
  8063. info: function(msg) {
  8064. if ($.ui.fancytree.debugLevel >= 3) {
  8065. consoleApply("info", arguments);
  8066. }
  8067. },
  8068. /* @deprecated: use eventToString(event) instead.
  8069. */
  8070. keyEventToString: function(event) {
  8071. this.warn(
  8072. "keyEventToString() is deprecated: use eventToString()"
  8073. );
  8074. return this.eventToString(event);
  8075. },
  8076. /** Return a wrapped handler method, that provides `this._super`.
  8077. *
  8078. * @example
  8079. // Implement `opts.createNode` event to add the 'draggable' attribute
  8080. $.ui.fancytree.overrideMethod(ctx.options, "createNode", function(event, data) {
  8081. // Default processing if any
  8082. this._super.apply(this, arguments);
  8083. // Add 'draggable' attribute
  8084. data.node.span.draggable = true;
  8085. });
  8086. *
  8087. * @param {object} instance
  8088. * @param {string} methodName
  8089. * @param {function} handler
  8090. * @param {object} [context] optional context
  8091. */
  8092. overrideMethod: function(instance, methodName, handler, context) {
  8093. var prevSuper,
  8094. _super = instance[methodName] || $.noop;
  8095. instance[methodName] = function() {
  8096. var self = context || this;
  8097. try {
  8098. prevSuper = self._super;
  8099. self._super = _super;
  8100. return handler.apply(self, arguments);
  8101. } finally {
  8102. self._super = prevSuper;
  8103. }
  8104. };
  8105. },
  8106. /**
  8107. * Parse tree data from HTML <ul> markup
  8108. *
  8109. * @param {jQueryObject} $ul
  8110. * @returns {NodeData[]}
  8111. */
  8112. parseHtml: function($ul) {
  8113. var classes,
  8114. className,
  8115. extraClasses,
  8116. i,
  8117. iPos,
  8118. l,
  8119. tmp,
  8120. tmp2,
  8121. $children = $ul.find(">li"),
  8122. children = [];
  8123. $children.each(function() {
  8124. var allData,
  8125. lowerCaseAttr,
  8126. $li = $(this),
  8127. $liSpan = $li.find(">span", this).first(),
  8128. $liA = $liSpan.length ? null : $li.find(">a").first(),
  8129. d = { tooltip: null, data: {} };
  8130. if ($liSpan.length) {
  8131. d.title = $liSpan.html();
  8132. } else if ($liA && $liA.length) {
  8133. // If a <li><a> tag is specified, use it literally and extract href/target.
  8134. d.title = $liA.html();
  8135. d.data.href = $liA.attr("href");
  8136. d.data.target = $liA.attr("target");
  8137. d.tooltip = $liA.attr("title");
  8138. } else {
  8139. // If only a <li> tag is specified, use the trimmed string up to
  8140. // the next child <ul> tag.
  8141. d.title = $li.html();
  8142. iPos = d.title.search(/<ul/i);
  8143. if (iPos >= 0) {
  8144. d.title = d.title.substring(0, iPos);
  8145. }
  8146. }
  8147. d.title = $.trim(d.title);
  8148. // Make sure all fields exist
  8149. for (i = 0, l = CLASS_ATTRS.length; i < l; i++) {
  8150. d[CLASS_ATTRS[i]] = undefined;
  8151. }
  8152. // Initialize to `true`, if class is set and collect extraClasses
  8153. classes = this.className.split(" ");
  8154. extraClasses = [];
  8155. for (i = 0, l = classes.length; i < l; i++) {
  8156. className = classes[i];
  8157. if (CLASS_ATTR_MAP[className]) {
  8158. d[className] = true;
  8159. } else {
  8160. extraClasses.push(className);
  8161. }
  8162. }
  8163. d.extraClasses = extraClasses.join(" ");
  8164. // Parse node options from ID, title and class attributes
  8165. tmp = $li.attr("title");
  8166. if (tmp) {
  8167. d.tooltip = tmp; // overrides <a title='...'>
  8168. }
  8169. tmp = $li.attr("id");
  8170. if (tmp) {
  8171. d.key = tmp;
  8172. }
  8173. // Translate hideCheckbox -> checkbox:false
  8174. if ($li.attr("hideCheckbox")) {
  8175. d.checkbox = false;
  8176. }
  8177. // Add <li data-NAME='...'> as node.data.NAME
  8178. allData = _getElementDataAsDict($li);
  8179. if (allData && !$.isEmptyObject(allData)) {
  8180. // #507: convert data-hidecheckbox (lower case) to hideCheckbox
  8181. for (lowerCaseAttr in NODE_ATTR_LOWERCASE_MAP) {
  8182. if (allData.hasOwnProperty(lowerCaseAttr)) {
  8183. allData[
  8184. NODE_ATTR_LOWERCASE_MAP[lowerCaseAttr]
  8185. ] = allData[lowerCaseAttr];
  8186. delete allData[lowerCaseAttr];
  8187. }
  8188. }
  8189. // #56: Allow to set special node.attributes from data-...
  8190. for (i = 0, l = NODE_ATTRS.length; i < l; i++) {
  8191. tmp = NODE_ATTRS[i];
  8192. tmp2 = allData[tmp];
  8193. if (tmp2 != null) {
  8194. delete allData[tmp];
  8195. d[tmp] = tmp2;
  8196. }
  8197. }
  8198. // All other data-... goes to node.data...
  8199. $.extend(d.data, allData);
  8200. }
  8201. // Recursive reading of child nodes, if LI tag contains an UL tag
  8202. $ul = $li.find(">ul").first();
  8203. if ($ul.length) {
  8204. d.children = $.ui.fancytree.parseHtml($ul);
  8205. } else {
  8206. d.children = d.lazy ? undefined : null;
  8207. }
  8208. children.push(d);
  8209. // FT.debug("parse ", d, children);
  8210. });
  8211. return children;
  8212. },
  8213. /** Add Fancytree extension definition to the list of globally available extensions.
  8214. *
  8215. * @param {object} definition
  8216. */
  8217. registerExtension: function(definition) {
  8218. _assert(
  8219. definition.name != null,
  8220. "extensions must have a `name` property."
  8221. );
  8222. _assert(
  8223. definition.version != null,
  8224. "extensions must have a `version` property."
  8225. );
  8226. $.ui.fancytree._extensions[definition.name] = definition;
  8227. },
  8228. /** Inverse of escapeHtml().
  8229. *
  8230. * @param {string} s
  8231. * @returns {string}
  8232. */
  8233. unescapeHtml: function(s) {
  8234. var e = document.createElement("div");
  8235. e.innerHTML = s;
  8236. return e.childNodes.length === 0
  8237. ? ""
  8238. : e.childNodes[0].nodeValue;
  8239. },
  8240. /** Write warning message to console if debugLevel >= 2.
  8241. * @param {string} msg
  8242. */
  8243. warn: function(msg) {
  8244. if ($.ui.fancytree.debugLevel >= 2) {
  8245. consoleApply("warn", arguments);
  8246. }
  8247. },
  8248. }
  8249. );
  8250. // Value returned by `require('jquery.fancytree')`
  8251. return $.ui.fancytree;
  8252. }); // End of closure
  8253. /*! Extension 'jquery.fancytree.childcounter.js' */// Extending Fancytree
  8254. // ===================
  8255. //
  8256. // See also the [live demo](https://wwWendt.de/tech/fancytree/demo/sample-ext-childcounter.html) of this code.
  8257. //
  8258. // Every extension should have a comment header containing some information
  8259. // about the author, copyright and licensing. Also a pointer to the latest
  8260. // source code.
  8261. // Prefix with `/*!` so the comment is not removed by the minifier.
  8262. /*!
  8263. * jquery.fancytree.childcounter.js
  8264. *
  8265. * Add a child counter bubble to tree nodes.
  8266. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8267. *
  8268. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  8269. *
  8270. * Released under the MIT license
  8271. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8272. *
  8273. * @version 2.38.0
  8274. * @date 2021-02-09T20:03:49Z
  8275. */
  8276. // To keep the global namespace clean, we wrap everything in a closure.
  8277. // The UMD wrapper pattern defines the dependencies on jQuery and the
  8278. // Fancytree core module, and makes sure that we can use the `require()`
  8279. // syntax with package loaders.
  8280. (function(factory) {
  8281. if (typeof define === "function" && define.amd) {
  8282. // AMD. Register as an anonymous module.
  8283. define(["jquery", "./jquery.fancytree"], factory);
  8284. } else if (typeof module === "object" && module.exports) {
  8285. // Node/CommonJS
  8286. require("./jquery.fancytree");
  8287. module.exports = factory(require("jquery"));
  8288. } else {
  8289. // Browser globals
  8290. factory(jQuery);
  8291. }
  8292. })(function($) {
  8293. // Consider to use [strict mode](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)
  8294. "use strict";
  8295. // The [coding guidelines](http://contribute.jquery.org/style-guide/js/)
  8296. // require jshint /eslint compliance.
  8297. // But for this sample, we want to allow unused variables for demonstration purpose.
  8298. /*eslint-disable no-unused-vars */
  8299. // Adding methods
  8300. // --------------
  8301. // New member functions can be added to the `Fancytree` class.
  8302. // This function will be available for every tree instance:
  8303. //
  8304. // var tree = $.ui.fancytree.getTree("#tree");
  8305. // tree.countSelected(false);
  8306. $.ui.fancytree._FancytreeClass.prototype.countSelected = function(topOnly) {
  8307. var tree = this,
  8308. treeOptions = tree.options;
  8309. return tree.getSelectedNodes(topOnly).length;
  8310. };
  8311. // The `FancytreeNode` class can also be easily extended. This would be called
  8312. // like
  8313. // node.updateCounters();
  8314. //
  8315. // It is also good practice to add a docstring comment.
  8316. /**
  8317. * [ext-childcounter] Update counter badges for `node` and its parents.
  8318. * May be called in the `loadChildren` event, to update parents of lazy loaded
  8319. * nodes.
  8320. * @alias FancytreeNode#updateCounters
  8321. * @requires jquery.fancytree.childcounters.js
  8322. */
  8323. $.ui.fancytree._FancytreeNodeClass.prototype.updateCounters = function() {
  8324. var node = this,
  8325. $badge = $("span.fancytree-childcounter", node.span),
  8326. extOpts = node.tree.options.childcounter,
  8327. count = node.countChildren(extOpts.deep);
  8328. node.data.childCounter = count;
  8329. if (
  8330. (count || !extOpts.hideZeros) &&
  8331. (!node.isExpanded() || !extOpts.hideExpanded)
  8332. ) {
  8333. if (!$badge.length) {
  8334. $badge = $("<span class='fancytree-childcounter'/>").appendTo(
  8335. $(
  8336. "span.fancytree-icon,span.fancytree-custom-icon",
  8337. node.span
  8338. )
  8339. );
  8340. }
  8341. $badge.text(count);
  8342. } else {
  8343. $badge.remove();
  8344. }
  8345. if (extOpts.deep && !node.isTopLevel() && !node.isRootNode()) {
  8346. node.parent.updateCounters();
  8347. }
  8348. };
  8349. // Finally, we can extend the widget API and create functions that are called
  8350. // like so:
  8351. //
  8352. // $("#tree").fancytree("widgetMethod1", "abc");
  8353. $.ui.fancytree.prototype.widgetMethod1 = function(arg1) {
  8354. var tree = this.tree;
  8355. return arg1;
  8356. };
  8357. // Register a Fancytree extension
  8358. // ------------------------------
  8359. // A full blown extension, extension is available for all trees and can be
  8360. // enabled like so (see also the [live demo](https://wwWendt.de/tech/fancytree/demo/sample-ext-childcounter.html)):
  8361. //
  8362. // <script src="../src/jquery.fancytree.js"></script>
  8363. // <script src="../src/jquery.fancytree.childcounter.js"></script>
  8364. // ...
  8365. //
  8366. // $("#tree").fancytree({
  8367. // extensions: ["childcounter"],
  8368. // childcounter: {
  8369. // hideExpanded: true
  8370. // },
  8371. // ...
  8372. // });
  8373. //
  8374. /* 'childcounter' extension */
  8375. $.ui.fancytree.registerExtension({
  8376. // Every extension must be registered by a unique name.
  8377. name: "childcounter",
  8378. // Version information should be compliant with [semver](http://semver.org)
  8379. version: "2.38.0",
  8380. // Extension specific options and their defaults.
  8381. // This options will be available as `tree.options.childcounter.hideExpanded`
  8382. options: {
  8383. deep: true,
  8384. hideZeros: true,
  8385. hideExpanded: false,
  8386. },
  8387. // Attributes other than `options` (or functions) can be defined here, and
  8388. // will be added to the tree.ext.EXTNAME namespace, in this case `tree.ext.childcounter.foo`.
  8389. // They can also be accessed as `this._local.foo` from within the extension
  8390. // methods.
  8391. foo: 42,
  8392. // Local functions are prefixed with an underscore '_'.
  8393. // Callable as `this._local._appendCounter()`.
  8394. _appendCounter: function(bar) {
  8395. var tree = this;
  8396. },
  8397. // **Override virtual methods for this extension.**
  8398. //
  8399. // Fancytree implements a number of 'hook methods', prefixed by 'node...' or 'tree...'.
  8400. // with a `ctx` argument (see [EventData](https://wwWendt.de/tech/fancytree/doc/jsdoc/global.html#EventData)
  8401. // for details) and an extended calling context:<br>
  8402. // `this` : the Fancytree instance<br>
  8403. // `this._local`: the namespace that contains extension attributes and private methods (same as this.ext.EXTNAME)<br>
  8404. // `this._super`: the virtual function that was overridden (member of previous extension or Fancytree)
  8405. //
  8406. // See also the [complete list of available hook functions](https://wwWendt.de/tech/fancytree/doc/jsdoc/Fancytree_Hooks.html).
  8407. /* Init */
  8408. // `treeInit` is triggered when a tree is initalized. We can set up classes or
  8409. // bind event handlers here...
  8410. treeInit: function(ctx) {
  8411. var tree = this, // same as ctx.tree,
  8412. opts = ctx.options,
  8413. extOpts = ctx.options.childcounter;
  8414. // Optionally check for dependencies with other extensions
  8415. /* this._requireExtension("glyph", false, false); */
  8416. // Call the base implementation
  8417. this._superApply(arguments);
  8418. // Add a class to the tree container
  8419. this.$container.addClass("fancytree-ext-childcounter");
  8420. },
  8421. // Destroy this tree instance (we only call the default implementation, so
  8422. // this method could as well be omitted).
  8423. treeDestroy: function(ctx) {
  8424. this._superApply(arguments);
  8425. },
  8426. // Overload the `renderTitle` hook, to append a counter badge
  8427. nodeRenderTitle: function(ctx, title) {
  8428. var node = ctx.node,
  8429. extOpts = ctx.options.childcounter,
  8430. count =
  8431. node.data.childCounter == null
  8432. ? node.countChildren(extOpts.deep)
  8433. : +node.data.childCounter;
  8434. // Let the base implementation render the title
  8435. // We use `_super()` instead of `_superApply()` here, since it is a little bit
  8436. // more performant when called often
  8437. this._super(ctx, title);
  8438. // Append a counter badge
  8439. if (
  8440. (count || !extOpts.hideZeros) &&
  8441. (!node.isExpanded() || !extOpts.hideExpanded)
  8442. ) {
  8443. $(
  8444. "span.fancytree-icon,span.fancytree-custom-icon",
  8445. node.span
  8446. ).append(
  8447. $("<span class='fancytree-childcounter'/>").text(count)
  8448. );
  8449. }
  8450. },
  8451. // Overload the `setExpanded` hook, so the counters are updated
  8452. nodeSetExpanded: function(ctx, flag, callOpts) {
  8453. var tree = ctx.tree,
  8454. node = ctx.node;
  8455. // Let the base implementation expand/collapse the node, then redraw the title
  8456. // after the animation has finished
  8457. return this._superApply(arguments).always(function() {
  8458. tree.nodeRenderTitle(ctx);
  8459. });
  8460. },
  8461. // End of extension definition
  8462. });
  8463. // Value returned by `require('jquery.fancytree..')`
  8464. return $.ui.fancytree;
  8465. }); // End of closure
  8466. /*! Extension 'jquery.fancytree.clones.js' *//*!
  8467. *
  8468. * jquery.fancytree.clones.js
  8469. * Support faster lookup of nodes by key and shared ref-ids.
  8470. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8471. *
  8472. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  8473. *
  8474. * Released under the MIT license
  8475. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8476. *
  8477. * @version 2.38.0
  8478. * @date 2021-02-09T20:03:49Z
  8479. */
  8480. (function(factory) {
  8481. if (typeof define === "function" && define.amd) {
  8482. // AMD. Register as an anonymous module.
  8483. define(["jquery", "./jquery.fancytree"], factory);
  8484. } else if (typeof module === "object" && module.exports) {
  8485. // Node/CommonJS
  8486. require("./jquery.fancytree");
  8487. module.exports = factory(require("jquery"));
  8488. } else {
  8489. // Browser globals
  8490. factory(jQuery);
  8491. }
  8492. })(function($) {
  8493. "use strict";
  8494. /*******************************************************************************
  8495. * Private functions and variables
  8496. */
  8497. var _assert = $.ui.fancytree.assert;
  8498. /* Return first occurrence of member from array. */
  8499. function _removeArrayMember(arr, elem) {
  8500. // TODO: use Array.indexOf for IE >= 9
  8501. var i;
  8502. for (i = arr.length - 1; i >= 0; i--) {
  8503. if (arr[i] === elem) {
  8504. arr.splice(i, 1);
  8505. return true;
  8506. }
  8507. }
  8508. return false;
  8509. }
  8510. /**
  8511. * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)
  8512. *
  8513. * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
  8514. * @see http://github.com/garycourt/murmurhash-js
  8515. * @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a>
  8516. * @see http://sites.google.com/site/murmurhash/
  8517. *
  8518. * @param {string} key ASCII only
  8519. * @param {boolean} [asString=false]
  8520. * @param {number} seed Positive integer only
  8521. * @return {number} 32-bit positive integer hash
  8522. */
  8523. function hashMurmur3(key, asString, seed) {
  8524. /*eslint-disable no-bitwise */
  8525. var h1b,
  8526. k1,
  8527. remainder = key.length & 3,
  8528. bytes = key.length - remainder,
  8529. h1 = seed,
  8530. c1 = 0xcc9e2d51,
  8531. c2 = 0x1b873593,
  8532. i = 0;
  8533. while (i < bytes) {
  8534. k1 =
  8535. (key.charCodeAt(i) & 0xff) |
  8536. ((key.charCodeAt(++i) & 0xff) << 8) |
  8537. ((key.charCodeAt(++i) & 0xff) << 16) |
  8538. ((key.charCodeAt(++i) & 0xff) << 24);
  8539. ++i;
  8540. k1 =
  8541. ((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
  8542. 0xffffffff;
  8543. k1 = (k1 << 15) | (k1 >>> 17);
  8544. k1 =
  8545. ((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
  8546. 0xffffffff;
  8547. h1 ^= k1;
  8548. h1 = (h1 << 13) | (h1 >>> 19);
  8549. h1b =
  8550. ((h1 & 0xffff) * 5 + ((((h1 >>> 16) * 5) & 0xffff) << 16)) &
  8551. 0xffffffff;
  8552. h1 =
  8553. (h1b & 0xffff) +
  8554. 0x6b64 +
  8555. ((((h1b >>> 16) + 0xe654) & 0xffff) << 16);
  8556. }
  8557. k1 = 0;
  8558. switch (remainder) {
  8559. case 3:
  8560. k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
  8561. // fall through
  8562. case 2:
  8563. k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
  8564. // fall through
  8565. case 1:
  8566. k1 ^= key.charCodeAt(i) & 0xff;
  8567. k1 =
  8568. ((k1 & 0xffff) * c1 +
  8569. ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
  8570. 0xffffffff;
  8571. k1 = (k1 << 15) | (k1 >>> 17);
  8572. k1 =
  8573. ((k1 & 0xffff) * c2 +
  8574. ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
  8575. 0xffffffff;
  8576. h1 ^= k1;
  8577. }
  8578. h1 ^= key.length;
  8579. h1 ^= h1 >>> 16;
  8580. h1 =
  8581. ((h1 & 0xffff) * 0x85ebca6b +
  8582. ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) &
  8583. 0xffffffff;
  8584. h1 ^= h1 >>> 13;
  8585. h1 =
  8586. ((h1 & 0xffff) * 0xc2b2ae35 +
  8587. ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16)) &
  8588. 0xffffffff;
  8589. h1 ^= h1 >>> 16;
  8590. if (asString) {
  8591. // Convert to 8 digit hex string
  8592. return ("0000000" + (h1 >>> 0).toString(16)).substr(-8);
  8593. }
  8594. return h1 >>> 0;
  8595. /*eslint-enable no-bitwise */
  8596. }
  8597. /*
  8598. * Return a unique key for node by calculating the hash of the parents refKey-list.
  8599. */
  8600. function calcUniqueKey(node) {
  8601. var key,
  8602. h1,
  8603. path = $.map(node.getParentList(false, true), function(e) {
  8604. return e.refKey || e.key;
  8605. });
  8606. path = path.join("/");
  8607. // 32-bit has a high probability of collisions, so we pump up to 64-bit
  8608. // https://security.stackexchange.com/q/209882/207588
  8609. h1 = hashMurmur3(path, true);
  8610. key = "id_" + h1 + hashMurmur3(h1 + path, true);
  8611. return key;
  8612. }
  8613. /**
  8614. * [ext-clones] Return a list of clone-nodes (i.e. same refKey) or null.
  8615. * @param {boolean} [includeSelf=false]
  8616. * @returns {FancytreeNode[] | null}
  8617. *
  8618. * @alias FancytreeNode#getCloneList
  8619. * @requires jquery.fancytree.clones.js
  8620. */
  8621. $.ui.fancytree._FancytreeNodeClass.prototype.getCloneList = function(
  8622. includeSelf
  8623. ) {
  8624. var key,
  8625. tree = this.tree,
  8626. refList = tree.refMap[this.refKey] || null,
  8627. keyMap = tree.keyMap;
  8628. if (refList) {
  8629. key = this.key;
  8630. // Convert key list to node list
  8631. if (includeSelf) {
  8632. refList = $.map(refList, function(val) {
  8633. return keyMap[val];
  8634. });
  8635. } else {
  8636. refList = $.map(refList, function(val) {
  8637. return val === key ? null : keyMap[val];
  8638. });
  8639. if (refList.length < 1) {
  8640. refList = null;
  8641. }
  8642. }
  8643. }
  8644. return refList;
  8645. };
  8646. /**
  8647. * [ext-clones] Return true if this node has at least another clone with same refKey.
  8648. * @returns {boolean}
  8649. *
  8650. * @alias FancytreeNode#isClone
  8651. * @requires jquery.fancytree.clones.js
  8652. */
  8653. $.ui.fancytree._FancytreeNodeClass.prototype.isClone = function() {
  8654. var refKey = this.refKey || null,
  8655. refList = (refKey && this.tree.refMap[refKey]) || null;
  8656. return !!(refList && refList.length > 1);
  8657. };
  8658. /**
  8659. * [ext-clones] Update key and/or refKey for an existing node.
  8660. * @param {string} key
  8661. * @param {string} refKey
  8662. * @returns {boolean}
  8663. *
  8664. * @alias FancytreeNode#reRegister
  8665. * @requires jquery.fancytree.clones.js
  8666. */
  8667. $.ui.fancytree._FancytreeNodeClass.prototype.reRegister = function(
  8668. key,
  8669. refKey
  8670. ) {
  8671. key = key == null ? null : "" + key;
  8672. refKey = refKey == null ? null : "" + refKey;
  8673. // this.debug("reRegister", key, refKey);
  8674. var tree = this.tree,
  8675. prevKey = this.key,
  8676. prevRefKey = this.refKey,
  8677. keyMap = tree.keyMap,
  8678. refMap = tree.refMap,
  8679. refList = refMap[prevRefKey] || null,
  8680. // curCloneKeys = refList ? node.getCloneList(true),
  8681. modified = false;
  8682. // Key has changed: update all references
  8683. if (key != null && key !== this.key) {
  8684. if (keyMap[key]) {
  8685. $.error(
  8686. "[ext-clones] reRegister(" +
  8687. key +
  8688. "): already exists: " +
  8689. this
  8690. );
  8691. }
  8692. // Update keyMap
  8693. delete keyMap[prevKey];
  8694. keyMap[key] = this;
  8695. // Update refMap
  8696. if (refList) {
  8697. refMap[prevRefKey] = $.map(refList, function(e) {
  8698. return e === prevKey ? key : e;
  8699. });
  8700. }
  8701. this.key = key;
  8702. modified = true;
  8703. }
  8704. // refKey has changed
  8705. if (refKey != null && refKey !== this.refKey) {
  8706. // Remove previous refKeys
  8707. if (refList) {
  8708. if (refList.length === 1) {
  8709. delete refMap[prevRefKey];
  8710. } else {
  8711. refMap[prevRefKey] = $.map(refList, function(e) {
  8712. return e === prevKey ? null : e;
  8713. });
  8714. }
  8715. }
  8716. // Add refKey
  8717. if (refMap[refKey]) {
  8718. refMap[refKey].append(key);
  8719. } else {
  8720. refMap[refKey] = [this.key];
  8721. }
  8722. this.refKey = refKey;
  8723. modified = true;
  8724. }
  8725. return modified;
  8726. };
  8727. /**
  8728. * [ext-clones] Define a refKey for an existing node.
  8729. * @param {string} refKey
  8730. * @returns {boolean}
  8731. *
  8732. * @alias FancytreeNode#setRefKey
  8733. * @requires jquery.fancytree.clones.js
  8734. * @since 2.16
  8735. */
  8736. $.ui.fancytree._FancytreeNodeClass.prototype.setRefKey = function(refKey) {
  8737. return this.reRegister(null, refKey);
  8738. };
  8739. /**
  8740. * [ext-clones] Return all nodes with a given refKey (null if not found).
  8741. * @param {string} refKey
  8742. * @param {FancytreeNode} [rootNode] optionally restrict results to descendants of this node
  8743. * @returns {FancytreeNode[] | null}
  8744. * @alias Fancytree#getNodesByRef
  8745. * @requires jquery.fancytree.clones.js
  8746. */
  8747. $.ui.fancytree._FancytreeClass.prototype.getNodesByRef = function(
  8748. refKey,
  8749. rootNode
  8750. ) {
  8751. var keyMap = this.keyMap,
  8752. refList = this.refMap[refKey] || null;
  8753. if (refList) {
  8754. // Convert key list to node list
  8755. if (rootNode) {
  8756. refList = $.map(refList, function(val) {
  8757. var node = keyMap[val];
  8758. return node.isDescendantOf(rootNode) ? node : null;
  8759. });
  8760. } else {
  8761. refList = $.map(refList, function(val) {
  8762. return keyMap[val];
  8763. });
  8764. }
  8765. if (refList.length < 1) {
  8766. refList = null;
  8767. }
  8768. }
  8769. return refList;
  8770. };
  8771. /**
  8772. * [ext-clones] Replace a refKey with a new one.
  8773. * @param {string} oldRefKey
  8774. * @param {string} newRefKey
  8775. * @alias Fancytree#changeRefKey
  8776. * @requires jquery.fancytree.clones.js
  8777. */
  8778. $.ui.fancytree._FancytreeClass.prototype.changeRefKey = function(
  8779. oldRefKey,
  8780. newRefKey
  8781. ) {
  8782. var i,
  8783. node,
  8784. keyMap = this.keyMap,
  8785. refList = this.refMap[oldRefKey] || null;
  8786. if (refList) {
  8787. for (i = 0; i < refList.length; i++) {
  8788. node = keyMap[refList[i]];
  8789. node.refKey = newRefKey;
  8790. }
  8791. delete this.refMap[oldRefKey];
  8792. this.refMap[newRefKey] = refList;
  8793. }
  8794. };
  8795. /*******************************************************************************
  8796. * Extension code
  8797. */
  8798. $.ui.fancytree.registerExtension({
  8799. name: "clones",
  8800. version: "2.38.0",
  8801. // Default options for this extension.
  8802. options: {
  8803. highlightActiveClones: true, // set 'fancytree-active-clone' on active clones and all peers
  8804. highlightClones: false, // set 'fancytree-clone' class on any node that has at least one clone
  8805. },
  8806. treeCreate: function(ctx) {
  8807. this._superApply(arguments);
  8808. ctx.tree.refMap = {};
  8809. ctx.tree.keyMap = {};
  8810. },
  8811. treeInit: function(ctx) {
  8812. this.$container.addClass("fancytree-ext-clones");
  8813. _assert(ctx.options.defaultKey == null);
  8814. // Generate unique / reproducible default keys
  8815. ctx.options.defaultKey = function(node) {
  8816. return calcUniqueKey(node);
  8817. };
  8818. // The default implementation loads initial data
  8819. this._superApply(arguments);
  8820. },
  8821. treeClear: function(ctx) {
  8822. ctx.tree.refMap = {};
  8823. ctx.tree.keyMap = {};
  8824. return this._superApply(arguments);
  8825. },
  8826. treeRegisterNode: function(ctx, add, node) {
  8827. var refList,
  8828. len,
  8829. tree = ctx.tree,
  8830. keyMap = tree.keyMap,
  8831. refMap = tree.refMap,
  8832. key = node.key,
  8833. refKey = node && node.refKey != null ? "" + node.refKey : null;
  8834. // ctx.tree.debug("clones.treeRegisterNode", add, node);
  8835. if (node.isStatusNode()) {
  8836. return this._super(ctx, add, node);
  8837. }
  8838. if (add) {
  8839. if (keyMap[node.key] != null) {
  8840. var other = keyMap[node.key],
  8841. msg =
  8842. "clones.treeRegisterNode: duplicate key '" +
  8843. node.key +
  8844. "': /" +
  8845. node.getPath(true) +
  8846. " => " +
  8847. other.getPath(true);
  8848. // Sometimes this exception is not visible in the console,
  8849. // so we also write it:
  8850. tree.error(msg);
  8851. $.error(msg);
  8852. }
  8853. keyMap[key] = node;
  8854. if (refKey) {
  8855. refList = refMap[refKey];
  8856. if (refList) {
  8857. refList.push(key);
  8858. if (
  8859. refList.length === 2 &&
  8860. ctx.options.clones.highlightClones
  8861. ) {
  8862. // Mark peer node, if it just became a clone (no need to
  8863. // mark current node, since it will be rendered later anyway)
  8864. keyMap[refList[0]].renderStatus();
  8865. }
  8866. } else {
  8867. refMap[refKey] = [key];
  8868. }
  8869. // node.debug("clones.treeRegisterNode: add clone =>", refMap[refKey]);
  8870. }
  8871. } else {
  8872. if (keyMap[key] == null) {
  8873. $.error(
  8874. "clones.treeRegisterNode: node.key not registered: " +
  8875. node.key
  8876. );
  8877. }
  8878. delete keyMap[key];
  8879. if (refKey) {
  8880. refList = refMap[refKey];
  8881. // node.debug("clones.treeRegisterNode: remove clone BEFORE =>", refMap[refKey]);
  8882. if (refList) {
  8883. len = refList.length;
  8884. if (len <= 1) {
  8885. _assert(len === 1);
  8886. _assert(refList[0] === key);
  8887. delete refMap[refKey];
  8888. } else {
  8889. _removeArrayMember(refList, key);
  8890. // Unmark peer node, if this was the only clone
  8891. if (
  8892. len === 2 &&
  8893. ctx.options.clones.highlightClones
  8894. ) {
  8895. // node.debug("clones.treeRegisterNode: last =>", node.getCloneList());
  8896. keyMap[refList[0]].renderStatus();
  8897. }
  8898. }
  8899. // node.debug("clones.treeRegisterNode: remove clone =>", refMap[refKey]);
  8900. }
  8901. }
  8902. }
  8903. return this._super(ctx, add, node);
  8904. },
  8905. nodeRenderStatus: function(ctx) {
  8906. var $span,
  8907. res,
  8908. node = ctx.node;
  8909. res = this._super(ctx);
  8910. if (ctx.options.clones.highlightClones) {
  8911. $span = $(node[ctx.tree.statusClassPropName]);
  8912. // Only if span already exists
  8913. if ($span.length && node.isClone()) {
  8914. // node.debug("clones.nodeRenderStatus: ", ctx.options.clones.highlightClones);
  8915. $span.addClass("fancytree-clone");
  8916. }
  8917. }
  8918. return res;
  8919. },
  8920. nodeSetActive: function(ctx, flag, callOpts) {
  8921. var res,
  8922. scpn = ctx.tree.statusClassPropName,
  8923. node = ctx.node;
  8924. res = this._superApply(arguments);
  8925. if (ctx.options.clones.highlightActiveClones && node.isClone()) {
  8926. $.each(node.getCloneList(true), function(idx, n) {
  8927. // n.debug("clones.nodeSetActive: ", flag !== false);
  8928. $(n[scpn]).toggleClass(
  8929. "fancytree-active-clone",
  8930. flag !== false
  8931. );
  8932. });
  8933. }
  8934. return res;
  8935. },
  8936. });
  8937. // Value returned by `require('jquery.fancytree..')`
  8938. return $.ui.fancytree;
  8939. }); // End of closure
  8940. /*! Extension 'jquery.fancytree.dnd5.js' *//*!
  8941. * jquery.fancytree.dnd5.js
  8942. *
  8943. * Drag-and-drop support (native HTML5).
  8944. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8945. *
  8946. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  8947. *
  8948. * Released under the MIT license
  8949. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8950. *
  8951. * @version 2.38.0
  8952. * @date 2021-02-09T20:03:49Z
  8953. */
  8954. /*
  8955. #TODO
  8956. Compatiblity when dragging between *separate* windows:
  8957. Drag from Chrome Edge FF IE11 Safari
  8958. To Chrome ok ok ok NO ?
  8959. Edge ok ok ok NO ?
  8960. FF ok ok ok NO ?
  8961. IE 11 ok ok ok ok ?
  8962. Safari ? ? ? ? ok
  8963. */
  8964. (function(factory) {
  8965. if (typeof define === "function" && define.amd) {
  8966. // AMD. Register as an anonymous module.
  8967. define(["jquery", "./jquery.fancytree"], factory);
  8968. } else if (typeof module === "object" && module.exports) {
  8969. // Node/CommonJS
  8970. require("./jquery.fancytree");
  8971. module.exports = factory(require("jquery"));
  8972. } else {
  8973. // Browser globals
  8974. factory(jQuery);
  8975. }
  8976. })(function($) {
  8977. "use strict";
  8978. /******************************************************************************
  8979. * Private functions and variables
  8980. */
  8981. var FT = $.ui.fancytree,
  8982. isMac = /Mac/.test(navigator.platform),
  8983. classDragSource = "fancytree-drag-source",
  8984. classDragRemove = "fancytree-drag-remove",
  8985. classDropAccept = "fancytree-drop-accept",
  8986. classDropAfter = "fancytree-drop-after",
  8987. classDropBefore = "fancytree-drop-before",
  8988. classDropOver = "fancytree-drop-over",
  8989. classDropReject = "fancytree-drop-reject",
  8990. classDropTarget = "fancytree-drop-target",
  8991. nodeMimeType = "application/x-fancytree-node",
  8992. $dropMarker = null,
  8993. $dragImage,
  8994. $extraHelper,
  8995. SOURCE_NODE = null,
  8996. SOURCE_NODE_LIST = null,
  8997. $sourceList = null,
  8998. DRAG_ENTER_RESPONSE = null,
  8999. // SESSION_DATA = null, // plain object passed to events as `data`
  9000. SUGGESTED_DROP_EFFECT = null,
  9001. REQUESTED_DROP_EFFECT = null,
  9002. REQUESTED_EFFECT_ALLOWED = null,
  9003. LAST_HIT_MODE = null,
  9004. DRAG_OVER_STAMP = null; // Time when a node entered the 'over' hitmode
  9005. /* */
  9006. function _clearGlobals() {
  9007. DRAG_ENTER_RESPONSE = null;
  9008. DRAG_OVER_STAMP = null;
  9009. REQUESTED_DROP_EFFECT = null;
  9010. REQUESTED_EFFECT_ALLOWED = null;
  9011. SUGGESTED_DROP_EFFECT = null;
  9012. SOURCE_NODE = null;
  9013. SOURCE_NODE_LIST = null;
  9014. if ($sourceList) {
  9015. $sourceList.removeClass(classDragSource + " " + classDragRemove);
  9016. }
  9017. $sourceList = null;
  9018. if ($dropMarker) {
  9019. $dropMarker.hide();
  9020. }
  9021. // Take this badge off of me - I can't use it anymore:
  9022. if ($extraHelper) {
  9023. $extraHelper.remove();
  9024. $extraHelper = null;
  9025. }
  9026. }
  9027. /* Convert number to string and prepend +/-; return empty string for 0.*/
  9028. function offsetString(n) {
  9029. // eslint-disable-next-line no-nested-ternary
  9030. return n === 0 ? "" : n > 0 ? "+" + n : "" + n;
  9031. }
  9032. /* Convert a dragEnter() or dragOver() response to a canonical form.
  9033. * Return false or plain object
  9034. * @param {string|object|boolean} r
  9035. * @return {object|false}
  9036. */
  9037. function normalizeDragEnterResponse(r) {
  9038. var res;
  9039. if (!r) {
  9040. return false;
  9041. }
  9042. if ($.isPlainObject(r)) {
  9043. res = {
  9044. over: !!r.over,
  9045. before: !!r.before,
  9046. after: !!r.after,
  9047. };
  9048. } else if ($.isArray(r)) {
  9049. res = {
  9050. over: $.inArray("over", r) >= 0,
  9051. before: $.inArray("before", r) >= 0,
  9052. after: $.inArray("after", r) >= 0,
  9053. };
  9054. } else {
  9055. res = {
  9056. over: r === true || r === "over",
  9057. before: r === true || r === "before",
  9058. after: r === true || r === "after",
  9059. };
  9060. }
  9061. if (Object.keys(res).length === 0) {
  9062. return false;
  9063. }
  9064. // if( Object.keys(res).length === 1 ) {
  9065. // res.unique = res[0];
  9066. // }
  9067. return res;
  9068. }
  9069. /* Convert a dataTransfer.effectAllowed to a canonical form.
  9070. * Return false or plain object
  9071. * @param {string|boolean} r
  9072. * @return {object|false}
  9073. */
  9074. // function normalizeEffectAllowed(r) {
  9075. // if (!r || r === "none") {
  9076. // return false;
  9077. // }
  9078. // var all = r === "all",
  9079. // res = {
  9080. // copy: all || /copy/i.test(r),
  9081. // link: all || /link/i.test(r),
  9082. // move: all || /move/i.test(r),
  9083. // };
  9084. // return res;
  9085. // }
  9086. /* Implement auto scrolling when drag cursor is in top/bottom area of scroll parent. */
  9087. function autoScroll(tree, event) {
  9088. var spOfs,
  9089. scrollTop,
  9090. delta,
  9091. dndOpts = tree.options.dnd5,
  9092. sp = tree.$scrollParent[0],
  9093. sensitivity = dndOpts.scrollSensitivity,
  9094. speed = dndOpts.scrollSpeed,
  9095. scrolled = 0;
  9096. if (sp !== document && sp.tagName !== "HTML") {
  9097. spOfs = tree.$scrollParent.offset();
  9098. scrollTop = sp.scrollTop;
  9099. if (spOfs.top + sp.offsetHeight - event.pageY < sensitivity) {
  9100. delta =
  9101. sp.scrollHeight -
  9102. tree.$scrollParent.innerHeight() -
  9103. scrollTop;
  9104. // console.log ("sp.offsetHeight: " + sp.offsetHeight
  9105. // + ", spOfs.top: " + spOfs.top
  9106. // + ", scrollTop: " + scrollTop
  9107. // + ", innerHeight: " + tree.$scrollParent.innerHeight()
  9108. // + ", scrollHeight: " + sp.scrollHeight
  9109. // + ", delta: " + delta
  9110. // );
  9111. if (delta > 0) {
  9112. sp.scrollTop = scrolled = scrollTop + speed;
  9113. }
  9114. } else if (scrollTop > 0 && event.pageY - spOfs.top < sensitivity) {
  9115. sp.scrollTop = scrolled = scrollTop - speed;
  9116. }
  9117. } else {
  9118. scrollTop = $(document).scrollTop();
  9119. if (scrollTop > 0 && event.pageY - scrollTop < sensitivity) {
  9120. scrolled = scrollTop - speed;
  9121. $(document).scrollTop(scrolled);
  9122. } else if (
  9123. $(window).height() - (event.pageY - scrollTop) <
  9124. sensitivity
  9125. ) {
  9126. scrolled = scrollTop + speed;
  9127. $(document).scrollTop(scrolled);
  9128. }
  9129. }
  9130. if (scrolled) {
  9131. tree.debug("autoScroll: " + scrolled + "px");
  9132. }
  9133. return scrolled;
  9134. }
  9135. /* Guess dropEffect from modifier keys.
  9136. * Using rules suggested here:
  9137. * https://ux.stackexchange.com/a/83769
  9138. * @returns
  9139. * 'copy', 'link', 'move', or 'none'
  9140. */
  9141. function evalEffectModifiers(tree, event, effectDefault) {
  9142. var res = effectDefault;
  9143. if (isMac) {
  9144. if (event.metaKey && event.altKey) {
  9145. // Mac: [Control] + [Option]
  9146. res = "link";
  9147. } else if (event.ctrlKey) {
  9148. // Chrome on Mac: [Control]
  9149. res = "link";
  9150. } else if (event.metaKey) {
  9151. // Mac: [Command]
  9152. res = "move";
  9153. } else if (event.altKey) {
  9154. // Mac: [Option]
  9155. res = "copy";
  9156. }
  9157. } else {
  9158. if (event.ctrlKey) {
  9159. // Windows: [Ctrl]
  9160. res = "copy";
  9161. } else if (event.shiftKey) {
  9162. // Windows: [Shift]
  9163. res = "move";
  9164. } else if (event.altKey) {
  9165. // Windows: [Alt]
  9166. res = "link";
  9167. }
  9168. }
  9169. if (res !== SUGGESTED_DROP_EFFECT) {
  9170. tree.info(
  9171. "evalEffectModifiers: " +
  9172. event.type +
  9173. " - evalEffectModifiers(): " +
  9174. SUGGESTED_DROP_EFFECT +
  9175. " -> " +
  9176. res
  9177. );
  9178. }
  9179. SUGGESTED_DROP_EFFECT = res;
  9180. // tree.debug("evalEffectModifiers: " + res);
  9181. return res;
  9182. }
  9183. /*
  9184. * Check if the previous callback (dragEnter, dragOver, ...) has changed
  9185. * the `data` object and apply those settings.
  9186. *
  9187. * Safari:
  9188. * It seems that `dataTransfer.dropEffect` can only be set on dragStart, and will remain
  9189. * even if the cursor changes when [Alt] or [Ctrl] are pressed (?)
  9190. * Using rules suggested here:
  9191. * https://ux.stackexchange.com/a/83769
  9192. * @returns
  9193. * 'copy', 'link', 'move', or 'none'
  9194. */
  9195. function prepareDropEffectCallback(event, data) {
  9196. var tree = data.tree,
  9197. dataTransfer = data.dataTransfer;
  9198. if (event.type === "dragstart") {
  9199. data.effectAllowed = tree.options.dnd5.effectAllowed;
  9200. data.dropEffect = tree.options.dnd5.dropEffectDefault;
  9201. } else {
  9202. data.effectAllowed = REQUESTED_EFFECT_ALLOWED;
  9203. data.dropEffect = REQUESTED_DROP_EFFECT;
  9204. }
  9205. data.dropEffectSuggested = evalEffectModifiers(
  9206. tree,
  9207. event,
  9208. tree.options.dnd5.dropEffectDefault
  9209. );
  9210. data.isMove = data.dropEffect === "move";
  9211. data.files = dataTransfer.files || [];
  9212. // if (REQUESTED_EFFECT_ALLOWED !== dataTransfer.effectAllowed) {
  9213. // tree.warn(
  9214. // "prepareDropEffectCallback(" +
  9215. // event.type +
  9216. // "): dataTransfer.effectAllowed changed from " +
  9217. // REQUESTED_EFFECT_ALLOWED +
  9218. // " -> " +
  9219. // dataTransfer.effectAllowed
  9220. // );
  9221. // }
  9222. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9223. // tree.warn(
  9224. // "prepareDropEffectCallback(" +
  9225. // event.type +
  9226. // "): dataTransfer.dropEffect changed from requested " +
  9227. // REQUESTED_DROP_EFFECT +
  9228. // " to " +
  9229. // dataTransfer.dropEffect
  9230. // );
  9231. // }
  9232. }
  9233. function applyDropEffectCallback(event, data, allowDrop) {
  9234. var tree = data.tree,
  9235. dataTransfer = data.dataTransfer;
  9236. if (
  9237. event.type !== "dragstart" &&
  9238. REQUESTED_EFFECT_ALLOWED !== data.effectAllowed
  9239. ) {
  9240. tree.warn(
  9241. "effectAllowed should only be changed in dragstart event: " +
  9242. event.type +
  9243. ": data.effectAllowed changed from " +
  9244. REQUESTED_EFFECT_ALLOWED +
  9245. " -> " +
  9246. data.effectAllowed
  9247. );
  9248. }
  9249. if (allowDrop === false) {
  9250. tree.info("applyDropEffectCallback: allowDrop === false");
  9251. data.effectAllowed = "none";
  9252. data.dropEffect = "none";
  9253. }
  9254. // if (REQUESTED_DROP_EFFECT !== data.dropEffect) {
  9255. // tree.debug(
  9256. // "applyDropEffectCallback(" +
  9257. // event.type +
  9258. // "): data.dropEffect changed from previous " +
  9259. // REQUESTED_DROP_EFFECT +
  9260. // " to " +
  9261. // data.dropEffect
  9262. // );
  9263. // }
  9264. data.isMove = data.dropEffect === "move";
  9265. // data.isMove = data.dropEffectSuggested === "move";
  9266. // `effectAllowed` must only be defined in dragstart event, so we
  9267. // store it in a global variable for reference
  9268. if (event.type === "dragstart") {
  9269. REQUESTED_EFFECT_ALLOWED = data.effectAllowed;
  9270. REQUESTED_DROP_EFFECT = data.dropEffect;
  9271. }
  9272. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9273. // data.tree.info(
  9274. // "applyDropEffectCallback(" +
  9275. // event.type +
  9276. // "): dataTransfer.dropEffect changed from " +
  9277. // REQUESTED_DROP_EFFECT +
  9278. // " -> " +
  9279. // dataTransfer.dropEffect
  9280. // );
  9281. // }
  9282. dataTransfer.effectAllowed = REQUESTED_EFFECT_ALLOWED;
  9283. dataTransfer.dropEffect = REQUESTED_DROP_EFFECT;
  9284. // tree.debug(
  9285. // "applyDropEffectCallback(" +
  9286. // event.type +
  9287. // "): set " +
  9288. // dataTransfer.dropEffect +
  9289. // "/" +
  9290. // dataTransfer.effectAllowed
  9291. // );
  9292. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9293. // data.tree.warn(
  9294. // "applyDropEffectCallback(" +
  9295. // event.type +
  9296. // "): could not set dataTransfer.dropEffect to " +
  9297. // REQUESTED_DROP_EFFECT +
  9298. // ": got " +
  9299. // dataTransfer.dropEffect
  9300. // );
  9301. // }
  9302. return REQUESTED_DROP_EFFECT;
  9303. }
  9304. /* Handle dragover event (fired every x ms) on valid drop targets.
  9305. *
  9306. * - Auto-scroll when cursor is in border regions
  9307. * - Apply restrictioan like 'preventVoidMoves'
  9308. * - Calculate hit mode
  9309. * - Calculate drop effect
  9310. * - Trigger dragOver() callback to let user modify hit mode and drop effect
  9311. * - Adjust the drop marker accordingly
  9312. *
  9313. * @returns hitMode
  9314. */
  9315. function handleDragOver(event, data) {
  9316. // Implement auto-scrolling
  9317. if (data.options.dnd5.scroll) {
  9318. autoScroll(data.tree, event);
  9319. }
  9320. // Bail out with previous response if we get an invalid dragover
  9321. if (!data.node) {
  9322. data.tree.warn("Ignored dragover for non-node"); //, event, data);
  9323. return LAST_HIT_MODE;
  9324. }
  9325. var markerOffsetX,
  9326. nodeOfs,
  9327. pos,
  9328. relPosY,
  9329. hitMode = null,
  9330. tree = data.tree,
  9331. options = tree.options,
  9332. dndOpts = options.dnd5,
  9333. targetNode = data.node,
  9334. sourceNode = data.otherNode,
  9335. markerAt = "center",
  9336. $target = $(targetNode.span),
  9337. $targetTitle = $target.find("span.fancytree-title");
  9338. if (DRAG_ENTER_RESPONSE === false) {
  9339. tree.debug("Ignored dragover, since dragenter returned false.");
  9340. return false;
  9341. } else if (typeof DRAG_ENTER_RESPONSE === "string") {
  9342. $.error("assert failed: dragenter returned string");
  9343. }
  9344. // Calculate hitMode from relative cursor position.
  9345. nodeOfs = $target.offset();
  9346. relPosY = (event.pageY - nodeOfs.top) / $target.height();
  9347. if (event.pageY === undefined) {
  9348. tree.warn("event.pageY is undefined: see issue #1013.");
  9349. }
  9350. if (DRAG_ENTER_RESPONSE.after && relPosY > 0.75) {
  9351. hitMode = "after";
  9352. } else if (
  9353. !DRAG_ENTER_RESPONSE.over &&
  9354. DRAG_ENTER_RESPONSE.after &&
  9355. relPosY > 0.5
  9356. ) {
  9357. hitMode = "after";
  9358. } else if (DRAG_ENTER_RESPONSE.before && relPosY <= 0.25) {
  9359. hitMode = "before";
  9360. } else if (
  9361. !DRAG_ENTER_RESPONSE.over &&
  9362. DRAG_ENTER_RESPONSE.before &&
  9363. relPosY <= 0.5
  9364. ) {
  9365. hitMode = "before";
  9366. } else if (DRAG_ENTER_RESPONSE.over) {
  9367. hitMode = "over";
  9368. }
  9369. // Prevent no-ops like 'before source node'
  9370. // TODO: these are no-ops when moving nodes, but not in copy mode
  9371. if (dndOpts.preventVoidMoves && data.dropEffect === "move") {
  9372. if (targetNode === sourceNode) {
  9373. targetNode.debug("Drop over source node prevented.");
  9374. hitMode = null;
  9375. } else if (
  9376. hitMode === "before" &&
  9377. sourceNode &&
  9378. targetNode === sourceNode.getNextSibling()
  9379. ) {
  9380. targetNode.debug("Drop after source node prevented.");
  9381. hitMode = null;
  9382. } else if (
  9383. hitMode === "after" &&
  9384. sourceNode &&
  9385. targetNode === sourceNode.getPrevSibling()
  9386. ) {
  9387. targetNode.debug("Drop before source node prevented.");
  9388. hitMode = null;
  9389. } else if (
  9390. hitMode === "over" &&
  9391. sourceNode &&
  9392. sourceNode.parent === targetNode &&
  9393. sourceNode.isLastSibling()
  9394. ) {
  9395. targetNode.debug("Drop last child over own parent prevented.");
  9396. hitMode = null;
  9397. }
  9398. }
  9399. // Let callback modify the calculated hitMode
  9400. data.hitMode = hitMode;
  9401. if (hitMode && dndOpts.dragOver) {
  9402. prepareDropEffectCallback(event, data);
  9403. dndOpts.dragOver(targetNode, data);
  9404. var allowDrop = !!hitMode;
  9405. applyDropEffectCallback(event, data, allowDrop);
  9406. hitMode = data.hitMode;
  9407. }
  9408. LAST_HIT_MODE = hitMode;
  9409. //
  9410. if (hitMode === "after" || hitMode === "before" || hitMode === "over") {
  9411. markerOffsetX = dndOpts.dropMarkerOffsetX || 0;
  9412. switch (hitMode) {
  9413. case "before":
  9414. markerAt = "top";
  9415. markerOffsetX += dndOpts.dropMarkerInsertOffsetX || 0;
  9416. break;
  9417. case "after":
  9418. markerAt = "bottom";
  9419. markerOffsetX += dndOpts.dropMarkerInsertOffsetX || 0;
  9420. break;
  9421. }
  9422. pos = {
  9423. my: "left" + offsetString(markerOffsetX) + " center",
  9424. at: "left " + markerAt,
  9425. of: $targetTitle,
  9426. };
  9427. if (options.rtl) {
  9428. pos.my = "right" + offsetString(-markerOffsetX) + " center";
  9429. pos.at = "right " + markerAt;
  9430. // console.log("rtl", pos);
  9431. }
  9432. $dropMarker
  9433. .toggleClass(classDropAfter, hitMode === "after")
  9434. .toggleClass(classDropOver, hitMode === "over")
  9435. .toggleClass(classDropBefore, hitMode === "before")
  9436. .show()
  9437. .position(FT.fixPositionOptions(pos));
  9438. } else {
  9439. $dropMarker.hide();
  9440. // console.log("hide dropmarker")
  9441. }
  9442. $(targetNode.span)
  9443. .toggleClass(
  9444. classDropTarget,
  9445. hitMode === "after" ||
  9446. hitMode === "before" ||
  9447. hitMode === "over"
  9448. )
  9449. .toggleClass(classDropAfter, hitMode === "after")
  9450. .toggleClass(classDropBefore, hitMode === "before")
  9451. .toggleClass(classDropAccept, hitMode === "over")
  9452. .toggleClass(classDropReject, hitMode === false);
  9453. return hitMode;
  9454. }
  9455. /*
  9456. * Handle dragstart drag dragend events on the container
  9457. */
  9458. function onDragEvent(event) {
  9459. var json,
  9460. tree = this,
  9461. dndOpts = tree.options.dnd5,
  9462. node = FT.getNode(event),
  9463. dataTransfer =
  9464. event.dataTransfer || event.originalEvent.dataTransfer,
  9465. data = {
  9466. tree: tree,
  9467. node: node,
  9468. options: tree.options,
  9469. originalEvent: event.originalEvent,
  9470. widget: tree.widget,
  9471. dataTransfer: dataTransfer,
  9472. useDefaultImage: true,
  9473. dropEffect: undefined,
  9474. dropEffectSuggested: undefined,
  9475. effectAllowed: undefined, // set by dragstart
  9476. files: undefined, // only for drop events
  9477. isCancelled: undefined, // set by dragend
  9478. isMove: undefined,
  9479. };
  9480. switch (event.type) {
  9481. case "dragstart":
  9482. if (!node) {
  9483. tree.info("Ignored dragstart on a non-node.");
  9484. return false;
  9485. }
  9486. // Store current source node in different formats
  9487. SOURCE_NODE = node;
  9488. // Also optionally store selected nodes
  9489. if (dndOpts.multiSource === false) {
  9490. SOURCE_NODE_LIST = [node];
  9491. } else if (dndOpts.multiSource === true) {
  9492. if (node.isSelected()) {
  9493. SOURCE_NODE_LIST = tree.getSelectedNodes();
  9494. } else {
  9495. SOURCE_NODE_LIST = [node];
  9496. }
  9497. } else {
  9498. SOURCE_NODE_LIST = dndOpts.multiSource(node, data);
  9499. }
  9500. // Cache as array of jQuery objects for faster access:
  9501. $sourceList = $(
  9502. $.map(SOURCE_NODE_LIST, function(n) {
  9503. return n.span;
  9504. })
  9505. );
  9506. // Set visual feedback
  9507. $sourceList.addClass(classDragSource);
  9508. // Set payload
  9509. // Note:
  9510. // Transfer data is only accessible on dragstart and drop!
  9511. // For all other events the formats and kinds in the drag
  9512. // data store list of items representing dragged data can be
  9513. // enumerated, but the data itself is unavailable and no new
  9514. // data can be added.
  9515. var nodeData = node.toDict(true, dndOpts.sourceCopyHook);
  9516. nodeData.treeId = node.tree._id;
  9517. json = JSON.stringify(nodeData);
  9518. try {
  9519. dataTransfer.setData(nodeMimeType, json);
  9520. dataTransfer.setData("text/html", $(node.span).html());
  9521. dataTransfer.setData("text/plain", node.title);
  9522. } catch (ex) {
  9523. // IE only accepts 'text' type
  9524. tree.warn(
  9525. "Could not set data (IE only accepts 'text') - " + ex
  9526. );
  9527. }
  9528. // We always need to set the 'text' type if we want to drag
  9529. // Because IE 11 only accepts this single type.
  9530. // If we pass JSON here, IE can can access all node properties,
  9531. // even when the source lives in another window. (D'n'd inside
  9532. // the same window will always work.)
  9533. // The drawback is, that in this case ALL browsers will see
  9534. // the JSON representation as 'text', so dragging
  9535. // to a text field will insert the JSON string instead of
  9536. // the node title.
  9537. if (dndOpts.setTextTypeJson) {
  9538. dataTransfer.setData("text", json);
  9539. } else {
  9540. dataTransfer.setData("text", node.title);
  9541. }
  9542. // Set the allowed drag modes (combinations of move, copy, and link)
  9543. // (effectAllowed can only be set in the dragstart event.)
  9544. // This can be overridden in the dragStart() callback
  9545. prepareDropEffectCallback(event, data);
  9546. // Let user cancel or modify above settings
  9547. // Realize potential changes by previous callback
  9548. if (dndOpts.dragStart(node, data) === false) {
  9549. // Cancel dragging
  9550. // dataTransfer.dropEffect = "none";
  9551. _clearGlobals();
  9552. return false;
  9553. }
  9554. applyDropEffectCallback(event, data);
  9555. // Unless user set `data.useDefaultImage` to false in dragStart,
  9556. // generata a default drag image now:
  9557. $extraHelper = null;
  9558. if (data.useDefaultImage) {
  9559. // Set the title as drag image (otherwise it would contain the expander)
  9560. $dragImage = $(node.span).find(".fancytree-title");
  9561. if (SOURCE_NODE_LIST && SOURCE_NODE_LIST.length > 1) {
  9562. // Add a counter badge to node title if dragging more than one node.
  9563. // We want this, because the element that is used as drag image
  9564. // must be *visible* in the DOM, so we cannot create some hidden
  9565. // custom markup.
  9566. // See https://kryogenix.org/code/browser/custom-drag-image.html
  9567. // Also, since IE 11 and Edge don't support setDragImage() alltogether,
  9568. // it gives som feedback to the user.
  9569. // The badge will be removed later on drag end.
  9570. $extraHelper = $(
  9571. "<span class='fancytree-childcounter'/>"
  9572. )
  9573. .text("+" + (SOURCE_NODE_LIST.length - 1))
  9574. .appendTo($dragImage);
  9575. }
  9576. if (dataTransfer.setDragImage) {
  9577. // IE 11 and Edge do not support this
  9578. dataTransfer.setDragImage($dragImage[0], -10, -10);
  9579. }
  9580. }
  9581. return true;
  9582. case "drag":
  9583. // Called every few milliseconds (no matter if the
  9584. // cursor is over a valid drop target)
  9585. // data.tree.info("drag", SOURCE_NODE)
  9586. prepareDropEffectCallback(event, data);
  9587. dndOpts.dragDrag(node, data);
  9588. applyDropEffectCallback(event, data);
  9589. $sourceList.toggleClass(classDragRemove, data.isMove);
  9590. break;
  9591. case "dragend":
  9592. // Called at the end of a d'n'd process (after drop)
  9593. // Note caveat: If drop removed the dragged source element,
  9594. // we may not get this event, since the target does not exist
  9595. // anymore
  9596. prepareDropEffectCallback(event, data);
  9597. _clearGlobals();
  9598. data.isCancelled = !LAST_HIT_MODE;
  9599. dndOpts.dragEnd(node, data, !LAST_HIT_MODE);
  9600. // applyDropEffectCallback(event, data);
  9601. break;
  9602. }
  9603. }
  9604. /*
  9605. * Handle dragenter dragover dragleave drop events on the container
  9606. */
  9607. function onDropEvent(event) {
  9608. var json,
  9609. allowAutoExpand,
  9610. nodeData,
  9611. isSourceFtNode,
  9612. r,
  9613. res,
  9614. tree = this,
  9615. dndOpts = tree.options.dnd5,
  9616. allowDrop = null,
  9617. node = FT.getNode(event),
  9618. dataTransfer =
  9619. event.dataTransfer || event.originalEvent.dataTransfer,
  9620. data = {
  9621. tree: tree,
  9622. node: node,
  9623. options: tree.options,
  9624. originalEvent: event.originalEvent,
  9625. widget: tree.widget,
  9626. hitMode: DRAG_ENTER_RESPONSE,
  9627. dataTransfer: dataTransfer,
  9628. otherNode: SOURCE_NODE || null,
  9629. otherNodeList: SOURCE_NODE_LIST || null,
  9630. otherNodeData: null, // set by drop event
  9631. useDefaultImage: true,
  9632. dropEffect: undefined,
  9633. dropEffectSuggested: undefined,
  9634. effectAllowed: undefined, // set by dragstart
  9635. files: null, // list of File objects (may be [])
  9636. isCancelled: undefined, // set by drop event
  9637. isMove: undefined,
  9638. };
  9639. // data.isMove = dropEffect === "move";
  9640. switch (event.type) {
  9641. case "dragenter":
  9642. // The dragenter event is fired when a dragged element or
  9643. // text selection enters a valid drop target.
  9644. DRAG_OVER_STAMP = null;
  9645. if (!node) {
  9646. // Sometimes we get dragenter for the container element
  9647. tree.debug(
  9648. "Ignore non-node " +
  9649. event.type +
  9650. ": " +
  9651. event.target.tagName +
  9652. "." +
  9653. event.target.className
  9654. );
  9655. DRAG_ENTER_RESPONSE = false;
  9656. break;
  9657. }
  9658. $(node.span)
  9659. .addClass(classDropOver)
  9660. .removeClass(classDropAccept + " " + classDropReject);
  9661. // Data is only readable in the dragstart and drop event,
  9662. // but we can check for the type:
  9663. isSourceFtNode =
  9664. $.inArray(nodeMimeType, dataTransfer.types) >= 0;
  9665. if (dndOpts.preventNonNodes && !isSourceFtNode) {
  9666. node.debug("Reject dropping a non-node.");
  9667. DRAG_ENTER_RESPONSE = false;
  9668. break;
  9669. } else if (
  9670. dndOpts.preventForeignNodes &&
  9671. (!SOURCE_NODE || SOURCE_NODE.tree !== node.tree)
  9672. ) {
  9673. node.debug("Reject dropping a foreign node.");
  9674. DRAG_ENTER_RESPONSE = false;
  9675. break;
  9676. } else if (
  9677. dndOpts.preventSameParent &&
  9678. data.otherNode &&
  9679. data.otherNode.tree === node.tree &&
  9680. node.parent === data.otherNode.parent
  9681. ) {
  9682. node.debug("Reject dropping as sibling (same parent).");
  9683. DRAG_ENTER_RESPONSE = false;
  9684. break;
  9685. } else if (
  9686. dndOpts.preventRecursion &&
  9687. data.otherNode &&
  9688. data.otherNode.tree === node.tree &&
  9689. node.isDescendantOf(data.otherNode)
  9690. ) {
  9691. node.debug("Reject dropping below own ancestor.");
  9692. DRAG_ENTER_RESPONSE = false;
  9693. break;
  9694. } else if (dndOpts.preventLazyParents && !node.isLoaded()) {
  9695. node.warn("Drop over unloaded target node prevented.");
  9696. DRAG_ENTER_RESPONSE = false;
  9697. break;
  9698. }
  9699. $dropMarker.show();
  9700. // Call dragEnter() to figure out if (and where) dropping is allowed
  9701. prepareDropEffectCallback(event, data);
  9702. r = dndOpts.dragEnter(node, data);
  9703. res = normalizeDragEnterResponse(r);
  9704. // alert("res:" + JSON.stringify(res))
  9705. DRAG_ENTER_RESPONSE = res;
  9706. allowDrop = res && (res.over || res.before || res.after);
  9707. applyDropEffectCallback(event, data, allowDrop);
  9708. break;
  9709. case "dragover":
  9710. if (!node) {
  9711. tree.debug(
  9712. "Ignore non-node " +
  9713. event.type +
  9714. ": " +
  9715. event.target.tagName +
  9716. "." +
  9717. event.target.className
  9718. );
  9719. break;
  9720. }
  9721. // The dragover event is fired when an element or text
  9722. // selection is being dragged over a valid drop target
  9723. // (every few hundred milliseconds).
  9724. // tree.debug(
  9725. // event.type +
  9726. // ": dropEffect: " +
  9727. // dataTransfer.dropEffect
  9728. // );
  9729. prepareDropEffectCallback(event, data);
  9730. LAST_HIT_MODE = handleDragOver(event, data);
  9731. // The flag controls the preventDefault() below:
  9732. allowDrop = !!LAST_HIT_MODE;
  9733. allowAutoExpand =
  9734. LAST_HIT_MODE === "over" || LAST_HIT_MODE === false;
  9735. if (
  9736. allowAutoExpand &&
  9737. !node.expanded &&
  9738. node.hasChildren() !== false
  9739. ) {
  9740. if (!DRAG_OVER_STAMP) {
  9741. DRAG_OVER_STAMP = Date.now();
  9742. } else if (
  9743. dndOpts.autoExpandMS &&
  9744. Date.now() - DRAG_OVER_STAMP > dndOpts.autoExpandMS &&
  9745. !node.isLoading() &&
  9746. (!dndOpts.dragExpand ||
  9747. dndOpts.dragExpand(node, data) !== false)
  9748. ) {
  9749. node.setExpanded();
  9750. }
  9751. } else {
  9752. DRAG_OVER_STAMP = null;
  9753. }
  9754. break;
  9755. case "dragleave":
  9756. // NOTE: dragleave is fired AFTER the dragenter event of the
  9757. // FOLLOWING element.
  9758. if (!node) {
  9759. tree.debug(
  9760. "Ignore non-node " +
  9761. event.type +
  9762. ": " +
  9763. event.target.tagName +
  9764. "." +
  9765. event.target.className
  9766. );
  9767. break;
  9768. }
  9769. if (!$(node.span).hasClass(classDropOver)) {
  9770. node.debug("Ignore dragleave (multi).");
  9771. break;
  9772. }
  9773. $(node.span).removeClass(
  9774. classDropOver +
  9775. " " +
  9776. classDropAccept +
  9777. " " +
  9778. classDropReject
  9779. );
  9780. node.scheduleAction("cancel");
  9781. dndOpts.dragLeave(node, data);
  9782. $dropMarker.hide();
  9783. break;
  9784. case "drop":
  9785. // Data is only readable in the (dragstart and) drop event:
  9786. if ($.inArray(nodeMimeType, dataTransfer.types) >= 0) {
  9787. nodeData = dataTransfer.getData(nodeMimeType);
  9788. tree.info(
  9789. event.type +
  9790. ": getData('application/x-fancytree-node'): '" +
  9791. nodeData +
  9792. "'"
  9793. );
  9794. }
  9795. if (!nodeData) {
  9796. // 1. Source is not a Fancytree node, or
  9797. // 2. If the FT mime type was set, but returns '', this
  9798. // is probably IE 11 (which only supports 'text')
  9799. nodeData = dataTransfer.getData("text");
  9800. tree.info(
  9801. event.type + ": getData('text'): '" + nodeData + "'"
  9802. );
  9803. }
  9804. if (nodeData) {
  9805. try {
  9806. // 'text' type may contain JSON if IE is involved
  9807. // and setTextTypeJson option was set
  9808. json = JSON.parse(nodeData);
  9809. if (json.title !== undefined) {
  9810. data.otherNodeData = json;
  9811. }
  9812. } catch (ex) {
  9813. // assume 'text' type contains plain text, so `otherNodeData`
  9814. // should not be set
  9815. }
  9816. }
  9817. tree.debug(
  9818. event.type +
  9819. ": nodeData: '" +
  9820. nodeData +
  9821. "', otherNodeData: ",
  9822. data.otherNodeData
  9823. );
  9824. $(node.span).removeClass(
  9825. classDropOver +
  9826. " " +
  9827. classDropAccept +
  9828. " " +
  9829. classDropReject
  9830. );
  9831. // Let user implement the actual drop operation
  9832. data.hitMode = LAST_HIT_MODE;
  9833. prepareDropEffectCallback(event, data, !LAST_HIT_MODE);
  9834. data.isCancelled = !LAST_HIT_MODE;
  9835. var orgSourceElem = SOURCE_NODE && SOURCE_NODE.span,
  9836. orgSourceTree = SOURCE_NODE && SOURCE_NODE.tree;
  9837. dndOpts.dragDrop(node, data);
  9838. // applyDropEffectCallback(event, data);
  9839. // Prevent browser's default drop handling, i.e. open as link, ...
  9840. event.preventDefault();
  9841. if (orgSourceElem && !document.body.contains(orgSourceElem)) {
  9842. // The drop handler removed the original drag source from
  9843. // the DOM, so the dragend event will probaly not fire.
  9844. if (orgSourceTree === tree) {
  9845. tree.debug(
  9846. "Drop handler removed source element: generating dragEnd."
  9847. );
  9848. dndOpts.dragEnd(SOURCE_NODE, data);
  9849. } else {
  9850. tree.warn(
  9851. "Drop handler removed source element: dragend event may be lost."
  9852. );
  9853. }
  9854. }
  9855. _clearGlobals();
  9856. break;
  9857. }
  9858. // Dnd API madness: we must PREVENT default handling to enable dropping
  9859. if (allowDrop) {
  9860. event.preventDefault();
  9861. return false;
  9862. }
  9863. }
  9864. /** [ext-dnd5] Return a Fancytree instance, from element, index, event, or jQueryObject.
  9865. *
  9866. * @returns {FancytreeNode[]} List of nodes (empty if no drag operation)
  9867. * @example
  9868. * $.ui.fancytree.getDragNodeList();
  9869. *
  9870. * @alias Fancytree_Static#getDragNodeList
  9871. * @requires jquery.fancytree.dnd5.js
  9872. * @since 2.31
  9873. */
  9874. $.ui.fancytree.getDragNodeList = function() {
  9875. return SOURCE_NODE_LIST || [];
  9876. };
  9877. /** [ext-dnd5] Return the FancytreeNode that is currently being dragged.
  9878. *
  9879. * If multiple nodes are dragged, only the first is returned.
  9880. *
  9881. * @returns {FancytreeNode | null} dragged nodes or null if no drag operation
  9882. * @example
  9883. * $.ui.fancytree.getDragNode();
  9884. *
  9885. * @alias Fancytree_Static#getDragNode
  9886. * @requires jquery.fancytree.dnd5.js
  9887. * @since 2.31
  9888. */
  9889. $.ui.fancytree.getDragNode = function() {
  9890. return SOURCE_NODE;
  9891. };
  9892. /******************************************************************************
  9893. *
  9894. */
  9895. $.ui.fancytree.registerExtension({
  9896. name: "dnd5",
  9897. version: "2.38.0",
  9898. // Default options for this extension.
  9899. options: {
  9900. autoExpandMS: 1500, // Expand nodes after n milliseconds of hovering
  9901. dropMarkerInsertOffsetX: -16, // Additional offset for drop-marker with hitMode = "before"/"after"
  9902. dropMarkerOffsetX: -24, // Absolute position offset for .fancytree-drop-marker relatively to ..fancytree-title (icon/img near a node accepting drop)
  9903. // #1021 `document.body` is not available yet
  9904. dropMarkerParent: "body", // Root Container used for drop marker (could be a shadow root)
  9905. multiSource: false, // true: Drag multiple (i.e. selected) nodes. Also a callback() is allowed
  9906. effectAllowed: "all", // Restrict the possible cursor shapes and modifier operations (can also be set in the dragStart event)
  9907. // dropEffect: "auto", // 'copy'|'link'|'move'|'auto'(calculate from `effectAllowed`+modifier keys) or callback(node, data) that returns such string.
  9908. dropEffectDefault: "move", // Default dropEffect ('copy', 'link', or 'move') when no modifier is pressed (overide in dragDrag, dragOver).
  9909. preventForeignNodes: false, // Prevent dropping nodes from different Fancytrees
  9910. preventLazyParents: true, // Prevent dropping items on unloaded lazy Fancytree nodes
  9911. preventNonNodes: false, // Prevent dropping items other than Fancytree nodes
  9912. preventRecursion: true, // Prevent dropping nodes on own descendants
  9913. preventSameParent: false, // Prevent dropping nodes under same direct parent
  9914. preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
  9915. scroll: true, // Enable auto-scrolling while dragging
  9916. scrollSensitivity: 20, // Active top/bottom margin in pixel
  9917. scrollSpeed: 5, // Pixel per event
  9918. setTextTypeJson: false, // Allow dragging of nodes to different IE windows
  9919. sourceCopyHook: null, // Optional callback passed to `toDict` on dragStart @since 2.38
  9920. // Events (drag support)
  9921. dragStart: null, // Callback(sourceNode, data), return true, to enable dnd drag
  9922. dragDrag: $.noop, // Callback(sourceNode, data)
  9923. dragEnd: $.noop, // Callback(sourceNode, data)
  9924. // Events (drop support)
  9925. dragEnter: null, // Callback(targetNode, data), return true, to enable dnd drop
  9926. dragOver: $.noop, // Callback(targetNode, data)
  9927. dragExpand: $.noop, // Callback(targetNode, data), return false to prevent autoExpand
  9928. dragDrop: $.noop, // Callback(targetNode, data)
  9929. dragLeave: $.noop, // Callback(targetNode, data)
  9930. },
  9931. treeInit: function(ctx) {
  9932. var $temp,
  9933. tree = ctx.tree,
  9934. opts = ctx.options,
  9935. glyph = opts.glyph || null,
  9936. dndOpts = opts.dnd5;
  9937. if ($.inArray("dnd", opts.extensions) >= 0) {
  9938. $.error("Extensions 'dnd' and 'dnd5' are mutually exclusive.");
  9939. }
  9940. if (dndOpts.dragStop) {
  9941. $.error(
  9942. "dragStop is not used by ext-dnd5. Use dragEnd instead."
  9943. );
  9944. }
  9945. if (dndOpts.preventRecursiveMoves != null) {
  9946. $.error(
  9947. "preventRecursiveMoves was renamed to preventRecursion."
  9948. );
  9949. }
  9950. // Implement `opts.createNode` event to add the 'draggable' attribute
  9951. // #680: this must happen before calling super.treeInit()
  9952. if (dndOpts.dragStart) {
  9953. FT.overrideMethod(ctx.options, "createNode", function(
  9954. event,
  9955. data
  9956. ) {
  9957. // Default processing if any
  9958. this._super.apply(this, arguments);
  9959. if (data.node.span) {
  9960. data.node.span.draggable = true;
  9961. } else {
  9962. data.node.warn("Cannot add `draggable`: no span tag");
  9963. }
  9964. });
  9965. }
  9966. this._superApply(arguments);
  9967. this.$container.addClass("fancytree-ext-dnd5");
  9968. // Store the current scroll parent, which may be the tree
  9969. // container, any enclosing div, or the document.
  9970. // #761: scrollParent() always needs a container child
  9971. $temp = $("<span>").appendTo(this.$container);
  9972. this.$scrollParent = $temp.scrollParent();
  9973. $temp.remove();
  9974. $dropMarker = $("#fancytree-drop-marker");
  9975. if (!$dropMarker.length) {
  9976. $dropMarker = $("<div id='fancytree-drop-marker'></div>")
  9977. .hide()
  9978. .css({
  9979. "z-index": 1000,
  9980. // Drop marker should not steal dragenter/dragover events:
  9981. "pointer-events": "none",
  9982. })
  9983. .prependTo(dndOpts.dropMarkerParent);
  9984. if (glyph) {
  9985. FT.setSpanIcon(
  9986. $dropMarker[0],
  9987. glyph.map._addClass,
  9988. glyph.map.dropMarker
  9989. );
  9990. }
  9991. }
  9992. $dropMarker.toggleClass("fancytree-rtl", !!opts.rtl);
  9993. // Enable drag support if dragStart() is specified:
  9994. if (dndOpts.dragStart) {
  9995. // Bind drag event handlers
  9996. tree.$container.on(
  9997. "dragstart drag dragend",
  9998. onDragEvent.bind(tree)
  9999. );
  10000. }
  10001. // Enable drop support if dragEnter() is specified:
  10002. if (dndOpts.dragEnter) {
  10003. // Bind drop event handlers
  10004. tree.$container.on(
  10005. "dragenter dragover dragleave drop",
  10006. onDropEvent.bind(tree)
  10007. );
  10008. }
  10009. },
  10010. });
  10011. // Value returned by `require('jquery.fancytree..')`
  10012. return $.ui.fancytree;
  10013. }); // End of closure
  10014. /*! Extension 'jquery.fancytree.edit.js' *//*!
  10015. * jquery.fancytree.edit.js
  10016. *
  10017. * Make node titles editable.
  10018. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10019. *
  10020. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  10021. *
  10022. * Released under the MIT license
  10023. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10024. *
  10025. * @version 2.38.0
  10026. * @date 2021-02-09T20:03:49Z
  10027. */
  10028. (function(factory) {
  10029. if (typeof define === "function" && define.amd) {
  10030. // AMD. Register as an anonymous module.
  10031. define(["jquery", "./jquery.fancytree"], factory);
  10032. } else if (typeof module === "object" && module.exports) {
  10033. // Node/CommonJS
  10034. require("./jquery.fancytree");
  10035. module.exports = factory(require("jquery"));
  10036. } else {
  10037. // Browser globals
  10038. factory(jQuery);
  10039. }
  10040. })(function($) {
  10041. "use strict";
  10042. /*******************************************************************************
  10043. * Private functions and variables
  10044. */
  10045. var isMac = /Mac/.test(navigator.platform),
  10046. escapeHtml = $.ui.fancytree.escapeHtml,
  10047. unescapeHtml = $.ui.fancytree.unescapeHtml;
  10048. /**
  10049. * [ext-edit] Start inline editing of current node title.
  10050. *
  10051. * @alias FancytreeNode#editStart
  10052. * @requires Fancytree
  10053. */
  10054. $.ui.fancytree._FancytreeNodeClass.prototype.editStart = function() {
  10055. var $input,
  10056. node = this,
  10057. tree = this.tree,
  10058. local = tree.ext.edit,
  10059. instOpts = tree.options.edit,
  10060. $title = $(".fancytree-title", node.span),
  10061. eventData = {
  10062. node: node,
  10063. tree: tree,
  10064. options: tree.options,
  10065. isNew: $(node[tree.statusClassPropName]).hasClass(
  10066. "fancytree-edit-new"
  10067. ),
  10068. orgTitle: node.title,
  10069. input: null,
  10070. dirty: false,
  10071. };
  10072. // beforeEdit may want to modify the title before editing
  10073. if (
  10074. instOpts.beforeEdit.call(
  10075. node,
  10076. { type: "beforeEdit" },
  10077. eventData
  10078. ) === false
  10079. ) {
  10080. return false;
  10081. }
  10082. $.ui.fancytree.assert(!local.currentNode, "recursive edit");
  10083. local.currentNode = this;
  10084. local.eventData = eventData;
  10085. // Disable standard Fancytree mouse- and key handling
  10086. tree.widget._unbind();
  10087. local.lastDraggableAttrValue = node.span.draggable;
  10088. if (local.lastDraggableAttrValue) {
  10089. node.span.draggable = false;
  10090. }
  10091. // #116: ext-dnd prevents the blur event, so we have to catch outer clicks
  10092. $(document).on("mousedown.fancytree-edit", function(event) {
  10093. if (!$(event.target).hasClass("fancytree-edit-input")) {
  10094. node.editEnd(true, event);
  10095. }
  10096. });
  10097. // Replace node with <input>
  10098. $input = $("<input />", {
  10099. class: "fancytree-edit-input",
  10100. type: "text",
  10101. value: tree.options.escapeTitles
  10102. ? eventData.orgTitle
  10103. : unescapeHtml(eventData.orgTitle),
  10104. });
  10105. local.eventData.input = $input;
  10106. if (instOpts.adjustWidthOfs != null) {
  10107. $input.width($title.width() + instOpts.adjustWidthOfs);
  10108. }
  10109. if (instOpts.inputCss != null) {
  10110. $input.css(instOpts.inputCss);
  10111. }
  10112. $title.html($input);
  10113. // Focus <input> and bind keyboard handler
  10114. $input
  10115. .focus()
  10116. .change(function(event) {
  10117. $input.addClass("fancytree-edit-dirty");
  10118. })
  10119. .on("keydown", function(event) {
  10120. switch (event.which) {
  10121. case $.ui.keyCode.ESCAPE:
  10122. node.editEnd(false, event);
  10123. break;
  10124. case $.ui.keyCode.ENTER:
  10125. node.editEnd(true, event);
  10126. return false; // so we don't start editmode on Mac
  10127. }
  10128. event.stopPropagation();
  10129. })
  10130. .blur(function(event) {
  10131. return node.editEnd(true, event);
  10132. });
  10133. instOpts.edit.call(node, { type: "edit" }, eventData);
  10134. };
  10135. /**
  10136. * [ext-edit] Stop inline editing.
  10137. * @param {Boolean} [applyChanges=false] false: cancel edit, true: save (if modified)
  10138. * @alias FancytreeNode#editEnd
  10139. * @requires jquery.fancytree.edit.js
  10140. */
  10141. $.ui.fancytree._FancytreeNodeClass.prototype.editEnd = function(
  10142. applyChanges,
  10143. _event
  10144. ) {
  10145. var newVal,
  10146. node = this,
  10147. tree = this.tree,
  10148. local = tree.ext.edit,
  10149. eventData = local.eventData,
  10150. instOpts = tree.options.edit,
  10151. $title = $(".fancytree-title", node.span),
  10152. $input = $title.find("input.fancytree-edit-input");
  10153. if (instOpts.trim) {
  10154. $input.val($.trim($input.val()));
  10155. }
  10156. newVal = $input.val();
  10157. eventData.dirty = newVal !== node.title;
  10158. eventData.originalEvent = _event;
  10159. // Find out, if saving is required
  10160. if (applyChanges === false) {
  10161. // If true/false was passed, honor this (except in rename mode, if unchanged)
  10162. eventData.save = false;
  10163. } else if (eventData.isNew) {
  10164. // In create mode, we save everything, except for empty text
  10165. eventData.save = newVal !== "";
  10166. } else {
  10167. // In rename mode, we save everyting, except for empty or unchanged text
  10168. eventData.save = eventData.dirty && newVal !== "";
  10169. }
  10170. // Allow to break (keep editor open), modify input, or re-define data.save
  10171. if (
  10172. instOpts.beforeClose.call(
  10173. node,
  10174. { type: "beforeClose" },
  10175. eventData
  10176. ) === false
  10177. ) {
  10178. return false;
  10179. }
  10180. if (
  10181. eventData.save &&
  10182. instOpts.save.call(node, { type: "save" }, eventData) === false
  10183. ) {
  10184. return false;
  10185. }
  10186. $input.removeClass("fancytree-edit-dirty").off();
  10187. // Unbind outer-click handler
  10188. $(document).off(".fancytree-edit");
  10189. if (eventData.save) {
  10190. // # 171: escape user input (not required if global escaping is on)
  10191. node.setTitle(
  10192. tree.options.escapeTitles ? newVal : escapeHtml(newVal)
  10193. );
  10194. node.setFocus();
  10195. } else {
  10196. if (eventData.isNew) {
  10197. node.remove();
  10198. node = eventData.node = null;
  10199. local.relatedNode.setFocus();
  10200. } else {
  10201. node.renderTitle();
  10202. node.setFocus();
  10203. }
  10204. }
  10205. local.eventData = null;
  10206. local.currentNode = null;
  10207. local.relatedNode = null;
  10208. // Re-enable mouse and keyboard handling
  10209. tree.widget._bind();
  10210. if (node && local.lastDraggableAttrValue) {
  10211. node.span.draggable = true;
  10212. }
  10213. // Set keyboard focus, even if setFocus() claims 'nothing to do'
  10214. tree.$container.get(0).focus({ preventScroll: true });
  10215. eventData.input = null;
  10216. instOpts.close.call(node, { type: "close" }, eventData);
  10217. return true;
  10218. };
  10219. /**
  10220. * [ext-edit] Create a new child or sibling node and start edit mode.
  10221. *
  10222. * @param {String} [mode='child'] 'before', 'after', or 'child'
  10223. * @param {Object} [init] NodeData (or simple title string)
  10224. * @alias FancytreeNode#editCreateNode
  10225. * @requires jquery.fancytree.edit.js
  10226. * @since 2.4
  10227. */
  10228. $.ui.fancytree._FancytreeNodeClass.prototype.editCreateNode = function(
  10229. mode,
  10230. init
  10231. ) {
  10232. var newNode,
  10233. tree = this.tree,
  10234. self = this;
  10235. mode = mode || "child";
  10236. if (init == null) {
  10237. init = { title: "" };
  10238. } else if (typeof init === "string") {
  10239. init = { title: init };
  10240. } else {
  10241. $.ui.fancytree.assert($.isPlainObject(init));
  10242. }
  10243. // Make sure node is expanded (and loaded) in 'child' mode
  10244. if (
  10245. mode === "child" &&
  10246. !this.isExpanded() &&
  10247. this.hasChildren() !== false
  10248. ) {
  10249. this.setExpanded().done(function() {
  10250. self.editCreateNode(mode, init);
  10251. });
  10252. return;
  10253. }
  10254. newNode = this.addNode(init, mode);
  10255. // #644: Don't filter new nodes.
  10256. newNode.match = true;
  10257. $(newNode[tree.statusClassPropName])
  10258. .removeClass("fancytree-hide")
  10259. .addClass("fancytree-match");
  10260. newNode.makeVisible(/*{noAnimation: true}*/).done(function() {
  10261. $(newNode[tree.statusClassPropName]).addClass("fancytree-edit-new");
  10262. self.tree.ext.edit.relatedNode = self;
  10263. newNode.editStart();
  10264. });
  10265. };
  10266. /**
  10267. * [ext-edit] Check if any node in this tree in edit mode.
  10268. *
  10269. * @returns {FancytreeNode | null}
  10270. * @alias Fancytree#isEditing
  10271. * @requires jquery.fancytree.edit.js
  10272. */
  10273. $.ui.fancytree._FancytreeClass.prototype.isEditing = function() {
  10274. return this.ext.edit ? this.ext.edit.currentNode : null;
  10275. };
  10276. /**
  10277. * [ext-edit] Check if this node is in edit mode.
  10278. * @returns {Boolean} true if node is currently beeing edited
  10279. * @alias FancytreeNode#isEditing
  10280. * @requires jquery.fancytree.edit.js
  10281. */
  10282. $.ui.fancytree._FancytreeNodeClass.prototype.isEditing = function() {
  10283. return this.tree.ext.edit
  10284. ? this.tree.ext.edit.currentNode === this
  10285. : false;
  10286. };
  10287. /*******************************************************************************
  10288. * Extension code
  10289. */
  10290. $.ui.fancytree.registerExtension({
  10291. name: "edit",
  10292. version: "2.38.0",
  10293. // Default options for this extension.
  10294. options: {
  10295. adjustWidthOfs: 4, // null: don't adjust input size to content
  10296. allowEmpty: false, // Prevent empty input
  10297. inputCss: { minWidth: "3em" },
  10298. // triggerCancel: ["esc", "tab", "click"],
  10299. triggerStart: ["f2", "mac+enter", "shift+click"],
  10300. trim: true, // Trim whitespace before save
  10301. // Events:
  10302. beforeClose: $.noop, // Return false to prevent cancel/save (data.input is available)
  10303. beforeEdit: $.noop, // Return false to prevent edit mode
  10304. close: $.noop, // Editor was removed
  10305. edit: $.noop, // Editor was opened (available as data.input)
  10306. // keypress: $.noop, // Not yet implemented
  10307. save: $.noop, // Save data.input.val() or return false to keep editor open
  10308. },
  10309. // Local attributes
  10310. currentNode: null,
  10311. treeInit: function(ctx) {
  10312. var tree = ctx.tree;
  10313. this._superApply(arguments);
  10314. this.$container
  10315. .addClass("fancytree-ext-edit")
  10316. .on("fancytreebeforeupdateviewport", function(event, data) {
  10317. var editNode = tree.isEditing();
  10318. // When scrolling, the TR may be re-used by another node, so the
  10319. // active cell marker an
  10320. if (editNode) {
  10321. editNode.info("Cancel edit due to scroll event.");
  10322. editNode.editEnd(false, event);
  10323. }
  10324. });
  10325. },
  10326. nodeClick: function(ctx) {
  10327. var eventStr = $.ui.fancytree.eventToString(ctx.originalEvent),
  10328. triggerStart = ctx.options.edit.triggerStart;
  10329. if (
  10330. eventStr === "shift+click" &&
  10331. $.inArray("shift+click", triggerStart) >= 0
  10332. ) {
  10333. if (ctx.originalEvent.shiftKey) {
  10334. ctx.node.editStart();
  10335. return false;
  10336. }
  10337. }
  10338. if (
  10339. eventStr === "click" &&
  10340. $.inArray("clickActive", triggerStart) >= 0
  10341. ) {
  10342. // Only when click was inside title text (not aynwhere else in the row)
  10343. if (
  10344. ctx.node.isActive() &&
  10345. !ctx.node.isEditing() &&
  10346. $(ctx.originalEvent.target).hasClass("fancytree-title")
  10347. ) {
  10348. ctx.node.editStart();
  10349. return false;
  10350. }
  10351. }
  10352. return this._superApply(arguments);
  10353. },
  10354. nodeDblclick: function(ctx) {
  10355. if ($.inArray("dblclick", ctx.options.edit.triggerStart) >= 0) {
  10356. ctx.node.editStart();
  10357. return false;
  10358. }
  10359. return this._superApply(arguments);
  10360. },
  10361. nodeKeydown: function(ctx) {
  10362. switch (ctx.originalEvent.which) {
  10363. case 113: // [F2]
  10364. if ($.inArray("f2", ctx.options.edit.triggerStart) >= 0) {
  10365. ctx.node.editStart();
  10366. return false;
  10367. }
  10368. break;
  10369. case $.ui.keyCode.ENTER:
  10370. if (
  10371. $.inArray("mac+enter", ctx.options.edit.triggerStart) >=
  10372. 0 &&
  10373. isMac
  10374. ) {
  10375. ctx.node.editStart();
  10376. return false;
  10377. }
  10378. break;
  10379. }
  10380. return this._superApply(arguments);
  10381. },
  10382. });
  10383. // Value returned by `require('jquery.fancytree..')`
  10384. return $.ui.fancytree;
  10385. }); // End of closure
  10386. /*! Extension 'jquery.fancytree.filter.js' *//*!
  10387. * jquery.fancytree.filter.js
  10388. *
  10389. * Remove or highlight tree nodes, based on a filter.
  10390. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10391. *
  10392. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  10393. *
  10394. * Released under the MIT license
  10395. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10396. *
  10397. * @version 2.38.0
  10398. * @date 2021-02-09T20:03:49Z
  10399. */
  10400. (function(factory) {
  10401. if (typeof define === "function" && define.amd) {
  10402. // AMD. Register as an anonymous module.
  10403. define(["jquery", "./jquery.fancytree"], factory);
  10404. } else if (typeof module === "object" && module.exports) {
  10405. // Node/CommonJS
  10406. require("./jquery.fancytree");
  10407. module.exports = factory(require("jquery"));
  10408. } else {
  10409. // Browser globals
  10410. factory(jQuery);
  10411. }
  10412. })(function($) {
  10413. "use strict";
  10414. /*******************************************************************************
  10415. * Private functions and variables
  10416. */
  10417. var KeyNoData = "__not_found__",
  10418. escapeHtml = $.ui.fancytree.escapeHtml,
  10419. exoticStartChar = "\uFFF7",
  10420. exoticEndChar = "\uFFF8";
  10421. function _escapeRegex(str) {
  10422. return (str + "").replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
  10423. }
  10424. function extractHtmlText(s) {
  10425. if (s.indexOf(">") >= 0) {
  10426. return $("<div/>")
  10427. .html(s)
  10428. .text();
  10429. }
  10430. return s;
  10431. }
  10432. /**
  10433. * @description Marks the matching charecters of `text` either by `mark` or
  10434. * by exotic*Chars (if `escapeTitles` is `true`) based on `regexMatchArray`
  10435. * which is an array of matching groups.
  10436. * @param {string} text
  10437. * @param {RegExpMatchArray} regexMatchArray
  10438. */
  10439. function _markFuzzyMatchedChars(text, regexMatchArray, escapeTitles) {
  10440. // It is extremely infuriating that we can not use `let` or `const` or arrow functions.
  10441. // Damn you IE!!!
  10442. var matchingIndices = [];
  10443. // get the indices of matched characters (Iterate through `RegExpMatchArray`)
  10444. for (
  10445. var _matchingArrIdx = 1;
  10446. _matchingArrIdx < regexMatchArray.length;
  10447. _matchingArrIdx++
  10448. ) {
  10449. var _mIdx =
  10450. // get matching char index by cumulatively adding
  10451. // the matched group length
  10452. regexMatchArray[_matchingArrIdx].length +
  10453. (_matchingArrIdx === 1 ? 0 : 1) +
  10454. (matchingIndices[matchingIndices.length - 1] || 0);
  10455. matchingIndices.push(_mIdx);
  10456. }
  10457. // Map each `text` char to its position and store in `textPoses`.
  10458. var textPoses = text.split("");
  10459. if (escapeTitles) {
  10460. // If escaping the title, then wrap the matchng char within exotic chars
  10461. matchingIndices.forEach(function(v) {
  10462. textPoses[v] = exoticStartChar + textPoses[v] + exoticEndChar;
  10463. });
  10464. } else {
  10465. // Otherwise, Wrap the matching chars within `mark`.
  10466. matchingIndices.forEach(function(v) {
  10467. textPoses[v] = "<mark>" + textPoses[v] + "</mark>";
  10468. });
  10469. }
  10470. // Join back the modified `textPoses` to create final highlight markup.
  10471. return textPoses.join("");
  10472. }
  10473. $.ui.fancytree._FancytreeClass.prototype._applyFilterImpl = function(
  10474. filter,
  10475. branchMode,
  10476. _opts
  10477. ) {
  10478. var match,
  10479. statusNode,
  10480. re,
  10481. reHighlight,
  10482. reExoticStartChar,
  10483. reExoticEndChar,
  10484. temp,
  10485. prevEnableUpdate,
  10486. count = 0,
  10487. treeOpts = this.options,
  10488. escapeTitles = treeOpts.escapeTitles,
  10489. prevAutoCollapse = treeOpts.autoCollapse,
  10490. opts = $.extend({}, treeOpts.filter, _opts),
  10491. hideMode = opts.mode === "hide",
  10492. leavesOnly = !!opts.leavesOnly && !branchMode;
  10493. // Default to 'match title substring (not case sensitive)'
  10494. if (typeof filter === "string") {
  10495. if (filter === "") {
  10496. this.warn(
  10497. "Fancytree passing an empty string as a filter is handled as clearFilter()."
  10498. );
  10499. this.clearFilter();
  10500. return;
  10501. }
  10502. if (opts.fuzzy) {
  10503. // See https://codereview.stackexchange.com/questions/23899/faster-javascript-fuzzy-string-matching-function/23905#23905
  10504. // and http://www.quora.com/How-is-the-fuzzy-search-algorithm-in-Sublime-Text-designed
  10505. // and http://www.dustindiaz.com/autocomplete-fuzzy-matching
  10506. match = filter
  10507. .split("")
  10508. // Escaping the `filter` will not work because,
  10509. // it gets further split into individual characters. So,
  10510. // escape each character after splitting
  10511. .map(_escapeRegex)
  10512. .reduce(function(a, b) {
  10513. // create capture groups for parts that comes before
  10514. // the character
  10515. return a + "([^" + b + "]*)" + b;
  10516. }, "");
  10517. } else {
  10518. match = _escapeRegex(filter); // make sure a '.' is treated literally
  10519. }
  10520. re = new RegExp(match, "i");
  10521. reHighlight = new RegExp(_escapeRegex(filter), "gi");
  10522. if (escapeTitles) {
  10523. reExoticStartChar = new RegExp(
  10524. _escapeRegex(exoticStartChar),
  10525. "g"
  10526. );
  10527. reExoticEndChar = new RegExp(_escapeRegex(exoticEndChar), "g");
  10528. }
  10529. filter = function(node) {
  10530. if (!node.title) {
  10531. return false;
  10532. }
  10533. var text = escapeTitles
  10534. ? node.title
  10535. : extractHtmlText(node.title),
  10536. // `.match` instead of `.test` to get the capture groups
  10537. res = text.match(re);
  10538. if (res && opts.highlight) {
  10539. if (escapeTitles) {
  10540. if (opts.fuzzy) {
  10541. temp = _markFuzzyMatchedChars(
  10542. text,
  10543. res,
  10544. escapeTitles
  10545. );
  10546. } else {
  10547. // #740: we must not apply the marks to escaped entity names, e.g. `&quot;`
  10548. // Use some exotic characters to mark matches:
  10549. temp = text.replace(reHighlight, function(s) {
  10550. return exoticStartChar + s + exoticEndChar;
  10551. });
  10552. }
  10553. // now we can escape the title...
  10554. node.titleWithHighlight = escapeHtml(temp)
  10555. // ... and finally insert the desired `<mark>` tags
  10556. .replace(reExoticStartChar, "<mark>")
  10557. .replace(reExoticEndChar, "</mark>");
  10558. } else {
  10559. if (opts.fuzzy) {
  10560. node.titleWithHighlight = _markFuzzyMatchedChars(
  10561. text,
  10562. res
  10563. );
  10564. } else {
  10565. node.titleWithHighlight = text.replace(
  10566. reHighlight,
  10567. function(s) {
  10568. return "<mark>" + s + "</mark>";
  10569. }
  10570. );
  10571. }
  10572. }
  10573. // node.debug("filter", escapeTitles, text, node.titleWithHighlight);
  10574. }
  10575. return !!res;
  10576. };
  10577. }
  10578. this.enableFilter = true;
  10579. this.lastFilterArgs = arguments;
  10580. prevEnableUpdate = this.enableUpdate(false);
  10581. this.$div.addClass("fancytree-ext-filter");
  10582. if (hideMode) {
  10583. this.$div.addClass("fancytree-ext-filter-hide");
  10584. } else {
  10585. this.$div.addClass("fancytree-ext-filter-dimm");
  10586. }
  10587. this.$div.toggleClass(
  10588. "fancytree-ext-filter-hide-expanders",
  10589. !!opts.hideExpanders
  10590. );
  10591. // Reset current filter
  10592. this.rootNode.subMatchCount = 0;
  10593. this.visit(function(node) {
  10594. delete node.match;
  10595. delete node.titleWithHighlight;
  10596. node.subMatchCount = 0;
  10597. });
  10598. statusNode = this.getRootNode()._findDirectChild(KeyNoData);
  10599. if (statusNode) {
  10600. statusNode.remove();
  10601. }
  10602. // Adjust node.hide, .match, and .subMatchCount properties
  10603. treeOpts.autoCollapse = false; // #528
  10604. this.visit(function(node) {
  10605. if (leavesOnly && node.children != null) {
  10606. return;
  10607. }
  10608. var res = filter(node),
  10609. matchedByBranch = false;
  10610. if (res === "skip") {
  10611. node.visit(function(c) {
  10612. c.match = false;
  10613. }, true);
  10614. return "skip";
  10615. }
  10616. if (!res && (branchMode || res === "branch") && node.parent.match) {
  10617. res = true;
  10618. matchedByBranch = true;
  10619. }
  10620. if (res) {
  10621. count++;
  10622. node.match = true;
  10623. node.visitParents(function(p) {
  10624. if (p !== node) {
  10625. p.subMatchCount += 1;
  10626. }
  10627. // Expand match (unless this is no real match, but only a node in a matched branch)
  10628. if (opts.autoExpand && !matchedByBranch && !p.expanded) {
  10629. p.setExpanded(true, {
  10630. noAnimation: true,
  10631. noEvents: true,
  10632. scrollIntoView: false,
  10633. });
  10634. p._filterAutoExpanded = true;
  10635. }
  10636. }, true);
  10637. }
  10638. });
  10639. treeOpts.autoCollapse = prevAutoCollapse;
  10640. if (count === 0 && opts.nodata && hideMode) {
  10641. statusNode = opts.nodata;
  10642. if ($.isFunction(statusNode)) {
  10643. statusNode = statusNode();
  10644. }
  10645. if (statusNode === true) {
  10646. statusNode = {};
  10647. } else if (typeof statusNode === "string") {
  10648. statusNode = { title: statusNode };
  10649. }
  10650. statusNode = $.extend(
  10651. {
  10652. statusNodeType: "nodata",
  10653. key: KeyNoData,
  10654. title: this.options.strings.noData,
  10655. },
  10656. statusNode
  10657. );
  10658. this.getRootNode().addNode(statusNode).match = true;
  10659. }
  10660. // Redraw whole tree
  10661. this._callHook("treeStructureChanged", this, "applyFilter");
  10662. // this.render();
  10663. this.enableUpdate(prevEnableUpdate);
  10664. return count;
  10665. };
  10666. /**
  10667. * [ext-filter] Dimm or hide nodes.
  10668. *
  10669. * @param {function | string} filter
  10670. * @param {boolean} [opts={autoExpand: false, leavesOnly: false}]
  10671. * @returns {integer} count
  10672. * @alias Fancytree#filterNodes
  10673. * @requires jquery.fancytree.filter.js
  10674. */
  10675. $.ui.fancytree._FancytreeClass.prototype.filterNodes = function(
  10676. filter,
  10677. opts
  10678. ) {
  10679. if (typeof opts === "boolean") {
  10680. opts = { leavesOnly: opts };
  10681. this.warn(
  10682. "Fancytree.filterNodes() leavesOnly option is deprecated since 2.9.0 / 2015-04-19. Use opts.leavesOnly instead."
  10683. );
  10684. }
  10685. return this._applyFilterImpl(filter, false, opts);
  10686. };
  10687. /**
  10688. * [ext-filter] Dimm or hide whole branches.
  10689. *
  10690. * @param {function | string} filter
  10691. * @param {boolean} [opts={autoExpand: false}]
  10692. * @returns {integer} count
  10693. * @alias Fancytree#filterBranches
  10694. * @requires jquery.fancytree.filter.js
  10695. */
  10696. $.ui.fancytree._FancytreeClass.prototype.filterBranches = function(
  10697. filter,
  10698. opts
  10699. ) {
  10700. return this._applyFilterImpl(filter, true, opts);
  10701. };
  10702. /**
  10703. * [ext-filter] Re-apply current filter.
  10704. *
  10705. * @returns {integer} count
  10706. * @alias Fancytree#updateFilter
  10707. * @requires jquery.fancytree.filter.js
  10708. * @since 2.38
  10709. */
  10710. $.ui.fancytree._FancytreeClass.prototype.updateFilter = function() {
  10711. if (
  10712. this.enableFilter &&
  10713. this.lastFilterArgs &&
  10714. this.options.filter.autoApply
  10715. ) {
  10716. this._applyFilterImpl.apply(this, this.lastFilterArgs);
  10717. } else {
  10718. this.warn("updateFilter(): no filter active.");
  10719. }
  10720. };
  10721. /**
  10722. * [ext-filter] Reset the filter.
  10723. *
  10724. * @alias Fancytree#clearFilter
  10725. * @requires jquery.fancytree.filter.js
  10726. */
  10727. $.ui.fancytree._FancytreeClass.prototype.clearFilter = function() {
  10728. var $title,
  10729. statusNode = this.getRootNode()._findDirectChild(KeyNoData),
  10730. escapeTitles = this.options.escapeTitles,
  10731. enhanceTitle = this.options.enhanceTitle,
  10732. prevEnableUpdate = this.enableUpdate(false);
  10733. if (statusNode) {
  10734. statusNode.remove();
  10735. }
  10736. // we also counted root node's subMatchCount
  10737. delete this.rootNode.match;
  10738. delete this.rootNode.subMatchCount;
  10739. this.visit(function(node) {
  10740. if (node.match && node.span) {
  10741. // #491, #601
  10742. $title = $(node.span).find(">span.fancytree-title");
  10743. if (escapeTitles) {
  10744. $title.text(node.title);
  10745. } else {
  10746. $title.html(node.title);
  10747. }
  10748. if (enhanceTitle) {
  10749. enhanceTitle(
  10750. { type: "enhanceTitle" },
  10751. { node: node, $title: $title }
  10752. );
  10753. }
  10754. }
  10755. delete node.match;
  10756. delete node.subMatchCount;
  10757. delete node.titleWithHighlight;
  10758. if (node.$subMatchBadge) {
  10759. node.$subMatchBadge.remove();
  10760. delete node.$subMatchBadge;
  10761. }
  10762. if (node._filterAutoExpanded && node.expanded) {
  10763. node.setExpanded(false, {
  10764. noAnimation: true,
  10765. noEvents: true,
  10766. scrollIntoView: false,
  10767. });
  10768. }
  10769. delete node._filterAutoExpanded;
  10770. });
  10771. this.enableFilter = false;
  10772. this.lastFilterArgs = null;
  10773. this.$div.removeClass(
  10774. "fancytree-ext-filter fancytree-ext-filter-dimm fancytree-ext-filter-hide"
  10775. );
  10776. this._callHook("treeStructureChanged", this, "clearFilter");
  10777. // this.render();
  10778. this.enableUpdate(prevEnableUpdate);
  10779. };
  10780. /**
  10781. * [ext-filter] Return true if a filter is currently applied.
  10782. *
  10783. * @returns {Boolean}
  10784. * @alias Fancytree#isFilterActive
  10785. * @requires jquery.fancytree.filter.js
  10786. * @since 2.13
  10787. */
  10788. $.ui.fancytree._FancytreeClass.prototype.isFilterActive = function() {
  10789. return !!this.enableFilter;
  10790. };
  10791. /**
  10792. * [ext-filter] Return true if this node is matched by current filter (or no filter is active).
  10793. *
  10794. * @returns {Boolean}
  10795. * @alias FancytreeNode#isMatched
  10796. * @requires jquery.fancytree.filter.js
  10797. * @since 2.13
  10798. */
  10799. $.ui.fancytree._FancytreeNodeClass.prototype.isMatched = function() {
  10800. return !(this.tree.enableFilter && !this.match);
  10801. };
  10802. /*******************************************************************************
  10803. * Extension code
  10804. */
  10805. $.ui.fancytree.registerExtension({
  10806. name: "filter",
  10807. version: "2.38.0",
  10808. // Default options for this extension.
  10809. options: {
  10810. autoApply: true, // Re-apply last filter if lazy data is loaded
  10811. autoExpand: false, // Expand all branches that contain matches while filtered
  10812. counter: true, // Show a badge with number of matching child nodes near parent icons
  10813. fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar'
  10814. hideExpandedCounter: true, // Hide counter badge if parent is expanded
  10815. hideExpanders: false, // Hide expanders if all child nodes are hidden by filter
  10816. highlight: true, // Highlight matches by wrapping inside <mark> tags
  10817. leavesOnly: false, // Match end nodes only
  10818. nodata: true, // Display a 'no data' status node if result is empty
  10819. mode: "dimm", // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
  10820. },
  10821. nodeLoadChildren: function(ctx, source) {
  10822. var tree = ctx.tree;
  10823. return this._superApply(arguments).done(function() {
  10824. if (
  10825. tree.enableFilter &&
  10826. tree.lastFilterArgs &&
  10827. ctx.options.filter.autoApply
  10828. ) {
  10829. tree._applyFilterImpl.apply(tree, tree.lastFilterArgs);
  10830. }
  10831. });
  10832. },
  10833. nodeSetExpanded: function(ctx, flag, callOpts) {
  10834. var node = ctx.node;
  10835. delete node._filterAutoExpanded;
  10836. // Make sure counter badge is displayed again, when node is beeing collapsed
  10837. if (
  10838. !flag &&
  10839. ctx.options.filter.hideExpandedCounter &&
  10840. node.$subMatchBadge
  10841. ) {
  10842. node.$subMatchBadge.show();
  10843. }
  10844. return this._superApply(arguments);
  10845. },
  10846. nodeRenderStatus: function(ctx) {
  10847. // Set classes for current status
  10848. var res,
  10849. node = ctx.node,
  10850. tree = ctx.tree,
  10851. opts = ctx.options.filter,
  10852. $title = $(node.span).find("span.fancytree-title"),
  10853. $span = $(node[tree.statusClassPropName]),
  10854. enhanceTitle = ctx.options.enhanceTitle,
  10855. escapeTitles = ctx.options.escapeTitles;
  10856. res = this._super(ctx);
  10857. // nothing to do, if node was not yet rendered
  10858. if (!$span.length || !tree.enableFilter) {
  10859. return res;
  10860. }
  10861. $span
  10862. .toggleClass("fancytree-match", !!node.match)
  10863. .toggleClass("fancytree-submatch", !!node.subMatchCount)
  10864. .toggleClass(
  10865. "fancytree-hide",
  10866. !(node.match || node.subMatchCount)
  10867. );
  10868. // Add/update counter badge
  10869. if (
  10870. opts.counter &&
  10871. node.subMatchCount &&
  10872. (!node.isExpanded() || !opts.hideExpandedCounter)
  10873. ) {
  10874. if (!node.$subMatchBadge) {
  10875. node.$subMatchBadge = $(
  10876. "<span class='fancytree-childcounter'/>"
  10877. );
  10878. $(
  10879. "span.fancytree-icon, span.fancytree-custom-icon",
  10880. node.span
  10881. ).append(node.$subMatchBadge);
  10882. }
  10883. node.$subMatchBadge.show().text(node.subMatchCount);
  10884. } else if (node.$subMatchBadge) {
  10885. node.$subMatchBadge.hide();
  10886. }
  10887. // node.debug("nodeRenderStatus", node.titleWithHighlight, node.title)
  10888. // #601: also check for $title.length, because we don't need to render
  10889. // if node.span is null (i.e. not rendered)
  10890. if (node.span && (!node.isEditing || !node.isEditing.call(node))) {
  10891. if (node.titleWithHighlight) {
  10892. $title.html(node.titleWithHighlight);
  10893. } else if (escapeTitles) {
  10894. $title.text(node.title);
  10895. } else {
  10896. $title.html(node.title);
  10897. }
  10898. if (enhanceTitle) {
  10899. enhanceTitle(
  10900. { type: "enhanceTitle" },
  10901. { node: node, $title: $title }
  10902. );
  10903. }
  10904. }
  10905. return res;
  10906. },
  10907. });
  10908. // Value returned by `require('jquery.fancytree..')`
  10909. return $.ui.fancytree;
  10910. }); // End of closure
  10911. /*! Extension 'jquery.fancytree.glyph.js' *//*!
  10912. * jquery.fancytree.glyph.js
  10913. *
  10914. * Use glyph-fonts, ligature-fonts, or SVG icons instead of icon sprites.
  10915. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10916. *
  10917. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  10918. *
  10919. * Released under the MIT license
  10920. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10921. *
  10922. * @version 2.38.0
  10923. * @date 2021-02-09T20:03:49Z
  10924. */
  10925. (function(factory) {
  10926. if (typeof define === "function" && define.amd) {
  10927. // AMD. Register as an anonymous module.
  10928. define(["jquery", "./jquery.fancytree"], factory);
  10929. } else if (typeof module === "object" && module.exports) {
  10930. // Node/CommonJS
  10931. require("./jquery.fancytree");
  10932. module.exports = factory(require("jquery"));
  10933. } else {
  10934. // Browser globals
  10935. factory(jQuery);
  10936. }
  10937. })(function($) {
  10938. "use strict";
  10939. /******************************************************************************
  10940. * Private functions and variables
  10941. */
  10942. var FT = $.ui.fancytree,
  10943. PRESETS = {
  10944. awesome3: {
  10945. // Outdated!
  10946. _addClass: "",
  10947. checkbox: "icon-check-empty",
  10948. checkboxSelected: "icon-check",
  10949. checkboxUnknown: "icon-check icon-muted",
  10950. dragHelper: "icon-caret-right",
  10951. dropMarker: "icon-caret-right",
  10952. error: "icon-exclamation-sign",
  10953. expanderClosed: "icon-caret-right",
  10954. expanderLazy: "icon-angle-right",
  10955. expanderOpen: "icon-caret-down",
  10956. loading: "icon-refresh icon-spin",
  10957. nodata: "icon-meh",
  10958. noExpander: "",
  10959. radio: "icon-circle-blank",
  10960. radioSelected: "icon-circle",
  10961. // radioUnknown: "icon-circle icon-muted",
  10962. // Default node icons.
  10963. // (Use tree.options.icon callback to define custom icons based on node data)
  10964. doc: "icon-file-alt",
  10965. docOpen: "icon-file-alt",
  10966. folder: "icon-folder-close-alt",
  10967. folderOpen: "icon-folder-open-alt",
  10968. },
  10969. awesome4: {
  10970. _addClass: "fa",
  10971. checkbox: "fa-square-o",
  10972. checkboxSelected: "fa-check-square-o",
  10973. checkboxUnknown: "fa-square fancytree-helper-indeterminate-cb",
  10974. dragHelper: "fa-arrow-right",
  10975. dropMarker: "fa-long-arrow-right",
  10976. error: "fa-warning",
  10977. expanderClosed: "fa-caret-right",
  10978. expanderLazy: "fa-angle-right",
  10979. expanderOpen: "fa-caret-down",
  10980. // We may prevent wobbling rotations on FF by creating a separate sub element:
  10981. loading: { html: "<span class='fa fa-spinner fa-pulse' />" },
  10982. nodata: "fa-meh-o",
  10983. noExpander: "",
  10984. radio: "fa-circle-thin", // "fa-circle-o"
  10985. radioSelected: "fa-circle",
  10986. // radioUnknown: "fa-dot-circle-o",
  10987. // Default node icons.
  10988. // (Use tree.options.icon callback to define custom icons based on node data)
  10989. doc: "fa-file-o",
  10990. docOpen: "fa-file-o",
  10991. folder: "fa-folder-o",
  10992. folderOpen: "fa-folder-open-o",
  10993. },
  10994. awesome5: {
  10995. // fontawesome 5 have several different base classes
  10996. // "far, fas, fal and fab" The rendered svg puts that prefix
  10997. // in a different location so we have to keep them separate here
  10998. _addClass: "",
  10999. checkbox: "far fa-square",
  11000. checkboxSelected: "far fa-check-square",
  11001. // checkboxUnknown: "far fa-window-close",
  11002. checkboxUnknown:
  11003. "fas fa-square fancytree-helper-indeterminate-cb",
  11004. radio: "far fa-circle",
  11005. radioSelected: "fas fa-circle",
  11006. radioUnknown: "far fa-dot-circle",
  11007. dragHelper: "fas fa-arrow-right",
  11008. dropMarker: "fas fa-long-arrow-alt-right",
  11009. error: "fas fa-exclamation-triangle",
  11010. expanderClosed: "fas fa-caret-right",
  11011. expanderLazy: "fas fa-angle-right",
  11012. expanderOpen: "fas fa-caret-down",
  11013. loading: "fas fa-spinner fa-pulse",
  11014. nodata: "far fa-meh",
  11015. noExpander: "",
  11016. // Default node icons.
  11017. // (Use tree.options.icon callback to define custom icons based on node data)
  11018. doc: "far fa-file",
  11019. docOpen: "far fa-file",
  11020. folder: "far fa-folder",
  11021. folderOpen: "far fa-folder-open",
  11022. },
  11023. bootstrap3: {
  11024. _addClass: "glyphicon",
  11025. checkbox: "glyphicon-unchecked",
  11026. checkboxSelected: "glyphicon-check",
  11027. checkboxUnknown:
  11028. "glyphicon-expand fancytree-helper-indeterminate-cb", // "glyphicon-share",
  11029. dragHelper: "glyphicon-play",
  11030. dropMarker: "glyphicon-arrow-right",
  11031. error: "glyphicon-warning-sign",
  11032. expanderClosed: "glyphicon-menu-right", // glyphicon-plus-sign
  11033. expanderLazy: "glyphicon-menu-right", // glyphicon-plus-sign
  11034. expanderOpen: "glyphicon-menu-down", // glyphicon-minus-sign
  11035. loading: "glyphicon-refresh fancytree-helper-spin",
  11036. nodata: "glyphicon-info-sign",
  11037. noExpander: "",
  11038. radio: "glyphicon-remove-circle", // "glyphicon-unchecked",
  11039. radioSelected: "glyphicon-ok-circle", // "glyphicon-check",
  11040. // radioUnknown: "glyphicon-ban-circle",
  11041. // Default node icons.
  11042. // (Use tree.options.icon callback to define custom icons based on node data)
  11043. doc: "glyphicon-file",
  11044. docOpen: "glyphicon-file",
  11045. folder: "glyphicon-folder-close",
  11046. folderOpen: "glyphicon-folder-open",
  11047. },
  11048. material: {
  11049. _addClass: "material-icons",
  11050. checkbox: { text: "check_box_outline_blank" },
  11051. checkboxSelected: { text: "check_box" },
  11052. checkboxUnknown: { text: "indeterminate_check_box" },
  11053. dragHelper: { text: "play_arrow" },
  11054. dropMarker: { text: "arrow-forward" },
  11055. error: { text: "warning" },
  11056. expanderClosed: { text: "chevron_right" },
  11057. expanderLazy: { text: "last_page" },
  11058. expanderOpen: { text: "expand_more" },
  11059. loading: {
  11060. text: "autorenew",
  11061. addClass: "fancytree-helper-spin",
  11062. },
  11063. nodata: { text: "info" },
  11064. noExpander: { text: "" },
  11065. radio: { text: "radio_button_unchecked" },
  11066. radioSelected: { text: "radio_button_checked" },
  11067. // Default node icons.
  11068. // (Use tree.options.icon callback to define custom icons based on node data)
  11069. doc: { text: "insert_drive_file" },
  11070. docOpen: { text: "insert_drive_file" },
  11071. folder: { text: "folder" },
  11072. folderOpen: { text: "folder_open" },
  11073. },
  11074. };
  11075. function setIcon(node, span, baseClass, opts, type) {
  11076. var map = opts.map,
  11077. icon = map[type],
  11078. $span = $(span),
  11079. $counter = $span.find(".fancytree-childcounter"),
  11080. setClass = baseClass + " " + (map._addClass || "");
  11081. // #871 Allow a callback
  11082. if ($.isFunction(icon)) {
  11083. icon = icon.call(this, node, span, type);
  11084. }
  11085. // node.debug( "setIcon(" + baseClass + ", " + type + "): " + "oldIcon" + " -> " + icon );
  11086. // #871: propsed this, but I am not sure how robust this is, e.g.
  11087. // the prefix (fas, far) class changes are not considered?
  11088. // if (span.tagName === "svg" && opts.preset === "awesome5") {
  11089. // // fa5 script converts <i> to <svg> so call a specific handler.
  11090. // var oldIcon = "fa-" + $span.data("icon");
  11091. // // node.debug( "setIcon(" + baseClass + ", " + type + "): " + oldIcon + " -> " + icon );
  11092. // if (typeof oldIcon === "string") {
  11093. // $span.removeClass(oldIcon);
  11094. // }
  11095. // if (typeof icon === "string") {
  11096. // $span.addClass(icon);
  11097. // }
  11098. // return;
  11099. // }
  11100. if (typeof icon === "string") {
  11101. // #883: remove inner html that may be added by prev. mode
  11102. span.innerHTML = "";
  11103. $span.attr("class", setClass + " " + icon).append($counter);
  11104. } else if (icon) {
  11105. if (icon.text) {
  11106. span.textContent = "" + icon.text;
  11107. } else if (icon.html) {
  11108. span.innerHTML = icon.html;
  11109. } else {
  11110. span.innerHTML = "";
  11111. }
  11112. $span
  11113. .attr("class", setClass + " " + (icon.addClass || ""))
  11114. .append($counter);
  11115. }
  11116. }
  11117. $.ui.fancytree.registerExtension({
  11118. name: "glyph",
  11119. version: "2.38.0",
  11120. // Default options for this extension.
  11121. options: {
  11122. preset: null, // 'awesome3', 'awesome4', 'bootstrap3', 'material'
  11123. map: {},
  11124. },
  11125. treeInit: function(ctx) {
  11126. var tree = ctx.tree,
  11127. opts = ctx.options.glyph;
  11128. if (opts.preset) {
  11129. FT.assert(
  11130. !!PRESETS[opts.preset],
  11131. "Invalid value for `options.glyph.preset`: " + opts.preset
  11132. );
  11133. opts.map = $.extend({}, PRESETS[opts.preset], opts.map);
  11134. } else {
  11135. tree.warn("ext-glyph: missing `preset` option.");
  11136. }
  11137. this._superApply(arguments);
  11138. tree.$container.addClass("fancytree-ext-glyph");
  11139. },
  11140. nodeRenderStatus: function(ctx) {
  11141. var checkbox,
  11142. icon,
  11143. res,
  11144. span,
  11145. node = ctx.node,
  11146. $span = $(node.span),
  11147. opts = ctx.options.glyph;
  11148. res = this._super(ctx);
  11149. if (node.isRootNode()) {
  11150. return res;
  11151. }
  11152. span = $span.children(".fancytree-expander").get(0);
  11153. if (span) {
  11154. // if( node.isLoading() ){
  11155. // icon = "loading";
  11156. if (node.expanded && node.hasChildren()) {
  11157. icon = "expanderOpen";
  11158. } else if (node.isUndefined()) {
  11159. icon = "expanderLazy";
  11160. } else if (node.hasChildren()) {
  11161. icon = "expanderClosed";
  11162. } else {
  11163. icon = "noExpander";
  11164. }
  11165. // span.className = "fancytree-expander " + map[icon];
  11166. setIcon(node, span, "fancytree-expander", opts, icon);
  11167. }
  11168. if (node.tr) {
  11169. span = $("td", node.tr)
  11170. .find(".fancytree-checkbox")
  11171. .get(0);
  11172. } else {
  11173. span = $span.children(".fancytree-checkbox").get(0);
  11174. }
  11175. if (span) {
  11176. checkbox = FT.evalOption("checkbox", node, node, opts, false);
  11177. if (
  11178. (node.parent && node.parent.radiogroup) ||
  11179. checkbox === "radio"
  11180. ) {
  11181. icon = node.selected ? "radioSelected" : "radio";
  11182. setIcon(
  11183. node,
  11184. span,
  11185. "fancytree-checkbox fancytree-radio",
  11186. opts,
  11187. icon
  11188. );
  11189. } else {
  11190. // eslint-disable-next-line no-nested-ternary
  11191. icon = node.selected
  11192. ? "checkboxSelected"
  11193. : node.partsel
  11194. ? "checkboxUnknown"
  11195. : "checkbox";
  11196. // span.className = "fancytree-checkbox " + map[icon];
  11197. setIcon(node, span, "fancytree-checkbox", opts, icon);
  11198. }
  11199. }
  11200. // Standard icon (note that this does not match .fancytree-custom-icon,
  11201. // that might be set by opts.icon callbacks)
  11202. span = $span.children(".fancytree-icon").get(0);
  11203. if (span) {
  11204. if (node.statusNodeType) {
  11205. icon = node.statusNodeType; // loading, error
  11206. } else if (node.folder) {
  11207. icon =
  11208. node.expanded && node.hasChildren()
  11209. ? "folderOpen"
  11210. : "folder";
  11211. } else {
  11212. icon = node.expanded ? "docOpen" : "doc";
  11213. }
  11214. setIcon(node, span, "fancytree-icon", opts, icon);
  11215. }
  11216. return res;
  11217. },
  11218. nodeSetStatus: function(ctx, status, message, details) {
  11219. var res,
  11220. span,
  11221. opts = ctx.options.glyph,
  11222. node = ctx.node;
  11223. res = this._superApply(arguments);
  11224. if (
  11225. status === "error" ||
  11226. status === "loading" ||
  11227. status === "nodata"
  11228. ) {
  11229. if (node.parent) {
  11230. span = $(".fancytree-expander", node.span).get(0);
  11231. if (span) {
  11232. setIcon(node, span, "fancytree-expander", opts, status);
  11233. }
  11234. } else {
  11235. //
  11236. span = $(
  11237. ".fancytree-statusnode-" + status,
  11238. node[this.nodeContainerAttrName]
  11239. )
  11240. .find(".fancytree-icon")
  11241. .get(0);
  11242. if (span) {
  11243. setIcon(node, span, "fancytree-icon", opts, status);
  11244. }
  11245. }
  11246. }
  11247. return res;
  11248. },
  11249. });
  11250. // Value returned by `require('jquery.fancytree..')`
  11251. return $.ui.fancytree;
  11252. }); // End of closure
  11253. /*! Extension 'jquery.fancytree.gridnav.js' *//*!
  11254. * jquery.fancytree.gridnav.js
  11255. *
  11256. * Support keyboard navigation for trees with embedded input controls.
  11257. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11258. *
  11259. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  11260. *
  11261. * Released under the MIT license
  11262. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11263. *
  11264. * @version 2.38.0
  11265. * @date 2021-02-09T20:03:49Z
  11266. */
  11267. (function(factory) {
  11268. if (typeof define === "function" && define.amd) {
  11269. // AMD. Register as an anonymous module.
  11270. define([
  11271. "jquery",
  11272. "./jquery.fancytree",
  11273. "./jquery.fancytree.table",
  11274. ], factory);
  11275. } else if (typeof module === "object" && module.exports) {
  11276. // Node/CommonJS
  11277. require("./jquery.fancytree.table"); // core + table
  11278. module.exports = factory(require("jquery"));
  11279. } else {
  11280. // Browser globals
  11281. factory(jQuery);
  11282. }
  11283. })(function($) {
  11284. "use strict";
  11285. /*******************************************************************************
  11286. * Private functions and variables
  11287. */
  11288. // Allow these navigation keys even when input controls are focused
  11289. var KC = $.ui.keyCode,
  11290. // which keys are *not* handled by embedded control, but passed to tree
  11291. // navigation handler:
  11292. NAV_KEYS = {
  11293. text: [KC.UP, KC.DOWN],
  11294. checkbox: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11295. link: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11296. radiobutton: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11297. "select-one": [KC.LEFT, KC.RIGHT],
  11298. "select-multiple": [KC.LEFT, KC.RIGHT],
  11299. };
  11300. /* Calculate TD column index (considering colspans).*/
  11301. function getColIdx($tr, $td) {
  11302. var colspan,
  11303. td = $td.get(0),
  11304. idx = 0;
  11305. $tr.children().each(function() {
  11306. if (this === td) {
  11307. return false;
  11308. }
  11309. colspan = $(this).prop("colspan");
  11310. idx += colspan ? colspan : 1;
  11311. });
  11312. return idx;
  11313. }
  11314. /* Find TD at given column index (considering colspans).*/
  11315. function findTdAtColIdx($tr, colIdx) {
  11316. var colspan,
  11317. res = null,
  11318. idx = 0;
  11319. $tr.children().each(function() {
  11320. if (idx >= colIdx) {
  11321. res = $(this);
  11322. return false;
  11323. }
  11324. colspan = $(this).prop("colspan");
  11325. idx += colspan ? colspan : 1;
  11326. });
  11327. return res;
  11328. }
  11329. /* Find adjacent cell for a given direction. Skip empty cells and consider merged cells */
  11330. function findNeighbourTd($target, keyCode) {
  11331. var $tr,
  11332. colIdx,
  11333. $td = $target.closest("td"),
  11334. $tdNext = null;
  11335. switch (keyCode) {
  11336. case KC.LEFT:
  11337. $tdNext = $td.prev();
  11338. break;
  11339. case KC.RIGHT:
  11340. $tdNext = $td.next();
  11341. break;
  11342. case KC.UP:
  11343. case KC.DOWN:
  11344. $tr = $td.parent();
  11345. colIdx = getColIdx($tr, $td);
  11346. while (true) {
  11347. $tr = keyCode === KC.UP ? $tr.prev() : $tr.next();
  11348. if (!$tr.length) {
  11349. break;
  11350. }
  11351. // Skip hidden rows
  11352. if ($tr.is(":hidden")) {
  11353. continue;
  11354. }
  11355. // Find adjacent cell in the same column
  11356. $tdNext = findTdAtColIdx($tr, colIdx);
  11357. // Skip cells that don't conatain a focusable element
  11358. if ($tdNext && $tdNext.find(":input,a").length) {
  11359. break;
  11360. }
  11361. }
  11362. break;
  11363. }
  11364. return $tdNext;
  11365. }
  11366. /*******************************************************************************
  11367. * Extension code
  11368. */
  11369. $.ui.fancytree.registerExtension({
  11370. name: "gridnav",
  11371. version: "2.38.0",
  11372. // Default options for this extension.
  11373. options: {
  11374. autofocusInput: false, // Focus first embedded input if node gets activated
  11375. handleCursorKeys: true, // Allow UP/DOWN in inputs to move to prev/next node
  11376. },
  11377. treeInit: function(ctx) {
  11378. // gridnav requires the table extension to be loaded before itself
  11379. this._requireExtension("table", true, true);
  11380. this._superApply(arguments);
  11381. this.$container.addClass("fancytree-ext-gridnav");
  11382. // Activate node if embedded input gets focus (due to a click)
  11383. this.$container.on("focusin", function(event) {
  11384. var ctx2,
  11385. node = $.ui.fancytree.getNode(event.target);
  11386. if (node && !node.isActive()) {
  11387. // Call node.setActive(), but also pass the event
  11388. ctx2 = ctx.tree._makeHookContext(node, event);
  11389. ctx.tree._callHook("nodeSetActive", ctx2, true);
  11390. }
  11391. });
  11392. },
  11393. nodeSetActive: function(ctx, flag, callOpts) {
  11394. var $outer,
  11395. opts = ctx.options.gridnav,
  11396. node = ctx.node,
  11397. event = ctx.originalEvent || {},
  11398. triggeredByInput = $(event.target).is(":input");
  11399. flag = flag !== false;
  11400. this._superApply(arguments);
  11401. if (flag) {
  11402. if (ctx.options.titlesTabbable) {
  11403. if (!triggeredByInput) {
  11404. $(node.span)
  11405. .find("span.fancytree-title")
  11406. .focus();
  11407. node.setFocus();
  11408. }
  11409. // If one node is tabbable, the container no longer needs to be
  11410. ctx.tree.$container.attr("tabindex", "-1");
  11411. // ctx.tree.$container.removeAttr("tabindex");
  11412. } else if (opts.autofocusInput && !triggeredByInput) {
  11413. // Set focus to input sub input (if node was clicked, but not
  11414. // when TAB was pressed )
  11415. $outer = $(node.tr || node.span);
  11416. $outer
  11417. .find(":input:enabled")
  11418. .first()
  11419. .focus();
  11420. }
  11421. }
  11422. },
  11423. nodeKeydown: function(ctx) {
  11424. var inputType,
  11425. handleKeys,
  11426. $td,
  11427. opts = ctx.options.gridnav,
  11428. event = ctx.originalEvent,
  11429. $target = $(event.target);
  11430. if ($target.is(":input:enabled")) {
  11431. inputType = $target.prop("type");
  11432. } else if ($target.is("a")) {
  11433. inputType = "link";
  11434. }
  11435. // ctx.tree.debug("ext-gridnav nodeKeydown", event, inputType);
  11436. if (inputType && opts.handleCursorKeys) {
  11437. handleKeys = NAV_KEYS[inputType];
  11438. if (handleKeys && $.inArray(event.which, handleKeys) >= 0) {
  11439. $td = findNeighbourTd($target, event.which);
  11440. if ($td && $td.length) {
  11441. // ctx.node.debug("ignore keydown in input", event.which, handleKeys);
  11442. $td.find(":input:enabled,a").focus();
  11443. // Prevent Fancytree default navigation
  11444. return false;
  11445. }
  11446. }
  11447. return true;
  11448. }
  11449. // ctx.tree.debug("ext-gridnav NOT HANDLED", event, inputType);
  11450. return this._superApply(arguments);
  11451. },
  11452. });
  11453. // Value returned by `require('jquery.fancytree..')`
  11454. return $.ui.fancytree;
  11455. }); // End of closure
  11456. /*! Extension 'jquery.fancytree.multi.js' *//*!
  11457. * jquery.fancytree.multi.js
  11458. *
  11459. * Allow multiple selection of nodes by mouse or keyboard.
  11460. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11461. *
  11462. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  11463. *
  11464. * Released under the MIT license
  11465. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11466. *
  11467. * @version 2.38.0
  11468. * @date 2021-02-09T20:03:49Z
  11469. */
  11470. (function(factory) {
  11471. if (typeof define === "function" && define.amd) {
  11472. // AMD. Register as an anonymous module.
  11473. define(["jquery", "./jquery.fancytree"], factory);
  11474. } else if (typeof module === "object" && module.exports) {
  11475. // Node/CommonJS
  11476. require("./jquery.fancytree");
  11477. module.exports = factory(require("jquery"));
  11478. } else {
  11479. // Browser globals
  11480. factory(jQuery);
  11481. }
  11482. })(function($) {
  11483. "use strict";
  11484. /*******************************************************************************
  11485. * Private functions and variables
  11486. */
  11487. // var isMac = /Mac/.test(navigator.platform);
  11488. /*******************************************************************************
  11489. * Extension code
  11490. */
  11491. $.ui.fancytree.registerExtension({
  11492. name: "multi",
  11493. version: "2.38.0",
  11494. // Default options for this extension.
  11495. options: {
  11496. allowNoSelect: false, //
  11497. mode: "sameParent", //
  11498. // Events:
  11499. // beforeSelect: $.noop // Return false to prevent cancel/save (data.input is available)
  11500. },
  11501. treeInit: function(ctx) {
  11502. this._superApply(arguments);
  11503. this.$container.addClass("fancytree-ext-multi");
  11504. if (ctx.options.selectMode === 1) {
  11505. $.error(
  11506. "Fancytree ext-multi: selectMode: 1 (single) is not compatible."
  11507. );
  11508. }
  11509. },
  11510. nodeClick: function(ctx) {
  11511. var //pluginOpts = ctx.options.multi,
  11512. tree = ctx.tree,
  11513. node = ctx.node,
  11514. activeNode = tree.getActiveNode() || tree.getFirstChild(),
  11515. isCbClick = ctx.targetType === "checkbox",
  11516. isExpanderClick = ctx.targetType === "expander",
  11517. eventStr = $.ui.fancytree.eventToString(ctx.originalEvent);
  11518. switch (eventStr) {
  11519. case "click":
  11520. if (isExpanderClick) {
  11521. break;
  11522. } // Default handler will expand/collapse
  11523. if (!isCbClick) {
  11524. tree.selectAll(false);
  11525. // Select clicked node (radio-button mode)
  11526. node.setSelected();
  11527. }
  11528. // Default handler will toggle checkbox clicks and activate
  11529. break;
  11530. case "shift+click":
  11531. // node.debug("click")
  11532. tree.visitRows(
  11533. function(n) {
  11534. // n.debug("click2", n===node, node)
  11535. n.setSelected();
  11536. if (n === node) {
  11537. return false;
  11538. }
  11539. },
  11540. {
  11541. start: activeNode,
  11542. reverse: activeNode.isBelowOf(node),
  11543. }
  11544. );
  11545. break;
  11546. case "ctrl+click":
  11547. case "meta+click": // Mac: [Command]
  11548. node.toggleSelected();
  11549. return;
  11550. }
  11551. return this._superApply(arguments);
  11552. },
  11553. nodeKeydown: function(ctx) {
  11554. var tree = ctx.tree,
  11555. node = ctx.node,
  11556. event = ctx.originalEvent,
  11557. eventStr = $.ui.fancytree.eventToString(event);
  11558. switch (eventStr) {
  11559. case "up":
  11560. case "down":
  11561. tree.selectAll(false);
  11562. node.navigate(event.which, true);
  11563. tree.getActiveNode().setSelected();
  11564. break;
  11565. case "shift+up":
  11566. case "shift+down":
  11567. node.navigate(event.which, true);
  11568. tree.getActiveNode().setSelected();
  11569. break;
  11570. }
  11571. return this._superApply(arguments);
  11572. },
  11573. });
  11574. // Value returned by `require('jquery.fancytree..')`
  11575. return $.ui.fancytree;
  11576. }); // End of closure
  11577. /*! Extension 'jquery.fancytree.persist.js' *//*!
  11578. * jquery.fancytree.persist.js
  11579. *
  11580. * Persist tree status in cookiesRemove or highlight tree nodes, based on a filter.
  11581. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11582. *
  11583. * @depends: js-cookie or jquery-cookie
  11584. *
  11585. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  11586. *
  11587. * Released under the MIT license
  11588. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11589. *
  11590. * @version 2.38.0
  11591. * @date 2021-02-09T20:03:49Z
  11592. */
  11593. (function(factory) {
  11594. if (typeof define === "function" && define.amd) {
  11595. // AMD. Register as an anonymous module.
  11596. define(["jquery", "./jquery.fancytree"], factory);
  11597. } else if (typeof module === "object" && module.exports) {
  11598. // Node/CommonJS
  11599. require("./jquery.fancytree");
  11600. module.exports = factory(require("jquery"));
  11601. } else {
  11602. // Browser globals
  11603. factory(jQuery);
  11604. }
  11605. })(function($) {
  11606. "use strict";
  11607. /* global Cookies:false */
  11608. /*******************************************************************************
  11609. * Private functions and variables
  11610. */
  11611. var cookieStore = null,
  11612. localStorageStore = null,
  11613. sessionStorageStore = null,
  11614. _assert = $.ui.fancytree.assert,
  11615. ACTIVE = "active",
  11616. EXPANDED = "expanded",
  11617. FOCUS = "focus",
  11618. SELECTED = "selected";
  11619. // Accessing window.xxxStorage may raise security exceptions (see #1022)
  11620. try {
  11621. _assert(window.localStorage && window.localStorage.getItem);
  11622. localStorageStore = {
  11623. get: function(key) {
  11624. return window.localStorage.getItem(key);
  11625. },
  11626. set: function(key, value) {
  11627. window.localStorage.setItem(key, value);
  11628. },
  11629. remove: function(key) {
  11630. window.localStorage.removeItem(key);
  11631. },
  11632. };
  11633. } catch (e) {
  11634. $.ui.fancytree.warn("Could not access window.localStorage", e);
  11635. }
  11636. try {
  11637. _assert(window.sessionStorage && window.sessionStorage.getItem);
  11638. sessionStorageStore = {
  11639. get: function(key) {
  11640. return window.sessionStorage.getItem(key);
  11641. },
  11642. set: function(key, value) {
  11643. window.sessionStorage.setItem(key, value);
  11644. },
  11645. remove: function(key) {
  11646. window.sessionStorage.removeItem(key);
  11647. },
  11648. };
  11649. } catch (e) {
  11650. $.ui.fancytree.warn("Could not access window.sessionStorage", e);
  11651. }
  11652. if (typeof Cookies === "function") {
  11653. // Assume https://github.com/js-cookie/js-cookie
  11654. cookieStore = {
  11655. get: Cookies.get,
  11656. set: function(key, value) {
  11657. Cookies.set(key, value, this.options.persist.cookie);
  11658. },
  11659. remove: Cookies.remove,
  11660. };
  11661. } else if ($ && typeof $.cookie === "function") {
  11662. // Fall back to https://github.com/carhartl/jquery-cookie
  11663. cookieStore = {
  11664. get: $.cookie,
  11665. set: function(key, value) {
  11666. $.cookie.set(key, value, this.options.persist.cookie);
  11667. },
  11668. remove: $.removeCookie,
  11669. };
  11670. }
  11671. /* Recursively load lazy nodes
  11672. * @param {string} mode 'load', 'expand', false
  11673. */
  11674. function _loadLazyNodes(tree, local, keyList, mode, dfd) {
  11675. var i,
  11676. key,
  11677. l,
  11678. node,
  11679. foundOne = false,
  11680. expandOpts = tree.options.persist.expandOpts,
  11681. deferredList = [],
  11682. missingKeyList = [];
  11683. keyList = keyList || [];
  11684. dfd = dfd || $.Deferred();
  11685. for (i = 0, l = keyList.length; i < l; i++) {
  11686. key = keyList[i];
  11687. node = tree.getNodeByKey(key);
  11688. if (node) {
  11689. if (mode && node.isUndefined()) {
  11690. foundOne = true;
  11691. tree.debug(
  11692. "_loadLazyNodes: " + node + " is lazy: loading..."
  11693. );
  11694. if (mode === "expand") {
  11695. deferredList.push(node.setExpanded(true, expandOpts));
  11696. } else {
  11697. deferredList.push(node.load());
  11698. }
  11699. } else {
  11700. tree.debug("_loadLazyNodes: " + node + " already loaded.");
  11701. node.setExpanded(true, expandOpts);
  11702. }
  11703. } else {
  11704. missingKeyList.push(key);
  11705. tree.debug("_loadLazyNodes: " + node + " was not yet found.");
  11706. }
  11707. }
  11708. $.when.apply($, deferredList).always(function() {
  11709. // All lazy-expands have finished
  11710. if (foundOne && missingKeyList.length > 0) {
  11711. // If we read new nodes from server, try to resolve yet-missing keys
  11712. _loadLazyNodes(tree, local, missingKeyList, mode, dfd);
  11713. } else {
  11714. if (missingKeyList.length) {
  11715. tree.warn(
  11716. "_loadLazyNodes: could not load those keys: ",
  11717. missingKeyList
  11718. );
  11719. for (i = 0, l = missingKeyList.length; i < l; i++) {
  11720. key = keyList[i];
  11721. local._appendKey(EXPANDED, keyList[i], false);
  11722. }
  11723. }
  11724. dfd.resolve();
  11725. }
  11726. });
  11727. return dfd;
  11728. }
  11729. /**
  11730. * [ext-persist] Remove persistence data of the given type(s).
  11731. * Called like
  11732. * $.ui.fancytree.getTree("#tree").clearCookies("active expanded focus selected");
  11733. *
  11734. * @alias Fancytree#clearPersistData
  11735. * @requires jquery.fancytree.persist.js
  11736. */
  11737. $.ui.fancytree._FancytreeClass.prototype.clearPersistData = function(
  11738. types
  11739. ) {
  11740. var local = this.ext.persist,
  11741. prefix = local.cookiePrefix;
  11742. types = types || "active expanded focus selected";
  11743. if (types.indexOf(ACTIVE) >= 0) {
  11744. local._data(prefix + ACTIVE, null);
  11745. }
  11746. if (types.indexOf(EXPANDED) >= 0) {
  11747. local._data(prefix + EXPANDED, null);
  11748. }
  11749. if (types.indexOf(FOCUS) >= 0) {
  11750. local._data(prefix + FOCUS, null);
  11751. }
  11752. if (types.indexOf(SELECTED) >= 0) {
  11753. local._data(prefix + SELECTED, null);
  11754. }
  11755. };
  11756. $.ui.fancytree._FancytreeClass.prototype.clearCookies = function(types) {
  11757. this.warn(
  11758. "'tree.clearCookies()' is deprecated since v2.27.0: use 'clearPersistData()' instead."
  11759. );
  11760. return this.clearPersistData(types);
  11761. };
  11762. /**
  11763. * [ext-persist] Return persistence information from cookies
  11764. *
  11765. * Called like
  11766. * $.ui.fancytree.getTree("#tree").getPersistData();
  11767. *
  11768. * @alias Fancytree#getPersistData
  11769. * @requires jquery.fancytree.persist.js
  11770. */
  11771. $.ui.fancytree._FancytreeClass.prototype.getPersistData = function() {
  11772. var local = this.ext.persist,
  11773. prefix = local.cookiePrefix,
  11774. delim = local.cookieDelimiter,
  11775. res = {};
  11776. res[ACTIVE] = local._data(prefix + ACTIVE);
  11777. res[EXPANDED] = (local._data(prefix + EXPANDED) || "").split(delim);
  11778. res[SELECTED] = (local._data(prefix + SELECTED) || "").split(delim);
  11779. res[FOCUS] = local._data(prefix + FOCUS);
  11780. return res;
  11781. };
  11782. /******************************************************************************
  11783. * Extension code
  11784. */
  11785. $.ui.fancytree.registerExtension({
  11786. name: "persist",
  11787. version: "2.38.0",
  11788. // Default options for this extension.
  11789. options: {
  11790. cookieDelimiter: "~",
  11791. cookiePrefix: undefined, // 'fancytree-<treeId>-' by default
  11792. cookie: {
  11793. raw: false,
  11794. expires: "",
  11795. path: "",
  11796. domain: "",
  11797. secure: false,
  11798. },
  11799. expandLazy: false, // true: recursively expand and load lazy nodes
  11800. expandOpts: undefined, // optional `opts` argument passed to setExpanded()
  11801. fireActivate: true, // false: suppress `activate` event after active node was restored
  11802. overrideSource: true, // true: cookie takes precedence over `source` data attributes.
  11803. store: "auto", // 'cookie': force cookie, 'local': force localStore, 'session': force sessionStore
  11804. types: "active expanded focus selected",
  11805. },
  11806. /* Generic read/write string data to cookie, sessionStorage or localStorage. */
  11807. _data: function(key, value) {
  11808. var store = this._local.store;
  11809. if (value === undefined) {
  11810. return store.get.call(this, key);
  11811. } else if (value === null) {
  11812. store.remove.call(this, key);
  11813. } else {
  11814. store.set.call(this, key, value);
  11815. }
  11816. },
  11817. /* Append `key` to a cookie. */
  11818. _appendKey: function(type, key, flag) {
  11819. key = "" + key; // #90
  11820. var local = this._local,
  11821. instOpts = this.options.persist,
  11822. delim = instOpts.cookieDelimiter,
  11823. cookieName = local.cookiePrefix + type,
  11824. data = local._data(cookieName),
  11825. keyList = data ? data.split(delim) : [],
  11826. idx = $.inArray(key, keyList);
  11827. // Remove, even if we add a key, so the key is always the last entry
  11828. if (idx >= 0) {
  11829. keyList.splice(idx, 1);
  11830. }
  11831. // Append key to cookie
  11832. if (flag) {
  11833. keyList.push(key);
  11834. }
  11835. local._data(cookieName, keyList.join(delim));
  11836. },
  11837. treeInit: function(ctx) {
  11838. var tree = ctx.tree,
  11839. opts = ctx.options,
  11840. local = this._local,
  11841. instOpts = this.options.persist;
  11842. // // For 'auto' or 'cookie' mode, the cookie plugin must be available
  11843. // _assert((instOpts.store !== "auto" && instOpts.store !== "cookie") || cookieStore,
  11844. // "Missing required plugin for 'persist' extension: js.cookie.js or jquery.cookie.js");
  11845. local.cookiePrefix =
  11846. instOpts.cookiePrefix || "fancytree-" + tree._id + "-";
  11847. local.storeActive = instOpts.types.indexOf(ACTIVE) >= 0;
  11848. local.storeExpanded = instOpts.types.indexOf(EXPANDED) >= 0;
  11849. local.storeSelected = instOpts.types.indexOf(SELECTED) >= 0;
  11850. local.storeFocus = instOpts.types.indexOf(FOCUS) >= 0;
  11851. local.store = null;
  11852. if (instOpts.store === "auto") {
  11853. instOpts.store = localStorageStore ? "local" : "cookie";
  11854. }
  11855. if ($.isPlainObject(instOpts.store)) {
  11856. local.store = instOpts.store;
  11857. } else if (instOpts.store === "cookie") {
  11858. local.store = cookieStore;
  11859. } else if (instOpts.store === "local") {
  11860. local.store =
  11861. instOpts.store === "local"
  11862. ? localStorageStore
  11863. : sessionStorageStore;
  11864. } else if (instOpts.store === "session") {
  11865. local.store =
  11866. instOpts.store === "local"
  11867. ? localStorageStore
  11868. : sessionStorageStore;
  11869. }
  11870. _assert(local.store, "Need a valid store.");
  11871. // Bind init-handler to apply cookie state
  11872. tree.$div.on("fancytreeinit", function(event) {
  11873. if (
  11874. tree._triggerTreeEvent("beforeRestore", null, {}) === false
  11875. ) {
  11876. return;
  11877. }
  11878. var cookie,
  11879. dfd,
  11880. i,
  11881. keyList,
  11882. node,
  11883. prevFocus = local._data(local.cookiePrefix + FOCUS), // record this before node.setActive() overrides it;
  11884. noEvents = instOpts.fireActivate === false;
  11885. // tree.debug("document.cookie:", document.cookie);
  11886. cookie = local._data(local.cookiePrefix + EXPANDED);
  11887. keyList = cookie && cookie.split(instOpts.cookieDelimiter);
  11888. if (local.storeExpanded) {
  11889. // Recursively load nested lazy nodes if expandLazy is 'expand' or 'load'
  11890. // Also remove expand-cookies for unmatched nodes
  11891. dfd = _loadLazyNodes(
  11892. tree,
  11893. local,
  11894. keyList,
  11895. instOpts.expandLazy ? "expand" : false,
  11896. null
  11897. );
  11898. } else {
  11899. // nothing to do
  11900. dfd = new $.Deferred().resolve();
  11901. }
  11902. dfd.done(function() {
  11903. if (local.storeSelected) {
  11904. cookie = local._data(local.cookiePrefix + SELECTED);
  11905. if (cookie) {
  11906. keyList = cookie.split(instOpts.cookieDelimiter);
  11907. for (i = 0; i < keyList.length; i++) {
  11908. node = tree.getNodeByKey(keyList[i]);
  11909. if (node) {
  11910. if (
  11911. node.selected === undefined ||
  11912. (instOpts.overrideSource &&
  11913. node.selected === false)
  11914. ) {
  11915. // node.setSelected();
  11916. node.selected = true;
  11917. node.renderStatus();
  11918. }
  11919. } else {
  11920. // node is no longer member of the tree: remove from cookie also
  11921. local._appendKey(
  11922. SELECTED,
  11923. keyList[i],
  11924. false
  11925. );
  11926. }
  11927. }
  11928. }
  11929. // In selectMode 3 we have to fix the child nodes, since we
  11930. // only stored the selected *top* nodes
  11931. if (tree.options.selectMode === 3) {
  11932. tree.visit(function(n) {
  11933. if (n.selected) {
  11934. n.fixSelection3AfterClick();
  11935. return "skip";
  11936. }
  11937. });
  11938. }
  11939. }
  11940. if (local.storeActive) {
  11941. cookie = local._data(local.cookiePrefix + ACTIVE);
  11942. if (
  11943. cookie &&
  11944. (opts.persist.overrideSource || !tree.activeNode)
  11945. ) {
  11946. node = tree.getNodeByKey(cookie);
  11947. if (node) {
  11948. node.debug("persist: set active", cookie);
  11949. // We only want to set the focus if the container
  11950. // had the keyboard focus before
  11951. node.setActive(true, {
  11952. noFocus: true,
  11953. noEvents: noEvents,
  11954. });
  11955. }
  11956. }
  11957. }
  11958. if (local.storeFocus && prevFocus) {
  11959. node = tree.getNodeByKey(prevFocus);
  11960. if (node) {
  11961. // node.debug("persist: set focus", cookie);
  11962. if (tree.options.titlesTabbable) {
  11963. $(node.span)
  11964. .find(".fancytree-title")
  11965. .focus();
  11966. } else {
  11967. $(tree.$container).focus();
  11968. }
  11969. // node.setFocus();
  11970. }
  11971. }
  11972. tree._triggerTreeEvent("restore", null, {});
  11973. });
  11974. });
  11975. // Init the tree
  11976. return this._superApply(arguments);
  11977. },
  11978. nodeSetActive: function(ctx, flag, callOpts) {
  11979. var res,
  11980. local = this._local;
  11981. flag = flag !== false;
  11982. res = this._superApply(arguments);
  11983. if (local.storeActive) {
  11984. local._data(
  11985. local.cookiePrefix + ACTIVE,
  11986. this.activeNode ? this.activeNode.key : null
  11987. );
  11988. }
  11989. return res;
  11990. },
  11991. nodeSetExpanded: function(ctx, flag, callOpts) {
  11992. var res,
  11993. node = ctx.node,
  11994. local = this._local;
  11995. flag = flag !== false;
  11996. res = this._superApply(arguments);
  11997. if (local.storeExpanded) {
  11998. local._appendKey(EXPANDED, node.key, flag);
  11999. }
  12000. return res;
  12001. },
  12002. nodeSetFocus: function(ctx, flag) {
  12003. var res,
  12004. local = this._local;
  12005. flag = flag !== false;
  12006. res = this._superApply(arguments);
  12007. if (local.storeFocus) {
  12008. local._data(
  12009. local.cookiePrefix + FOCUS,
  12010. this.focusNode ? this.focusNode.key : null
  12011. );
  12012. }
  12013. return res;
  12014. },
  12015. nodeSetSelected: function(ctx, flag, callOpts) {
  12016. var res,
  12017. selNodes,
  12018. tree = ctx.tree,
  12019. node = ctx.node,
  12020. local = this._local;
  12021. flag = flag !== false;
  12022. res = this._superApply(arguments);
  12023. if (local.storeSelected) {
  12024. if (tree.options.selectMode === 3) {
  12025. // In selectMode 3 we only store the the selected *top* nodes.
  12026. // De-selecting a node may also de-select some parents, so we
  12027. // calculate the current status again
  12028. selNodes = $.map(tree.getSelectedNodes(true), function(n) {
  12029. return n.key;
  12030. });
  12031. selNodes = selNodes.join(
  12032. ctx.options.persist.cookieDelimiter
  12033. );
  12034. local._data(local.cookiePrefix + SELECTED, selNodes);
  12035. } else {
  12036. // beforeSelect can prevent the change - flag doesn't reflect the node.selected state
  12037. local._appendKey(SELECTED, node.key, node.selected);
  12038. }
  12039. }
  12040. return res;
  12041. },
  12042. });
  12043. // Value returned by `require('jquery.fancytree..')`
  12044. return $.ui.fancytree;
  12045. }); // End of closure
  12046. /*! Extension 'jquery.fancytree.table.js' *//*!
  12047. * jquery.fancytree.table.js
  12048. *
  12049. * Render tree as table (aka 'tree grid', 'table tree').
  12050. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12051. *
  12052. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  12053. *
  12054. * Released under the MIT license
  12055. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12056. *
  12057. * @version 2.38.0
  12058. * @date 2021-02-09T20:03:49Z
  12059. */
  12060. (function(factory) {
  12061. if (typeof define === "function" && define.amd) {
  12062. // AMD. Register as an anonymous module.
  12063. define(["jquery", "./jquery.fancytree"], factory);
  12064. } else if (typeof module === "object" && module.exports) {
  12065. // Node/CommonJS
  12066. require("./jquery.fancytree");
  12067. module.exports = factory(require("jquery"));
  12068. } else {
  12069. // Browser globals
  12070. factory(jQuery);
  12071. }
  12072. })(function($) {
  12073. "use strict";
  12074. /******************************************************************************
  12075. * Private functions and variables
  12076. */
  12077. var _assert = $.ui.fancytree.assert;
  12078. function insertFirstChild(referenceNode, newNode) {
  12079. referenceNode.insertBefore(newNode, referenceNode.firstChild);
  12080. }
  12081. function insertSiblingAfter(referenceNode, newNode) {
  12082. referenceNode.parentNode.insertBefore(
  12083. newNode,
  12084. referenceNode.nextSibling
  12085. );
  12086. }
  12087. /* Show/hide all rows that are structural descendants of `parent`. */
  12088. function setChildRowVisibility(parent, flag) {
  12089. parent.visit(function(node) {
  12090. var tr = node.tr;
  12091. // currentFlag = node.hide ? false : flag; // fix for ext-filter
  12092. if (tr) {
  12093. tr.style.display = node.hide || !flag ? "none" : "";
  12094. }
  12095. if (!node.expanded) {
  12096. return "skip";
  12097. }
  12098. });
  12099. }
  12100. /* Find node that is rendered in previous row. */
  12101. function findPrevRowNode(node) {
  12102. var i,
  12103. last,
  12104. prev,
  12105. parent = node.parent,
  12106. siblings = parent ? parent.children : null;
  12107. if (siblings && siblings.length > 1 && siblings[0] !== node) {
  12108. // use the lowest descendant of the preceeding sibling
  12109. i = $.inArray(node, siblings);
  12110. prev = siblings[i - 1];
  12111. _assert(prev.tr);
  12112. // descend to lowest child (with a <tr> tag)
  12113. while (prev.children && prev.children.length) {
  12114. last = prev.children[prev.children.length - 1];
  12115. if (!last.tr) {
  12116. break;
  12117. }
  12118. prev = last;
  12119. }
  12120. } else {
  12121. // if there is no preceding sibling, use the direct parent
  12122. prev = parent;
  12123. }
  12124. return prev;
  12125. }
  12126. $.ui.fancytree.registerExtension({
  12127. name: "table",
  12128. version: "2.38.0",
  12129. // Default options for this extension.
  12130. options: {
  12131. checkboxColumnIdx: null, // render the checkboxes into the this column index (default: nodeColumnIdx)
  12132. indentation: 16, // indent every node level by 16px
  12133. mergeStatusColumns: true, // display 'nodata', 'loading', 'error' centered in a single, merged TR
  12134. nodeColumnIdx: 0, // render node expander, icon, and title to this column (default: #0)
  12135. },
  12136. // Overide virtual methods for this extension.
  12137. // `this` : is this extension object
  12138. // `this._super`: the virtual function that was overriden (member of prev. extension or Fancytree)
  12139. treeInit: function(ctx) {
  12140. var i,
  12141. n,
  12142. $row,
  12143. $tbody,
  12144. tree = ctx.tree,
  12145. opts = ctx.options,
  12146. tableOpts = opts.table,
  12147. $table = tree.widget.element;
  12148. if (tableOpts.customStatus != null) {
  12149. if (opts.renderStatusColumns == null) {
  12150. tree.warn(
  12151. "The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' instead."
  12152. );
  12153. opts.renderStatusColumns = tableOpts.customStatus;
  12154. } else {
  12155. $.error(
  12156. "The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' only instead."
  12157. );
  12158. }
  12159. }
  12160. if (opts.renderStatusColumns) {
  12161. if (opts.renderStatusColumns === true) {
  12162. opts.renderStatusColumns = opts.renderColumns;
  12163. // } else if( opts.renderStatusColumns === "wide" ) {
  12164. // opts.renderStatusColumns = _renderStatusNodeWide;
  12165. }
  12166. }
  12167. $table.addClass("fancytree-container fancytree-ext-table");
  12168. $tbody = $table.find(">tbody");
  12169. if (!$tbody.length) {
  12170. // TODO: not sure if we can rely on browsers to insert missing <tbody> before <tr>s:
  12171. if ($table.find(">tr").length) {
  12172. $.error(
  12173. "Expected table > tbody > tr. If you see this please open an issue."
  12174. );
  12175. }
  12176. $tbody = $("<tbody>").appendTo($table);
  12177. }
  12178. tree.tbody = $tbody[0];
  12179. // Prepare row templates:
  12180. // Determine column count from table header if any
  12181. tree.columnCount = $("thead >tr", $table)
  12182. .last()
  12183. .find(">th", $table).length;
  12184. // Read TR templates from tbody if any
  12185. $row = $tbody.children("tr").first();
  12186. if ($row.length) {
  12187. n = $row.children("td").length;
  12188. if (tree.columnCount && n !== tree.columnCount) {
  12189. tree.warn(
  12190. "Column count mismatch between thead (" +
  12191. tree.columnCount +
  12192. ") and tbody (" +
  12193. n +
  12194. "): using tbody."
  12195. );
  12196. tree.columnCount = n;
  12197. }
  12198. $row = $row.clone();
  12199. } else {
  12200. // Only thead is defined: create default row markup
  12201. _assert(
  12202. tree.columnCount >= 1,
  12203. "Need either <thead> or <tbody> with <td> elements to determine column count."
  12204. );
  12205. $row = $("<tr />");
  12206. for (i = 0; i < tree.columnCount; i++) {
  12207. $row.append("<td />");
  12208. }
  12209. }
  12210. $row.find(">td")
  12211. .eq(tableOpts.nodeColumnIdx)
  12212. .html("<span class='fancytree-node' />");
  12213. if (opts.aria) {
  12214. $row.attr("role", "row");
  12215. $row.find("td").attr("role", "gridcell");
  12216. }
  12217. tree.rowFragment = document.createDocumentFragment();
  12218. tree.rowFragment.appendChild($row.get(0));
  12219. // // If tbody contains a second row, use this as status node template
  12220. // $row = $tbody.children("tr").eq(1);
  12221. // if( $row.length === 0 ) {
  12222. // tree.statusRowFragment = tree.rowFragment;
  12223. // } else {
  12224. // $row = $row.clone();
  12225. // tree.statusRowFragment = document.createDocumentFragment();
  12226. // tree.statusRowFragment.appendChild($row.get(0));
  12227. // }
  12228. //
  12229. $tbody.empty();
  12230. // Make sure that status classes are set on the node's <tr> elements
  12231. tree.statusClassPropName = "tr";
  12232. tree.ariaPropName = "tr";
  12233. this.nodeContainerAttrName = "tr";
  12234. // #489: make sure $container is set to <table>, even if ext-dnd is listed before ext-table
  12235. tree.$container = $table;
  12236. this._superApply(arguments);
  12237. // standard Fancytree created a root UL
  12238. $(tree.rootNode.ul).remove();
  12239. tree.rootNode.ul = null;
  12240. // Add container to the TAB chain
  12241. // #577: Allow to set tabindex to "0", "-1" and ""
  12242. this.$container.attr("tabindex", opts.tabindex);
  12243. // this.$container.attr("tabindex", opts.tabbable ? "0" : "-1");
  12244. if (opts.aria) {
  12245. tree.$container
  12246. .attr("role", "treegrid")
  12247. .attr("aria-readonly", true);
  12248. }
  12249. },
  12250. nodeRemoveChildMarkup: function(ctx) {
  12251. var node = ctx.node;
  12252. // node.debug("nodeRemoveChildMarkup()");
  12253. node.visit(function(n) {
  12254. if (n.tr) {
  12255. $(n.tr).remove();
  12256. n.tr = null;
  12257. }
  12258. });
  12259. },
  12260. nodeRemoveMarkup: function(ctx) {
  12261. var node = ctx.node;
  12262. // node.debug("nodeRemoveMarkup()");
  12263. if (node.tr) {
  12264. $(node.tr).remove();
  12265. node.tr = null;
  12266. }
  12267. this.nodeRemoveChildMarkup(ctx);
  12268. },
  12269. /* Override standard render. */
  12270. nodeRender: function(ctx, force, deep, collapsed, _recursive) {
  12271. var children,
  12272. firstTr,
  12273. i,
  12274. l,
  12275. newRow,
  12276. prevNode,
  12277. prevTr,
  12278. subCtx,
  12279. tree = ctx.tree,
  12280. node = ctx.node,
  12281. opts = ctx.options,
  12282. isRootNode = !node.parent;
  12283. if (tree._enableUpdate === false) {
  12284. // $.ui.fancytree.debug("*** nodeRender _enableUpdate: false");
  12285. return;
  12286. }
  12287. if (!_recursive) {
  12288. ctx.hasCollapsedParents = node.parent && !node.parent.expanded;
  12289. }
  12290. // $.ui.fancytree.debug("*** nodeRender " + node + ", isRoot=" + isRootNode, "tr=" + node.tr, "hcp=" + ctx.hasCollapsedParents, "parent.tr=" + (node.parent && node.parent.tr));
  12291. if (!isRootNode) {
  12292. if (node.tr && force) {
  12293. this.nodeRemoveMarkup(ctx);
  12294. }
  12295. if (node.tr) {
  12296. if (force) {
  12297. // Set icon, link, and title (normally this is only required on initial render)
  12298. this.nodeRenderTitle(ctx); // triggers renderColumns()
  12299. } else {
  12300. // Update element classes according to node state
  12301. this.nodeRenderStatus(ctx);
  12302. }
  12303. } else {
  12304. if (ctx.hasCollapsedParents && !deep) {
  12305. // #166: we assume that the parent will be (recursively) rendered
  12306. // later anyway.
  12307. // node.debug("nodeRender ignored due to unrendered parent");
  12308. return;
  12309. }
  12310. // Create new <tr> after previous row
  12311. // if( node.isStatusNode() ) {
  12312. // newRow = tree.statusRowFragment.firstChild.cloneNode(true);
  12313. // } else {
  12314. newRow = tree.rowFragment.firstChild.cloneNode(true);
  12315. // }
  12316. prevNode = findPrevRowNode(node);
  12317. // $.ui.fancytree.debug("*** nodeRender " + node + ": prev: " + prevNode.key);
  12318. _assert(prevNode);
  12319. if (collapsed === true && _recursive) {
  12320. // hide all child rows, so we can use an animation to show it later
  12321. newRow.style.display = "none";
  12322. } else if (deep && ctx.hasCollapsedParents) {
  12323. // also hide this row if deep === true but any parent is collapsed
  12324. newRow.style.display = "none";
  12325. // newRow.style.color = "red";
  12326. }
  12327. if (prevNode.tr) {
  12328. insertSiblingAfter(prevNode.tr, newRow);
  12329. } else {
  12330. _assert(
  12331. !prevNode.parent,
  12332. "prev. row must have a tr, or be system root"
  12333. );
  12334. // tree.tbody.appendChild(newRow);
  12335. insertFirstChild(tree.tbody, newRow); // #675
  12336. }
  12337. node.tr = newRow;
  12338. if (node.key && opts.generateIds) {
  12339. node.tr.id = opts.idPrefix + node.key;
  12340. }
  12341. node.tr.ftnode = node;
  12342. // if(opts.aria){
  12343. // $(node.tr).attr("aria-labelledby", "ftal_" + opts.idPrefix + node.key);
  12344. // }
  12345. node.span = $("span.fancytree-node", node.tr).get(0);
  12346. // Set icon, link, and title (normally this is only required on initial render)
  12347. this.nodeRenderTitle(ctx);
  12348. // Allow tweaking, binding, after node was created for the first time
  12349. // tree._triggerNodeEvent("createNode", ctx);
  12350. if (opts.createNode) {
  12351. opts.createNode.call(tree, { type: "createNode" }, ctx);
  12352. }
  12353. }
  12354. }
  12355. // Allow tweaking after node state was rendered
  12356. // tree._triggerNodeEvent("renderNode", ctx);
  12357. if (opts.renderNode) {
  12358. opts.renderNode.call(tree, { type: "renderNode" }, ctx);
  12359. }
  12360. // Visit child nodes
  12361. // Add child markup
  12362. children = node.children;
  12363. if (children && (isRootNode || deep || node.expanded)) {
  12364. for (i = 0, l = children.length; i < l; i++) {
  12365. subCtx = $.extend({}, ctx, { node: children[i] });
  12366. subCtx.hasCollapsedParents =
  12367. subCtx.hasCollapsedParents || !node.expanded;
  12368. this.nodeRender(subCtx, force, deep, collapsed, true);
  12369. }
  12370. }
  12371. // Make sure, that <tr> order matches node.children order.
  12372. if (children && !_recursive) {
  12373. // we only have to do it once, for the root branch
  12374. prevTr = node.tr || null;
  12375. firstTr = tree.tbody.firstChild;
  12376. // Iterate over all descendants
  12377. node.visit(function(n) {
  12378. if (n.tr) {
  12379. if (
  12380. !n.parent.expanded &&
  12381. n.tr.style.display !== "none"
  12382. ) {
  12383. // fix after a node was dropped over a collapsed
  12384. n.tr.style.display = "none";
  12385. setChildRowVisibility(n, false);
  12386. }
  12387. if (n.tr.previousSibling !== prevTr) {
  12388. node.debug("_fixOrder: mismatch at node: " + n);
  12389. var nextTr = prevTr ? prevTr.nextSibling : firstTr;
  12390. tree.tbody.insertBefore(n.tr, nextTr);
  12391. }
  12392. prevTr = n.tr;
  12393. }
  12394. });
  12395. }
  12396. // Update element classes according to node state
  12397. // if(!isRootNode){
  12398. // this.nodeRenderStatus(ctx);
  12399. // }
  12400. },
  12401. nodeRenderTitle: function(ctx, title) {
  12402. var $cb,
  12403. res,
  12404. tree = ctx.tree,
  12405. node = ctx.node,
  12406. opts = ctx.options,
  12407. isStatusNode = node.isStatusNode();
  12408. res = this._super(ctx, title);
  12409. if (node.isRootNode()) {
  12410. return res;
  12411. }
  12412. // Move checkbox to custom column
  12413. if (
  12414. opts.checkbox &&
  12415. !isStatusNode &&
  12416. opts.table.checkboxColumnIdx != null
  12417. ) {
  12418. $cb = $("span.fancytree-checkbox", node.span); //.detach();
  12419. $(node.tr)
  12420. .find("td")
  12421. .eq(+opts.table.checkboxColumnIdx)
  12422. .html($cb);
  12423. }
  12424. // Update element classes according to node state
  12425. this.nodeRenderStatus(ctx);
  12426. if (isStatusNode) {
  12427. if (opts.renderStatusColumns) {
  12428. // Let user code write column content
  12429. opts.renderStatusColumns.call(
  12430. tree,
  12431. { type: "renderStatusColumns" },
  12432. ctx
  12433. );
  12434. } else if (opts.table.mergeStatusColumns && node.isTopLevel()) {
  12435. $(node.tr)
  12436. .find(">td")
  12437. .eq(0)
  12438. .prop("colspan", tree.columnCount)
  12439. .text(node.title)
  12440. .addClass("fancytree-status-merged")
  12441. .nextAll()
  12442. .remove();
  12443. } // else: default rendering for status node: leave other cells empty
  12444. } else if (opts.renderColumns) {
  12445. opts.renderColumns.call(tree, { type: "renderColumns" }, ctx);
  12446. }
  12447. return res;
  12448. },
  12449. nodeRenderStatus: function(ctx) {
  12450. var indent,
  12451. node = ctx.node,
  12452. opts = ctx.options;
  12453. this._super(ctx);
  12454. $(node.tr).removeClass("fancytree-node");
  12455. // indent
  12456. indent = (node.getLevel() - 1) * opts.table.indentation;
  12457. if (opts.rtl) {
  12458. $(node.span).css({ paddingRight: indent + "px" });
  12459. } else {
  12460. $(node.span).css({ paddingLeft: indent + "px" });
  12461. }
  12462. },
  12463. /* Expand node, return Deferred.promise. */
  12464. nodeSetExpanded: function(ctx, flag, callOpts) {
  12465. // flag defaults to true
  12466. flag = flag !== false;
  12467. if ((ctx.node.expanded && flag) || (!ctx.node.expanded && !flag)) {
  12468. // Expanded state isn't changed - just call base implementation
  12469. return this._superApply(arguments);
  12470. }
  12471. var dfd = new $.Deferred(),
  12472. subOpts = $.extend({}, callOpts, {
  12473. noEvents: true,
  12474. noAnimation: true,
  12475. });
  12476. callOpts = callOpts || {};
  12477. function _afterExpand(ok) {
  12478. setChildRowVisibility(ctx.node, flag);
  12479. if (ok) {
  12480. if (
  12481. flag &&
  12482. ctx.options.autoScroll &&
  12483. !callOpts.noAnimation &&
  12484. ctx.node.hasChildren()
  12485. ) {
  12486. // Scroll down to last child, but keep current node visible
  12487. ctx.node
  12488. .getLastChild()
  12489. .scrollIntoView(true, { topNode: ctx.node })
  12490. .always(function() {
  12491. if (!callOpts.noEvents) {
  12492. ctx.tree._triggerNodeEvent(
  12493. flag ? "expand" : "collapse",
  12494. ctx
  12495. );
  12496. }
  12497. dfd.resolveWith(ctx.node);
  12498. });
  12499. } else {
  12500. if (!callOpts.noEvents) {
  12501. ctx.tree._triggerNodeEvent(
  12502. flag ? "expand" : "collapse",
  12503. ctx
  12504. );
  12505. }
  12506. dfd.resolveWith(ctx.node);
  12507. }
  12508. } else {
  12509. if (!callOpts.noEvents) {
  12510. ctx.tree._triggerNodeEvent(
  12511. flag ? "expand" : "collapse",
  12512. ctx
  12513. );
  12514. }
  12515. dfd.rejectWith(ctx.node);
  12516. }
  12517. }
  12518. // Call base-expand with disabled events and animation
  12519. this._super(ctx, flag, subOpts)
  12520. .done(function() {
  12521. _afterExpand(true);
  12522. })
  12523. .fail(function() {
  12524. _afterExpand(false);
  12525. });
  12526. return dfd.promise();
  12527. },
  12528. nodeSetStatus: function(ctx, status, message, details) {
  12529. if (status === "ok") {
  12530. var node = ctx.node,
  12531. firstChild = node.children ? node.children[0] : null;
  12532. if (firstChild && firstChild.isStatusNode()) {
  12533. $(firstChild.tr).remove();
  12534. }
  12535. }
  12536. return this._superApply(arguments);
  12537. },
  12538. treeClear: function(ctx) {
  12539. this.nodeRemoveChildMarkup(this._makeHookContext(this.rootNode));
  12540. return this._superApply(arguments);
  12541. },
  12542. treeDestroy: function(ctx) {
  12543. this.$container.find("tbody").empty();
  12544. if (this.$source) {
  12545. this.$source.removeClass("fancytree-helper-hidden");
  12546. }
  12547. return this._superApply(arguments);
  12548. },
  12549. /*,
  12550. treeSetFocus: function(ctx, flag) {
  12551. // alert("treeSetFocus" + ctx.tree.$container);
  12552. ctx.tree.$container.focus();
  12553. $.ui.fancytree.focusTree = ctx.tree;
  12554. }*/
  12555. });
  12556. // Value returned by `require('jquery.fancytree..')`
  12557. return $.ui.fancytree;
  12558. }); // End of closure
  12559. /*! Extension 'jquery.fancytree.themeroller.js' *//*!
  12560. * jquery.fancytree.themeroller.js
  12561. *
  12562. * Enable jQuery UI ThemeRoller styles.
  12563. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12564. *
  12565. * @see http://jqueryui.com/themeroller/
  12566. *
  12567. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  12568. *
  12569. * Released under the MIT license
  12570. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12571. *
  12572. * @version 2.38.0
  12573. * @date 2021-02-09T20:03:49Z
  12574. */
  12575. (function(factory) {
  12576. if (typeof define === "function" && define.amd) {
  12577. // AMD. Register as an anonymous module.
  12578. define(["jquery", "./jquery.fancytree"], factory);
  12579. } else if (typeof module === "object" && module.exports) {
  12580. // Node/CommonJS
  12581. require("./jquery.fancytree");
  12582. module.exports = factory(require("jquery"));
  12583. } else {
  12584. // Browser globals
  12585. factory(jQuery);
  12586. }
  12587. })(function($) {
  12588. "use strict";
  12589. /*******************************************************************************
  12590. * Extension code
  12591. */
  12592. $.ui.fancytree.registerExtension({
  12593. name: "themeroller",
  12594. version: "2.38.0",
  12595. // Default options for this extension.
  12596. options: {
  12597. activeClass: "ui-state-active", // Class added to active node
  12598. // activeClass: "ui-state-highlight",
  12599. addClass: "ui-corner-all", // Class added to all nodes
  12600. focusClass: "ui-state-focus", // Class added to focused node
  12601. hoverClass: "ui-state-hover", // Class added to hovered node
  12602. selectedClass: "ui-state-highlight", // Class added to selected nodes
  12603. // selectedClass: "ui-state-active"
  12604. },
  12605. treeInit: function(ctx) {
  12606. var $el = ctx.widget.element,
  12607. opts = ctx.options.themeroller;
  12608. this._superApply(arguments);
  12609. if ($el[0].nodeName === "TABLE") {
  12610. $el.addClass("ui-widget ui-corner-all");
  12611. $el.find(">thead tr").addClass("ui-widget-header");
  12612. $el.find(">tbody").addClass("ui-widget-conent");
  12613. } else {
  12614. $el.addClass("ui-widget ui-widget-content ui-corner-all");
  12615. }
  12616. $el.on("mouseenter mouseleave", ".fancytree-node", function(event) {
  12617. var node = $.ui.fancytree.getNode(event.target),
  12618. flag = event.type === "mouseenter";
  12619. $(node.tr ? node.tr : node.span).toggleClass(
  12620. opts.hoverClass + " " + opts.addClass,
  12621. flag
  12622. );
  12623. });
  12624. },
  12625. treeDestroy: function(ctx) {
  12626. this._superApply(arguments);
  12627. ctx.widget.element.removeClass(
  12628. "ui-widget ui-widget-content ui-corner-all"
  12629. );
  12630. },
  12631. nodeRenderStatus: function(ctx) {
  12632. var classes = {},
  12633. node = ctx.node,
  12634. $el = $(node.tr ? node.tr : node.span),
  12635. opts = ctx.options.themeroller;
  12636. this._super(ctx);
  12637. /*
  12638. .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.
  12639. .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.
  12640. .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.
  12641. .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.
  12642. .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.
  12643. .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.
  12644. .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.
  12645. */
  12646. // Set ui-state-* class (handle the case that the same class is assigned
  12647. // to different states)
  12648. classes[opts.activeClass] = false;
  12649. classes[opts.focusClass] = false;
  12650. classes[opts.selectedClass] = false;
  12651. if (node.isActive()) {
  12652. classes[opts.activeClass] = true;
  12653. }
  12654. if (node.hasFocus()) {
  12655. classes[opts.focusClass] = true;
  12656. }
  12657. // activeClass takes precedence before selectedClass:
  12658. if (node.isSelected() && !node.isActive()) {
  12659. classes[opts.selectedClass] = true;
  12660. }
  12661. $el.toggleClass(opts.activeClass, classes[opts.activeClass]);
  12662. $el.toggleClass(opts.focusClass, classes[opts.focusClass]);
  12663. $el.toggleClass(opts.selectedClass, classes[opts.selectedClass]);
  12664. // Additional classes (e.g. 'ui-corner-all')
  12665. $el.addClass(opts.addClass);
  12666. },
  12667. });
  12668. // Value returned by `require('jquery.fancytree..')`
  12669. return $.ui.fancytree;
  12670. }); // End of closure
  12671. /*! Extension 'jquery.fancytree.wide.js' *//*!
  12672. * jquery.fancytree.wide.js
  12673. * Support for 100% wide selection bars.
  12674. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12675. *
  12676. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  12677. *
  12678. * Released under the MIT license
  12679. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12680. *
  12681. * @version 2.38.0
  12682. * @date 2021-02-09T20:03:49Z
  12683. */
  12684. (function(factory) {
  12685. if (typeof define === "function" && define.amd) {
  12686. // AMD. Register as an anonymous module.
  12687. define(["jquery", "./jquery.fancytree"], factory);
  12688. } else if (typeof module === "object" && module.exports) {
  12689. // Node/CommonJS
  12690. require("./jquery.fancytree");
  12691. module.exports = factory(require("jquery"));
  12692. } else {
  12693. // Browser globals
  12694. factory(jQuery);
  12695. }
  12696. })(function($) {
  12697. "use strict";
  12698. var reNumUnit = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/; // split "1.5em" to ["1.5", "em"]
  12699. /*******************************************************************************
  12700. * Private functions and variables
  12701. */
  12702. // var _assert = $.ui.fancytree.assert;
  12703. /* Calculate inner width without scrollbar */
  12704. // function realInnerWidth($el) {
  12705. // // http://blog.jquery.com/2012/08/16/jquery-1-8-box-sizing-width-csswidth-and-outerwidth/
  12706. // // inst.contWidth = parseFloat(this.$container.css("width"), 10);
  12707. // // 'Client width without scrollbar' - 'padding'
  12708. // return $el[0].clientWidth - ($el.innerWidth() - parseFloat($el.css("width"), 10));
  12709. // }
  12710. /* Create a global embedded CSS style for the tree. */
  12711. function defineHeadStyleElement(id, cssText) {
  12712. id = "fancytree-style-" + id;
  12713. var $headStyle = $("#" + id);
  12714. if (!cssText) {
  12715. $headStyle.remove();
  12716. return null;
  12717. }
  12718. if (!$headStyle.length) {
  12719. $headStyle = $("<style />")
  12720. .attr("id", id)
  12721. .addClass("fancytree-style")
  12722. .prop("type", "text/css")
  12723. .appendTo("head");
  12724. }
  12725. try {
  12726. $headStyle.html(cssText);
  12727. } catch (e) {
  12728. // fix for IE 6-8
  12729. $headStyle[0].styleSheet.cssText = cssText;
  12730. }
  12731. return $headStyle;
  12732. }
  12733. /* Calculate the CSS rules that indent title spans. */
  12734. function renderLevelCss(
  12735. containerId,
  12736. depth,
  12737. levelOfs,
  12738. lineOfs,
  12739. labelOfs,
  12740. measureUnit
  12741. ) {
  12742. var i,
  12743. prefix = "#" + containerId + " span.fancytree-level-",
  12744. rules = [];
  12745. for (i = 0; i < depth; i++) {
  12746. rules.push(
  12747. prefix +
  12748. (i + 1) +
  12749. " span.fancytree-title { padding-left: " +
  12750. (i * levelOfs + lineOfs) +
  12751. measureUnit +
  12752. "; }"
  12753. );
  12754. }
  12755. // Some UI animations wrap the UL inside a DIV and set position:relative on both.
  12756. // This breaks the left:0 and padding-left:nn settings of the title
  12757. rules.push(
  12758. "#" +
  12759. containerId +
  12760. " div.ui-effects-wrapper ul li span.fancytree-title, " +
  12761. "#" +
  12762. containerId +
  12763. " li.fancytree-animating span.fancytree-title " + // #716
  12764. "{ padding-left: " +
  12765. labelOfs +
  12766. measureUnit +
  12767. "; position: static; width: auto; }"
  12768. );
  12769. return rules.join("\n");
  12770. }
  12771. // /**
  12772. // * [ext-wide] Recalculate the width of the selection bar after the tree container
  12773. // * was resized.<br>
  12774. // * May be called explicitly on container resize, since there is no resize event
  12775. // * for DIV tags.
  12776. // *
  12777. // * @alias Fancytree#wideUpdate
  12778. // * @requires jquery.fancytree.wide.js
  12779. // */
  12780. // $.ui.fancytree._FancytreeClass.prototype.wideUpdate = function(){
  12781. // var inst = this.ext.wide,
  12782. // prevCw = inst.contWidth,
  12783. // prevLo = inst.lineOfs;
  12784. // inst.contWidth = realInnerWidth(this.$container);
  12785. // // Each title is precceeded by 2 or 3 icons (16px + 3 margin)
  12786. // // + 1px title border and 3px title padding
  12787. // // TODO: use code from treeInit() below
  12788. // inst.lineOfs = (this.options.checkbox ? 3 : 2) * 19;
  12789. // if( prevCw !== inst.contWidth || prevLo !== inst.lineOfs ) {
  12790. // this.debug("wideUpdate: " + inst.contWidth);
  12791. // this.visit(function(node){
  12792. // node.tree._callHook("nodeRenderTitle", node);
  12793. // });
  12794. // }
  12795. // };
  12796. /*******************************************************************************
  12797. * Extension code
  12798. */
  12799. $.ui.fancytree.registerExtension({
  12800. name: "wide",
  12801. version: "2.38.0",
  12802. // Default options for this extension.
  12803. options: {
  12804. iconWidth: null, // Adjust this if @fancy-icon-width != "16px"
  12805. iconSpacing: null, // Adjust this if @fancy-icon-spacing != "3px"
  12806. labelSpacing: null, // Adjust this if padding between icon and label != "3px"
  12807. levelOfs: null, // Adjust this if ul padding != "16px"
  12808. },
  12809. treeCreate: function(ctx) {
  12810. this._superApply(arguments);
  12811. this.$container.addClass("fancytree-ext-wide");
  12812. var containerId,
  12813. cssText,
  12814. iconSpacingUnit,
  12815. labelSpacingUnit,
  12816. iconWidthUnit,
  12817. levelOfsUnit,
  12818. instOpts = ctx.options.wide,
  12819. // css sniffing
  12820. $dummyLI = $(
  12821. "<li id='fancytreeTemp'><span class='fancytree-node'><span class='fancytree-icon' /><span class='fancytree-title' /></span><ul />"
  12822. ).appendTo(ctx.tree.$container),
  12823. $dummyIcon = $dummyLI.find(".fancytree-icon"),
  12824. $dummyUL = $dummyLI.find("ul"),
  12825. // $dummyTitle = $dummyLI.find(".fancytree-title"),
  12826. iconSpacing =
  12827. instOpts.iconSpacing || $dummyIcon.css("margin-left"),
  12828. iconWidth = instOpts.iconWidth || $dummyIcon.css("width"),
  12829. labelSpacing = instOpts.labelSpacing || "3px",
  12830. levelOfs = instOpts.levelOfs || $dummyUL.css("padding-left");
  12831. $dummyLI.remove();
  12832. iconSpacingUnit = iconSpacing.match(reNumUnit)[2];
  12833. iconSpacing = parseFloat(iconSpacing, 10);
  12834. labelSpacingUnit = labelSpacing.match(reNumUnit)[2];
  12835. labelSpacing = parseFloat(labelSpacing, 10);
  12836. iconWidthUnit = iconWidth.match(reNumUnit)[2];
  12837. iconWidth = parseFloat(iconWidth, 10);
  12838. levelOfsUnit = levelOfs.match(reNumUnit)[2];
  12839. if (
  12840. iconSpacingUnit !== iconWidthUnit ||
  12841. levelOfsUnit !== iconWidthUnit ||
  12842. labelSpacingUnit !== iconWidthUnit
  12843. ) {
  12844. $.error(
  12845. "iconWidth, iconSpacing, and levelOfs must have the same css measure unit"
  12846. );
  12847. }
  12848. this._local.measureUnit = iconWidthUnit;
  12849. this._local.levelOfs = parseFloat(levelOfs);
  12850. this._local.lineOfs =
  12851. (1 +
  12852. (ctx.options.checkbox ? 1 : 0) +
  12853. (ctx.options.icon === false ? 0 : 1)) *
  12854. (iconWidth + iconSpacing) +
  12855. iconSpacing;
  12856. this._local.labelOfs = labelSpacing;
  12857. this._local.maxDepth = 10;
  12858. // Get/Set a unique Id on the container (if not already exists)
  12859. containerId = this.$container.uniqueId().attr("id");
  12860. // Generated css rules for some levels (extended on demand)
  12861. cssText = renderLevelCss(
  12862. containerId,
  12863. this._local.maxDepth,
  12864. this._local.levelOfs,
  12865. this._local.lineOfs,
  12866. this._local.labelOfs,
  12867. this._local.measureUnit
  12868. );
  12869. defineHeadStyleElement(containerId, cssText);
  12870. },
  12871. treeDestroy: function(ctx) {
  12872. // Remove generated css rules
  12873. defineHeadStyleElement(this.$container.attr("id"), null);
  12874. return this._superApply(arguments);
  12875. },
  12876. nodeRenderStatus: function(ctx) {
  12877. var containerId,
  12878. cssText,
  12879. res,
  12880. node = ctx.node,
  12881. level = node.getLevel();
  12882. res = this._super(ctx);
  12883. // Generate some more level-n rules if required
  12884. if (level > this._local.maxDepth) {
  12885. containerId = this.$container.attr("id");
  12886. this._local.maxDepth *= 2;
  12887. node.debug(
  12888. "Define global ext-wide css up to level " +
  12889. this._local.maxDepth
  12890. );
  12891. cssText = renderLevelCss(
  12892. containerId,
  12893. this._local.maxDepth,
  12894. this._local.levelOfs,
  12895. this._local.lineOfs,
  12896. this._local.labelSpacing,
  12897. this._local.measureUnit
  12898. );
  12899. defineHeadStyleElement(containerId, cssText);
  12900. }
  12901. // Add level-n class to apply indentation padding.
  12902. // (Setting element style would not work, since it cannot easily be
  12903. // overriden while animations run)
  12904. $(node.span).addClass("fancytree-level-" + level);
  12905. return res;
  12906. },
  12907. });
  12908. // Value returned by `require('jquery.fancytree..')`
  12909. return $.ui.fancytree;
  12910. }); // End of closure
  12911. // Value returned by `require('jquery.fancytree')`
  12912. return $.ui.fancytree;
  12913. })); // End of closure