jquery.fancytree-all-deps.js 396 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839
  1. /*! jQuery Fancytree Plugin - 2.38.5 - 2025-04-05T06:40:00Z
  2. * https://github.com/mar10/fancytree
  3. * Copyright (c) 2025 Martin Wendt; Licensed MIT
  4. */
  5. /*! jQuery UI - v1.14.1 - 2025-03-26
  6. * https://jqueryui.com
  7. * Includes: widget.js, position.js, jquery-patch.js, keycode.js, scroll-parent.js, unique-id.js
  8. * Copyright OpenJS 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.14.1";
  16. /*!
  17. * jQuery UI Widget 1.14.1
  18. * https://jqueryui.com
  19. *
  20. * Copyright OpenJS Foundation and other contributors
  21. * Released under the MIT license.
  22. * https://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: https://api.jqueryui.com/jQuery.widget/
  28. //>>demos: https://jqueryui.com/widget/
  29. var widgetUuid = 0;
  30. var widgetHasOwnProperty = Array.prototype.hasOwnProperty;
  31. var widgetSlice = Array.prototype.slice;
  32. $.cleanData = ( function( orig ) {
  33. return function( elems ) {
  34. var events, elem, i;
  35. for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {
  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. }
  42. orig( elems );
  43. };
  44. } )( $.cleanData );
  45. $.widget = function( name, base, prototype ) {
  46. var existingConstructor, constructor, basePrototype;
  47. // ProxiedPrototype allows the provided prototype to remain unmodified
  48. // so that it can be used as a mixin for multiple widgets (#8876)
  49. var proxiedPrototype = {};
  50. var namespace = name.split( "." )[ 0 ];
  51. name = name.split( "." )[ 1 ];
  52. if ( name === "__proto__" || name === "constructor" ) {
  53. return $.error( "Invalid widget name: " + name );
  54. }
  55. var fullName = namespace + "-" + name;
  56. if ( !prototype ) {
  57. prototype = base;
  58. base = $.Widget;
  59. }
  60. if ( Array.isArray( prototype ) ) {
  61. prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
  62. }
  63. // Create selector for plugin
  64. $.expr.pseudos[ fullName.toLowerCase() ] = function( elem ) {
  65. return !!$.data( elem, fullName );
  66. };
  67. $[ namespace ] = $[ namespace ] || {};
  68. existingConstructor = $[ namespace ][ name ];
  69. constructor = $[ namespace ][ name ] = function( options, element ) {
  70. // Allow instantiation without "new" keyword
  71. if ( !this || !this._createWidget ) {
  72. return new constructor( options, element );
  73. }
  74. // Allow instantiation without initializing for simple inheritance
  75. // must use "new" keyword (the code above always passes args)
  76. if ( arguments.length ) {
  77. this._createWidget( options, element );
  78. }
  79. };
  80. // Extend with the existing constructor to carry over any static properties
  81. $.extend( constructor, existingConstructor, {
  82. version: prototype.version,
  83. // Copy the object used to create the prototype in case we need to
  84. // redefine the widget later
  85. _proto: $.extend( {}, prototype ),
  86. // Track widgets that inherit from this widget in case this widget is
  87. // redefined after a widget inherits from it
  88. _childConstructors: []
  89. } );
  90. basePrototype = new base();
  91. // We need to make the options hash a property directly on the new instance
  92. // otherwise we'll modify the options hash on the prototype that we're
  93. // inheriting from
  94. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  95. $.each( prototype, function( prop, value ) {
  96. if ( typeof value !== "function" ) {
  97. proxiedPrototype[ prop ] = value;
  98. return;
  99. }
  100. proxiedPrototype[ prop ] = ( function() {
  101. function _super() {
  102. return base.prototype[ prop ].apply( this, arguments );
  103. }
  104. function _superApply( args ) {
  105. return base.prototype[ prop ].apply( this, args );
  106. }
  107. return function() {
  108. var __super = this._super;
  109. var __superApply = this._superApply;
  110. var returnValue;
  111. this._super = _super;
  112. this._superApply = _superApply;
  113. returnValue = value.apply( this, arguments );
  114. this._super = __super;
  115. this._superApply = __superApply;
  116. return returnValue;
  117. };
  118. } )();
  119. } );
  120. constructor.prototype = $.widget.extend( basePrototype, {
  121. // TODO: remove support for widgetEventPrefix
  122. // always use the name + a colon as the prefix, e.g., draggable:start
  123. // don't prefix for widgets that aren't DOM-based
  124. widgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name
  125. }, proxiedPrototype, {
  126. constructor: constructor,
  127. namespace: namespace,
  128. widgetName: name,
  129. widgetFullName: fullName
  130. } );
  131. // If this widget is being redefined then we need to find all widgets that
  132. // are inheriting from it and redefine all of them so that they inherit from
  133. // the new version of this widget. We're essentially trying to replace one
  134. // level in the prototype chain.
  135. if ( existingConstructor ) {
  136. $.each( existingConstructor._childConstructors, function( i, child ) {
  137. var childPrototype = child.prototype;
  138. // Redefine the child widget using the same prototype that was
  139. // originally used, but inherit from the new version of the base
  140. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor,
  141. child._proto );
  142. } );
  143. // Remove the list of existing child constructors from the old constructor
  144. // so the old child constructors can be garbage collected
  145. delete existingConstructor._childConstructors;
  146. } else {
  147. base._childConstructors.push( constructor );
  148. }
  149. $.widget.bridge( name, constructor );
  150. return constructor;
  151. };
  152. $.widget.extend = function( target ) {
  153. var input = widgetSlice.call( arguments, 1 );
  154. var inputIndex = 0;
  155. var inputLength = input.length;
  156. var key;
  157. var value;
  158. for ( ; inputIndex < inputLength; inputIndex++ ) {
  159. for ( key in input[ inputIndex ] ) {
  160. value = input[ inputIndex ][ key ];
  161. if ( widgetHasOwnProperty.call( input[ inputIndex ], key ) && value !== undefined ) {
  162. // Clone objects
  163. if ( $.isPlainObject( value ) ) {
  164. target[ key ] = $.isPlainObject( target[ key ] ) ?
  165. $.widget.extend( {}, target[ key ], value ) :
  166. // Don't extend strings, arrays, etc. with objects
  167. $.widget.extend( {}, value );
  168. // Copy everything else by reference
  169. } else {
  170. target[ key ] = value;
  171. }
  172. }
  173. }
  174. }
  175. return target;
  176. };
  177. $.widget.bridge = function( name, object ) {
  178. var fullName = object.prototype.widgetFullName || name;
  179. $.fn[ name ] = function( options ) {
  180. var isMethodCall = typeof options === "string";
  181. var args = widgetSlice.call( arguments, 1 );
  182. var returnValue = this;
  183. if ( isMethodCall ) {
  184. // If this is an empty collection, we need to have the instance method
  185. // return undefined instead of the jQuery instance
  186. if ( !this.length && options === "instance" ) {
  187. returnValue = undefined;
  188. } else {
  189. this.each( function() {
  190. var methodValue;
  191. var instance = $.data( this, fullName );
  192. if ( options === "instance" ) {
  193. returnValue = instance;
  194. return false;
  195. }
  196. if ( !instance ) {
  197. return $.error( "cannot call methods on " + name +
  198. " prior to initialization; " +
  199. "attempted to call method '" + options + "'" );
  200. }
  201. if ( typeof instance[ options ] !== "function" ||
  202. options.charAt( 0 ) === "_" ) {
  203. return $.error( "no such method '" + options + "' for " + name +
  204. " widget instance" );
  205. }
  206. methodValue = instance[ options ].apply( instance, args );
  207. if ( methodValue !== instance && methodValue !== undefined ) {
  208. returnValue = methodValue && methodValue.jquery ?
  209. returnValue.pushStack( methodValue.get() ) :
  210. methodValue;
  211. return false;
  212. }
  213. } );
  214. }
  215. } else {
  216. // Allow multiple hashes to be passed on init
  217. if ( args.length ) {
  218. options = $.widget.extend.apply( null, [ options ].concat( args ) );
  219. }
  220. this.each( function() {
  221. var instance = $.data( this, fullName );
  222. if ( instance ) {
  223. instance.option( options || {} );
  224. if ( instance._init ) {
  225. instance._init();
  226. }
  227. } else {
  228. $.data( this, fullName, new object( options, this ) );
  229. }
  230. } );
  231. }
  232. return returnValue;
  233. };
  234. };
  235. $.Widget = function( /* options, element */ ) {};
  236. $.Widget._childConstructors = [];
  237. $.Widget.prototype = {
  238. widgetName: "widget",
  239. widgetEventPrefix: "",
  240. defaultElement: "<div>",
  241. options: {
  242. classes: {},
  243. disabled: false,
  244. // Callbacks
  245. create: null
  246. },
  247. _createWidget: function( options, element ) {
  248. element = $( element || this.defaultElement || this )[ 0 ];
  249. this.element = $( element );
  250. this.uuid = widgetUuid++;
  251. this.eventNamespace = "." + this.widgetName + this.uuid;
  252. this.bindings = $();
  253. this.hoverable = $();
  254. this.focusable = $();
  255. this.classesElementLookup = {};
  256. if ( element !== this ) {
  257. $.data( element, this.widgetFullName, this );
  258. this._on( true, this.element, {
  259. remove: function( event ) {
  260. if ( event.target === element ) {
  261. this.destroy();
  262. }
  263. }
  264. } );
  265. this.document = $( element.style ?
  266. // Element within the document
  267. element.ownerDocument :
  268. // Element is window or document
  269. element.document || element );
  270. this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );
  271. }
  272. this.options = $.widget.extend( {},
  273. this.options,
  274. this._getCreateOptions(),
  275. options );
  276. this._create();
  277. if ( this.options.disabled ) {
  278. this._setOptionDisabled( this.options.disabled );
  279. }
  280. this._trigger( "create", null, this._getCreateEventData() );
  281. this._init();
  282. },
  283. _getCreateOptions: function() {
  284. return {};
  285. },
  286. _getCreateEventData: $.noop,
  287. _create: $.noop,
  288. _init: $.noop,
  289. destroy: function() {
  290. var that = this;
  291. this._destroy();
  292. $.each( this.classesElementLookup, function( key, value ) {
  293. that._removeClass( value, key );
  294. } );
  295. // We can probably remove the unbind calls in 2.0
  296. // all event bindings should go through this._on()
  297. this.element
  298. .off( this.eventNamespace )
  299. .removeData( this.widgetFullName );
  300. this.widget()
  301. .off( this.eventNamespace )
  302. .removeAttr( "aria-disabled" );
  303. // Clean up events and states
  304. this.bindings.off( this.eventNamespace );
  305. },
  306. _destroy: $.noop,
  307. widget: function() {
  308. return this.element;
  309. },
  310. option: function( key, value ) {
  311. var options = key;
  312. var parts;
  313. var curOption;
  314. var i;
  315. if ( arguments.length === 0 ) {
  316. // Don't return a reference to the internal hash
  317. return $.widget.extend( {}, this.options );
  318. }
  319. if ( typeof key === "string" ) {
  320. // Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  321. options = {};
  322. parts = key.split( "." );
  323. key = parts.shift();
  324. if ( parts.length ) {
  325. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  326. for ( i = 0; i < parts.length - 1; i++ ) {
  327. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  328. curOption = curOption[ parts[ i ] ];
  329. }
  330. key = parts.pop();
  331. if ( arguments.length === 1 ) {
  332. return curOption[ key ] === undefined ? null : curOption[ key ];
  333. }
  334. curOption[ key ] = value;
  335. } else {
  336. if ( arguments.length === 1 ) {
  337. return this.options[ key ] === undefined ? null : this.options[ key ];
  338. }
  339. options[ key ] = value;
  340. }
  341. }
  342. this._setOptions( options );
  343. return this;
  344. },
  345. _setOptions: function( options ) {
  346. var key;
  347. for ( key in options ) {
  348. this._setOption( key, options[ key ] );
  349. }
  350. return this;
  351. },
  352. _setOption: function( key, value ) {
  353. if ( key === "classes" ) {
  354. this._setOptionClasses( value );
  355. }
  356. this.options[ key ] = value;
  357. if ( key === "disabled" ) {
  358. this._setOptionDisabled( value );
  359. }
  360. return this;
  361. },
  362. _setOptionClasses: function( value ) {
  363. var classKey, elements, currentElements;
  364. for ( classKey in value ) {
  365. currentElements = this.classesElementLookup[ classKey ];
  366. if ( value[ classKey ] === this.options.classes[ classKey ] ||
  367. !currentElements ||
  368. !currentElements.length ) {
  369. continue;
  370. }
  371. // We are doing this to create a new jQuery object because the _removeClass() call
  372. // on the next line is going to destroy the reference to the current elements being
  373. // tracked. We need to save a copy of this collection so that we can add the new classes
  374. // below.
  375. elements = $( currentElements.get() );
  376. this._removeClass( currentElements, classKey );
  377. // We don't use _addClass() here, because that uses this.options.classes
  378. // for generating the string of classes. We want to use the value passed in from
  379. // _setOption(), this is the new value of the classes option which was passed to
  380. // _setOption(). We pass this value directly to _classes().
  381. elements.addClass( this._classes( {
  382. element: elements,
  383. keys: classKey,
  384. classes: value,
  385. add: true
  386. } ) );
  387. }
  388. },
  389. _setOptionDisabled: function( value ) {
  390. this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
  391. // If the widget is becoming disabled, then nothing is interactive
  392. if ( value ) {
  393. this._removeClass( this.hoverable, null, "ui-state-hover" );
  394. this._removeClass( this.focusable, null, "ui-state-focus" );
  395. }
  396. },
  397. enable: function() {
  398. return this._setOptions( { disabled: false } );
  399. },
  400. disable: function() {
  401. return this._setOptions( { disabled: true } );
  402. },
  403. _classes: function( options ) {
  404. var full = [];
  405. var that = this;
  406. options = $.extend( {
  407. element: this.element,
  408. classes: this.options.classes || {}
  409. }, options );
  410. function bindRemoveEvent() {
  411. var nodesToBind = [];
  412. options.element.each( function( _, element ) {
  413. var isTracked = $.map( that.classesElementLookup, function( elements ) {
  414. return elements;
  415. } )
  416. .some( function( elements ) {
  417. return elements.is( element );
  418. } );
  419. if ( !isTracked ) {
  420. nodesToBind.push( element );
  421. }
  422. } );
  423. that._on( $( nodesToBind ), {
  424. remove: "_untrackClassesElement"
  425. } );
  426. }
  427. function processClassString( classes, checkOption ) {
  428. var current, i;
  429. for ( i = 0; i < classes.length; i++ ) {
  430. current = that.classesElementLookup[ classes[ i ] ] || $();
  431. if ( options.add ) {
  432. bindRemoveEvent();
  433. current = $( $.uniqueSort( current.get().concat( options.element.get() ) ) );
  434. } else {
  435. current = $( current.not( options.element ).get() );
  436. }
  437. that.classesElementLookup[ classes[ i ] ] = current;
  438. full.push( classes[ i ] );
  439. if ( checkOption && options.classes[ classes[ i ] ] ) {
  440. full.push( options.classes[ classes[ i ] ] );
  441. }
  442. }
  443. }
  444. if ( options.keys ) {
  445. processClassString( options.keys.match( /\S+/g ) || [], true );
  446. }
  447. if ( options.extra ) {
  448. processClassString( options.extra.match( /\S+/g ) || [] );
  449. }
  450. return full.join( " " );
  451. },
  452. _untrackClassesElement: function( event ) {
  453. var that = this;
  454. $.each( that.classesElementLookup, function( key, value ) {
  455. if ( $.inArray( event.target, value ) !== -1 ) {
  456. that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
  457. }
  458. } );
  459. this._off( $( event.target ) );
  460. },
  461. _removeClass: function( element, keys, extra ) {
  462. return this._toggleClass( element, keys, extra, false );
  463. },
  464. _addClass: function( element, keys, extra ) {
  465. return this._toggleClass( element, keys, extra, true );
  466. },
  467. _toggleClass: function( element, keys, extra, add ) {
  468. add = ( typeof add === "boolean" ) ? add : extra;
  469. var shift = ( typeof element === "string" || element === null ),
  470. options = {
  471. extra: shift ? keys : extra,
  472. keys: shift ? element : keys,
  473. element: shift ? this.element : element,
  474. add: add
  475. };
  476. options.element.toggleClass( this._classes( options ), add );
  477. return this;
  478. },
  479. _on: function( suppressDisabledCheck, element, handlers ) {
  480. var delegateElement;
  481. var instance = this;
  482. // No suppressDisabledCheck flag, shuffle arguments
  483. if ( typeof suppressDisabledCheck !== "boolean" ) {
  484. handlers = element;
  485. element = suppressDisabledCheck;
  486. suppressDisabledCheck = false;
  487. }
  488. // No element argument, shuffle and use this.element
  489. if ( !handlers ) {
  490. handlers = element;
  491. element = this.element;
  492. delegateElement = this.widget();
  493. } else {
  494. element = delegateElement = $( element );
  495. this.bindings = this.bindings.add( element );
  496. }
  497. $.each( handlers, function( event, handler ) {
  498. function handlerProxy() {
  499. // Allow widgets to customize the disabled handling
  500. // - disabled as an array instead of boolean
  501. // - disabled class as method for disabling individual parts
  502. if ( !suppressDisabledCheck &&
  503. ( instance.options.disabled === true ||
  504. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  505. return;
  506. }
  507. return ( typeof handler === "string" ? instance[ handler ] : handler )
  508. .apply( instance, arguments );
  509. }
  510. // Copy the guid so direct unbinding works
  511. if ( typeof handler !== "string" ) {
  512. handlerProxy.guid = handler.guid =
  513. handler.guid || handlerProxy.guid || $.guid++;
  514. }
  515. var match = event.match( /^([\w:-]*)\s*(.*)$/ );
  516. var eventName = match[ 1 ] + instance.eventNamespace;
  517. var selector = match[ 2 ];
  518. if ( selector ) {
  519. delegateElement.on( eventName, selector, handlerProxy );
  520. } else {
  521. element.on( eventName, handlerProxy );
  522. }
  523. } );
  524. },
  525. _off: function( element, eventName ) {
  526. eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
  527. this.eventNamespace;
  528. element.off( eventName );
  529. // Clear the stack to avoid memory leaks (#10056)
  530. this.bindings = $( this.bindings.not( element ).get() );
  531. this.focusable = $( this.focusable.not( element ).get() );
  532. this.hoverable = $( this.hoverable.not( element ).get() );
  533. },
  534. _delay: function( handler, delay ) {
  535. function handlerProxy() {
  536. return ( typeof handler === "string" ? instance[ handler ] : handler )
  537. .apply( instance, arguments );
  538. }
  539. var instance = this;
  540. return setTimeout( handlerProxy, delay || 0 );
  541. },
  542. _hoverable: function( element ) {
  543. this.hoverable = this.hoverable.add( element );
  544. this._on( element, {
  545. mouseenter: function( event ) {
  546. this._addClass( $( event.currentTarget ), null, "ui-state-hover" );
  547. },
  548. mouseleave: function( event ) {
  549. this._removeClass( $( event.currentTarget ), null, "ui-state-hover" );
  550. }
  551. } );
  552. },
  553. _focusable: function( element ) {
  554. this.focusable = this.focusable.add( element );
  555. this._on( element, {
  556. focusin: function( event ) {
  557. this._addClass( $( event.currentTarget ), null, "ui-state-focus" );
  558. },
  559. focusout: function( event ) {
  560. this._removeClass( $( event.currentTarget ), null, "ui-state-focus" );
  561. }
  562. } );
  563. },
  564. _trigger: function( type, event, data ) {
  565. var prop, orig;
  566. var callback = this.options[ type ];
  567. data = data || {};
  568. event = $.Event( event );
  569. event.type = ( type === this.widgetEventPrefix ?
  570. type :
  571. this.widgetEventPrefix + type ).toLowerCase();
  572. // The original event may come from any element
  573. // so we need to reset the target on the new event
  574. event.target = this.element[ 0 ];
  575. // Copy original event properties over to the new event
  576. orig = event.originalEvent;
  577. if ( orig ) {
  578. for ( prop in orig ) {
  579. if ( !( prop in event ) ) {
  580. event[ prop ] = orig[ prop ];
  581. }
  582. }
  583. }
  584. this.element.trigger( event, data );
  585. return !( typeof callback === "function" &&
  586. callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
  587. event.isDefaultPrevented() );
  588. }
  589. };
  590. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  591. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  592. if ( typeof options === "string" ) {
  593. options = { effect: options };
  594. }
  595. var hasOptions;
  596. var effectName = !options ?
  597. method :
  598. options === true || typeof options === "number" ?
  599. defaultEffect :
  600. options.effect || defaultEffect;
  601. options = options || {};
  602. if ( typeof options === "number" ) {
  603. options = { duration: options };
  604. } else if ( options === true ) {
  605. options = {};
  606. }
  607. hasOptions = !$.isEmptyObject( options );
  608. options.complete = callback;
  609. if ( options.delay ) {
  610. element.delay( options.delay );
  611. }
  612. if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
  613. element[ method ]( options );
  614. } else if ( effectName !== method && element[ effectName ] ) {
  615. element[ effectName ]( options.duration, options.easing, callback );
  616. } else {
  617. element.queue( function( next ) {
  618. $( this )[ method ]();
  619. if ( callback ) {
  620. callback.call( element[ 0 ] );
  621. }
  622. next();
  623. } );
  624. }
  625. };
  626. } );
  627. var widget = $.widget;
  628. /*!
  629. * jQuery UI Position 1.14.1
  630. * https://jqueryui.com
  631. *
  632. * Copyright OpenJS Foundation and other contributors
  633. * Released under the MIT license.
  634. * https://jquery.org/license
  635. *
  636. * https://api.jqueryui.com/position/
  637. */
  638. //>>label: Position
  639. //>>group: Core
  640. //>>description: Positions elements relative to other elements.
  641. //>>docs: https://api.jqueryui.com/position/
  642. //>>demos: https://jqueryui.com/position/
  643. ( function() {
  644. var cachedScrollbarWidth,
  645. max = Math.max,
  646. abs = Math.abs,
  647. rhorizontal = /left|center|right/,
  648. rvertical = /top|center|bottom/,
  649. roffset = /[\+\-]\d+(\.[\d]+)?%?/,
  650. rposition = /^\w+/,
  651. rpercent = /%$/,
  652. _position = $.fn.position;
  653. function getOffsets( offsets, width, height ) {
  654. return [
  655. parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  656. parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  657. ];
  658. }
  659. function parseCss( element, property ) {
  660. return parseInt( $.css( element, property ), 10 ) || 0;
  661. }
  662. function isWindow( obj ) {
  663. return obj != null && obj === obj.window;
  664. }
  665. function getDimensions( elem ) {
  666. var raw = elem[ 0 ];
  667. if ( raw.nodeType === 9 ) {
  668. return {
  669. width: elem.width(),
  670. height: elem.height(),
  671. offset: { top: 0, left: 0 }
  672. };
  673. }
  674. if ( isWindow( raw ) ) {
  675. return {
  676. width: elem.width(),
  677. height: elem.height(),
  678. offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
  679. };
  680. }
  681. if ( raw.preventDefault ) {
  682. return {
  683. width: 0,
  684. height: 0,
  685. offset: { top: raw.pageY, left: raw.pageX }
  686. };
  687. }
  688. return {
  689. width: elem.outerWidth(),
  690. height: elem.outerHeight(),
  691. offset: elem.offset()
  692. };
  693. }
  694. $.position = {
  695. scrollbarWidth: function() {
  696. if ( cachedScrollbarWidth !== undefined ) {
  697. return cachedScrollbarWidth;
  698. }
  699. var w1, w2,
  700. div = $( "<div style=" +
  701. "'display:block;position:absolute;width:200px;height:200px;overflow:hidden;'>" +
  702. "<div style='height:300px;width:auto;'></div></div>" ),
  703. innerDiv = div.children()[ 0 ];
  704. $( "body" ).append( div );
  705. w1 = innerDiv.offsetWidth;
  706. div.css( "overflow", "scroll" );
  707. w2 = innerDiv.offsetWidth;
  708. if ( w1 === w2 ) {
  709. w2 = div[ 0 ].clientWidth;
  710. }
  711. div.remove();
  712. return ( cachedScrollbarWidth = w1 - w2 );
  713. },
  714. getScrollInfo: function( within ) {
  715. var overflowX = within.isWindow || within.isDocument ? "" :
  716. within.element.css( "overflow-x" ),
  717. overflowY = within.isWindow || within.isDocument ? "" :
  718. within.element.css( "overflow-y" ),
  719. hasOverflowX = overflowX === "scroll" ||
  720. ( overflowX === "auto" && within.width < within.element[ 0 ].scrollWidth ),
  721. hasOverflowY = overflowY === "scroll" ||
  722. ( overflowY === "auto" && within.height < within.element[ 0 ].scrollHeight );
  723. return {
  724. width: hasOverflowY ? $.position.scrollbarWidth() : 0,
  725. height: hasOverflowX ? $.position.scrollbarWidth() : 0
  726. };
  727. },
  728. getWithinInfo: function( element ) {
  729. var withinElement = $( element || window ),
  730. isElemWindow = isWindow( withinElement[ 0 ] ),
  731. isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
  732. hasOffset = !isElemWindow && !isDocument;
  733. return {
  734. element: withinElement,
  735. isWindow: isElemWindow,
  736. isDocument: isDocument,
  737. offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
  738. scrollLeft: withinElement.scrollLeft(),
  739. scrollTop: withinElement.scrollTop(),
  740. width: withinElement.outerWidth(),
  741. height: withinElement.outerHeight()
  742. };
  743. }
  744. };
  745. $.fn.position = function( options ) {
  746. if ( !options || !options.of ) {
  747. return _position.apply( this, arguments );
  748. }
  749. // Make a copy, we don't want to modify arguments
  750. options = $.extend( {}, options );
  751. var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
  752. // Make sure string options are treated as CSS selectors
  753. target = typeof options.of === "string" ?
  754. $( document ).find( options.of ) :
  755. $( options.of ),
  756. within = $.position.getWithinInfo( options.within ),
  757. scrollInfo = $.position.getScrollInfo( within ),
  758. collision = ( options.collision || "flip" ).split( " " ),
  759. offsets = {};
  760. dimensions = getDimensions( target );
  761. if ( target[ 0 ].preventDefault ) {
  762. // Force left top to allow flipping
  763. options.at = "left top";
  764. }
  765. targetWidth = dimensions.width;
  766. targetHeight = dimensions.height;
  767. targetOffset = dimensions.offset;
  768. // Clone to reuse original targetOffset later
  769. basePosition = $.extend( {}, targetOffset );
  770. // Force my and at to have valid horizontal and vertical positions
  771. // if a value is missing or invalid, it will be converted to center
  772. $.each( [ "my", "at" ], function() {
  773. var pos = ( options[ this ] || "" ).split( " " ),
  774. horizontalOffset,
  775. verticalOffset;
  776. if ( pos.length === 1 ) {
  777. pos = rhorizontal.test( pos[ 0 ] ) ?
  778. pos.concat( [ "center" ] ) :
  779. rvertical.test( pos[ 0 ] ) ?
  780. [ "center" ].concat( pos ) :
  781. [ "center", "center" ];
  782. }
  783. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  784. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  785. // Calculate offsets
  786. horizontalOffset = roffset.exec( pos[ 0 ] );
  787. verticalOffset = roffset.exec( pos[ 1 ] );
  788. offsets[ this ] = [
  789. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  790. verticalOffset ? verticalOffset[ 0 ] : 0
  791. ];
  792. // Reduce to just the positions without the offsets
  793. options[ this ] = [
  794. rposition.exec( pos[ 0 ] )[ 0 ],
  795. rposition.exec( pos[ 1 ] )[ 0 ]
  796. ];
  797. } );
  798. // Normalize collision option
  799. if ( collision.length === 1 ) {
  800. collision[ 1 ] = collision[ 0 ];
  801. }
  802. if ( options.at[ 0 ] === "right" ) {
  803. basePosition.left += targetWidth;
  804. } else if ( options.at[ 0 ] === "center" ) {
  805. basePosition.left += targetWidth / 2;
  806. }
  807. if ( options.at[ 1 ] === "bottom" ) {
  808. basePosition.top += targetHeight;
  809. } else if ( options.at[ 1 ] === "center" ) {
  810. basePosition.top += targetHeight / 2;
  811. }
  812. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  813. basePosition.left += atOffset[ 0 ];
  814. basePosition.top += atOffset[ 1 ];
  815. return this.each( function() {
  816. var collisionPosition, using,
  817. elem = $( this ),
  818. elemWidth = elem.outerWidth(),
  819. elemHeight = elem.outerHeight(),
  820. marginLeft = parseCss( this, "marginLeft" ),
  821. marginTop = parseCss( this, "marginTop" ),
  822. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) +
  823. scrollInfo.width,
  824. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) +
  825. scrollInfo.height,
  826. position = $.extend( {}, basePosition ),
  827. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  828. if ( options.my[ 0 ] === "right" ) {
  829. position.left -= elemWidth;
  830. } else if ( options.my[ 0 ] === "center" ) {
  831. position.left -= elemWidth / 2;
  832. }
  833. if ( options.my[ 1 ] === "bottom" ) {
  834. position.top -= elemHeight;
  835. } else if ( options.my[ 1 ] === "center" ) {
  836. position.top -= elemHeight / 2;
  837. }
  838. position.left += myOffset[ 0 ];
  839. position.top += myOffset[ 1 ];
  840. collisionPosition = {
  841. marginLeft: marginLeft,
  842. marginTop: marginTop
  843. };
  844. $.each( [ "left", "top" ], function( i, dir ) {
  845. if ( $.ui.position[ collision[ i ] ] ) {
  846. $.ui.position[ collision[ i ] ][ dir ]( position, {
  847. targetWidth: targetWidth,
  848. targetHeight: targetHeight,
  849. elemWidth: elemWidth,
  850. elemHeight: elemHeight,
  851. collisionPosition: collisionPosition,
  852. collisionWidth: collisionWidth,
  853. collisionHeight: collisionHeight,
  854. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  855. my: options.my,
  856. at: options.at,
  857. within: within,
  858. elem: elem
  859. } );
  860. }
  861. } );
  862. if ( options.using ) {
  863. // Adds feedback as second argument to using callback, if present
  864. using = function( props ) {
  865. var left = targetOffset.left - position.left,
  866. right = left + targetWidth - elemWidth,
  867. top = targetOffset.top - position.top,
  868. bottom = top + targetHeight - elemHeight,
  869. feedback = {
  870. target: {
  871. element: target,
  872. left: targetOffset.left,
  873. top: targetOffset.top,
  874. width: targetWidth,
  875. height: targetHeight
  876. },
  877. element: {
  878. element: elem,
  879. left: position.left,
  880. top: position.top,
  881. width: elemWidth,
  882. height: elemHeight
  883. },
  884. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  885. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  886. };
  887. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  888. feedback.horizontal = "center";
  889. }
  890. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  891. feedback.vertical = "middle";
  892. }
  893. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  894. feedback.important = "horizontal";
  895. } else {
  896. feedback.important = "vertical";
  897. }
  898. options.using.call( this, props, feedback );
  899. };
  900. }
  901. elem.offset( $.extend( position, { using: using } ) );
  902. } );
  903. };
  904. $.ui.position = {
  905. fit: {
  906. left: function( position, data ) {
  907. var within = data.within,
  908. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  909. outerWidth = within.width,
  910. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  911. overLeft = withinOffset - collisionPosLeft,
  912. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  913. newOverRight;
  914. // Element is wider than within
  915. if ( data.collisionWidth > outerWidth ) {
  916. // Element is initially over the left side of within
  917. if ( overLeft > 0 && overRight <= 0 ) {
  918. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth -
  919. withinOffset;
  920. position.left += overLeft - newOverRight;
  921. // Element is initially over right side of within
  922. } else if ( overRight > 0 && overLeft <= 0 ) {
  923. position.left = withinOffset;
  924. // Element is initially over both left and right sides of within
  925. } else {
  926. if ( overLeft > overRight ) {
  927. position.left = withinOffset + outerWidth - data.collisionWidth;
  928. } else {
  929. position.left = withinOffset;
  930. }
  931. }
  932. // Too far left -> align with left edge
  933. } else if ( overLeft > 0 ) {
  934. position.left += overLeft;
  935. // Too far right -> align with right edge
  936. } else if ( overRight > 0 ) {
  937. position.left -= overRight;
  938. // Adjust based on position and margin
  939. } else {
  940. position.left = max( position.left - collisionPosLeft, position.left );
  941. }
  942. },
  943. top: function( position, data ) {
  944. var within = data.within,
  945. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  946. outerHeight = data.within.height,
  947. collisionPosTop = position.top - data.collisionPosition.marginTop,
  948. overTop = withinOffset - collisionPosTop,
  949. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  950. newOverBottom;
  951. // Element is taller than within
  952. if ( data.collisionHeight > outerHeight ) {
  953. // Element is initially over the top of within
  954. if ( overTop > 0 && overBottom <= 0 ) {
  955. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight -
  956. withinOffset;
  957. position.top += overTop - newOverBottom;
  958. // Element is initially over bottom of within
  959. } else if ( overBottom > 0 && overTop <= 0 ) {
  960. position.top = withinOffset;
  961. // Element is initially over both top and bottom of within
  962. } else {
  963. if ( overTop > overBottom ) {
  964. position.top = withinOffset + outerHeight - data.collisionHeight;
  965. } else {
  966. position.top = withinOffset;
  967. }
  968. }
  969. // Too far up -> align with top
  970. } else if ( overTop > 0 ) {
  971. position.top += overTop;
  972. // Too far down -> align with bottom edge
  973. } else if ( overBottom > 0 ) {
  974. position.top -= overBottom;
  975. // Adjust based on position and margin
  976. } else {
  977. position.top = max( position.top - collisionPosTop, position.top );
  978. }
  979. }
  980. },
  981. flip: {
  982. left: function( position, data ) {
  983. var within = data.within,
  984. withinOffset = within.offset.left + within.scrollLeft,
  985. outerWidth = within.width,
  986. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  987. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  988. overLeft = collisionPosLeft - offsetLeft,
  989. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  990. myOffset = data.my[ 0 ] === "left" ?
  991. -data.elemWidth :
  992. data.my[ 0 ] === "right" ?
  993. data.elemWidth :
  994. 0,
  995. atOffset = data.at[ 0 ] === "left" ?
  996. data.targetWidth :
  997. data.at[ 0 ] === "right" ?
  998. -data.targetWidth :
  999. 0,
  1000. offset = -2 * data.offset[ 0 ],
  1001. newOverRight,
  1002. newOverLeft;
  1003. if ( overLeft < 0 ) {
  1004. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth -
  1005. outerWidth - withinOffset;
  1006. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  1007. position.left += myOffset + atOffset + offset;
  1008. }
  1009. } else if ( overRight > 0 ) {
  1010. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset +
  1011. atOffset + offset - offsetLeft;
  1012. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  1013. position.left += myOffset + atOffset + offset;
  1014. }
  1015. }
  1016. },
  1017. top: function( position, data ) {
  1018. var within = data.within,
  1019. withinOffset = within.offset.top + within.scrollTop,
  1020. outerHeight = within.height,
  1021. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  1022. collisionPosTop = position.top - data.collisionPosition.marginTop,
  1023. overTop = collisionPosTop - offsetTop,
  1024. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  1025. top = data.my[ 1 ] === "top",
  1026. myOffset = top ?
  1027. -data.elemHeight :
  1028. data.my[ 1 ] === "bottom" ?
  1029. data.elemHeight :
  1030. 0,
  1031. atOffset = data.at[ 1 ] === "top" ?
  1032. data.targetHeight :
  1033. data.at[ 1 ] === "bottom" ?
  1034. -data.targetHeight :
  1035. 0,
  1036. offset = -2 * data.offset[ 1 ],
  1037. newOverTop,
  1038. newOverBottom;
  1039. if ( overTop < 0 ) {
  1040. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight -
  1041. outerHeight - withinOffset;
  1042. if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) {
  1043. position.top += myOffset + atOffset + offset;
  1044. }
  1045. } else if ( overBottom > 0 ) {
  1046. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset +
  1047. offset - offsetTop;
  1048. if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) {
  1049. position.top += myOffset + atOffset + offset;
  1050. }
  1051. }
  1052. }
  1053. },
  1054. flipfit: {
  1055. left: function() {
  1056. $.ui.position.flip.left.apply( this, arguments );
  1057. $.ui.position.fit.left.apply( this, arguments );
  1058. },
  1059. top: function() {
  1060. $.ui.position.flip.top.apply( this, arguments );
  1061. $.ui.position.fit.top.apply( this, arguments );
  1062. }
  1063. }
  1064. };
  1065. } )();
  1066. var position = $.ui.position;
  1067. /*!
  1068. * jQuery UI Legacy jQuery Core patches 1.14.1
  1069. * https://jqueryui.com
  1070. *
  1071. * Copyright OpenJS Foundation and other contributors
  1072. * Released under the MIT license.
  1073. * https://jquery.org/license
  1074. *
  1075. */
  1076. //>>label: Legacy jQuery Core patches
  1077. //>>group: Core
  1078. //>>description: Backport `.even()`, `.odd()` and `$.escapeSelector` to older jQuery Core versions (deprecated)
  1079. // Support: jQuery 2.2.x or older.
  1080. // This method has been defined in jQuery 3.0.0.
  1081. // Code from https://github.com/jquery/jquery/blob/e539bac79e666bba95bba86d690b4e609dca2286/src/selector/escapeSelector.js
  1082. if ( !$.escapeSelector ) {
  1083. $.escapeSelector = function( id ) {
  1084. return CSS.escape( id + "" );
  1085. };
  1086. }
  1087. // Support: jQuery 3.4.x or older
  1088. // These methods have been defined in jQuery 3.5.0.
  1089. if ( !$.fn.even || !$.fn.odd ) {
  1090. $.fn.extend( {
  1091. even: function() {
  1092. return this.filter( function( i ) {
  1093. return i % 2 === 0;
  1094. } );
  1095. },
  1096. odd: function() {
  1097. return this.filter( function( i ) {
  1098. return i % 2 === 1;
  1099. } );
  1100. }
  1101. } );
  1102. }
  1103. ;
  1104. /*!
  1105. * jQuery UI Keycode 1.14.1
  1106. * https://jqueryui.com
  1107. *
  1108. * Copyright OpenJS Foundation and other contributors
  1109. * Released under the MIT license.
  1110. * https://jquery.org/license
  1111. */
  1112. //>>label: Keycode
  1113. //>>group: Core
  1114. //>>description: Provide keycodes as keynames
  1115. //>>docs: https://api.jqueryui.com/jQuery.ui.keyCode/
  1116. var keycode = $.ui.keyCode = {
  1117. BACKSPACE: 8,
  1118. COMMA: 188,
  1119. DELETE: 46,
  1120. DOWN: 40,
  1121. END: 35,
  1122. ENTER: 13,
  1123. ESCAPE: 27,
  1124. HOME: 36,
  1125. LEFT: 37,
  1126. PAGE_DOWN: 34,
  1127. PAGE_UP: 33,
  1128. PERIOD: 190,
  1129. RIGHT: 39,
  1130. SPACE: 32,
  1131. TAB: 9,
  1132. UP: 38
  1133. };
  1134. /*!
  1135. * jQuery UI Scroll Parent 1.14.1
  1136. * https://jqueryui.com
  1137. *
  1138. * Copyright OpenJS Foundation and other contributors
  1139. * Released under the MIT license.
  1140. * https://jquery.org/license
  1141. */
  1142. //>>label: scrollParent
  1143. //>>group: Core
  1144. //>>description: Get the closest ancestor element that is scrollable.
  1145. //>>docs: https://api.jqueryui.com/scrollParent/
  1146. var scrollParent = $.fn.scrollParent = function( includeHidden ) {
  1147. var position = this.css( "position" ),
  1148. excludeStaticParent = position === "absolute",
  1149. overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,
  1150. scrollParent = this.parents().filter( function() {
  1151. var parent = $( this );
  1152. if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
  1153. return false;
  1154. }
  1155. return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) +
  1156. parent.css( "overflow-x" ) );
  1157. } ).eq( 0 );
  1158. return position === "fixed" || !scrollParent.length ?
  1159. $( this[ 0 ].ownerDocument || document ) :
  1160. scrollParent;
  1161. };
  1162. /*!
  1163. * jQuery UI Unique ID 1.14.1
  1164. * https://jqueryui.com
  1165. *
  1166. * Copyright OpenJS Foundation and other contributors
  1167. * Released under the MIT license.
  1168. * https://jquery.org/license
  1169. */
  1170. //>>label: uniqueId
  1171. //>>group: Core
  1172. //>>description: Functions to generate and remove uniqueId's
  1173. //>>docs: https://api.jqueryui.com/uniqueId/
  1174. var uniqueId = $.fn.extend( {
  1175. uniqueId: ( function() {
  1176. var uuid = 0;
  1177. return function() {
  1178. return this.each( function() {
  1179. if ( !this.id ) {
  1180. this.id = "ui-id-" + ( ++uuid );
  1181. }
  1182. } );
  1183. };
  1184. } )(),
  1185. removeUniqueId: function() {
  1186. return this.each( function() {
  1187. if ( /^ui-id-\d+$/.test( this.id ) ) {
  1188. $( this ).removeAttr( "id" );
  1189. }
  1190. } );
  1191. }
  1192. } );
  1193. // NOTE: Original jQuery UI wrapper was replaced. See README-Fancytree.md
  1194. // }));
  1195. })(jQuery);
  1196. (function( factory ) {
  1197. if ( typeof define === "function" && define.amd ) {
  1198. // AMD. Register as an anonymous module.
  1199. define( [ "jquery" ], factory );
  1200. } else if ( typeof module === "object" && module.exports ) {
  1201. // Node/CommonJS
  1202. module.exports = factory(require("jquery"));
  1203. } else {
  1204. // Browser globals
  1205. factory( jQuery );
  1206. }
  1207. }(function( $ ) {
  1208. /*! Fancytree Core *//*!
  1209. * jquery.fancytree.js
  1210. * Tree view control with support for lazy loading and much more.
  1211. * https://github.com/mar10/fancytree/
  1212. *
  1213. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  1214. * Released under the MIT license
  1215. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  1216. *
  1217. * @version 2.38.5
  1218. * @date 2025-04-05T06:40:00Z
  1219. */
  1220. /** Core Fancytree module.
  1221. */
  1222. // UMD wrapper for the Fancytree core module
  1223. (function (factory) {
  1224. if (typeof define === "function" && define.amd) {
  1225. // AMD. Register as an anonymous module.
  1226. define(["jquery", "./jquery.fancytree.ui-deps"], factory);
  1227. } else if (typeof module === "object" && module.exports) {
  1228. // Node/CommonJS
  1229. require("./jquery.fancytree.ui-deps");
  1230. module.exports = factory(require("jquery"));
  1231. } else {
  1232. // Browser globals
  1233. factory(jQuery);
  1234. }
  1235. })(function ($) {
  1236. "use strict";
  1237. // prevent duplicate loading
  1238. if ($.ui && $.ui.fancytree) {
  1239. $.ui.fancytree.warn("Fancytree: ignored duplicate include");
  1240. return;
  1241. }
  1242. /******************************************************************************
  1243. * Private functions and variables
  1244. */
  1245. var i,
  1246. attr,
  1247. FT = null, // initialized below
  1248. TEST_IMG = new RegExp(/\.|\//), // strings are considered image urls if they contain '.' or '/'
  1249. REX_HTML = /[&<>"'/]/g, // Escape those characters
  1250. REX_TOOLTIP = /[<>"'/]/g, // Don't escape `&` in tooltips
  1251. RECURSIVE_REQUEST_ERROR = "$recursive_request",
  1252. INVALID_REQUEST_TARGET_ERROR = "$request_target_invalid",
  1253. ENTITY_MAP = {
  1254. "&": "&amp;",
  1255. "<": "&lt;",
  1256. ">": "&gt;",
  1257. '"': "&quot;",
  1258. "'": "&#39;",
  1259. "/": "&#x2F;",
  1260. },
  1261. IGNORE_KEYCODES = { 16: true, 17: true, 18: true },
  1262. SPECIAL_KEYCODES = {
  1263. 8: "backspace",
  1264. 9: "tab",
  1265. 10: "return",
  1266. 13: "return",
  1267. // 16: null, 17: null, 18: null, // ignore shift, ctrl, alt
  1268. 19: "pause",
  1269. 20: "capslock",
  1270. 27: "esc",
  1271. 32: "space",
  1272. 33: "pageup",
  1273. 34: "pagedown",
  1274. 35: "end",
  1275. 36: "home",
  1276. 37: "left",
  1277. 38: "up",
  1278. 39: "right",
  1279. 40: "down",
  1280. 45: "insert",
  1281. 46: "del",
  1282. 59: ";",
  1283. 61: "=",
  1284. // 91: null, 93: null, // ignore left and right meta
  1285. 96: "0",
  1286. 97: "1",
  1287. 98: "2",
  1288. 99: "3",
  1289. 100: "4",
  1290. 101: "5",
  1291. 102: "6",
  1292. 103: "7",
  1293. 104: "8",
  1294. 105: "9",
  1295. 106: "*",
  1296. 107: "+",
  1297. 109: "-",
  1298. 110: ".",
  1299. 111: "/",
  1300. 112: "f1",
  1301. 113: "f2",
  1302. 114: "f3",
  1303. 115: "f4",
  1304. 116: "f5",
  1305. 117: "f6",
  1306. 118: "f7",
  1307. 119: "f8",
  1308. 120: "f9",
  1309. 121: "f10",
  1310. 122: "f11",
  1311. 123: "f12",
  1312. 144: "numlock",
  1313. 145: "scroll",
  1314. 173: "-",
  1315. 186: ";",
  1316. 187: "=",
  1317. 188: ",",
  1318. 189: "-",
  1319. 190: ".",
  1320. 191: "/",
  1321. 192: "`",
  1322. 219: "[",
  1323. 220: "\\",
  1324. 221: "]",
  1325. 222: "'",
  1326. },
  1327. MODIFIERS = {
  1328. 16: "shift",
  1329. 17: "ctrl",
  1330. 18: "alt",
  1331. 91: "meta",
  1332. 93: "meta",
  1333. },
  1334. MOUSE_BUTTONS = { 0: "", 1: "left", 2: "middle", 3: "right" },
  1335. // Boolean attributes that can be set with equivalent class names in the LI tags
  1336. // Note: v2.23: checkbox and hideCheckbox are *not* in this list
  1337. CLASS_ATTRS =
  1338. "active expanded focus folder lazy radiogroup selected unselectable unselectableIgnore".split(
  1339. " "
  1340. ),
  1341. CLASS_ATTR_MAP = {},
  1342. // Top-level Fancytree attributes, that can be set by dict
  1343. TREE_ATTRS = "columns types".split(" "),
  1344. // TREE_ATTR_MAP = {},
  1345. // Top-level FancytreeNode attributes, that can be set by dict
  1346. NODE_ATTRS =
  1347. "checkbox expanded extraClasses folder icon iconTooltip key lazy partsel radiogroup refKey selected statusNodeType title tooltip type unselectable unselectableIgnore unselectableStatus".split(
  1348. " "
  1349. ),
  1350. NODE_ATTR_MAP = {},
  1351. // Mapping of lowercase -> real name (because HTML5 data-... attribute only supports lowercase)
  1352. NODE_ATTR_LOWERCASE_MAP = {},
  1353. // Attribute names that should NOT be added to node.data
  1354. NONE_NODE_DATA_MAP = {
  1355. active: true,
  1356. children: true,
  1357. data: true,
  1358. focus: true,
  1359. };
  1360. for (i = 0; i < CLASS_ATTRS.length; i++) {
  1361. CLASS_ATTR_MAP[CLASS_ATTRS[i]] = true;
  1362. }
  1363. for (i = 0; i < NODE_ATTRS.length; i++) {
  1364. attr = NODE_ATTRS[i];
  1365. NODE_ATTR_MAP[attr] = true;
  1366. if (attr !== attr.toLowerCase()) {
  1367. NODE_ATTR_LOWERCASE_MAP[attr.toLowerCase()] = attr;
  1368. }
  1369. }
  1370. // for(i=0; i<TREE_ATTRS.length; i++) {
  1371. // TREE_ATTR_MAP[TREE_ATTRS[i]] = true;
  1372. // }
  1373. function _assert(cond, msg) {
  1374. // TODO: see qunit.js extractStacktrace()
  1375. if (!cond) {
  1376. msg = msg ? ": " + msg : "";
  1377. msg = "Fancytree assertion failed" + msg;
  1378. // consoleApply("assert", [!!cond, msg]);
  1379. // #1041: Raised exceptions may not be visible in the browser
  1380. // console if inside promise chains, so we also print directly:
  1381. if ($.ui && $.ui.fancytree) {
  1382. $.ui.fancytree.error(msg);
  1383. }
  1384. // Throw exception:
  1385. $.error(msg);
  1386. }
  1387. }
  1388. function _hasProp(object, property) {
  1389. return Object.prototype.hasOwnProperty.call(object, property);
  1390. }
  1391. /* Replacement for the deprecated `jQuery.isFunction()`. */
  1392. function _isFunction(obj) {
  1393. return typeof obj === "function";
  1394. }
  1395. /* Replacement for the deprecated `jQuery.trim()`. */
  1396. function _trim(text) {
  1397. return text == null ? "" : text.trim();
  1398. }
  1399. /* Replacement for the deprecated `jQuery.isArray()`. */
  1400. var _isArray = Array.isArray;
  1401. _assert($.ui, "Fancytree requires jQuery UI (http://jqueryui.com)");
  1402. function consoleApply(method, args) {
  1403. var i,
  1404. s,
  1405. fn = window.console ? window.console[method] : null;
  1406. if (fn) {
  1407. try {
  1408. fn.apply(window.console, args);
  1409. } catch (e) {
  1410. // IE 8?
  1411. s = "";
  1412. for (i = 0; i < args.length; i++) {
  1413. s += args[i];
  1414. }
  1415. fn(s);
  1416. }
  1417. }
  1418. }
  1419. /* support: IE8 Polyfil for Date.now() */
  1420. if (!Date.now) {
  1421. Date.now = function now() {
  1422. return new Date().getTime();
  1423. };
  1424. }
  1425. /*Return true if x is a FancytreeNode.*/
  1426. function _isNode(x) {
  1427. return !!(x.tree && x.statusNodeType !== undefined);
  1428. }
  1429. /** Return true if dotted version string is equal or higher than requested version.
  1430. *
  1431. * See http://jsfiddle.net/mar10/FjSAN/
  1432. */
  1433. function isVersionAtLeast(dottedVersion, major, minor, patch) {
  1434. var i,
  1435. v,
  1436. t,
  1437. verParts = $.map(_trim(dottedVersion).split("."), function (e) {
  1438. return parseInt(e, 10);
  1439. }),
  1440. testParts = $.map(
  1441. Array.prototype.slice.call(arguments, 1),
  1442. function (e) {
  1443. return parseInt(e, 10);
  1444. }
  1445. );
  1446. for (i = 0; i < testParts.length; i++) {
  1447. v = verParts[i] || 0;
  1448. t = testParts[i] || 0;
  1449. if (v !== t) {
  1450. return v > t;
  1451. }
  1452. }
  1453. return true;
  1454. }
  1455. /**
  1456. * Deep-merge a list of objects (but replace array-type options).
  1457. *
  1458. * jQuery's $.extend(true, ...) method does a deep merge, that also merges Arrays.
  1459. * This variant is used to merge extension defaults with user options, and should
  1460. * merge objects, but override arrays (for example the `triggerStart: [...]` option
  1461. * of ext-edit). Also `null` values are copied over and not skipped.
  1462. *
  1463. * See issue #876
  1464. *
  1465. * Example:
  1466. * _simpleDeepMerge({}, o1, o2);
  1467. */
  1468. function _simpleDeepMerge() {
  1469. var options,
  1470. name,
  1471. src,
  1472. copy,
  1473. clone,
  1474. target = arguments[0] || {},
  1475. i = 1,
  1476. length = arguments.length;
  1477. // Handle case when target is a string or something (possible in deep copy)
  1478. if (typeof target !== "object" && !_isFunction(target)) {
  1479. target = {};
  1480. }
  1481. if (i === length) {
  1482. throw Error("need at least two args");
  1483. }
  1484. for (; i < length; i++) {
  1485. // Only deal with non-null/undefined values
  1486. if ((options = arguments[i]) != null) {
  1487. // Extend the base object
  1488. for (name in options) {
  1489. if (_hasProp(options, name)) {
  1490. src = target[name];
  1491. copy = options[name];
  1492. // Prevent never-ending loop
  1493. if (target === copy) {
  1494. continue;
  1495. }
  1496. // Recurse if we're merging plain objects
  1497. // (NOTE: unlike $.extend, we don't merge arrays, but replace them)
  1498. if (copy && $.isPlainObject(copy)) {
  1499. clone = src && $.isPlainObject(src) ? src : {};
  1500. // Never move original objects, clone them
  1501. target[name] = _simpleDeepMerge(clone, copy);
  1502. // Don't bring in undefined values
  1503. } else if (copy !== undefined) {
  1504. target[name] = copy;
  1505. }
  1506. }
  1507. }
  1508. }
  1509. }
  1510. // Return the modified object
  1511. return target;
  1512. }
  1513. /** Return a wrapper that calls sub.methodName() and exposes
  1514. * this : tree
  1515. * this._local : tree.ext.EXTNAME
  1516. * this._super : base.methodName.call()
  1517. * this._superApply : base.methodName.apply()
  1518. */
  1519. function _makeVirtualFunction(methodName, tree, base, extension, extName) {
  1520. // $.ui.fancytree.debug("_makeVirtualFunction", methodName, tree, base, extension, extName);
  1521. // if(rexTestSuper && !rexTestSuper.test(func)){
  1522. // // extension.methodName() doesn't call _super(), so no wrapper required
  1523. // return func;
  1524. // }
  1525. // Use an immediate function as closure
  1526. var proxy = (function () {
  1527. var prevFunc = tree[methodName], // org. tree method or prev. proxy
  1528. baseFunc = extension[methodName], //
  1529. _local = tree.ext[extName],
  1530. _super = function () {
  1531. return prevFunc.apply(tree, arguments);
  1532. },
  1533. _superApply = function (args) {
  1534. return prevFunc.apply(tree, args);
  1535. };
  1536. // Return the wrapper function
  1537. return function () {
  1538. var prevLocal = tree._local,
  1539. prevSuper = tree._super,
  1540. prevSuperApply = tree._superApply;
  1541. try {
  1542. tree._local = _local;
  1543. tree._super = _super;
  1544. tree._superApply = _superApply;
  1545. return baseFunc.apply(tree, arguments);
  1546. } finally {
  1547. tree._local = prevLocal;
  1548. tree._super = prevSuper;
  1549. tree._superApply = prevSuperApply;
  1550. }
  1551. };
  1552. })(); // end of Immediate Function
  1553. return proxy;
  1554. }
  1555. /**
  1556. * Subclass `base` by creating proxy functions
  1557. */
  1558. function _subclassObject(tree, base, extension, extName) {
  1559. // $.ui.fancytree.debug("_subclassObject", tree, base, extension, extName);
  1560. for (var attrName in extension) {
  1561. if (typeof extension[attrName] === "function") {
  1562. if (typeof tree[attrName] === "function") {
  1563. // override existing method
  1564. tree[attrName] = _makeVirtualFunction(
  1565. attrName,
  1566. tree,
  1567. base,
  1568. extension,
  1569. extName
  1570. );
  1571. } else if (attrName.charAt(0) === "_") {
  1572. // Create private methods in tree.ext.EXTENSION namespace
  1573. tree.ext[extName][attrName] = _makeVirtualFunction(
  1574. attrName,
  1575. tree,
  1576. base,
  1577. extension,
  1578. extName
  1579. );
  1580. } else {
  1581. $.error(
  1582. "Could not override tree." +
  1583. attrName +
  1584. ". Use prefix '_' to create tree." +
  1585. extName +
  1586. "._" +
  1587. attrName
  1588. );
  1589. }
  1590. } else {
  1591. // Create member variables in tree.ext.EXTENSION namespace
  1592. if (attrName !== "options") {
  1593. tree.ext[extName][attrName] = extension[attrName];
  1594. }
  1595. }
  1596. }
  1597. }
  1598. function _getResolvedPromise(context, argArray) {
  1599. if (context === undefined) {
  1600. return $.Deferred(function () {
  1601. this.resolve();
  1602. }).promise();
  1603. }
  1604. return $.Deferred(function () {
  1605. this.resolveWith(context, argArray);
  1606. }).promise();
  1607. }
  1608. function _getRejectedPromise(context, argArray) {
  1609. if (context === undefined) {
  1610. return $.Deferred(function () {
  1611. this.reject();
  1612. }).promise();
  1613. }
  1614. return $.Deferred(function () {
  1615. this.rejectWith(context, argArray);
  1616. }).promise();
  1617. }
  1618. function _makeResolveFunc(deferred, context) {
  1619. return function () {
  1620. deferred.resolveWith(context);
  1621. };
  1622. }
  1623. function _getElementDataAsDict($el) {
  1624. // Evaluate 'data-NAME' attributes with special treatment for 'data-json'.
  1625. var d = $.extend({}, $el.data()),
  1626. json = d.json;
  1627. delete d.fancytree; // added to container by widget factory (old jQuery UI)
  1628. delete d.uiFancytree; // added to container by widget factory
  1629. if (json) {
  1630. delete d.json;
  1631. // <li data-json='...'> is already returned as object (http://api.jquery.com/data/#data-html5)
  1632. d = $.extend(d, json);
  1633. }
  1634. return d;
  1635. }
  1636. function _escapeTooltip(s) {
  1637. return ("" + s).replace(REX_TOOLTIP, function (s) {
  1638. return ENTITY_MAP[s];
  1639. });
  1640. }
  1641. // TODO: use currying
  1642. function _makeNodeTitleMatcher(s) {
  1643. s = s.toLowerCase();
  1644. return function (node) {
  1645. return node.title.toLowerCase().indexOf(s) >= 0;
  1646. };
  1647. }
  1648. function _makeNodeTitleStartMatcher(s) {
  1649. var reMatch = new RegExp("^" + s, "i");
  1650. return function (node) {
  1651. return reMatch.test(node.title);
  1652. };
  1653. }
  1654. /******************************************************************************
  1655. * FancytreeNode
  1656. */
  1657. /**
  1658. * Creates a new FancytreeNode
  1659. *
  1660. * @class FancytreeNode
  1661. * @classdesc A FancytreeNode represents the hierarchical data model and operations.
  1662. *
  1663. * @param {FancytreeNode} parent
  1664. * @param {NodeData} obj
  1665. *
  1666. * @property {Fancytree} tree The tree instance
  1667. * @property {FancytreeNode} parent The parent node
  1668. * @property {string} key Node id (must be unique inside the tree)
  1669. * @property {string} title Display name (may contain HTML)
  1670. * @property {object} data Contains all extra data that was passed on node creation
  1671. * @property {FancytreeNode[] | null | undefined} children Array of child nodes.<br>
  1672. * For lazy nodes, null or undefined means 'not yet loaded'. Use an empty array
  1673. * to define a node that has no children.
  1674. * @property {boolean} expanded Use isExpanded(), setExpanded() to access this property.
  1675. * @property {string} extraClasses Additional CSS classes, added to the node's `<span>`.<br>
  1676. * Note: use `node.add/remove/toggleClass()` to modify.
  1677. * @property {boolean} folder Folder nodes have different default icons and click behavior.<br>
  1678. * Note: Also non-folders may have children.
  1679. * @property {string} statusNodeType null for standard nodes. Otherwise type of special system node: 'error', 'loading', 'nodata', or 'paging'.
  1680. * @property {boolean} lazy True if this node is loaded on demand, i.e. on first expansion.
  1681. * @property {boolean} selected Use isSelected(), setSelected() to access this property.
  1682. * @property {string} tooltip Alternative description used as hover popup
  1683. * @property {string} iconTooltip Description used as hover popup for icon. @since 2.27
  1684. * @property {string} type Node type, used with tree.types map. @since 2.27
  1685. */
  1686. function FancytreeNode(parent, obj) {
  1687. var i, l, name, cl;
  1688. this.parent = parent;
  1689. this.tree = parent.tree;
  1690. this.ul = null;
  1691. this.li = null; // <li id='key' ftnode=this> tag
  1692. this.statusNodeType = null; // if this is a temp. node to display the status of its parent
  1693. this._isLoading = false; // if this node itself is loading
  1694. this._error = null; // {message: '...'} if a load error occurred
  1695. this.data = {};
  1696. // TODO: merge this code with node.toDict()
  1697. // copy attributes from obj object
  1698. for (i = 0, l = NODE_ATTRS.length; i < l; i++) {
  1699. name = NODE_ATTRS[i];
  1700. this[name] = obj[name];
  1701. }
  1702. // unselectableIgnore and unselectableStatus imply unselectable
  1703. if (
  1704. this.unselectableIgnore != null ||
  1705. this.unselectableStatus != null
  1706. ) {
  1707. this.unselectable = true;
  1708. }
  1709. if (obj.hideCheckbox) {
  1710. $.error(
  1711. "'hideCheckbox' node option was removed in v2.23.0: use 'checkbox: false'"
  1712. );
  1713. }
  1714. // node.data += obj.data
  1715. if (obj.data) {
  1716. $.extend(this.data, obj.data);
  1717. }
  1718. // Copy all other attributes to this.data.NAME
  1719. for (name in obj) {
  1720. if (
  1721. !NODE_ATTR_MAP[name] &&
  1722. (this.tree.options.copyFunctionsToData ||
  1723. !_isFunction(obj[name])) &&
  1724. !NONE_NODE_DATA_MAP[name]
  1725. ) {
  1726. // node.data.NAME = obj.NAME
  1727. this.data[name] = obj[name];
  1728. }
  1729. }
  1730. // Fix missing key
  1731. if (this.key == null) {
  1732. // test for null OR undefined
  1733. if (this.tree.options.defaultKey) {
  1734. this.key = "" + this.tree.options.defaultKey(this);
  1735. _assert(this.key, "defaultKey() must return a unique key");
  1736. } else {
  1737. this.key = "_" + FT._nextNodeKey++;
  1738. }
  1739. } else {
  1740. this.key = "" + this.key; // Convert to string (#217)
  1741. }
  1742. // Fix tree.activeNode
  1743. // TODO: not elegant: we use obj.active as marker to set tree.activeNode
  1744. // when loading from a dictionary.
  1745. if (obj.active) {
  1746. _assert(
  1747. this.tree.activeNode === null,
  1748. "only one active node allowed"
  1749. );
  1750. this.tree.activeNode = this;
  1751. }
  1752. if (obj.selected) {
  1753. // #186
  1754. this.tree.lastSelectedNode = this;
  1755. }
  1756. // TODO: handle obj.focus = true
  1757. // Create child nodes
  1758. cl = obj.children;
  1759. if (cl) {
  1760. if (cl.length) {
  1761. this._setChildren(cl);
  1762. } else {
  1763. // if an empty array was passed for a lazy node, keep it, in order to mark it 'loaded'
  1764. this.children = this.lazy ? [] : null;
  1765. }
  1766. } else {
  1767. this.children = null;
  1768. }
  1769. // Add to key/ref map (except for root node)
  1770. // if( parent ) {
  1771. this.tree._callHook("treeRegisterNode", this.tree, true, this);
  1772. // }
  1773. }
  1774. FancytreeNode.prototype = /** @lends FancytreeNode# */ {
  1775. /* Return the direct child FancytreeNode with a given key, index. */
  1776. _findDirectChild: function (ptr) {
  1777. var i,
  1778. l,
  1779. cl = this.children;
  1780. if (cl) {
  1781. if (typeof ptr === "string") {
  1782. for (i = 0, l = cl.length; i < l; i++) {
  1783. if (cl[i].key === ptr) {
  1784. return cl[i];
  1785. }
  1786. }
  1787. } else if (typeof ptr === "number") {
  1788. return this.children[ptr];
  1789. } else if (ptr.parent === this) {
  1790. return ptr;
  1791. }
  1792. }
  1793. return null;
  1794. },
  1795. // TODO: activate()
  1796. // TODO: activateSilently()
  1797. /* Internal helper called in recursive addChildren sequence.*/
  1798. _setChildren: function (children) {
  1799. _assert(
  1800. children && (!this.children || this.children.length === 0),
  1801. "only init supported"
  1802. );
  1803. this.children = [];
  1804. for (var i = 0, l = children.length; i < l; i++) {
  1805. this.children.push(new FancytreeNode(this, children[i]));
  1806. }
  1807. this.tree._callHook(
  1808. "treeStructureChanged",
  1809. this.tree,
  1810. "setChildren"
  1811. );
  1812. },
  1813. /**
  1814. * Append (or insert) a list of child nodes.
  1815. *
  1816. * @param {NodeData[]} children array of child node definitions (also single child accepted)
  1817. * @param {FancytreeNode | string | Integer} [insertBefore] child node (or key or index of such).
  1818. * If omitted, the new children are appended.
  1819. * @returns {FancytreeNode} first child added
  1820. *
  1821. * @see FancytreeNode#applyPatch
  1822. */
  1823. addChildren: function (children, insertBefore) {
  1824. var i,
  1825. l,
  1826. pos,
  1827. origFirstChild = this.getFirstChild(),
  1828. origLastChild = this.getLastChild(),
  1829. firstNode = null,
  1830. nodeList = [];
  1831. if ($.isPlainObject(children)) {
  1832. children = [children];
  1833. }
  1834. if (!this.children) {
  1835. this.children = [];
  1836. }
  1837. for (i = 0, l = children.length; i < l; i++) {
  1838. nodeList.push(new FancytreeNode(this, children[i]));
  1839. }
  1840. firstNode = nodeList[0];
  1841. if (insertBefore == null) {
  1842. this.children = this.children.concat(nodeList);
  1843. } else {
  1844. // Returns null if insertBefore is not a direct child:
  1845. insertBefore = this._findDirectChild(insertBefore);
  1846. pos = $.inArray(insertBefore, this.children);
  1847. _assert(pos >= 0, "insertBefore must be an existing child");
  1848. // insert nodeList after children[pos]
  1849. this.children.splice.apply(
  1850. this.children,
  1851. [pos, 0].concat(nodeList)
  1852. );
  1853. }
  1854. if (origFirstChild && !insertBefore) {
  1855. // #708: Fast path -- don't render every child of root, just the new ones!
  1856. // #723, #729: but only if it's appended to an existing child list
  1857. for (i = 0, l = nodeList.length; i < l; i++) {
  1858. nodeList[i].render(); // New nodes were never rendered before
  1859. }
  1860. // Adjust classes where status may have changed
  1861. // Has a first child
  1862. if (origFirstChild !== this.getFirstChild()) {
  1863. // Different first child -- recompute classes
  1864. origFirstChild.renderStatus();
  1865. }
  1866. if (origLastChild !== this.getLastChild()) {
  1867. // Different last child -- recompute classes
  1868. origLastChild.renderStatus();
  1869. }
  1870. } else if (!this.parent || this.parent.ul || this.tr) {
  1871. // render if the parent was rendered (or this is a root node)
  1872. this.render();
  1873. }
  1874. if (this.tree.options.selectMode === 3) {
  1875. this.fixSelection3FromEndNodes();
  1876. }
  1877. this.triggerModifyChild(
  1878. "add",
  1879. nodeList.length === 1 ? nodeList[0] : null
  1880. );
  1881. return firstNode;
  1882. },
  1883. /**
  1884. * Add class to node's span tag and to .extraClasses.
  1885. *
  1886. * @param {string} className class name
  1887. *
  1888. * @since 2.17
  1889. */
  1890. addClass: function (className) {
  1891. return this.toggleClass(className, true);
  1892. },
  1893. /**
  1894. * Append or prepend a node, or append a child node.
  1895. *
  1896. * This a convenience function that calls addChildren()
  1897. *
  1898. * @param {NodeData} node node definition
  1899. * @param {string} [mode=child] 'before', 'after', 'firstChild', or 'child' ('over' is a synonym for 'child')
  1900. * @returns {FancytreeNode} new node
  1901. */
  1902. addNode: function (node, mode) {
  1903. if (mode === undefined || mode === "over") {
  1904. mode = "child";
  1905. }
  1906. switch (mode) {
  1907. case "after":
  1908. return this.getParent().addChildren(
  1909. node,
  1910. this.getNextSibling()
  1911. );
  1912. case "before":
  1913. return this.getParent().addChildren(node, this);
  1914. case "firstChild":
  1915. // Insert before the first child if any
  1916. var insertBefore = this.children ? this.children[0] : null;
  1917. return this.addChildren(node, insertBefore);
  1918. case "child":
  1919. case "over":
  1920. return this.addChildren(node);
  1921. }
  1922. _assert(false, "Invalid mode: " + mode);
  1923. },
  1924. /**Add child status nodes that indicate 'More...', etc.
  1925. *
  1926. * This also maintains the node's `partload` property.
  1927. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  1928. * @param {string} [mode='child'] 'child'|firstChild'
  1929. * @since 2.15
  1930. */
  1931. addPagingNode: function (node, mode) {
  1932. var i, n;
  1933. mode = mode || "child";
  1934. if (node === false) {
  1935. for (i = this.children.length - 1; i >= 0; i--) {
  1936. n = this.children[i];
  1937. if (n.statusNodeType === "paging") {
  1938. this.removeChild(n);
  1939. }
  1940. }
  1941. this.partload = false;
  1942. return;
  1943. }
  1944. node = $.extend(
  1945. {
  1946. title: this.tree.options.strings.moreData,
  1947. statusNodeType: "paging",
  1948. icon: false,
  1949. },
  1950. node
  1951. );
  1952. this.partload = true;
  1953. return this.addNode(node, mode);
  1954. },
  1955. /**
  1956. * Append new node after this.
  1957. *
  1958. * This a convenience function that calls addNode(node, 'after')
  1959. *
  1960. * @param {NodeData} node node definition
  1961. * @returns {FancytreeNode} new node
  1962. */
  1963. appendSibling: function (node) {
  1964. return this.addNode(node, "after");
  1965. },
  1966. /**
  1967. * (experimental) Apply a modification (or navigation) operation.
  1968. *
  1969. * @param {string} cmd
  1970. * @param {object} [opts]
  1971. * @see Fancytree#applyCommand
  1972. * @since 2.32
  1973. */
  1974. applyCommand: function (cmd, opts) {
  1975. return this.tree.applyCommand(cmd, this, opts);
  1976. },
  1977. /**
  1978. * Modify existing child nodes.
  1979. *
  1980. * @param {NodePatch} patch
  1981. * @returns {$.Promise}
  1982. * @see FancytreeNode#addChildren
  1983. */
  1984. applyPatch: function (patch) {
  1985. // patch [key, null] means 'remove'
  1986. if (patch === null) {
  1987. this.remove();
  1988. return _getResolvedPromise(this);
  1989. }
  1990. // TODO: make sure that root node is not collapsed or modified
  1991. // copy (most) attributes to node.ATTR or node.data.ATTR
  1992. var name,
  1993. promise,
  1994. v,
  1995. IGNORE_MAP = { children: true, expanded: true, parent: true }; // TODO: should be global
  1996. for (name in patch) {
  1997. if (_hasProp(patch, name)) {
  1998. v = patch[name];
  1999. if (!IGNORE_MAP[name] && !_isFunction(v)) {
  2000. if (NODE_ATTR_MAP[name]) {
  2001. this[name] = v;
  2002. } else {
  2003. this.data[name] = v;
  2004. }
  2005. }
  2006. }
  2007. }
  2008. // Remove and/or create children
  2009. if (_hasProp(patch, "children")) {
  2010. this.removeChildren();
  2011. if (patch.children) {
  2012. // only if not null and not empty list
  2013. // TODO: addChildren instead?
  2014. this._setChildren(patch.children);
  2015. }
  2016. // TODO: how can we APPEND or INSERT child nodes?
  2017. }
  2018. if (this.isVisible()) {
  2019. this.renderTitle();
  2020. this.renderStatus();
  2021. }
  2022. // Expand collapse (final step, since this may be async)
  2023. if (_hasProp(patch, "expanded")) {
  2024. promise = this.setExpanded(patch.expanded);
  2025. } else {
  2026. promise = _getResolvedPromise(this);
  2027. }
  2028. return promise;
  2029. },
  2030. /** Collapse all sibling nodes.
  2031. * @returns {$.Promise}
  2032. */
  2033. collapseSiblings: function () {
  2034. return this.tree._callHook("nodeCollapseSiblings", this);
  2035. },
  2036. /** Copy this node as sibling or child of `node`.
  2037. *
  2038. * @param {FancytreeNode} node source node
  2039. * @param {string} [mode=child] 'before' | 'after' | 'child'
  2040. * @param {Function} [map] callback function(NodeData, FancytreeNode) that could modify the new node
  2041. * @returns {FancytreeNode} new
  2042. */
  2043. copyTo: function (node, mode, map) {
  2044. return node.addNode(this.toDict(true, map), mode);
  2045. },
  2046. /** Count direct and indirect children.
  2047. *
  2048. * @param {boolean} [deep=true] pass 'false' to only count direct children
  2049. * @returns {int} number of child nodes
  2050. */
  2051. countChildren: function (deep) {
  2052. var cl = this.children,
  2053. i,
  2054. l,
  2055. n;
  2056. if (!cl) {
  2057. return 0;
  2058. }
  2059. n = cl.length;
  2060. if (deep !== false) {
  2061. for (i = 0, l = n; i < l; i++) {
  2062. n += cl[i].countChildren();
  2063. }
  2064. }
  2065. return n;
  2066. },
  2067. // TODO: deactivate()
  2068. /** Write to browser console if debugLevel >= 4 (prepending node info)
  2069. *
  2070. * @param {*} msg string or object or array of such
  2071. */
  2072. debug: function (msg) {
  2073. if (this.tree.options.debugLevel >= 4) {
  2074. Array.prototype.unshift.call(arguments, this.toString());
  2075. consoleApply("log", arguments);
  2076. }
  2077. },
  2078. /** Deprecated.
  2079. * @deprecated since 2014-02-16. Use resetLazy() instead.
  2080. */
  2081. discard: function () {
  2082. this.warn(
  2083. "FancytreeNode.discard() is deprecated since 2014-02-16. Use .resetLazy() instead."
  2084. );
  2085. return this.resetLazy();
  2086. },
  2087. /** Remove DOM elements for all descendents. May be called on .collapse event
  2088. * to keep the DOM small.
  2089. * @param {boolean} [includeSelf=false]
  2090. */
  2091. discardMarkup: function (includeSelf) {
  2092. var fn = includeSelf ? "nodeRemoveMarkup" : "nodeRemoveChildMarkup";
  2093. this.tree._callHook(fn, this);
  2094. },
  2095. /** Write error to browser console if debugLevel >= 1 (prepending tree info)
  2096. *
  2097. * @param {*} msg string or object or array of such
  2098. */
  2099. error: function (msg) {
  2100. if (this.tree.options.debugLevel >= 1) {
  2101. Array.prototype.unshift.call(arguments, this.toString());
  2102. consoleApply("error", arguments);
  2103. }
  2104. },
  2105. /**Find all nodes that match condition (excluding self).
  2106. *
  2107. * @param {string | function(node)} match title string to search for, or a
  2108. * callback function that returns `true` if a node is matched.
  2109. * @returns {FancytreeNode[]} array of nodes (may be empty)
  2110. */
  2111. findAll: function (match) {
  2112. match = _isFunction(match) ? match : _makeNodeTitleMatcher(match);
  2113. var res = [];
  2114. this.visit(function (n) {
  2115. if (match(n)) {
  2116. res.push(n);
  2117. }
  2118. });
  2119. return res;
  2120. },
  2121. /**Find first node that matches condition (excluding self).
  2122. *
  2123. * @param {string | function(node)} match title string to search for, or a
  2124. * callback function that returns `true` if a node is matched.
  2125. * @returns {FancytreeNode} matching node or null
  2126. * @see FancytreeNode#findAll
  2127. */
  2128. findFirst: function (match) {
  2129. match = _isFunction(match) ? match : _makeNodeTitleMatcher(match);
  2130. var res = null;
  2131. this.visit(function (n) {
  2132. if (match(n)) {
  2133. res = n;
  2134. return false;
  2135. }
  2136. });
  2137. return res;
  2138. },
  2139. /** Find a node relative to self.
  2140. *
  2141. * @param {number|string} where The keyCode that would normally trigger this move,
  2142. * or a keyword ('down', 'first', 'last', 'left', 'parent', 'right', 'up').
  2143. * @returns {FancytreeNode}
  2144. * @since v2.31
  2145. */
  2146. findRelatedNode: function (where, includeHidden) {
  2147. return this.tree.findRelatedNode(this, where, includeHidden);
  2148. },
  2149. /* Apply selection state (internal use only) */
  2150. _changeSelectStatusAttrs: function (state) {
  2151. var changed = false,
  2152. opts = this.tree.options,
  2153. unselectable = FT.evalOption(
  2154. "unselectable",
  2155. this,
  2156. this,
  2157. opts,
  2158. false
  2159. ),
  2160. unselectableStatus = FT.evalOption(
  2161. "unselectableStatus",
  2162. this,
  2163. this,
  2164. opts,
  2165. undefined
  2166. );
  2167. if (unselectable && unselectableStatus != null) {
  2168. state = unselectableStatus;
  2169. }
  2170. switch (state) {
  2171. case false:
  2172. changed = this.selected || this.partsel;
  2173. this.selected = false;
  2174. this.partsel = false;
  2175. break;
  2176. case true:
  2177. changed = !this.selected || !this.partsel;
  2178. this.selected = true;
  2179. this.partsel = true;
  2180. break;
  2181. case undefined:
  2182. changed = this.selected || !this.partsel;
  2183. this.selected = false;
  2184. this.partsel = true;
  2185. break;
  2186. default:
  2187. _assert(false, "invalid state: " + state);
  2188. }
  2189. // this.debug("fixSelection3AfterLoad() _changeSelectStatusAttrs()", state, changed);
  2190. if (changed) {
  2191. this.renderStatus();
  2192. }
  2193. return changed;
  2194. },
  2195. /**
  2196. * Fix selection status, after this node was (de)selected in multi-hier mode.
  2197. * This includes (de)selecting all children.
  2198. */
  2199. fixSelection3AfterClick: function (callOpts) {
  2200. var flag = this.isSelected();
  2201. // this.debug("fixSelection3AfterClick()");
  2202. this.visit(function (node) {
  2203. node._changeSelectStatusAttrs(flag);
  2204. if (node.radiogroup) {
  2205. // #931: don't (de)select this branch
  2206. return "skip";
  2207. }
  2208. });
  2209. this.fixSelection3FromEndNodes(callOpts);
  2210. },
  2211. /**
  2212. * Fix selection status for multi-hier mode.
  2213. * Only end-nodes are considered to update the descendants branch and parents.
  2214. * Should be called after this node has loaded new children or after
  2215. * children have been modified using the API.
  2216. */
  2217. fixSelection3FromEndNodes: function (callOpts) {
  2218. var opts = this.tree.options;
  2219. // this.debug("fixSelection3FromEndNodes()");
  2220. _assert(opts.selectMode === 3, "expected selectMode 3");
  2221. // Visit all end nodes and adjust their parent's `selected` and `partsel`
  2222. // attributes. Return selection state true, false, or undefined.
  2223. function _walk(node) {
  2224. var i,
  2225. l,
  2226. child,
  2227. s,
  2228. state,
  2229. allSelected,
  2230. someSelected,
  2231. unselIgnore,
  2232. unselState,
  2233. children = node.children;
  2234. if (children && children.length) {
  2235. // check all children recursively
  2236. allSelected = true;
  2237. someSelected = false;
  2238. for (i = 0, l = children.length; i < l; i++) {
  2239. child = children[i];
  2240. // the selection state of a node is not relevant; we need the end-nodes
  2241. s = _walk(child);
  2242. // if( !child.unselectableIgnore ) {
  2243. unselIgnore = FT.evalOption(
  2244. "unselectableIgnore",
  2245. child,
  2246. child,
  2247. opts,
  2248. false
  2249. );
  2250. if (!unselIgnore) {
  2251. if (s !== false) {
  2252. someSelected = true;
  2253. }
  2254. if (s !== true) {
  2255. allSelected = false;
  2256. }
  2257. }
  2258. }
  2259. // eslint-disable-next-line no-nested-ternary
  2260. state = allSelected
  2261. ? true
  2262. : someSelected
  2263. ? undefined
  2264. : false;
  2265. } else {
  2266. // This is an end-node: simply report the status
  2267. unselState = FT.evalOption(
  2268. "unselectableStatus",
  2269. node,
  2270. node,
  2271. opts,
  2272. undefined
  2273. );
  2274. state = unselState == null ? !!node.selected : !!unselState;
  2275. }
  2276. // #939: Keep a `partsel` flag that was explicitly set on a lazy node
  2277. if (
  2278. node.partsel &&
  2279. !node.selected &&
  2280. node.lazy &&
  2281. node.children == null
  2282. ) {
  2283. state = undefined;
  2284. }
  2285. node._changeSelectStatusAttrs(state);
  2286. return state;
  2287. }
  2288. _walk(this);
  2289. // Update parent's state
  2290. this.visitParents(function (node) {
  2291. var i,
  2292. l,
  2293. child,
  2294. state,
  2295. unselIgnore,
  2296. unselState,
  2297. children = node.children,
  2298. allSelected = true,
  2299. someSelected = false;
  2300. for (i = 0, l = children.length; i < l; i++) {
  2301. child = children[i];
  2302. unselIgnore = FT.evalOption(
  2303. "unselectableIgnore",
  2304. child,
  2305. child,
  2306. opts,
  2307. false
  2308. );
  2309. if (!unselIgnore) {
  2310. unselState = FT.evalOption(
  2311. "unselectableStatus",
  2312. child,
  2313. child,
  2314. opts,
  2315. undefined
  2316. );
  2317. state =
  2318. unselState == null
  2319. ? !!child.selected
  2320. : !!unselState;
  2321. // When fixing the parents, we trust the sibling status (i.e.
  2322. // we don't recurse)
  2323. if (state || child.partsel) {
  2324. someSelected = true;
  2325. }
  2326. if (!state) {
  2327. allSelected = false;
  2328. }
  2329. }
  2330. }
  2331. // eslint-disable-next-line no-nested-ternary
  2332. state = allSelected ? true : someSelected ? undefined : false;
  2333. node._changeSelectStatusAttrs(state);
  2334. });
  2335. },
  2336. // TODO: focus()
  2337. /**
  2338. * Update node data. If dict contains 'children', then also replace
  2339. * the hole sub tree.
  2340. * @param {NodeData} dict
  2341. *
  2342. * @see FancytreeNode#addChildren
  2343. * @see FancytreeNode#applyPatch
  2344. */
  2345. fromDict: function (dict) {
  2346. // copy all other attributes to this.data.xxx
  2347. for (var name in dict) {
  2348. if (NODE_ATTR_MAP[name]) {
  2349. // node.NAME = dict.NAME
  2350. this[name] = dict[name];
  2351. } else if (name === "data") {
  2352. // node.data += dict.data
  2353. $.extend(this.data, dict.data);
  2354. } else if (
  2355. !_isFunction(dict[name]) &&
  2356. !NONE_NODE_DATA_MAP[name]
  2357. ) {
  2358. // node.data.NAME = dict.NAME
  2359. this.data[name] = dict[name];
  2360. }
  2361. }
  2362. if (dict.children) {
  2363. // recursively set children and render
  2364. this.removeChildren();
  2365. this.addChildren(dict.children);
  2366. }
  2367. this.renderTitle();
  2368. /*
  2369. var children = dict.children;
  2370. if(children === undefined){
  2371. this.data = $.extend(this.data, dict);
  2372. this.render();
  2373. return;
  2374. }
  2375. dict = $.extend({}, dict);
  2376. dict.children = undefined;
  2377. this.data = $.extend(this.data, dict);
  2378. this.removeChildren();
  2379. this.addChild(children);
  2380. */
  2381. },
  2382. /** Return the list of child nodes (undefined for unexpanded lazy nodes).
  2383. * @returns {FancytreeNode[] | undefined}
  2384. */
  2385. getChildren: function () {
  2386. if (this.hasChildren() === undefined) {
  2387. // TODO: only required for lazy nodes?
  2388. return undefined; // Lazy node: unloaded, currently loading, or load error
  2389. }
  2390. return this.children;
  2391. },
  2392. /** Return the first child node or null.
  2393. * @returns {FancytreeNode | null}
  2394. */
  2395. getFirstChild: function () {
  2396. return this.children ? this.children[0] : null;
  2397. },
  2398. /** Return the 0-based child index.
  2399. * @returns {int}
  2400. */
  2401. getIndex: function () {
  2402. // return this.parent.children.indexOf(this);
  2403. return $.inArray(this, this.parent.children); // indexOf doesn't work in IE7
  2404. },
  2405. /** Return the hierarchical child index (1-based, e.g. '3.2.4').
  2406. * @param {string} [separator="."]
  2407. * @param {int} [digits=1]
  2408. * @returns {string}
  2409. */
  2410. getIndexHier: function (separator, digits) {
  2411. separator = separator || ".";
  2412. var s,
  2413. res = [];
  2414. $.each(this.getParentList(false, true), function (i, o) {
  2415. s = "" + (o.getIndex() + 1);
  2416. if (digits) {
  2417. // prepend leading zeroes
  2418. s = ("0000000" + s).substr(-digits);
  2419. }
  2420. res.push(s);
  2421. });
  2422. return res.join(separator);
  2423. },
  2424. /** Return the parent keys separated by options.keyPathSeparator, e.g. "/id_1/id_17/id_32".
  2425. *
  2426. * (Unlike `node.getPath()`, this method prepends a "/" and inverts the first argument.)
  2427. *
  2428. * @see FancytreeNode#getPath
  2429. * @param {boolean} [excludeSelf=false]
  2430. * @returns {string}
  2431. */
  2432. getKeyPath: function (excludeSelf) {
  2433. var sep = this.tree.options.keyPathSeparator;
  2434. return sep + this.getPath(!excludeSelf, "key", sep);
  2435. },
  2436. /** Return the last child of this node or null.
  2437. * @returns {FancytreeNode | null}
  2438. */
  2439. getLastChild: function () {
  2440. return this.children
  2441. ? this.children[this.children.length - 1]
  2442. : null;
  2443. },
  2444. /** Return node depth. 0: System root node, 1: visible top-level node, 2: first sub-level, ... .
  2445. * @returns {int}
  2446. */
  2447. getLevel: function () {
  2448. var level = 0,
  2449. dtn = this.parent;
  2450. while (dtn) {
  2451. level++;
  2452. dtn = dtn.parent;
  2453. }
  2454. return level;
  2455. },
  2456. /** Return the successor node (under the same parent) or null.
  2457. * @returns {FancytreeNode | null}
  2458. */
  2459. getNextSibling: function () {
  2460. // TODO: use indexOf, if available: (not in IE6)
  2461. if (this.parent) {
  2462. var i,
  2463. l,
  2464. ac = this.parent.children;
  2465. for (i = 0, l = ac.length - 1; i < l; i++) {
  2466. // up to length-2, so next(last) = null
  2467. if (ac[i] === this) {
  2468. return ac[i + 1];
  2469. }
  2470. }
  2471. }
  2472. return null;
  2473. },
  2474. /** Return the parent node (null for the system root node).
  2475. * @returns {FancytreeNode | null}
  2476. */
  2477. getParent: function () {
  2478. // TODO: return null for top-level nodes?
  2479. return this.parent;
  2480. },
  2481. /** Return an array of all parent nodes (top-down).
  2482. * @param {boolean} [includeRoot=false] Include the invisible system root node.
  2483. * @param {boolean} [includeSelf=false] Include the node itself.
  2484. * @returns {FancytreeNode[]}
  2485. */
  2486. getParentList: function (includeRoot, includeSelf) {
  2487. var l = [],
  2488. dtn = includeSelf ? this : this.parent;
  2489. while (dtn) {
  2490. if (includeRoot || dtn.parent) {
  2491. l.unshift(dtn);
  2492. }
  2493. dtn = dtn.parent;
  2494. }
  2495. return l;
  2496. },
  2497. /** Return a string representing the hierachical node path, e.g. "a/b/c".
  2498. * @param {boolean} [includeSelf=true]
  2499. * @param {string | function} [part="title"] node property name or callback
  2500. * @param {string} [separator="/"]
  2501. * @returns {string}
  2502. * @since v2.31
  2503. */
  2504. getPath: function (includeSelf, part, separator) {
  2505. includeSelf = includeSelf !== false;
  2506. part = part || "title";
  2507. separator = separator || "/";
  2508. var val,
  2509. path = [],
  2510. isFunc = _isFunction(part);
  2511. this.visitParents(function (n) {
  2512. if (n.parent) {
  2513. val = isFunc ? part(n) : n[part];
  2514. path.unshift(val);
  2515. }
  2516. }, includeSelf);
  2517. return path.join(separator);
  2518. },
  2519. /** Return the predecessor node (under the same parent) or null.
  2520. * @returns {FancytreeNode | null}
  2521. */
  2522. getPrevSibling: function () {
  2523. if (this.parent) {
  2524. var i,
  2525. l,
  2526. ac = this.parent.children;
  2527. for (i = 1, l = ac.length; i < l; i++) {
  2528. // start with 1, so prev(first) = null
  2529. if (ac[i] === this) {
  2530. return ac[i - 1];
  2531. }
  2532. }
  2533. }
  2534. return null;
  2535. },
  2536. /**
  2537. * Return an array of selected descendant nodes.
  2538. * @param {boolean} [stopOnParents=false] only return the topmost selected
  2539. * node (useful with selectMode 3)
  2540. * @returns {FancytreeNode[]}
  2541. */
  2542. getSelectedNodes: function (stopOnParents) {
  2543. var nodeList = [];
  2544. this.visit(function (node) {
  2545. if (node.selected) {
  2546. nodeList.push(node);
  2547. if (stopOnParents === true) {
  2548. return "skip"; // stop processing this branch
  2549. }
  2550. }
  2551. });
  2552. return nodeList;
  2553. },
  2554. /** Return true if node has children. Return undefined if not sure, i.e. the node is lazy and not yet loaded).
  2555. * @returns {boolean | undefined}
  2556. */
  2557. hasChildren: function () {
  2558. if (this.lazy) {
  2559. if (this.children == null) {
  2560. // null or undefined: Not yet loaded
  2561. return undefined;
  2562. } else if (this.children.length === 0) {
  2563. // Loaded, but response was empty
  2564. return false;
  2565. } else if (
  2566. this.children.length === 1 &&
  2567. this.children[0].isStatusNode()
  2568. ) {
  2569. // Currently loading or load error
  2570. return undefined;
  2571. }
  2572. return true;
  2573. }
  2574. return !!(this.children && this.children.length);
  2575. },
  2576. /**
  2577. * Return true if node has `className` defined in .extraClasses.
  2578. *
  2579. * @param {string} className class name (separate multiple classes by space)
  2580. * @returns {boolean}
  2581. *
  2582. * @since 2.32
  2583. */
  2584. hasClass: function (className) {
  2585. return (
  2586. (" " + (this.extraClasses || "") + " ").indexOf(
  2587. " " + className + " "
  2588. ) >= 0
  2589. );
  2590. },
  2591. /** Return true if node has keyboard focus.
  2592. * @returns {boolean}
  2593. */
  2594. hasFocus: function () {
  2595. return this.tree.hasFocus() && this.tree.focusNode === this;
  2596. },
  2597. /** Write to browser console if debugLevel >= 3 (prepending node info)
  2598. *
  2599. * @param {*} msg string or object or array of such
  2600. */
  2601. info: function (msg) {
  2602. if (this.tree.options.debugLevel >= 3) {
  2603. Array.prototype.unshift.call(arguments, this.toString());
  2604. consoleApply("info", arguments);
  2605. }
  2606. },
  2607. /** Return true if node is active (see also FancytreeNode#isSelected).
  2608. * @returns {boolean}
  2609. */
  2610. isActive: function () {
  2611. return this.tree.activeNode === this;
  2612. },
  2613. /** Return true if node is vertically below `otherNode`, i.e. rendered in a subsequent row.
  2614. * @param {FancytreeNode} otherNode
  2615. * @returns {boolean}
  2616. * @since 2.28
  2617. */
  2618. isBelowOf: function (otherNode) {
  2619. return this.getIndexHier(".", 5) > otherNode.getIndexHier(".", 5);
  2620. },
  2621. /** Return true if node is a direct child of otherNode.
  2622. * @param {FancytreeNode} otherNode
  2623. * @returns {boolean}
  2624. */
  2625. isChildOf: function (otherNode) {
  2626. return this.parent && this.parent === otherNode;
  2627. },
  2628. /** Return true, if node is a direct or indirect sub node of otherNode.
  2629. * @param {FancytreeNode} otherNode
  2630. * @returns {boolean}
  2631. */
  2632. isDescendantOf: function (otherNode) {
  2633. if (!otherNode || otherNode.tree !== this.tree) {
  2634. return false;
  2635. }
  2636. var p = this.parent;
  2637. while (p) {
  2638. if (p === otherNode) {
  2639. return true;
  2640. }
  2641. if (p === p.parent) {
  2642. $.error("Recursive parent link: " + p);
  2643. }
  2644. p = p.parent;
  2645. }
  2646. return false;
  2647. },
  2648. /** Return true if node is expanded.
  2649. * @returns {boolean}
  2650. */
  2651. isExpanded: function () {
  2652. return !!this.expanded;
  2653. },
  2654. /** Return true if node is the first node of its parent's children.
  2655. * @returns {boolean}
  2656. */
  2657. isFirstSibling: function () {
  2658. var p = this.parent;
  2659. return !p || p.children[0] === this;
  2660. },
  2661. /** Return true if node is a folder, i.e. has the node.folder attribute set.
  2662. * @returns {boolean}
  2663. */
  2664. isFolder: function () {
  2665. return !!this.folder;
  2666. },
  2667. /** Return true if node is the last node of its parent's children.
  2668. * @returns {boolean}
  2669. */
  2670. isLastSibling: function () {
  2671. var p = this.parent;
  2672. return !p || p.children[p.children.length - 1] === this;
  2673. },
  2674. /** Return true if node is lazy (even if data was already loaded)
  2675. * @returns {boolean}
  2676. */
  2677. isLazy: function () {
  2678. return !!this.lazy;
  2679. },
  2680. /** Return true if node is lazy and loaded. For non-lazy nodes always return true.
  2681. * @returns {boolean}
  2682. */
  2683. isLoaded: function () {
  2684. return !this.lazy || this.hasChildren() !== undefined; // Also checks if the only child is a status node
  2685. },
  2686. /** Return true if children are currently beeing loaded, i.e. a Ajax request is pending.
  2687. * @returns {boolean}
  2688. */
  2689. isLoading: function () {
  2690. return !!this._isLoading;
  2691. },
  2692. /*
  2693. * @deprecated since v2.4.0: Use isRootNode() instead
  2694. */
  2695. isRoot: function () {
  2696. return this.isRootNode();
  2697. },
  2698. /** Return true if node is partially selected (tri-state).
  2699. * @returns {boolean}
  2700. * @since 2.23
  2701. */
  2702. isPartsel: function () {
  2703. return !this.selected && !!this.partsel;
  2704. },
  2705. /** (experimental) Return true if this is partially loaded.
  2706. * @returns {boolean}
  2707. * @since 2.15
  2708. */
  2709. isPartload: function () {
  2710. return !!this.partload;
  2711. },
  2712. /** Return true if this is the (invisible) system root node.
  2713. * @returns {boolean}
  2714. * @since 2.4
  2715. */
  2716. isRootNode: function () {
  2717. return this.tree.rootNode === this;
  2718. },
  2719. /** Return true if node is selected, i.e. has a checkmark set (see also FancytreeNode#isActive).
  2720. * @returns {boolean}
  2721. */
  2722. isSelected: function () {
  2723. return !!this.selected;
  2724. },
  2725. /** Return true if this node is a temporarily generated system node like
  2726. * 'loading', 'paging', or 'error' (node.statusNodeType contains the type).
  2727. * @returns {boolean}
  2728. */
  2729. isStatusNode: function () {
  2730. return !!this.statusNodeType;
  2731. },
  2732. /** Return true if this node is a status node of type 'paging'.
  2733. * @returns {boolean}
  2734. * @since 2.15
  2735. */
  2736. isPagingNode: function () {
  2737. return this.statusNodeType === "paging";
  2738. },
  2739. /** Return true if this a top level node, i.e. a direct child of the (invisible) system root node.
  2740. * @returns {boolean}
  2741. * @since 2.4
  2742. */
  2743. isTopLevel: function () {
  2744. return this.tree.rootNode === this.parent;
  2745. },
  2746. /** Return true if node is lazy and not yet loaded. For non-lazy nodes always return false.
  2747. * @returns {boolean}
  2748. */
  2749. isUndefined: function () {
  2750. return this.hasChildren() === undefined; // also checks if the only child is a status node
  2751. },
  2752. /** Return true if all parent nodes are expanded. Note: this does not check
  2753. * whether the node is scrolled into the visible part of the screen.
  2754. * @returns {boolean}
  2755. */
  2756. isVisible: function () {
  2757. var i,
  2758. l,
  2759. n,
  2760. hasFilter = this.tree.enableFilter,
  2761. parents = this.getParentList(false, false);
  2762. // TODO: check $(n.span).is(":visible")
  2763. // i.e. return false for nodes (but not parents) that are hidden
  2764. // by a filter
  2765. if (hasFilter && !this.match && !this.subMatchCount) {
  2766. // this.debug( "isVisible: HIDDEN (" + hasFilter + ", " + this.match + ", " + this.match + ")" );
  2767. return false;
  2768. }
  2769. for (i = 0, l = parents.length; i < l; i++) {
  2770. n = parents[i];
  2771. if (!n.expanded) {
  2772. // this.debug("isVisible: HIDDEN (parent collapsed)");
  2773. return false;
  2774. }
  2775. // if (hasFilter && !n.match && !n.subMatchCount) {
  2776. // this.debug("isVisible: HIDDEN (" + hasFilter + ", " + this.match + ", " + this.match + ")");
  2777. // return false;
  2778. // }
  2779. }
  2780. // this.debug("isVisible: VISIBLE");
  2781. return true;
  2782. },
  2783. /** Deprecated.
  2784. * @deprecated since 2014-02-16: use load() instead.
  2785. */
  2786. lazyLoad: function (discard) {
  2787. $.error(
  2788. "FancytreeNode.lazyLoad() is deprecated since 2014-02-16. Use .load() instead."
  2789. );
  2790. },
  2791. /**
  2792. * Load all children of a lazy node if neccessary. The <i>expanded</i> state is maintained.
  2793. * @param {boolean} [forceReload=false] Pass true to discard any existing nodes before. Otherwise this method does nothing if the node was already loaded.
  2794. * @returns {$.Promise}
  2795. */
  2796. load: function (forceReload) {
  2797. var res,
  2798. source,
  2799. self = this,
  2800. wasExpanded = this.isExpanded();
  2801. _assert(this.isLazy(), "load() requires a lazy node");
  2802. // _assert( forceReload || this.isUndefined(), "Pass forceReload=true to re-load a lazy node" );
  2803. if (!forceReload && !this.isUndefined()) {
  2804. return _getResolvedPromise(this);
  2805. }
  2806. if (this.isLoaded()) {
  2807. this.resetLazy(); // also collapses
  2808. }
  2809. // This method is also called by setExpanded() and loadKeyPath(), so we
  2810. // have to avoid recursion.
  2811. source = this.tree._triggerNodeEvent("lazyLoad", this);
  2812. if (source === false) {
  2813. // #69
  2814. return _getResolvedPromise(this);
  2815. }
  2816. _assert(
  2817. typeof source !== "boolean",
  2818. "lazyLoad event must return source in data.result"
  2819. );
  2820. res = this.tree._callHook("nodeLoadChildren", this, source);
  2821. if (wasExpanded) {
  2822. this.expanded = true;
  2823. res.always(function () {
  2824. self.render();
  2825. });
  2826. } else {
  2827. res.always(function () {
  2828. self.renderStatus(); // fix expander icon to 'loaded'
  2829. });
  2830. }
  2831. return res;
  2832. },
  2833. /** Expand all parents and optionally scroll into visible area as neccessary.
  2834. * Promise is resolved, when lazy loading and animations are done.
  2835. * @param {object} [opts] passed to `setExpanded()`.
  2836. * Defaults to {noAnimation: false, noEvents: false, scrollIntoView: true}
  2837. * @returns {$.Promise}
  2838. */
  2839. makeVisible: function (opts) {
  2840. var i,
  2841. self = this,
  2842. deferreds = [],
  2843. dfd = new $.Deferred(),
  2844. parents = this.getParentList(false, false),
  2845. len = parents.length,
  2846. effects = !(opts && opts.noAnimation === true),
  2847. scroll = !(opts && opts.scrollIntoView === false);
  2848. // Expand bottom-up, so only the top node is animated
  2849. for (i = len - 1; i >= 0; i--) {
  2850. // self.debug("pushexpand" + parents[i]);
  2851. deferreds.push(parents[i].setExpanded(true, opts));
  2852. }
  2853. $.when.apply($, deferreds).done(function () {
  2854. // All expands have finished
  2855. // self.debug("expand DONE", scroll);
  2856. if (scroll) {
  2857. self.scrollIntoView(effects).done(function () {
  2858. // self.debug("scroll DONE");
  2859. dfd.resolve();
  2860. });
  2861. } else {
  2862. dfd.resolve();
  2863. }
  2864. });
  2865. return dfd.promise();
  2866. },
  2867. /** Move this node to targetNode.
  2868. * @param {FancytreeNode} targetNode
  2869. * @param {string} mode <pre>
  2870. * 'child': append this node as last child of targetNode.
  2871. * This is the default. To be compatble with the D'n'd
  2872. * hitMode, we also accept 'over'.
  2873. * 'firstChild': add this node as first child of targetNode.
  2874. * 'before': add this node as sibling before targetNode.
  2875. * 'after': add this node as sibling after targetNode.</pre>
  2876. * @param {function} [map] optional callback(FancytreeNode) to allow modifcations
  2877. */
  2878. moveTo: function (targetNode, mode, map) {
  2879. if (mode === undefined || mode === "over") {
  2880. mode = "child";
  2881. } else if (mode === "firstChild") {
  2882. if (targetNode.children && targetNode.children.length) {
  2883. mode = "before";
  2884. targetNode = targetNode.children[0];
  2885. } else {
  2886. mode = "child";
  2887. }
  2888. }
  2889. var pos,
  2890. tree = this.tree,
  2891. prevParent = this.parent,
  2892. targetParent =
  2893. mode === "child" ? targetNode : targetNode.parent;
  2894. if (this === targetNode) {
  2895. return;
  2896. } else if (!this.parent) {
  2897. $.error("Cannot move system root");
  2898. } else if (targetParent.isDescendantOf(this)) {
  2899. $.error("Cannot move a node to its own descendant");
  2900. }
  2901. if (targetParent !== prevParent) {
  2902. prevParent.triggerModifyChild("remove", this);
  2903. }
  2904. // Unlink this node from current parent
  2905. if (this.parent.children.length === 1) {
  2906. if (this.parent === targetParent) {
  2907. return; // #258
  2908. }
  2909. this.parent.children = this.parent.lazy ? [] : null;
  2910. this.parent.expanded = false;
  2911. } else {
  2912. pos = $.inArray(this, this.parent.children);
  2913. _assert(pos >= 0, "invalid source parent");
  2914. this.parent.children.splice(pos, 1);
  2915. }
  2916. // Remove from source DOM parent
  2917. // if(this.parent.ul){
  2918. // this.parent.ul.removeChild(this.li);
  2919. // }
  2920. // Insert this node to target parent's child list
  2921. this.parent = targetParent;
  2922. if (targetParent.hasChildren()) {
  2923. switch (mode) {
  2924. case "child":
  2925. // Append to existing target children
  2926. targetParent.children.push(this);
  2927. break;
  2928. case "before":
  2929. // Insert this node before target node
  2930. pos = $.inArray(targetNode, targetParent.children);
  2931. _assert(pos >= 0, "invalid target parent");
  2932. targetParent.children.splice(pos, 0, this);
  2933. break;
  2934. case "after":
  2935. // Insert this node after target node
  2936. pos = $.inArray(targetNode, targetParent.children);
  2937. _assert(pos >= 0, "invalid target parent");
  2938. targetParent.children.splice(pos + 1, 0, this);
  2939. break;
  2940. default:
  2941. $.error("Invalid mode " + mode);
  2942. }
  2943. } else {
  2944. targetParent.children = [this];
  2945. }
  2946. // Parent has no <ul> tag yet:
  2947. // if( !targetParent.ul ) {
  2948. // // This is the parent's first child: create UL tag
  2949. // // (Hidden, because it will be
  2950. // targetParent.ul = document.createElement("ul");
  2951. // targetParent.ul.style.display = "none";
  2952. // targetParent.li.appendChild(targetParent.ul);
  2953. // }
  2954. // // Issue 319: Add to target DOM parent (only if node was already rendered(expanded))
  2955. // if(this.li){
  2956. // targetParent.ul.appendChild(this.li);
  2957. // }
  2958. // Let caller modify the nodes
  2959. if (map) {
  2960. targetNode.visit(map, true);
  2961. }
  2962. if (targetParent === prevParent) {
  2963. targetParent.triggerModifyChild("move", this);
  2964. } else {
  2965. // prevParent.triggerModifyChild("remove", this);
  2966. targetParent.triggerModifyChild("add", this);
  2967. }
  2968. // Handle cross-tree moves
  2969. if (tree !== targetNode.tree) {
  2970. // Fix node.tree for all source nodes
  2971. // _assert(false, "Cross-tree move is not yet implemented.");
  2972. this.warn("Cross-tree moveTo is experimental!");
  2973. this.visit(function (n) {
  2974. // TODO: fix selection state and activation, ...
  2975. n.tree = targetNode.tree;
  2976. }, true);
  2977. }
  2978. // A collaposed node won't re-render children, so we have to remove it manually
  2979. // if( !targetParent.expanded ){
  2980. // prevParent.ul.removeChild(this.li);
  2981. // }
  2982. tree._callHook("treeStructureChanged", tree, "moveTo");
  2983. // Update HTML markup
  2984. if (!prevParent.isDescendantOf(targetParent)) {
  2985. prevParent.render();
  2986. }
  2987. if (
  2988. !targetParent.isDescendantOf(prevParent) &&
  2989. targetParent !== prevParent
  2990. ) {
  2991. targetParent.render();
  2992. }
  2993. // TODO: fix selection state
  2994. // TODO: fix active state
  2995. /*
  2996. var tree = this.tree;
  2997. var opts = tree.options;
  2998. var pers = tree.persistence;
  2999. // Always expand, if it's below minExpandLevel
  3000. // tree.logDebug ("%s._addChildNode(%o), l=%o", this, ftnode, ftnode.getLevel());
  3001. if ( opts.minExpandLevel >= ftnode.getLevel() ) {
  3002. // tree.logDebug ("Force expand for %o", ftnode);
  3003. this.bExpanded = true;
  3004. }
  3005. // In multi-hier mode, update the parents selection state
  3006. // DT issue #82: only if not initializing, because the children may not exist yet
  3007. // if( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing )
  3008. // ftnode._fixSelectionState();
  3009. // In multi-hier mode, update the parents selection state
  3010. if( ftnode.bSelected && opts.selectMode==3 ) {
  3011. var p = this;
  3012. while( p ) {
  3013. if( !p.hasSubSel )
  3014. p._setSubSel(true);
  3015. p = p.parent;
  3016. }
  3017. }
  3018. // render this node and the new child
  3019. if ( tree.bEnableUpdate )
  3020. this.render();
  3021. return ftnode;
  3022. */
  3023. },
  3024. /** Set focus relative to this node and optionally activate.
  3025. *
  3026. * 'left' collapses the node if it is expanded, or move to the parent
  3027. * otherwise.
  3028. * 'right' expands the node if it is collapsed, or move to the first
  3029. * child otherwise.
  3030. *
  3031. * @param {string|number} where 'down', 'first', 'last', 'left', 'parent', 'right', or 'up'.
  3032. * (Alternatively the keyCode that would normally trigger this move,
  3033. * e.g. `$.ui.keyCode.LEFT` = 'left'.
  3034. * @param {boolean} [activate=true]
  3035. * @returns {$.Promise}
  3036. */
  3037. navigate: function (where, activate) {
  3038. var node,
  3039. KC = $.ui.keyCode;
  3040. // Handle optional expand/collapse action for LEFT/RIGHT
  3041. switch (where) {
  3042. case "left":
  3043. case KC.LEFT:
  3044. if (this.expanded) {
  3045. return this.setExpanded(false);
  3046. }
  3047. break;
  3048. case "right":
  3049. case KC.RIGHT:
  3050. if (!this.expanded && (this.children || this.lazy)) {
  3051. return this.setExpanded();
  3052. }
  3053. break;
  3054. }
  3055. // Otherwise activate or focus the related node
  3056. node = this.findRelatedNode(where);
  3057. if (node) {
  3058. // setFocus/setActive will scroll later (if autoScroll is specified)
  3059. try {
  3060. node.makeVisible({ scrollIntoView: false });
  3061. } catch (e) {} // #272
  3062. if (activate === false) {
  3063. node.setFocus();
  3064. return _getResolvedPromise();
  3065. }
  3066. return node.setActive();
  3067. }
  3068. this.warn("Could not find related node '" + where + "'.");
  3069. return _getResolvedPromise();
  3070. },
  3071. /**
  3072. * Remove this node (not allowed for system root).
  3073. */
  3074. remove: function () {
  3075. return this.parent.removeChild(this);
  3076. },
  3077. /**
  3078. * Remove childNode from list of direct children.
  3079. * @param {FancytreeNode} childNode
  3080. */
  3081. removeChild: function (childNode) {
  3082. return this.tree._callHook("nodeRemoveChild", this, childNode);
  3083. },
  3084. /**
  3085. * Remove all child nodes and descendents. This converts the node into a leaf.<br>
  3086. * If this was a lazy node, it is still considered 'loaded'; call node.resetLazy()
  3087. * in order to trigger lazyLoad on next expand.
  3088. */
  3089. removeChildren: function () {
  3090. return this.tree._callHook("nodeRemoveChildren", this);
  3091. },
  3092. /**
  3093. * Remove class from node's span tag and .extraClasses.
  3094. *
  3095. * @param {string} className class name
  3096. *
  3097. * @since 2.17
  3098. */
  3099. removeClass: function (className) {
  3100. return this.toggleClass(className, false);
  3101. },
  3102. /**
  3103. * This method renders and updates all HTML markup that is required
  3104. * to display this node in its current state.<br>
  3105. * Note:
  3106. * <ul>
  3107. * <li>It should only be neccessary to call this method after the node object
  3108. * was modified by direct access to its properties, because the common
  3109. * API methods (node.setTitle(), moveTo(), addChildren(), remove(), ...)
  3110. * already handle this.
  3111. * <li> {@link FancytreeNode#renderTitle} and {@link FancytreeNode#renderStatus}
  3112. * are implied. If changes are more local, calling only renderTitle() or
  3113. * renderStatus() may be sufficient and faster.
  3114. * </ul>
  3115. *
  3116. * @param {boolean} [force=false] re-render, even if html markup was already created
  3117. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  3118. */
  3119. render: function (force, deep) {
  3120. return this.tree._callHook("nodeRender", this, force, deep);
  3121. },
  3122. /** Create HTML markup for the node's outer `<span>` (expander, checkbox, icon, and title).
  3123. * Implies {@link FancytreeNode#renderStatus}.
  3124. * @see Fancytree_Hooks#nodeRenderTitle
  3125. */
  3126. renderTitle: function () {
  3127. return this.tree._callHook("nodeRenderTitle", this);
  3128. },
  3129. /** Update element's CSS classes according to node state.
  3130. * @see Fancytree_Hooks#nodeRenderStatus
  3131. */
  3132. renderStatus: function () {
  3133. return this.tree._callHook("nodeRenderStatus", this);
  3134. },
  3135. /**
  3136. * (experimental) Replace this node with `source`.
  3137. * (Currently only available for paging nodes.)
  3138. * @param {NodeData[]} source List of child node definitions
  3139. * @since 2.15
  3140. */
  3141. replaceWith: function (source) {
  3142. var res,
  3143. parent = this.parent,
  3144. pos = $.inArray(this, parent.children),
  3145. self = this;
  3146. _assert(
  3147. this.isPagingNode(),
  3148. "replaceWith() currently requires a paging status node"
  3149. );
  3150. res = this.tree._callHook("nodeLoadChildren", this, source);
  3151. res.done(function (data) {
  3152. // New nodes are currently children of `this`.
  3153. var children = self.children;
  3154. // Prepend newly loaded child nodes to `this`
  3155. // Move new children after self
  3156. for (i = 0; i < children.length; i++) {
  3157. children[i].parent = parent;
  3158. }
  3159. parent.children.splice.apply(
  3160. parent.children,
  3161. [pos + 1, 0].concat(children)
  3162. );
  3163. // Remove self
  3164. self.children = null;
  3165. self.remove();
  3166. // Redraw new nodes
  3167. parent.render();
  3168. // TODO: set node.partload = false if this was tha last paging node?
  3169. // parent.addPagingNode(false);
  3170. }).fail(function () {
  3171. self.setExpanded();
  3172. });
  3173. return res;
  3174. // $.error("Not implemented: replaceWith()");
  3175. },
  3176. /**
  3177. * Remove all children, collapse, and set the lazy-flag, so that the lazyLoad
  3178. * event is triggered on next expand.
  3179. */
  3180. resetLazy: function () {
  3181. this.removeChildren();
  3182. this.expanded = false;
  3183. this.lazy = true;
  3184. this.children = undefined;
  3185. this.renderStatus();
  3186. },
  3187. /** Schedule activity for delayed execution (cancel any pending request).
  3188. * scheduleAction('cancel') will only cancel a pending request (if any).
  3189. * @param {string} mode
  3190. * @param {number} ms
  3191. */
  3192. scheduleAction: function (mode, ms) {
  3193. if (this.tree.timer) {
  3194. clearTimeout(this.tree.timer);
  3195. this.tree.debug("clearTimeout(%o)", this.tree.timer);
  3196. }
  3197. this.tree.timer = null;
  3198. var self = this; // required for closures
  3199. switch (mode) {
  3200. case "cancel":
  3201. // Simply made sure that timer was cleared
  3202. break;
  3203. case "expand":
  3204. this.tree.timer = setTimeout(function () {
  3205. self.tree.debug("setTimeout: trigger expand");
  3206. self.setExpanded(true);
  3207. }, ms);
  3208. break;
  3209. case "activate":
  3210. this.tree.timer = setTimeout(function () {
  3211. self.tree.debug("setTimeout: trigger activate");
  3212. self.setActive(true);
  3213. }, ms);
  3214. break;
  3215. default:
  3216. $.error("Invalid mode " + mode);
  3217. }
  3218. // this.tree.debug("setTimeout(%s, %s): %s", mode, ms, this.tree.timer);
  3219. },
  3220. /**
  3221. *
  3222. * @param {boolean | PlainObject} [effects=false] animation options.
  3223. * @param {object} [options=null] {topNode: null, effects: ..., parent: ...} this node will remain visible in
  3224. * any case, even if `this` is outside the scroll pane.
  3225. * @returns {$.Promise}
  3226. */
  3227. scrollIntoView: function (effects, options) {
  3228. if (options !== undefined && _isNode(options)) {
  3229. throw Error(
  3230. "scrollIntoView() with 'topNode' option is deprecated since 2014-05-08. Use 'options.topNode' instead."
  3231. );
  3232. }
  3233. // The scroll parent is typically the plain tree's <UL> container.
  3234. // For ext-table, we choose the nearest parent that has `position: relative`
  3235. // and `overflow` set.
  3236. // (This default can be overridden by the local or global `scrollParent` option.)
  3237. var opts = $.extend(
  3238. {
  3239. effects:
  3240. effects === true
  3241. ? { duration: 200, queue: false }
  3242. : effects,
  3243. scrollOfs: this.tree.options.scrollOfs,
  3244. scrollParent: this.tree.options.scrollParent,
  3245. topNode: null,
  3246. },
  3247. options
  3248. ),
  3249. $scrollParent = opts.scrollParent,
  3250. $container = this.tree.$container,
  3251. overflowY = $container.css("overflow-y");
  3252. if (!$scrollParent) {
  3253. if (this.tree.tbody) {
  3254. $scrollParent = $container.scrollParent();
  3255. } else if (overflowY === "scroll" || overflowY === "auto") {
  3256. $scrollParent = $container;
  3257. } else {
  3258. // #922 plain tree in a non-fixed-sized UL scrolls inside its parent
  3259. $scrollParent = $container.scrollParent();
  3260. }
  3261. } else if (!$scrollParent.jquery) {
  3262. // Make sure we have a jQuery object
  3263. $scrollParent = $($scrollParent);
  3264. }
  3265. if (
  3266. $scrollParent[0] === document ||
  3267. $scrollParent[0] === document.body
  3268. ) {
  3269. // `document` may be returned by $().scrollParent(), if nothing is found,
  3270. // but would not work: (see #894)
  3271. this.debug(
  3272. "scrollIntoView(): normalizing scrollParent to 'window':",
  3273. $scrollParent[0]
  3274. );
  3275. $scrollParent = $(window);
  3276. }
  3277. // eslint-disable-next-line one-var
  3278. var topNodeY,
  3279. nodeY,
  3280. horzScrollbarHeight,
  3281. containerOffsetTop,
  3282. dfd = new $.Deferred(),
  3283. self = this,
  3284. nodeHeight = $(this.span).height(),
  3285. topOfs = opts.scrollOfs.top || 0,
  3286. bottomOfs = opts.scrollOfs.bottom || 0,
  3287. containerHeight = $scrollParent.height(),
  3288. scrollTop = $scrollParent.scrollTop(),
  3289. $animateTarget = $scrollParent,
  3290. isParentWindow = $scrollParent[0] === window,
  3291. topNode = opts.topNode || null,
  3292. newScrollTop = null;
  3293. // this.debug("scrollIntoView(), scrollTop=" + scrollTop, opts.scrollOfs);
  3294. // _assert($(this.span).is(":visible"), "scrollIntoView node is invisible"); // otherwise we cannot calc offsets
  3295. if (this.isRootNode() || !this.isVisible()) {
  3296. // We cannot calc offsets for hidden elements
  3297. this.info("scrollIntoView(): node is invisible.");
  3298. return _getResolvedPromise();
  3299. }
  3300. if (isParentWindow) {
  3301. nodeY = $(this.span).offset().top;
  3302. topNodeY =
  3303. topNode && topNode.span ? $(topNode.span).offset().top : 0;
  3304. $animateTarget = $("html,body");
  3305. } else {
  3306. _assert(
  3307. $scrollParent[0] !== document &&
  3308. $scrollParent[0] !== document.body,
  3309. "scrollParent should be a simple element or `window`, not document or body."
  3310. );
  3311. containerOffsetTop = $scrollParent.offset().top;
  3312. nodeY =
  3313. $(this.span).offset().top - containerOffsetTop + scrollTop; // relative to scroll parent
  3314. topNodeY = topNode
  3315. ? $(topNode.span).offset().top -
  3316. containerOffsetTop +
  3317. scrollTop
  3318. : 0;
  3319. horzScrollbarHeight = Math.max(
  3320. 0,
  3321. $scrollParent.innerHeight() - $scrollParent[0].clientHeight
  3322. );
  3323. containerHeight -= horzScrollbarHeight;
  3324. }
  3325. // this.debug(" scrollIntoView(), nodeY=" + nodeY + ", containerHeight=" + containerHeight);
  3326. if (nodeY < scrollTop + topOfs) {
  3327. // Node is above visible container area
  3328. newScrollTop = nodeY - topOfs;
  3329. // this.debug(" scrollIntoView(), UPPER newScrollTop=" + newScrollTop);
  3330. } else if (
  3331. nodeY + nodeHeight >
  3332. scrollTop + containerHeight - bottomOfs
  3333. ) {
  3334. newScrollTop = nodeY + nodeHeight - containerHeight + bottomOfs;
  3335. // this.debug(" scrollIntoView(), LOWER newScrollTop=" + newScrollTop);
  3336. // If a topNode was passed, make sure that it is never scrolled
  3337. // outside the upper border
  3338. if (topNode) {
  3339. _assert(
  3340. topNode.isRootNode() || topNode.isVisible(),
  3341. "topNode must be visible"
  3342. );
  3343. if (topNodeY < newScrollTop) {
  3344. newScrollTop = topNodeY - topOfs;
  3345. // this.debug(" scrollIntoView(), TOP newScrollTop=" + newScrollTop);
  3346. }
  3347. }
  3348. }
  3349. if (newScrollTop === null) {
  3350. dfd.resolveWith(this);
  3351. } else {
  3352. // this.debug(" scrollIntoView(), SET newScrollTop=" + newScrollTop);
  3353. if (opts.effects) {
  3354. opts.effects.complete = function () {
  3355. dfd.resolveWith(self);
  3356. };
  3357. $animateTarget.stop(true).animate(
  3358. {
  3359. scrollTop: newScrollTop,
  3360. },
  3361. opts.effects
  3362. );
  3363. } else {
  3364. $animateTarget[0].scrollTop = newScrollTop;
  3365. dfd.resolveWith(this);
  3366. }
  3367. }
  3368. return dfd.promise();
  3369. },
  3370. /**Activate this node.
  3371. *
  3372. * The `cell` option requires the ext-table and ext-ariagrid extensions.
  3373. *
  3374. * @param {boolean} [flag=true] pass false to deactivate
  3375. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false, cell: null}
  3376. * @returns {$.Promise}
  3377. */
  3378. setActive: function (flag, opts) {
  3379. return this.tree._callHook("nodeSetActive", this, flag, opts);
  3380. },
  3381. /**Expand or collapse this node. Promise is resolved, when lazy loading and animations are done.
  3382. * @param {boolean} [flag=true] pass false to collapse
  3383. * @param {object} [opts] additional options. Defaults to {noAnimation: false, noEvents: false}
  3384. * @returns {$.Promise}
  3385. */
  3386. setExpanded: function (flag, opts) {
  3387. return this.tree._callHook("nodeSetExpanded", this, flag, opts);
  3388. },
  3389. /**Set keyboard focus to this node.
  3390. * @param {boolean} [flag=true] pass false to blur
  3391. * @see Fancytree#setFocus
  3392. */
  3393. setFocus: function (flag) {
  3394. return this.tree._callHook("nodeSetFocus", this, flag);
  3395. },
  3396. /**Select this node, i.e. check the checkbox.
  3397. * @param {boolean} [flag=true] pass false to deselect
  3398. * @param {object} [opts] additional options. Defaults to {noEvents: false, p
  3399. * propagateDown: null, propagateUp: null, callback: null }
  3400. */
  3401. setSelected: function (flag, opts) {
  3402. return this.tree._callHook("nodeSetSelected", this, flag, opts);
  3403. },
  3404. /**Mark a lazy node as 'error', 'loading', 'nodata', or 'ok'.
  3405. * @param {string} status 'error'|'loading'|'nodata'|'ok'
  3406. * @param {string} [message]
  3407. * @param {string} [details]
  3408. */
  3409. setStatus: function (status, message, details) {
  3410. return this.tree._callHook(
  3411. "nodeSetStatus",
  3412. this,
  3413. status,
  3414. message,
  3415. details
  3416. );
  3417. },
  3418. /**Rename this node.
  3419. * @param {string} title
  3420. */
  3421. setTitle: function (title) {
  3422. this.title = title;
  3423. this.renderTitle();
  3424. this.triggerModify("rename");
  3425. },
  3426. /**Sort child list by title.
  3427. * @param {function} [cmp] custom compare function(a, b) that returns -1, 0, or 1 (defaults to sort by title).
  3428. * @param {boolean} [deep=false] pass true to sort all descendant nodes
  3429. */
  3430. sortChildren: function (cmp, deep) {
  3431. var i,
  3432. l,
  3433. cl = this.children;
  3434. if (!cl) {
  3435. return;
  3436. }
  3437. cmp =
  3438. cmp ||
  3439. function (a, b) {
  3440. var x = a.title.toLowerCase(),
  3441. y = b.title.toLowerCase();
  3442. // eslint-disable-next-line no-nested-ternary
  3443. return x === y ? 0 : x > y ? 1 : -1;
  3444. };
  3445. cl.sort(cmp);
  3446. if (deep) {
  3447. for (i = 0, l = cl.length; i < l; i++) {
  3448. if (cl[i].children) {
  3449. cl[i].sortChildren(cmp, "$norender$");
  3450. }
  3451. }
  3452. }
  3453. if (deep !== "$norender$") {
  3454. this.render();
  3455. }
  3456. this.triggerModifyChild("sort");
  3457. },
  3458. /** Convert node (or whole branch) into a plain object.
  3459. *
  3460. * The result is compatible with node.addChildren().
  3461. *
  3462. * @param {boolean} [recursive=false] include child nodes
  3463. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications.
  3464. * Return `false` to ignore this node or `"skip"` to include this node without its children.
  3465. * @returns {NodeData}
  3466. */
  3467. toDict: function (recursive, callback) {
  3468. var i,
  3469. l,
  3470. node,
  3471. res,
  3472. dict = {},
  3473. self = this;
  3474. $.each(NODE_ATTRS, function (i, a) {
  3475. if (self[a] || self[a] === false) {
  3476. dict[a] = self[a];
  3477. }
  3478. });
  3479. if (!$.isEmptyObject(this.data)) {
  3480. dict.data = $.extend({}, this.data);
  3481. if ($.isEmptyObject(dict.data)) {
  3482. delete dict.data;
  3483. }
  3484. }
  3485. if (callback) {
  3486. res = callback(dict, self);
  3487. if (res === false) {
  3488. return false; // Don't include this node nor its children
  3489. }
  3490. if (res === "skip") {
  3491. recursive = false; // Include this node, but not the children
  3492. }
  3493. }
  3494. if (recursive) {
  3495. if (_isArray(this.children)) {
  3496. dict.children = [];
  3497. for (i = 0, l = this.children.length; i < l; i++) {
  3498. node = this.children[i];
  3499. if (!node.isStatusNode()) {
  3500. res = node.toDict(true, callback);
  3501. if (res !== false) {
  3502. dict.children.push(res);
  3503. }
  3504. }
  3505. }
  3506. }
  3507. }
  3508. return dict;
  3509. },
  3510. /**
  3511. * Set, clear, or toggle class of node's span tag and .extraClasses.
  3512. *
  3513. * @param {string} className class name (separate multiple classes by space)
  3514. * @param {boolean} [flag] true/false to add/remove class. If omitted, class is toggled.
  3515. * @returns {boolean} true if a class was added
  3516. *
  3517. * @since 2.17
  3518. */
  3519. toggleClass: function (value, flag) {
  3520. var className,
  3521. hasClass,
  3522. rnotwhite = /\S+/g,
  3523. classNames = value.match(rnotwhite) || [],
  3524. i = 0,
  3525. wasAdded = false,
  3526. statusElem = this[this.tree.statusClassPropName],
  3527. curClasses = " " + (this.extraClasses || "") + " ";
  3528. // this.info("toggleClass('" + value + "', " + flag + ")", curClasses);
  3529. // Modify DOM element directly if it already exists
  3530. if (statusElem) {
  3531. $(statusElem).toggleClass(value, flag);
  3532. }
  3533. // Modify node.extraClasses to make this change persistent
  3534. // Toggle if flag was not passed
  3535. while ((className = classNames[i++])) {
  3536. hasClass = curClasses.indexOf(" " + className + " ") >= 0;
  3537. flag = flag === undefined ? !hasClass : !!flag;
  3538. if (flag) {
  3539. if (!hasClass) {
  3540. curClasses += className + " ";
  3541. wasAdded = true;
  3542. }
  3543. } else {
  3544. while (curClasses.indexOf(" " + className + " ") > -1) {
  3545. curClasses = curClasses.replace(
  3546. " " + className + " ",
  3547. " "
  3548. );
  3549. }
  3550. }
  3551. }
  3552. this.extraClasses = _trim(curClasses);
  3553. // this.info("-> toggleClass('" + value + "', " + flag + "): '" + this.extraClasses + "'");
  3554. return wasAdded;
  3555. },
  3556. /** Flip expanded status. */
  3557. toggleExpanded: function () {
  3558. return this.tree._callHook("nodeToggleExpanded", this);
  3559. },
  3560. /** Flip selection status. */
  3561. toggleSelected: function () {
  3562. return this.tree._callHook("nodeToggleSelected", this);
  3563. },
  3564. toString: function () {
  3565. return "FancytreeNode@" + this.key + "[title='" + this.title + "']";
  3566. // return "<FancytreeNode(#" + this.key + ", '" + this.title + "')>";
  3567. },
  3568. /**
  3569. * Trigger `modifyChild` event on a parent to signal that a child was modified.
  3570. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  3571. * @param {FancytreeNode} [childNode]
  3572. * @param {object} [extra]
  3573. */
  3574. triggerModifyChild: function (operation, childNode, extra) {
  3575. var data,
  3576. modifyChild = this.tree.options.modifyChild;
  3577. if (modifyChild) {
  3578. if (childNode && childNode.parent !== this) {
  3579. $.error(
  3580. "childNode " + childNode + " is not a child of " + this
  3581. );
  3582. }
  3583. data = {
  3584. node: this,
  3585. tree: this.tree,
  3586. operation: operation,
  3587. childNode: childNode || null,
  3588. };
  3589. if (extra) {
  3590. $.extend(data, extra);
  3591. }
  3592. modifyChild({ type: "modifyChild" }, data);
  3593. }
  3594. },
  3595. /**
  3596. * Trigger `modifyChild` event on node.parent(!).
  3597. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  3598. * @param {object} [extra]
  3599. */
  3600. triggerModify: function (operation, extra) {
  3601. this.parent.triggerModifyChild(operation, this, extra);
  3602. },
  3603. /** Call fn(node) for all child nodes in hierarchical order (depth-first).<br>
  3604. * Stop iteration, if fn() returns false. Skip current branch, if fn() returns "skip".<br>
  3605. * Return false if iteration was stopped.
  3606. *
  3607. * @param {function} fn the callback function.
  3608. * Return false to stop iteration, return "skip" to skip this node and
  3609. * its children only.
  3610. * @param {boolean} [includeSelf=false]
  3611. * @returns {boolean}
  3612. */
  3613. visit: function (fn, includeSelf) {
  3614. var i,
  3615. l,
  3616. res = true,
  3617. children = this.children;
  3618. if (includeSelf === true) {
  3619. res = fn(this);
  3620. if (res === false || res === "skip") {
  3621. return res;
  3622. }
  3623. }
  3624. if (children) {
  3625. for (i = 0, l = children.length; i < l; i++) {
  3626. res = children[i].visit(fn, true);
  3627. if (res === false) {
  3628. break;
  3629. }
  3630. }
  3631. }
  3632. return res;
  3633. },
  3634. /** Call fn(node) for all child nodes and recursively load lazy children.<br>
  3635. * <b>Note:</b> If you need this method, you probably should consider to review
  3636. * your architecture! Recursivley loading nodes is a perfect way for lazy
  3637. * programmers to flood the server with requests ;-)
  3638. *
  3639. * @param {function} [fn] optional callback function.
  3640. * Return false to stop iteration, return "skip" to skip this node and
  3641. * its children only.
  3642. * @param {boolean} [includeSelf=false]
  3643. * @returns {$.Promise}
  3644. * @since 2.4
  3645. */
  3646. visitAndLoad: function (fn, includeSelf, _recursion) {
  3647. var dfd,
  3648. res,
  3649. loaders,
  3650. node = this;
  3651. // node.debug("visitAndLoad");
  3652. if (fn && includeSelf === true) {
  3653. res = fn(node);
  3654. if (res === false || res === "skip") {
  3655. return _recursion ? res : _getResolvedPromise();
  3656. }
  3657. }
  3658. if (!node.children && !node.lazy) {
  3659. return _getResolvedPromise();
  3660. }
  3661. dfd = new $.Deferred();
  3662. loaders = [];
  3663. // node.debug("load()...");
  3664. node.load().done(function () {
  3665. // node.debug("load()... done.");
  3666. for (var i = 0, l = node.children.length; i < l; i++) {
  3667. res = node.children[i].visitAndLoad(fn, true, true);
  3668. if (res === false) {
  3669. dfd.reject();
  3670. break;
  3671. } else if (res !== "skip") {
  3672. loaders.push(res); // Add promise to the list
  3673. }
  3674. }
  3675. $.when.apply(this, loaders).then(function () {
  3676. dfd.resolve();
  3677. });
  3678. });
  3679. return dfd.promise();
  3680. },
  3681. /** Call fn(node) for all parent nodes, bottom-up, including invisible system root.<br>
  3682. * Stop iteration, if fn() returns false.<br>
  3683. * Return false if iteration was stopped.
  3684. *
  3685. * @param {function} fn the callback function.
  3686. * Return false to stop iteration, return "skip" to skip this node and children only.
  3687. * @param {boolean} [includeSelf=false]
  3688. * @returns {boolean}
  3689. */
  3690. visitParents: function (fn, includeSelf) {
  3691. // Visit parent nodes (bottom up)
  3692. if (includeSelf && fn(this) === false) {
  3693. return false;
  3694. }
  3695. var p = this.parent;
  3696. while (p) {
  3697. if (fn(p) === false) {
  3698. return false;
  3699. }
  3700. p = p.parent;
  3701. }
  3702. return true;
  3703. },
  3704. /** Call fn(node) for all sibling nodes.<br>
  3705. * Stop iteration, if fn() returns false.<br>
  3706. * Return false if iteration was stopped.
  3707. *
  3708. * @param {function} fn the callback function.
  3709. * Return false to stop iteration.
  3710. * @param {boolean} [includeSelf=false]
  3711. * @returns {boolean}
  3712. */
  3713. visitSiblings: function (fn, includeSelf) {
  3714. var i,
  3715. l,
  3716. n,
  3717. ac = this.parent.children;
  3718. for (i = 0, l = ac.length; i < l; i++) {
  3719. n = ac[i];
  3720. if (includeSelf || n !== this) {
  3721. if (fn(n) === false) {
  3722. return false;
  3723. }
  3724. }
  3725. }
  3726. return true;
  3727. },
  3728. /** Write warning to browser console if debugLevel >= 2 (prepending node info)
  3729. *
  3730. * @param {*} msg string or object or array of such
  3731. */
  3732. warn: function (msg) {
  3733. if (this.tree.options.debugLevel >= 2) {
  3734. Array.prototype.unshift.call(arguments, this.toString());
  3735. consoleApply("warn", arguments);
  3736. }
  3737. },
  3738. };
  3739. /******************************************************************************
  3740. * Fancytree
  3741. */
  3742. /**
  3743. * Construct a new tree object.
  3744. *
  3745. * @class Fancytree
  3746. * @classdesc The controller behind a fancytree.
  3747. * This class also contains 'hook methods': see {@link Fancytree_Hooks}.
  3748. *
  3749. * @param {Widget} widget
  3750. *
  3751. * @property {string} _id Automatically generated unique tree instance ID, e.g. "1".
  3752. * @property {string} _ns Automatically generated unique tree namespace, e.g. ".fancytree-1".
  3753. * @property {FancytreeNode} activeNode Currently active node or null.
  3754. * @property {string} ariaPropName Property name of FancytreeNode that contains the element which will receive the aria attributes.
  3755. * Typically "li", but "tr" for table extension.
  3756. * @property {jQueryObject} $container Outer `<ul>` element (or `<table>` element for ext-table).
  3757. * @property {jQueryObject} $div A jQuery object containing the element used to instantiate the tree widget (`widget.element`)
  3758. * @property {object|array} columns Recommended place to store shared column meta data. @since 2.27
  3759. * @property {object} data Metadata, i.e. properties that may be passed to `source` in addition to a children array.
  3760. * @property {object} ext Hash of all active plugin instances.
  3761. * @property {FancytreeNode} focusNode Currently focused node or null.
  3762. * @property {FancytreeNode} lastSelectedNode Used to implement selectMode 1 (single select)
  3763. * @property {string} nodeContainerAttrName Property name of FancytreeNode that contains the outer element of single nodes.
  3764. * Typically "li", but "tr" for table extension.
  3765. * @property {FancytreeOptions} options Current options, i.e. default options + options passed to constructor.
  3766. * @property {FancytreeNode} rootNode Invisible system root node.
  3767. * @property {string} statusClassPropName Property name of FancytreeNode that contains the element which will receive the status classes.
  3768. * Typically "span", but "tr" for table extension.
  3769. * @property {object} types Map for shared type specific meta data, used with node.type attribute. @since 2.27
  3770. * @property {object} viewport See ext-vieport. @since v2.31
  3771. * @property {object} widget Base widget instance.
  3772. */
  3773. function Fancytree(widget) {
  3774. this.widget = widget;
  3775. this.$div = widget.element;
  3776. this.options = widget.options;
  3777. if (this.options) {
  3778. if (this.options.lazyload !== undefined) {
  3779. $.error(
  3780. "The 'lazyload' event is deprecated since 2014-02-25. Use 'lazyLoad' (with uppercase L) instead."
  3781. );
  3782. }
  3783. if (this.options.loaderror !== undefined) {
  3784. $.error(
  3785. "The 'loaderror' event was renamed since 2014-07-03. Use 'loadError' (with uppercase E) instead."
  3786. );
  3787. }
  3788. if (this.options.fx !== undefined) {
  3789. $.error(
  3790. "The 'fx' option was replaced by 'toggleEffect' since 2014-11-30."
  3791. );
  3792. }
  3793. if (this.options.removeNode !== undefined) {
  3794. $.error(
  3795. "The 'removeNode' event was replaced by 'modifyChild' since 2.20 (2016-09-10)."
  3796. );
  3797. }
  3798. }
  3799. this.ext = {}; // Active extension instances
  3800. this.types = {};
  3801. this.columns = {};
  3802. // allow to init tree.data.foo from <div data-foo=''>
  3803. this.data = _getElementDataAsDict(this.$div);
  3804. // TODO: use widget.uuid instead?
  3805. this._id = "" + (this.options.treeId || $.ui.fancytree._nextId++);
  3806. // TODO: use widget.eventNamespace instead?
  3807. this._ns = ".fancytree-" + this._id; // append for namespaced events
  3808. this.activeNode = null;
  3809. this.focusNode = null;
  3810. this._hasFocus = null;
  3811. this._tempCache = {};
  3812. this._lastMousedownNode = null;
  3813. this._enableUpdate = true;
  3814. this.lastSelectedNode = null;
  3815. this.systemFocusElement = null;
  3816. this.lastQuicksearchTerm = "";
  3817. this.lastQuicksearchTime = 0;
  3818. this.viewport = null; // ext-grid
  3819. this.statusClassPropName = "span";
  3820. this.ariaPropName = "li";
  3821. this.nodeContainerAttrName = "li";
  3822. // Remove previous markup if any
  3823. this.$div.find(">ul.fancytree-container").remove();
  3824. // Create a node without parent.
  3825. var fakeParent = { tree: this },
  3826. $ul;
  3827. this.rootNode = new FancytreeNode(fakeParent, {
  3828. title: "root",
  3829. key: "root_" + this._id,
  3830. children: null,
  3831. expanded: true,
  3832. });
  3833. this.rootNode.parent = null;
  3834. // Create root markup
  3835. $ul = $("<ul>", {
  3836. id: "ft-id-" + this._id,
  3837. class: "ui-fancytree fancytree-container fancytree-plain",
  3838. }).appendTo(this.$div);
  3839. this.$container = $ul;
  3840. this.rootNode.ul = $ul[0];
  3841. if (this.options.debugLevel == null) {
  3842. this.options.debugLevel = FT.debugLevel;
  3843. }
  3844. // // Add container to the TAB chain
  3845. // // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  3846. // // #577: Allow to set tabindex to "0", "-1" and ""
  3847. // this.$container.attr("tabindex", this.options.tabindex);
  3848. // if( this.options.rtl ) {
  3849. // this.$container.attr("DIR", "RTL").addClass("fancytree-rtl");
  3850. // // }else{
  3851. // // this.$container.attr("DIR", null).removeClass("fancytree-rtl");
  3852. // }
  3853. // if(this.options.aria){
  3854. // this.$container.attr("role", "tree");
  3855. // if( this.options.selectMode !== 1 ) {
  3856. // this.$container.attr("aria-multiselectable", true);
  3857. // }
  3858. // }
  3859. }
  3860. Fancytree.prototype = /** @lends Fancytree# */ {
  3861. /* Return a context object that can be re-used for _callHook().
  3862. * @param {Fancytree | FancytreeNode | EventData} obj
  3863. * @param {Event} originalEvent
  3864. * @param {Object} extra
  3865. * @returns {EventData}
  3866. */
  3867. _makeHookContext: function (obj, originalEvent, extra) {
  3868. var ctx, tree;
  3869. if (obj.node !== undefined) {
  3870. // obj is already a context object
  3871. if (originalEvent && obj.originalEvent !== originalEvent) {
  3872. $.error("invalid args");
  3873. }
  3874. ctx = obj;
  3875. } else if (obj.tree) {
  3876. // obj is a FancytreeNode
  3877. tree = obj.tree;
  3878. ctx = {
  3879. node: obj,
  3880. tree: tree,
  3881. widget: tree.widget,
  3882. options: tree.widget.options,
  3883. originalEvent: originalEvent,
  3884. typeInfo: tree.types[obj.type] || {},
  3885. };
  3886. } else if (obj.widget) {
  3887. // obj is a Fancytree
  3888. ctx = {
  3889. node: null,
  3890. tree: obj,
  3891. widget: obj.widget,
  3892. options: obj.widget.options,
  3893. originalEvent: originalEvent,
  3894. };
  3895. } else {
  3896. $.error("invalid args");
  3897. }
  3898. if (extra) {
  3899. $.extend(ctx, extra);
  3900. }
  3901. return ctx;
  3902. },
  3903. /* Trigger a hook function: funcName(ctx, [...]).
  3904. *
  3905. * @param {string} funcName
  3906. * @param {Fancytree|FancytreeNode|EventData} contextObject
  3907. * @param {any} [_extraArgs] optional additional arguments
  3908. * @returns {any}
  3909. */
  3910. _callHook: function (funcName, contextObject, _extraArgs) {
  3911. var ctx = this._makeHookContext(contextObject),
  3912. fn = this[funcName],
  3913. args = Array.prototype.slice.call(arguments, 2);
  3914. if (!_isFunction(fn)) {
  3915. $.error("_callHook('" + funcName + "') is not a function");
  3916. }
  3917. args.unshift(ctx);
  3918. // this.debug("_hook", funcName, ctx.node && ctx.node.toString() || ctx.tree.toString(), args);
  3919. return fn.apply(this, args);
  3920. },
  3921. _setExpiringValue: function (key, value, ms) {
  3922. this._tempCache[key] = {
  3923. value: value,
  3924. expire: Date.now() + (+ms || 50),
  3925. };
  3926. },
  3927. _getExpiringValue: function (key) {
  3928. var entry = this._tempCache[key];
  3929. if (entry && entry.expire > Date.now()) {
  3930. return entry.value;
  3931. }
  3932. delete this._tempCache[key];
  3933. return null;
  3934. },
  3935. /* Check if this tree has extension `name` enabled.
  3936. *
  3937. * @param {string} name name of the required extension
  3938. */
  3939. _usesExtension: function (name) {
  3940. return $.inArray(name, this.options.extensions) >= 0;
  3941. },
  3942. /* Check if current extensions dependencies are met and throw an error if not.
  3943. *
  3944. * This method may be called inside the `treeInit` hook for custom extensions.
  3945. *
  3946. * @param {string} name name of the required extension
  3947. * @param {boolean} [required=true] pass `false` if the extension is optional, but we want to check for order if it is present
  3948. * @param {boolean} [before] `true` if `name` must be included before this, `false` otherwise (use `null` if order doesn't matter)
  3949. * @param {string} [message] optional error message (defaults to a descriptve error message)
  3950. */
  3951. _requireExtension: function (name, required, before, message) {
  3952. if (before != null) {
  3953. before = !!before;
  3954. }
  3955. var thisName = this._local.name,
  3956. extList = this.options.extensions,
  3957. isBefore =
  3958. $.inArray(name, extList) < $.inArray(thisName, extList),
  3959. isMissing = required && this.ext[name] == null,
  3960. badOrder = !isMissing && before != null && before !== isBefore;
  3961. _assert(
  3962. thisName && thisName !== name,
  3963. "invalid or same name '" + thisName + "' (require yourself?)"
  3964. );
  3965. if (isMissing || badOrder) {
  3966. if (!message) {
  3967. if (isMissing || required) {
  3968. message =
  3969. "'" +
  3970. thisName +
  3971. "' extension requires '" +
  3972. name +
  3973. "'";
  3974. if (badOrder) {
  3975. message +=
  3976. " to be registered " +
  3977. (before ? "before" : "after") +
  3978. " itself";
  3979. }
  3980. } else {
  3981. message =
  3982. "If used together, `" +
  3983. name +
  3984. "` must be registered " +
  3985. (before ? "before" : "after") +
  3986. " `" +
  3987. thisName +
  3988. "`";
  3989. }
  3990. }
  3991. $.error(message);
  3992. return false;
  3993. }
  3994. return true;
  3995. },
  3996. /** Activate node with a given key and fire focus and activate events.
  3997. *
  3998. * A previously activated node will be deactivated.
  3999. * If activeVisible option is set, all parents will be expanded as necessary.
  4000. * Pass key = false, to deactivate the current node only.
  4001. * @param {string} key
  4002. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  4003. * @returns {FancytreeNode} activated node (null, if not found)
  4004. */
  4005. activateKey: function (key, opts) {
  4006. var node = this.getNodeByKey(key);
  4007. if (node) {
  4008. node.setActive(true, opts);
  4009. } else if (this.activeNode) {
  4010. this.activeNode.setActive(false, opts);
  4011. }
  4012. return node;
  4013. },
  4014. /** (experimental) Add child status nodes that indicate 'More...', ....
  4015. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  4016. * @param {string} [mode='append'] 'child'|firstChild'
  4017. * @since 2.15
  4018. */
  4019. addPagingNode: function (node, mode) {
  4020. return this.rootNode.addPagingNode(node, mode);
  4021. },
  4022. /**
  4023. * (experimental) Apply a modification (or navigation) operation.
  4024. *
  4025. * Valid commands:
  4026. * - 'moveUp', 'moveDown'
  4027. * - 'indent', 'outdent'
  4028. * - 'remove'
  4029. * - 'edit', 'addChild', 'addSibling': (reqires ext-edit extension)
  4030. * - 'cut', 'copy', 'paste': (use an internal singleton 'clipboard')
  4031. * - 'down', 'first', 'last', 'left', 'parent', 'right', 'up': navigate
  4032. *
  4033. * @param {string} cmd
  4034. * @param {FancytreeNode} [node=active_node]
  4035. * @param {object} [opts] Currently unused
  4036. *
  4037. * @since 2.32
  4038. */
  4039. applyCommand: function (cmd, node, opts_) {
  4040. var // clipboard,
  4041. refNode;
  4042. // opts = $.extend(
  4043. // { setActive: true, clipboard: CLIPBOARD },
  4044. // opts_
  4045. // );
  4046. node = node || this.getActiveNode();
  4047. // clipboard = opts.clipboard;
  4048. switch (cmd) {
  4049. // Sorting and indentation:
  4050. case "moveUp":
  4051. refNode = node.getPrevSibling();
  4052. if (refNode) {
  4053. node.moveTo(refNode, "before");
  4054. node.setActive();
  4055. }
  4056. break;
  4057. case "moveDown":
  4058. refNode = node.getNextSibling();
  4059. if (refNode) {
  4060. node.moveTo(refNode, "after");
  4061. node.setActive();
  4062. }
  4063. break;
  4064. case "indent":
  4065. refNode = node.getPrevSibling();
  4066. if (refNode) {
  4067. node.moveTo(refNode, "child");
  4068. refNode.setExpanded();
  4069. node.setActive();
  4070. }
  4071. break;
  4072. case "outdent":
  4073. if (!node.isTopLevel()) {
  4074. node.moveTo(node.getParent(), "after");
  4075. node.setActive();
  4076. }
  4077. break;
  4078. // Remove:
  4079. case "remove":
  4080. refNode = node.getPrevSibling() || node.getParent();
  4081. node.remove();
  4082. if (refNode) {
  4083. refNode.setActive();
  4084. }
  4085. break;
  4086. // Add, edit (requires ext-edit):
  4087. case "addChild":
  4088. node.editCreateNode("child", "");
  4089. break;
  4090. case "addSibling":
  4091. node.editCreateNode("after", "");
  4092. break;
  4093. case "rename":
  4094. node.editStart();
  4095. break;
  4096. // Simple clipboard simulation:
  4097. // case "cut":
  4098. // clipboard = { mode: cmd, data: node };
  4099. // break;
  4100. // case "copy":
  4101. // clipboard = {
  4102. // mode: cmd,
  4103. // data: node.toDict(function(d, n) {
  4104. // delete d.key;
  4105. // }),
  4106. // };
  4107. // break;
  4108. // case "clear":
  4109. // clipboard = null;
  4110. // break;
  4111. // case "paste":
  4112. // if (clipboard.mode === "cut") {
  4113. // // refNode = node.getPrevSibling();
  4114. // clipboard.data.moveTo(node, "child");
  4115. // clipboard.data.setActive();
  4116. // } else if (clipboard.mode === "copy") {
  4117. // node.addChildren(clipboard.data).setActive();
  4118. // }
  4119. // break;
  4120. // Navigation commands:
  4121. case "down":
  4122. case "first":
  4123. case "last":
  4124. case "left":
  4125. case "parent":
  4126. case "right":
  4127. case "up":
  4128. return node.navigate(cmd);
  4129. default:
  4130. $.error("Unhandled command: '" + cmd + "'");
  4131. }
  4132. },
  4133. /** (experimental) Modify existing data model.
  4134. *
  4135. * @param {Array} patchList array of [key, NodePatch] arrays
  4136. * @returns {$.Promise} resolved, when all patches have been applied
  4137. * @see TreePatch
  4138. */
  4139. applyPatch: function (patchList) {
  4140. var dfd,
  4141. i,
  4142. p2,
  4143. key,
  4144. patch,
  4145. node,
  4146. patchCount = patchList.length,
  4147. deferredList = [];
  4148. for (i = 0; i < patchCount; i++) {
  4149. p2 = patchList[i];
  4150. _assert(
  4151. p2.length === 2,
  4152. "patchList must be an array of length-2-arrays"
  4153. );
  4154. key = p2[0];
  4155. patch = p2[1];
  4156. node = key === null ? this.rootNode : this.getNodeByKey(key);
  4157. if (node) {
  4158. dfd = new $.Deferred();
  4159. deferredList.push(dfd);
  4160. node.applyPatch(patch).always(_makeResolveFunc(dfd, node));
  4161. } else {
  4162. this.warn("could not find node with key '" + key + "'");
  4163. }
  4164. }
  4165. // Return a promise that is resolved, when ALL patches were applied
  4166. return $.when.apply($, deferredList).promise();
  4167. },
  4168. /* TODO: implement in dnd extension
  4169. cancelDrag: function() {
  4170. var dd = $.ui.ddmanager.current;
  4171. if(dd){
  4172. dd.cancel();
  4173. }
  4174. },
  4175. */
  4176. /** Remove all nodes.
  4177. * @since 2.14
  4178. */
  4179. clear: function (source) {
  4180. this._callHook("treeClear", this);
  4181. },
  4182. /** Return the number of nodes.
  4183. * @returns {integer}
  4184. */
  4185. count: function () {
  4186. return this.rootNode.countChildren();
  4187. },
  4188. /** Write to browser console if debugLevel >= 4 (prepending tree name)
  4189. *
  4190. * @param {*} msg string or object or array of such
  4191. */
  4192. debug: function (msg) {
  4193. if (this.options.debugLevel >= 4) {
  4194. Array.prototype.unshift.call(arguments, this.toString());
  4195. consoleApply("log", arguments);
  4196. }
  4197. },
  4198. /** Destroy this widget, restore previous markup and cleanup resources.
  4199. *
  4200. * @since 2.34
  4201. */
  4202. destroy: function () {
  4203. this.widget.destroy();
  4204. },
  4205. /** Enable (or disable) the tree control.
  4206. *
  4207. * @param {boolean} [flag=true] pass false to disable
  4208. * @since 2.30
  4209. */
  4210. enable: function (flag) {
  4211. if (flag === false) {
  4212. this.widget.disable();
  4213. } else {
  4214. this.widget.enable();
  4215. }
  4216. },
  4217. /** Temporarily suppress rendering to improve performance on bulk-updates.
  4218. *
  4219. * @param {boolean} flag
  4220. * @returns {boolean} previous status
  4221. * @since 2.19
  4222. */
  4223. enableUpdate: function (flag) {
  4224. flag = flag !== false;
  4225. if (!!this._enableUpdate === !!flag) {
  4226. return flag;
  4227. }
  4228. this._enableUpdate = flag;
  4229. if (flag) {
  4230. this.debug("enableUpdate(true): redraw "); //, this._dirtyRoots);
  4231. this._callHook("treeStructureChanged", this, "enableUpdate");
  4232. this.render();
  4233. } else {
  4234. // this._dirtyRoots = null;
  4235. this.debug("enableUpdate(false)...");
  4236. }
  4237. return !flag; // return previous value
  4238. },
  4239. /** Write error to browser console if debugLevel >= 1 (prepending tree info)
  4240. *
  4241. * @param {*} msg string or object or array of such
  4242. */
  4243. error: function (msg) {
  4244. if (this.options.debugLevel >= 1) {
  4245. Array.prototype.unshift.call(arguments, this.toString());
  4246. consoleApply("error", arguments);
  4247. }
  4248. },
  4249. /** Expand (or collapse) all parent nodes.
  4250. *
  4251. * This convenience method uses `tree.visit()` and `tree.setExpanded()`
  4252. * internally.
  4253. *
  4254. * @param {boolean} [flag=true] pass false to collapse
  4255. * @param {object} [opts] passed to setExpanded()
  4256. * @since 2.30
  4257. */
  4258. expandAll: function (flag, opts) {
  4259. var prev = this.enableUpdate(false);
  4260. flag = flag !== false;
  4261. this.visit(function (node) {
  4262. if (
  4263. node.hasChildren() !== false &&
  4264. node.isExpanded() !== flag
  4265. ) {
  4266. node.setExpanded(flag, opts);
  4267. }
  4268. });
  4269. this.enableUpdate(prev);
  4270. },
  4271. /**Find all nodes that matches condition.
  4272. *
  4273. * @param {string | function(node)} match title string to search for, or a
  4274. * callback function that returns `true` if a node is matched.
  4275. * @returns {FancytreeNode[]} array of nodes (may be empty)
  4276. * @see FancytreeNode#findAll
  4277. * @since 2.12
  4278. */
  4279. findAll: function (match) {
  4280. return this.rootNode.findAll(match);
  4281. },
  4282. /**Find first node that matches condition.
  4283. *
  4284. * @param {string | function(node)} match title string to search for, or a
  4285. * callback function that returns `true` if a node is matched.
  4286. * @returns {FancytreeNode} matching node or null
  4287. * @see FancytreeNode#findFirst
  4288. * @since 2.12
  4289. */
  4290. findFirst: function (match) {
  4291. return this.rootNode.findFirst(match);
  4292. },
  4293. /** Find the next visible node that starts with `match`, starting at `startNode`
  4294. * and wrap-around at the end.
  4295. *
  4296. * @param {string|function} match
  4297. * @param {FancytreeNode} [startNode] defaults to first node
  4298. * @returns {FancytreeNode} matching node or null
  4299. */
  4300. findNextNode: function (match, startNode) {
  4301. //, visibleOnly) {
  4302. var res = null,
  4303. firstNode = this.getFirstChild();
  4304. match =
  4305. typeof match === "string"
  4306. ? _makeNodeTitleStartMatcher(match)
  4307. : match;
  4308. startNode = startNode || firstNode;
  4309. function _checkNode(n) {
  4310. // console.log("_check " + n)
  4311. if (match(n)) {
  4312. res = n;
  4313. }
  4314. if (res || n === startNode) {
  4315. return false;
  4316. }
  4317. }
  4318. this.visitRows(_checkNode, {
  4319. start: startNode,
  4320. includeSelf: false,
  4321. });
  4322. // Wrap around search
  4323. if (!res && startNode !== firstNode) {
  4324. this.visitRows(_checkNode, {
  4325. start: firstNode,
  4326. includeSelf: true,
  4327. });
  4328. }
  4329. return res;
  4330. },
  4331. /** Find a node relative to another node.
  4332. *
  4333. * @param {FancytreeNode} node
  4334. * @param {string|number} where 'down', 'first', 'last', 'left', 'parent', 'right', or 'up'.
  4335. * (Alternatively the keyCode that would normally trigger this move,
  4336. * e.g. `$.ui.keyCode.LEFT` = 'left'.
  4337. * @param {boolean} [includeHidden=false] Not yet implemented
  4338. * @returns {FancytreeNode|null}
  4339. * @since v2.31
  4340. */
  4341. findRelatedNode: function (node, where, includeHidden) {
  4342. var res = null,
  4343. KC = $.ui.keyCode;
  4344. switch (where) {
  4345. case "parent":
  4346. case KC.BACKSPACE:
  4347. if (node.parent && node.parent.parent) {
  4348. res = node.parent;
  4349. }
  4350. break;
  4351. case "first":
  4352. case KC.HOME:
  4353. // First visible node
  4354. this.visit(function (n) {
  4355. if (n.isVisible()) {
  4356. res = n;
  4357. return false;
  4358. }
  4359. });
  4360. break;
  4361. case "last":
  4362. case KC.END:
  4363. this.visit(function (n) {
  4364. // last visible node
  4365. if (n.isVisible()) {
  4366. res = n;
  4367. }
  4368. });
  4369. break;
  4370. case "left":
  4371. case KC.LEFT:
  4372. if (node.expanded) {
  4373. node.setExpanded(false);
  4374. } else if (node.parent && node.parent.parent) {
  4375. res = node.parent;
  4376. }
  4377. break;
  4378. case "right":
  4379. case KC.RIGHT:
  4380. if (!node.expanded && (node.children || node.lazy)) {
  4381. node.setExpanded();
  4382. res = node;
  4383. } else if (node.children && node.children.length) {
  4384. res = node.children[0];
  4385. }
  4386. break;
  4387. case "up":
  4388. case KC.UP:
  4389. this.visitRows(
  4390. function (n) {
  4391. res = n;
  4392. return false;
  4393. },
  4394. { start: node, reverse: true, includeSelf: false }
  4395. );
  4396. break;
  4397. case "down":
  4398. case KC.DOWN:
  4399. this.visitRows(
  4400. function (n) {
  4401. res = n;
  4402. return false;
  4403. },
  4404. { start: node, includeSelf: false }
  4405. );
  4406. break;
  4407. default:
  4408. this.tree.warn("Unknown relation '" + where + "'.");
  4409. }
  4410. return res;
  4411. },
  4412. // TODO: fromDict
  4413. /**
  4414. * Generate INPUT elements that can be submitted with html forms.
  4415. *
  4416. * In selectMode 3 only the topmost selected nodes are considered, unless
  4417. * `opts.stopOnParents: false` is passed.
  4418. *
  4419. * @example
  4420. * // Generate input elements for active and selected nodes
  4421. * tree.generateFormElements();
  4422. * // Generate input elements selected nodes, using a custom `name` attribute
  4423. * tree.generateFormElements("cust_sel", false);
  4424. * // Generate input elements using a custom filter
  4425. * tree.generateFormElements(true, true, { filter: function(node) {
  4426. * return node.isSelected() && node.data.yes;
  4427. * }});
  4428. *
  4429. * @param {boolean | string} [selected=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID[]')
  4430. * @param {boolean | string} [active=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID_active')
  4431. * @param {object} [opts] default { filter: null, stopOnParents: true }
  4432. */
  4433. generateFormElements: function (selected, active, opts) {
  4434. opts = opts || {};
  4435. var nodeList,
  4436. selectedName =
  4437. typeof selected === "string"
  4438. ? selected
  4439. : "ft_" + this._id + "[]",
  4440. activeName =
  4441. typeof active === "string"
  4442. ? active
  4443. : "ft_" + this._id + "_active",
  4444. id = "fancytree_result_" + this._id,
  4445. $result = $("#" + id),
  4446. stopOnParents =
  4447. this.options.selectMode === 3 &&
  4448. opts.stopOnParents !== false;
  4449. if ($result.length) {
  4450. $result.empty();
  4451. } else {
  4452. $result = $("<div>", {
  4453. id: id,
  4454. })
  4455. .hide()
  4456. .insertAfter(this.$container);
  4457. }
  4458. if (active !== false && this.activeNode) {
  4459. $result.append(
  4460. $("<input>", {
  4461. type: "radio",
  4462. name: activeName,
  4463. value: this.activeNode.key,
  4464. checked: true,
  4465. })
  4466. );
  4467. }
  4468. function _appender(node) {
  4469. $result.append(
  4470. $("<input>", {
  4471. type: "checkbox",
  4472. name: selectedName,
  4473. value: node.key,
  4474. checked: true,
  4475. })
  4476. );
  4477. }
  4478. if (opts.filter) {
  4479. this.visit(function (node) {
  4480. var res = opts.filter(node);
  4481. if (res === "skip") {
  4482. return res;
  4483. }
  4484. if (res !== false) {
  4485. _appender(node);
  4486. }
  4487. });
  4488. } else if (selected !== false) {
  4489. nodeList = this.getSelectedNodes(stopOnParents);
  4490. $.each(nodeList, function (idx, node) {
  4491. _appender(node);
  4492. });
  4493. }
  4494. },
  4495. /**
  4496. * Return the currently active node or null.
  4497. * @returns {FancytreeNode}
  4498. */
  4499. getActiveNode: function () {
  4500. return this.activeNode;
  4501. },
  4502. /** Return the first top level node if any (not the invisible root node).
  4503. * @returns {FancytreeNode | null}
  4504. */
  4505. getFirstChild: function () {
  4506. return this.rootNode.getFirstChild();
  4507. },
  4508. /**
  4509. * Return node that has keyboard focus or null.
  4510. * @returns {FancytreeNode}
  4511. */
  4512. getFocusNode: function () {
  4513. return this.focusNode;
  4514. },
  4515. /**
  4516. * Return current option value.
  4517. * (Note: this is the preferred variant of `$().fancytree("option", "KEY")`)
  4518. *
  4519. * @param {string} name option name (may contain '.')
  4520. * @returns {any}
  4521. */
  4522. getOption: function (optionName) {
  4523. return this.widget.option(optionName);
  4524. },
  4525. /**
  4526. * Return node with a given key or null if not found.
  4527. *
  4528. * @param {string} key
  4529. * @param {FancytreeNode} [searchRoot] only search below this node
  4530. * @returns {FancytreeNode | null}
  4531. */
  4532. getNodeByKey: function (key, searchRoot) {
  4533. // Search the DOM by element ID (assuming this is faster than traversing all nodes).
  4534. var el, match;
  4535. // TODO: use tree.keyMap if available
  4536. // TODO: check opts.generateIds === true
  4537. if (!searchRoot) {
  4538. el = document.getElementById(this.options.idPrefix + key);
  4539. if (el) {
  4540. return el.ftnode ? el.ftnode : null;
  4541. }
  4542. }
  4543. // Not found in the DOM, but still may be in an unrendered part of tree
  4544. searchRoot = searchRoot || this.rootNode;
  4545. match = null;
  4546. key = "" + key; // Convert to string (#1005)
  4547. searchRoot.visit(function (node) {
  4548. if (node.key === key) {
  4549. match = node;
  4550. return false; // Stop iteration
  4551. }
  4552. }, true);
  4553. return match;
  4554. },
  4555. /** Return the invisible system root node.
  4556. * @returns {FancytreeNode}
  4557. */
  4558. getRootNode: function () {
  4559. return this.rootNode;
  4560. },
  4561. /**
  4562. * Return an array of selected nodes.
  4563. *
  4564. * Note: you cannot send this result via Ajax directly. Instead the
  4565. * node object need to be converted to plain objects, for example
  4566. * by using `$.map()` and `node.toDict()`.
  4567. * @param {boolean} [stopOnParents=false] only return the topmost selected
  4568. * node (useful with selectMode 3)
  4569. * @returns {FancytreeNode[]}
  4570. */
  4571. getSelectedNodes: function (stopOnParents) {
  4572. return this.rootNode.getSelectedNodes(stopOnParents);
  4573. },
  4574. /** Return true if the tree control has keyboard focus
  4575. * @returns {boolean}
  4576. */
  4577. hasFocus: function () {
  4578. // var ae = document.activeElement,
  4579. // hasFocus = !!(
  4580. // ae && $(ae).closest(".fancytree-container").length
  4581. // );
  4582. // if (hasFocus !== !!this._hasFocus) {
  4583. // this.warn(
  4584. // "hasFocus(): fix inconsistent container state, now: " +
  4585. // hasFocus
  4586. // );
  4587. // this._hasFocus = hasFocus;
  4588. // this.$container.toggleClass("fancytree-treefocus", hasFocus);
  4589. // }
  4590. // return hasFocus;
  4591. return !!this._hasFocus;
  4592. },
  4593. /** Write to browser console if debugLevel >= 3 (prepending tree name)
  4594. * @param {*} msg string or object or array of such
  4595. */
  4596. info: function (msg) {
  4597. if (this.options.debugLevel >= 3) {
  4598. Array.prototype.unshift.call(arguments, this.toString());
  4599. consoleApply("info", arguments);
  4600. }
  4601. },
  4602. /** Return true if any node is currently beeing loaded, i.e. a Ajax request is pending.
  4603. * @returns {boolean}
  4604. * @since 2.32
  4605. */
  4606. isLoading: function () {
  4607. var res = false;
  4608. this.rootNode.visit(function (n) {
  4609. // also visit rootNode
  4610. if (n._isLoading || n._requestId) {
  4611. res = true;
  4612. return false;
  4613. }
  4614. }, true);
  4615. return res;
  4616. },
  4617. /*
  4618. TODO: isInitializing: function() {
  4619. return ( this.phase=="init" || this.phase=="postInit" );
  4620. },
  4621. TODO: isReloading: function() {
  4622. return ( this.phase=="init" || this.phase=="postInit" ) && this.options.persist && this.persistence.cookiesFound;
  4623. },
  4624. TODO: isUserEvent: function() {
  4625. return ( this.phase=="userEvent" );
  4626. },
  4627. */
  4628. /**
  4629. * Make sure that a node with a given ID is loaded, by traversing - and
  4630. * loading - its parents. This method is meant for lazy hierarchies.
  4631. * A callback is executed for every node as we go.
  4632. * @example
  4633. * // Resolve using node.key:
  4634. * tree.loadKeyPath("/_3/_23/_26/_27", function(node, status){
  4635. * if(status === "loaded") {
  4636. * console.log("loaded intermediate node " + node);
  4637. * }else if(status === "ok") {
  4638. * node.activate();
  4639. * }
  4640. * });
  4641. * // Use deferred promise:
  4642. * tree.loadKeyPath("/_3/_23/_26/_27").progress(function(data){
  4643. * if(data.status === "loaded") {
  4644. * console.log("loaded intermediate node " + data.node);
  4645. * }else if(data.status === "ok") {
  4646. * node.activate();
  4647. * }
  4648. * }).done(function(){
  4649. * ...
  4650. * });
  4651. * // Custom path segment resolver:
  4652. * tree.loadKeyPath("/321/431/21/2", {
  4653. * matchKey: function(node, key){
  4654. * return node.data.refKey === key;
  4655. * },
  4656. * callback: function(node, status){
  4657. * if(status === "loaded") {
  4658. * console.log("loaded intermediate node " + node);
  4659. * }else if(status === "ok") {
  4660. * node.activate();
  4661. * }
  4662. * }
  4663. * });
  4664. * @param {string | string[]} keyPathList one or more key paths (e.g. '/3/2_1/7')
  4665. * @param {function | object} optsOrCallback callback(node, status) is called for every visited node ('loading', 'loaded', 'ok', 'error').
  4666. * Pass an object to define custom key matchers for the path segments: {callback: function, matchKey: function}.
  4667. * @returns {$.Promise}
  4668. */
  4669. loadKeyPath: function (keyPathList, optsOrCallback) {
  4670. var callback,
  4671. i,
  4672. path,
  4673. self = this,
  4674. dfd = new $.Deferred(),
  4675. parent = this.getRootNode(),
  4676. sep = this.options.keyPathSeparator,
  4677. pathSegList = [],
  4678. opts = $.extend({}, optsOrCallback);
  4679. // Prepare options
  4680. if (typeof optsOrCallback === "function") {
  4681. callback = optsOrCallback;
  4682. } else if (optsOrCallback && optsOrCallback.callback) {
  4683. callback = optsOrCallback.callback;
  4684. }
  4685. opts.callback = function (ctx, node, status) {
  4686. if (callback) {
  4687. callback.call(ctx, node, status);
  4688. }
  4689. dfd.notifyWith(ctx, [{ node: node, status: status }]);
  4690. };
  4691. if (opts.matchKey == null) {
  4692. opts.matchKey = function (node, key) {
  4693. return node.key === key;
  4694. };
  4695. }
  4696. // Convert array of path strings to array of segment arrays
  4697. if (!_isArray(keyPathList)) {
  4698. keyPathList = [keyPathList];
  4699. }
  4700. for (i = 0; i < keyPathList.length; i++) {
  4701. path = keyPathList[i];
  4702. // strip leading slash
  4703. if (path.charAt(0) === sep) {
  4704. path = path.substr(1);
  4705. }
  4706. // segListMap[path] = { parent: parent, segList: path.split(sep) };
  4707. pathSegList.push(path.split(sep));
  4708. // targetList.push({ parent: parent, segList: path.split(sep)/* , path: path*/});
  4709. }
  4710. // The timeout forces async behavior always (even if nodes are all loaded)
  4711. // This way a potential progress() event will fire.
  4712. setTimeout(function () {
  4713. self._loadKeyPathImpl(dfd, opts, parent, pathSegList).done(
  4714. function () {
  4715. dfd.resolve();
  4716. }
  4717. );
  4718. }, 0);
  4719. return dfd.promise();
  4720. },
  4721. /*
  4722. * Resolve a list of paths, relative to one parent node.
  4723. */
  4724. _loadKeyPathImpl: function (dfd, opts, parent, pathSegList) {
  4725. var deferredList,
  4726. i,
  4727. key,
  4728. node,
  4729. nodeKey,
  4730. remain,
  4731. remainMap,
  4732. tmpParent,
  4733. segList,
  4734. subDfd,
  4735. self = this;
  4736. function __findChild(parent, key) {
  4737. // console.log("__findChild", key, parent);
  4738. var i,
  4739. l,
  4740. cl = parent.children;
  4741. if (cl) {
  4742. for (i = 0, l = cl.length; i < l; i++) {
  4743. if (opts.matchKey(cl[i], key)) {
  4744. return cl[i];
  4745. }
  4746. }
  4747. }
  4748. return null;
  4749. }
  4750. // console.log("_loadKeyPathImpl, parent=", parent, ", pathSegList=", pathSegList);
  4751. // Pass 1:
  4752. // Handle all path segments for nodes that are already loaded.
  4753. // Collect distinct top-most lazy nodes in a map.
  4754. // Note that we can use node.key to de-dupe entries, even if a custom matcher would
  4755. // look for other node attributes.
  4756. // map[node.key] => {node: node, pathList: [list of remaining rest-paths]}
  4757. remainMap = {};
  4758. for (i = 0; i < pathSegList.length; i++) {
  4759. segList = pathSegList[i];
  4760. // target = targetList[i];
  4761. // Traverse and pop path segments (i.e. keys), until we hit a lazy, unloaded node
  4762. tmpParent = parent;
  4763. while (segList.length) {
  4764. key = segList.shift();
  4765. node = __findChild(tmpParent, key);
  4766. if (!node) {
  4767. this.warn(
  4768. "loadKeyPath: key not found: " +
  4769. key +
  4770. " (parent: " +
  4771. tmpParent +
  4772. ")"
  4773. );
  4774. opts.callback(this, key, "error");
  4775. break;
  4776. } else if (segList.length === 0) {
  4777. opts.callback(this, node, "ok");
  4778. break;
  4779. } else if (!node.lazy || node.hasChildren() !== undefined) {
  4780. opts.callback(this, node, "loaded");
  4781. tmpParent = node;
  4782. } else {
  4783. opts.callback(this, node, "loaded");
  4784. key = node.key; //target.segList.join(sep);
  4785. if (remainMap[key]) {
  4786. remainMap[key].pathSegList.push(segList);
  4787. } else {
  4788. remainMap[key] = {
  4789. parent: node,
  4790. pathSegList: [segList],
  4791. };
  4792. }
  4793. break;
  4794. }
  4795. }
  4796. }
  4797. // console.log("_loadKeyPathImpl AFTER pass 1, remainMap=", remainMap);
  4798. // Now load all lazy nodes and continue iteration for remaining paths
  4799. deferredList = [];
  4800. // Avoid jshint warning 'Don't make functions within a loop.':
  4801. function __lazyload(dfd, parent, pathSegList) {
  4802. // console.log("__lazyload", parent, "pathSegList=", pathSegList);
  4803. opts.callback(self, parent, "loading");
  4804. parent
  4805. .load()
  4806. .done(function () {
  4807. self._loadKeyPathImpl
  4808. .call(self, dfd, opts, parent, pathSegList)
  4809. .always(_makeResolveFunc(dfd, self));
  4810. })
  4811. .fail(function (errMsg) {
  4812. self.warn("loadKeyPath: error loading lazy " + parent);
  4813. opts.callback(self, node, "error");
  4814. dfd.rejectWith(self);
  4815. });
  4816. }
  4817. // remainMap contains parent nodes, each with a list of relative sub-paths.
  4818. // We start loading all of them now, and pass the the list to each loader.
  4819. for (nodeKey in remainMap) {
  4820. if (_hasProp(remainMap, nodeKey)) {
  4821. remain = remainMap[nodeKey];
  4822. // console.log("for(): remain=", remain, "remainMap=", remainMap);
  4823. // key = remain.segList.shift();
  4824. // node = __findChild(remain.parent, key);
  4825. // if (node == null) { // #576
  4826. // // Issue #576, refactored for v2.27:
  4827. // // The root cause was, that sometimes the wrong parent was used here
  4828. // // to find the next segment.
  4829. // // Falling back to getNodeByKey() was a hack that no longer works if a custom
  4830. // // matcher is used, because we cannot assume that a single segment-key is unique
  4831. // // throughout the tree.
  4832. // self.error("loadKeyPath: error loading child by key '" + key + "' (parent: " + target.parent + ")", target);
  4833. // // node = self.getNodeByKey(key);
  4834. // continue;
  4835. // }
  4836. subDfd = new $.Deferred();
  4837. deferredList.push(subDfd);
  4838. __lazyload(subDfd, remain.parent, remain.pathSegList);
  4839. }
  4840. }
  4841. // Return a promise that is resolved, when ALL paths were loaded
  4842. return $.when.apply($, deferredList).promise();
  4843. },
  4844. /** Re-fire beforeActivate, activate, and (optional) focus events.
  4845. * Calling this method in the `init` event, will activate the node that
  4846. * was marked 'active' in the source data, and optionally set the keyboard
  4847. * focus.
  4848. * @param [setFocus=false]
  4849. */
  4850. reactivate: function (setFocus) {
  4851. var res,
  4852. node = this.activeNode;
  4853. if (!node) {
  4854. return _getResolvedPromise();
  4855. }
  4856. this.activeNode = null; // Force re-activating
  4857. res = node.setActive(true, { noFocus: true });
  4858. if (setFocus) {
  4859. node.setFocus();
  4860. }
  4861. return res;
  4862. },
  4863. /** Reload tree from source and return a promise.
  4864. * @param [source] optional new source (defaults to initial source data)
  4865. * @returns {$.Promise}
  4866. */
  4867. reload: function (source) {
  4868. this._callHook("treeClear", this);
  4869. return this._callHook("treeLoad", this, source);
  4870. },
  4871. /**Render tree (i.e. create DOM elements for all top-level nodes).
  4872. * @param {boolean} [force=false] create DOM elemnts, even if parent is collapsed
  4873. * @param {boolean} [deep=false]
  4874. */
  4875. render: function (force, deep) {
  4876. return this.rootNode.render(force, deep);
  4877. },
  4878. /**(De)select all nodes.
  4879. * @param {boolean} [flag=true]
  4880. * @since 2.28
  4881. */
  4882. selectAll: function (flag) {
  4883. this.visit(function (node) {
  4884. node.setSelected(flag);
  4885. });
  4886. },
  4887. // TODO: selectKey: function(key, select)
  4888. // TODO: serializeArray: function(stopOnParents)
  4889. /**
  4890. * @param {boolean} [flag=true]
  4891. */
  4892. setFocus: function (flag) {
  4893. return this._callHook("treeSetFocus", this, flag);
  4894. },
  4895. /**
  4896. * Set current option value.
  4897. * (Note: this is the preferred variant of `$().fancytree("option", "KEY", VALUE)`)
  4898. * @param {string} name option name (may contain '.')
  4899. * @param {any} new value
  4900. */
  4901. setOption: function (optionName, value) {
  4902. return this.widget.option(optionName, value);
  4903. },
  4904. /**
  4905. * Call console.time() when in debug mode (verbose >= 4).
  4906. *
  4907. * @param {string} label
  4908. */
  4909. debugTime: function (label) {
  4910. if (this.options.debugLevel >= 4) {
  4911. window.console.time(this + " - " + label);
  4912. }
  4913. },
  4914. /**
  4915. * Call console.timeEnd() when in debug mode (verbose >= 4).
  4916. *
  4917. * @param {string} label
  4918. */
  4919. debugTimeEnd: function (label) {
  4920. if (this.options.debugLevel >= 4) {
  4921. window.console.timeEnd(this + " - " + label);
  4922. }
  4923. },
  4924. /**
  4925. * Return all nodes as nested list of {@link NodeData}.
  4926. *
  4927. * @param {boolean} [includeRoot=false] Returns the hidden system root node (and its children)
  4928. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications.
  4929. * Return `false` to ignore this node or "skip" to include this node without its children.
  4930. * @returns {Array | object}
  4931. * @see FancytreeNode#toDict
  4932. */
  4933. toDict: function (includeRoot, callback) {
  4934. var res = this.rootNode.toDict(true, callback);
  4935. return includeRoot ? res : res.children;
  4936. },
  4937. /* Implicitly called for string conversions.
  4938. * @returns {string}
  4939. */
  4940. toString: function () {
  4941. return "Fancytree@" + this._id;
  4942. // return "<Fancytree(#" + this._id + ")>";
  4943. },
  4944. /* _trigger a widget event with additional node ctx.
  4945. * @see EventData
  4946. */
  4947. _triggerNodeEvent: function (type, node, originalEvent, extra) {
  4948. // this.debug("_trigger(" + type + "): '" + ctx.node.title + "'", ctx);
  4949. var ctx = this._makeHookContext(node, originalEvent, extra),
  4950. res = this.widget._trigger(type, originalEvent, ctx);
  4951. if (res !== false && ctx.result !== undefined) {
  4952. return ctx.result;
  4953. }
  4954. return res;
  4955. },
  4956. /* _trigger a widget event with additional tree data. */
  4957. _triggerTreeEvent: function (type, originalEvent, extra) {
  4958. // this.debug("_trigger(" + type + ")", ctx);
  4959. var ctx = this._makeHookContext(this, originalEvent, extra),
  4960. res = this.widget._trigger(type, originalEvent, ctx);
  4961. if (res !== false && ctx.result !== undefined) {
  4962. return ctx.result;
  4963. }
  4964. return res;
  4965. },
  4966. /** Call fn(node) for all nodes in hierarchical order (depth-first).
  4967. *
  4968. * @param {function} fn the callback function.
  4969. * Return false to stop iteration, return "skip" to skip this node and children only.
  4970. * @returns {boolean} false, if the iterator was stopped.
  4971. */
  4972. visit: function (fn) {
  4973. return this.rootNode.visit(fn, false);
  4974. },
  4975. /** Call fn(node) for all nodes in vertical order, top down (or bottom up).<br>
  4976. * Stop iteration, if fn() returns false.<br>
  4977. * Return false if iteration was stopped.
  4978. *
  4979. * @param {function} fn the callback function.
  4980. * Return false to stop iteration, return "skip" to skip this node and children only.
  4981. * @param {object} [options]
  4982. * Defaults:
  4983. * {start: First top node, reverse: false, includeSelf: true, includeHidden: false}
  4984. * @returns {boolean} false if iteration was cancelled
  4985. * @since 2.28
  4986. */
  4987. visitRows: function (fn, opts) {
  4988. if (!this.rootNode.hasChildren()) {
  4989. return false;
  4990. }
  4991. if (opts && opts.reverse) {
  4992. delete opts.reverse;
  4993. return this._visitRowsUp(fn, opts);
  4994. }
  4995. opts = opts || {};
  4996. var i,
  4997. nextIdx,
  4998. parent,
  4999. res,
  5000. siblings,
  5001. siblingOfs = 0,
  5002. skipFirstNode = opts.includeSelf === false,
  5003. includeHidden = !!opts.includeHidden,
  5004. checkFilter = !includeHidden && this.enableFilter,
  5005. node = opts.start || this.rootNode.children[0];
  5006. parent = node.parent;
  5007. while (parent) {
  5008. // visit siblings
  5009. siblings = parent.children;
  5010. nextIdx = siblings.indexOf(node) + siblingOfs;
  5011. _assert(
  5012. nextIdx >= 0,
  5013. "Could not find " +
  5014. node +
  5015. " in parent's children: " +
  5016. parent
  5017. );
  5018. for (i = nextIdx; i < siblings.length; i++) {
  5019. node = siblings[i];
  5020. if (checkFilter && !node.match && !node.subMatchCount) {
  5021. continue;
  5022. }
  5023. if (!skipFirstNode && fn(node) === false) {
  5024. return false;
  5025. }
  5026. skipFirstNode = false;
  5027. // Dive into node's child nodes
  5028. if (
  5029. node.children &&
  5030. node.children.length &&
  5031. (includeHidden || node.expanded)
  5032. ) {
  5033. // Disable warning: Functions declared within loops referencing an outer
  5034. // scoped variable may lead to confusing semantics:
  5035. /*jshint -W083 */
  5036. res = node.visit(function (n) {
  5037. if (checkFilter && !n.match && !n.subMatchCount) {
  5038. return "skip";
  5039. }
  5040. if (fn(n) === false) {
  5041. return false;
  5042. }
  5043. if (!includeHidden && n.children && !n.expanded) {
  5044. return "skip";
  5045. }
  5046. }, false);
  5047. /*jshint +W083 */
  5048. if (res === false) {
  5049. return false;
  5050. }
  5051. }
  5052. }
  5053. // Visit parent nodes (bottom up)
  5054. node = parent;
  5055. parent = parent.parent;
  5056. siblingOfs = 1; //
  5057. }
  5058. return true;
  5059. },
  5060. /* Call fn(node) for all nodes in vertical order, bottom up.
  5061. */
  5062. _visitRowsUp: function (fn, opts) {
  5063. var children,
  5064. idx,
  5065. parent,
  5066. includeHidden = !!opts.includeHidden,
  5067. node = opts.start || this.rootNode.children[0];
  5068. while (true) {
  5069. parent = node.parent;
  5070. children = parent.children;
  5071. if (children[0] === node) {
  5072. // If this is already the first sibling, goto parent
  5073. node = parent;
  5074. if (!node.parent) {
  5075. break; // first node of the tree
  5076. }
  5077. children = parent.children;
  5078. } else {
  5079. // Otherwise, goto prev. sibling
  5080. idx = children.indexOf(node);
  5081. node = children[idx - 1];
  5082. // If the prev. sibling has children, follow down to last descendant
  5083. while (
  5084. // See: https://github.com/eslint/eslint/issues/11302
  5085. // eslint-disable-next-line no-unmodified-loop-condition
  5086. (includeHidden || node.expanded) &&
  5087. node.children &&
  5088. node.children.length
  5089. ) {
  5090. children = node.children;
  5091. parent = node;
  5092. node = children[children.length - 1];
  5093. }
  5094. }
  5095. // Skip invisible
  5096. if (!includeHidden && !node.isVisible()) {
  5097. continue;
  5098. }
  5099. if (fn(node) === false) {
  5100. return false;
  5101. }
  5102. }
  5103. },
  5104. /** Write warning to browser console if debugLevel >= 2 (prepending tree info)
  5105. *
  5106. * @param {*} msg string or object or array of such
  5107. */
  5108. warn: function (msg) {
  5109. if (this.options.debugLevel >= 2) {
  5110. Array.prototype.unshift.call(arguments, this.toString());
  5111. consoleApply("warn", arguments);
  5112. }
  5113. },
  5114. };
  5115. /**
  5116. * These additional methods of the {@link Fancytree} class are 'hook functions'
  5117. * that can be used and overloaded by extensions.
  5118. *
  5119. * @see [writing extensions](https://github.com/mar10/fancytree/wiki/TutorialExtensions)
  5120. * @mixin Fancytree_Hooks
  5121. */
  5122. $.extend(
  5123. Fancytree.prototype,
  5124. /** @lends Fancytree_Hooks# */
  5125. {
  5126. /** Default handling for mouse click events.
  5127. *
  5128. * @param {EventData} ctx
  5129. */
  5130. nodeClick: function (ctx) {
  5131. var activate,
  5132. expand,
  5133. // event = ctx.originalEvent,
  5134. targetType = ctx.targetType,
  5135. node = ctx.node;
  5136. // this.debug("ftnode.onClick(" + event.type + "): ftnode:" + this + ", button:" + event.button + ", which: " + event.which, ctx);
  5137. // TODO: use switch
  5138. // TODO: make sure clicks on embedded <input> doesn't steal focus (see table sample)
  5139. if (targetType === "expander") {
  5140. if (node.isLoading()) {
  5141. // #495: we probably got a click event while a lazy load is pending.
  5142. // The 'expanded' state is not yet set, so 'toggle' would expand
  5143. // and trigger lazyLoad again.
  5144. // It would be better to allow to collapse/expand the status node
  5145. // while loading (instead of ignoring), but that would require some
  5146. // more work.
  5147. node.debug("Got 2nd click while loading: ignored");
  5148. return;
  5149. }
  5150. // Clicking the expander icon always expands/collapses
  5151. this._callHook("nodeToggleExpanded", ctx);
  5152. } else if (targetType === "checkbox") {
  5153. // Clicking the checkbox always (de)selects
  5154. this._callHook("nodeToggleSelected", ctx);
  5155. if (ctx.options.focusOnSelect) {
  5156. // #358
  5157. this._callHook("nodeSetFocus", ctx, true);
  5158. }
  5159. } else {
  5160. // Honor `clickFolderMode` for
  5161. expand = false;
  5162. activate = true;
  5163. if (node.folder) {
  5164. switch (ctx.options.clickFolderMode) {
  5165. case 2: // expand only
  5166. expand = true;
  5167. activate = false;
  5168. break;
  5169. case 3: // expand and activate
  5170. activate = true;
  5171. expand = true; //!node.isExpanded();
  5172. break;
  5173. // else 1 or 4: just activate
  5174. }
  5175. }
  5176. if (activate) {
  5177. this.nodeSetFocus(ctx);
  5178. this._callHook("nodeSetActive", ctx, true);
  5179. }
  5180. if (expand) {
  5181. if (!activate) {
  5182. // this._callHook("nodeSetFocus", ctx);
  5183. }
  5184. // this._callHook("nodeSetExpanded", ctx, true);
  5185. this._callHook("nodeToggleExpanded", ctx);
  5186. }
  5187. }
  5188. // Make sure that clicks stop, otherwise <a href='#'> jumps to the top
  5189. // if(event.target.localName === "a" && event.target.className === "fancytree-title"){
  5190. // event.preventDefault();
  5191. // }
  5192. // TODO: return promise?
  5193. },
  5194. /** Collapse all other children of same parent.
  5195. *
  5196. * @param {EventData} ctx
  5197. * @param {object} callOpts
  5198. */
  5199. nodeCollapseSiblings: function (ctx, callOpts) {
  5200. // TODO: return promise?
  5201. var ac,
  5202. i,
  5203. l,
  5204. node = ctx.node;
  5205. if (node.parent) {
  5206. ac = node.parent.children;
  5207. for (i = 0, l = ac.length; i < l; i++) {
  5208. if (ac[i] !== node && ac[i].expanded) {
  5209. this._callHook(
  5210. "nodeSetExpanded",
  5211. ac[i],
  5212. false,
  5213. callOpts
  5214. );
  5215. }
  5216. }
  5217. }
  5218. },
  5219. /** Default handling for mouse douleclick events.
  5220. * @param {EventData} ctx
  5221. */
  5222. nodeDblclick: function (ctx) {
  5223. // TODO: return promise?
  5224. if (
  5225. ctx.targetType === "title" &&
  5226. ctx.options.clickFolderMode === 4
  5227. ) {
  5228. // this.nodeSetFocus(ctx);
  5229. // this._callHook("nodeSetActive", ctx, true);
  5230. this._callHook("nodeToggleExpanded", ctx);
  5231. }
  5232. // TODO: prevent text selection on dblclicks
  5233. if (ctx.targetType === "title") {
  5234. ctx.originalEvent.preventDefault();
  5235. }
  5236. },
  5237. /** Default handling for mouse keydown events.
  5238. *
  5239. * NOTE: this may be called with node == null if tree (but no node) has focus.
  5240. * @param {EventData} ctx
  5241. */
  5242. nodeKeydown: function (ctx) {
  5243. // TODO: return promise?
  5244. var matchNode,
  5245. stamp,
  5246. _res,
  5247. focusNode,
  5248. event = ctx.originalEvent,
  5249. node = ctx.node,
  5250. tree = ctx.tree,
  5251. opts = ctx.options,
  5252. which = event.which,
  5253. // #909: Use event.key, to get unicode characters.
  5254. // We can't use `/\w/.test(key)`, because that would
  5255. // only detect plain ascii alpha-numerics. But we still need
  5256. // to ignore modifier-only, whitespace, cursor-keys, etc.
  5257. key = event.key || String.fromCharCode(which),
  5258. specialModifiers = !!(
  5259. event.altKey ||
  5260. event.ctrlKey ||
  5261. event.metaKey
  5262. ),
  5263. isAlnum =
  5264. !MODIFIERS[which] &&
  5265. !SPECIAL_KEYCODES[which] &&
  5266. !specialModifiers,
  5267. $target = $(event.target),
  5268. handled = true,
  5269. activate = !(event.ctrlKey || !opts.autoActivate);
  5270. // (node || FT).debug("ftnode.nodeKeydown(" + event.type + "): ftnode:" + this + ", charCode:" + event.charCode + ", keyCode: " + event.keyCode + ", which: " + event.which);
  5271. // FT.debug( "eventToString(): " + FT.eventToString(event) + ", key='" + key + "', isAlnum: " + isAlnum );
  5272. // Set focus to active (or first node) if no other node has the focus yet
  5273. if (!node) {
  5274. focusNode = this.getActiveNode() || this.getFirstChild();
  5275. if (focusNode) {
  5276. focusNode.setFocus();
  5277. node = ctx.node = this.focusNode;
  5278. node.debug("Keydown force focus on active node");
  5279. }
  5280. }
  5281. if (
  5282. opts.quicksearch &&
  5283. isAlnum &&
  5284. !$target.is(":input:enabled")
  5285. ) {
  5286. // Allow to search for longer streaks if typed in quickly
  5287. stamp = Date.now();
  5288. if (stamp - tree.lastQuicksearchTime > 500) {
  5289. tree.lastQuicksearchTerm = "";
  5290. }
  5291. tree.lastQuicksearchTime = stamp;
  5292. tree.lastQuicksearchTerm += key;
  5293. // tree.debug("quicksearch find", tree.lastQuicksearchTerm);
  5294. matchNode = tree.findNextNode(
  5295. tree.lastQuicksearchTerm,
  5296. tree.getActiveNode()
  5297. );
  5298. if (matchNode) {
  5299. matchNode.setActive();
  5300. }
  5301. event.preventDefault();
  5302. return;
  5303. }
  5304. switch (FT.eventToString(event)) {
  5305. case "+":
  5306. case "=": // 187: '+' @ Chrome, Safari
  5307. tree.nodeSetExpanded(ctx, true);
  5308. break;
  5309. case "-":
  5310. tree.nodeSetExpanded(ctx, false);
  5311. break;
  5312. case "space":
  5313. if (node.isPagingNode()) {
  5314. tree._triggerNodeEvent("clickPaging", ctx, event);
  5315. } else if (
  5316. FT.evalOption("checkbox", node, node, opts, false)
  5317. ) {
  5318. // #768
  5319. tree.nodeToggleSelected(ctx);
  5320. } else {
  5321. tree.nodeSetActive(ctx, true);
  5322. }
  5323. break;
  5324. case "return":
  5325. tree.nodeSetActive(ctx, true);
  5326. break;
  5327. case "home":
  5328. case "end":
  5329. case "backspace":
  5330. case "left":
  5331. case "right":
  5332. case "up":
  5333. case "down":
  5334. _res = node.navigate(event.which, activate);
  5335. break;
  5336. default:
  5337. handled = false;
  5338. }
  5339. if (handled) {
  5340. event.preventDefault();
  5341. }
  5342. },
  5343. // /** Default handling for mouse keypress events. */
  5344. // nodeKeypress: function(ctx) {
  5345. // var event = ctx.originalEvent;
  5346. // },
  5347. // /** Trigger lazyLoad event (async). */
  5348. // nodeLazyLoad: function(ctx) {
  5349. // var node = ctx.node;
  5350. // if(this._triggerNodeEvent())
  5351. // },
  5352. /** Load child nodes (async).
  5353. *
  5354. * @param {EventData} ctx
  5355. * @param {object[]|object|string|$.Promise|function} source
  5356. * @returns {$.Promise} The deferred will be resolved as soon as the (ajax)
  5357. * data was rendered.
  5358. */
  5359. nodeLoadChildren: function (ctx, source) {
  5360. var ajax,
  5361. delay,
  5362. ajaxDfd = null,
  5363. resultDfd,
  5364. isAsync = true,
  5365. tree = ctx.tree,
  5366. node = ctx.node,
  5367. nodePrevParent = node.parent,
  5368. tag = "nodeLoadChildren",
  5369. requestId = Date.now();
  5370. // `source` is a callback: use the returned result instead:
  5371. if (_isFunction(source)) {
  5372. source = source.call(tree, { type: "source" }, ctx);
  5373. _assert(
  5374. !_isFunction(source),
  5375. "source callback must not return another function"
  5376. );
  5377. }
  5378. // `source` is already a promise:
  5379. if (_isFunction(source.then)) {
  5380. // _assert(_isFunction(source.always), "Expected jQuery?");
  5381. ajaxDfd = source;
  5382. } else if (source.url) {
  5383. // `source` is an Ajax options object
  5384. ajax = $.extend({}, ctx.options.ajax, source);
  5385. if (ajax.debugDelay) {
  5386. // Simulate a slow server
  5387. delay = ajax.debugDelay;
  5388. delete ajax.debugDelay; // remove debug option
  5389. if (_isArray(delay)) {
  5390. // random delay range [min..max]
  5391. delay =
  5392. delay[0] +
  5393. Math.random() * (delay[1] - delay[0]);
  5394. }
  5395. node.warn(
  5396. "nodeLoadChildren waiting debugDelay " +
  5397. Math.round(delay) +
  5398. " ms ..."
  5399. );
  5400. ajaxDfd = $.Deferred(function (ajaxDfd) {
  5401. setTimeout(function () {
  5402. $.ajax(ajax)
  5403. .done(function () {
  5404. ajaxDfd.resolveWith(this, arguments);
  5405. })
  5406. .fail(function () {
  5407. ajaxDfd.rejectWith(this, arguments);
  5408. });
  5409. }, delay);
  5410. });
  5411. } else {
  5412. ajaxDfd = $.ajax(ajax);
  5413. }
  5414. } else if ($.isPlainObject(source) || _isArray(source)) {
  5415. // `source` is already a constant dict or list, but we convert
  5416. // to a thenable for unified processing.
  5417. // 2020-01-03: refactored.
  5418. // `ajaxDfd = $.when(source)` would do the trick, but the returned
  5419. // promise will resolve async, which broke some tests and
  5420. // would probably also break current implementations out there.
  5421. // So we mock-up a thenable that resolves synchronously:
  5422. ajaxDfd = {
  5423. then: function (resolve, reject) {
  5424. resolve(source, null, null);
  5425. },
  5426. };
  5427. isAsync = false;
  5428. } else {
  5429. $.error("Invalid source type: " + source);
  5430. }
  5431. // Check for overlapping requests
  5432. if (node._requestId) {
  5433. node.warn(
  5434. "Recursive load request #" +
  5435. requestId +
  5436. " while #" +
  5437. node._requestId +
  5438. " is pending."
  5439. );
  5440. node._requestId = requestId;
  5441. // node.debug("Send load request #" + requestId);
  5442. }
  5443. if (isAsync) {
  5444. tree.debugTime(tag);
  5445. tree.nodeSetStatus(ctx, "loading");
  5446. }
  5447. // The async Ajax request has now started...
  5448. // Defer the deferred:
  5449. // we want to be able to reject invalid responses, even if
  5450. // the raw HTTP Ajax XHR resolved as Ok.
  5451. // We use the ajaxDfd.then() syntax here, which is compatible with
  5452. // jQuery and ECMA6.
  5453. // However resultDfd is a jQuery deferred, which is currently the
  5454. // expected result type of nodeLoadChildren()
  5455. resultDfd = new $.Deferred();
  5456. ajaxDfd.then(
  5457. function (data, textStatus, jqXHR) {
  5458. // ajaxDfd was resolved, but we reject or resolve resultDfd
  5459. // depending on the response data
  5460. var errorObj, res;
  5461. if (
  5462. (source.dataType === "json" ||
  5463. source.dataType === "jsonp") &&
  5464. typeof data === "string"
  5465. ) {
  5466. $.error(
  5467. "Ajax request returned a string (did you get the JSON dataType wrong?)."
  5468. );
  5469. }
  5470. if (node._requestId && node._requestId > requestId) {
  5471. // The expected request time stamp is later than `requestId`
  5472. // (which was kept as as closure variable to this handler function)
  5473. // node.warn("Ignored load response for obsolete request #" + requestId + " (expected #" + node._requestId + ")");
  5474. resultDfd.rejectWith(this, [
  5475. RECURSIVE_REQUEST_ERROR,
  5476. ]);
  5477. return;
  5478. // } else {
  5479. // node.debug("Response returned for load request #" + requestId);
  5480. }
  5481. if (node.parent === null && nodePrevParent !== null) {
  5482. resultDfd.rejectWith(this, [
  5483. INVALID_REQUEST_TARGET_ERROR,
  5484. ]);
  5485. return;
  5486. }
  5487. // Allow to adjust the received response data in the `postProcess` event.
  5488. if (ctx.options.postProcess) {
  5489. // The handler may either
  5490. // - modify `ctx.response` in-place (and leave `ctx.result` undefined)
  5491. // => res = undefined
  5492. // - return a replacement in `ctx.result`
  5493. // => res = <new data>
  5494. // If res contains an `error` property, an error status is displayed
  5495. try {
  5496. res = tree._triggerNodeEvent(
  5497. "postProcess",
  5498. ctx,
  5499. ctx.originalEvent,
  5500. {
  5501. response: data,
  5502. error: null,
  5503. dataType: source.dataType,
  5504. }
  5505. );
  5506. if (res.error) {
  5507. tree.warn(
  5508. "postProcess returned error:",
  5509. res
  5510. );
  5511. }
  5512. } catch (e) {
  5513. res = {
  5514. error: e,
  5515. message: "" + e,
  5516. details: "postProcess failed",
  5517. };
  5518. }
  5519. if (res.error) {
  5520. // Either postProcess failed with an exception, or the returned
  5521. // result object has an 'error' property attached:
  5522. errorObj = $.isPlainObject(res.error)
  5523. ? res.error
  5524. : { message: res.error };
  5525. errorObj = tree._makeHookContext(
  5526. node,
  5527. null,
  5528. errorObj
  5529. );
  5530. resultDfd.rejectWith(this, [errorObj]);
  5531. return;
  5532. }
  5533. if (
  5534. _isArray(res) ||
  5535. ($.isPlainObject(res) && _isArray(res.children))
  5536. ) {
  5537. // Use `ctx.result` if valid
  5538. // (otherwise use existing data, which may have been modified in-place)
  5539. data = res;
  5540. }
  5541. } else if (
  5542. data &&
  5543. _hasProp(data, "d") &&
  5544. ctx.options.enableAspx
  5545. ) {
  5546. // Process ASPX WebMethod JSON object inside "d" property
  5547. // (only if no postProcess event was defined)
  5548. if (ctx.options.enableAspx === 42) {
  5549. tree.warn(
  5550. "The default for enableAspx will change to `false` in the fututure. " +
  5551. "Pass `enableAspx: true` or implement postProcess to silence this warning."
  5552. );
  5553. }
  5554. data =
  5555. typeof data.d === "string"
  5556. ? $.parseJSON(data.d)
  5557. : data.d;
  5558. }
  5559. resultDfd.resolveWith(this, [data]);
  5560. },
  5561. function (jqXHR, textStatus, errorThrown) {
  5562. // ajaxDfd was rejected, so we reject resultDfd as well
  5563. var errorObj = tree._makeHookContext(node, null, {
  5564. error: jqXHR,
  5565. args: Array.prototype.slice.call(arguments),
  5566. message: errorThrown,
  5567. details: jqXHR.status + ": " + errorThrown,
  5568. });
  5569. resultDfd.rejectWith(this, [errorObj]);
  5570. }
  5571. );
  5572. // The async Ajax request has now started.
  5573. // resultDfd will be resolved/rejected after the response arrived,
  5574. // was postProcessed, and checked.
  5575. // Now we implement the UI update and add the data to the tree.
  5576. // We also return this promise to the caller.
  5577. resultDfd
  5578. .done(function (data) {
  5579. tree.nodeSetStatus(ctx, "ok");
  5580. var children, metaData, noDataRes;
  5581. if ($.isPlainObject(data)) {
  5582. // We got {foo: 'abc', children: [...]}
  5583. // Copy extra properties to tree.data.foo
  5584. _assert(
  5585. node.isRootNode(),
  5586. "source may only be an object for root nodes (expecting an array of child objects otherwise)"
  5587. );
  5588. _assert(
  5589. _isArray(data.children),
  5590. "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')"
  5591. );
  5592. metaData = data;
  5593. children = data.children;
  5594. delete metaData.children;
  5595. // Copy some attributes to tree.data
  5596. $.each(TREE_ATTRS, function (i, attr) {
  5597. if (metaData[attr] !== undefined) {
  5598. tree[attr] = metaData[attr];
  5599. delete metaData[attr];
  5600. }
  5601. });
  5602. // Copy all other attributes to tree.data.NAME
  5603. $.extend(tree.data, metaData);
  5604. } else {
  5605. children = data;
  5606. }
  5607. _assert(
  5608. _isArray(children),
  5609. "expected array of children"
  5610. );
  5611. node._setChildren(children);
  5612. if (tree.options.nodata && children.length === 0) {
  5613. if (_isFunction(tree.options.nodata)) {
  5614. noDataRes = tree.options.nodata.call(
  5615. tree,
  5616. { type: "nodata" },
  5617. ctx
  5618. );
  5619. } else if (
  5620. tree.options.nodata === true &&
  5621. node.isRootNode()
  5622. ) {
  5623. noDataRes = tree.options.strings.noData;
  5624. } else if (
  5625. typeof tree.options.nodata === "string" &&
  5626. node.isRootNode()
  5627. ) {
  5628. noDataRes = tree.options.nodata;
  5629. }
  5630. if (noDataRes) {
  5631. node.setStatus("nodata", noDataRes);
  5632. }
  5633. }
  5634. // trigger fancytreeloadchildren
  5635. tree._triggerNodeEvent("loadChildren", node);
  5636. })
  5637. .fail(function (error) {
  5638. var ctxErr;
  5639. if (error === RECURSIVE_REQUEST_ERROR) {
  5640. node.warn(
  5641. "Ignored response for obsolete load request #" +
  5642. requestId +
  5643. " (expected #" +
  5644. node._requestId +
  5645. ")"
  5646. );
  5647. return;
  5648. } else if (error === INVALID_REQUEST_TARGET_ERROR) {
  5649. node.warn(
  5650. "Lazy parent node was removed while loading: discarding response."
  5651. );
  5652. return;
  5653. } else if (error.node && error.error && error.message) {
  5654. // error is already a context object
  5655. ctxErr = error;
  5656. } else {
  5657. ctxErr = tree._makeHookContext(node, null, {
  5658. error: error, // it can be jqXHR or any custom error
  5659. args: Array.prototype.slice.call(arguments),
  5660. message: error
  5661. ? error.message || error.toString()
  5662. : "",
  5663. });
  5664. if (ctxErr.message === "[object Object]") {
  5665. ctxErr.message = "";
  5666. }
  5667. }
  5668. node.warn(
  5669. "Load children failed (" + ctxErr.message + ")",
  5670. ctxErr
  5671. );
  5672. if (
  5673. tree._triggerNodeEvent(
  5674. "loadError",
  5675. ctxErr,
  5676. null
  5677. ) !== false
  5678. ) {
  5679. tree.nodeSetStatus(
  5680. ctx,
  5681. "error",
  5682. ctxErr.message,
  5683. ctxErr.details
  5684. );
  5685. }
  5686. })
  5687. .always(function () {
  5688. node._requestId = null;
  5689. if (isAsync) {
  5690. tree.debugTimeEnd(tag);
  5691. }
  5692. });
  5693. return resultDfd.promise();
  5694. },
  5695. /** [Not Implemented] */
  5696. nodeLoadKeyPath: function (ctx, keyPathList) {
  5697. // TODO: implement and improve
  5698. // http://code.google.com/p/dynatree/issues/detail?id=222
  5699. },
  5700. /**
  5701. * Remove a single direct child of ctx.node.
  5702. * @param {EventData} ctx
  5703. * @param {FancytreeNode} childNode dircect child of ctx.node
  5704. */
  5705. nodeRemoveChild: function (ctx, childNode) {
  5706. var idx,
  5707. node = ctx.node,
  5708. // opts = ctx.options,
  5709. subCtx = $.extend({}, ctx, { node: childNode }),
  5710. children = node.children;
  5711. // FT.debug("nodeRemoveChild()", node.toString(), childNode.toString());
  5712. if (children.length === 1) {
  5713. _assert(childNode === children[0], "invalid single child");
  5714. return this.nodeRemoveChildren(ctx);
  5715. }
  5716. if (
  5717. this.activeNode &&
  5718. (childNode === this.activeNode ||
  5719. this.activeNode.isDescendantOf(childNode))
  5720. ) {
  5721. this.activeNode.setActive(false); // TODO: don't fire events
  5722. }
  5723. if (
  5724. this.focusNode &&
  5725. (childNode === this.focusNode ||
  5726. this.focusNode.isDescendantOf(childNode))
  5727. ) {
  5728. this.focusNode = null;
  5729. }
  5730. // TODO: persist must take care to clear select and expand cookies
  5731. this.nodeRemoveMarkup(subCtx);
  5732. this.nodeRemoveChildren(subCtx);
  5733. idx = $.inArray(childNode, children);
  5734. _assert(idx >= 0, "invalid child");
  5735. // Notify listeners
  5736. node.triggerModifyChild("remove", childNode);
  5737. // Unlink to support GC
  5738. childNode.visit(function (n) {
  5739. n.parent = null;
  5740. }, true);
  5741. this._callHook("treeRegisterNode", this, false, childNode);
  5742. // remove from child list
  5743. children.splice(idx, 1);
  5744. },
  5745. /**Remove HTML markup for all descendents of ctx.node.
  5746. * @param {EventData} ctx
  5747. */
  5748. nodeRemoveChildMarkup: function (ctx) {
  5749. var node = ctx.node;
  5750. // FT.debug("nodeRemoveChildMarkup()", node.toString());
  5751. // TODO: Unlink attr.ftnode to support GC
  5752. if (node.ul) {
  5753. if (node.isRootNode()) {
  5754. $(node.ul).empty();
  5755. } else {
  5756. $(node.ul).remove();
  5757. node.ul = null;
  5758. }
  5759. node.visit(function (n) {
  5760. n.li = n.ul = null;
  5761. });
  5762. }
  5763. },
  5764. /**Remove all descendants of ctx.node.
  5765. * @param {EventData} ctx
  5766. */
  5767. nodeRemoveChildren: function (ctx) {
  5768. var //subCtx,
  5769. tree = ctx.tree,
  5770. node = ctx.node,
  5771. children = node.children;
  5772. // opts = ctx.options;
  5773. // FT.debug("nodeRemoveChildren()", node.toString());
  5774. if (!children) {
  5775. return;
  5776. }
  5777. if (this.activeNode && this.activeNode.isDescendantOf(node)) {
  5778. this.activeNode.setActive(false); // TODO: don't fire events
  5779. }
  5780. if (this.focusNode && this.focusNode.isDescendantOf(node)) {
  5781. this.focusNode = null;
  5782. }
  5783. // TODO: persist must take care to clear select and expand cookies
  5784. this.nodeRemoveChildMarkup(ctx);
  5785. // Unlink children to support GC
  5786. // TODO: also delete this.children (not possible using visit())
  5787. // subCtx = $.extend({}, ctx);
  5788. node.triggerModifyChild("remove", null);
  5789. node.visit(function (n) {
  5790. n.parent = null;
  5791. tree._callHook("treeRegisterNode", tree, false, n);
  5792. });
  5793. if (node.lazy) {
  5794. // 'undefined' would be interpreted as 'not yet loaded' for lazy nodes
  5795. node.children = [];
  5796. } else {
  5797. node.children = null;
  5798. }
  5799. if (!node.isRootNode()) {
  5800. node.expanded = false; // #449, #459
  5801. }
  5802. this.nodeRenderStatus(ctx);
  5803. },
  5804. /**Remove HTML markup for ctx.node and all its descendents.
  5805. * @param {EventData} ctx
  5806. */
  5807. nodeRemoveMarkup: function (ctx) {
  5808. var node = ctx.node;
  5809. // FT.debug("nodeRemoveMarkup()", node.toString());
  5810. // TODO: Unlink attr.ftnode to support GC
  5811. if (node.li) {
  5812. $(node.li).remove();
  5813. node.li = null;
  5814. }
  5815. this.nodeRemoveChildMarkup(ctx);
  5816. },
  5817. /**
  5818. * Create `<li><span>..</span> .. </li>` tags for this node.
  5819. *
  5820. * This method takes care that all HTML markup is created that is required
  5821. * to display this node in its current state.
  5822. *
  5823. * Call this method to create new nodes, or after the strucuture
  5824. * was changed (e.g. after moving this node or adding/removing children)
  5825. * nodeRenderTitle() and nodeRenderStatus() are implied.
  5826. *
  5827. * ```html
  5828. * <li id='KEY' ftnode=NODE>
  5829. * <span class='fancytree-node fancytree-expanded fancytree-has-children fancytree-lastsib fancytree-exp-el fancytree-ico-e'>
  5830. * <span class="fancytree-expander"></span>
  5831. * <span class="fancytree-checkbox"></span> // only present in checkbox mode
  5832. * <span class="fancytree-icon"></span>
  5833. * <a href="#" class="fancytree-title"> Node 1 </a>
  5834. * </span>
  5835. * <ul> // only present if node has children
  5836. * <li id='KEY' ftnode=NODE> child1 ... </li>
  5837. * <li id='KEY' ftnode=NODE> child2 ... </li>
  5838. * </ul>
  5839. * </li>
  5840. * ```
  5841. *
  5842. * @param {EventData} ctx
  5843. * @param {boolean} [force=false] re-render, even if html markup was already created
  5844. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  5845. * @param {boolean} [collapsed=false] force root node to be collapsed, so we can apply animated expand later
  5846. */
  5847. nodeRender: function (ctx, force, deep, collapsed, _recursive) {
  5848. /* This method must take care of all cases where the current data mode
  5849. * (i.e. node hierarchy) does not match the current markup.
  5850. *
  5851. * - node was not yet rendered:
  5852. * create markup
  5853. * - node was rendered: exit fast
  5854. * - children have been added
  5855. * - children have been removed
  5856. */
  5857. var childLI,
  5858. childNode1,
  5859. childNode2,
  5860. i,
  5861. l,
  5862. next,
  5863. subCtx,
  5864. node = ctx.node,
  5865. tree = ctx.tree,
  5866. opts = ctx.options,
  5867. aria = opts.aria,
  5868. firstTime = false,
  5869. parent = node.parent,
  5870. isRootNode = !parent,
  5871. children = node.children,
  5872. successorLi = null;
  5873. // FT.debug("nodeRender(" + !!force + ", " + !!deep + ")", node.toString());
  5874. if (tree._enableUpdate === false) {
  5875. // tree.debug("no render", tree._enableUpdate);
  5876. return;
  5877. }
  5878. if (!isRootNode && !parent.ul) {
  5879. // Calling node.collapse on a deep, unrendered node
  5880. return;
  5881. }
  5882. _assert(isRootNode || parent.ul, "parent UL must exist");
  5883. // Render the node
  5884. if (!isRootNode) {
  5885. // Discard markup on force-mode, or if it is not linked to parent <ul>
  5886. if (
  5887. node.li &&
  5888. (force || node.li.parentNode !== node.parent.ul)
  5889. ) {
  5890. if (node.li.parentNode === node.parent.ul) {
  5891. // #486: store following node, so we can insert the new markup there later
  5892. successorLi = node.li.nextSibling;
  5893. } else {
  5894. // May happen, when a top-level node was dropped over another
  5895. this.debug(
  5896. "Unlinking " +
  5897. node +
  5898. " (must be child of " +
  5899. node.parent +
  5900. ")"
  5901. );
  5902. }
  5903. // this.debug("nodeRemoveMarkup...");
  5904. this.nodeRemoveMarkup(ctx);
  5905. }
  5906. // Create <li><span /> </li>
  5907. // node.debug("render...");
  5908. if (node.li) {
  5909. // this.nodeRenderTitle(ctx);
  5910. this.nodeRenderStatus(ctx);
  5911. } else {
  5912. // node.debug("render... really");
  5913. firstTime = true;
  5914. node.li = document.createElement("li");
  5915. node.li.ftnode = node;
  5916. if (node.key && opts.generateIds) {
  5917. node.li.id = opts.idPrefix + node.key;
  5918. }
  5919. node.span = document.createElement("span");
  5920. node.span.className = "fancytree-node";
  5921. if (aria && !node.tr) {
  5922. $(node.li).attr("role", "treeitem");
  5923. }
  5924. node.li.appendChild(node.span);
  5925. // Create inner HTML for the <span> (expander, checkbox, icon, and title)
  5926. this.nodeRenderTitle(ctx);
  5927. // Allow tweaking and binding, after node was created for the first time
  5928. if (opts.createNode) {
  5929. opts.createNode.call(
  5930. tree,
  5931. { type: "createNode" },
  5932. ctx
  5933. );
  5934. }
  5935. }
  5936. // Allow tweaking after node state was rendered
  5937. if (opts.renderNode) {
  5938. opts.renderNode.call(tree, { type: "renderNode" }, ctx);
  5939. }
  5940. }
  5941. // Visit child nodes
  5942. if (children) {
  5943. if (isRootNode || node.expanded || deep === true) {
  5944. // Create a UL to hold the children
  5945. if (!node.ul) {
  5946. node.ul = document.createElement("ul");
  5947. if (
  5948. (collapsed === true && !_recursive) ||
  5949. !node.expanded
  5950. ) {
  5951. // hide top UL, so we can use an animation to show it later
  5952. node.ul.style.display = "none";
  5953. }
  5954. if (aria) {
  5955. $(node.ul).attr("role", "group");
  5956. }
  5957. if (node.li) {
  5958. // issue #67
  5959. node.li.appendChild(node.ul);
  5960. } else {
  5961. node.tree.$div.append(node.ul);
  5962. }
  5963. }
  5964. // Add child markup
  5965. for (i = 0, l = children.length; i < l; i++) {
  5966. subCtx = $.extend({}, ctx, { node: children[i] });
  5967. this.nodeRender(subCtx, force, deep, false, true);
  5968. }
  5969. // Remove <li> if nodes have moved to another parent
  5970. childLI = node.ul.firstChild;
  5971. while (childLI) {
  5972. childNode2 = childLI.ftnode;
  5973. if (childNode2 && childNode2.parent !== node) {
  5974. node.debug(
  5975. "_fixParent: remove missing " + childNode2,
  5976. childLI
  5977. );
  5978. next = childLI.nextSibling;
  5979. childLI.parentNode.removeChild(childLI);
  5980. childLI = next;
  5981. } else {
  5982. childLI = childLI.nextSibling;
  5983. }
  5984. }
  5985. // Make sure, that <li> order matches node.children order.
  5986. childLI = node.ul.firstChild;
  5987. for (i = 0, l = children.length - 1; i < l; i++) {
  5988. childNode1 = children[i];
  5989. childNode2 = childLI.ftnode;
  5990. if (childNode1 === childNode2) {
  5991. childLI = childLI.nextSibling;
  5992. } else {
  5993. // node.debug("_fixOrder: mismatch at index " + i + ": " + childNode1 + " != " + childNode2);
  5994. node.ul.insertBefore(
  5995. childNode1.li,
  5996. childNode2.li
  5997. );
  5998. }
  5999. }
  6000. }
  6001. } else {
  6002. // No children: remove markup if any
  6003. if (node.ul) {
  6004. // alert("remove child markup for " + node);
  6005. this.warn("remove child markup for " + node);
  6006. this.nodeRemoveChildMarkup(ctx);
  6007. }
  6008. }
  6009. if (!isRootNode) {
  6010. // Update element classes according to node state
  6011. // this.nodeRenderStatus(ctx);
  6012. // Finally add the whole structure to the DOM, so the browser can render
  6013. if (firstTime) {
  6014. // #486: successorLi is set, if we re-rendered (i.e. discarded)
  6015. // existing markup, which we want to insert at the same position.
  6016. // (null is equivalent to append)
  6017. // parent.ul.appendChild(node.li);
  6018. parent.ul.insertBefore(node.li, successorLi);
  6019. }
  6020. }
  6021. },
  6022. /** Create HTML inside the node's outer `<span>` (i.e. expander, checkbox,
  6023. * icon, and title).
  6024. *
  6025. * nodeRenderStatus() is implied.
  6026. * @param {EventData} ctx
  6027. * @param {string} [title] optinal new title
  6028. */
  6029. nodeRenderTitle: function (ctx, title) {
  6030. // set node connector images, links and text
  6031. var checkbox,
  6032. className,
  6033. icon,
  6034. nodeTitle,
  6035. role,
  6036. tabindex,
  6037. tooltip,
  6038. iconTooltip,
  6039. node = ctx.node,
  6040. tree = ctx.tree,
  6041. opts = ctx.options,
  6042. aria = opts.aria,
  6043. level = node.getLevel(),
  6044. ares = [];
  6045. if (title !== undefined) {
  6046. node.title = title;
  6047. }
  6048. if (!node.span || tree._enableUpdate === false) {
  6049. // Silently bail out if node was not rendered yet, assuming
  6050. // node.render() will be called as the node becomes visible
  6051. return;
  6052. }
  6053. // Connector (expanded, expandable or simple)
  6054. role =
  6055. aria && node.hasChildren() !== false
  6056. ? " role='button'"
  6057. : "";
  6058. if (level < opts.minExpandLevel) {
  6059. if (!node.lazy) {
  6060. node.expanded = true;
  6061. }
  6062. if (level > 1) {
  6063. ares.push(
  6064. "<span " +
  6065. role +
  6066. " class='fancytree-expander fancytree-expander-fixed'></span>"
  6067. );
  6068. }
  6069. // .. else (i.e. for root level) skip expander/connector alltogether
  6070. } else {
  6071. ares.push(
  6072. "<span " + role + " class='fancytree-expander'></span>"
  6073. );
  6074. }
  6075. // Checkbox mode
  6076. checkbox = FT.evalOption("checkbox", node, node, opts, false);
  6077. if (checkbox && !node.isStatusNode()) {
  6078. role = aria ? " role='checkbox'" : "";
  6079. className = "fancytree-checkbox";
  6080. if (
  6081. checkbox === "radio" ||
  6082. (node.parent && node.parent.radiogroup)
  6083. ) {
  6084. className += " fancytree-radio";
  6085. }
  6086. ares.push(
  6087. "<span " + role + " class='" + className + "'></span>"
  6088. );
  6089. }
  6090. // Folder or doctype icon
  6091. if (node.data.iconClass !== undefined) {
  6092. // 2015-11-16
  6093. // Handle / warn about backward compatibility
  6094. if (node.icon) {
  6095. $.error(
  6096. "'iconClass' node option is deprecated since v2.14.0: use 'icon' only instead"
  6097. );
  6098. } else {
  6099. node.warn(
  6100. "'iconClass' node option is deprecated since v2.14.0: use 'icon' instead"
  6101. );
  6102. node.icon = node.data.iconClass;
  6103. }
  6104. }
  6105. // If opts.icon is a callback and returns something other than undefined, use that
  6106. // else if node.icon is a boolean or string, use that
  6107. // else if opts.icon is a boolean or string, use that
  6108. // else show standard icon (which may be different for folders or documents)
  6109. icon = FT.evalOption("icon", node, node, opts, true);
  6110. // if( typeof icon !== "boolean" ) {
  6111. // // icon is defined, but not true/false: must be a string
  6112. // icon = "" + icon;
  6113. // }
  6114. if (icon !== false) {
  6115. role = aria ? " role='presentation'" : "";
  6116. iconTooltip = FT.evalOption(
  6117. "iconTooltip",
  6118. node,
  6119. node,
  6120. opts,
  6121. null
  6122. );
  6123. iconTooltip = iconTooltip
  6124. ? " title='" + _escapeTooltip(iconTooltip) + "'"
  6125. : "";
  6126. if (typeof icon === "string") {
  6127. if (TEST_IMG.test(icon)) {
  6128. // node.icon is an image url. Prepend imagePath
  6129. icon =
  6130. icon.charAt(0) === "/"
  6131. ? icon
  6132. : (opts.imagePath || "") + icon;
  6133. ares.push(
  6134. "<img src='" +
  6135. icon +
  6136. "' class='fancytree-icon'" +
  6137. iconTooltip +
  6138. " alt='' />"
  6139. );
  6140. } else {
  6141. ares.push(
  6142. "<span " +
  6143. role +
  6144. " class='fancytree-custom-icon " +
  6145. icon +
  6146. "'" +
  6147. iconTooltip +
  6148. "></span>"
  6149. );
  6150. }
  6151. } else if (icon.text) {
  6152. ares.push(
  6153. "<span " +
  6154. role +
  6155. " class='fancytree-custom-icon " +
  6156. (icon.addClass || "") +
  6157. "'" +
  6158. iconTooltip +
  6159. ">" +
  6160. FT.escapeHtml(icon.text) +
  6161. "</span>"
  6162. );
  6163. } else if (icon.html) {
  6164. ares.push(
  6165. "<span " +
  6166. role +
  6167. " class='fancytree-custom-icon " +
  6168. (icon.addClass || "") +
  6169. "'" +
  6170. iconTooltip +
  6171. ">" +
  6172. icon.html +
  6173. "</span>"
  6174. );
  6175. } else {
  6176. // standard icon: theme css will take care of this
  6177. ares.push(
  6178. "<span " +
  6179. role +
  6180. " class='fancytree-icon'" +
  6181. iconTooltip +
  6182. "></span>"
  6183. );
  6184. }
  6185. }
  6186. // Node title
  6187. nodeTitle = "";
  6188. if (opts.renderTitle) {
  6189. nodeTitle =
  6190. opts.renderTitle.call(
  6191. tree,
  6192. { type: "renderTitle" },
  6193. ctx
  6194. ) || "";
  6195. }
  6196. if (!nodeTitle) {
  6197. tooltip = FT.evalOption("tooltip", node, node, opts, null);
  6198. if (tooltip === true) {
  6199. tooltip = node.title;
  6200. }
  6201. // if( node.tooltip ) {
  6202. // tooltip = node.tooltip;
  6203. // } else if ( opts.tooltip ) {
  6204. // tooltip = opts.tooltip === true ? node.title : opts.tooltip.call(tree, node);
  6205. // }
  6206. tooltip = tooltip
  6207. ? " title='" + _escapeTooltip(tooltip) + "'"
  6208. : "";
  6209. tabindex = opts.titlesTabbable ? " tabindex='0'" : "";
  6210. nodeTitle =
  6211. "<span class='fancytree-title'" +
  6212. tooltip +
  6213. tabindex +
  6214. ">" +
  6215. (opts.escapeTitles
  6216. ? FT.escapeHtml(node.title)
  6217. : node.title) +
  6218. "</span>";
  6219. }
  6220. ares.push(nodeTitle);
  6221. // Note: this will trigger focusout, if node had the focus
  6222. //$(node.span).html(ares.join("")); // it will cleanup the jQuery data currently associated with SPAN (if any), but it executes more slowly
  6223. node.span.innerHTML = ares.join("");
  6224. // Update CSS classes
  6225. this.nodeRenderStatus(ctx);
  6226. if (opts.enhanceTitle) {
  6227. ctx.$title = $(">span.fancytree-title", node.span);
  6228. nodeTitle =
  6229. opts.enhanceTitle.call(
  6230. tree,
  6231. { type: "enhanceTitle" },
  6232. ctx
  6233. ) || "";
  6234. }
  6235. },
  6236. /** Update element classes according to node state.
  6237. * @param {EventData} ctx
  6238. */
  6239. nodeRenderStatus: function (ctx) {
  6240. // Set classes for current status
  6241. var $ariaElem,
  6242. node = ctx.node,
  6243. tree = ctx.tree,
  6244. opts = ctx.options,
  6245. // nodeContainer = node[tree.nodeContainerAttrName],
  6246. hasChildren = node.hasChildren(),
  6247. isLastSib = node.isLastSibling(),
  6248. aria = opts.aria,
  6249. cn = opts._classNames,
  6250. cnList = [],
  6251. statusElem = node[tree.statusClassPropName];
  6252. if (!statusElem || tree._enableUpdate === false) {
  6253. // if this function is called for an unrendered node, ignore it (will be updated on nect render anyway)
  6254. return;
  6255. }
  6256. if (aria) {
  6257. $ariaElem = $(node.tr || node.li);
  6258. }
  6259. // Build a list of class names that we will add to the node <span>
  6260. cnList.push(cn.node);
  6261. if (tree.activeNode === node) {
  6262. cnList.push(cn.active);
  6263. // $(">span.fancytree-title", statusElem).attr("tabindex", "0");
  6264. // tree.$container.removeAttr("tabindex");
  6265. // }else{
  6266. // $(">span.fancytree-title", statusElem).removeAttr("tabindex");
  6267. // tree.$container.attr("tabindex", "0");
  6268. }
  6269. if (tree.focusNode === node) {
  6270. cnList.push(cn.focused);
  6271. }
  6272. if (node.expanded) {
  6273. cnList.push(cn.expanded);
  6274. }
  6275. if (aria) {
  6276. if (hasChildren === false) {
  6277. $ariaElem.removeAttr("aria-expanded");
  6278. } else {
  6279. $ariaElem.attr("aria-expanded", Boolean(node.expanded));
  6280. }
  6281. }
  6282. if (node.folder) {
  6283. cnList.push(cn.folder);
  6284. }
  6285. if (hasChildren !== false) {
  6286. cnList.push(cn.hasChildren);
  6287. }
  6288. // TODO: required?
  6289. if (isLastSib) {
  6290. cnList.push(cn.lastsib);
  6291. }
  6292. if (node.lazy && node.children == null) {
  6293. cnList.push(cn.lazy);
  6294. }
  6295. if (node.partload) {
  6296. cnList.push(cn.partload);
  6297. }
  6298. if (node.partsel) {
  6299. cnList.push(cn.partsel);
  6300. }
  6301. if (FT.evalOption("unselectable", node, node, opts, false)) {
  6302. cnList.push(cn.unselectable);
  6303. }
  6304. if (node._isLoading) {
  6305. cnList.push(cn.loading);
  6306. }
  6307. if (node._error) {
  6308. cnList.push(cn.error);
  6309. }
  6310. if (node.statusNodeType) {
  6311. cnList.push(cn.statusNodePrefix + node.statusNodeType);
  6312. }
  6313. if (node.selected) {
  6314. cnList.push(cn.selected);
  6315. if (aria) {
  6316. $ariaElem.attr("aria-selected", true);
  6317. }
  6318. } else if (aria) {
  6319. $ariaElem.attr("aria-selected", false);
  6320. }
  6321. if (node.extraClasses) {
  6322. cnList.push(node.extraClasses);
  6323. }
  6324. // IE6 doesn't correctly evaluate multiple class names,
  6325. // so we create combined class names that can be used in the CSS
  6326. if (hasChildren === false) {
  6327. cnList.push(
  6328. cn.combinedExpanderPrefix + "n" + (isLastSib ? "l" : "")
  6329. );
  6330. } else {
  6331. cnList.push(
  6332. cn.combinedExpanderPrefix +
  6333. (node.expanded ? "e" : "c") +
  6334. (node.lazy && node.children == null ? "d" : "") +
  6335. (isLastSib ? "l" : "")
  6336. );
  6337. }
  6338. cnList.push(
  6339. cn.combinedIconPrefix +
  6340. (node.expanded ? "e" : "c") +
  6341. (node.folder ? "f" : "")
  6342. );
  6343. // node.span.className = cnList.join(" ");
  6344. statusElem.className = cnList.join(" ");
  6345. // TODO: we should not set this in the <span> tag also, if we set it here:
  6346. // Maybe most (all) of the classes should be set in LI instead of SPAN?
  6347. if (node.li) {
  6348. // #719: we have to consider that there may be already other classes:
  6349. $(node.li).toggleClass(cn.lastsib, isLastSib);
  6350. }
  6351. },
  6352. /** Activate node.
  6353. * flag defaults to true.
  6354. * If flag is true, the node is activated (must be a synchronous operation)
  6355. * If flag is false, the node is deactivated (must be a synchronous operation)
  6356. * @param {EventData} ctx
  6357. * @param {boolean} [flag=true]
  6358. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  6359. * @returns {$.Promise}
  6360. */
  6361. nodeSetActive: function (ctx, flag, callOpts) {
  6362. // Handle user click / [space] / [enter], according to clickFolderMode.
  6363. callOpts = callOpts || {};
  6364. var subCtx,
  6365. node = ctx.node,
  6366. tree = ctx.tree,
  6367. opts = ctx.options,
  6368. noEvents = callOpts.noEvents === true,
  6369. noFocus = callOpts.noFocus === true,
  6370. scroll = callOpts.scrollIntoView !== false,
  6371. isActive = node === tree.activeNode;
  6372. // flag defaults to true
  6373. flag = flag !== false;
  6374. // node.debug("nodeSetActive", flag);
  6375. if (isActive === flag) {
  6376. // Nothing to do
  6377. return _getResolvedPromise(node);
  6378. }
  6379. // #1042: don't scroll between mousedown/-up when clicking an embedded link
  6380. if (
  6381. scroll &&
  6382. ctx.originalEvent &&
  6383. $(ctx.originalEvent.target).is("a,:checkbox")
  6384. ) {
  6385. node.info("Not scrolling while clicking an embedded link.");
  6386. scroll = false;
  6387. }
  6388. if (
  6389. flag &&
  6390. !noEvents &&
  6391. this._triggerNodeEvent(
  6392. "beforeActivate",
  6393. node,
  6394. ctx.originalEvent
  6395. ) === false
  6396. ) {
  6397. // Callback returned false
  6398. return _getRejectedPromise(node, ["rejected"]);
  6399. }
  6400. if (flag) {
  6401. if (tree.activeNode) {
  6402. _assert(
  6403. tree.activeNode !== node,
  6404. "node was active (inconsistency)"
  6405. );
  6406. subCtx = $.extend({}, ctx, { node: tree.activeNode });
  6407. tree.nodeSetActive(subCtx, false);
  6408. _assert(
  6409. tree.activeNode === null,
  6410. "deactivate was out of sync?"
  6411. );
  6412. }
  6413. if (opts.activeVisible) {
  6414. // If no focus is set (noFocus: true) and there is no focused node, this node is made visible.
  6415. // scroll = noFocus && tree.focusNode == null;
  6416. // #863: scroll by default (unless `scrollIntoView: false` was passed)
  6417. node.makeVisible({ scrollIntoView: scroll });
  6418. }
  6419. tree.activeNode = node;
  6420. tree.nodeRenderStatus(ctx);
  6421. if (!noFocus) {
  6422. tree.nodeSetFocus(ctx);
  6423. }
  6424. if (!noEvents) {
  6425. tree._triggerNodeEvent(
  6426. "activate",
  6427. node,
  6428. ctx.originalEvent
  6429. );
  6430. }
  6431. } else {
  6432. _assert(
  6433. tree.activeNode === node,
  6434. "node was not active (inconsistency)"
  6435. );
  6436. tree.activeNode = null;
  6437. this.nodeRenderStatus(ctx);
  6438. if (!noEvents) {
  6439. ctx.tree._triggerNodeEvent(
  6440. "deactivate",
  6441. node,
  6442. ctx.originalEvent
  6443. );
  6444. }
  6445. }
  6446. return _getResolvedPromise(node);
  6447. },
  6448. /** Expand or collapse node, return Deferred.promise.
  6449. *
  6450. * @param {EventData} ctx
  6451. * @param {boolean} [flag=true]
  6452. * @param {object} [opts] additional options. Defaults to `{noAnimation: false, noEvents: false}`
  6453. * @returns {$.Promise} The deferred will be resolved as soon as the (lazy)
  6454. * data was retrieved, rendered, and the expand animation finished.
  6455. */
  6456. nodeSetExpanded: function (ctx, flag, callOpts) {
  6457. callOpts = callOpts || {};
  6458. var _afterLoad,
  6459. dfd,
  6460. i,
  6461. l,
  6462. parents,
  6463. prevAC,
  6464. node = ctx.node,
  6465. tree = ctx.tree,
  6466. opts = ctx.options,
  6467. noAnimation = callOpts.noAnimation === true,
  6468. noEvents = callOpts.noEvents === true;
  6469. // flag defaults to true
  6470. flag = flag !== false;
  6471. // node.debug("nodeSetExpanded(" + flag + ")");
  6472. if ($(node.li).hasClass(opts._classNames.animating)) {
  6473. node.warn(
  6474. "setExpanded(" + flag + ") while animating: ignored."
  6475. );
  6476. return _getRejectedPromise(node, ["recursion"]);
  6477. }
  6478. if ((node.expanded && flag) || (!node.expanded && !flag)) {
  6479. // Nothing to do
  6480. // node.debug("nodeSetExpanded(" + flag + "): nothing to do");
  6481. return _getResolvedPromise(node);
  6482. } else if (flag && !node.lazy && !node.hasChildren()) {
  6483. // Prevent expanding of empty nodes
  6484. // return _getRejectedPromise(node, ["empty"]);
  6485. return _getResolvedPromise(node);
  6486. } else if (!flag && node.getLevel() < opts.minExpandLevel) {
  6487. // Prevent collapsing locked levels
  6488. return _getRejectedPromise(node, ["locked"]);
  6489. } else if (
  6490. !noEvents &&
  6491. this._triggerNodeEvent(
  6492. "beforeExpand",
  6493. node,
  6494. ctx.originalEvent
  6495. ) === false
  6496. ) {
  6497. // Callback returned false
  6498. return _getRejectedPromise(node, ["rejected"]);
  6499. }
  6500. // If this node inside a collpased node, no animation and scrolling is needed
  6501. if (!noAnimation && !node.isVisible()) {
  6502. noAnimation = callOpts.noAnimation = true;
  6503. }
  6504. dfd = new $.Deferred();
  6505. // Auto-collapse mode: collapse all siblings
  6506. if (flag && !node.expanded && opts.autoCollapse) {
  6507. parents = node.getParentList(false, true);
  6508. prevAC = opts.autoCollapse;
  6509. try {
  6510. opts.autoCollapse = false;
  6511. for (i = 0, l = parents.length; i < l; i++) {
  6512. // TODO: should return promise?
  6513. this._callHook(
  6514. "nodeCollapseSiblings",
  6515. parents[i],
  6516. callOpts
  6517. );
  6518. }
  6519. } finally {
  6520. opts.autoCollapse = prevAC;
  6521. }
  6522. }
  6523. // Trigger expand/collapse after expanding
  6524. dfd.done(function () {
  6525. var lastChild = node.getLastChild();
  6526. if (
  6527. flag &&
  6528. opts.autoScroll &&
  6529. !noAnimation &&
  6530. lastChild &&
  6531. tree._enableUpdate
  6532. ) {
  6533. // Scroll down to last child, but keep current node visible
  6534. lastChild
  6535. .scrollIntoView(true, { topNode: node })
  6536. .always(function () {
  6537. if (!noEvents) {
  6538. ctx.tree._triggerNodeEvent(
  6539. flag ? "expand" : "collapse",
  6540. ctx
  6541. );
  6542. }
  6543. });
  6544. } else {
  6545. if (!noEvents) {
  6546. ctx.tree._triggerNodeEvent(
  6547. flag ? "expand" : "collapse",
  6548. ctx
  6549. );
  6550. }
  6551. }
  6552. });
  6553. // vvv Code below is executed after loading finished:
  6554. _afterLoad = function (callback) {
  6555. var cn = opts._classNames,
  6556. isVisible,
  6557. isExpanded,
  6558. effect = opts.toggleEffect;
  6559. node.expanded = flag;
  6560. tree._callHook(
  6561. "treeStructureChanged",
  6562. ctx,
  6563. flag ? "expand" : "collapse"
  6564. );
  6565. // Create required markup, but make sure the top UL is hidden, so we
  6566. // can animate later
  6567. tree._callHook("nodeRender", ctx, false, false, true);
  6568. // Hide children, if node is collapsed
  6569. if (node.ul) {
  6570. isVisible = node.ul.style.display !== "none";
  6571. isExpanded = !!node.expanded;
  6572. if (isVisible === isExpanded) {
  6573. node.warn(
  6574. "nodeSetExpanded: UL.style.display already set"
  6575. );
  6576. } else if (!effect || noAnimation) {
  6577. node.ul.style.display =
  6578. node.expanded || !parent ? "" : "none";
  6579. } else {
  6580. // The UI toggle() effect works with the ext-wide extension,
  6581. // while jQuery.animate() has problems when the title span
  6582. // has position: absolute.
  6583. // Since jQuery UI 1.12, the blind effect requires the parent
  6584. // element to have 'position: relative'.
  6585. // See #716, #717
  6586. $(node.li).addClass(cn.animating); // #717
  6587. if (_isFunction($(node.ul)[effect.effect])) {
  6588. // tree.debug( "use jquery." + effect.effect + " method" );
  6589. $(node.ul)[effect.effect]({
  6590. duration: effect.duration,
  6591. always: function () {
  6592. // node.debug("fancytree-animating end: " + node.li.className);
  6593. $(this).removeClass(cn.animating); // #716
  6594. $(node.li).removeClass(cn.animating); // #717
  6595. callback();
  6596. },
  6597. });
  6598. } else {
  6599. // The UI toggle() effect works with the ext-wide extension,
  6600. // while jQuery.animate() has problems when the title span
  6601. // has positon: absolute.
  6602. // Since jQuery UI 1.12, the blind effect requires the parent
  6603. // element to have 'position: relative'.
  6604. // See #716, #717
  6605. // tree.debug("use specified effect (" + effect.effect + ") with the jqueryui.toggle method");
  6606. // try to stop an animation that might be already in progress
  6607. $(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"
  6608. // dirty fix to remove a defunct animation (effect: "blind") after resetLazy has been called
  6609. $(node.ul)
  6610. .parent()
  6611. .find(".ui-effects-placeholder")
  6612. .remove();
  6613. $(node.ul).toggle(
  6614. effect.effect,
  6615. effect.options,
  6616. effect.duration,
  6617. function () {
  6618. // node.debug("fancytree-animating end: " + node.li.className);
  6619. $(this).removeClass(cn.animating); // #716
  6620. $(node.li).removeClass(cn.animating); // #717
  6621. callback();
  6622. }
  6623. );
  6624. }
  6625. return;
  6626. }
  6627. }
  6628. callback();
  6629. };
  6630. // ^^^ Code above is executed after loading finshed.
  6631. // Load lazy nodes, if any. Then continue with _afterLoad()
  6632. if (flag && node.lazy && node.hasChildren() === undefined) {
  6633. // node.debug("nodeSetExpanded: load start...");
  6634. node.load()
  6635. .done(function () {
  6636. // node.debug("nodeSetExpanded: load done");
  6637. if (dfd.notifyWith) {
  6638. // requires jQuery 1.6+
  6639. dfd.notifyWith(node, ["loaded"]);
  6640. }
  6641. _afterLoad(function () {
  6642. dfd.resolveWith(node);
  6643. });
  6644. })
  6645. .fail(function (errMsg) {
  6646. _afterLoad(function () {
  6647. dfd.rejectWith(node, [
  6648. "load failed (" + errMsg + ")",
  6649. ]);
  6650. });
  6651. });
  6652. /*
  6653. var source = tree._triggerNodeEvent("lazyLoad", node, ctx.originalEvent);
  6654. _assert(typeof source !== "boolean", "lazyLoad event must return source in data.result");
  6655. node.debug("nodeSetExpanded: load start...");
  6656. this._callHook("nodeLoadChildren", ctx, source).done(function(){
  6657. node.debug("nodeSetExpanded: load done");
  6658. if(dfd.notifyWith){ // requires jQuery 1.6+
  6659. dfd.notifyWith(node, ["loaded"]);
  6660. }
  6661. _afterLoad.call(tree);
  6662. }).fail(function(errMsg){
  6663. dfd.rejectWith(node, ["load failed (" + errMsg + ")"]);
  6664. });
  6665. */
  6666. } else {
  6667. _afterLoad(function () {
  6668. dfd.resolveWith(node);
  6669. });
  6670. }
  6671. // node.debug("nodeSetExpanded: returns");
  6672. return dfd.promise();
  6673. },
  6674. /** Focus or blur this node.
  6675. * @param {EventData} ctx
  6676. * @param {boolean} [flag=true]
  6677. */
  6678. nodeSetFocus: function (ctx, flag) {
  6679. // ctx.node.debug("nodeSetFocus(" + flag + ")");
  6680. var ctx2,
  6681. tree = ctx.tree,
  6682. node = ctx.node,
  6683. opts = tree.options,
  6684. // et = ctx.originalEvent && ctx.originalEvent.type,
  6685. isInput = ctx.originalEvent
  6686. ? $(ctx.originalEvent.target).is(":input")
  6687. : false;
  6688. flag = flag !== false;
  6689. // (node || tree).debug("nodeSetFocus(" + flag + "), event: " + et + ", isInput: "+ isInput);
  6690. // Blur previous node if any
  6691. if (tree.focusNode) {
  6692. if (tree.focusNode === node && flag) {
  6693. // node.debug("nodeSetFocus(" + flag + "): nothing to do");
  6694. return;
  6695. }
  6696. ctx2 = $.extend({}, ctx, { node: tree.focusNode });
  6697. tree.focusNode = null;
  6698. this._triggerNodeEvent("blur", ctx2);
  6699. this._callHook("nodeRenderStatus", ctx2);
  6700. }
  6701. // Set focus to container and node
  6702. if (flag) {
  6703. if (!this.hasFocus()) {
  6704. node.debug("nodeSetFocus: forcing container focus");
  6705. this._callHook("treeSetFocus", ctx, true, {
  6706. calledByNode: true,
  6707. });
  6708. }
  6709. node.makeVisible({ scrollIntoView: false });
  6710. tree.focusNode = node;
  6711. if (opts.titlesTabbable) {
  6712. if (!isInput) {
  6713. // #621
  6714. $(node.span)
  6715. .find(".fancytree-title")
  6716. .trigger("focus");
  6717. }
  6718. }
  6719. if (opts.aria) {
  6720. // Set active descendant to node's span ID (create one, if needed)
  6721. $(tree.$container).attr(
  6722. "aria-activedescendant",
  6723. $(node.tr || node.li)
  6724. .uniqueId()
  6725. .attr("id")
  6726. );
  6727. // "ftal_" + opts.idPrefix + node.key);
  6728. }
  6729. // $(node.span).find(".fancytree-title").trigger("focus");
  6730. this._triggerNodeEvent("focus", ctx);
  6731. // determine if we have focus on or inside tree container
  6732. var hasFancytreeFocus =
  6733. document.activeElement === tree.$container.get(0) ||
  6734. $(document.activeElement, tree.$container).length >= 1;
  6735. if (!hasFancytreeFocus) {
  6736. // We cannot set KB focus to a node, so use the tree container
  6737. // #563, #570: IE scrolls on every call to .trigger("focus"), if the container
  6738. // is partially outside the viewport. So do it only, when absolutely
  6739. // necessary.
  6740. $(tree.$container).trigger("focus");
  6741. }
  6742. // if( opts.autoActivate ){
  6743. // tree.nodeSetActive(ctx, true);
  6744. // }
  6745. if (opts.autoScroll) {
  6746. node.scrollIntoView();
  6747. }
  6748. this._callHook("nodeRenderStatus", ctx);
  6749. }
  6750. },
  6751. /** (De)Select node, return new status (sync).
  6752. *
  6753. * @param {EventData} ctx
  6754. * @param {boolean} [flag=true]
  6755. * @param {object} [opts] additional options. Defaults to {noEvents: false,
  6756. * propagateDown: null, propagateUp: null,
  6757. * callback: null,
  6758. * }
  6759. * @returns {boolean} previous status
  6760. */
  6761. nodeSetSelected: function (ctx, flag, callOpts) {
  6762. callOpts = callOpts || {};
  6763. var node = ctx.node,
  6764. tree = ctx.tree,
  6765. opts = ctx.options,
  6766. noEvents = callOpts.noEvents === true,
  6767. parent = node.parent;
  6768. // flag defaults to true
  6769. flag = flag !== false;
  6770. // node.debug("nodeSetSelected(" + flag + ")", ctx);
  6771. // Cannot (de)select unselectable nodes directly (only by propagation or
  6772. // by setting the `.selected` property)
  6773. if (FT.evalOption("unselectable", node, node, opts, false)) {
  6774. return;
  6775. }
  6776. // Remember the user's intent, in case down -> up propagation prevents
  6777. // applying it to node.selected
  6778. node._lastSelectIntent = flag; // Confusing use of '!'
  6779. // Nothing to do?
  6780. if (!!node.selected === flag) {
  6781. if (opts.selectMode === 3 && node.partsel && !flag) {
  6782. // If propagation prevented selecting this node last time, we still
  6783. // want to allow to apply setSelected(false) now
  6784. } else {
  6785. return flag;
  6786. }
  6787. }
  6788. if (
  6789. !noEvents &&
  6790. this._triggerNodeEvent(
  6791. "beforeSelect",
  6792. node,
  6793. ctx.originalEvent
  6794. ) === false
  6795. ) {
  6796. return !!node.selected;
  6797. }
  6798. if (flag && opts.selectMode === 1) {
  6799. // single selection mode (we don't uncheck all tree nodes, for performance reasons)
  6800. if (tree.lastSelectedNode) {
  6801. tree.lastSelectedNode.setSelected(false);
  6802. }
  6803. node.selected = flag;
  6804. } else if (
  6805. opts.selectMode === 3 &&
  6806. parent &&
  6807. !parent.radiogroup &&
  6808. !node.radiogroup
  6809. ) {
  6810. // multi-hierarchical selection mode
  6811. node.selected = flag;
  6812. node.fixSelection3AfterClick(callOpts);
  6813. } else if (parent && parent.radiogroup) {
  6814. node.visitSiblings(function (n) {
  6815. n._changeSelectStatusAttrs(flag && n === node);
  6816. }, true);
  6817. } else {
  6818. // default: selectMode: 2, multi selection mode
  6819. node.selected = flag;
  6820. }
  6821. this.nodeRenderStatus(ctx);
  6822. tree.lastSelectedNode = flag ? node : null;
  6823. if (!noEvents) {
  6824. tree._triggerNodeEvent("select", ctx);
  6825. }
  6826. },
  6827. /** Show node status (ok, loading, error, nodata) using styles and a dummy child node.
  6828. *
  6829. * @param {EventData} ctx
  6830. * @param status
  6831. * @param message
  6832. * @param details
  6833. * @since 2.3
  6834. */
  6835. nodeSetStatus: function (ctx, status, message, details) {
  6836. var node = ctx.node,
  6837. tree = ctx.tree;
  6838. function _clearStatusNode() {
  6839. // Remove dedicated dummy node, if any
  6840. var firstChild = node.children ? node.children[0] : null;
  6841. if (firstChild && firstChild.isStatusNode()) {
  6842. try {
  6843. // I've seen exceptions here with loadKeyPath...
  6844. if (node.ul) {
  6845. node.ul.removeChild(firstChild.li);
  6846. firstChild.li = null; // avoid leaks (DT issue 215)
  6847. }
  6848. } catch (e) {}
  6849. if (node.children.length === 1) {
  6850. node.children = [];
  6851. } else {
  6852. node.children.shift();
  6853. }
  6854. tree._callHook(
  6855. "treeStructureChanged",
  6856. ctx,
  6857. "clearStatusNode"
  6858. );
  6859. }
  6860. }
  6861. function _setStatusNode(data, type) {
  6862. // Create/modify the dedicated dummy node for 'loading...' or
  6863. // 'error!' status. (only called for direct child of the invisible
  6864. // system root)
  6865. var firstChild = node.children ? node.children[0] : null;
  6866. if (firstChild && firstChild.isStatusNode()) {
  6867. $.extend(firstChild, data);
  6868. firstChild.statusNodeType = type;
  6869. tree._callHook("nodeRenderTitle", firstChild);
  6870. } else {
  6871. node._setChildren([data]);
  6872. tree._callHook(
  6873. "treeStructureChanged",
  6874. ctx,
  6875. "setStatusNode"
  6876. );
  6877. node.children[0].statusNodeType = type;
  6878. tree.render();
  6879. }
  6880. return node.children[0];
  6881. }
  6882. switch (status) {
  6883. case "ok":
  6884. _clearStatusNode();
  6885. node._isLoading = false;
  6886. node._error = null;
  6887. node.renderStatus();
  6888. break;
  6889. case "loading":
  6890. if (!node.parent) {
  6891. _setStatusNode(
  6892. {
  6893. title:
  6894. tree.options.strings.loading +
  6895. (message ? " (" + message + ")" : ""),
  6896. // icon: true, // needed for 'loding' icon
  6897. checkbox: false,
  6898. tooltip: details,
  6899. },
  6900. status
  6901. );
  6902. }
  6903. node._isLoading = true;
  6904. node._error = null;
  6905. node.renderStatus();
  6906. break;
  6907. case "error":
  6908. _setStatusNode(
  6909. {
  6910. title:
  6911. tree.options.strings.loadError +
  6912. (message ? " (" + message + ")" : ""),
  6913. // icon: false,
  6914. checkbox: false,
  6915. tooltip: details,
  6916. },
  6917. status
  6918. );
  6919. node._isLoading = false;
  6920. node._error = { message: message, details: details };
  6921. node.renderStatus();
  6922. break;
  6923. case "nodata":
  6924. _setStatusNode(
  6925. {
  6926. title: message || tree.options.strings.noData,
  6927. // icon: false,
  6928. checkbox: false,
  6929. tooltip: details,
  6930. },
  6931. status
  6932. );
  6933. node._isLoading = false;
  6934. node._error = null;
  6935. node.renderStatus();
  6936. break;
  6937. default:
  6938. $.error("invalid node status " + status);
  6939. }
  6940. },
  6941. /**
  6942. *
  6943. * @param {EventData} ctx
  6944. */
  6945. nodeToggleExpanded: function (ctx) {
  6946. return this.nodeSetExpanded(ctx, !ctx.node.expanded);
  6947. },
  6948. /**
  6949. * @param {EventData} ctx
  6950. */
  6951. nodeToggleSelected: function (ctx) {
  6952. var node = ctx.node,
  6953. flag = !node.selected;
  6954. // In selectMode: 3 this node may be unselected+partsel, even if
  6955. // setSelected(true) was called before, due to `unselectable` children.
  6956. // In this case, we now toggle as `setSelected(false)`
  6957. if (
  6958. node.partsel &&
  6959. !node.selected &&
  6960. node._lastSelectIntent === true
  6961. ) {
  6962. flag = false;
  6963. node.selected = true; // so it is not considered 'nothing to do'
  6964. }
  6965. node._lastSelectIntent = flag;
  6966. return this.nodeSetSelected(ctx, flag);
  6967. },
  6968. /** Remove all nodes.
  6969. * @param {EventData} ctx
  6970. */
  6971. treeClear: function (ctx) {
  6972. var tree = ctx.tree;
  6973. tree.activeNode = null;
  6974. tree.focusNode = null;
  6975. tree.$div.find(">ul.fancytree-container").empty();
  6976. // TODO: call destructors and remove reference loops
  6977. tree.rootNode.children = null;
  6978. tree._callHook("treeStructureChanged", ctx, "clear");
  6979. },
  6980. /** Widget was created (called only once, even it re-initialized).
  6981. * @param {EventData} ctx
  6982. */
  6983. treeCreate: function (ctx) {},
  6984. /** Widget was destroyed.
  6985. * @param {EventData} ctx
  6986. */
  6987. treeDestroy: function (ctx) {
  6988. this.$div.find(">ul.fancytree-container").remove();
  6989. if (this.$source) {
  6990. this.$source.removeClass("fancytree-helper-hidden");
  6991. }
  6992. },
  6993. /** Widget was (re-)initialized.
  6994. * @param {EventData} ctx
  6995. */
  6996. treeInit: function (ctx) {
  6997. var tree = ctx.tree,
  6998. opts = tree.options;
  6999. //this.debug("Fancytree.treeInit()");
  7000. // Add container to the TAB chain
  7001. // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  7002. // #577: Allow to set tabindex to "0", "-1" and ""
  7003. tree.$container.attr("tabindex", opts.tabindex);
  7004. // Copy some attributes to tree.data
  7005. $.each(TREE_ATTRS, function (i, attr) {
  7006. if (opts[attr] !== undefined) {
  7007. tree.info("Move option " + attr + " to tree");
  7008. tree[attr] = opts[attr];
  7009. delete opts[attr];
  7010. }
  7011. });
  7012. if (opts.checkboxAutoHide) {
  7013. tree.$container.addClass("fancytree-checkbox-auto-hide");
  7014. }
  7015. if (opts.rtl) {
  7016. tree.$container
  7017. .attr("DIR", "RTL")
  7018. .addClass("fancytree-rtl");
  7019. } else {
  7020. tree.$container
  7021. .removeAttr("DIR")
  7022. .removeClass("fancytree-rtl");
  7023. }
  7024. if (opts.aria) {
  7025. tree.$container.attr("role", "tree");
  7026. if (opts.selectMode !== 1) {
  7027. tree.$container.attr("aria-multiselectable", true);
  7028. }
  7029. }
  7030. this.treeLoad(ctx);
  7031. },
  7032. /** Parse Fancytree from source, as configured in the options.
  7033. * @param {EventData} ctx
  7034. * @param {object} [source] optional new source (use last data otherwise)
  7035. */
  7036. treeLoad: function (ctx, source) {
  7037. var metaData,
  7038. type,
  7039. $ul,
  7040. tree = ctx.tree,
  7041. $container = ctx.widget.element,
  7042. dfd,
  7043. // calling context for root node
  7044. rootCtx = $.extend({}, ctx, { node: this.rootNode });
  7045. if (tree.rootNode.children) {
  7046. this.treeClear(ctx);
  7047. }
  7048. source = source || this.options.source;
  7049. if (!source) {
  7050. type = $container.data("type") || "html";
  7051. switch (type) {
  7052. case "html":
  7053. // There should be an embedded `<ul>` with initial nodes,
  7054. // but another `<ul class='fancytree-container'>` is appended
  7055. // to the tree's <div> on startup anyway.
  7056. $ul = $container
  7057. .find(">ul")
  7058. .not(".fancytree-container")
  7059. .first();
  7060. if ($ul.length) {
  7061. $ul.addClass(
  7062. "ui-fancytree-source fancytree-helper-hidden"
  7063. );
  7064. source = $.ui.fancytree.parseHtml($ul);
  7065. // allow to init tree.data.foo from <ul data-foo=''>
  7066. this.data = $.extend(
  7067. this.data,
  7068. _getElementDataAsDict($ul)
  7069. );
  7070. } else {
  7071. FT.warn(
  7072. "No `source` option was passed and container does not contain `<ul>`: assuming `source: []`."
  7073. );
  7074. source = [];
  7075. }
  7076. break;
  7077. case "json":
  7078. source = $.parseJSON($container.text());
  7079. // $container already contains the <ul>, but we remove the plain (json) text
  7080. // $container.empty();
  7081. $container
  7082. .contents()
  7083. .filter(function () {
  7084. return this.nodeType === 3;
  7085. })
  7086. .remove();
  7087. if ($.isPlainObject(source)) {
  7088. // We got {foo: 'abc', children: [...]}
  7089. _assert(
  7090. _isArray(source.children),
  7091. "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')"
  7092. );
  7093. metaData = source;
  7094. source = source.children;
  7095. delete metaData.children;
  7096. // Copy some attributes to tree.data
  7097. $.each(TREE_ATTRS, function (i, attr) {
  7098. if (metaData[attr] !== undefined) {
  7099. tree[attr] = metaData[attr];
  7100. delete metaData[attr];
  7101. }
  7102. });
  7103. // Copy extra properties to tree.data.foo
  7104. $.extend(tree.data, metaData);
  7105. }
  7106. break;
  7107. default:
  7108. $.error("Invalid data-type: " + type);
  7109. }
  7110. } else if (typeof source === "string") {
  7111. // TODO: source is an element ID
  7112. $.error("Not implemented");
  7113. }
  7114. // preInit is fired when the widget markup is created, but nodes
  7115. // not yet loaded
  7116. tree._triggerTreeEvent("preInit", null);
  7117. // Trigger fancytreeinit after nodes have been loaded
  7118. dfd = this.nodeLoadChildren(rootCtx, source)
  7119. .done(function () {
  7120. tree._callHook(
  7121. "treeStructureChanged",
  7122. ctx,
  7123. "loadChildren"
  7124. );
  7125. tree.render();
  7126. if (ctx.options.selectMode === 3) {
  7127. tree.rootNode.fixSelection3FromEndNodes();
  7128. }
  7129. if (tree.activeNode && tree.options.activeVisible) {
  7130. tree.activeNode.makeVisible();
  7131. }
  7132. tree._triggerTreeEvent("init", null, { status: true });
  7133. })
  7134. .fail(function () {
  7135. tree.render();
  7136. tree._triggerTreeEvent("init", null, { status: false });
  7137. });
  7138. return dfd;
  7139. },
  7140. /** Node was inserted into or removed from the tree.
  7141. * @param {EventData} ctx
  7142. * @param {boolean} add
  7143. * @param {FancytreeNode} node
  7144. */
  7145. treeRegisterNode: function (ctx, add, node) {
  7146. ctx.tree._callHook(
  7147. "treeStructureChanged",
  7148. ctx,
  7149. add ? "addNode" : "removeNode"
  7150. );
  7151. },
  7152. /** Widget got focus.
  7153. * @param {EventData} ctx
  7154. * @param {boolean} [flag=true]
  7155. */
  7156. treeSetFocus: function (ctx, flag, callOpts) {
  7157. var targetNode;
  7158. flag = flag !== false;
  7159. // this.debug("treeSetFocus(" + flag + "), callOpts: ", callOpts, this.hasFocus());
  7160. // this.debug(" focusNode: " + this.focusNode);
  7161. // this.debug(" activeNode: " + this.activeNode);
  7162. if (flag !== this.hasFocus()) {
  7163. this._hasFocus = flag;
  7164. if (!flag && this.focusNode) {
  7165. // Node also looses focus if widget blurs
  7166. this.focusNode.setFocus(false);
  7167. } else if (flag && (!callOpts || !callOpts.calledByNode)) {
  7168. $(this.$container).trigger("focus");
  7169. }
  7170. this.$container.toggleClass("fancytree-treefocus", flag);
  7171. this._triggerTreeEvent(flag ? "focusTree" : "blurTree");
  7172. if (flag && !this.activeNode) {
  7173. // #712: Use last mousedowned node ('click' event fires after focusin)
  7174. targetNode =
  7175. this._lastMousedownNode || this.getFirstChild();
  7176. if (targetNode) {
  7177. targetNode.setFocus();
  7178. }
  7179. }
  7180. }
  7181. },
  7182. /** Widget option was set using `$().fancytree("option", "KEY", VALUE)`.
  7183. *
  7184. * Note: `key` may reference a nested option, e.g. 'dnd5.scroll'.
  7185. * In this case `value`contains the complete, modified `dnd5` option hash.
  7186. * We can check for changed values like
  7187. * if( value.scroll !== tree.options.dnd5.scroll ) {...}
  7188. *
  7189. * @param {EventData} ctx
  7190. * @param {string} key option name
  7191. * @param {any} value option value
  7192. */
  7193. treeSetOption: function (ctx, key, value) {
  7194. var tree = ctx.tree,
  7195. callDefault = true,
  7196. callCreate = false,
  7197. callRender = false;
  7198. switch (key) {
  7199. case "aria":
  7200. case "checkbox":
  7201. case "icon":
  7202. case "minExpandLevel":
  7203. case "tabindex":
  7204. // tree._callHook("treeCreate", tree);
  7205. callCreate = true;
  7206. callRender = true;
  7207. break;
  7208. case "checkboxAutoHide":
  7209. tree.$container.toggleClass(
  7210. "fancytree-checkbox-auto-hide",
  7211. !!value
  7212. );
  7213. break;
  7214. case "escapeTitles":
  7215. case "tooltip":
  7216. callRender = true;
  7217. break;
  7218. case "rtl":
  7219. if (value === false) {
  7220. tree.$container
  7221. .removeAttr("DIR")
  7222. .removeClass("fancytree-rtl");
  7223. } else {
  7224. tree.$container
  7225. .attr("DIR", "RTL")
  7226. .addClass("fancytree-rtl");
  7227. }
  7228. callRender = true;
  7229. break;
  7230. case "source":
  7231. callDefault = false;
  7232. tree._callHook("treeLoad", tree, value);
  7233. callRender = true;
  7234. break;
  7235. }
  7236. tree.debug(
  7237. "set option " +
  7238. key +
  7239. "=" +
  7240. value +
  7241. " <" +
  7242. typeof value +
  7243. ">"
  7244. );
  7245. if (callDefault) {
  7246. if (this.widget._super) {
  7247. // jQuery UI 1.9+
  7248. this.widget._super.call(this.widget, key, value);
  7249. } else {
  7250. // jQuery UI <= 1.8, we have to manually invoke the _setOption method from the base widget
  7251. $.Widget.prototype._setOption.call(
  7252. this.widget,
  7253. key,
  7254. value
  7255. );
  7256. }
  7257. }
  7258. if (callCreate) {
  7259. tree._callHook("treeCreate", tree);
  7260. }
  7261. if (callRender) {
  7262. tree.render(true, false); // force, not-deep
  7263. }
  7264. },
  7265. /** A Node was added, removed, moved, or it's visibility changed.
  7266. * @param {EventData} ctx
  7267. */
  7268. treeStructureChanged: function (ctx, type) {},
  7269. }
  7270. );
  7271. /*******************************************************************************
  7272. * jQuery UI widget boilerplate
  7273. */
  7274. /**
  7275. * The plugin (derrived from [jQuery.Widget](http://api.jqueryui.com/jQuery.widget/)).
  7276. *
  7277. * **Note:**
  7278. * These methods implement the standard jQuery UI widget API.
  7279. * It is recommended to use methods of the {Fancytree} instance instead
  7280. *
  7281. * @example
  7282. * // DEPRECATED: Access jQuery UI widget methods and members:
  7283. * var tree = $("#tree").fancytree("getTree");
  7284. * var node = $("#tree").fancytree("getActiveNode");
  7285. *
  7286. * // RECOMMENDED: Use the Fancytree object API
  7287. * var tree = $.ui.fancytree.getTree("#tree");
  7288. * var node = tree.getActiveNode();
  7289. *
  7290. * // or you may already have stored the tree instance upon creation:
  7291. * import {createTree, version} from 'jquery.fancytree'
  7292. * const tree = createTree('#tree', { ... });
  7293. * var node = tree.getActiveNode();
  7294. *
  7295. * @see {Fancytree_Static#getTree}
  7296. * @deprecated Use methods of the {Fancytree} instance instead
  7297. * @mixin Fancytree_Widget
  7298. */
  7299. $.widget(
  7300. "ui.fancytree",
  7301. /** @lends Fancytree_Widget# */
  7302. {
  7303. /**These options will be used as defaults
  7304. * @type {FancytreeOptions}
  7305. */
  7306. options: {
  7307. activeVisible: true,
  7308. ajax: {
  7309. type: "GET",
  7310. cache: false, // false: Append random '_' argument to the request url to prevent caching.
  7311. // timeout: 0, // >0: Make sure we get an ajax error if server is unreachable
  7312. dataType: "json", // Expect json format and pass json object to callbacks.
  7313. },
  7314. aria: true,
  7315. autoActivate: true,
  7316. autoCollapse: false,
  7317. autoScroll: false,
  7318. checkbox: false,
  7319. clickFolderMode: 4,
  7320. copyFunctionsToData: false,
  7321. debugLevel: null, // 0..4 (null: use global setting $.ui.fancytree.debugLevel)
  7322. disabled: false, // TODO: required anymore?
  7323. enableAspx: 42, // TODO: this is truethy, but distinguishable from true: default will change to false in the future
  7324. escapeTitles: false,
  7325. extensions: [],
  7326. focusOnSelect: false,
  7327. generateIds: false,
  7328. icon: true,
  7329. idPrefix: "ft_",
  7330. keyboard: true,
  7331. keyPathSeparator: "/",
  7332. minExpandLevel: 1,
  7333. nodata: true, // (bool, string, or callback) display message, when no data available
  7334. quicksearch: false,
  7335. rtl: false,
  7336. scrollOfs: { top: 0, bottom: 0 },
  7337. scrollParent: null,
  7338. selectMode: 2,
  7339. strings: {
  7340. loading: "Loading...", // &#8230; would be escaped when escapeTitles is true
  7341. loadError: "Load error!",
  7342. moreData: "More...",
  7343. noData: "No data.",
  7344. },
  7345. tabindex: "0",
  7346. titlesTabbable: false,
  7347. toggleEffect: { effect: "slideToggle", duration: 200 }, //< "toggle" or "slideToggle" to use jQuery instead of jQueryUI for toggleEffect animation
  7348. tooltip: false,
  7349. treeId: null,
  7350. _classNames: {
  7351. active: "fancytree-active",
  7352. animating: "fancytree-animating",
  7353. combinedExpanderPrefix: "fancytree-exp-",
  7354. combinedIconPrefix: "fancytree-ico-",
  7355. error: "fancytree-error",
  7356. expanded: "fancytree-expanded",
  7357. focused: "fancytree-focused",
  7358. folder: "fancytree-folder",
  7359. hasChildren: "fancytree-has-children",
  7360. lastsib: "fancytree-lastsib",
  7361. lazy: "fancytree-lazy",
  7362. loading: "fancytree-loading",
  7363. node: "fancytree-node",
  7364. partload: "fancytree-partload",
  7365. partsel: "fancytree-partsel",
  7366. radio: "fancytree-radio",
  7367. selected: "fancytree-selected",
  7368. statusNodePrefix: "fancytree-statusnode-",
  7369. unselectable: "fancytree-unselectable",
  7370. },
  7371. // events
  7372. lazyLoad: null,
  7373. postProcess: null,
  7374. },
  7375. _deprecationWarning: function (name) {
  7376. var tree = this.tree;
  7377. if (tree && tree.options.debugLevel >= 3) {
  7378. tree.warn(
  7379. "$().fancytree('" +
  7380. name +
  7381. "') is deprecated (see https://wwwendt.de/tech/fancytree/doc/jsdoc/Fancytree_Widget.html"
  7382. );
  7383. }
  7384. },
  7385. /* Set up the widget, Called on first $().fancytree() */
  7386. _create: function () {
  7387. this.tree = new Fancytree(this);
  7388. this.$source =
  7389. this.source || this.element.data("type") === "json"
  7390. ? this.element
  7391. : this.element.find(">ul").first();
  7392. // Subclass Fancytree instance with all enabled extensions
  7393. var extension,
  7394. extName,
  7395. i,
  7396. opts = this.options,
  7397. extensions = opts.extensions,
  7398. base = this.tree;
  7399. for (i = 0; i < extensions.length; i++) {
  7400. extName = extensions[i];
  7401. extension = $.ui.fancytree._extensions[extName];
  7402. if (!extension) {
  7403. $.error(
  7404. "Could not apply extension '" +
  7405. extName +
  7406. "' (it is not registered, did you forget to include it?)"
  7407. );
  7408. }
  7409. // Add extension options as tree.options.EXTENSION
  7410. // _assert(!this.tree.options[extName], "Extension name must not exist as option name: " + extName);
  7411. // console.info("extend " + extName, extension.options, this.tree.options[extName])
  7412. // issue #876: we want to replace custom array-options, not merge them
  7413. this.tree.options[extName] = _simpleDeepMerge(
  7414. {},
  7415. extension.options,
  7416. this.tree.options[extName]
  7417. );
  7418. // this.tree.options[extName] = $.extend(true, {}, extension.options, this.tree.options[extName]);
  7419. // console.info("extend " + extName + " =>", this.tree.options[extName])
  7420. // console.info("extend " + extName + " org default =>", extension.options)
  7421. // Add a namespace tree.ext.EXTENSION, to hold instance data
  7422. _assert(
  7423. this.tree.ext[extName] === undefined,
  7424. "Extension name must not exist as Fancytree.ext attribute: '" +
  7425. extName +
  7426. "'"
  7427. );
  7428. // this.tree[extName] = extension;
  7429. this.tree.ext[extName] = {};
  7430. // Subclass Fancytree methods using proxies.
  7431. _subclassObject(this.tree, base, extension, extName);
  7432. // current extension becomes base for the next extension
  7433. base = extension;
  7434. }
  7435. //
  7436. if (opts.icons !== undefined) {
  7437. // 2015-11-16
  7438. if (opts.icon === true) {
  7439. this.tree.warn(
  7440. "'icons' tree option is deprecated since v2.14.0: use 'icon' instead"
  7441. );
  7442. opts.icon = opts.icons;
  7443. } else {
  7444. $.error(
  7445. "'icons' tree option is deprecated since v2.14.0: use 'icon' only instead"
  7446. );
  7447. }
  7448. }
  7449. if (opts.iconClass !== undefined) {
  7450. // 2015-11-16
  7451. if (opts.icon) {
  7452. $.error(
  7453. "'iconClass' tree option is deprecated since v2.14.0: use 'icon' only instead"
  7454. );
  7455. } else {
  7456. this.tree.warn(
  7457. "'iconClass' tree option is deprecated since v2.14.0: use 'icon' instead"
  7458. );
  7459. opts.icon = opts.iconClass;
  7460. }
  7461. }
  7462. if (opts.tabbable !== undefined) {
  7463. // 2016-04-04
  7464. opts.tabindex = opts.tabbable ? "0" : "-1";
  7465. this.tree.warn(
  7466. "'tabbable' tree option is deprecated since v2.17.0: use 'tabindex='" +
  7467. opts.tabindex +
  7468. "' instead"
  7469. );
  7470. }
  7471. //
  7472. this.tree._callHook("treeCreate", this.tree);
  7473. // Note: 'fancytreecreate' event is fired by widget base class
  7474. // this.tree._triggerTreeEvent("create");
  7475. },
  7476. /* Called on every $().fancytree() */
  7477. _init: function () {
  7478. this.tree._callHook("treeInit", this.tree);
  7479. // TODO: currently we call bind after treeInit, because treeInit
  7480. // might change tree.$container.
  7481. // It would be better, to move event binding into hooks altogether
  7482. this._bind();
  7483. },
  7484. /* Use the _setOption method to respond to changes to options. */
  7485. _setOption: function (key, value) {
  7486. return this.tree._callHook(
  7487. "treeSetOption",
  7488. this.tree,
  7489. key,
  7490. value
  7491. );
  7492. },
  7493. /** Use the destroy method to clean up any modifications your widget has made to the DOM */
  7494. _destroy: function () {
  7495. this._unbind();
  7496. this.tree._callHook("treeDestroy", this.tree);
  7497. // In jQuery UI 1.8, you must invoke the destroy method from the base widget
  7498. // $.Widget.prototype.destroy.call(this);
  7499. // TODO: delete tree and nodes to make garbage collect easier?
  7500. // TODO: In jQuery UI 1.9 and above, you would define _destroy instead of destroy and not call the base method
  7501. },
  7502. // -------------------------------------------------------------------------
  7503. /* Remove all event handlers for our namespace */
  7504. _unbind: function () {
  7505. var ns = this.tree._ns;
  7506. this.element.off(ns);
  7507. this.tree.$container.off(ns);
  7508. $(document).off(ns);
  7509. },
  7510. /* Add mouse and kyboard handlers to the container */
  7511. _bind: function () {
  7512. var self = this,
  7513. opts = this.options,
  7514. tree = this.tree,
  7515. ns = tree._ns;
  7516. // selstartEvent = ( $.support.selectstart ? "selectstart" : "mousedown" )
  7517. // Remove all previuous handlers for this tree
  7518. this._unbind();
  7519. //alert("keydown" + ns + "foc=" + tree.hasFocus() + tree.$container);
  7520. // tree.debug("bind events; container: ", tree.$container);
  7521. tree.$container
  7522. .on("focusin" + ns + " focusout" + ns, function (event) {
  7523. var node = FT.getNode(event),
  7524. flag = event.type === "focusin";
  7525. if (!flag && node && $(event.target).is("a")) {
  7526. // #764
  7527. node.debug(
  7528. "Ignored focusout on embedded <a> element."
  7529. );
  7530. return;
  7531. }
  7532. // tree.treeOnFocusInOut.call(tree, event);
  7533. // tree.debug("Tree container got event " + event.type, node, event, FT.getEventTarget(event));
  7534. if (flag) {
  7535. if (tree._getExpiringValue("focusin")) {
  7536. // #789: IE 11 may send duplicate focusin events
  7537. tree.debug("Ignored double focusin.");
  7538. return;
  7539. }
  7540. tree._setExpiringValue("focusin", true, 50);
  7541. if (!node) {
  7542. // #789: IE 11 may send focusin before mousdown(?)
  7543. node = tree._getExpiringValue("mouseDownNode");
  7544. if (node) {
  7545. tree.debug(
  7546. "Reconstruct mouse target for focusin from recent event."
  7547. );
  7548. }
  7549. }
  7550. }
  7551. if (node) {
  7552. // For example clicking into an <input> that is part of a node
  7553. tree._callHook(
  7554. "nodeSetFocus",
  7555. tree._makeHookContext(node, event),
  7556. flag
  7557. );
  7558. } else {
  7559. if (
  7560. tree.tbody &&
  7561. $(event.target).parents(
  7562. "table.fancytree-container > thead"
  7563. ).length
  7564. ) {
  7565. // #767: ignore events in the table's header
  7566. tree.debug(
  7567. "Ignore focus event outside table body.",
  7568. event
  7569. );
  7570. } else {
  7571. tree._callHook("treeSetFocus", tree, flag);
  7572. }
  7573. }
  7574. })
  7575. .on(
  7576. "selectstart" + ns,
  7577. "span.fancytree-title",
  7578. function (event) {
  7579. // prevent mouse-drags to select text ranges
  7580. // tree.debug("<span title> got event " + event.type);
  7581. event.preventDefault();
  7582. }
  7583. )
  7584. .on("keydown" + ns, function (event) {
  7585. // TODO: also bind keyup and keypress
  7586. // tree.debug("got event " + event.type + ", hasFocus:" + tree.hasFocus());
  7587. // if(opts.disabled || opts.keyboard === false || !tree.hasFocus() ){
  7588. if (opts.disabled || opts.keyboard === false) {
  7589. return true;
  7590. }
  7591. var res,
  7592. node = tree.focusNode, // node may be null
  7593. ctx = tree._makeHookContext(node || tree, event),
  7594. prevPhase = tree.phase;
  7595. try {
  7596. tree.phase = "userEvent";
  7597. // If a 'fancytreekeydown' handler returns false, skip the default
  7598. // handling (implemented by tree.nodeKeydown()).
  7599. if (node) {
  7600. res = tree._triggerNodeEvent(
  7601. "keydown",
  7602. node,
  7603. event
  7604. );
  7605. } else {
  7606. res = tree._triggerTreeEvent("keydown", event);
  7607. }
  7608. if (res === "preventNav") {
  7609. res = true; // prevent keyboard navigation, but don't prevent default handling of embedded input controls
  7610. } else if (res !== false) {
  7611. res = tree._callHook("nodeKeydown", ctx);
  7612. }
  7613. return res;
  7614. } finally {
  7615. tree.phase = prevPhase;
  7616. }
  7617. })
  7618. .on("mousedown" + ns, function (event) {
  7619. var et = FT.getEventTarget(event);
  7620. // self.tree.debug("event(" + event.type + "): node: ", et.node);
  7621. // #712: Store the clicked node, so we can use it when we get a focusin event
  7622. // ('click' event fires after focusin)
  7623. // tree.debug("event(" + event.type + "): node: ", et.node);
  7624. tree._lastMousedownNode = et ? et.node : null;
  7625. // #789: Store the node also for a short period, so we can use it
  7626. // in a *resulting* focusin event
  7627. tree._setExpiringValue(
  7628. "mouseDownNode",
  7629. tree._lastMousedownNode
  7630. );
  7631. })
  7632. .on("click" + ns + " dblclick" + ns, function (event) {
  7633. if (opts.disabled) {
  7634. return true;
  7635. }
  7636. var ctx,
  7637. et = FT.getEventTarget(event),
  7638. node = et.node,
  7639. tree = self.tree,
  7640. prevPhase = tree.phase;
  7641. // self.tree.debug("event(" + event.type + "): node: ", node);
  7642. if (!node) {
  7643. return true; // Allow bubbling of other events
  7644. }
  7645. ctx = tree._makeHookContext(node, event);
  7646. // self.tree.debug("event(" + event.type + "): node: ", node);
  7647. try {
  7648. tree.phase = "userEvent";
  7649. switch (event.type) {
  7650. case "click":
  7651. ctx.targetType = et.type;
  7652. if (node.isPagingNode()) {
  7653. return (
  7654. tree._triggerNodeEvent(
  7655. "clickPaging",
  7656. ctx,
  7657. event
  7658. ) === true
  7659. );
  7660. }
  7661. return tree._triggerNodeEvent(
  7662. "click",
  7663. ctx,
  7664. event
  7665. ) === false
  7666. ? false
  7667. : tree._callHook("nodeClick", ctx);
  7668. case "dblclick":
  7669. ctx.targetType = et.type;
  7670. return tree._triggerNodeEvent(
  7671. "dblclick",
  7672. ctx,
  7673. event
  7674. ) === false
  7675. ? false
  7676. : tree._callHook("nodeDblclick", ctx);
  7677. }
  7678. } finally {
  7679. tree.phase = prevPhase;
  7680. }
  7681. });
  7682. },
  7683. /** Return the active node or null.
  7684. * @returns {FancytreeNode}
  7685. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7686. */
  7687. getActiveNode: function () {
  7688. this._deprecationWarning("getActiveNode");
  7689. return this.tree.activeNode;
  7690. },
  7691. /** Return the matching node or null.
  7692. * @param {string} key
  7693. * @returns {FancytreeNode}
  7694. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7695. */
  7696. getNodeByKey: function (key) {
  7697. this._deprecationWarning("getNodeByKey");
  7698. return this.tree.getNodeByKey(key);
  7699. },
  7700. /** Return the invisible system root node.
  7701. * @returns {FancytreeNode}
  7702. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7703. */
  7704. getRootNode: function () {
  7705. this._deprecationWarning("getRootNode");
  7706. return this.tree.rootNode;
  7707. },
  7708. /** Return the current tree instance.
  7709. * @returns {Fancytree}
  7710. * @deprecated Use `$.ui.fancytree.getTree()` instead (<a href="Fancytree_Widget.html">example above</a>).
  7711. */
  7712. getTree: function () {
  7713. this._deprecationWarning("getTree");
  7714. return this.tree;
  7715. },
  7716. }
  7717. );
  7718. // $.ui.fancytree was created by the widget factory. Create a local shortcut:
  7719. FT = $.ui.fancytree;
  7720. /**
  7721. * Static members in the `$.ui.fancytree` namespace.
  7722. * This properties and methods can be accessed without instantiating a concrete
  7723. * Fancytree instance.
  7724. *
  7725. * @example
  7726. * // Access static members:
  7727. * var node = $.ui.fancytree.getNode(element);
  7728. * alert($.ui.fancytree.version);
  7729. *
  7730. * @mixin Fancytree_Static
  7731. */
  7732. $.extend(
  7733. $.ui.fancytree,
  7734. /** @lends Fancytree_Static# */
  7735. {
  7736. /** Version number `"MAJOR.MINOR.PATCH"`
  7737. * @type {string} */
  7738. version: "2.38.5", // Set to semver by 'grunt release'
  7739. /** @type {string}
  7740. * @description `"production" for release builds` */
  7741. buildType: "production", // Set to 'production' by 'grunt build'
  7742. /** @type {int}
  7743. * @description 0: silent .. 5: verbose (default: 3 for release builds). */
  7744. debugLevel: 3, // Set to 3 by 'grunt build'
  7745. // Used by $.ui.fancytree.debug() and as default for tree.options.debugLevel
  7746. _nextId: 1,
  7747. _nextNodeKey: 1,
  7748. _extensions: {},
  7749. // focusTree: null,
  7750. /** Expose class object as `$.ui.fancytree._FancytreeClass`.
  7751. * Useful to extend `$.ui.fancytree._FancytreeClass.prototype`.
  7752. * @type {Fancytree}
  7753. */
  7754. _FancytreeClass: Fancytree,
  7755. /** Expose class object as $.ui.fancytree._FancytreeNodeClass
  7756. * Useful to extend `$.ui.fancytree._FancytreeNodeClass.prototype`.
  7757. * @type {FancytreeNode}
  7758. */
  7759. _FancytreeNodeClass: FancytreeNode,
  7760. /* Feature checks to provide backwards compatibility */
  7761. jquerySupports: {
  7762. // http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7763. positionMyOfs: isVersionAtLeast($.ui.version, 1, 9),
  7764. },
  7765. /** Throw an error if condition fails (debug method).
  7766. * @param {boolean} cond
  7767. * @param {string} msg
  7768. */
  7769. assert: function (cond, msg) {
  7770. return _assert(cond, msg);
  7771. },
  7772. /** Create a new Fancytree instance on a target element.
  7773. *
  7774. * @param {Element | jQueryObject | string} el Target DOM element or selector
  7775. * @param {FancytreeOptions} [opts] Fancytree options
  7776. * @returns {Fancytree} new tree instance
  7777. * @example
  7778. * var tree = $.ui.fancytree.createTree("#tree", {
  7779. * source: {url: "my/webservice"}
  7780. * }); // Create tree for this matching element
  7781. *
  7782. * @since 2.25
  7783. */
  7784. createTree: function (el, opts) {
  7785. var $tree = $(el).fancytree(opts);
  7786. return FT.getTree($tree);
  7787. },
  7788. /** Return a function that executes *fn* at most every *timeout* ms.
  7789. * @param {integer} timeout
  7790. * @param {function} fn
  7791. * @param {boolean} [invokeAsap=false]
  7792. * @param {any} [ctx]
  7793. */
  7794. debounce: function (timeout, fn, invokeAsap, ctx) {
  7795. var timer;
  7796. if (arguments.length === 3 && typeof invokeAsap !== "boolean") {
  7797. ctx = invokeAsap;
  7798. invokeAsap = false;
  7799. }
  7800. return function () {
  7801. var args = arguments;
  7802. ctx = ctx || this;
  7803. // eslint-disable-next-line no-unused-expressions
  7804. invokeAsap && !timer && fn.apply(ctx, args);
  7805. clearTimeout(timer);
  7806. timer = setTimeout(function () {
  7807. // eslint-disable-next-line no-unused-expressions
  7808. invokeAsap || fn.apply(ctx, args);
  7809. timer = null;
  7810. }, timeout);
  7811. };
  7812. },
  7813. /** Write message to console if debugLevel >= 4
  7814. * @param {string} msg
  7815. */
  7816. debug: function (msg) {
  7817. if ($.ui.fancytree.debugLevel >= 4) {
  7818. consoleApply("log", arguments);
  7819. }
  7820. },
  7821. /** Write error message to console if debugLevel >= 1.
  7822. * @param {string} msg
  7823. */
  7824. error: function (msg) {
  7825. if ($.ui.fancytree.debugLevel >= 1) {
  7826. consoleApply("error", arguments);
  7827. }
  7828. },
  7829. /** Convert `<`, `>`, `&`, `"`, `'`, and `/` to the equivalent entities.
  7830. *
  7831. * @param {string} s
  7832. * @returns {string}
  7833. */
  7834. escapeHtml: function (s) {
  7835. return ("" + s).replace(REX_HTML, function (s) {
  7836. return ENTITY_MAP[s];
  7837. });
  7838. },
  7839. /** Make jQuery.position() arguments backwards compatible, i.e. if
  7840. * jQuery UI version <= 1.8, convert
  7841. * { my: "left+3 center", at: "left bottom", of: $target }
  7842. * to
  7843. * { my: "left center", at: "left bottom", of: $target, offset: "3 0" }
  7844. *
  7845. * See http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7846. * and http://jsfiddle.net/mar10/6xtu9a4e/
  7847. *
  7848. * @param {object} opts
  7849. * @returns {object} the (potentially modified) original opts hash object
  7850. */
  7851. fixPositionOptions: function (opts) {
  7852. if (opts.offset || ("" + opts.my + opts.at).indexOf("%") >= 0) {
  7853. $.error(
  7854. "expected new position syntax (but '%' is not supported)"
  7855. );
  7856. }
  7857. if (!$.ui.fancytree.jquerySupports.positionMyOfs) {
  7858. var // parse 'left+3 center' into ['left+3 center', 'left', '+3', 'center', undefined]
  7859. myParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(
  7860. opts.my
  7861. ),
  7862. atParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(
  7863. opts.at
  7864. ),
  7865. // convert to numbers
  7866. dx =
  7867. (myParts[2] ? +myParts[2] : 0) +
  7868. (atParts[2] ? +atParts[2] : 0),
  7869. dy =
  7870. (myParts[4] ? +myParts[4] : 0) +
  7871. (atParts[4] ? +atParts[4] : 0);
  7872. opts = $.extend({}, opts, {
  7873. // make a copy and overwrite
  7874. my: myParts[1] + " " + myParts[3],
  7875. at: atParts[1] + " " + atParts[3],
  7876. });
  7877. if (dx || dy) {
  7878. opts.offset = "" + dx + " " + dy;
  7879. }
  7880. }
  7881. return opts;
  7882. },
  7883. /** Return a {node: FancytreeNode, type: TYPE} object for a mouse event.
  7884. *
  7885. * @param {Event} event Mouse event, e.g. click, ...
  7886. * @returns {object} Return a {node: FancytreeNode, type: TYPE} object
  7887. * TYPE: 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7888. */
  7889. getEventTarget: function (event) {
  7890. var $target,
  7891. tree,
  7892. tcn = event && event.target ? event.target.className : "",
  7893. res = { node: this.getNode(event.target), type: undefined };
  7894. // We use a fast version of $(res.node).hasClass()
  7895. // See http://jsperf.com/test-for-classname/2
  7896. if (/\bfancytree-title\b/.test(tcn)) {
  7897. res.type = "title";
  7898. } else if (/\bfancytree-expander\b/.test(tcn)) {
  7899. res.type =
  7900. res.node.hasChildren() === false
  7901. ? "prefix"
  7902. : "expander";
  7903. // }else if( /\bfancytree-checkbox\b/.test(tcn) || /\bfancytree-radio\b/.test(tcn) ){
  7904. } else if (/\bfancytree-checkbox\b/.test(tcn)) {
  7905. res.type = "checkbox";
  7906. } else if (/\bfancytree(-custom)?-icon\b/.test(tcn)) {
  7907. res.type = "icon";
  7908. } else if (/\bfancytree-node\b/.test(tcn)) {
  7909. // Somewhere near the title
  7910. res.type = "title";
  7911. } else if (event && event.target) {
  7912. $target = $(event.target);
  7913. if ($target.is("ul[role=group]")) {
  7914. // #nnn: Clicking right to a node may hit the surrounding UL
  7915. tree = res.node && res.node.tree;
  7916. (tree || FT).debug("Ignoring click on outer UL.");
  7917. res.node = null;
  7918. } else if ($target.closest(".fancytree-title").length) {
  7919. // #228: clicking an embedded element inside a title
  7920. res.type = "title";
  7921. } else if ($target.closest(".fancytree-checkbox").length) {
  7922. // E.g. <svg> inside checkbox span
  7923. res.type = "checkbox";
  7924. } else if ($target.closest(".fancytree-expander").length) {
  7925. res.type = "expander";
  7926. }
  7927. }
  7928. return res;
  7929. },
  7930. /** Return a string describing the affected node region for a mouse event.
  7931. *
  7932. * @param {Event} event Mouse event, e.g. click, mousemove, ...
  7933. * @returns {string} 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7934. */
  7935. getEventTargetType: function (event) {
  7936. return this.getEventTarget(event).type;
  7937. },
  7938. /** Return a FancytreeNode instance from element, event, or jQuery object.
  7939. *
  7940. * @param {Element | jQueryObject | Event} el
  7941. * @returns {FancytreeNode} matching node or null
  7942. */
  7943. getNode: function (el) {
  7944. if (el instanceof FancytreeNode) {
  7945. return el; // el already was a FancytreeNode
  7946. } else if (el instanceof $) {
  7947. el = el[0]; // el was a jQuery object: use the DOM element
  7948. } else if (el.originalEvent !== undefined) {
  7949. el = el.target; // el was an Event
  7950. }
  7951. while (el) {
  7952. if (el.ftnode) {
  7953. return el.ftnode;
  7954. }
  7955. el = el.parentNode;
  7956. }
  7957. return null;
  7958. },
  7959. /** Return a Fancytree instance, from element, index, event, or jQueryObject.
  7960. *
  7961. * @param {Element | jQueryObject | Event | integer | string} [el]
  7962. * @returns {Fancytree} matching tree or null
  7963. * @example
  7964. * $.ui.fancytree.getTree(); // Get first Fancytree instance on page
  7965. * $.ui.fancytree.getTree(1); // Get second Fancytree instance on page
  7966. * $.ui.fancytree.getTree(event); // Get tree for this mouse- or keyboard event
  7967. * $.ui.fancytree.getTree("foo"); // Get tree for this `opts.treeId`
  7968. * $.ui.fancytree.getTree("#tree"); // Get tree for this matching element
  7969. *
  7970. * @since 2.13
  7971. */
  7972. getTree: function (el) {
  7973. var widget,
  7974. orgEl = el;
  7975. if (el instanceof Fancytree) {
  7976. return el; // el already was a Fancytree
  7977. }
  7978. if (el === undefined) {
  7979. el = 0; // get first tree
  7980. }
  7981. if (typeof el === "number") {
  7982. el = $(".fancytree-container").eq(el); // el was an integer: return nth instance
  7983. } else if (typeof el === "string") {
  7984. // `el` may be a treeId or a selector:
  7985. el = $("#ft-id-" + orgEl).eq(0);
  7986. if (!el.length) {
  7987. el = $(orgEl).eq(0); // el was a selector: use first match
  7988. }
  7989. } else if (
  7990. el instanceof Element ||
  7991. el instanceof HTMLDocument
  7992. ) {
  7993. el = $(el);
  7994. } else if (el instanceof $) {
  7995. el = el.eq(0); // el was a jQuery object: use the first
  7996. } else if (el.originalEvent !== undefined) {
  7997. el = $(el.target); // el was an Event
  7998. }
  7999. // el is a jQuery object wit one element here
  8000. el = el.closest(":ui-fancytree");
  8001. widget = el.data("ui-fancytree") || el.data("fancytree"); // the latter is required by jQuery <= 1.8
  8002. return widget ? widget.tree : null;
  8003. },
  8004. /** Return an option value that has a default, but may be overridden by a
  8005. * callback or a node instance attribute.
  8006. *
  8007. * Evaluation sequence:
  8008. *
  8009. * If `tree.options.<optionName>` is a callback that returns something, use that.
  8010. * Else if `node.<optionName>` is defined, use that.
  8011. * Else if `tree.options.<optionName>` is a value, use that.
  8012. * Else use `defaultValue`.
  8013. *
  8014. * @param {string} optionName name of the option property (on node and tree)
  8015. * @param {FancytreeNode} node passed to the callback
  8016. * @param {object} nodeObject where to look for the local option property, e.g. `node` or `node.data`
  8017. * @param {object} treeOption where to look for the tree option, e.g. `tree.options` or `tree.options.dnd5`
  8018. * @param {any} [defaultValue]
  8019. * @returns {any}
  8020. *
  8021. * @example
  8022. * // Check for node.foo, tree,options.foo(), and tree.options.foo:
  8023. * $.ui.fancytree.evalOption("foo", node, node, tree.options);
  8024. * // Check for node.data.bar, tree,options.qux.bar(), and tree.options.qux.bar:
  8025. * $.ui.fancytree.evalOption("bar", node, node.data, tree.options.qux);
  8026. *
  8027. * @since 2.22
  8028. */
  8029. evalOption: function (
  8030. optionName,
  8031. node,
  8032. nodeObject,
  8033. treeOptions,
  8034. defaultValue
  8035. ) {
  8036. var ctx,
  8037. res,
  8038. tree = node.tree,
  8039. treeOpt = treeOptions[optionName],
  8040. nodeOpt = nodeObject[optionName];
  8041. if (_isFunction(treeOpt)) {
  8042. ctx = {
  8043. node: node,
  8044. tree: tree,
  8045. widget: tree.widget,
  8046. options: tree.widget.options,
  8047. typeInfo: tree.types[node.type] || {},
  8048. };
  8049. res = treeOpt.call(tree, { type: optionName }, ctx);
  8050. if (res == null) {
  8051. res = nodeOpt;
  8052. }
  8053. } else {
  8054. res = nodeOpt == null ? treeOpt : nodeOpt;
  8055. }
  8056. if (res == null) {
  8057. res = defaultValue; // no option set at all: return default
  8058. }
  8059. return res;
  8060. },
  8061. /** Set expander, checkbox, or node icon, supporting string and object format.
  8062. *
  8063. * @param {Element | jQueryObject} span
  8064. * @param {string} baseClass
  8065. * @param {string | object} icon
  8066. * @since 2.27
  8067. */
  8068. setSpanIcon: function (span, baseClass, icon) {
  8069. var $span = $(span);
  8070. if (typeof icon === "string") {
  8071. $span.attr("class", baseClass + " " + icon);
  8072. } else {
  8073. // support object syntax: { text: ligature, addClasse: classname }
  8074. if (icon.text) {
  8075. $span.text("" + icon.text);
  8076. } else if (icon.html) {
  8077. span.innerHTML = icon.html;
  8078. }
  8079. $span.attr(
  8080. "class",
  8081. baseClass + " " + (icon.addClass || "")
  8082. );
  8083. }
  8084. },
  8085. /** Convert a keydown or mouse event to a canonical string like 'ctrl+a',
  8086. * 'ctrl+shift+f2', 'shift+leftdblclick'.
  8087. *
  8088. * This is especially handy for switch-statements in event handlers.
  8089. *
  8090. * @param {event}
  8091. * @returns {string}
  8092. *
  8093. * @example
  8094. switch( $.ui.fancytree.eventToString(event) ) {
  8095. case "-":
  8096. tree.nodeSetExpanded(ctx, false);
  8097. break;
  8098. case "shift+return":
  8099. tree.nodeSetActive(ctx, true);
  8100. break;
  8101. case "down":
  8102. res = node.navigate(event.which, activate);
  8103. break;
  8104. default:
  8105. handled = false;
  8106. }
  8107. if( handled ){
  8108. event.preventDefault();
  8109. }
  8110. */
  8111. eventToString: function (event) {
  8112. // Poor-man's hotkeys. See here for a complete implementation:
  8113. // https://github.com/jeresig/jquery.hotkeys
  8114. var which = event.which,
  8115. et = event.type,
  8116. s = [];
  8117. if (event.altKey) {
  8118. s.push("alt");
  8119. }
  8120. if (event.ctrlKey) {
  8121. s.push("ctrl");
  8122. }
  8123. if (event.metaKey) {
  8124. s.push("meta");
  8125. }
  8126. if (event.shiftKey) {
  8127. s.push("shift");
  8128. }
  8129. if (et === "click" || et === "dblclick") {
  8130. s.push(MOUSE_BUTTONS[event.button] + et);
  8131. } else if (et === "wheel") {
  8132. s.push(et);
  8133. } else if (!IGNORE_KEYCODES[which]) {
  8134. s.push(
  8135. SPECIAL_KEYCODES[which] ||
  8136. String.fromCharCode(which).toLowerCase()
  8137. );
  8138. }
  8139. return s.join("+");
  8140. },
  8141. /** Write message to console if debugLevel >= 3
  8142. * @param {string} msg
  8143. */
  8144. info: function (msg) {
  8145. if ($.ui.fancytree.debugLevel >= 3) {
  8146. consoleApply("info", arguments);
  8147. }
  8148. },
  8149. /* @deprecated: use eventToString(event) instead.
  8150. */
  8151. keyEventToString: function (event) {
  8152. this.warn(
  8153. "keyEventToString() is deprecated: use eventToString()"
  8154. );
  8155. return this.eventToString(event);
  8156. },
  8157. /** Return a wrapped handler method, that provides `this._super`.
  8158. *
  8159. * @example
  8160. // Implement `opts.createNode` event to add the 'draggable' attribute
  8161. $.ui.fancytree.overrideMethod(ctx.options, "createNode", function(event, data) {
  8162. // Default processing if any
  8163. this._super.apply(this, arguments);
  8164. // Add 'draggable' attribute
  8165. data.node.span.draggable = true;
  8166. });
  8167. *
  8168. * @param {object} instance
  8169. * @param {string} methodName
  8170. * @param {function} handler
  8171. * @param {object} [context] optional context
  8172. */
  8173. overrideMethod: function (instance, methodName, handler, context) {
  8174. var prevSuper,
  8175. _super = instance[methodName] || $.noop;
  8176. instance[methodName] = function () {
  8177. var self = context || this;
  8178. try {
  8179. prevSuper = self._super;
  8180. self._super = _super;
  8181. return handler.apply(self, arguments);
  8182. } finally {
  8183. self._super = prevSuper;
  8184. }
  8185. };
  8186. },
  8187. /**
  8188. * Parse tree data from HTML <ul> markup
  8189. *
  8190. * @param {jQueryObject} $ul
  8191. * @returns {NodeData[]}
  8192. */
  8193. parseHtml: function ($ul) {
  8194. var classes,
  8195. className,
  8196. extraClasses,
  8197. i,
  8198. iPos,
  8199. l,
  8200. tmp,
  8201. tmp2,
  8202. $children = $ul.find(">li"),
  8203. children = [];
  8204. $children.each(function () {
  8205. var allData,
  8206. lowerCaseAttr,
  8207. $li = $(this),
  8208. $liSpan = $li.find(">span", this).first(),
  8209. $liA = $liSpan.length ? null : $li.find(">a").first(),
  8210. d = { tooltip: null, data: {} };
  8211. if ($liSpan.length) {
  8212. d.title = $liSpan.html();
  8213. } else if ($liA && $liA.length) {
  8214. // If a <li><a> tag is specified, use it literally and extract href/target.
  8215. d.title = $liA.html();
  8216. d.data.href = $liA.attr("href");
  8217. d.data.target = $liA.attr("target");
  8218. d.tooltip = $liA.attr("title");
  8219. } else {
  8220. // If only a <li> tag is specified, use the trimmed string up to
  8221. // the next child <ul> tag.
  8222. d.title = $li.html();
  8223. iPos = d.title.search(/<ul/i);
  8224. if (iPos >= 0) {
  8225. d.title = d.title.substring(0, iPos);
  8226. }
  8227. }
  8228. d.title = _trim(d.title);
  8229. // Make sure all fields exist
  8230. for (i = 0, l = CLASS_ATTRS.length; i < l; i++) {
  8231. d[CLASS_ATTRS[i]] = undefined;
  8232. }
  8233. // Initialize to `true`, if class is set and collect extraClasses
  8234. classes = this.className.split(" ");
  8235. extraClasses = [];
  8236. for (i = 0, l = classes.length; i < l; i++) {
  8237. className = classes[i];
  8238. if (CLASS_ATTR_MAP[className]) {
  8239. d[className] = true;
  8240. } else {
  8241. extraClasses.push(className);
  8242. }
  8243. }
  8244. d.extraClasses = extraClasses.join(" ");
  8245. // Parse node options from ID, title and class attributes
  8246. tmp = $li.attr("title");
  8247. if (tmp) {
  8248. d.tooltip = tmp; // overrides <a title='...'>
  8249. }
  8250. tmp = $li.attr("id");
  8251. if (tmp) {
  8252. d.key = tmp;
  8253. }
  8254. // Translate hideCheckbox -> checkbox:false
  8255. if ($li.attr("hideCheckbox")) {
  8256. d.checkbox = false;
  8257. }
  8258. // Add <li data-NAME='...'> as node.data.NAME
  8259. allData = _getElementDataAsDict($li);
  8260. if (allData && !$.isEmptyObject(allData)) {
  8261. // #507: convert data-hidecheckbox (lower case) to hideCheckbox
  8262. for (lowerCaseAttr in NODE_ATTR_LOWERCASE_MAP) {
  8263. if (_hasProp(allData, lowerCaseAttr)) {
  8264. allData[
  8265. NODE_ATTR_LOWERCASE_MAP[lowerCaseAttr]
  8266. ] = allData[lowerCaseAttr];
  8267. delete allData[lowerCaseAttr];
  8268. }
  8269. }
  8270. // #56: Allow to set special node.attributes from data-...
  8271. for (i = 0, l = NODE_ATTRS.length; i < l; i++) {
  8272. tmp = NODE_ATTRS[i];
  8273. tmp2 = allData[tmp];
  8274. if (tmp2 != null) {
  8275. delete allData[tmp];
  8276. d[tmp] = tmp2;
  8277. }
  8278. }
  8279. // All other data-... goes to node.data...
  8280. $.extend(d.data, allData);
  8281. }
  8282. // Recursive reading of child nodes, if LI tag contains an UL tag
  8283. $ul = $li.find(">ul").first();
  8284. if ($ul.length) {
  8285. d.children = $.ui.fancytree.parseHtml($ul);
  8286. } else {
  8287. d.children = d.lazy ? undefined : null;
  8288. }
  8289. children.push(d);
  8290. // FT.debug("parse ", d, children);
  8291. });
  8292. return children;
  8293. },
  8294. /** Add Fancytree extension definition to the list of globally available extensions.
  8295. *
  8296. * @param {object} definition
  8297. */
  8298. registerExtension: function (definition) {
  8299. _assert(
  8300. definition.name != null,
  8301. "extensions must have a `name` property."
  8302. );
  8303. _assert(
  8304. definition.version != null,
  8305. "extensions must have a `version` property."
  8306. );
  8307. $.ui.fancytree._extensions[definition.name] = definition;
  8308. },
  8309. /** Replacement for the deprecated `jQuery.trim()`.
  8310. *
  8311. * @param {string} text
  8312. */
  8313. trim: _trim,
  8314. /** Inverse of escapeHtml().
  8315. *
  8316. * @param {string} s
  8317. * @returns {string}
  8318. */
  8319. unescapeHtml: function (s) {
  8320. var e = document.createElement("div");
  8321. e.innerHTML = s;
  8322. return e.childNodes.length === 0
  8323. ? ""
  8324. : e.childNodes[0].nodeValue;
  8325. },
  8326. /** Write warning message to console if debugLevel >= 2.
  8327. * @param {string} msg
  8328. */
  8329. warn: function (msg) {
  8330. if ($.ui.fancytree.debugLevel >= 2) {
  8331. consoleApply("warn", arguments);
  8332. }
  8333. },
  8334. }
  8335. );
  8336. // Value returned by `require('jquery.fancytree')`
  8337. return $.ui.fancytree;
  8338. }); // End of closure
  8339. /*! Extension 'jquery.fancytree.childcounter.js' */// Extending Fancytree
  8340. // ===================
  8341. //
  8342. // See also the [live demo](https://wwWendt.de/tech/fancytree/demo/sample-ext-childcounter.html) of this code.
  8343. //
  8344. // Every extension should have a comment header containing some information
  8345. // about the author, copyright and licensing. Also a pointer to the latest
  8346. // source code.
  8347. // Prefix with `/*!` so the comment is not removed by the minifier.
  8348. /*!
  8349. * jquery.fancytree.childcounter.js
  8350. *
  8351. * Add a child counter bubble to tree nodes.
  8352. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8353. *
  8354. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  8355. *
  8356. * Released under the MIT license
  8357. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8358. *
  8359. * @version 2.38.5
  8360. * @date 2025-04-05T06:40:00Z
  8361. */
  8362. // To keep the global namespace clean, we wrap everything in a closure.
  8363. // The UMD wrapper pattern defines the dependencies on jQuery and the
  8364. // Fancytree core module, and makes sure that we can use the `require()`
  8365. // syntax with package loaders.
  8366. (function (factory) {
  8367. if (typeof define === "function" && define.amd) {
  8368. // AMD. Register as an anonymous module.
  8369. define(["jquery", "./jquery.fancytree"], factory);
  8370. } else if (typeof module === "object" && module.exports) {
  8371. // Node/CommonJS
  8372. require("./jquery.fancytree");
  8373. module.exports = factory(require("jquery"));
  8374. } else {
  8375. // Browser globals
  8376. factory(jQuery);
  8377. }
  8378. })(function ($) {
  8379. // Consider to use [strict mode](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)
  8380. "use strict";
  8381. // The [coding guidelines](http://contribute.jquery.org/style-guide/js/)
  8382. // require jshint /eslint compliance.
  8383. // But for this sample, we want to allow unused variables for demonstration purpose.
  8384. /*eslint-disable no-unused-vars */
  8385. // Adding methods
  8386. // --------------
  8387. // New member functions can be added to the `Fancytree` class.
  8388. // This function will be available for every tree instance:
  8389. //
  8390. // var tree = $.ui.fancytree.getTree("#tree");
  8391. // tree.countSelected(false);
  8392. $.ui.fancytree._FancytreeClass.prototype.countSelected = function (
  8393. topOnly
  8394. ) {
  8395. var tree = this,
  8396. treeOptions = tree.options;
  8397. return tree.getSelectedNodes(topOnly).length;
  8398. };
  8399. // The `FancytreeNode` class can also be easily extended. This would be called
  8400. // like
  8401. // node.updateCounters();
  8402. //
  8403. // It is also good practice to add a docstring comment.
  8404. /**
  8405. * [ext-childcounter] Update counter badges for `node` and its parents.
  8406. * May be called in the `loadChildren` event, to update parents of lazy loaded
  8407. * nodes.
  8408. * @alias FancytreeNode#updateCounters
  8409. * @requires jquery.fancytree.childcounters.js
  8410. */
  8411. $.ui.fancytree._FancytreeNodeClass.prototype.updateCounters = function () {
  8412. var node = this,
  8413. $badge = $("span.fancytree-childcounter", node.span),
  8414. extOpts = node.tree.options.childcounter,
  8415. count = node.countChildren(extOpts.deep);
  8416. node.data.childCounter = count;
  8417. if (
  8418. (count || !extOpts.hideZeros) &&
  8419. (!node.isExpanded() || !extOpts.hideExpanded)
  8420. ) {
  8421. if (!$badge.length) {
  8422. $badge = $("<span class='fancytree-childcounter'/>").appendTo(
  8423. $(
  8424. "span.fancytree-icon,span.fancytree-custom-icon",
  8425. node.span
  8426. )
  8427. );
  8428. }
  8429. $badge.text(count);
  8430. } else {
  8431. $badge.remove();
  8432. }
  8433. if (extOpts.deep && !node.isTopLevel() && !node.isRootNode()) {
  8434. node.parent.updateCounters();
  8435. }
  8436. };
  8437. // Finally, we can extend the widget API and create functions that are called
  8438. // like so:
  8439. //
  8440. // $("#tree").fancytree("widgetMethod1", "abc");
  8441. $.ui.fancytree.prototype.widgetMethod1 = function (arg1) {
  8442. var tree = this.tree;
  8443. return arg1;
  8444. };
  8445. // Register a Fancytree extension
  8446. // ------------------------------
  8447. // A full blown extension, extension is available for all trees and can be
  8448. // enabled like so (see also the [live demo](https://wwWendt.de/tech/fancytree/demo/sample-ext-childcounter.html)):
  8449. //
  8450. // <script src="../src/jquery.fancytree.js"></script>
  8451. // <script src="../src/jquery.fancytree.childcounter.js"></script>
  8452. // ...
  8453. //
  8454. // $("#tree").fancytree({
  8455. // extensions: ["childcounter"],
  8456. // childcounter: {
  8457. // hideExpanded: true
  8458. // },
  8459. // ...
  8460. // });
  8461. //
  8462. /* 'childcounter' extension */
  8463. $.ui.fancytree.registerExtension({
  8464. // Every extension must be registered by a unique name.
  8465. name: "childcounter",
  8466. // Version information should be compliant with [semver](http://semver.org)
  8467. version: "2.38.5",
  8468. // Extension specific options and their defaults.
  8469. // This options will be available as `tree.options.childcounter.hideExpanded`
  8470. options: {
  8471. deep: true,
  8472. hideZeros: true,
  8473. hideExpanded: false,
  8474. },
  8475. // Attributes other than `options` (or functions) can be defined here, and
  8476. // will be added to the tree.ext.EXTNAME namespace, in this case `tree.ext.childcounter.foo`.
  8477. // They can also be accessed as `this._local.foo` from within the extension
  8478. // methods.
  8479. foo: 42,
  8480. // Local functions are prefixed with an underscore '_'.
  8481. // Callable as `this._local._appendCounter()`.
  8482. _appendCounter: function (bar) {
  8483. var tree = this;
  8484. },
  8485. // **Override virtual methods for this extension.**
  8486. //
  8487. // Fancytree implements a number of 'hook methods', prefixed by 'node...' or 'tree...'.
  8488. // with a `ctx` argument (see [EventData](https://wwWendt.de/tech/fancytree/doc/jsdoc/global.html#EventData)
  8489. // for details) and an extended calling context:<br>
  8490. // `this` : the Fancytree instance<br>
  8491. // `this._local`: the namespace that contains extension attributes and private methods (same as this.ext.EXTNAME)<br>
  8492. // `this._super`: the virtual function that was overridden (member of previous extension or Fancytree)
  8493. //
  8494. // See also the [complete list of available hook functions](https://wwWendt.de/tech/fancytree/doc/jsdoc/Fancytree_Hooks.html).
  8495. /* Init */
  8496. // `treeInit` is triggered when a tree is initalized. We can set up classes or
  8497. // bind event handlers here...
  8498. treeInit: function (ctx) {
  8499. var tree = this, // same as ctx.tree,
  8500. opts = ctx.options,
  8501. extOpts = ctx.options.childcounter;
  8502. // Optionally check for dependencies with other extensions
  8503. /* this._requireExtension("glyph", false, false); */
  8504. // Call the base implementation
  8505. this._superApply(arguments);
  8506. // Add a class to the tree container
  8507. this.$container.addClass("fancytree-ext-childcounter");
  8508. },
  8509. // Destroy this tree instance (we only call the default implementation, so
  8510. // this method could as well be omitted).
  8511. treeDestroy: function (ctx) {
  8512. this._superApply(arguments);
  8513. },
  8514. // Overload the `renderTitle` hook, to append a counter badge
  8515. nodeRenderTitle: function (ctx, title) {
  8516. var node = ctx.node,
  8517. extOpts = ctx.options.childcounter,
  8518. count =
  8519. node.data.childCounter == null
  8520. ? node.countChildren(extOpts.deep)
  8521. : +node.data.childCounter;
  8522. // Let the base implementation render the title
  8523. // We use `_super()` instead of `_superApply()` here, since it is a little bit
  8524. // more performant when called often
  8525. this._super(ctx, title);
  8526. // Append a counter badge
  8527. if (
  8528. (count || !extOpts.hideZeros) &&
  8529. (!node.isExpanded() || !extOpts.hideExpanded)
  8530. ) {
  8531. $(
  8532. "span.fancytree-icon,span.fancytree-custom-icon",
  8533. node.span
  8534. ).append(
  8535. $("<span class='fancytree-childcounter'/>").text(count)
  8536. );
  8537. }
  8538. },
  8539. // Overload the `setExpanded` hook, so the counters are updated
  8540. nodeSetExpanded: function (ctx, flag, callOpts) {
  8541. var tree = ctx.tree,
  8542. node = ctx.node;
  8543. // Let the base implementation expand/collapse the node, then redraw the title
  8544. // after the animation has finished
  8545. return this._superApply(arguments).always(function () {
  8546. tree.nodeRenderTitle(ctx);
  8547. });
  8548. },
  8549. // End of extension definition
  8550. });
  8551. // Value returned by `require('jquery.fancytree..')`
  8552. return $.ui.fancytree;
  8553. }); // End of closure
  8554. /*! Extension 'jquery.fancytree.clones.js' *//*!
  8555. *
  8556. * jquery.fancytree.clones.js
  8557. * Support faster lookup of nodes by key and shared ref-ids.
  8558. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8559. *
  8560. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  8561. *
  8562. * Released under the MIT license
  8563. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8564. *
  8565. * @version 2.38.5
  8566. * @date 2025-04-05T06:40:00Z
  8567. */
  8568. (function (factory) {
  8569. if (typeof define === "function" && define.amd) {
  8570. // AMD. Register as an anonymous module.
  8571. define(["jquery", "./jquery.fancytree"], factory);
  8572. } else if (typeof module === "object" && module.exports) {
  8573. // Node/CommonJS
  8574. require("./jquery.fancytree");
  8575. module.exports = factory(require("jquery"));
  8576. } else {
  8577. // Browser globals
  8578. factory(jQuery);
  8579. }
  8580. })(function ($) {
  8581. "use strict";
  8582. /*******************************************************************************
  8583. * Private functions and variables
  8584. */
  8585. var _assert = $.ui.fancytree.assert;
  8586. /* Return first occurrence of member from array. */
  8587. function _removeArrayMember(arr, elem) {
  8588. // TODO: use Array.indexOf for IE >= 9
  8589. var i;
  8590. for (i = arr.length - 1; i >= 0; i--) {
  8591. if (arr[i] === elem) {
  8592. arr.splice(i, 1);
  8593. return true;
  8594. }
  8595. }
  8596. return false;
  8597. }
  8598. /**
  8599. * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)
  8600. *
  8601. * @author <a href="mailto:[email protected]">Gary Court</a>
  8602. * @see http://github.com/garycourt/murmurhash-js
  8603. * @author <a href="mailto:[email protected]">Austin Appleby</a>
  8604. * @see http://sites.google.com/site/murmurhash/
  8605. *
  8606. * @param {string} key ASCII only
  8607. * @param {boolean} [asString=false]
  8608. * @param {number} seed Positive integer only
  8609. * @return {number} 32-bit positive integer hash
  8610. */
  8611. function hashMurmur3(key, asString, seed) {
  8612. /*eslint-disable no-bitwise */
  8613. var h1b,
  8614. k1,
  8615. remainder = key.length & 3,
  8616. bytes = key.length - remainder,
  8617. h1 = seed,
  8618. c1 = 0xcc9e2d51,
  8619. c2 = 0x1b873593,
  8620. i = 0;
  8621. while (i < bytes) {
  8622. k1 =
  8623. (key.charCodeAt(i) & 0xff) |
  8624. ((key.charCodeAt(++i) & 0xff) << 8) |
  8625. ((key.charCodeAt(++i) & 0xff) << 16) |
  8626. ((key.charCodeAt(++i) & 0xff) << 24);
  8627. ++i;
  8628. k1 =
  8629. ((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
  8630. 0xffffffff;
  8631. k1 = (k1 << 15) | (k1 >>> 17);
  8632. k1 =
  8633. ((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
  8634. 0xffffffff;
  8635. h1 ^= k1;
  8636. h1 = (h1 << 13) | (h1 >>> 19);
  8637. h1b =
  8638. ((h1 & 0xffff) * 5 + ((((h1 >>> 16) * 5) & 0xffff) << 16)) &
  8639. 0xffffffff;
  8640. h1 =
  8641. (h1b & 0xffff) +
  8642. 0x6b64 +
  8643. ((((h1b >>> 16) + 0xe654) & 0xffff) << 16);
  8644. }
  8645. k1 = 0;
  8646. switch (remainder) {
  8647. case 3:
  8648. k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
  8649. // fall through
  8650. case 2:
  8651. k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
  8652. // fall through
  8653. case 1:
  8654. k1 ^= key.charCodeAt(i) & 0xff;
  8655. k1 =
  8656. ((k1 & 0xffff) * c1 +
  8657. ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
  8658. 0xffffffff;
  8659. k1 = (k1 << 15) | (k1 >>> 17);
  8660. k1 =
  8661. ((k1 & 0xffff) * c2 +
  8662. ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
  8663. 0xffffffff;
  8664. h1 ^= k1;
  8665. }
  8666. h1 ^= key.length;
  8667. h1 ^= h1 >>> 16;
  8668. h1 =
  8669. ((h1 & 0xffff) * 0x85ebca6b +
  8670. ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) &
  8671. 0xffffffff;
  8672. h1 ^= h1 >>> 13;
  8673. h1 =
  8674. ((h1 & 0xffff) * 0xc2b2ae35 +
  8675. ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16)) &
  8676. 0xffffffff;
  8677. h1 ^= h1 >>> 16;
  8678. if (asString) {
  8679. // Convert to 8 digit hex string
  8680. return ("0000000" + (h1 >>> 0).toString(16)).substr(-8);
  8681. }
  8682. return h1 >>> 0;
  8683. /*eslint-enable no-bitwise */
  8684. }
  8685. /*
  8686. * Return a unique key for node by calculating the hash of the parents refKey-list.
  8687. */
  8688. function calcUniqueKey(node) {
  8689. var key,
  8690. h1,
  8691. path = $.map(node.getParentList(false, true), function (e) {
  8692. return e.refKey || e.key;
  8693. });
  8694. path = path.join("/");
  8695. // 32-bit has a high probability of collisions, so we pump up to 64-bit
  8696. // https://security.stackexchange.com/q/209882/207588
  8697. h1 = hashMurmur3(path, true);
  8698. key = "id_" + h1 + hashMurmur3(h1 + path, true);
  8699. return key;
  8700. }
  8701. /**
  8702. * [ext-clones] Return a list of clone-nodes (i.e. same refKey) or null.
  8703. * @param {boolean} [includeSelf=false]
  8704. * @returns {FancytreeNode[] | null}
  8705. *
  8706. * @alias FancytreeNode#getCloneList
  8707. * @requires jquery.fancytree.clones.js
  8708. */
  8709. $.ui.fancytree._FancytreeNodeClass.prototype.getCloneList = function (
  8710. includeSelf
  8711. ) {
  8712. var key,
  8713. tree = this.tree,
  8714. refList = tree.refMap[this.refKey] || null,
  8715. keyMap = tree.keyMap;
  8716. if (refList) {
  8717. key = this.key;
  8718. // Convert key list to node list
  8719. if (includeSelf) {
  8720. refList = $.map(refList, function (val) {
  8721. return keyMap[val];
  8722. });
  8723. } else {
  8724. refList = $.map(refList, function (val) {
  8725. return val === key ? null : keyMap[val];
  8726. });
  8727. if (refList.length < 1) {
  8728. refList = null;
  8729. }
  8730. }
  8731. }
  8732. return refList;
  8733. };
  8734. /**
  8735. * [ext-clones] Return true if this node has at least another clone with same refKey.
  8736. * @returns {boolean}
  8737. *
  8738. * @alias FancytreeNode#isClone
  8739. * @requires jquery.fancytree.clones.js
  8740. */
  8741. $.ui.fancytree._FancytreeNodeClass.prototype.isClone = function () {
  8742. var refKey = this.refKey || null,
  8743. refList = (refKey && this.tree.refMap[refKey]) || null;
  8744. return !!(refList && refList.length > 1);
  8745. };
  8746. /**
  8747. * [ext-clones] Update key and/or refKey for an existing node.
  8748. * @param {string} key
  8749. * @param {string} refKey
  8750. * @returns {boolean}
  8751. *
  8752. * @alias FancytreeNode#reRegister
  8753. * @requires jquery.fancytree.clones.js
  8754. */
  8755. $.ui.fancytree._FancytreeNodeClass.prototype.reRegister = function (
  8756. key,
  8757. refKey
  8758. ) {
  8759. key = key == null ? null : "" + key;
  8760. refKey = refKey == null ? null : "" + refKey;
  8761. // this.debug("reRegister", key, refKey);
  8762. var tree = this.tree,
  8763. prevKey = this.key,
  8764. prevRefKey = this.refKey,
  8765. keyMap = tree.keyMap,
  8766. refMap = tree.refMap,
  8767. refList = refMap[prevRefKey] || null,
  8768. // curCloneKeys = refList ? node.getCloneList(true),
  8769. modified = false;
  8770. // Key has changed: update all references
  8771. if (key != null && key !== this.key) {
  8772. if (keyMap[key]) {
  8773. $.error(
  8774. "[ext-clones] reRegister(" +
  8775. key +
  8776. "): already exists: " +
  8777. this
  8778. );
  8779. }
  8780. // Update keyMap
  8781. delete keyMap[prevKey];
  8782. keyMap[key] = this;
  8783. // Update refMap
  8784. if (refList) {
  8785. refMap[prevRefKey] = $.map(refList, function (e) {
  8786. return e === prevKey ? key : e;
  8787. });
  8788. }
  8789. this.key = key;
  8790. modified = true;
  8791. }
  8792. // refKey has changed
  8793. if (refKey != null && refKey !== this.refKey) {
  8794. // Remove previous refKeys
  8795. if (refList) {
  8796. if (refList.length === 1) {
  8797. delete refMap[prevRefKey];
  8798. } else {
  8799. refMap[prevRefKey] = $.map(refList, function (e) {
  8800. return e === prevKey ? null : e;
  8801. });
  8802. }
  8803. }
  8804. // Add refKey
  8805. if (refMap[refKey]) {
  8806. refMap[refKey].append(key);
  8807. } else {
  8808. refMap[refKey] = [this.key];
  8809. }
  8810. this.refKey = refKey;
  8811. modified = true;
  8812. }
  8813. return modified;
  8814. };
  8815. /**
  8816. * [ext-clones] Define a refKey for an existing node.
  8817. * @param {string} refKey
  8818. * @returns {boolean}
  8819. *
  8820. * @alias FancytreeNode#setRefKey
  8821. * @requires jquery.fancytree.clones.js
  8822. * @since 2.16
  8823. */
  8824. $.ui.fancytree._FancytreeNodeClass.prototype.setRefKey = function (refKey) {
  8825. return this.reRegister(null, refKey);
  8826. };
  8827. /**
  8828. * [ext-clones] Return all nodes with a given refKey (null if not found).
  8829. * @param {string} refKey
  8830. * @param {FancytreeNode} [rootNode] optionally restrict results to descendants of this node
  8831. * @returns {FancytreeNode[] | null}
  8832. * @alias Fancytree#getNodesByRef
  8833. * @requires jquery.fancytree.clones.js
  8834. */
  8835. $.ui.fancytree._FancytreeClass.prototype.getNodesByRef = function (
  8836. refKey,
  8837. rootNode
  8838. ) {
  8839. var keyMap = this.keyMap,
  8840. refList = this.refMap[refKey] || null;
  8841. if (refList) {
  8842. // Convert key list to node list
  8843. if (rootNode) {
  8844. refList = $.map(refList, function (val) {
  8845. var node = keyMap[val];
  8846. return node.isDescendantOf(rootNode) ? node : null;
  8847. });
  8848. } else {
  8849. refList = $.map(refList, function (val) {
  8850. return keyMap[val];
  8851. });
  8852. }
  8853. if (refList.length < 1) {
  8854. refList = null;
  8855. }
  8856. }
  8857. return refList;
  8858. };
  8859. /**
  8860. * [ext-clones] Replace a refKey with a new one.
  8861. * @param {string} oldRefKey
  8862. * @param {string} newRefKey
  8863. * @alias Fancytree#changeRefKey
  8864. * @requires jquery.fancytree.clones.js
  8865. */
  8866. $.ui.fancytree._FancytreeClass.prototype.changeRefKey = function (
  8867. oldRefKey,
  8868. newRefKey
  8869. ) {
  8870. var i,
  8871. node,
  8872. keyMap = this.keyMap,
  8873. refList = this.refMap[oldRefKey] || null;
  8874. if (refList) {
  8875. for (i = 0; i < refList.length; i++) {
  8876. node = keyMap[refList[i]];
  8877. node.refKey = newRefKey;
  8878. }
  8879. delete this.refMap[oldRefKey];
  8880. this.refMap[newRefKey] = refList;
  8881. }
  8882. };
  8883. /*******************************************************************************
  8884. * Extension code
  8885. */
  8886. $.ui.fancytree.registerExtension({
  8887. name: "clones",
  8888. version: "2.38.5",
  8889. // Default options for this extension.
  8890. options: {
  8891. highlightActiveClones: true, // set 'fancytree-active-clone' on active clones and all peers
  8892. highlightClones: false, // set 'fancytree-clone' class on any node that has at least one clone
  8893. },
  8894. treeCreate: function (ctx) {
  8895. this._superApply(arguments);
  8896. ctx.tree.refMap = {};
  8897. ctx.tree.keyMap = {};
  8898. },
  8899. treeInit: function (ctx) {
  8900. this.$container.addClass("fancytree-ext-clones");
  8901. _assert(ctx.options.defaultKey == null);
  8902. // Generate unique / reproducible default keys
  8903. ctx.options.defaultKey = function (node) {
  8904. return calcUniqueKey(node);
  8905. };
  8906. // The default implementation loads initial data
  8907. this._superApply(arguments);
  8908. },
  8909. treeClear: function (ctx) {
  8910. ctx.tree.refMap = {};
  8911. ctx.tree.keyMap = {};
  8912. return this._superApply(arguments);
  8913. },
  8914. treeRegisterNode: function (ctx, add, node) {
  8915. var refList,
  8916. len,
  8917. tree = ctx.tree,
  8918. keyMap = tree.keyMap,
  8919. refMap = tree.refMap,
  8920. key = node.key,
  8921. refKey = node && node.refKey != null ? "" + node.refKey : null;
  8922. // ctx.tree.debug("clones.treeRegisterNode", add, node);
  8923. if (node.isStatusNode()) {
  8924. return this._super(ctx, add, node);
  8925. }
  8926. if (add) {
  8927. if (keyMap[node.key] != null) {
  8928. var other = keyMap[node.key],
  8929. msg =
  8930. "clones.treeRegisterNode: duplicate key '" +
  8931. node.key +
  8932. "': /" +
  8933. node.getPath(true) +
  8934. " => " +
  8935. other.getPath(true);
  8936. // Sometimes this exception is not visible in the console,
  8937. // so we also write it:
  8938. tree.error(msg);
  8939. $.error(msg);
  8940. }
  8941. keyMap[key] = node;
  8942. if (refKey) {
  8943. refList = refMap[refKey];
  8944. if (refList) {
  8945. refList.push(key);
  8946. if (
  8947. refList.length === 2 &&
  8948. ctx.options.clones.highlightClones
  8949. ) {
  8950. // Mark peer node, if it just became a clone (no need to
  8951. // mark current node, since it will be rendered later anyway)
  8952. keyMap[refList[0]].renderStatus();
  8953. }
  8954. } else {
  8955. refMap[refKey] = [key];
  8956. }
  8957. // node.debug("clones.treeRegisterNode: add clone =>", refMap[refKey]);
  8958. }
  8959. } else {
  8960. if (keyMap[key] == null) {
  8961. $.error(
  8962. "clones.treeRegisterNode: node.key not registered: " +
  8963. node.key
  8964. );
  8965. }
  8966. delete keyMap[key];
  8967. if (refKey) {
  8968. refList = refMap[refKey];
  8969. // node.debug("clones.treeRegisterNode: remove clone BEFORE =>", refMap[refKey]);
  8970. if (refList) {
  8971. len = refList.length;
  8972. if (len <= 1) {
  8973. _assert(len === 1);
  8974. _assert(refList[0] === key);
  8975. delete refMap[refKey];
  8976. } else {
  8977. _removeArrayMember(refList, key);
  8978. // Unmark peer node, if this was the only clone
  8979. if (
  8980. len === 2 &&
  8981. ctx.options.clones.highlightClones
  8982. ) {
  8983. // node.debug("clones.treeRegisterNode: last =>", node.getCloneList());
  8984. keyMap[refList[0]].renderStatus();
  8985. }
  8986. }
  8987. // node.debug("clones.treeRegisterNode: remove clone =>", refMap[refKey]);
  8988. }
  8989. }
  8990. }
  8991. return this._super(ctx, add, node);
  8992. },
  8993. nodeRenderStatus: function (ctx) {
  8994. var $span,
  8995. res,
  8996. node = ctx.node;
  8997. res = this._super(ctx);
  8998. if (ctx.options.clones.highlightClones) {
  8999. $span = $(node[ctx.tree.statusClassPropName]);
  9000. // Only if span already exists
  9001. if ($span.length && node.isClone()) {
  9002. // node.debug("clones.nodeRenderStatus: ", ctx.options.clones.highlightClones);
  9003. $span.addClass("fancytree-clone");
  9004. }
  9005. }
  9006. return res;
  9007. },
  9008. nodeSetActive: function (ctx, flag, callOpts) {
  9009. var res,
  9010. scpn = ctx.tree.statusClassPropName,
  9011. node = ctx.node;
  9012. res = this._superApply(arguments);
  9013. if (ctx.options.clones.highlightActiveClones && node.isClone()) {
  9014. $.each(node.getCloneList(true), function (idx, n) {
  9015. // n.debug("clones.nodeSetActive: ", flag !== false);
  9016. $(n[scpn]).toggleClass(
  9017. "fancytree-active-clone",
  9018. flag !== false
  9019. );
  9020. });
  9021. }
  9022. return res;
  9023. },
  9024. });
  9025. // Value returned by `require('jquery.fancytree..')`
  9026. return $.ui.fancytree;
  9027. }); // End of closure
  9028. /*! Extension 'jquery.fancytree.dnd5.js' *//*!
  9029. * jquery.fancytree.dnd5.js
  9030. *
  9031. * Drag-and-drop support (native HTML5).
  9032. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  9033. *
  9034. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  9035. *
  9036. * Released under the MIT license
  9037. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  9038. *
  9039. * @version 2.38.5
  9040. * @date 2025-04-05T06:40:00Z
  9041. */
  9042. /*
  9043. #TODO
  9044. Compatiblity when dragging between *separate* windows:
  9045. Drag from Chrome Edge FF IE11 Safari
  9046. To Chrome ok ok ok NO ?
  9047. Edge ok ok ok NO ?
  9048. FF ok ok ok NO ?
  9049. IE 11 ok ok ok ok ?
  9050. Safari ? ? ? ? ok
  9051. */
  9052. (function (factory) {
  9053. if (typeof define === "function" && define.amd) {
  9054. // AMD. Register as an anonymous module.
  9055. define(["jquery", "./jquery.fancytree"], factory);
  9056. } else if (typeof module === "object" && module.exports) {
  9057. // Node/CommonJS
  9058. require("./jquery.fancytree");
  9059. module.exports = factory(require("jquery"));
  9060. } else {
  9061. // Browser globals
  9062. factory(jQuery);
  9063. }
  9064. })(function ($) {
  9065. "use strict";
  9066. /******************************************************************************
  9067. * Private functions and variables
  9068. */
  9069. var FT = $.ui.fancytree,
  9070. isMac = /Mac/.test(navigator.platform),
  9071. classDragSource = "fancytree-drag-source",
  9072. classDragRemove = "fancytree-drag-remove",
  9073. classDropAccept = "fancytree-drop-accept",
  9074. classDropAfter = "fancytree-drop-after",
  9075. classDropBefore = "fancytree-drop-before",
  9076. classDropOver = "fancytree-drop-over",
  9077. classDropReject = "fancytree-drop-reject",
  9078. classDropTarget = "fancytree-drop-target",
  9079. nodeMimeType = "application/x-fancytree-node",
  9080. $dropMarker = null,
  9081. $dragImage,
  9082. $extraHelper,
  9083. SOURCE_NODE = null,
  9084. SOURCE_NODE_LIST = null,
  9085. $sourceList = null,
  9086. DRAG_ENTER_RESPONSE = null,
  9087. // SESSION_DATA = null, // plain object passed to events as `data`
  9088. SUGGESTED_DROP_EFFECT = null,
  9089. REQUESTED_DROP_EFFECT = null,
  9090. REQUESTED_EFFECT_ALLOWED = null,
  9091. LAST_HIT_MODE = null,
  9092. DRAG_OVER_STAMP = null; // Time when a node entered the 'over' hitmode
  9093. /* */
  9094. function _clearGlobals() {
  9095. DRAG_ENTER_RESPONSE = null;
  9096. DRAG_OVER_STAMP = null;
  9097. REQUESTED_DROP_EFFECT = null;
  9098. REQUESTED_EFFECT_ALLOWED = null;
  9099. SUGGESTED_DROP_EFFECT = null;
  9100. SOURCE_NODE = null;
  9101. SOURCE_NODE_LIST = null;
  9102. if ($sourceList) {
  9103. $sourceList.removeClass(classDragSource + " " + classDragRemove);
  9104. }
  9105. $sourceList = null;
  9106. if ($dropMarker) {
  9107. $dropMarker.hide();
  9108. }
  9109. // Take this badge off of me - I can't use it anymore:
  9110. if ($extraHelper) {
  9111. $extraHelper.remove();
  9112. $extraHelper = null;
  9113. }
  9114. }
  9115. /* Convert number to string and prepend +/-; return empty string for 0.*/
  9116. function offsetString(n) {
  9117. // eslint-disable-next-line no-nested-ternary
  9118. return n === 0 ? "" : n > 0 ? "+" + n : "" + n;
  9119. }
  9120. /* Convert a dragEnter() or dragOver() response to a canonical form.
  9121. * Return false or plain object
  9122. * @param {string|object|boolean} r
  9123. * @return {object|false}
  9124. */
  9125. function normalizeDragEnterResponse(r) {
  9126. var res;
  9127. if (!r) {
  9128. return false;
  9129. }
  9130. if ($.isPlainObject(r)) {
  9131. res = {
  9132. over: !!r.over,
  9133. before: !!r.before,
  9134. after: !!r.after,
  9135. };
  9136. } else if (Array.isArray(r)) {
  9137. res = {
  9138. over: $.inArray("over", r) >= 0,
  9139. before: $.inArray("before", r) >= 0,
  9140. after: $.inArray("after", r) >= 0,
  9141. };
  9142. } else {
  9143. res = {
  9144. over: r === true || r === "over",
  9145. before: r === true || r === "before",
  9146. after: r === true || r === "after",
  9147. };
  9148. }
  9149. if (Object.keys(res).length === 0) {
  9150. return false;
  9151. }
  9152. // if( Object.keys(res).length === 1 ) {
  9153. // res.unique = res[0];
  9154. // }
  9155. return res;
  9156. }
  9157. /* Convert a dataTransfer.effectAllowed to a canonical form.
  9158. * Return false or plain object
  9159. * @param {string|boolean} r
  9160. * @return {object|false}
  9161. */
  9162. // function normalizeEffectAllowed(r) {
  9163. // if (!r || r === "none") {
  9164. // return false;
  9165. // }
  9166. // var all = r === "all",
  9167. // res = {
  9168. // copy: all || /copy/i.test(r),
  9169. // link: all || /link/i.test(r),
  9170. // move: all || /move/i.test(r),
  9171. // };
  9172. // return res;
  9173. // }
  9174. /* Implement auto scrolling when drag cursor is in top/bottom area of scroll parent. */
  9175. function autoScroll(tree, event) {
  9176. var spOfs,
  9177. scrollTop,
  9178. delta,
  9179. dndOpts = tree.options.dnd5,
  9180. sp = tree.$scrollParent[0],
  9181. sensitivity = dndOpts.scrollSensitivity,
  9182. speed = dndOpts.scrollSpeed,
  9183. scrolled = 0;
  9184. if (sp !== document && sp.tagName !== "HTML") {
  9185. spOfs = tree.$scrollParent.offset();
  9186. scrollTop = sp.scrollTop;
  9187. if (spOfs.top + sp.offsetHeight - event.pageY < sensitivity) {
  9188. delta =
  9189. sp.scrollHeight -
  9190. tree.$scrollParent.innerHeight() -
  9191. scrollTop;
  9192. // console.log ("sp.offsetHeight: " + sp.offsetHeight
  9193. // + ", spOfs.top: " + spOfs.top
  9194. // + ", scrollTop: " + scrollTop
  9195. // + ", innerHeight: " + tree.$scrollParent.innerHeight()
  9196. // + ", scrollHeight: " + sp.scrollHeight
  9197. // + ", delta: " + delta
  9198. // );
  9199. if (delta > 0) {
  9200. sp.scrollTop = scrolled = scrollTop + speed;
  9201. }
  9202. } else if (scrollTop > 0 && event.pageY - spOfs.top < sensitivity) {
  9203. sp.scrollTop = scrolled = scrollTop - speed;
  9204. }
  9205. } else {
  9206. scrollTop = $(document).scrollTop();
  9207. if (scrollTop > 0 && event.pageY - scrollTop < sensitivity) {
  9208. scrolled = scrollTop - speed;
  9209. $(document).scrollTop(scrolled);
  9210. } else if (
  9211. $(window).height() - (event.pageY - scrollTop) <
  9212. sensitivity
  9213. ) {
  9214. scrolled = scrollTop + speed;
  9215. $(document).scrollTop(scrolled);
  9216. }
  9217. }
  9218. if (scrolled) {
  9219. tree.debug("autoScroll: " + scrolled + "px");
  9220. }
  9221. return scrolled;
  9222. }
  9223. /* Guess dropEffect from modifier keys.
  9224. * Using rules suggested here:
  9225. * https://ux.stackexchange.com/a/83769
  9226. * @returns
  9227. * 'copy', 'link', 'move', or 'none'
  9228. */
  9229. function evalEffectModifiers(tree, event, effectDefault) {
  9230. var res = effectDefault;
  9231. if (isMac) {
  9232. if (event.metaKey && event.altKey) {
  9233. // Mac: [Control] + [Option]
  9234. res = "link";
  9235. } else if (event.ctrlKey) {
  9236. // Chrome on Mac: [Control]
  9237. res = "link";
  9238. } else if (event.metaKey) {
  9239. // Mac: [Command]
  9240. res = "move";
  9241. } else if (event.altKey) {
  9242. // Mac: [Option]
  9243. res = "copy";
  9244. }
  9245. } else {
  9246. if (event.ctrlKey) {
  9247. // Windows: [Ctrl]
  9248. res = "copy";
  9249. } else if (event.shiftKey) {
  9250. // Windows: [Shift]
  9251. res = "move";
  9252. } else if (event.altKey) {
  9253. // Windows: [Alt]
  9254. res = "link";
  9255. }
  9256. }
  9257. if (res !== SUGGESTED_DROP_EFFECT) {
  9258. tree.info(
  9259. "evalEffectModifiers: " +
  9260. event.type +
  9261. " - evalEffectModifiers(): " +
  9262. SUGGESTED_DROP_EFFECT +
  9263. " -> " +
  9264. res
  9265. );
  9266. }
  9267. SUGGESTED_DROP_EFFECT = res;
  9268. // tree.debug("evalEffectModifiers: " + res);
  9269. return res;
  9270. }
  9271. /*
  9272. * Check if the previous callback (dragEnter, dragOver, ...) has changed
  9273. * the `data` object and apply those settings.
  9274. *
  9275. * Safari:
  9276. * It seems that `dataTransfer.dropEffect` can only be set on dragStart, and will remain
  9277. * even if the cursor changes when [Alt] or [Ctrl] are pressed (?)
  9278. * Using rules suggested here:
  9279. * https://ux.stackexchange.com/a/83769
  9280. * @returns
  9281. * 'copy', 'link', 'move', or 'none'
  9282. */
  9283. function prepareDropEffectCallback(event, data) {
  9284. var tree = data.tree,
  9285. dataTransfer = data.dataTransfer;
  9286. if (event.type === "dragstart") {
  9287. data.effectAllowed = tree.options.dnd5.effectAllowed;
  9288. data.dropEffect = tree.options.dnd5.dropEffectDefault;
  9289. } else {
  9290. data.effectAllowed = REQUESTED_EFFECT_ALLOWED;
  9291. data.dropEffect = REQUESTED_DROP_EFFECT;
  9292. }
  9293. data.dropEffectSuggested = evalEffectModifiers(
  9294. tree,
  9295. event,
  9296. tree.options.dnd5.dropEffectDefault
  9297. );
  9298. data.isMove = data.dropEffect === "move";
  9299. data.files = dataTransfer.files || [];
  9300. // if (REQUESTED_EFFECT_ALLOWED !== dataTransfer.effectAllowed) {
  9301. // tree.warn(
  9302. // "prepareDropEffectCallback(" +
  9303. // event.type +
  9304. // "): dataTransfer.effectAllowed changed from " +
  9305. // REQUESTED_EFFECT_ALLOWED +
  9306. // " -> " +
  9307. // dataTransfer.effectAllowed
  9308. // );
  9309. // }
  9310. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9311. // tree.warn(
  9312. // "prepareDropEffectCallback(" +
  9313. // event.type +
  9314. // "): dataTransfer.dropEffect changed from requested " +
  9315. // REQUESTED_DROP_EFFECT +
  9316. // " to " +
  9317. // dataTransfer.dropEffect
  9318. // );
  9319. // }
  9320. }
  9321. function applyDropEffectCallback(event, data, allowDrop) {
  9322. var tree = data.tree,
  9323. dataTransfer = data.dataTransfer;
  9324. if (
  9325. event.type !== "dragstart" &&
  9326. REQUESTED_EFFECT_ALLOWED !== data.effectAllowed
  9327. ) {
  9328. tree.warn(
  9329. "effectAllowed should only be changed in dragstart event: " +
  9330. event.type +
  9331. ": data.effectAllowed changed from " +
  9332. REQUESTED_EFFECT_ALLOWED +
  9333. " -> " +
  9334. data.effectAllowed
  9335. );
  9336. }
  9337. if (allowDrop === false) {
  9338. tree.info("applyDropEffectCallback: allowDrop === false");
  9339. data.effectAllowed = "none";
  9340. data.dropEffect = "none";
  9341. }
  9342. // if (REQUESTED_DROP_EFFECT !== data.dropEffect) {
  9343. // tree.debug(
  9344. // "applyDropEffectCallback(" +
  9345. // event.type +
  9346. // "): data.dropEffect changed from previous " +
  9347. // REQUESTED_DROP_EFFECT +
  9348. // " to " +
  9349. // data.dropEffect
  9350. // );
  9351. // }
  9352. data.isMove = data.dropEffect === "move";
  9353. // data.isMove = data.dropEffectSuggested === "move";
  9354. // `effectAllowed` must only be defined in dragstart event, so we
  9355. // store it in a global variable for reference
  9356. if (event.type === "dragstart") {
  9357. REQUESTED_EFFECT_ALLOWED = data.effectAllowed;
  9358. REQUESTED_DROP_EFFECT = data.dropEffect;
  9359. }
  9360. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9361. // data.tree.info(
  9362. // "applyDropEffectCallback(" +
  9363. // event.type +
  9364. // "): dataTransfer.dropEffect changed from " +
  9365. // REQUESTED_DROP_EFFECT +
  9366. // " -> " +
  9367. // dataTransfer.dropEffect
  9368. // );
  9369. // }
  9370. dataTransfer.effectAllowed = REQUESTED_EFFECT_ALLOWED;
  9371. dataTransfer.dropEffect = REQUESTED_DROP_EFFECT;
  9372. // tree.debug(
  9373. // "applyDropEffectCallback(" +
  9374. // event.type +
  9375. // "): set " +
  9376. // dataTransfer.dropEffect +
  9377. // "/" +
  9378. // dataTransfer.effectAllowed
  9379. // );
  9380. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9381. // data.tree.warn(
  9382. // "applyDropEffectCallback(" +
  9383. // event.type +
  9384. // "): could not set dataTransfer.dropEffect to " +
  9385. // REQUESTED_DROP_EFFECT +
  9386. // ": got " +
  9387. // dataTransfer.dropEffect
  9388. // );
  9389. // }
  9390. return REQUESTED_DROP_EFFECT;
  9391. }
  9392. /* Handle dragover event (fired every x ms) on valid drop targets.
  9393. *
  9394. * - Auto-scroll when cursor is in border regions
  9395. * - Apply restrictioan like 'preventVoidMoves'
  9396. * - Calculate hit mode
  9397. * - Calculate drop effect
  9398. * - Trigger dragOver() callback to let user modify hit mode and drop effect
  9399. * - Adjust the drop marker accordingly
  9400. *
  9401. * @returns hitMode
  9402. */
  9403. function handleDragOver(event, data) {
  9404. // Implement auto-scrolling
  9405. if (data.options.dnd5.scroll) {
  9406. autoScroll(data.tree, event);
  9407. }
  9408. // Bail out with previous response if we get an invalid dragover
  9409. if (!data.node) {
  9410. data.tree.warn("Ignored dragover for non-node"); //, event, data);
  9411. return LAST_HIT_MODE;
  9412. }
  9413. var markerOffsetX,
  9414. nodeOfs,
  9415. pos,
  9416. relPosY,
  9417. hitMode = null,
  9418. tree = data.tree,
  9419. options = tree.options,
  9420. dndOpts = options.dnd5,
  9421. targetNode = data.node,
  9422. sourceNode = data.otherNode,
  9423. markerAt = "center",
  9424. $target = $(targetNode.span),
  9425. $targetTitle = $target.find("span.fancytree-title");
  9426. if (DRAG_ENTER_RESPONSE === false) {
  9427. tree.debug("Ignored dragover, since dragenter returned false.");
  9428. return false;
  9429. } else if (typeof DRAG_ENTER_RESPONSE === "string") {
  9430. $.error("assert failed: dragenter returned string");
  9431. }
  9432. // Calculate hitMode from relative cursor position.
  9433. nodeOfs = $target.offset();
  9434. relPosY = (event.pageY - nodeOfs.top) / $target.height();
  9435. if (event.pageY === undefined) {
  9436. tree.warn("event.pageY is undefined: see issue #1013.");
  9437. }
  9438. if (DRAG_ENTER_RESPONSE.after && relPosY > 0.75) {
  9439. hitMode = "after";
  9440. } else if (
  9441. !DRAG_ENTER_RESPONSE.over &&
  9442. DRAG_ENTER_RESPONSE.after &&
  9443. relPosY > 0.5
  9444. ) {
  9445. hitMode = "after";
  9446. } else if (DRAG_ENTER_RESPONSE.before && relPosY <= 0.25) {
  9447. hitMode = "before";
  9448. } else if (
  9449. !DRAG_ENTER_RESPONSE.over &&
  9450. DRAG_ENTER_RESPONSE.before &&
  9451. relPosY <= 0.5
  9452. ) {
  9453. hitMode = "before";
  9454. } else if (DRAG_ENTER_RESPONSE.over) {
  9455. hitMode = "over";
  9456. }
  9457. // Prevent no-ops like 'before source node'
  9458. // TODO: these are no-ops when moving nodes, but not in copy mode
  9459. if (dndOpts.preventVoidMoves && data.dropEffect === "move") {
  9460. if (targetNode === sourceNode) {
  9461. targetNode.debug("Drop over source node prevented.");
  9462. hitMode = null;
  9463. } else if (
  9464. hitMode === "before" &&
  9465. sourceNode &&
  9466. targetNode === sourceNode.getNextSibling()
  9467. ) {
  9468. targetNode.debug("Drop after source node prevented.");
  9469. hitMode = null;
  9470. } else if (
  9471. hitMode === "after" &&
  9472. sourceNode &&
  9473. targetNode === sourceNode.getPrevSibling()
  9474. ) {
  9475. targetNode.debug("Drop before source node prevented.");
  9476. hitMode = null;
  9477. } else if (
  9478. hitMode === "over" &&
  9479. sourceNode &&
  9480. sourceNode.parent === targetNode &&
  9481. sourceNode.isLastSibling()
  9482. ) {
  9483. targetNode.debug("Drop last child over own parent prevented.");
  9484. hitMode = null;
  9485. }
  9486. }
  9487. // Let callback modify the calculated hitMode
  9488. data.hitMode = hitMode;
  9489. if (hitMode && dndOpts.dragOver) {
  9490. prepareDropEffectCallback(event, data);
  9491. dndOpts.dragOver(targetNode, data);
  9492. var allowDrop = !!hitMode;
  9493. applyDropEffectCallback(event, data, allowDrop);
  9494. hitMode = data.hitMode;
  9495. }
  9496. LAST_HIT_MODE = hitMode;
  9497. //
  9498. if (hitMode === "after" || hitMode === "before" || hitMode === "over") {
  9499. markerOffsetX = dndOpts.dropMarkerOffsetX || 0;
  9500. switch (hitMode) {
  9501. case "before":
  9502. markerAt = "top";
  9503. markerOffsetX += dndOpts.dropMarkerInsertOffsetX || 0;
  9504. break;
  9505. case "after":
  9506. markerAt = "bottom";
  9507. markerOffsetX += dndOpts.dropMarkerInsertOffsetX || 0;
  9508. break;
  9509. }
  9510. pos = {
  9511. my: "left" + offsetString(markerOffsetX) + " center",
  9512. at: "left " + markerAt,
  9513. of: $targetTitle,
  9514. };
  9515. if (options.rtl) {
  9516. pos.my = "right" + offsetString(-markerOffsetX) + " center";
  9517. pos.at = "right " + markerAt;
  9518. // console.log("rtl", pos);
  9519. }
  9520. $dropMarker
  9521. .toggleClass(classDropAfter, hitMode === "after")
  9522. .toggleClass(classDropOver, hitMode === "over")
  9523. .toggleClass(classDropBefore, hitMode === "before")
  9524. .show()
  9525. .position(FT.fixPositionOptions(pos));
  9526. } else {
  9527. $dropMarker.hide();
  9528. // console.log("hide dropmarker")
  9529. }
  9530. $(targetNode.span)
  9531. .toggleClass(
  9532. classDropTarget,
  9533. hitMode === "after" ||
  9534. hitMode === "before" ||
  9535. hitMode === "over"
  9536. )
  9537. .toggleClass(classDropAfter, hitMode === "after")
  9538. .toggleClass(classDropBefore, hitMode === "before")
  9539. .toggleClass(classDropAccept, hitMode === "over")
  9540. .toggleClass(classDropReject, hitMode === false);
  9541. return hitMode;
  9542. }
  9543. /*
  9544. * Handle dragstart drag dragend events on the container
  9545. */
  9546. function onDragEvent(event) {
  9547. var json,
  9548. tree = this,
  9549. dndOpts = tree.options.dnd5,
  9550. node = FT.getNode(event),
  9551. dataTransfer =
  9552. event.dataTransfer || event.originalEvent.dataTransfer,
  9553. data = {
  9554. tree: tree,
  9555. node: node,
  9556. options: tree.options,
  9557. originalEvent: event.originalEvent,
  9558. widget: tree.widget,
  9559. dataTransfer: dataTransfer,
  9560. useDefaultImage: true,
  9561. dropEffect: undefined,
  9562. dropEffectSuggested: undefined,
  9563. effectAllowed: undefined, // set by dragstart
  9564. files: undefined, // only for drop events
  9565. isCancelled: undefined, // set by dragend
  9566. isMove: undefined,
  9567. };
  9568. switch (event.type) {
  9569. case "dragstart":
  9570. if (!node) {
  9571. tree.info("Ignored dragstart on a non-node.");
  9572. return false;
  9573. }
  9574. // Store current source node in different formats
  9575. SOURCE_NODE = node;
  9576. // Also optionally store selected nodes
  9577. if (dndOpts.multiSource === false) {
  9578. SOURCE_NODE_LIST = [node];
  9579. } else if (dndOpts.multiSource === true) {
  9580. if (node.isSelected()) {
  9581. SOURCE_NODE_LIST = tree.getSelectedNodes();
  9582. } else {
  9583. SOURCE_NODE_LIST = [node];
  9584. }
  9585. } else {
  9586. SOURCE_NODE_LIST = dndOpts.multiSource(node, data);
  9587. }
  9588. // Cache as array of jQuery objects for faster access:
  9589. $sourceList = $(
  9590. $.map(SOURCE_NODE_LIST, function (n) {
  9591. return n.span;
  9592. })
  9593. );
  9594. // Set visual feedback
  9595. $sourceList.addClass(classDragSource);
  9596. // Set payload
  9597. // Note:
  9598. // Transfer data is only accessible on dragstart and drop!
  9599. // For all other events the formats and kinds in the drag
  9600. // data store list of items representing dragged data can be
  9601. // enumerated, but the data itself is unavailable and no new
  9602. // data can be added.
  9603. var nodeData = node.toDict(true, dndOpts.sourceCopyHook);
  9604. nodeData.treeId = node.tree._id;
  9605. json = JSON.stringify(nodeData);
  9606. try {
  9607. dataTransfer.setData(nodeMimeType, json);
  9608. dataTransfer.setData("text/html", $(node.span).html());
  9609. dataTransfer.setData("text/plain", node.title);
  9610. } catch (ex) {
  9611. // IE only accepts 'text' type
  9612. tree.warn(
  9613. "Could not set data (IE only accepts 'text') - " + ex
  9614. );
  9615. }
  9616. // We always need to set the 'text' type if we want to drag
  9617. // Because IE 11 only accepts this single type.
  9618. // If we pass JSON here, IE can can access all node properties,
  9619. // even when the source lives in another window. (D'n'd inside
  9620. // the same window will always work.)
  9621. // The drawback is, that in this case ALL browsers will see
  9622. // the JSON representation as 'text', so dragging
  9623. // to a text field will insert the JSON string instead of
  9624. // the node title.
  9625. if (dndOpts.setTextTypeJson) {
  9626. dataTransfer.setData("text", json);
  9627. } else {
  9628. dataTransfer.setData("text", node.title);
  9629. }
  9630. // Set the allowed drag modes (combinations of move, copy, and link)
  9631. // (effectAllowed can only be set in the dragstart event.)
  9632. // This can be overridden in the dragStart() callback
  9633. prepareDropEffectCallback(event, data);
  9634. // Let user cancel or modify above settings
  9635. // Realize potential changes by previous callback
  9636. if (dndOpts.dragStart(node, data) === false) {
  9637. // Cancel dragging
  9638. // dataTransfer.dropEffect = "none";
  9639. _clearGlobals();
  9640. return false;
  9641. }
  9642. applyDropEffectCallback(event, data);
  9643. // Unless user set `data.useDefaultImage` to false in dragStart,
  9644. // generata a default drag image now:
  9645. $extraHelper = null;
  9646. if (data.useDefaultImage) {
  9647. // Set the title as drag image (otherwise it would contain the expander)
  9648. $dragImage = $(node.span).find(".fancytree-title");
  9649. if (SOURCE_NODE_LIST && SOURCE_NODE_LIST.length > 1) {
  9650. // Add a counter badge to node title if dragging more than one node.
  9651. // We want this, because the element that is used as drag image
  9652. // must be *visible* in the DOM, so we cannot create some hidden
  9653. // custom markup.
  9654. // See https://kryogenix.org/code/browser/custom-drag-image.html
  9655. // Also, since IE 11 and Edge don't support setDragImage() alltogether,
  9656. // it gives som feedback to the user.
  9657. // The badge will be removed later on drag end.
  9658. $extraHelper = $(
  9659. "<span class='fancytree-childcounter'/>"
  9660. )
  9661. .text("+" + (SOURCE_NODE_LIST.length - 1))
  9662. .appendTo($dragImage);
  9663. }
  9664. if (dataTransfer.setDragImage) {
  9665. // IE 11 and Edge do not support this
  9666. dataTransfer.setDragImage($dragImage[0], -10, -10);
  9667. }
  9668. }
  9669. return true;
  9670. case "drag":
  9671. // Called every few milliseconds (no matter if the
  9672. // cursor is over a valid drop target)
  9673. // data.tree.info("drag", SOURCE_NODE)
  9674. prepareDropEffectCallback(event, data);
  9675. dndOpts.dragDrag(node, data);
  9676. applyDropEffectCallback(event, data);
  9677. $sourceList.toggleClass(classDragRemove, data.isMove);
  9678. break;
  9679. case "dragend":
  9680. // Called at the end of a d'n'd process (after drop)
  9681. // Note caveat: If drop removed the dragged source element,
  9682. // we may not get this event, since the target does not exist
  9683. // anymore
  9684. prepareDropEffectCallback(event, data);
  9685. _clearGlobals();
  9686. data.isCancelled = !LAST_HIT_MODE;
  9687. dndOpts.dragEnd(node, data, !LAST_HIT_MODE);
  9688. // applyDropEffectCallback(event, data);
  9689. break;
  9690. }
  9691. }
  9692. /*
  9693. * Handle dragenter dragover dragleave drop events on the container
  9694. */
  9695. function onDropEvent(event) {
  9696. var json,
  9697. allowAutoExpand,
  9698. nodeData,
  9699. isSourceFtNode,
  9700. r,
  9701. res,
  9702. tree = this,
  9703. dndOpts = tree.options.dnd5,
  9704. allowDrop = null,
  9705. node = FT.getNode(event),
  9706. dataTransfer =
  9707. event.dataTransfer || event.originalEvent.dataTransfer,
  9708. data = {
  9709. tree: tree,
  9710. node: node,
  9711. options: tree.options,
  9712. originalEvent: event.originalEvent,
  9713. widget: tree.widget,
  9714. hitMode: DRAG_ENTER_RESPONSE,
  9715. dataTransfer: dataTransfer,
  9716. otherNode: SOURCE_NODE || null,
  9717. otherNodeList: SOURCE_NODE_LIST || null,
  9718. otherNodeData: null, // set by drop event
  9719. useDefaultImage: true,
  9720. dropEffect: undefined,
  9721. dropEffectSuggested: undefined,
  9722. effectAllowed: undefined, // set by dragstart
  9723. files: null, // list of File objects (may be [])
  9724. isCancelled: undefined, // set by drop event
  9725. isMove: undefined,
  9726. };
  9727. // data.isMove = dropEffect === "move";
  9728. switch (event.type) {
  9729. case "dragenter":
  9730. // The dragenter event is fired when a dragged element or
  9731. // text selection enters a valid drop target.
  9732. DRAG_OVER_STAMP = null;
  9733. if (!node) {
  9734. // Sometimes we get dragenter for the container element
  9735. tree.debug(
  9736. "Ignore non-node " +
  9737. event.type +
  9738. ": " +
  9739. event.target.tagName +
  9740. "." +
  9741. event.target.className
  9742. );
  9743. DRAG_ENTER_RESPONSE = false;
  9744. break;
  9745. }
  9746. $(node.span)
  9747. .addClass(classDropOver)
  9748. .removeClass(classDropAccept + " " + classDropReject);
  9749. // Data is only readable in the dragstart and drop event,
  9750. // but we can check for the type:
  9751. isSourceFtNode =
  9752. $.inArray(nodeMimeType, dataTransfer.types) >= 0;
  9753. if (dndOpts.preventNonNodes && !isSourceFtNode) {
  9754. node.debug("Reject dropping a non-node.");
  9755. DRAG_ENTER_RESPONSE = false;
  9756. break;
  9757. } else if (
  9758. dndOpts.preventForeignNodes &&
  9759. (!SOURCE_NODE || SOURCE_NODE.tree !== node.tree)
  9760. ) {
  9761. node.debug("Reject dropping a foreign node.");
  9762. DRAG_ENTER_RESPONSE = false;
  9763. break;
  9764. } else if (
  9765. dndOpts.preventSameParent &&
  9766. data.otherNode &&
  9767. data.otherNode.tree === node.tree &&
  9768. node.parent === data.otherNode.parent
  9769. ) {
  9770. node.debug("Reject dropping as sibling (same parent).");
  9771. DRAG_ENTER_RESPONSE = false;
  9772. break;
  9773. } else if (
  9774. dndOpts.preventRecursion &&
  9775. data.otherNode &&
  9776. data.otherNode.tree === node.tree &&
  9777. node.isDescendantOf(data.otherNode)
  9778. ) {
  9779. node.debug("Reject dropping below own ancestor.");
  9780. DRAG_ENTER_RESPONSE = false;
  9781. break;
  9782. } else if (dndOpts.preventLazyParents && !node.isLoaded()) {
  9783. node.warn("Drop over unloaded target node prevented.");
  9784. DRAG_ENTER_RESPONSE = false;
  9785. break;
  9786. }
  9787. $dropMarker.show();
  9788. // Call dragEnter() to figure out if (and where) dropping is allowed
  9789. prepareDropEffectCallback(event, data);
  9790. r = dndOpts.dragEnter(node, data);
  9791. res = normalizeDragEnterResponse(r);
  9792. // alert("res:" + JSON.stringify(res))
  9793. DRAG_ENTER_RESPONSE = res;
  9794. allowDrop = res && (res.over || res.before || res.after);
  9795. applyDropEffectCallback(event, data, allowDrop);
  9796. break;
  9797. case "dragover":
  9798. if (!node) {
  9799. tree.debug(
  9800. "Ignore non-node " +
  9801. event.type +
  9802. ": " +
  9803. event.target.tagName +
  9804. "." +
  9805. event.target.className
  9806. );
  9807. break;
  9808. }
  9809. // The dragover event is fired when an element or text
  9810. // selection is being dragged over a valid drop target
  9811. // (every few hundred milliseconds).
  9812. // tree.debug(
  9813. // event.type +
  9814. // ": dropEffect: " +
  9815. // dataTransfer.dropEffect
  9816. // );
  9817. prepareDropEffectCallback(event, data);
  9818. LAST_HIT_MODE = handleDragOver(event, data);
  9819. // The flag controls the preventDefault() below:
  9820. allowDrop = !!LAST_HIT_MODE;
  9821. allowAutoExpand =
  9822. LAST_HIT_MODE === "over" || LAST_HIT_MODE === false;
  9823. if (
  9824. allowAutoExpand &&
  9825. !node.expanded &&
  9826. node.hasChildren() !== false
  9827. ) {
  9828. if (!DRAG_OVER_STAMP) {
  9829. DRAG_OVER_STAMP = Date.now();
  9830. } else if (
  9831. dndOpts.autoExpandMS &&
  9832. Date.now() - DRAG_OVER_STAMP > dndOpts.autoExpandMS &&
  9833. !node.isLoading() &&
  9834. (!dndOpts.dragExpand ||
  9835. dndOpts.dragExpand(node, data) !== false)
  9836. ) {
  9837. node.setExpanded();
  9838. }
  9839. } else {
  9840. DRAG_OVER_STAMP = null;
  9841. }
  9842. break;
  9843. case "dragleave":
  9844. // NOTE: dragleave is fired AFTER the dragenter event of the
  9845. // FOLLOWING element.
  9846. if (!node) {
  9847. tree.debug(
  9848. "Ignore non-node " +
  9849. event.type +
  9850. ": " +
  9851. event.target.tagName +
  9852. "." +
  9853. event.target.className
  9854. );
  9855. break;
  9856. }
  9857. if (!$(node.span).hasClass(classDropOver)) {
  9858. node.debug("Ignore dragleave (multi).");
  9859. break;
  9860. }
  9861. $(node.span).removeClass(
  9862. classDropOver +
  9863. " " +
  9864. classDropAccept +
  9865. " " +
  9866. classDropReject
  9867. );
  9868. node.scheduleAction("cancel");
  9869. dndOpts.dragLeave(node, data);
  9870. $dropMarker.hide();
  9871. break;
  9872. case "drop":
  9873. // Data is only readable in the (dragstart and) drop event:
  9874. if ($.inArray(nodeMimeType, dataTransfer.types) >= 0) {
  9875. nodeData = dataTransfer.getData(nodeMimeType);
  9876. tree.info(
  9877. event.type +
  9878. ": getData('application/x-fancytree-node'): '" +
  9879. nodeData +
  9880. "'"
  9881. );
  9882. }
  9883. if (!nodeData) {
  9884. // 1. Source is not a Fancytree node, or
  9885. // 2. If the FT mime type was set, but returns '', this
  9886. // is probably IE 11 (which only supports 'text')
  9887. nodeData = dataTransfer.getData("text");
  9888. tree.info(
  9889. event.type + ": getData('text'): '" + nodeData + "'"
  9890. );
  9891. }
  9892. if (nodeData) {
  9893. try {
  9894. // 'text' type may contain JSON if IE is involved
  9895. // and setTextTypeJson option was set
  9896. json = JSON.parse(nodeData);
  9897. if (json.title !== undefined) {
  9898. data.otherNodeData = json;
  9899. }
  9900. } catch (ex) {
  9901. // assume 'text' type contains plain text, so `otherNodeData`
  9902. // should not be set
  9903. }
  9904. }
  9905. tree.debug(
  9906. event.type +
  9907. ": nodeData: '" +
  9908. nodeData +
  9909. "', otherNodeData: ",
  9910. data.otherNodeData
  9911. );
  9912. $(node.span).removeClass(
  9913. classDropOver +
  9914. " " +
  9915. classDropAccept +
  9916. " " +
  9917. classDropReject
  9918. );
  9919. // Let user implement the actual drop operation
  9920. data.hitMode = LAST_HIT_MODE;
  9921. prepareDropEffectCallback(event, data, !LAST_HIT_MODE);
  9922. data.isCancelled = !LAST_HIT_MODE;
  9923. var orgSourceElem = SOURCE_NODE && SOURCE_NODE.span,
  9924. orgSourceTree = SOURCE_NODE && SOURCE_NODE.tree;
  9925. dndOpts.dragDrop(node, data);
  9926. // applyDropEffectCallback(event, data);
  9927. // Prevent browser's default drop handling, i.e. open as link, ...
  9928. event.preventDefault();
  9929. if (orgSourceElem && !document.body.contains(orgSourceElem)) {
  9930. // The drop handler removed the original drag source from
  9931. // the DOM, so the dragend event will probaly not fire.
  9932. if (orgSourceTree === tree) {
  9933. tree.debug(
  9934. "Drop handler removed source element: generating dragEnd."
  9935. );
  9936. dndOpts.dragEnd(SOURCE_NODE, data);
  9937. } else {
  9938. tree.warn(
  9939. "Drop handler removed source element: dragend event may be lost."
  9940. );
  9941. }
  9942. }
  9943. _clearGlobals();
  9944. break;
  9945. }
  9946. // Dnd API madness: we must PREVENT default handling to enable dropping
  9947. if (allowDrop) {
  9948. event.preventDefault();
  9949. return false;
  9950. }
  9951. }
  9952. /** [ext-dnd5] Return a Fancytree instance, from element, index, event, or jQueryObject.
  9953. *
  9954. * @returns {FancytreeNode[]} List of nodes (empty if no drag operation)
  9955. * @example
  9956. * $.ui.fancytree.getDragNodeList();
  9957. *
  9958. * @alias Fancytree_Static#getDragNodeList
  9959. * @requires jquery.fancytree.dnd5.js
  9960. * @since 2.31
  9961. */
  9962. $.ui.fancytree.getDragNodeList = function () {
  9963. return SOURCE_NODE_LIST || [];
  9964. };
  9965. /** [ext-dnd5] Return the FancytreeNode that is currently being dragged.
  9966. *
  9967. * If multiple nodes are dragged, only the first is returned.
  9968. *
  9969. * @returns {FancytreeNode | null} dragged nodes or null if no drag operation
  9970. * @example
  9971. * $.ui.fancytree.getDragNode();
  9972. *
  9973. * @alias Fancytree_Static#getDragNode
  9974. * @requires jquery.fancytree.dnd5.js
  9975. * @since 2.31
  9976. */
  9977. $.ui.fancytree.getDragNode = function () {
  9978. return SOURCE_NODE;
  9979. };
  9980. /******************************************************************************
  9981. *
  9982. */
  9983. $.ui.fancytree.registerExtension({
  9984. name: "dnd5",
  9985. version: "2.38.5",
  9986. // Default options for this extension.
  9987. options: {
  9988. autoExpandMS: 1500, // Expand nodes after n milliseconds of hovering
  9989. dropMarkerInsertOffsetX: -16, // Additional offset for drop-marker with hitMode = "before"/"after"
  9990. dropMarkerOffsetX: -24, // Absolute position offset for .fancytree-drop-marker relatively to ..fancytree-title (icon/img near a node accepting drop)
  9991. // #1021 `document.body` is not available yet
  9992. dropMarkerParent: "body", // Root Container used for drop marker (could be a shadow root)
  9993. multiSource: false, // true: Drag multiple (i.e. selected) nodes. Also a callback() is allowed
  9994. effectAllowed: "all", // Restrict the possible cursor shapes and modifier operations (can also be set in the dragStart event)
  9995. // dropEffect: "auto", // 'copy'|'link'|'move'|'auto'(calculate from `effectAllowed`+modifier keys) or callback(node, data) that returns such string.
  9996. dropEffectDefault: "move", // Default dropEffect ('copy', 'link', or 'move') when no modifier is pressed (overide in dragDrag, dragOver).
  9997. preventForeignNodes: false, // Prevent dropping nodes from different Fancytrees
  9998. preventLazyParents: true, // Prevent dropping items on unloaded lazy Fancytree nodes
  9999. preventNonNodes: false, // Prevent dropping items other than Fancytree nodes
  10000. preventRecursion: true, // Prevent dropping nodes on own descendants
  10001. preventSameParent: false, // Prevent dropping nodes under same direct parent
  10002. preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
  10003. scroll: true, // Enable auto-scrolling while dragging
  10004. scrollSensitivity: 20, // Active top/bottom margin in pixel
  10005. scrollSpeed: 5, // Pixel per event
  10006. setTextTypeJson: false, // Allow dragging of nodes to different IE windows
  10007. sourceCopyHook: null, // Optional callback passed to `toDict` on dragStart @since 2.38
  10008. // Events (drag support)
  10009. dragStart: null, // Callback(sourceNode, data), return true, to enable dnd drag
  10010. dragDrag: $.noop, // Callback(sourceNode, data)
  10011. dragEnd: $.noop, // Callback(sourceNode, data)
  10012. // Events (drop support)
  10013. dragEnter: null, // Callback(targetNode, data), return true, to enable dnd drop
  10014. dragOver: $.noop, // Callback(targetNode, data)
  10015. dragExpand: $.noop, // Callback(targetNode, data), return false to prevent autoExpand
  10016. dragDrop: $.noop, // Callback(targetNode, data)
  10017. dragLeave: $.noop, // Callback(targetNode, data)
  10018. },
  10019. treeInit: function (ctx) {
  10020. var $temp,
  10021. tree = ctx.tree,
  10022. opts = ctx.options,
  10023. glyph = opts.glyph || null,
  10024. dndOpts = opts.dnd5;
  10025. if ($.inArray("dnd", opts.extensions) >= 0) {
  10026. $.error("Extensions 'dnd' and 'dnd5' are mutually exclusive.");
  10027. }
  10028. if (dndOpts.dragStop) {
  10029. $.error(
  10030. "dragStop is not used by ext-dnd5. Use dragEnd instead."
  10031. );
  10032. }
  10033. if (dndOpts.preventRecursiveMoves != null) {
  10034. $.error(
  10035. "preventRecursiveMoves was renamed to preventRecursion."
  10036. );
  10037. }
  10038. // Implement `opts.createNode` event to add the 'draggable' attribute
  10039. // #680: this must happen before calling super.treeInit()
  10040. if (dndOpts.dragStart) {
  10041. FT.overrideMethod(
  10042. ctx.options,
  10043. "createNode",
  10044. function (event, data) {
  10045. // Default processing if any
  10046. this._super.apply(this, arguments);
  10047. if (data.node.span) {
  10048. data.node.span.draggable = true;
  10049. } else {
  10050. data.node.warn(
  10051. "Cannot add `draggable`: no span tag"
  10052. );
  10053. }
  10054. }
  10055. );
  10056. }
  10057. this._superApply(arguments);
  10058. this.$container.addClass("fancytree-ext-dnd5");
  10059. // Store the current scroll parent, which may be the tree
  10060. // container, any enclosing div, or the document.
  10061. // #761: scrollParent() always needs a container child
  10062. $temp = $("<span>").appendTo(this.$container);
  10063. this.$scrollParent = $temp.scrollParent();
  10064. $temp.remove();
  10065. $dropMarker = $("#fancytree-drop-marker");
  10066. if (!$dropMarker.length) {
  10067. $dropMarker = $("<div id='fancytree-drop-marker'></div>")
  10068. .hide()
  10069. .css({
  10070. "z-index": 1000,
  10071. // Drop marker should not steal dragenter/dragover events:
  10072. "pointer-events": "none",
  10073. })
  10074. .prependTo(dndOpts.dropMarkerParent);
  10075. if (glyph) {
  10076. FT.setSpanIcon(
  10077. $dropMarker[0],
  10078. glyph.map._addClass,
  10079. glyph.map.dropMarker
  10080. );
  10081. }
  10082. }
  10083. $dropMarker.toggleClass("fancytree-rtl", !!opts.rtl);
  10084. // Enable drag support if dragStart() is specified:
  10085. if (dndOpts.dragStart) {
  10086. // Bind drag event handlers
  10087. tree.$container.on(
  10088. "dragstart drag dragend",
  10089. onDragEvent.bind(tree)
  10090. );
  10091. }
  10092. // Enable drop support if dragEnter() is specified:
  10093. if (dndOpts.dragEnter) {
  10094. // Bind drop event handlers
  10095. tree.$container.on(
  10096. "dragenter dragover dragleave drop",
  10097. onDropEvent.bind(tree)
  10098. );
  10099. }
  10100. },
  10101. });
  10102. // Value returned by `require('jquery.fancytree..')`
  10103. return $.ui.fancytree;
  10104. }); // End of closure
  10105. /*! Extension 'jquery.fancytree.edit.js' *//*!
  10106. * jquery.fancytree.edit.js
  10107. *
  10108. * Make node titles editable.
  10109. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10110. *
  10111. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  10112. *
  10113. * Released under the MIT license
  10114. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10115. *
  10116. * @version 2.38.5
  10117. * @date 2025-04-05T06:40:00Z
  10118. */
  10119. (function (factory) {
  10120. if (typeof define === "function" && define.amd) {
  10121. // AMD. Register as an anonymous module.
  10122. define(["jquery", "./jquery.fancytree"], factory);
  10123. } else if (typeof module === "object" && module.exports) {
  10124. // Node/CommonJS
  10125. require("./jquery.fancytree");
  10126. module.exports = factory(require("jquery"));
  10127. } else {
  10128. // Browser globals
  10129. factory(jQuery);
  10130. }
  10131. })(function ($) {
  10132. "use strict";
  10133. /*******************************************************************************
  10134. * Private functions and variables
  10135. */
  10136. var isMac = /Mac/.test(navigator.platform),
  10137. escapeHtml = $.ui.fancytree.escapeHtml,
  10138. trim = $.ui.fancytree.trim,
  10139. unescapeHtml = $.ui.fancytree.unescapeHtml;
  10140. /**
  10141. * [ext-edit] Start inline editing of current node title.
  10142. *
  10143. * @alias FancytreeNode#editStart
  10144. * @requires Fancytree
  10145. */
  10146. $.ui.fancytree._FancytreeNodeClass.prototype.editStart = function () {
  10147. var $input,
  10148. node = this,
  10149. tree = this.tree,
  10150. local = tree.ext.edit,
  10151. instOpts = tree.options.edit,
  10152. $title = $(".fancytree-title", node.span),
  10153. eventData = {
  10154. node: node,
  10155. tree: tree,
  10156. options: tree.options,
  10157. isNew: $(node[tree.statusClassPropName]).hasClass(
  10158. "fancytree-edit-new"
  10159. ),
  10160. orgTitle: node.title,
  10161. input: null,
  10162. dirty: false,
  10163. };
  10164. // beforeEdit may want to modify the title before editing
  10165. if (
  10166. instOpts.beforeEdit.call(
  10167. node,
  10168. { type: "beforeEdit" },
  10169. eventData
  10170. ) === false
  10171. ) {
  10172. return false;
  10173. }
  10174. $.ui.fancytree.assert(!local.currentNode, "recursive edit");
  10175. local.currentNode = this;
  10176. local.eventData = eventData;
  10177. // Disable standard Fancytree mouse- and key handling
  10178. tree.widget._unbind();
  10179. local.lastDraggableAttrValue = node.span.draggable;
  10180. if (local.lastDraggableAttrValue) {
  10181. node.span.draggable = false;
  10182. }
  10183. // #116: ext-dnd prevents the blur event, so we have to catch outer clicks
  10184. $(document).on("mousedown.fancytree-edit", function (event) {
  10185. if (!$(event.target).hasClass("fancytree-edit-input")) {
  10186. node.editEnd(true, event);
  10187. }
  10188. });
  10189. // Replace node with <input>
  10190. $input = $("<input />", {
  10191. class: "fancytree-edit-input",
  10192. type: "text",
  10193. value: tree.options.escapeTitles
  10194. ? eventData.orgTitle
  10195. : unescapeHtml(eventData.orgTitle),
  10196. });
  10197. local.eventData.input = $input;
  10198. if (instOpts.adjustWidthOfs != null) {
  10199. $input.width($title.width() + instOpts.adjustWidthOfs);
  10200. }
  10201. if (instOpts.inputCss != null) {
  10202. $input.css(instOpts.inputCss);
  10203. }
  10204. $title.html($input);
  10205. // Focus <input> and bind keyboard handler
  10206. $input
  10207. .trigger("focus")
  10208. .change(function (event) {
  10209. $input.addClass("fancytree-edit-dirty");
  10210. })
  10211. .on("keydown", function (event) {
  10212. switch (event.which) {
  10213. case $.ui.keyCode.ESCAPE:
  10214. node.editEnd(false, event);
  10215. break;
  10216. case $.ui.keyCode.ENTER:
  10217. node.editEnd(true, event);
  10218. return false; // so we don't start editmode on Mac
  10219. }
  10220. event.stopPropagation();
  10221. })
  10222. .blur(function (event) {
  10223. return node.editEnd(true, event);
  10224. });
  10225. instOpts.edit.call(node, { type: "edit" }, eventData);
  10226. };
  10227. /**
  10228. * [ext-edit] Stop inline editing.
  10229. * @param {Boolean} [applyChanges=false] false: cancel edit, true: save (if modified)
  10230. * @alias FancytreeNode#editEnd
  10231. * @requires jquery.fancytree.edit.js
  10232. */
  10233. $.ui.fancytree._FancytreeNodeClass.prototype.editEnd = function (
  10234. applyChanges,
  10235. _event
  10236. ) {
  10237. var newVal,
  10238. node = this,
  10239. tree = this.tree,
  10240. local = tree.ext.edit,
  10241. eventData = local.eventData,
  10242. instOpts = tree.options.edit,
  10243. $title = $(".fancytree-title", node.span),
  10244. $input = $title.find("input.fancytree-edit-input");
  10245. if (instOpts.trim) {
  10246. $input.val(trim($input.val()));
  10247. }
  10248. newVal = $input.val();
  10249. eventData.dirty = newVal !== node.title;
  10250. eventData.originalEvent = _event;
  10251. // Find out, if saving is required
  10252. if (applyChanges === false) {
  10253. // If true/false was passed, honor this (except in rename mode, if unchanged)
  10254. eventData.save = false;
  10255. } else if (eventData.isNew) {
  10256. // In create mode, we save everything, except for empty text
  10257. eventData.save = newVal !== "";
  10258. } else {
  10259. // In rename mode, we save everyting, except for empty or unchanged text
  10260. eventData.save = eventData.dirty && newVal !== "";
  10261. }
  10262. // Allow to break (keep editor open), modify input, or re-define data.save
  10263. if (
  10264. instOpts.beforeClose.call(
  10265. node,
  10266. { type: "beforeClose" },
  10267. eventData
  10268. ) === false
  10269. ) {
  10270. return false;
  10271. }
  10272. if (
  10273. eventData.save &&
  10274. instOpts.save.call(node, { type: "save" }, eventData) === false
  10275. ) {
  10276. return false;
  10277. }
  10278. $input.removeClass("fancytree-edit-dirty").off();
  10279. // Unbind outer-click handler
  10280. $(document).off(".fancytree-edit");
  10281. if (eventData.save) {
  10282. // # 171: escape user input (not required if global escaping is on)
  10283. node.setTitle(
  10284. tree.options.escapeTitles ? newVal : escapeHtml(newVal)
  10285. );
  10286. node.setFocus();
  10287. } else {
  10288. if (eventData.isNew) {
  10289. node.remove();
  10290. node = eventData.node = null;
  10291. local.relatedNode.setFocus();
  10292. } else {
  10293. node.renderTitle();
  10294. node.setFocus();
  10295. }
  10296. }
  10297. local.eventData = null;
  10298. local.currentNode = null;
  10299. local.relatedNode = null;
  10300. // Re-enable mouse and keyboard handling
  10301. tree.widget._bind();
  10302. if (node && local.lastDraggableAttrValue) {
  10303. node.span.draggable = true;
  10304. }
  10305. // Set keyboard focus, even if setFocus() claims 'nothing to do'
  10306. tree.$container.get(0).focus({ preventScroll: true });
  10307. eventData.input = null;
  10308. instOpts.close.call(node, { type: "close" }, eventData);
  10309. return true;
  10310. };
  10311. /**
  10312. * [ext-edit] Create a new child or sibling node and start edit mode.
  10313. *
  10314. * @param {String} [mode='child'] 'before', 'after', or 'child'
  10315. * @param {Object} [init] NodeData (or simple title string)
  10316. * @alias FancytreeNode#editCreateNode
  10317. * @requires jquery.fancytree.edit.js
  10318. * @since 2.4
  10319. */
  10320. $.ui.fancytree._FancytreeNodeClass.prototype.editCreateNode = function (
  10321. mode,
  10322. init
  10323. ) {
  10324. var newNode,
  10325. tree = this.tree,
  10326. self = this;
  10327. mode = mode || "child";
  10328. if (init == null) {
  10329. init = { title: "" };
  10330. } else if (typeof init === "string") {
  10331. init = { title: init };
  10332. } else {
  10333. $.ui.fancytree.assert($.isPlainObject(init));
  10334. }
  10335. // Make sure node is expanded (and loaded) in 'child' mode
  10336. if (
  10337. mode === "child" &&
  10338. !this.isExpanded() &&
  10339. this.hasChildren() !== false
  10340. ) {
  10341. this.setExpanded().done(function () {
  10342. self.editCreateNode(mode, init);
  10343. });
  10344. return;
  10345. }
  10346. newNode = this.addNode(init, mode);
  10347. // #644: Don't filter new nodes.
  10348. newNode.match = true;
  10349. $(newNode[tree.statusClassPropName])
  10350. .removeClass("fancytree-hide")
  10351. .addClass("fancytree-match");
  10352. newNode.makeVisible(/*{noAnimation: true}*/).done(function () {
  10353. $(newNode[tree.statusClassPropName]).addClass("fancytree-edit-new");
  10354. self.tree.ext.edit.relatedNode = self;
  10355. newNode.editStart();
  10356. });
  10357. };
  10358. /**
  10359. * [ext-edit] Check if any node in this tree in edit mode.
  10360. *
  10361. * @returns {FancytreeNode | null}
  10362. * @alias Fancytree#isEditing
  10363. * @requires jquery.fancytree.edit.js
  10364. */
  10365. $.ui.fancytree._FancytreeClass.prototype.isEditing = function () {
  10366. return this.ext.edit ? this.ext.edit.currentNode : null;
  10367. };
  10368. /**
  10369. * [ext-edit] Check if this node is in edit mode.
  10370. * @returns {Boolean} true if node is currently beeing edited
  10371. * @alias FancytreeNode#isEditing
  10372. * @requires jquery.fancytree.edit.js
  10373. */
  10374. $.ui.fancytree._FancytreeNodeClass.prototype.isEditing = function () {
  10375. return this.tree.ext.edit
  10376. ? this.tree.ext.edit.currentNode === this
  10377. : false;
  10378. };
  10379. /*******************************************************************************
  10380. * Extension code
  10381. */
  10382. $.ui.fancytree.registerExtension({
  10383. name: "edit",
  10384. version: "2.38.5",
  10385. // Default options for this extension.
  10386. options: {
  10387. adjustWidthOfs: 4, // null: don't adjust input size to content
  10388. allowEmpty: false, // Prevent empty input
  10389. inputCss: { minWidth: "3em" },
  10390. // triggerCancel: ["esc", "tab", "click"],
  10391. triggerStart: ["f2", "mac+enter", "shift+click"],
  10392. trim: true, // Trim whitespace before save
  10393. // Events:
  10394. beforeClose: $.noop, // Return false to prevent cancel/save (data.input is available)
  10395. beforeEdit: $.noop, // Return false to prevent edit mode
  10396. close: $.noop, // Editor was removed
  10397. edit: $.noop, // Editor was opened (available as data.input)
  10398. // keypress: $.noop, // Not yet implemented
  10399. save: $.noop, // Save data.input.val() or return false to keep editor open
  10400. },
  10401. // Local attributes
  10402. currentNode: null,
  10403. treeInit: function (ctx) {
  10404. var tree = ctx.tree;
  10405. this._superApply(arguments);
  10406. this.$container
  10407. .addClass("fancytree-ext-edit")
  10408. .on("fancytreebeforeupdateviewport", function (event, data) {
  10409. var editNode = tree.isEditing();
  10410. // When scrolling, the TR may be re-used by another node, so the
  10411. // active cell marker an
  10412. if (editNode) {
  10413. editNode.info("Cancel edit due to scroll event.");
  10414. editNode.editEnd(false, event);
  10415. }
  10416. });
  10417. },
  10418. nodeClick: function (ctx) {
  10419. var eventStr = $.ui.fancytree.eventToString(ctx.originalEvent),
  10420. triggerStart = ctx.options.edit.triggerStart;
  10421. if (
  10422. eventStr === "shift+click" &&
  10423. $.inArray("shift+click", triggerStart) >= 0
  10424. ) {
  10425. if (ctx.originalEvent.shiftKey) {
  10426. ctx.node.editStart();
  10427. return false;
  10428. }
  10429. }
  10430. if (
  10431. eventStr === "click" &&
  10432. $.inArray("clickActive", triggerStart) >= 0
  10433. ) {
  10434. // Only when click was inside title text (not aynwhere else in the row)
  10435. if (
  10436. ctx.node.isActive() &&
  10437. !ctx.node.isEditing() &&
  10438. $(ctx.originalEvent.target).hasClass("fancytree-title")
  10439. ) {
  10440. ctx.node.editStart();
  10441. return false;
  10442. }
  10443. }
  10444. return this._superApply(arguments);
  10445. },
  10446. nodeDblclick: function (ctx) {
  10447. if ($.inArray("dblclick", ctx.options.edit.triggerStart) >= 0) {
  10448. ctx.node.editStart();
  10449. return false;
  10450. }
  10451. return this._superApply(arguments);
  10452. },
  10453. nodeKeydown: function (ctx) {
  10454. switch (ctx.originalEvent.which) {
  10455. case 113: // [F2]
  10456. if ($.inArray("f2", ctx.options.edit.triggerStart) >= 0) {
  10457. ctx.node.editStart();
  10458. return false;
  10459. }
  10460. break;
  10461. case $.ui.keyCode.ENTER:
  10462. if (
  10463. $.inArray("mac+enter", ctx.options.edit.triggerStart) >=
  10464. 0 &&
  10465. isMac
  10466. ) {
  10467. ctx.node.editStart();
  10468. return false;
  10469. }
  10470. break;
  10471. }
  10472. return this._superApply(arguments);
  10473. },
  10474. });
  10475. // Value returned by `require('jquery.fancytree..')`
  10476. return $.ui.fancytree;
  10477. }); // End of closure
  10478. /*! Extension 'jquery.fancytree.filter.js' *//*!
  10479. * jquery.fancytree.filter.js
  10480. *
  10481. * Remove or highlight tree nodes, based on a filter.
  10482. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10483. *
  10484. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  10485. *
  10486. * Released under the MIT license
  10487. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10488. *
  10489. * @version 2.38.5
  10490. * @date 2025-04-05T06:40:00Z
  10491. */
  10492. (function (factory) {
  10493. if (typeof define === "function" && define.amd) {
  10494. // AMD. Register as an anonymous module.
  10495. define(["jquery", "./jquery.fancytree"], factory);
  10496. } else if (typeof module === "object" && module.exports) {
  10497. // Node/CommonJS
  10498. require("./jquery.fancytree");
  10499. module.exports = factory(require("jquery"));
  10500. } else {
  10501. // Browser globals
  10502. factory(jQuery);
  10503. }
  10504. })(function ($) {
  10505. "use strict";
  10506. /*******************************************************************************
  10507. * Private functions and variables
  10508. */
  10509. var KeyNoData = "__not_found__",
  10510. escapeHtml = $.ui.fancytree.escapeHtml,
  10511. exoticStartChar = "\uFFF7",
  10512. exoticEndChar = "\uFFF8";
  10513. function _escapeRegex(str) {
  10514. return (str + "").replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
  10515. }
  10516. function extractHtmlText(s) {
  10517. if (s.indexOf(">") >= 0) {
  10518. return $("<div/>").html(s).text();
  10519. }
  10520. return s;
  10521. }
  10522. /**
  10523. * @description Marks the matching charecters of `text` either by `mark` or
  10524. * by exotic*Chars (if `escapeTitles` is `true`) based on `regexMatchArray`
  10525. * which is an array of matching groups.
  10526. * @param {string} text
  10527. * @param {RegExpMatchArray} regexMatchArray
  10528. */
  10529. function _markFuzzyMatchedChars(text, regexMatchArray, escapeTitles) {
  10530. // It is extremely infuriating that we can not use `let` or `const` or arrow functions.
  10531. // Damn you IE!!!
  10532. var matchingIndices = [];
  10533. // get the indices of matched characters (Iterate through `RegExpMatchArray`)
  10534. for (
  10535. var _matchingArrIdx = 1;
  10536. _matchingArrIdx < regexMatchArray.length;
  10537. _matchingArrIdx++
  10538. ) {
  10539. var _mIdx =
  10540. // get matching char index by cumulatively adding
  10541. // the matched group length
  10542. regexMatchArray[_matchingArrIdx].length +
  10543. (_matchingArrIdx === 1 ? 0 : 1) +
  10544. (matchingIndices[matchingIndices.length - 1] || 0);
  10545. matchingIndices.push(_mIdx);
  10546. }
  10547. // Map each `text` char to its position and store in `textPoses`.
  10548. var textPoses = text.split("");
  10549. if (escapeTitles) {
  10550. // If escaping the title, then wrap the matchng char within exotic chars
  10551. matchingIndices.forEach(function (v) {
  10552. textPoses[v] = exoticStartChar + textPoses[v] + exoticEndChar;
  10553. });
  10554. } else {
  10555. // Otherwise, Wrap the matching chars within `mark`.
  10556. matchingIndices.forEach(function (v) {
  10557. textPoses[v] = "<mark>" + textPoses[v] + "</mark>";
  10558. });
  10559. }
  10560. // Join back the modified `textPoses` to create final highlight markup.
  10561. return textPoses.join("");
  10562. }
  10563. $.ui.fancytree._FancytreeClass.prototype._applyFilterImpl = function (
  10564. filter,
  10565. branchMode,
  10566. _opts
  10567. ) {
  10568. var match,
  10569. statusNode,
  10570. re,
  10571. reHighlight,
  10572. reExoticStartChar,
  10573. reExoticEndChar,
  10574. temp,
  10575. prevEnableUpdate,
  10576. count = 0,
  10577. treeOpts = this.options,
  10578. escapeTitles = treeOpts.escapeTitles,
  10579. prevAutoCollapse = treeOpts.autoCollapse,
  10580. opts = $.extend({}, treeOpts.filter, _opts),
  10581. hideMode = opts.mode === "hide",
  10582. leavesOnly = !!opts.leavesOnly && !branchMode;
  10583. // Default to 'match title substring (not case sensitive)'
  10584. if (typeof filter === "string") {
  10585. if (filter === "") {
  10586. this.warn(
  10587. "Fancytree passing an empty string as a filter is handled as clearFilter()."
  10588. );
  10589. this.clearFilter();
  10590. return;
  10591. }
  10592. if (opts.fuzzy) {
  10593. // See https://codereview.stackexchange.com/questions/23899/faster-javascript-fuzzy-string-matching-function/23905#23905
  10594. // and http://www.quora.com/How-is-the-fuzzy-search-algorithm-in-Sublime-Text-designed
  10595. // and http://www.dustindiaz.com/autocomplete-fuzzy-matching
  10596. match = filter
  10597. .split("")
  10598. // Escaping the `filter` will not work because,
  10599. // it gets further split into individual characters. So,
  10600. // escape each character after splitting
  10601. .map(_escapeRegex)
  10602. .reduce(function (a, b) {
  10603. // create capture groups for parts that comes before
  10604. // the character
  10605. return a + "([^" + b + "]*)" + b;
  10606. }, "");
  10607. } else {
  10608. match = _escapeRegex(filter); // make sure a '.' is treated literally
  10609. }
  10610. re = new RegExp(match, "i");
  10611. reHighlight = new RegExp(_escapeRegex(filter), "gi");
  10612. if (escapeTitles) {
  10613. reExoticStartChar = new RegExp(
  10614. _escapeRegex(exoticStartChar),
  10615. "g"
  10616. );
  10617. reExoticEndChar = new RegExp(_escapeRegex(exoticEndChar), "g");
  10618. }
  10619. filter = function (node) {
  10620. if (!node.title) {
  10621. return false;
  10622. }
  10623. var text = escapeTitles
  10624. ? node.title
  10625. : extractHtmlText(node.title),
  10626. // `.match` instead of `.test` to get the capture groups
  10627. res = text.match(re);
  10628. if (res && opts.highlight) {
  10629. if (escapeTitles) {
  10630. if (opts.fuzzy) {
  10631. temp = _markFuzzyMatchedChars(
  10632. text,
  10633. res,
  10634. escapeTitles
  10635. );
  10636. } else {
  10637. // #740: we must not apply the marks to escaped entity names, e.g. `&quot;`
  10638. // Use some exotic characters to mark matches:
  10639. temp = text.replace(reHighlight, function (s) {
  10640. return exoticStartChar + s + exoticEndChar;
  10641. });
  10642. }
  10643. // now we can escape the title...
  10644. node.titleWithHighlight = escapeHtml(temp)
  10645. // ... and finally insert the desired `<mark>` tags
  10646. .replace(reExoticStartChar, "<mark>")
  10647. .replace(reExoticEndChar, "</mark>");
  10648. } else {
  10649. if (opts.fuzzy) {
  10650. node.titleWithHighlight = _markFuzzyMatchedChars(
  10651. text,
  10652. res
  10653. );
  10654. } else {
  10655. node.titleWithHighlight = text.replace(
  10656. reHighlight,
  10657. function (s) {
  10658. return "<mark>" + s + "</mark>";
  10659. }
  10660. );
  10661. }
  10662. }
  10663. // node.debug("filter", escapeTitles, text, node.titleWithHighlight);
  10664. }
  10665. return !!res;
  10666. };
  10667. }
  10668. this.enableFilter = true;
  10669. this.lastFilterArgs = arguments;
  10670. prevEnableUpdate = this.enableUpdate(false);
  10671. this.$div.addClass("fancytree-ext-filter");
  10672. if (hideMode) {
  10673. this.$div.addClass("fancytree-ext-filter-hide");
  10674. } else {
  10675. this.$div.addClass("fancytree-ext-filter-dimm");
  10676. }
  10677. this.$div.toggleClass(
  10678. "fancytree-ext-filter-hide-expanders",
  10679. !!opts.hideExpanders
  10680. );
  10681. // Reset current filter
  10682. this.rootNode.subMatchCount = 0;
  10683. this.visit(function (node) {
  10684. delete node.match;
  10685. delete node.titleWithHighlight;
  10686. node.subMatchCount = 0;
  10687. });
  10688. statusNode = this.getRootNode()._findDirectChild(KeyNoData);
  10689. if (statusNode) {
  10690. statusNode.remove();
  10691. }
  10692. // Adjust node.hide, .match, and .subMatchCount properties
  10693. treeOpts.autoCollapse = false; // #528
  10694. this.visit(function (node) {
  10695. if (leavesOnly && node.children != null) {
  10696. return;
  10697. }
  10698. var res = filter(node),
  10699. matchedByBranch = false;
  10700. if (res === "skip") {
  10701. node.visit(function (c) {
  10702. c.match = false;
  10703. }, true);
  10704. return "skip";
  10705. }
  10706. if (!res && (branchMode || res === "branch") && node.parent.match) {
  10707. res = true;
  10708. matchedByBranch = true;
  10709. }
  10710. if (res) {
  10711. count++;
  10712. node.match = true;
  10713. node.visitParents(function (p) {
  10714. if (p !== node) {
  10715. p.subMatchCount += 1;
  10716. }
  10717. // Expand match (unless this is no real match, but only a node in a matched branch)
  10718. if (opts.autoExpand && !matchedByBranch && !p.expanded) {
  10719. p.setExpanded(true, {
  10720. noAnimation: true,
  10721. noEvents: true,
  10722. scrollIntoView: false,
  10723. });
  10724. p._filterAutoExpanded = true;
  10725. }
  10726. }, true);
  10727. }
  10728. });
  10729. treeOpts.autoCollapse = prevAutoCollapse;
  10730. if (count === 0 && opts.nodata && hideMode) {
  10731. statusNode = opts.nodata;
  10732. if (typeof statusNode === "function") {
  10733. statusNode = statusNode();
  10734. }
  10735. if (statusNode === true) {
  10736. statusNode = {};
  10737. } else if (typeof statusNode === "string") {
  10738. statusNode = { title: statusNode };
  10739. }
  10740. statusNode = $.extend(
  10741. {
  10742. statusNodeType: "nodata",
  10743. key: KeyNoData,
  10744. title: this.options.strings.noData,
  10745. },
  10746. statusNode
  10747. );
  10748. this.getRootNode().addNode(statusNode).match = true;
  10749. }
  10750. // Redraw whole tree
  10751. this._callHook("treeStructureChanged", this, "applyFilter");
  10752. // this.render();
  10753. this.enableUpdate(prevEnableUpdate);
  10754. return count;
  10755. };
  10756. /**
  10757. * [ext-filter] Dimm or hide nodes.
  10758. *
  10759. * @param {function | string} filter
  10760. * @param {boolean} [opts={autoExpand: false, leavesOnly: false}]
  10761. * @returns {integer} count
  10762. * @alias Fancytree#filterNodes
  10763. * @requires jquery.fancytree.filter.js
  10764. */
  10765. $.ui.fancytree._FancytreeClass.prototype.filterNodes = function (
  10766. filter,
  10767. opts
  10768. ) {
  10769. if (typeof opts === "boolean") {
  10770. opts = { leavesOnly: opts };
  10771. this.warn(
  10772. "Fancytree.filterNodes() leavesOnly option is deprecated since 2.9.0 / 2015-04-19. Use opts.leavesOnly instead."
  10773. );
  10774. }
  10775. return this._applyFilterImpl(filter, false, opts);
  10776. };
  10777. /**
  10778. * [ext-filter] Dimm or hide whole branches.
  10779. *
  10780. * @param {function | string} filter
  10781. * @param {boolean} [opts={autoExpand: false}]
  10782. * @returns {integer} count
  10783. * @alias Fancytree#filterBranches
  10784. * @requires jquery.fancytree.filter.js
  10785. */
  10786. $.ui.fancytree._FancytreeClass.prototype.filterBranches = function (
  10787. filter,
  10788. opts
  10789. ) {
  10790. return this._applyFilterImpl(filter, true, opts);
  10791. };
  10792. /**
  10793. * [ext-filter] Re-apply current filter.
  10794. *
  10795. * @returns {integer} count
  10796. * @alias Fancytree#updateFilter
  10797. * @requires jquery.fancytree.filter.js
  10798. * @since 2.38
  10799. */
  10800. $.ui.fancytree._FancytreeClass.prototype.updateFilter = function () {
  10801. if (
  10802. this.enableFilter &&
  10803. this.lastFilterArgs &&
  10804. this.options.filter.autoApply
  10805. ) {
  10806. this._applyFilterImpl.apply(this, this.lastFilterArgs);
  10807. } else {
  10808. this.warn("updateFilter(): no filter active.");
  10809. }
  10810. };
  10811. /**
  10812. * [ext-filter] Reset the filter.
  10813. *
  10814. * @alias Fancytree#clearFilter
  10815. * @requires jquery.fancytree.filter.js
  10816. */
  10817. $.ui.fancytree._FancytreeClass.prototype.clearFilter = function () {
  10818. var $title,
  10819. statusNode = this.getRootNode()._findDirectChild(KeyNoData),
  10820. escapeTitles = this.options.escapeTitles,
  10821. enhanceTitle = this.options.enhanceTitle,
  10822. prevEnableUpdate = this.enableUpdate(false);
  10823. if (statusNode) {
  10824. statusNode.remove();
  10825. }
  10826. // we also counted root node's subMatchCount
  10827. delete this.rootNode.match;
  10828. delete this.rootNode.subMatchCount;
  10829. this.visit(function (node) {
  10830. if (node.match && node.span) {
  10831. // #491, #601
  10832. $title = $(node.span).find(">span.fancytree-title");
  10833. if (escapeTitles) {
  10834. $title.text(node.title);
  10835. } else {
  10836. $title.html(node.title);
  10837. }
  10838. if (enhanceTitle) {
  10839. enhanceTitle(
  10840. { type: "enhanceTitle" },
  10841. { node: node, $title: $title }
  10842. );
  10843. }
  10844. }
  10845. delete node.match;
  10846. delete node.subMatchCount;
  10847. delete node.titleWithHighlight;
  10848. if (node.$subMatchBadge) {
  10849. node.$subMatchBadge.remove();
  10850. delete node.$subMatchBadge;
  10851. }
  10852. if (node._filterAutoExpanded && node.expanded) {
  10853. node.setExpanded(false, {
  10854. noAnimation: true,
  10855. noEvents: true,
  10856. scrollIntoView: false,
  10857. });
  10858. }
  10859. delete node._filterAutoExpanded;
  10860. });
  10861. this.enableFilter = false;
  10862. this.lastFilterArgs = null;
  10863. this.$div.removeClass(
  10864. "fancytree-ext-filter fancytree-ext-filter-dimm fancytree-ext-filter-hide"
  10865. );
  10866. this._callHook("treeStructureChanged", this, "clearFilter");
  10867. // this.render();
  10868. this.enableUpdate(prevEnableUpdate);
  10869. };
  10870. /**
  10871. * [ext-filter] Return true if a filter is currently applied.
  10872. *
  10873. * @returns {Boolean}
  10874. * @alias Fancytree#isFilterActive
  10875. * @requires jquery.fancytree.filter.js
  10876. * @since 2.13
  10877. */
  10878. $.ui.fancytree._FancytreeClass.prototype.isFilterActive = function () {
  10879. return !!this.enableFilter;
  10880. };
  10881. /**
  10882. * [ext-filter] Return true if this node is matched by current filter (or no filter is active).
  10883. *
  10884. * @returns {Boolean}
  10885. * @alias FancytreeNode#isMatched
  10886. * @requires jquery.fancytree.filter.js
  10887. * @since 2.13
  10888. */
  10889. $.ui.fancytree._FancytreeNodeClass.prototype.isMatched = function () {
  10890. return !(this.tree.enableFilter && !this.match);
  10891. };
  10892. /*******************************************************************************
  10893. * Extension code
  10894. */
  10895. $.ui.fancytree.registerExtension({
  10896. name: "filter",
  10897. version: "2.38.5",
  10898. // Default options for this extension.
  10899. options: {
  10900. autoApply: true, // Re-apply last filter if lazy data is loaded
  10901. autoExpand: false, // Expand all branches that contain matches while filtered
  10902. counter: true, // Show a badge with number of matching child nodes near parent icons
  10903. fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar'
  10904. hideExpandedCounter: true, // Hide counter badge if parent is expanded
  10905. hideExpanders: false, // Hide expanders if all child nodes are hidden by filter
  10906. highlight: true, // Highlight matches by wrapping inside <mark> tags
  10907. leavesOnly: false, // Match end nodes only
  10908. nodata: true, // Display a 'no data' status node if result is empty
  10909. mode: "dimm", // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
  10910. },
  10911. nodeLoadChildren: function (ctx, source) {
  10912. var tree = ctx.tree;
  10913. return this._superApply(arguments).done(function () {
  10914. if (
  10915. tree.enableFilter &&
  10916. tree.lastFilterArgs &&
  10917. ctx.options.filter.autoApply
  10918. ) {
  10919. tree._applyFilterImpl.apply(tree, tree.lastFilterArgs);
  10920. }
  10921. });
  10922. },
  10923. nodeSetExpanded: function (ctx, flag, callOpts) {
  10924. var node = ctx.node;
  10925. delete node._filterAutoExpanded;
  10926. // Make sure counter badge is displayed again, when node is beeing collapsed
  10927. if (
  10928. !flag &&
  10929. ctx.options.filter.hideExpandedCounter &&
  10930. node.$subMatchBadge
  10931. ) {
  10932. node.$subMatchBadge.show();
  10933. }
  10934. return this._superApply(arguments);
  10935. },
  10936. nodeRenderStatus: function (ctx) {
  10937. // Set classes for current status
  10938. var res,
  10939. node = ctx.node,
  10940. tree = ctx.tree,
  10941. opts = ctx.options.filter,
  10942. $title = $(node.span).find("span.fancytree-title"),
  10943. $span = $(node[tree.statusClassPropName]),
  10944. enhanceTitle = ctx.options.enhanceTitle,
  10945. escapeTitles = ctx.options.escapeTitles;
  10946. res = this._super(ctx);
  10947. // nothing to do, if node was not yet rendered
  10948. if (!$span.length || !tree.enableFilter) {
  10949. return res;
  10950. }
  10951. $span
  10952. .toggleClass("fancytree-match", !!node.match)
  10953. .toggleClass("fancytree-submatch", !!node.subMatchCount)
  10954. .toggleClass(
  10955. "fancytree-hide",
  10956. !(node.match || node.subMatchCount)
  10957. );
  10958. // Add/update counter badge
  10959. if (
  10960. opts.counter &&
  10961. node.subMatchCount &&
  10962. (!node.isExpanded() || !opts.hideExpandedCounter)
  10963. ) {
  10964. if (!node.$subMatchBadge) {
  10965. node.$subMatchBadge = $(
  10966. "<span class='fancytree-childcounter'/>"
  10967. );
  10968. $(
  10969. "span.fancytree-icon, span.fancytree-custom-icon",
  10970. node.span
  10971. ).append(node.$subMatchBadge);
  10972. }
  10973. node.$subMatchBadge.show().text(node.subMatchCount);
  10974. } else if (node.$subMatchBadge) {
  10975. node.$subMatchBadge.hide();
  10976. }
  10977. // node.debug("nodeRenderStatus", node.titleWithHighlight, node.title)
  10978. // #601: also check for $title.length, because we don't need to render
  10979. // if node.span is null (i.e. not rendered)
  10980. if (node.span && (!node.isEditing || !node.isEditing.call(node))) {
  10981. if (node.titleWithHighlight) {
  10982. $title.html(node.titleWithHighlight);
  10983. } else if (escapeTitles) {
  10984. $title.text(node.title);
  10985. } else {
  10986. $title.html(node.title);
  10987. }
  10988. if (enhanceTitle) {
  10989. enhanceTitle(
  10990. { type: "enhanceTitle" },
  10991. { node: node, $title: $title }
  10992. );
  10993. }
  10994. }
  10995. return res;
  10996. },
  10997. });
  10998. // Value returned by `require('jquery.fancytree..')`
  10999. return $.ui.fancytree;
  11000. }); // End of closure
  11001. /*! Extension 'jquery.fancytree.glyph.js' *//*!
  11002. * jquery.fancytree.glyph.js
  11003. *
  11004. * Use glyph-fonts, ligature-fonts, or SVG icons instead of icon sprites.
  11005. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11006. *
  11007. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  11008. *
  11009. * Released under the MIT license
  11010. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11011. *
  11012. * @version 2.38.5
  11013. * @date 2025-04-05T06:40:00Z
  11014. */
  11015. (function (factory) {
  11016. if (typeof define === "function" && define.amd) {
  11017. // AMD. Register as an anonymous module.
  11018. define(["jquery", "./jquery.fancytree"], factory);
  11019. } else if (typeof module === "object" && module.exports) {
  11020. // Node/CommonJS
  11021. require("./jquery.fancytree");
  11022. module.exports = factory(require("jquery"));
  11023. } else {
  11024. // Browser globals
  11025. factory(jQuery);
  11026. }
  11027. })(function ($) {
  11028. "use strict";
  11029. /******************************************************************************
  11030. * Private functions and variables
  11031. */
  11032. var FT = $.ui.fancytree,
  11033. PRESETS = {
  11034. awesome3: {
  11035. // Outdated!
  11036. _addClass: "",
  11037. checkbox: "icon-check-empty",
  11038. checkboxSelected: "icon-check",
  11039. checkboxUnknown: "icon-check icon-muted",
  11040. dragHelper: "icon-caret-right",
  11041. dropMarker: "icon-caret-right",
  11042. error: "icon-exclamation-sign",
  11043. expanderClosed: "icon-caret-right",
  11044. expanderLazy: "icon-angle-right",
  11045. expanderOpen: "icon-caret-down",
  11046. loading: "icon-refresh icon-spin",
  11047. nodata: "icon-meh",
  11048. noExpander: "",
  11049. radio: "icon-circle-blank",
  11050. radioSelected: "icon-circle",
  11051. // radioUnknown: "icon-circle icon-muted",
  11052. // Default node icons.
  11053. // (Use tree.options.icon callback to define custom icons based on node data)
  11054. doc: "icon-file-alt",
  11055. docOpen: "icon-file-alt",
  11056. folder: "icon-folder-close-alt",
  11057. folderOpen: "icon-folder-open-alt",
  11058. },
  11059. awesome4: {
  11060. _addClass: "fa",
  11061. checkbox: "fa-square-o",
  11062. checkboxSelected: "fa-check-square-o",
  11063. checkboxUnknown: "fa-square fancytree-helper-indeterminate-cb",
  11064. dragHelper: "fa-arrow-right",
  11065. dropMarker: "fa-long-arrow-right",
  11066. error: "fa-warning",
  11067. expanderClosed: "fa-caret-right",
  11068. expanderLazy: "fa-angle-right",
  11069. expanderOpen: "fa-caret-down",
  11070. // We may prevent wobbling rotations on FF by creating a separate sub element:
  11071. loading: { html: "<span class='fa fa-spinner fa-pulse' />" },
  11072. nodata: "fa-meh-o",
  11073. noExpander: "",
  11074. radio: "fa-circle-thin", // "fa-circle-o"
  11075. radioSelected: "fa-circle",
  11076. // radioUnknown: "fa-dot-circle-o",
  11077. // Default node icons.
  11078. // (Use tree.options.icon callback to define custom icons based on node data)
  11079. doc: "fa-file-o",
  11080. docOpen: "fa-file-o",
  11081. folder: "fa-folder-o",
  11082. folderOpen: "fa-folder-open-o",
  11083. },
  11084. awesome5: {
  11085. // fontawesome 5 have several different base classes
  11086. // "far, fas, fal and fab" The rendered svg puts that prefix
  11087. // in a different location so we have to keep them separate here
  11088. _addClass: "",
  11089. checkbox: "far fa-square",
  11090. checkboxSelected: "far fa-check-square",
  11091. // checkboxUnknown: "far fa-window-close",
  11092. checkboxUnknown:
  11093. "fas fa-square fancytree-helper-indeterminate-cb",
  11094. radio: "far fa-circle",
  11095. radioSelected: "fas fa-circle",
  11096. radioUnknown: "far fa-dot-circle",
  11097. dragHelper: "fas fa-arrow-right",
  11098. dropMarker: "fas fa-long-arrow-alt-right",
  11099. error: "fas fa-exclamation-triangle",
  11100. expanderClosed: "fas fa-caret-right",
  11101. expanderLazy: "fas fa-angle-right",
  11102. expanderOpen: "fas fa-caret-down",
  11103. loading: "fas fa-spinner fa-pulse",
  11104. nodata: "far fa-meh",
  11105. noExpander: "",
  11106. // Default node icons.
  11107. // (Use tree.options.icon callback to define custom icons based on node data)
  11108. doc: "far fa-file",
  11109. docOpen: "far fa-file",
  11110. folder: "far fa-folder",
  11111. folderOpen: "far fa-folder-open",
  11112. },
  11113. bootstrap3: {
  11114. _addClass: "glyphicon",
  11115. checkbox: "glyphicon-unchecked",
  11116. checkboxSelected: "glyphicon-check",
  11117. checkboxUnknown:
  11118. "glyphicon-expand fancytree-helper-indeterminate-cb", // "glyphicon-share",
  11119. dragHelper: "glyphicon-play",
  11120. dropMarker: "glyphicon-arrow-right",
  11121. error: "glyphicon-warning-sign",
  11122. expanderClosed: "glyphicon-menu-right", // glyphicon-plus-sign
  11123. expanderLazy: "glyphicon-menu-right", // glyphicon-plus-sign
  11124. expanderOpen: "glyphicon-menu-down", // glyphicon-minus-sign
  11125. loading: "glyphicon-refresh fancytree-helper-spin",
  11126. nodata: "glyphicon-info-sign",
  11127. noExpander: "",
  11128. radio: "glyphicon-remove-circle", // "glyphicon-unchecked",
  11129. radioSelected: "glyphicon-ok-circle", // "glyphicon-check",
  11130. // radioUnknown: "glyphicon-ban-circle",
  11131. // Default node icons.
  11132. // (Use tree.options.icon callback to define custom icons based on node data)
  11133. doc: "glyphicon-file",
  11134. docOpen: "glyphicon-file",
  11135. folder: "glyphicon-folder-close",
  11136. folderOpen: "glyphicon-folder-open",
  11137. },
  11138. material: {
  11139. _addClass: "material-icons",
  11140. checkbox: { text: "check_box_outline_blank" },
  11141. checkboxSelected: { text: "check_box" },
  11142. checkboxUnknown: { text: "indeterminate_check_box" },
  11143. dragHelper: { text: "play_arrow" },
  11144. dropMarker: { text: "arrow_forward" },
  11145. error: { text: "warning" },
  11146. expanderClosed: { text: "chevron_right" },
  11147. expanderLazy: { text: "last_page" },
  11148. expanderOpen: { text: "expand_more" },
  11149. loading: {
  11150. text: "autorenew",
  11151. addClass: "fancytree-helper-spin",
  11152. },
  11153. nodata: { text: "info" },
  11154. noExpander: { text: "" },
  11155. radio: { text: "radio_button_unchecked" },
  11156. radioSelected: { text: "radio_button_checked" },
  11157. // Default node icons.
  11158. // (Use tree.options.icon callback to define custom icons based on node data)
  11159. doc: { text: "insert_drive_file" },
  11160. docOpen: { text: "insert_drive_file" },
  11161. folder: { text: "folder" },
  11162. folderOpen: { text: "folder_open" },
  11163. },
  11164. };
  11165. function setIcon(node, span, baseClass, opts, type) {
  11166. var map = opts.map,
  11167. icon = map[type],
  11168. $span = $(span),
  11169. $counter = $span.find(".fancytree-childcounter"),
  11170. setClass = baseClass + " " + (map._addClass || "");
  11171. // #871 Allow a callback
  11172. if (typeof icon === "function") {
  11173. icon = icon.call(this, node, span, type);
  11174. }
  11175. // node.debug( "setIcon(" + baseClass + ", " + type + "): " + "oldIcon" + " -> " + icon );
  11176. // #871: propsed this, but I am not sure how robust this is, e.g.
  11177. // the prefix (fas, far) class changes are not considered?
  11178. // if (span.tagName === "svg" && opts.preset === "awesome5") {
  11179. // // fa5 script converts <i> to <svg> so call a specific handler.
  11180. // var oldIcon = "fa-" + $span.data("icon");
  11181. // // node.debug( "setIcon(" + baseClass + ", " + type + "): " + oldIcon + " -> " + icon );
  11182. // if (typeof oldIcon === "string") {
  11183. // $span.removeClass(oldIcon);
  11184. // }
  11185. // if (typeof icon === "string") {
  11186. // $span.addClass(icon);
  11187. // }
  11188. // return;
  11189. // }
  11190. if (typeof icon === "string") {
  11191. // #883: remove inner html that may be added by prev. mode
  11192. span.innerHTML = "";
  11193. $span.attr("class", setClass + " " + icon).append($counter);
  11194. } else if (icon) {
  11195. if (icon.text) {
  11196. span.textContent = "" + icon.text;
  11197. } else if (icon.html) {
  11198. span.innerHTML = icon.html;
  11199. } else {
  11200. span.innerHTML = "";
  11201. }
  11202. $span
  11203. .attr("class", setClass + " " + (icon.addClass || ""))
  11204. .append($counter);
  11205. }
  11206. }
  11207. $.ui.fancytree.registerExtension({
  11208. name: "glyph",
  11209. version: "2.38.5",
  11210. // Default options for this extension.
  11211. options: {
  11212. preset: null, // 'awesome3', 'awesome4', 'bootstrap3', 'material'
  11213. map: {},
  11214. },
  11215. treeInit: function (ctx) {
  11216. var tree = ctx.tree,
  11217. opts = ctx.options.glyph;
  11218. if (opts.preset) {
  11219. FT.assert(
  11220. !!PRESETS[opts.preset],
  11221. "Invalid value for `options.glyph.preset`: " + opts.preset
  11222. );
  11223. opts.map = $.extend({}, PRESETS[opts.preset], opts.map);
  11224. } else {
  11225. tree.warn("ext-glyph: missing `preset` option.");
  11226. }
  11227. this._superApply(arguments);
  11228. tree.$container.addClass("fancytree-ext-glyph");
  11229. },
  11230. nodeRenderStatus: function (ctx) {
  11231. var checkbox,
  11232. icon,
  11233. res,
  11234. span,
  11235. node = ctx.node,
  11236. $span = $(node.span),
  11237. opts = ctx.options.glyph;
  11238. res = this._super(ctx);
  11239. if (node.isRootNode()) {
  11240. return res;
  11241. }
  11242. span = $span.children(".fancytree-expander").get(0);
  11243. if (span) {
  11244. // if( node.isLoading() ){
  11245. // icon = "loading";
  11246. if (node.expanded && node.hasChildren()) {
  11247. icon = "expanderOpen";
  11248. } else if (node.isUndefined()) {
  11249. icon = "expanderLazy";
  11250. } else if (node.hasChildren()) {
  11251. icon = "expanderClosed";
  11252. } else {
  11253. icon = "noExpander";
  11254. }
  11255. // span.className = "fancytree-expander " + map[icon];
  11256. setIcon(node, span, "fancytree-expander", opts, icon);
  11257. }
  11258. if (node.tr) {
  11259. span = $("td", node.tr).find(".fancytree-checkbox").get(0);
  11260. } else {
  11261. span = $span.children(".fancytree-checkbox").get(0);
  11262. }
  11263. if (span) {
  11264. checkbox = FT.evalOption("checkbox", node, node, opts, false);
  11265. if (
  11266. (node.parent && node.parent.radiogroup) ||
  11267. checkbox === "radio"
  11268. ) {
  11269. icon = node.selected ? "radioSelected" : "radio";
  11270. setIcon(
  11271. node,
  11272. span,
  11273. "fancytree-checkbox fancytree-radio",
  11274. opts,
  11275. icon
  11276. );
  11277. } else {
  11278. // eslint-disable-next-line no-nested-ternary
  11279. icon = node.selected
  11280. ? "checkboxSelected"
  11281. : node.partsel
  11282. ? "checkboxUnknown"
  11283. : "checkbox";
  11284. // span.className = "fancytree-checkbox " + map[icon];
  11285. setIcon(node, span, "fancytree-checkbox", opts, icon);
  11286. }
  11287. }
  11288. // Standard icon (note that this does not match .fancytree-custom-icon,
  11289. // that might be set by opts.icon callbacks)
  11290. span = $span.children(".fancytree-icon").get(0);
  11291. if (span) {
  11292. if (node.statusNodeType) {
  11293. icon = node.statusNodeType; // loading, error
  11294. } else if (node.folder) {
  11295. icon =
  11296. node.expanded && node.hasChildren()
  11297. ? "folderOpen"
  11298. : "folder";
  11299. } else {
  11300. icon = node.expanded ? "docOpen" : "doc";
  11301. }
  11302. setIcon(node, span, "fancytree-icon", opts, icon);
  11303. }
  11304. return res;
  11305. },
  11306. nodeSetStatus: function (ctx, status, message, details) {
  11307. var res,
  11308. span,
  11309. opts = ctx.options.glyph,
  11310. node = ctx.node;
  11311. res = this._superApply(arguments);
  11312. if (
  11313. status === "error" ||
  11314. status === "loading" ||
  11315. status === "nodata"
  11316. ) {
  11317. if (node.parent) {
  11318. span = $(".fancytree-expander", node.span).get(0);
  11319. if (span) {
  11320. setIcon(node, span, "fancytree-expander", opts, status);
  11321. }
  11322. } else {
  11323. //
  11324. span = $(
  11325. ".fancytree-statusnode-" + status,
  11326. node[this.nodeContainerAttrName]
  11327. )
  11328. .find(".fancytree-icon")
  11329. .get(0);
  11330. if (span) {
  11331. setIcon(node, span, "fancytree-icon", opts, status);
  11332. }
  11333. }
  11334. }
  11335. return res;
  11336. },
  11337. });
  11338. // Value returned by `require('jquery.fancytree..')`
  11339. return $.ui.fancytree;
  11340. }); // End of closure
  11341. /*! Extension 'jquery.fancytree.gridnav.js' *//*!
  11342. * jquery.fancytree.gridnav.js
  11343. *
  11344. * Support keyboard navigation for trees with embedded input controls.
  11345. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11346. *
  11347. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  11348. *
  11349. * Released under the MIT license
  11350. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11351. *
  11352. * @version 2.38.5
  11353. * @date 2025-04-05T06:40:00Z
  11354. */
  11355. (function (factory) {
  11356. if (typeof define === "function" && define.amd) {
  11357. // AMD. Register as an anonymous module.
  11358. define([
  11359. "jquery",
  11360. "./jquery.fancytree",
  11361. "./jquery.fancytree.table",
  11362. ], factory);
  11363. } else if (typeof module === "object" && module.exports) {
  11364. // Node/CommonJS
  11365. require("./jquery.fancytree.table"); // core + table
  11366. module.exports = factory(require("jquery"));
  11367. } else {
  11368. // Browser globals
  11369. factory(jQuery);
  11370. }
  11371. })(function ($) {
  11372. "use strict";
  11373. /*******************************************************************************
  11374. * Private functions and variables
  11375. */
  11376. // Allow these navigation keys even when input controls are focused
  11377. var KC = $.ui.keyCode,
  11378. // which keys are *not* handled by embedded control, but passed to tree
  11379. // navigation handler:
  11380. NAV_KEYS = {
  11381. text: [KC.UP, KC.DOWN],
  11382. checkbox: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11383. link: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11384. radiobutton: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11385. "select-one": [KC.LEFT, KC.RIGHT],
  11386. "select-multiple": [KC.LEFT, KC.RIGHT],
  11387. };
  11388. /* Calculate TD column index (considering colspans).*/
  11389. function getColIdx($tr, $td) {
  11390. var colspan,
  11391. td = $td.get(0),
  11392. idx = 0;
  11393. $tr.children().each(function () {
  11394. if (this === td) {
  11395. return false;
  11396. }
  11397. colspan = $(this).prop("colspan");
  11398. idx += colspan ? colspan : 1;
  11399. });
  11400. return idx;
  11401. }
  11402. /* Find TD at given column index (considering colspans).*/
  11403. function findTdAtColIdx($tr, colIdx) {
  11404. var colspan,
  11405. res = null,
  11406. idx = 0;
  11407. $tr.children().each(function () {
  11408. if (idx >= colIdx) {
  11409. res = $(this);
  11410. return false;
  11411. }
  11412. colspan = $(this).prop("colspan");
  11413. idx += colspan ? colspan : 1;
  11414. });
  11415. return res;
  11416. }
  11417. /* Find adjacent cell for a given direction. Skip empty cells and consider merged cells */
  11418. function findNeighbourTd($target, keyCode) {
  11419. var $tr,
  11420. colIdx,
  11421. $td = $target.closest("td"),
  11422. $tdNext = null;
  11423. switch (keyCode) {
  11424. case KC.LEFT:
  11425. $tdNext = $td.prev();
  11426. break;
  11427. case KC.RIGHT:
  11428. $tdNext = $td.next();
  11429. break;
  11430. case KC.UP:
  11431. case KC.DOWN:
  11432. $tr = $td.parent();
  11433. colIdx = getColIdx($tr, $td);
  11434. while (true) {
  11435. $tr = keyCode === KC.UP ? $tr.prev() : $tr.next();
  11436. if (!$tr.length) {
  11437. break;
  11438. }
  11439. // Skip hidden rows
  11440. if ($tr.is(":hidden")) {
  11441. continue;
  11442. }
  11443. // Find adjacent cell in the same column
  11444. $tdNext = findTdAtColIdx($tr, colIdx);
  11445. // Skip cells that don't conatain a focusable element
  11446. if ($tdNext && $tdNext.find(":input,a").length) {
  11447. break;
  11448. }
  11449. }
  11450. break;
  11451. }
  11452. return $tdNext;
  11453. }
  11454. /*******************************************************************************
  11455. * Extension code
  11456. */
  11457. $.ui.fancytree.registerExtension({
  11458. name: "gridnav",
  11459. version: "2.38.5",
  11460. // Default options for this extension.
  11461. options: {
  11462. autofocusInput: false, // Focus first embedded input if node gets activated
  11463. handleCursorKeys: true, // Allow UP/DOWN in inputs to move to prev/next node
  11464. },
  11465. treeInit: function (ctx) {
  11466. // gridnav requires the table extension to be loaded before itself
  11467. this._requireExtension("table", true, true);
  11468. this._superApply(arguments);
  11469. this.$container.addClass("fancytree-ext-gridnav");
  11470. // Activate node if embedded input gets focus (due to a click)
  11471. this.$container.on("focusin", function (event) {
  11472. var ctx2,
  11473. node = $.ui.fancytree.getNode(event.target);
  11474. if (node && !node.isActive()) {
  11475. // Call node.setActive(), but also pass the event
  11476. ctx2 = ctx.tree._makeHookContext(node, event);
  11477. ctx.tree._callHook("nodeSetActive", ctx2, true);
  11478. }
  11479. });
  11480. },
  11481. nodeSetActive: function (ctx, flag, callOpts) {
  11482. var $outer,
  11483. opts = ctx.options.gridnav,
  11484. node = ctx.node,
  11485. event = ctx.originalEvent || {},
  11486. triggeredByInput = $(event.target).is(":input");
  11487. flag = flag !== false;
  11488. this._superApply(arguments);
  11489. if (flag) {
  11490. if (ctx.options.titlesTabbable) {
  11491. if (!triggeredByInput) {
  11492. $(node.span)
  11493. .find("span.fancytree-title")
  11494. .trigger("focus");
  11495. node.setFocus();
  11496. }
  11497. // If one node is tabbable, the container no longer needs to be
  11498. ctx.tree.$container.attr("tabindex", "-1");
  11499. // ctx.tree.$container.removeAttr("tabindex");
  11500. } else if (opts.autofocusInput && !triggeredByInput) {
  11501. // Set focus to input sub input (if node was clicked, but not
  11502. // when TAB was pressed )
  11503. $outer = $(node.tr || node.span);
  11504. $outer.find(":input:enabled").first().trigger("focus");
  11505. }
  11506. }
  11507. },
  11508. nodeKeydown: function (ctx) {
  11509. var inputType,
  11510. handleKeys,
  11511. $td,
  11512. opts = ctx.options.gridnav,
  11513. event = ctx.originalEvent,
  11514. $target = $(event.target);
  11515. if ($target.is(":input:enabled")) {
  11516. inputType = $target.prop("type");
  11517. } else if ($target.is("a")) {
  11518. inputType = "link";
  11519. }
  11520. // ctx.tree.debug("ext-gridnav nodeKeydown", event, inputType);
  11521. if (inputType && opts.handleCursorKeys) {
  11522. handleKeys = NAV_KEYS[inputType];
  11523. if (handleKeys && $.inArray(event.which, handleKeys) >= 0) {
  11524. $td = findNeighbourTd($target, event.which);
  11525. if ($td && $td.length) {
  11526. // ctx.node.debug("ignore keydown in input", event.which, handleKeys);
  11527. $td.find(":input:enabled,a").trigger("focus");
  11528. // Prevent Fancytree default navigation
  11529. return false;
  11530. }
  11531. }
  11532. return true;
  11533. }
  11534. // ctx.tree.debug("ext-gridnav NOT HANDLED", event, inputType);
  11535. return this._superApply(arguments);
  11536. },
  11537. });
  11538. // Value returned by `require('jquery.fancytree..')`
  11539. return $.ui.fancytree;
  11540. }); // End of closure
  11541. /*! Extension 'jquery.fancytree.multi.js' *//*!
  11542. * jquery.fancytree.multi.js
  11543. *
  11544. * Allow multiple selection of nodes by mouse or keyboard.
  11545. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11546. *
  11547. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  11548. *
  11549. * Released under the MIT license
  11550. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11551. *
  11552. * @version 2.38.5
  11553. * @date 2025-04-05T06:40:00Z
  11554. */
  11555. (function (factory) {
  11556. if (typeof define === "function" && define.amd) {
  11557. // AMD. Register as an anonymous module.
  11558. define(["jquery", "./jquery.fancytree"], factory);
  11559. } else if (typeof module === "object" && module.exports) {
  11560. // Node/CommonJS
  11561. require("./jquery.fancytree");
  11562. module.exports = factory(require("jquery"));
  11563. } else {
  11564. // Browser globals
  11565. factory(jQuery);
  11566. }
  11567. })(function ($) {
  11568. "use strict";
  11569. /*******************************************************************************
  11570. * Private functions and variables
  11571. */
  11572. // var isMac = /Mac/.test(navigator.platform);
  11573. /*******************************************************************************
  11574. * Extension code
  11575. */
  11576. $.ui.fancytree.registerExtension({
  11577. name: "multi",
  11578. version: "2.38.5",
  11579. // Default options for this extension.
  11580. options: {
  11581. allowNoSelect: false, //
  11582. mode: "sameParent", //
  11583. // Events:
  11584. // beforeSelect: $.noop // Return false to prevent cancel/save (data.input is available)
  11585. },
  11586. treeInit: function (ctx) {
  11587. this._superApply(arguments);
  11588. this.$container.addClass("fancytree-ext-multi");
  11589. if (ctx.options.selectMode === 1) {
  11590. $.error(
  11591. "Fancytree ext-multi: selectMode: 1 (single) is not compatible."
  11592. );
  11593. }
  11594. },
  11595. nodeClick: function (ctx) {
  11596. var //pluginOpts = ctx.options.multi,
  11597. tree = ctx.tree,
  11598. node = ctx.node,
  11599. activeNode = tree.getActiveNode() || tree.getFirstChild(),
  11600. isCbClick = ctx.targetType === "checkbox",
  11601. isExpanderClick = ctx.targetType === "expander",
  11602. eventStr = $.ui.fancytree.eventToString(ctx.originalEvent);
  11603. switch (eventStr) {
  11604. case "click":
  11605. if (isExpanderClick) {
  11606. break;
  11607. } // Default handler will expand/collapse
  11608. if (!isCbClick) {
  11609. tree.selectAll(false);
  11610. // Select clicked node (radio-button mode)
  11611. node.setSelected();
  11612. }
  11613. // Default handler will toggle checkbox clicks and activate
  11614. break;
  11615. case "shift+click":
  11616. // node.debug("click")
  11617. tree.visitRows(
  11618. function (n) {
  11619. // n.debug("click2", n===node, node)
  11620. n.setSelected();
  11621. if (n === node) {
  11622. return false;
  11623. }
  11624. },
  11625. {
  11626. start: activeNode,
  11627. reverse: activeNode.isBelowOf(node),
  11628. }
  11629. );
  11630. break;
  11631. case "ctrl+click":
  11632. case "meta+click": // Mac: [Command]
  11633. node.toggleSelected();
  11634. return;
  11635. }
  11636. return this._superApply(arguments);
  11637. },
  11638. nodeKeydown: function (ctx) {
  11639. var tree = ctx.tree,
  11640. node = ctx.node,
  11641. event = ctx.originalEvent,
  11642. eventStr = $.ui.fancytree.eventToString(event);
  11643. switch (eventStr) {
  11644. case "up":
  11645. case "down":
  11646. tree.selectAll(false);
  11647. node.navigate(event.which, true);
  11648. tree.getActiveNode().setSelected();
  11649. break;
  11650. case "shift+up":
  11651. case "shift+down":
  11652. node.navigate(event.which, true);
  11653. tree.getActiveNode().setSelected();
  11654. break;
  11655. }
  11656. return this._superApply(arguments);
  11657. },
  11658. });
  11659. // Value returned by `require('jquery.fancytree..')`
  11660. return $.ui.fancytree;
  11661. }); // End of closure
  11662. /*! Extension 'jquery.fancytree.persist.js' *//*!
  11663. * jquery.fancytree.persist.js
  11664. *
  11665. * Persist tree status in cookiesRemove or highlight tree nodes, based on a filter.
  11666. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11667. *
  11668. * @depends: js-cookie or jquery-cookie
  11669. *
  11670. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  11671. *
  11672. * Released under the MIT license
  11673. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11674. *
  11675. * @version 2.38.5
  11676. * @date 2025-04-05T06:40:00Z
  11677. */
  11678. (function (factory) {
  11679. if (typeof define === "function" && define.amd) {
  11680. // AMD. Register as an anonymous module.
  11681. define(["jquery", "./jquery.fancytree"], factory);
  11682. } else if (typeof module === "object" && module.exports) {
  11683. // Node/CommonJS
  11684. require("./jquery.fancytree");
  11685. module.exports = factory(require("jquery"));
  11686. } else {
  11687. // Browser globals
  11688. factory(jQuery);
  11689. }
  11690. })(function ($) {
  11691. "use strict";
  11692. /* global Cookies:false */
  11693. /*******************************************************************************
  11694. * Private functions and variables
  11695. */
  11696. var cookieStore = null,
  11697. localStorageStore = null,
  11698. sessionStorageStore = null,
  11699. _assert = $.ui.fancytree.assert,
  11700. ACTIVE = "active",
  11701. EXPANDED = "expanded",
  11702. FOCUS = "focus",
  11703. SELECTED = "selected";
  11704. // Accessing window.xxxStorage may raise security exceptions (see #1022)
  11705. try {
  11706. _assert(window.localStorage && window.localStorage.getItem);
  11707. localStorageStore = {
  11708. get: function (key) {
  11709. return window.localStorage.getItem(key);
  11710. },
  11711. set: function (key, value) {
  11712. window.localStorage.setItem(key, value);
  11713. },
  11714. remove: function (key) {
  11715. window.localStorage.removeItem(key);
  11716. },
  11717. };
  11718. } catch (e) {
  11719. $.ui.fancytree.warn("Could not access window.localStorage", e);
  11720. }
  11721. try {
  11722. _assert(window.sessionStorage && window.sessionStorage.getItem);
  11723. sessionStorageStore = {
  11724. get: function (key) {
  11725. return window.sessionStorage.getItem(key);
  11726. },
  11727. set: function (key, value) {
  11728. window.sessionStorage.setItem(key, value);
  11729. },
  11730. remove: function (key) {
  11731. window.sessionStorage.removeItem(key);
  11732. },
  11733. };
  11734. } catch (e) {
  11735. $.ui.fancytree.warn("Could not access window.sessionStorage", e);
  11736. }
  11737. if (typeof Cookies === "function") {
  11738. // Assume https://github.com/js-cookie/js-cookie
  11739. cookieStore = {
  11740. get: Cookies.get,
  11741. set: function (key, value) {
  11742. Cookies.set(key, value, this.options.persist.cookie);
  11743. },
  11744. remove: Cookies.remove,
  11745. };
  11746. } else if ($ && typeof $.cookie === "function") {
  11747. // Fall back to https://github.com/carhartl/jquery-cookie
  11748. cookieStore = {
  11749. get: $.cookie,
  11750. set: function (key, value) {
  11751. $.cookie(key, value, this.options.persist.cookie);
  11752. },
  11753. remove: $.removeCookie,
  11754. };
  11755. }
  11756. /* Recursively load lazy nodes
  11757. * @param {string} mode 'load', 'expand', false
  11758. */
  11759. function _loadLazyNodes(tree, local, keyList, mode, dfd) {
  11760. var i,
  11761. key,
  11762. l,
  11763. node,
  11764. foundOne = false,
  11765. expandOpts = tree.options.persist.expandOpts,
  11766. deferredList = [],
  11767. missingKeyList = [];
  11768. keyList = keyList || [];
  11769. dfd = dfd || $.Deferred();
  11770. for (i = 0, l = keyList.length; i < l; i++) {
  11771. key = keyList[i];
  11772. node = tree.getNodeByKey(key);
  11773. if (node) {
  11774. if (mode && node.isUndefined()) {
  11775. foundOne = true;
  11776. tree.debug(
  11777. "_loadLazyNodes: " + node + " is lazy: loading..."
  11778. );
  11779. if (mode === "expand") {
  11780. deferredList.push(node.setExpanded(true, expandOpts));
  11781. } else {
  11782. deferredList.push(node.load());
  11783. }
  11784. } else {
  11785. tree.debug("_loadLazyNodes: " + node + " already loaded.");
  11786. try {
  11787. node.setExpanded(true, expandOpts);
  11788. } catch (e) {
  11789. // #1157
  11790. tree.warn(
  11791. "ext-persist: setExpanded failed for " + node,
  11792. e
  11793. );
  11794. }
  11795. }
  11796. } else {
  11797. missingKeyList.push(key);
  11798. tree.debug("_loadLazyNodes: " + node + " was not yet found.");
  11799. }
  11800. }
  11801. $.when.apply($, deferredList).always(function () {
  11802. // All lazy-expands have finished
  11803. if (foundOne && missingKeyList.length > 0) {
  11804. // If we read new nodes from server, try to resolve yet-missing keys
  11805. _loadLazyNodes(tree, local, missingKeyList, mode, dfd);
  11806. } else {
  11807. if (missingKeyList.length) {
  11808. tree.warn(
  11809. "_loadLazyNodes: could not load those keys: ",
  11810. missingKeyList
  11811. );
  11812. for (i = 0, l = missingKeyList.length; i < l; i++) {
  11813. key = keyList[i];
  11814. local._appendKey(EXPANDED, keyList[i], false);
  11815. }
  11816. }
  11817. dfd.resolve();
  11818. }
  11819. });
  11820. return dfd;
  11821. }
  11822. /**
  11823. * [ext-persist] Remove persistence data of the given type(s).
  11824. * Called like
  11825. * $.ui.fancytree.getTree("#tree").clearCookies("active expanded focus selected");
  11826. *
  11827. * @alias Fancytree#clearPersistData
  11828. * @requires jquery.fancytree.persist.js
  11829. */
  11830. $.ui.fancytree._FancytreeClass.prototype.clearPersistData = function (
  11831. types
  11832. ) {
  11833. var local = this.ext.persist,
  11834. prefix = local.cookiePrefix;
  11835. types = types || "active expanded focus selected";
  11836. if (types.indexOf(ACTIVE) >= 0) {
  11837. local._data(prefix + ACTIVE, null);
  11838. }
  11839. if (types.indexOf(EXPANDED) >= 0) {
  11840. local._data(prefix + EXPANDED, null);
  11841. }
  11842. if (types.indexOf(FOCUS) >= 0) {
  11843. local._data(prefix + FOCUS, null);
  11844. }
  11845. if (types.indexOf(SELECTED) >= 0) {
  11846. local._data(prefix + SELECTED, null);
  11847. }
  11848. };
  11849. $.ui.fancytree._FancytreeClass.prototype.clearCookies = function (types) {
  11850. this.warn(
  11851. "'tree.clearCookies()' is deprecated since v2.27.0: use 'clearPersistData()' instead."
  11852. );
  11853. return this.clearPersistData(types);
  11854. };
  11855. /**
  11856. * [ext-persist] Return persistence information from cookies
  11857. *
  11858. * Called like
  11859. * $.ui.fancytree.getTree("#tree").getPersistData();
  11860. *
  11861. * @alias Fancytree#getPersistData
  11862. * @requires jquery.fancytree.persist.js
  11863. */
  11864. $.ui.fancytree._FancytreeClass.prototype.getPersistData = function () {
  11865. var local = this.ext.persist,
  11866. prefix = local.cookiePrefix,
  11867. delim = local.cookieDelimiter,
  11868. res = {};
  11869. res[ACTIVE] = local._data(prefix + ACTIVE);
  11870. res[EXPANDED] = (local._data(prefix + EXPANDED) || "").split(delim);
  11871. res[SELECTED] = (local._data(prefix + SELECTED) || "").split(delim);
  11872. res[FOCUS] = local._data(prefix + FOCUS);
  11873. return res;
  11874. };
  11875. /******************************************************************************
  11876. * Extension code
  11877. */
  11878. $.ui.fancytree.registerExtension({
  11879. name: "persist",
  11880. version: "2.38.5",
  11881. // Default options for this extension.
  11882. options: {
  11883. cookieDelimiter: "~",
  11884. cookiePrefix: undefined, // 'fancytree-<treeId>-' by default
  11885. cookie: {
  11886. raw: false,
  11887. expires: "",
  11888. path: "",
  11889. domain: "",
  11890. secure: false,
  11891. },
  11892. expandLazy: false, // true: recursively expand and load lazy nodes
  11893. expandOpts: undefined, // optional `opts` argument passed to setExpanded()
  11894. fireActivate: true, // false: suppress `activate` event after active node was restored
  11895. overrideSource: true, // true: cookie takes precedence over `source` data attributes.
  11896. store: "auto", // 'cookie': force cookie, 'local': force localStore, 'session': force sessionStore
  11897. types: "active expanded focus selected",
  11898. },
  11899. /* Generic read/write string data to cookie, sessionStorage or localStorage. */
  11900. _data: function (key, value) {
  11901. var store = this._local.store;
  11902. if (value === undefined) {
  11903. return store.get.call(this, key);
  11904. } else if (value === null) {
  11905. store.remove.call(this, key);
  11906. } else {
  11907. store.set.call(this, key, value);
  11908. }
  11909. },
  11910. /* Append `key` to a cookie. */
  11911. _appendKey: function (type, key, flag) {
  11912. key = "" + key; // #90
  11913. var local = this._local,
  11914. instOpts = this.options.persist,
  11915. delim = instOpts.cookieDelimiter,
  11916. cookieName = local.cookiePrefix + type,
  11917. data = local._data(cookieName),
  11918. keyList = data ? data.split(delim) : [],
  11919. idx = $.inArray(key, keyList);
  11920. // Remove, even if we add a key, so the key is always the last entry
  11921. if (idx >= 0) {
  11922. keyList.splice(idx, 1);
  11923. }
  11924. // Append key to cookie
  11925. if (flag) {
  11926. keyList.push(key);
  11927. }
  11928. local._data(cookieName, keyList.join(delim));
  11929. },
  11930. treeInit: function (ctx) {
  11931. var tree = ctx.tree,
  11932. opts = ctx.options,
  11933. local = this._local,
  11934. instOpts = this.options.persist;
  11935. // // For 'auto' or 'cookie' mode, the cookie plugin must be available
  11936. // _assert((instOpts.store !== "auto" && instOpts.store !== "cookie") || cookieStore,
  11937. // "Missing required plugin for 'persist' extension: js.cookie.js or jquery.cookie.js");
  11938. local.cookiePrefix =
  11939. instOpts.cookiePrefix || "fancytree-" + tree._id + "-";
  11940. local.storeActive = instOpts.types.indexOf(ACTIVE) >= 0;
  11941. local.storeExpanded = instOpts.types.indexOf(EXPANDED) >= 0;
  11942. local.storeSelected = instOpts.types.indexOf(SELECTED) >= 0;
  11943. local.storeFocus = instOpts.types.indexOf(FOCUS) >= 0;
  11944. local.store = null;
  11945. if (instOpts.store === "auto") {
  11946. instOpts.store = localStorageStore ? "local" : "cookie";
  11947. }
  11948. if ($.isPlainObject(instOpts.store)) {
  11949. local.store = instOpts.store;
  11950. } else if (instOpts.store === "cookie") {
  11951. local.store = cookieStore;
  11952. } else if (instOpts.store === "local") {
  11953. local.store =
  11954. instOpts.store === "local"
  11955. ? localStorageStore
  11956. : sessionStorageStore;
  11957. } else if (instOpts.store === "session") {
  11958. local.store =
  11959. instOpts.store === "local"
  11960. ? localStorageStore
  11961. : sessionStorageStore;
  11962. }
  11963. _assert(local.store, "Need a valid store.");
  11964. // Bind init-handler to apply cookie state
  11965. tree.$div.on("fancytreeinit", function (event) {
  11966. if (
  11967. tree._triggerTreeEvent("beforeRestore", null, {}) === false
  11968. ) {
  11969. return;
  11970. }
  11971. var cookie,
  11972. dfd,
  11973. i,
  11974. keyList,
  11975. node,
  11976. prevFocus = local._data(local.cookiePrefix + FOCUS), // record this before node.setActive() overrides it;
  11977. noEvents = instOpts.fireActivate === false;
  11978. // tree.debug("document.cookie:", document.cookie);
  11979. cookie = local._data(local.cookiePrefix + EXPANDED);
  11980. keyList = cookie && cookie.split(instOpts.cookieDelimiter);
  11981. if (local.storeExpanded) {
  11982. // Recursively load nested lazy nodes if expandLazy is 'expand' or 'load'
  11983. // Also remove expand-cookies for unmatched nodes
  11984. dfd = _loadLazyNodes(
  11985. tree,
  11986. local,
  11987. keyList,
  11988. instOpts.expandLazy ? "expand" : false,
  11989. null
  11990. );
  11991. } else {
  11992. // nothing to do
  11993. dfd = new $.Deferred().resolve();
  11994. }
  11995. dfd.done(function () {
  11996. if (local.storeSelected) {
  11997. cookie = local._data(local.cookiePrefix + SELECTED);
  11998. if (cookie) {
  11999. keyList = cookie.split(instOpts.cookieDelimiter);
  12000. for (i = 0; i < keyList.length; i++) {
  12001. node = tree.getNodeByKey(keyList[i]);
  12002. if (node) {
  12003. if (
  12004. node.selected === undefined ||
  12005. (instOpts.overrideSource &&
  12006. node.selected === false)
  12007. ) {
  12008. // node.setSelected();
  12009. node.selected = true;
  12010. node.renderStatus();
  12011. }
  12012. } else {
  12013. // node is no longer member of the tree: remove from cookie also
  12014. local._appendKey(
  12015. SELECTED,
  12016. keyList[i],
  12017. false
  12018. );
  12019. }
  12020. }
  12021. }
  12022. // In selectMode 3 we have to fix the child nodes, since we
  12023. // only stored the selected *top* nodes
  12024. if (tree.options.selectMode === 3) {
  12025. tree.visit(function (n) {
  12026. if (n.selected) {
  12027. n.fixSelection3AfterClick();
  12028. return "skip";
  12029. }
  12030. });
  12031. }
  12032. }
  12033. if (local.storeActive) {
  12034. cookie = local._data(local.cookiePrefix + ACTIVE);
  12035. if (
  12036. cookie &&
  12037. (opts.persist.overrideSource || !tree.activeNode)
  12038. ) {
  12039. node = tree.getNodeByKey(cookie);
  12040. if (node) {
  12041. node.debug("persist: set active", cookie);
  12042. // We only want to set the focus if the container
  12043. // had the keyboard focus before
  12044. node.setActive(true, {
  12045. noFocus: true,
  12046. noEvents: noEvents,
  12047. });
  12048. }
  12049. }
  12050. }
  12051. if (local.storeFocus && prevFocus) {
  12052. node = tree.getNodeByKey(prevFocus);
  12053. if (node) {
  12054. // node.debug("persist: set focus", cookie);
  12055. if (tree.options.titlesTabbable) {
  12056. $(node.span)
  12057. .find(".fancytree-title")
  12058. .trigger("focus");
  12059. } else {
  12060. $(tree.$container).trigger("focus");
  12061. }
  12062. // node.setFocus();
  12063. }
  12064. }
  12065. tree._triggerTreeEvent("restore", null, {});
  12066. });
  12067. });
  12068. // Init the tree
  12069. return this._superApply(arguments);
  12070. },
  12071. nodeSetActive: function (ctx, flag, callOpts) {
  12072. var res,
  12073. local = this._local;
  12074. flag = flag !== false;
  12075. res = this._superApply(arguments);
  12076. if (local.storeActive) {
  12077. local._data(
  12078. local.cookiePrefix + ACTIVE,
  12079. this.activeNode ? this.activeNode.key : null
  12080. );
  12081. }
  12082. return res;
  12083. },
  12084. nodeSetExpanded: function (ctx, flag, callOpts) {
  12085. var res,
  12086. node = ctx.node,
  12087. local = this._local;
  12088. flag = flag !== false;
  12089. res = this._superApply(arguments);
  12090. if (local.storeExpanded) {
  12091. local._appendKey(EXPANDED, node.key, flag);
  12092. }
  12093. return res;
  12094. },
  12095. nodeSetFocus: function (ctx, flag) {
  12096. var res,
  12097. local = this._local;
  12098. flag = flag !== false;
  12099. res = this._superApply(arguments);
  12100. if (local.storeFocus) {
  12101. local._data(
  12102. local.cookiePrefix + FOCUS,
  12103. this.focusNode ? this.focusNode.key : null
  12104. );
  12105. }
  12106. return res;
  12107. },
  12108. nodeSetSelected: function (ctx, flag, callOpts) {
  12109. var res,
  12110. selNodes,
  12111. tree = ctx.tree,
  12112. node = ctx.node,
  12113. local = this._local;
  12114. flag = flag !== false;
  12115. res = this._superApply(arguments);
  12116. if (local.storeSelected) {
  12117. if (tree.options.selectMode === 3) {
  12118. // In selectMode 3 we only store the the selected *top* nodes.
  12119. // De-selecting a node may also de-select some parents, so we
  12120. // calculate the current status again
  12121. selNodes = $.map(tree.getSelectedNodes(true), function (n) {
  12122. return n.key;
  12123. });
  12124. selNodes = selNodes.join(
  12125. ctx.options.persist.cookieDelimiter
  12126. );
  12127. local._data(local.cookiePrefix + SELECTED, selNodes);
  12128. } else {
  12129. // beforeSelect can prevent the change - flag doesn't reflect the node.selected state
  12130. local._appendKey(SELECTED, node.key, node.selected);
  12131. }
  12132. }
  12133. return res;
  12134. },
  12135. });
  12136. // Value returned by `require('jquery.fancytree..')`
  12137. return $.ui.fancytree;
  12138. }); // End of closure
  12139. /*! Extension 'jquery.fancytree.table.js' *//*!
  12140. * jquery.fancytree.table.js
  12141. *
  12142. * Render tree as table (aka 'tree grid', 'table tree').
  12143. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12144. *
  12145. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  12146. *
  12147. * Released under the MIT license
  12148. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12149. *
  12150. * @version 2.38.5
  12151. * @date 2025-04-05T06:40:00Z
  12152. */
  12153. (function (factory) {
  12154. if (typeof define === "function" && define.amd) {
  12155. // AMD. Register as an anonymous module.
  12156. define(["jquery", "./jquery.fancytree"], factory);
  12157. } else if (typeof module === "object" && module.exports) {
  12158. // Node/CommonJS
  12159. require("./jquery.fancytree");
  12160. module.exports = factory(require("jquery"));
  12161. } else {
  12162. // Browser globals
  12163. factory(jQuery);
  12164. }
  12165. })(function ($) {
  12166. "use strict";
  12167. /******************************************************************************
  12168. * Private functions and variables
  12169. */
  12170. var _assert = $.ui.fancytree.assert;
  12171. function insertFirstChild(referenceNode, newNode) {
  12172. referenceNode.insertBefore(newNode, referenceNode.firstChild);
  12173. }
  12174. function insertSiblingAfter(referenceNode, newNode) {
  12175. referenceNode.parentNode.insertBefore(
  12176. newNode,
  12177. referenceNode.nextSibling
  12178. );
  12179. }
  12180. /* Show/hide all rows that are structural descendants of `parent`. */
  12181. function setChildRowVisibility(parent, flag) {
  12182. parent.visit(function (node) {
  12183. var tr = node.tr;
  12184. // currentFlag = node.hide ? false : flag; // fix for ext-filter
  12185. if (tr) {
  12186. tr.style.display = node.hide || !flag ? "none" : "";
  12187. }
  12188. if (!node.expanded) {
  12189. return "skip";
  12190. }
  12191. });
  12192. }
  12193. /* Find node that is rendered in previous row. */
  12194. function findPrevRowNode(node) {
  12195. var i,
  12196. last,
  12197. prev,
  12198. parent = node.parent,
  12199. siblings = parent ? parent.children : null;
  12200. if (siblings && siblings.length > 1 && siblings[0] !== node) {
  12201. // use the lowest descendant of the preceeding sibling
  12202. i = $.inArray(node, siblings);
  12203. prev = siblings[i - 1];
  12204. _assert(prev.tr, "prev.tr missing: " + prev);
  12205. // descend to lowest child (with a <tr> tag)
  12206. while (prev.children && prev.children.length) {
  12207. last = prev.children[prev.children.length - 1];
  12208. if (!last.tr) {
  12209. break;
  12210. }
  12211. prev = last;
  12212. }
  12213. } else {
  12214. // if there is no preceding sibling, use the direct parent
  12215. prev = parent;
  12216. }
  12217. return prev;
  12218. }
  12219. $.ui.fancytree.registerExtension({
  12220. name: "table",
  12221. version: "2.38.5",
  12222. // Default options for this extension.
  12223. options: {
  12224. checkboxColumnIdx: null, // render the checkboxes into the this column index (default: nodeColumnIdx)
  12225. indentation: 16, // indent every node level by 16px
  12226. mergeStatusColumns: true, // display 'nodata', 'loading', 'error' centered in a single, merged TR
  12227. nodeColumnIdx: 0, // render node expander, icon, and title to this column (default: #0)
  12228. },
  12229. // Overide virtual methods for this extension.
  12230. // `this` : is this extension object
  12231. // `this._super`: the virtual function that was overriden (member of prev. extension or Fancytree)
  12232. treeInit: function (ctx) {
  12233. var i,
  12234. n,
  12235. $row,
  12236. $tbody,
  12237. tree = ctx.tree,
  12238. opts = ctx.options,
  12239. tableOpts = opts.table,
  12240. $table = tree.widget.element;
  12241. if (tableOpts.customStatus != null) {
  12242. if (opts.renderStatusColumns == null) {
  12243. tree.warn(
  12244. "The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' instead."
  12245. );
  12246. opts.renderStatusColumns = tableOpts.customStatus;
  12247. } else {
  12248. $.error(
  12249. "The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' only instead."
  12250. );
  12251. }
  12252. }
  12253. if (opts.renderStatusColumns) {
  12254. if (opts.renderStatusColumns === true) {
  12255. opts.renderStatusColumns = opts.renderColumns;
  12256. // } else if( opts.renderStatusColumns === "wide" ) {
  12257. // opts.renderStatusColumns = _renderStatusNodeWide;
  12258. }
  12259. }
  12260. $table.addClass("fancytree-container fancytree-ext-table");
  12261. $tbody = $table.find(">tbody");
  12262. if (!$tbody.length) {
  12263. // TODO: not sure if we can rely on browsers to insert missing <tbody> before <tr>s:
  12264. if ($table.find(">tr").length) {
  12265. $.error(
  12266. "Expected table > tbody > tr. If you see this please open an issue."
  12267. );
  12268. }
  12269. $tbody = $("<tbody>").appendTo($table);
  12270. }
  12271. tree.tbody = $tbody[0];
  12272. // Prepare row templates:
  12273. // Determine column count from table header if any
  12274. tree.columnCount = $("thead >tr", $table)
  12275. .last()
  12276. .find(">th", $table).length;
  12277. // Read TR templates from tbody if any
  12278. $row = $tbody.children("tr").first();
  12279. if ($row.length) {
  12280. n = $row.children("td").length;
  12281. if (tree.columnCount && n !== tree.columnCount) {
  12282. tree.warn(
  12283. "Column count mismatch between thead (" +
  12284. tree.columnCount +
  12285. ") and tbody (" +
  12286. n +
  12287. "): using tbody."
  12288. );
  12289. tree.columnCount = n;
  12290. }
  12291. $row = $row.clone();
  12292. } else {
  12293. // Only thead is defined: create default row markup
  12294. _assert(
  12295. tree.columnCount >= 1,
  12296. "Need either <thead> or <tbody> with <td> elements to determine column count."
  12297. );
  12298. $row = $("<tr />");
  12299. for (i = 0; i < tree.columnCount; i++) {
  12300. $row.append("<td />");
  12301. }
  12302. }
  12303. $row.find(">td")
  12304. .eq(tableOpts.nodeColumnIdx)
  12305. .html("<span class='fancytree-node' />");
  12306. if (opts.aria) {
  12307. $row.attr("role", "row");
  12308. $row.find("td").attr("role", "gridcell");
  12309. }
  12310. tree.rowFragment = document.createDocumentFragment();
  12311. tree.rowFragment.appendChild($row.get(0));
  12312. // // If tbody contains a second row, use this as status node template
  12313. // $row = $tbody.children("tr").eq(1);
  12314. // if( $row.length === 0 ) {
  12315. // tree.statusRowFragment = tree.rowFragment;
  12316. // } else {
  12317. // $row = $row.clone();
  12318. // tree.statusRowFragment = document.createDocumentFragment();
  12319. // tree.statusRowFragment.appendChild($row.get(0));
  12320. // }
  12321. //
  12322. $tbody.empty();
  12323. // Make sure that status classes are set on the node's <tr> elements
  12324. tree.statusClassPropName = "tr";
  12325. tree.ariaPropName = "tr";
  12326. this.nodeContainerAttrName = "tr";
  12327. // #489: make sure $container is set to <table>, even if ext-dnd is listed before ext-table
  12328. tree.$container = $table;
  12329. this._superApply(arguments);
  12330. // standard Fancytree created a root UL
  12331. $(tree.rootNode.ul).remove();
  12332. tree.rootNode.ul = null;
  12333. // Add container to the TAB chain
  12334. // #577: Allow to set tabindex to "0", "-1" and ""
  12335. this.$container.attr("tabindex", opts.tabindex);
  12336. // this.$container.attr("tabindex", opts.tabbable ? "0" : "-1");
  12337. if (opts.aria) {
  12338. tree.$container
  12339. .attr("role", "treegrid")
  12340. .attr("aria-readonly", true);
  12341. }
  12342. },
  12343. nodeRemoveChildMarkup: function (ctx) {
  12344. var node = ctx.node;
  12345. // node.debug("nodeRemoveChildMarkup()");
  12346. node.visit(function (n) {
  12347. if (n.tr) {
  12348. $(n.tr).remove();
  12349. n.tr = null;
  12350. }
  12351. });
  12352. },
  12353. nodeRemoveMarkup: function (ctx) {
  12354. var node = ctx.node;
  12355. // node.debug("nodeRemoveMarkup()");
  12356. if (node.tr) {
  12357. $(node.tr).remove();
  12358. node.tr = null;
  12359. }
  12360. this.nodeRemoveChildMarkup(ctx);
  12361. },
  12362. /* Override standard render. */
  12363. nodeRender: function (ctx, force, deep, collapsed, _recursive) {
  12364. var children,
  12365. firstTr,
  12366. i,
  12367. l,
  12368. newRow,
  12369. prevNode,
  12370. prevTr,
  12371. subCtx,
  12372. tree = ctx.tree,
  12373. node = ctx.node,
  12374. opts = ctx.options,
  12375. isRootNode = !node.parent;
  12376. if (tree._enableUpdate === false) {
  12377. // $.ui.fancytree.debug("*** nodeRender _enableUpdate: false");
  12378. return;
  12379. }
  12380. if (!_recursive) {
  12381. ctx.hasCollapsedParents = node.parent && !node.parent.expanded;
  12382. }
  12383. // $.ui.fancytree.debug("*** nodeRender " + node + ", isRoot=" + isRootNode, "tr=" + node.tr, "hcp=" + ctx.hasCollapsedParents, "parent.tr=" + (node.parent && node.parent.tr));
  12384. if (!isRootNode) {
  12385. if (node.tr && force) {
  12386. this.nodeRemoveMarkup(ctx);
  12387. }
  12388. if (node.tr) {
  12389. if (force) {
  12390. // Set icon, link, and title (normally this is only required on initial render)
  12391. this.nodeRenderTitle(ctx); // triggers renderColumns()
  12392. } else {
  12393. // Update element classes according to node state
  12394. this.nodeRenderStatus(ctx);
  12395. }
  12396. } else {
  12397. if (ctx.hasCollapsedParents && !deep) {
  12398. // #166: we assume that the parent will be (recursively) rendered
  12399. // later anyway.
  12400. // node.debug("nodeRender ignored due to unrendered parent");
  12401. return;
  12402. }
  12403. // Create new <tr> after previous row
  12404. // if( node.isStatusNode() ) {
  12405. // newRow = tree.statusRowFragment.firstChild.cloneNode(true);
  12406. // } else {
  12407. newRow = tree.rowFragment.firstChild.cloneNode(true);
  12408. // }
  12409. prevNode = findPrevRowNode(node);
  12410. // $.ui.fancytree.debug("*** nodeRender " + node + ": prev: " + prevNode.key);
  12411. _assert(prevNode);
  12412. if (collapsed === true && _recursive) {
  12413. // hide all child rows, so we can use an animation to show it later
  12414. newRow.style.display = "none";
  12415. } else if (deep && ctx.hasCollapsedParents) {
  12416. // also hide this row if deep === true but any parent is collapsed
  12417. newRow.style.display = "none";
  12418. // newRow.style.color = "red";
  12419. }
  12420. if (prevNode.tr) {
  12421. insertSiblingAfter(prevNode.tr, newRow);
  12422. } else {
  12423. _assert(
  12424. !prevNode.parent,
  12425. "prev. row must have a tr, or be system root: " +
  12426. prevNode
  12427. );
  12428. // tree.tbody.appendChild(newRow);
  12429. insertFirstChild(tree.tbody, newRow); // #675
  12430. }
  12431. node.tr = newRow;
  12432. if (node.key && opts.generateIds) {
  12433. node.tr.id = opts.idPrefix + node.key;
  12434. }
  12435. node.tr.ftnode = node;
  12436. // if(opts.aria){
  12437. // $(node.tr).attr("aria-labelledby", "ftal_" + opts.idPrefix + node.key);
  12438. // }
  12439. node.span = $("span.fancytree-node", node.tr).get(0);
  12440. // Set icon, link, and title (normally this is only required on initial render)
  12441. this.nodeRenderTitle(ctx);
  12442. // Allow tweaking, binding, after node was created for the first time
  12443. // tree._triggerNodeEvent("createNode", ctx);
  12444. if (opts.createNode) {
  12445. opts.createNode.call(tree, { type: "createNode" }, ctx);
  12446. }
  12447. }
  12448. }
  12449. // Allow tweaking after node state was rendered
  12450. // tree._triggerNodeEvent("renderNode", ctx);
  12451. if (opts.renderNode) {
  12452. opts.renderNode.call(tree, { type: "renderNode" }, ctx);
  12453. }
  12454. // Visit child nodes
  12455. // Add child markup
  12456. children = node.children;
  12457. if (children && (isRootNode || deep || node.expanded)) {
  12458. for (i = 0, l = children.length; i < l; i++) {
  12459. subCtx = $.extend({}, ctx, { node: children[i] });
  12460. subCtx.hasCollapsedParents =
  12461. subCtx.hasCollapsedParents || !node.expanded;
  12462. this.nodeRender(subCtx, force, deep, collapsed, true);
  12463. }
  12464. }
  12465. // Make sure, that <tr> order matches node.children order.
  12466. if (children && !_recursive) {
  12467. // we only have to do it once, for the root branch
  12468. prevTr = node.tr || null;
  12469. firstTr = tree.tbody.firstChild;
  12470. // Iterate over all descendants
  12471. node.visit(function (n) {
  12472. if (n.tr) {
  12473. if (
  12474. !n.parent.expanded &&
  12475. n.tr.style.display !== "none"
  12476. ) {
  12477. // fix after a node was dropped over a collapsed
  12478. n.tr.style.display = "none";
  12479. setChildRowVisibility(n, false);
  12480. }
  12481. if (n.tr.previousSibling !== prevTr) {
  12482. node.debug("_fixOrder: mismatch at node: " + n);
  12483. var nextTr = prevTr ? prevTr.nextSibling : firstTr;
  12484. tree.tbody.insertBefore(n.tr, nextTr);
  12485. }
  12486. prevTr = n.tr;
  12487. }
  12488. });
  12489. }
  12490. // Update element classes according to node state
  12491. // if(!isRootNode){
  12492. // this.nodeRenderStatus(ctx);
  12493. // }
  12494. },
  12495. nodeRenderTitle: function (ctx, title) {
  12496. var $cb,
  12497. res,
  12498. tree = ctx.tree,
  12499. node = ctx.node,
  12500. opts = ctx.options,
  12501. isStatusNode = node.isStatusNode();
  12502. res = this._super(ctx, title);
  12503. if (node.isRootNode()) {
  12504. return res;
  12505. }
  12506. // Move checkbox to custom column
  12507. if (
  12508. opts.checkbox &&
  12509. !isStatusNode &&
  12510. opts.table.checkboxColumnIdx != null
  12511. ) {
  12512. $cb = $("span.fancytree-checkbox", node.span); //.detach();
  12513. $(node.tr)
  12514. .find("td")
  12515. .eq(+opts.table.checkboxColumnIdx)
  12516. .html($cb);
  12517. }
  12518. // Update element classes according to node state
  12519. this.nodeRenderStatus(ctx);
  12520. if (isStatusNode) {
  12521. if (opts.renderStatusColumns) {
  12522. // Let user code write column content
  12523. opts.renderStatusColumns.call(
  12524. tree,
  12525. { type: "renderStatusColumns" },
  12526. ctx
  12527. );
  12528. } else if (opts.table.mergeStatusColumns && node.isTopLevel()) {
  12529. $(node.tr)
  12530. .find(">td")
  12531. .eq(0)
  12532. .prop("colspan", tree.columnCount)
  12533. .text(node.title)
  12534. .addClass("fancytree-status-merged")
  12535. .nextAll()
  12536. .remove();
  12537. } // else: default rendering for status node: leave other cells empty
  12538. } else if (opts.renderColumns) {
  12539. opts.renderColumns.call(tree, { type: "renderColumns" }, ctx);
  12540. }
  12541. return res;
  12542. },
  12543. nodeRenderStatus: function (ctx) {
  12544. var indent,
  12545. node = ctx.node,
  12546. opts = ctx.options;
  12547. this._super(ctx);
  12548. $(node.tr).removeClass("fancytree-node");
  12549. // indent
  12550. indent = (node.getLevel() - 1) * opts.table.indentation;
  12551. if (opts.rtl) {
  12552. $(node.span).css({ paddingRight: indent + "px" });
  12553. } else {
  12554. $(node.span).css({ paddingLeft: indent + "px" });
  12555. }
  12556. },
  12557. /* Expand node, return Deferred.promise. */
  12558. nodeSetExpanded: function (ctx, flag, callOpts) {
  12559. // flag defaults to true
  12560. flag = flag !== false;
  12561. if ((ctx.node.expanded && flag) || (!ctx.node.expanded && !flag)) {
  12562. // Expanded state isn't changed - just call base implementation
  12563. return this._superApply(arguments);
  12564. }
  12565. var dfd = new $.Deferred(),
  12566. subOpts = $.extend({}, callOpts, {
  12567. noEvents: true,
  12568. noAnimation: true,
  12569. });
  12570. callOpts = callOpts || {};
  12571. function _afterExpand(ok, args) {
  12572. // ctx.tree.info("ok:" + ok, args);
  12573. if (ok) {
  12574. // #1108 minExpandLevel: 2 together with table extension does not work
  12575. // don't call when 'ok' is false:
  12576. setChildRowVisibility(ctx.node, flag);
  12577. if (
  12578. flag &&
  12579. ctx.options.autoScroll &&
  12580. !callOpts.noAnimation &&
  12581. ctx.node.hasChildren()
  12582. ) {
  12583. // Scroll down to last child, but keep current node visible
  12584. ctx.node
  12585. .getLastChild()
  12586. .scrollIntoView(true, { topNode: ctx.node })
  12587. .always(function () {
  12588. if (!callOpts.noEvents) {
  12589. ctx.tree._triggerNodeEvent(
  12590. flag ? "expand" : "collapse",
  12591. ctx
  12592. );
  12593. }
  12594. dfd.resolveWith(ctx.node);
  12595. });
  12596. } else {
  12597. if (!callOpts.noEvents) {
  12598. ctx.tree._triggerNodeEvent(
  12599. flag ? "expand" : "collapse",
  12600. ctx
  12601. );
  12602. }
  12603. dfd.resolveWith(ctx.node);
  12604. }
  12605. } else {
  12606. if (!callOpts.noEvents) {
  12607. ctx.tree._triggerNodeEvent(
  12608. flag ? "expand" : "collapse",
  12609. ctx
  12610. );
  12611. }
  12612. dfd.rejectWith(ctx.node);
  12613. }
  12614. }
  12615. // Call base-expand with disabled events and animation
  12616. this._super(ctx, flag, subOpts)
  12617. .done(function () {
  12618. _afterExpand(true, arguments);
  12619. })
  12620. .fail(function () {
  12621. _afterExpand(false, arguments);
  12622. });
  12623. return dfd.promise();
  12624. },
  12625. nodeSetStatus: function (ctx, status, message, details) {
  12626. if (status === "ok") {
  12627. var node = ctx.node,
  12628. firstChild = node.children ? node.children[0] : null;
  12629. if (firstChild && firstChild.isStatusNode()) {
  12630. $(firstChild.tr).remove();
  12631. }
  12632. }
  12633. return this._superApply(arguments);
  12634. },
  12635. treeClear: function (ctx) {
  12636. this.nodeRemoveChildMarkup(this._makeHookContext(this.rootNode));
  12637. return this._superApply(arguments);
  12638. },
  12639. treeDestroy: function (ctx) {
  12640. this.$container.find("tbody").empty();
  12641. if (this.$source) {
  12642. this.$source.removeClass("fancytree-helper-hidden");
  12643. }
  12644. return this._superApply(arguments);
  12645. },
  12646. /*,
  12647. treeSetFocus: function(ctx, flag) {
  12648. // alert("treeSetFocus" + ctx.tree.$container);
  12649. ctx.tree.$container.trigger("focus");
  12650. $.ui.fancytree.focusTree = ctx.tree;
  12651. }*/
  12652. });
  12653. // Value returned by `require('jquery.fancytree..')`
  12654. return $.ui.fancytree;
  12655. }); // End of closure
  12656. /*! Extension 'jquery.fancytree.themeroller.js' *//*!
  12657. * jquery.fancytree.themeroller.js
  12658. *
  12659. * Enable jQuery UI ThemeRoller styles.
  12660. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12661. *
  12662. * @see http://jqueryui.com/themeroller/
  12663. *
  12664. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  12665. *
  12666. * Released under the MIT license
  12667. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12668. *
  12669. * @version 2.38.5
  12670. * @date 2025-04-05T06:40:00Z
  12671. */
  12672. (function (factory) {
  12673. if (typeof define === "function" && define.amd) {
  12674. // AMD. Register as an anonymous module.
  12675. define(["jquery", "./jquery.fancytree"], factory);
  12676. } else if (typeof module === "object" && module.exports) {
  12677. // Node/CommonJS
  12678. require("./jquery.fancytree");
  12679. module.exports = factory(require("jquery"));
  12680. } else {
  12681. // Browser globals
  12682. factory(jQuery);
  12683. }
  12684. })(function ($) {
  12685. "use strict";
  12686. /*******************************************************************************
  12687. * Extension code
  12688. */
  12689. $.ui.fancytree.registerExtension({
  12690. name: "themeroller",
  12691. version: "2.38.5",
  12692. // Default options for this extension.
  12693. options: {
  12694. activeClass: "ui-state-active", // Class added to active node
  12695. // activeClass: "ui-state-highlight",
  12696. addClass: "ui-corner-all", // Class added to all nodes
  12697. focusClass: "ui-state-focus", // Class added to focused node
  12698. hoverClass: "ui-state-hover", // Class added to hovered node
  12699. selectedClass: "ui-state-highlight", // Class added to selected nodes
  12700. // selectedClass: "ui-state-active"
  12701. },
  12702. treeInit: function (ctx) {
  12703. var $el = ctx.widget.element,
  12704. opts = ctx.options.themeroller;
  12705. this._superApply(arguments);
  12706. if ($el[0].nodeName === "TABLE") {
  12707. $el.addClass("ui-widget ui-corner-all");
  12708. $el.find(">thead tr").addClass("ui-widget-header");
  12709. $el.find(">tbody").addClass("ui-widget-conent");
  12710. } else {
  12711. $el.addClass("ui-widget ui-widget-content ui-corner-all");
  12712. }
  12713. $el.on(
  12714. "mouseenter mouseleave",
  12715. ".fancytree-node",
  12716. function (event) {
  12717. var node = $.ui.fancytree.getNode(event.target),
  12718. flag = event.type === "mouseenter";
  12719. $(node.tr ? node.tr : node.span).toggleClass(
  12720. opts.hoverClass + " " + opts.addClass,
  12721. flag
  12722. );
  12723. }
  12724. );
  12725. },
  12726. treeDestroy: function (ctx) {
  12727. this._superApply(arguments);
  12728. ctx.widget.element.removeClass(
  12729. "ui-widget ui-widget-content ui-corner-all"
  12730. );
  12731. },
  12732. nodeRenderStatus: function (ctx) {
  12733. var classes = {},
  12734. node = ctx.node,
  12735. $el = $(node.tr ? node.tr : node.span),
  12736. opts = ctx.options.themeroller;
  12737. this._super(ctx);
  12738. /*
  12739. .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.
  12740. .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.
  12741. .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.
  12742. .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.
  12743. .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.
  12744. .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.
  12745. .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.
  12746. */
  12747. // Set ui-state-* class (handle the case that the same class is assigned
  12748. // to different states)
  12749. classes[opts.activeClass] = false;
  12750. classes[opts.focusClass] = false;
  12751. classes[opts.selectedClass] = false;
  12752. if (node.isActive()) {
  12753. classes[opts.activeClass] = true;
  12754. }
  12755. if (node.hasFocus()) {
  12756. classes[opts.focusClass] = true;
  12757. }
  12758. // activeClass takes precedence before selectedClass:
  12759. if (node.isSelected() && !node.isActive()) {
  12760. classes[opts.selectedClass] = true;
  12761. }
  12762. $el.toggleClass(opts.activeClass, classes[opts.activeClass]);
  12763. $el.toggleClass(opts.focusClass, classes[opts.focusClass]);
  12764. $el.toggleClass(opts.selectedClass, classes[opts.selectedClass]);
  12765. // Additional classes (e.g. 'ui-corner-all')
  12766. $el.addClass(opts.addClass);
  12767. },
  12768. });
  12769. // Value returned by `require('jquery.fancytree..')`
  12770. return $.ui.fancytree;
  12771. }); // End of closure
  12772. /*! Extension 'jquery.fancytree.wide.js' *//*!
  12773. * jquery.fancytree.wide.js
  12774. * Support for 100% wide selection bars.
  12775. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12776. *
  12777. * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
  12778. *
  12779. * Released under the MIT license
  12780. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12781. *
  12782. * @version 2.38.5
  12783. * @date 2025-04-05T06:40:00Z
  12784. */
  12785. (function (factory) {
  12786. if (typeof define === "function" && define.amd) {
  12787. // AMD. Register as an anonymous module.
  12788. define(["jquery", "./jquery.fancytree"], factory);
  12789. } else if (typeof module === "object" && module.exports) {
  12790. // Node/CommonJS
  12791. require("./jquery.fancytree");
  12792. module.exports = factory(require("jquery"));
  12793. } else {
  12794. // Browser globals
  12795. factory(jQuery);
  12796. }
  12797. })(function ($) {
  12798. "use strict";
  12799. var reNumUnit = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/; // split "1.5em" to ["1.5", "em"]
  12800. /*******************************************************************************
  12801. * Private functions and variables
  12802. */
  12803. // var _assert = $.ui.fancytree.assert;
  12804. /* Calculate inner width without scrollbar */
  12805. // function realInnerWidth($el) {
  12806. // // http://blog.jquery.com/2012/08/16/jquery-1-8-box-sizing-width-csswidth-and-outerwidth/
  12807. // // inst.contWidth = parseFloat(this.$container.css("width"), 10);
  12808. // // 'Client width without scrollbar' - 'padding'
  12809. // return $el[0].clientWidth - ($el.innerWidth() - parseFloat($el.css("width"), 10));
  12810. // }
  12811. /* Create a global embedded CSS style for the tree. */
  12812. function defineHeadStyleElement(id, cssText) {
  12813. id = "fancytree-style-" + id;
  12814. var $headStyle = $("#" + id);
  12815. if (!cssText) {
  12816. $headStyle.remove();
  12817. return null;
  12818. }
  12819. if (!$headStyle.length) {
  12820. $headStyle = $("<style />")
  12821. .attr("id", id)
  12822. .addClass("fancytree-style")
  12823. .prop("type", "text/css")
  12824. .appendTo("head");
  12825. }
  12826. try {
  12827. $headStyle.html(cssText);
  12828. } catch (e) {
  12829. // fix for IE 6-8
  12830. $headStyle[0].styleSheet.cssText = cssText;
  12831. }
  12832. return $headStyle;
  12833. }
  12834. /* Calculate the CSS rules that indent title spans. */
  12835. function renderLevelCss(
  12836. containerId,
  12837. depth,
  12838. levelOfs,
  12839. lineOfs,
  12840. labelOfs,
  12841. measureUnit
  12842. ) {
  12843. var i,
  12844. prefix = "#" + containerId + " span.fancytree-level-",
  12845. rules = [];
  12846. for (i = 0; i < depth; i++) {
  12847. rules.push(
  12848. prefix +
  12849. (i + 1) +
  12850. " span.fancytree-title { padding-left: " +
  12851. (i * levelOfs + lineOfs) +
  12852. measureUnit +
  12853. "; }"
  12854. );
  12855. }
  12856. // Some UI animations wrap the UL inside a DIV and set position:relative on both.
  12857. // This breaks the left:0 and padding-left:nn settings of the title
  12858. rules.push(
  12859. "#" +
  12860. containerId +
  12861. " div.ui-effects-wrapper ul li span.fancytree-title, " +
  12862. "#" +
  12863. containerId +
  12864. " li.fancytree-animating span.fancytree-title " + // #716
  12865. "{ padding-left: " +
  12866. labelOfs +
  12867. measureUnit +
  12868. "; position: static; width: auto; }"
  12869. );
  12870. return rules.join("\n");
  12871. }
  12872. // /**
  12873. // * [ext-wide] Recalculate the width of the selection bar after the tree container
  12874. // * was resized.<br>
  12875. // * May be called explicitly on container resize, since there is no resize event
  12876. // * for DIV tags.
  12877. // *
  12878. // * @alias Fancytree#wideUpdate
  12879. // * @requires jquery.fancytree.wide.js
  12880. // */
  12881. // $.ui.fancytree._FancytreeClass.prototype.wideUpdate = function(){
  12882. // var inst = this.ext.wide,
  12883. // prevCw = inst.contWidth,
  12884. // prevLo = inst.lineOfs;
  12885. // inst.contWidth = realInnerWidth(this.$container);
  12886. // // Each title is precceeded by 2 or 3 icons (16px + 3 margin)
  12887. // // + 1px title border and 3px title padding
  12888. // // TODO: use code from treeInit() below
  12889. // inst.lineOfs = (this.options.checkbox ? 3 : 2) * 19;
  12890. // if( prevCw !== inst.contWidth || prevLo !== inst.lineOfs ) {
  12891. // this.debug("wideUpdate: " + inst.contWidth);
  12892. // this.visit(function(node){
  12893. // node.tree._callHook("nodeRenderTitle", node);
  12894. // });
  12895. // }
  12896. // };
  12897. /*******************************************************************************
  12898. * Extension code
  12899. */
  12900. $.ui.fancytree.registerExtension({
  12901. name: "wide",
  12902. version: "2.38.5",
  12903. // Default options for this extension.
  12904. options: {
  12905. iconWidth: null, // Adjust this if @fancy-icon-width != "16px"
  12906. iconSpacing: null, // Adjust this if @fancy-icon-spacing != "3px"
  12907. labelSpacing: null, // Adjust this if padding between icon and label != "3px"
  12908. levelOfs: null, // Adjust this if ul padding != "16px"
  12909. },
  12910. treeCreate: function (ctx) {
  12911. this._superApply(arguments);
  12912. this.$container.addClass("fancytree-ext-wide");
  12913. var containerId,
  12914. cssText,
  12915. iconSpacingUnit,
  12916. labelSpacingUnit,
  12917. iconWidthUnit,
  12918. levelOfsUnit,
  12919. instOpts = ctx.options.wide,
  12920. // css sniffing
  12921. $dummyLI = $(
  12922. "<li id='fancytreeTemp'><span class='fancytree-node'><span class='fancytree-icon' /><span class='fancytree-title' /></span><ul />"
  12923. ).appendTo(ctx.tree.$container),
  12924. $dummyIcon = $dummyLI.find(".fancytree-icon"),
  12925. $dummyUL = $dummyLI.find("ul"),
  12926. // $dummyTitle = $dummyLI.find(".fancytree-title"),
  12927. iconSpacing =
  12928. instOpts.iconSpacing || $dummyIcon.css("margin-left"),
  12929. iconWidth = instOpts.iconWidth || $dummyIcon.css("width"),
  12930. labelSpacing = instOpts.labelSpacing || "3px",
  12931. levelOfs = instOpts.levelOfs || $dummyUL.css("padding-left");
  12932. $dummyLI.remove();
  12933. iconSpacingUnit = iconSpacing.match(reNumUnit)[2];
  12934. iconSpacing = parseFloat(iconSpacing, 10);
  12935. labelSpacingUnit = labelSpacing.match(reNumUnit)[2];
  12936. labelSpacing = parseFloat(labelSpacing, 10);
  12937. iconWidthUnit = iconWidth.match(reNumUnit)[2];
  12938. iconWidth = parseFloat(iconWidth, 10);
  12939. levelOfsUnit = levelOfs.match(reNumUnit)[2];
  12940. if (
  12941. iconSpacingUnit !== iconWidthUnit ||
  12942. levelOfsUnit !== iconWidthUnit ||
  12943. labelSpacingUnit !== iconWidthUnit
  12944. ) {
  12945. $.error(
  12946. "iconWidth, iconSpacing, and levelOfs must have the same css measure unit"
  12947. );
  12948. }
  12949. this._local.measureUnit = iconWidthUnit;
  12950. this._local.levelOfs = parseFloat(levelOfs);
  12951. this._local.lineOfs =
  12952. (1 +
  12953. (ctx.options.checkbox ? 1 : 0) +
  12954. (ctx.options.icon === false ? 0 : 1)) *
  12955. (iconWidth + iconSpacing) +
  12956. iconSpacing;
  12957. this._local.labelOfs = labelSpacing;
  12958. this._local.maxDepth = 10;
  12959. // Get/Set a unique Id on the container (if not already exists)
  12960. containerId = this.$container.uniqueId().attr("id");
  12961. // Generated css rules for some levels (extended on demand)
  12962. cssText = renderLevelCss(
  12963. containerId,
  12964. this._local.maxDepth,
  12965. this._local.levelOfs,
  12966. this._local.lineOfs,
  12967. this._local.labelOfs,
  12968. this._local.measureUnit
  12969. );
  12970. defineHeadStyleElement(containerId, cssText);
  12971. },
  12972. treeDestroy: function (ctx) {
  12973. // Remove generated css rules
  12974. defineHeadStyleElement(this.$container.attr("id"), null);
  12975. return this._superApply(arguments);
  12976. },
  12977. nodeRenderStatus: function (ctx) {
  12978. var containerId,
  12979. cssText,
  12980. res,
  12981. node = ctx.node,
  12982. level = node.getLevel();
  12983. res = this._super(ctx);
  12984. // Generate some more level-n rules if required
  12985. if (level > this._local.maxDepth) {
  12986. containerId = this.$container.attr("id");
  12987. this._local.maxDepth *= 2;
  12988. node.debug(
  12989. "Define global ext-wide css up to level " +
  12990. this._local.maxDepth
  12991. );
  12992. cssText = renderLevelCss(
  12993. containerId,
  12994. this._local.maxDepth,
  12995. this._local.levelOfs,
  12996. this._local.lineOfs,
  12997. this._local.labelSpacing,
  12998. this._local.measureUnit
  12999. );
  13000. defineHeadStyleElement(containerId, cssText);
  13001. }
  13002. // Add level-n class to apply indentation padding.
  13003. // (Setting element style would not work, since it cannot easily be
  13004. // overriden while animations run)
  13005. $(node.span).addClass("fancytree-level-" + level);
  13006. return res;
  13007. },
  13008. });
  13009. // Value returned by `require('jquery.fancytree..')`
  13010. return $.ui.fancytree;
  13011. }); // End of closure
  13012. // Value returned by `require('jquery.fancytree')`
  13013. return $.ui.fancytree;
  13014. })); // End of closure