jquery.fancytree-all-deps.js 392 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729
  1. /*! jQuery Fancytree Plugin - 2.38.0 - 2021-02-09T20:03:49Z
  2. * https://github.com/mar10/fancytree
  3. * Copyright (c) 2021 Martin Wendt; Licensed MIT
  4. */
  5. /*! jQuery UI - v1.12.1 - 2018-05-20
  6. * http://jqueryui.com
  7. * Includes: widget.js, position.js, keycode.js, scroll-parent.js, unique-id.js
  8. * Copyright jQuery Foundation and other contributors; Licensed MIT */
  9. /*
  10. NOTE: Original jQuery UI wrapper was replaced with a simple IIFE.
  11. See README-Fancytree.md
  12. */
  13. (function( $ ) {
  14. $.ui = $.ui || {};
  15. var version = $.ui.version = "1.12.1";
  16. /*!
  17. * jQuery UI Widget 1.12.1
  18. * http://jqueryui.com
  19. *
  20. * Copyright jQuery Foundation and other contributors
  21. * Released under the MIT license.
  22. * http://jquery.org/license
  23. */
  24. //>>label: Widget
  25. //>>group: Core
  26. //>>description: Provides a factory for creating stateful widgets with a common API.
  27. //>>docs: http://api.jqueryui.com/jQuery.widget/
  28. //>>demos: http://jqueryui.com/widget/
  29. var widgetUuid = 0;
  30. var widgetSlice = Array.prototype.slice;
  31. $.cleanData = ( function( orig ) {
  32. return function( elems ) {
  33. var events, elem, i;
  34. for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {
  35. try {
  36. // Only trigger remove when necessary to save time
  37. events = $._data( elem, "events" );
  38. if ( events && events.remove ) {
  39. $( elem ).triggerHandler( "remove" );
  40. }
  41. // Http://bugs.jquery.com/ticket/8235
  42. } catch ( e ) {}
  43. }
  44. orig( elems );
  45. };
  46. } )( $.cleanData );
  47. $.widget = function( name, base, prototype ) {
  48. var existingConstructor, constructor, basePrototype;
  49. // ProxiedPrototype allows the provided prototype to remain unmodified
  50. // so that it can be used as a mixin for multiple widgets (#8876)
  51. var proxiedPrototype = {};
  52. var namespace = name.split( "." )[ 0 ];
  53. name = name.split( "." )[ 1 ];
  54. var fullName = namespace + "-" + name;
  55. if ( !prototype ) {
  56. prototype = base;
  57. base = $.Widget;
  58. }
  59. if ( $.isArray( prototype ) ) {
  60. prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
  61. }
  62. // Create selector for plugin
  63. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  64. return !!$.data( elem, fullName );
  65. };
  66. $[ namespace ] = $[ namespace ] || {};
  67. existingConstructor = $[ namespace ][ name ];
  68. constructor = $[ namespace ][ name ] = function( options, element ) {
  69. // Allow instantiation without "new" keyword
  70. if ( !this._createWidget ) {
  71. return new constructor( options, element );
  72. }
  73. // Allow instantiation without initializing for simple inheritance
  74. // must use "new" keyword (the code above always passes args)
  75. if ( arguments.length ) {
  76. this._createWidget( options, element );
  77. }
  78. };
  79. // Extend with the existing constructor to carry over any static properties
  80. $.extend( constructor, existingConstructor, {
  81. version: prototype.version,
  82. // Copy the object used to create the prototype in case we need to
  83. // redefine the widget later
  84. _proto: $.extend( {}, prototype ),
  85. // Track widgets that inherit from this widget in case this widget is
  86. // redefined after a widget inherits from it
  87. _childConstructors: []
  88. } );
  89. basePrototype = new base();
  90. // We need to make the options hash a property directly on the new instance
  91. // otherwise we'll modify the options hash on the prototype that we're
  92. // inheriting from
  93. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  94. $.each( prototype, function( prop, value ) {
  95. if ( !$.isFunction( value ) ) {
  96. proxiedPrototype[ prop ] = value;
  97. return;
  98. }
  99. proxiedPrototype[ prop ] = ( function() {
  100. function _super() {
  101. return base.prototype[ prop ].apply( this, arguments );
  102. }
  103. function _superApply( args ) {
  104. return base.prototype[ prop ].apply( this, args );
  105. }
  106. return function() {
  107. var __super = this._super;
  108. var __superApply = this._superApply;
  109. var returnValue;
  110. this._super = _super;
  111. this._superApply = _superApply;
  112. returnValue = value.apply( this, arguments );
  113. this._super = __super;
  114. this._superApply = __superApply;
  115. return returnValue;
  116. };
  117. } )();
  118. } );
  119. constructor.prototype = $.widget.extend( basePrototype, {
  120. // TODO: remove support for widgetEventPrefix
  121. // always use the name + a colon as the prefix, e.g., draggable:start
  122. // don't prefix for widgets that aren't DOM-based
  123. widgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name
  124. }, proxiedPrototype, {
  125. constructor: constructor,
  126. namespace: namespace,
  127. widgetName: name,
  128. widgetFullName: fullName
  129. } );
  130. // If this widget is being redefined then we need to find all widgets that
  131. // are inheriting from it and redefine all of them so that they inherit from
  132. // the new version of this widget. We're essentially trying to replace one
  133. // level in the prototype chain.
  134. if ( existingConstructor ) {
  135. $.each( existingConstructor._childConstructors, function( i, child ) {
  136. var childPrototype = child.prototype;
  137. // Redefine the child widget using the same prototype that was
  138. // originally used, but inherit from the new version of the base
  139. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor,
  140. child._proto );
  141. } );
  142. // Remove the list of existing child constructors from the old constructor
  143. // so the old child constructors can be garbage collected
  144. delete existingConstructor._childConstructors;
  145. } else {
  146. base._childConstructors.push( constructor );
  147. }
  148. $.widget.bridge( name, constructor );
  149. return constructor;
  150. };
  151. $.widget.extend = function( target ) {
  152. var input = widgetSlice.call( arguments, 1 );
  153. var inputIndex = 0;
  154. var inputLength = input.length;
  155. var key;
  156. var value;
  157. for ( ; inputIndex < inputLength; inputIndex++ ) {
  158. for ( key in input[ inputIndex ] ) {
  159. value = input[ inputIndex ][ key ];
  160. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  161. // Clone objects
  162. if ( $.isPlainObject( value ) ) {
  163. target[ key ] = $.isPlainObject( target[ key ] ) ?
  164. $.widget.extend( {}, target[ key ], value ) :
  165. // Don't extend strings, arrays, etc. with objects
  166. $.widget.extend( {}, value );
  167. // Copy everything else by reference
  168. } else {
  169. target[ key ] = value;
  170. }
  171. }
  172. }
  173. }
  174. return target;
  175. };
  176. $.widget.bridge = function( name, object ) {
  177. var fullName = object.prototype.widgetFullName || name;
  178. $.fn[ name ] = function( options ) {
  179. var isMethodCall = typeof options === "string";
  180. var args = widgetSlice.call( arguments, 1 );
  181. var returnValue = this;
  182. if ( isMethodCall ) {
  183. // If this is an empty collection, we need to have the instance method
  184. // return undefined instead of the jQuery instance
  185. if ( !this.length && options === "instance" ) {
  186. returnValue = undefined;
  187. } else {
  188. this.each( function() {
  189. var methodValue;
  190. var instance = $.data( this, fullName );
  191. if ( options === "instance" ) {
  192. returnValue = instance;
  193. return false;
  194. }
  195. if ( !instance ) {
  196. return $.error( "cannot call methods on " + name +
  197. " prior to initialization; " +
  198. "attempted to call method '" + options + "'" );
  199. }
  200. if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
  201. return $.error( "no such method '" + options + "' for " + name +
  202. " widget instance" );
  203. }
  204. methodValue = instance[ options ].apply( instance, args );
  205. if ( methodValue !== instance && methodValue !== undefined ) {
  206. returnValue = methodValue && methodValue.jquery ?
  207. returnValue.pushStack( methodValue.get() ) :
  208. methodValue;
  209. return false;
  210. }
  211. } );
  212. }
  213. } else {
  214. // Allow multiple hashes to be passed on init
  215. if ( args.length ) {
  216. options = $.widget.extend.apply( null, [ options ].concat( args ) );
  217. }
  218. this.each( function() {
  219. var instance = $.data( this, fullName );
  220. if ( instance ) {
  221. instance.option( options || {} );
  222. if ( instance._init ) {
  223. instance._init();
  224. }
  225. } else {
  226. $.data( this, fullName, new object( options, this ) );
  227. }
  228. } );
  229. }
  230. return returnValue;
  231. };
  232. };
  233. $.Widget = function( /* options, element */ ) {};
  234. $.Widget._childConstructors = [];
  235. $.Widget.prototype = {
  236. widgetName: "widget",
  237. widgetEventPrefix: "",
  238. defaultElement: "<div>",
  239. options: {
  240. classes: {},
  241. disabled: false,
  242. // Callbacks
  243. create: null
  244. },
  245. _createWidget: function( options, element ) {
  246. element = $( element || this.defaultElement || this )[ 0 ];
  247. this.element = $( element );
  248. this.uuid = widgetUuid++;
  249. this.eventNamespace = "." + this.widgetName + this.uuid;
  250. this.bindings = $();
  251. this.hoverable = $();
  252. this.focusable = $();
  253. this.classesElementLookup = {};
  254. if ( element !== this ) {
  255. $.data( element, this.widgetFullName, this );
  256. this._on( true, this.element, {
  257. remove: function( event ) {
  258. if ( event.target === element ) {
  259. this.destroy();
  260. }
  261. }
  262. } );
  263. this.document = $( element.style ?
  264. // Element within the document
  265. element.ownerDocument :
  266. // Element is window or document
  267. element.document || element );
  268. this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );
  269. }
  270. this.options = $.widget.extend( {},
  271. this.options,
  272. this._getCreateOptions(),
  273. options );
  274. this._create();
  275. if ( this.options.disabled ) {
  276. this._setOptionDisabled( this.options.disabled );
  277. }
  278. this._trigger( "create", null, this._getCreateEventData() );
  279. this._init();
  280. },
  281. _getCreateOptions: function() {
  282. return {};
  283. },
  284. _getCreateEventData: $.noop,
  285. _create: $.noop,
  286. _init: $.noop,
  287. destroy: function() {
  288. var that = this;
  289. this._destroy();
  290. $.each( this.classesElementLookup, function( key, value ) {
  291. that._removeClass( value, key );
  292. } );
  293. // We can probably remove the unbind calls in 2.0
  294. // all event bindings should go through this._on()
  295. this.element
  296. .off( this.eventNamespace )
  297. .removeData( this.widgetFullName );
  298. this.widget()
  299. .off( this.eventNamespace )
  300. .removeAttr( "aria-disabled" );
  301. // Clean up events and states
  302. this.bindings.off( this.eventNamespace );
  303. },
  304. _destroy: $.noop,
  305. widget: function() {
  306. return this.element;
  307. },
  308. option: function( key, value ) {
  309. var options = key;
  310. var parts;
  311. var curOption;
  312. var i;
  313. if ( arguments.length === 0 ) {
  314. // Don't return a reference to the internal hash
  315. return $.widget.extend( {}, this.options );
  316. }
  317. if ( typeof key === "string" ) {
  318. // Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  319. options = {};
  320. parts = key.split( "." );
  321. key = parts.shift();
  322. if ( parts.length ) {
  323. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  324. for ( i = 0; i < parts.length - 1; i++ ) {
  325. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  326. curOption = curOption[ parts[ i ] ];
  327. }
  328. key = parts.pop();
  329. if ( arguments.length === 1 ) {
  330. return curOption[ key ] === undefined ? null : curOption[ key ];
  331. }
  332. curOption[ key ] = value;
  333. } else {
  334. if ( arguments.length === 1 ) {
  335. return this.options[ key ] === undefined ? null : this.options[ key ];
  336. }
  337. options[ key ] = value;
  338. }
  339. }
  340. this._setOptions( options );
  341. return this;
  342. },
  343. _setOptions: function( options ) {
  344. var key;
  345. for ( key in options ) {
  346. this._setOption( key, options[ key ] );
  347. }
  348. return this;
  349. },
  350. _setOption: function( key, value ) {
  351. if ( key === "classes" ) {
  352. this._setOptionClasses( value );
  353. }
  354. this.options[ key ] = value;
  355. if ( key === "disabled" ) {
  356. this._setOptionDisabled( value );
  357. }
  358. return this;
  359. },
  360. _setOptionClasses: function( value ) {
  361. var classKey, elements, currentElements;
  362. for ( classKey in value ) {
  363. currentElements = this.classesElementLookup[ classKey ];
  364. if ( value[ classKey ] === this.options.classes[ classKey ] ||
  365. !currentElements ||
  366. !currentElements.length ) {
  367. continue;
  368. }
  369. // We are doing this to create a new jQuery object because the _removeClass() call
  370. // on the next line is going to destroy the reference to the current elements being
  371. // tracked. We need to save a copy of this collection so that we can add the new classes
  372. // below.
  373. elements = $( currentElements.get() );
  374. this._removeClass( currentElements, classKey );
  375. // We don't use _addClass() here, because that uses this.options.classes
  376. // for generating the string of classes. We want to use the value passed in from
  377. // _setOption(), this is the new value of the classes option which was passed to
  378. // _setOption(). We pass this value directly to _classes().
  379. elements.addClass( this._classes( {
  380. element: elements,
  381. keys: classKey,
  382. classes: value,
  383. add: true
  384. } ) );
  385. }
  386. },
  387. _setOptionDisabled: function( value ) {
  388. this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
  389. // If the widget is becoming disabled, then nothing is interactive
  390. if ( value ) {
  391. this._removeClass( this.hoverable, null, "ui-state-hover" );
  392. this._removeClass( this.focusable, null, "ui-state-focus" );
  393. }
  394. },
  395. enable: function() {
  396. return this._setOptions( { disabled: false } );
  397. },
  398. disable: function() {
  399. return this._setOptions( { disabled: true } );
  400. },
  401. _classes: function( options ) {
  402. var full = [];
  403. var that = this;
  404. options = $.extend( {
  405. element: this.element,
  406. classes: this.options.classes || {}
  407. }, options );
  408. function processClassString( classes, checkOption ) {
  409. var current, i;
  410. for ( i = 0; i < classes.length; i++ ) {
  411. current = that.classesElementLookup[ classes[ i ] ] || $();
  412. if ( options.add ) {
  413. current = $( $.unique( current.get().concat( options.element.get() ) ) );
  414. } else {
  415. current = $( current.not( options.element ).get() );
  416. }
  417. that.classesElementLookup[ classes[ i ] ] = current;
  418. full.push( classes[ i ] );
  419. if ( checkOption && options.classes[ classes[ i ] ] ) {
  420. full.push( options.classes[ classes[ i ] ] );
  421. }
  422. }
  423. }
  424. this._on( options.element, {
  425. "remove": "_untrackClassesElement"
  426. } );
  427. if ( options.keys ) {
  428. processClassString( options.keys.match( /\S+/g ) || [], true );
  429. }
  430. if ( options.extra ) {
  431. processClassString( options.extra.match( /\S+/g ) || [] );
  432. }
  433. return full.join( " " );
  434. },
  435. _untrackClassesElement: function( event ) {
  436. var that = this;
  437. $.each( that.classesElementLookup, function( key, value ) {
  438. if ( $.inArray( event.target, value ) !== -1 ) {
  439. that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
  440. }
  441. } );
  442. },
  443. _removeClass: function( element, keys, extra ) {
  444. return this._toggleClass( element, keys, extra, false );
  445. },
  446. _addClass: function( element, keys, extra ) {
  447. return this._toggleClass( element, keys, extra, true );
  448. },
  449. _toggleClass: function( element, keys, extra, add ) {
  450. add = ( typeof add === "boolean" ) ? add : extra;
  451. var shift = ( typeof element === "string" || element === null ),
  452. options = {
  453. extra: shift ? keys : extra,
  454. keys: shift ? element : keys,
  455. element: shift ? this.element : element,
  456. add: add
  457. };
  458. options.element.toggleClass( this._classes( options ), add );
  459. return this;
  460. },
  461. _on: function( suppressDisabledCheck, element, handlers ) {
  462. var delegateElement;
  463. var instance = this;
  464. // No suppressDisabledCheck flag, shuffle arguments
  465. if ( typeof suppressDisabledCheck !== "boolean" ) {
  466. handlers = element;
  467. element = suppressDisabledCheck;
  468. suppressDisabledCheck = false;
  469. }
  470. // No element argument, shuffle and use this.element
  471. if ( !handlers ) {
  472. handlers = element;
  473. element = this.element;
  474. delegateElement = this.widget();
  475. } else {
  476. element = delegateElement = $( element );
  477. this.bindings = this.bindings.add( element );
  478. }
  479. $.each( handlers, function( event, handler ) {
  480. function handlerProxy() {
  481. // Allow widgets to customize the disabled handling
  482. // - disabled as an array instead of boolean
  483. // - disabled class as method for disabling individual parts
  484. if ( !suppressDisabledCheck &&
  485. ( instance.options.disabled === true ||
  486. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  487. return;
  488. }
  489. return ( typeof handler === "string" ? instance[ handler ] : handler )
  490. .apply( instance, arguments );
  491. }
  492. // Copy the guid so direct unbinding works
  493. if ( typeof handler !== "string" ) {
  494. handlerProxy.guid = handler.guid =
  495. handler.guid || handlerProxy.guid || $.guid++;
  496. }
  497. var match = event.match( /^([\w:-]*)\s*(.*)$/ );
  498. var eventName = match[ 1 ] + instance.eventNamespace;
  499. var selector = match[ 2 ];
  500. if ( selector ) {
  501. delegateElement.on( eventName, selector, handlerProxy );
  502. } else {
  503. element.on( eventName, handlerProxy );
  504. }
  505. } );
  506. },
  507. _off: function( element, eventName ) {
  508. eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
  509. this.eventNamespace;
  510. element.off( eventName ).off( eventName );
  511. // Clear the stack to avoid memory leaks (#10056)
  512. this.bindings = $( this.bindings.not( element ).get() );
  513. this.focusable = $( this.focusable.not( element ).get() );
  514. this.hoverable = $( this.hoverable.not( element ).get() );
  515. },
  516. _delay: function( handler, delay ) {
  517. function handlerProxy() {
  518. return ( typeof handler === "string" ? instance[ handler ] : handler )
  519. .apply( instance, arguments );
  520. }
  521. var instance = this;
  522. return setTimeout( handlerProxy, delay || 0 );
  523. },
  524. _hoverable: function( element ) {
  525. this.hoverable = this.hoverable.add( element );
  526. this._on( element, {
  527. mouseenter: function( event ) {
  528. this._addClass( $( event.currentTarget ), null, "ui-state-hover" );
  529. },
  530. mouseleave: function( event ) {
  531. this._removeClass( $( event.currentTarget ), null, "ui-state-hover" );
  532. }
  533. } );
  534. },
  535. _focusable: function( element ) {
  536. this.focusable = this.focusable.add( element );
  537. this._on( element, {
  538. focusin: function( event ) {
  539. this._addClass( $( event.currentTarget ), null, "ui-state-focus" );
  540. },
  541. focusout: function( event ) {
  542. this._removeClass( $( event.currentTarget ), null, "ui-state-focus" );
  543. }
  544. } );
  545. },
  546. _trigger: function( type, event, data ) {
  547. var prop, orig;
  548. var callback = this.options[ type ];
  549. data = data || {};
  550. event = $.Event( event );
  551. event.type = ( type === this.widgetEventPrefix ?
  552. type :
  553. this.widgetEventPrefix + type ).toLowerCase();
  554. // The original event may come from any element
  555. // so we need to reset the target on the new event
  556. event.target = this.element[ 0 ];
  557. // Copy original event properties over to the new event
  558. orig = event.originalEvent;
  559. if ( orig ) {
  560. for ( prop in orig ) {
  561. if ( !( prop in event ) ) {
  562. event[ prop ] = orig[ prop ];
  563. }
  564. }
  565. }
  566. this.element.trigger( event, data );
  567. return !( $.isFunction( callback ) &&
  568. callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
  569. event.isDefaultPrevented() );
  570. }
  571. };
  572. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  573. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  574. if ( typeof options === "string" ) {
  575. options = { effect: options };
  576. }
  577. var hasOptions;
  578. var effectName = !options ?
  579. method :
  580. options === true || typeof options === "number" ?
  581. defaultEffect :
  582. options.effect || defaultEffect;
  583. options = options || {};
  584. if ( typeof options === "number" ) {
  585. options = { duration: options };
  586. }
  587. hasOptions = !$.isEmptyObject( options );
  588. options.complete = callback;
  589. if ( options.delay ) {
  590. element.delay( options.delay );
  591. }
  592. if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
  593. element[ method ]( options );
  594. } else if ( effectName !== method && element[ effectName ] ) {
  595. element[ effectName ]( options.duration, options.easing, callback );
  596. } else {
  597. element.queue( function( next ) {
  598. $( this )[ method ]();
  599. if ( callback ) {
  600. callback.call( element[ 0 ] );
  601. }
  602. next();
  603. } );
  604. }
  605. };
  606. } );
  607. var widget = $.widget;
  608. /*!
  609. * jQuery UI Position 1.12.1
  610. * http://jqueryui.com
  611. *
  612. * Copyright jQuery Foundation and other contributors
  613. * Released under the MIT license.
  614. * http://jquery.org/license
  615. *
  616. * http://api.jqueryui.com/position/
  617. */
  618. //>>label: Position
  619. //>>group: Core
  620. //>>description: Positions elements relative to other elements.
  621. //>>docs: http://api.jqueryui.com/position/
  622. //>>demos: http://jqueryui.com/position/
  623. ( function() {
  624. var cachedScrollbarWidth,
  625. max = Math.max,
  626. abs = Math.abs,
  627. rhorizontal = /left|center|right/,
  628. rvertical = /top|center|bottom/,
  629. roffset = /[\+\-]\d+(\.[\d]+)?%?/,
  630. rposition = /^\w+/,
  631. rpercent = /%$/,
  632. _position = $.fn.position;
  633. function getOffsets( offsets, width, height ) {
  634. return [
  635. parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  636. parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  637. ];
  638. }
  639. function parseCss( element, property ) {
  640. return parseInt( $.css( element, property ), 10 ) || 0;
  641. }
  642. function getDimensions( elem ) {
  643. var raw = elem[ 0 ];
  644. if ( raw.nodeType === 9 ) {
  645. return {
  646. width: elem.width(),
  647. height: elem.height(),
  648. offset: { top: 0, left: 0 }
  649. };
  650. }
  651. if ( $.isWindow( raw ) ) {
  652. return {
  653. width: elem.width(),
  654. height: elem.height(),
  655. offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
  656. };
  657. }
  658. if ( raw.preventDefault ) {
  659. return {
  660. width: 0,
  661. height: 0,
  662. offset: { top: raw.pageY, left: raw.pageX }
  663. };
  664. }
  665. return {
  666. width: elem.outerWidth(),
  667. height: elem.outerHeight(),
  668. offset: elem.offset()
  669. };
  670. }
  671. $.position = {
  672. scrollbarWidth: function() {
  673. if ( cachedScrollbarWidth !== undefined ) {
  674. return cachedScrollbarWidth;
  675. }
  676. var w1, w2,
  677. div = $( "<div " +
  678. "style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'>" +
  679. "<div style='height:100px;width:auto;'></div></div>" ),
  680. innerDiv = div.children()[ 0 ];
  681. $( "body" ).append( div );
  682. w1 = innerDiv.offsetWidth;
  683. div.css( "overflow", "scroll" );
  684. w2 = innerDiv.offsetWidth;
  685. if ( w1 === w2 ) {
  686. w2 = div[ 0 ].clientWidth;
  687. }
  688. div.remove();
  689. return ( cachedScrollbarWidth = w1 - w2 );
  690. },
  691. getScrollInfo: function( within ) {
  692. var overflowX = within.isWindow || within.isDocument ? "" :
  693. within.element.css( "overflow-x" ),
  694. overflowY = within.isWindow || within.isDocument ? "" :
  695. within.element.css( "overflow-y" ),
  696. hasOverflowX = overflowX === "scroll" ||
  697. ( overflowX === "auto" && within.width < within.element[ 0 ].scrollWidth ),
  698. hasOverflowY = overflowY === "scroll" ||
  699. ( overflowY === "auto" && within.height < within.element[ 0 ].scrollHeight );
  700. return {
  701. width: hasOverflowY ? $.position.scrollbarWidth() : 0,
  702. height: hasOverflowX ? $.position.scrollbarWidth() : 0
  703. };
  704. },
  705. getWithinInfo: function( element ) {
  706. var withinElement = $( element || window ),
  707. isWindow = $.isWindow( withinElement[ 0 ] ),
  708. isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
  709. hasOffset = !isWindow && !isDocument;
  710. return {
  711. element: withinElement,
  712. isWindow: isWindow,
  713. isDocument: isDocument,
  714. offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
  715. scrollLeft: withinElement.scrollLeft(),
  716. scrollTop: withinElement.scrollTop(),
  717. width: withinElement.outerWidth(),
  718. height: withinElement.outerHeight()
  719. };
  720. }
  721. };
  722. $.fn.position = function( options ) {
  723. if ( !options || !options.of ) {
  724. return _position.apply( this, arguments );
  725. }
  726. // Make a copy, we don't want to modify arguments
  727. options = $.extend( {}, options );
  728. var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
  729. target = $( options.of ),
  730. within = $.position.getWithinInfo( options.within ),
  731. scrollInfo = $.position.getScrollInfo( within ),
  732. collision = ( options.collision || "flip" ).split( " " ),
  733. offsets = {};
  734. dimensions = getDimensions( target );
  735. if ( target[ 0 ].preventDefault ) {
  736. // Force left top to allow flipping
  737. options.at = "left top";
  738. }
  739. targetWidth = dimensions.width;
  740. targetHeight = dimensions.height;
  741. targetOffset = dimensions.offset;
  742. // Clone to reuse original targetOffset later
  743. basePosition = $.extend( {}, targetOffset );
  744. // Force my and at to have valid horizontal and vertical positions
  745. // if a value is missing or invalid, it will be converted to center
  746. $.each( [ "my", "at" ], function() {
  747. var pos = ( options[ this ] || "" ).split( " " ),
  748. horizontalOffset,
  749. verticalOffset;
  750. if ( pos.length === 1 ) {
  751. pos = rhorizontal.test( pos[ 0 ] ) ?
  752. pos.concat( [ "center" ] ) :
  753. rvertical.test( pos[ 0 ] ) ?
  754. [ "center" ].concat( pos ) :
  755. [ "center", "center" ];
  756. }
  757. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  758. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  759. // Calculate offsets
  760. horizontalOffset = roffset.exec( pos[ 0 ] );
  761. verticalOffset = roffset.exec( pos[ 1 ] );
  762. offsets[ this ] = [
  763. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  764. verticalOffset ? verticalOffset[ 0 ] : 0
  765. ];
  766. // Reduce to just the positions without the offsets
  767. options[ this ] = [
  768. rposition.exec( pos[ 0 ] )[ 0 ],
  769. rposition.exec( pos[ 1 ] )[ 0 ]
  770. ];
  771. } );
  772. // Normalize collision option
  773. if ( collision.length === 1 ) {
  774. collision[ 1 ] = collision[ 0 ];
  775. }
  776. if ( options.at[ 0 ] === "right" ) {
  777. basePosition.left += targetWidth;
  778. } else if ( options.at[ 0 ] === "center" ) {
  779. basePosition.left += targetWidth / 2;
  780. }
  781. if ( options.at[ 1 ] === "bottom" ) {
  782. basePosition.top += targetHeight;
  783. } else if ( options.at[ 1 ] === "center" ) {
  784. basePosition.top += targetHeight / 2;
  785. }
  786. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  787. basePosition.left += atOffset[ 0 ];
  788. basePosition.top += atOffset[ 1 ];
  789. return this.each( function() {
  790. var collisionPosition, using,
  791. elem = $( this ),
  792. elemWidth = elem.outerWidth(),
  793. elemHeight = elem.outerHeight(),
  794. marginLeft = parseCss( this, "marginLeft" ),
  795. marginTop = parseCss( this, "marginTop" ),
  796. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) +
  797. scrollInfo.width,
  798. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) +
  799. scrollInfo.height,
  800. position = $.extend( {}, basePosition ),
  801. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  802. if ( options.my[ 0 ] === "right" ) {
  803. position.left -= elemWidth;
  804. } else if ( options.my[ 0 ] === "center" ) {
  805. position.left -= elemWidth / 2;
  806. }
  807. if ( options.my[ 1 ] === "bottom" ) {
  808. position.top -= elemHeight;
  809. } else if ( options.my[ 1 ] === "center" ) {
  810. position.top -= elemHeight / 2;
  811. }
  812. position.left += myOffset[ 0 ];
  813. position.top += myOffset[ 1 ];
  814. collisionPosition = {
  815. marginLeft: marginLeft,
  816. marginTop: marginTop
  817. };
  818. $.each( [ "left", "top" ], function( i, dir ) {
  819. if ( $.ui.position[ collision[ i ] ] ) {
  820. $.ui.position[ collision[ i ] ][ dir ]( position, {
  821. targetWidth: targetWidth,
  822. targetHeight: targetHeight,
  823. elemWidth: elemWidth,
  824. elemHeight: elemHeight,
  825. collisionPosition: collisionPosition,
  826. collisionWidth: collisionWidth,
  827. collisionHeight: collisionHeight,
  828. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  829. my: options.my,
  830. at: options.at,
  831. within: within,
  832. elem: elem
  833. } );
  834. }
  835. } );
  836. if ( options.using ) {
  837. // Adds feedback as second argument to using callback, if present
  838. using = function( props ) {
  839. var left = targetOffset.left - position.left,
  840. right = left + targetWidth - elemWidth,
  841. top = targetOffset.top - position.top,
  842. bottom = top + targetHeight - elemHeight,
  843. feedback = {
  844. target: {
  845. element: target,
  846. left: targetOffset.left,
  847. top: targetOffset.top,
  848. width: targetWidth,
  849. height: targetHeight
  850. },
  851. element: {
  852. element: elem,
  853. left: position.left,
  854. top: position.top,
  855. width: elemWidth,
  856. height: elemHeight
  857. },
  858. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  859. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  860. };
  861. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  862. feedback.horizontal = "center";
  863. }
  864. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  865. feedback.vertical = "middle";
  866. }
  867. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  868. feedback.important = "horizontal";
  869. } else {
  870. feedback.important = "vertical";
  871. }
  872. options.using.call( this, props, feedback );
  873. };
  874. }
  875. elem.offset( $.extend( position, { using: using } ) );
  876. } );
  877. };
  878. $.ui.position = {
  879. fit: {
  880. left: function( position, data ) {
  881. var within = data.within,
  882. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  883. outerWidth = within.width,
  884. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  885. overLeft = withinOffset - collisionPosLeft,
  886. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  887. newOverRight;
  888. // Element is wider than within
  889. if ( data.collisionWidth > outerWidth ) {
  890. // Element is initially over the left side of within
  891. if ( overLeft > 0 && overRight <= 0 ) {
  892. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth -
  893. withinOffset;
  894. position.left += overLeft - newOverRight;
  895. // Element is initially over right side of within
  896. } else if ( overRight > 0 && overLeft <= 0 ) {
  897. position.left = withinOffset;
  898. // Element is initially over both left and right sides of within
  899. } else {
  900. if ( overLeft > overRight ) {
  901. position.left = withinOffset + outerWidth - data.collisionWidth;
  902. } else {
  903. position.left = withinOffset;
  904. }
  905. }
  906. // Too far left -> align with left edge
  907. } else if ( overLeft > 0 ) {
  908. position.left += overLeft;
  909. // Too far right -> align with right edge
  910. } else if ( overRight > 0 ) {
  911. position.left -= overRight;
  912. // Adjust based on position and margin
  913. } else {
  914. position.left = max( position.left - collisionPosLeft, position.left );
  915. }
  916. },
  917. top: function( position, data ) {
  918. var within = data.within,
  919. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  920. outerHeight = data.within.height,
  921. collisionPosTop = position.top - data.collisionPosition.marginTop,
  922. overTop = withinOffset - collisionPosTop,
  923. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  924. newOverBottom;
  925. // Element is taller than within
  926. if ( data.collisionHeight > outerHeight ) {
  927. // Element is initially over the top of within
  928. if ( overTop > 0 && overBottom <= 0 ) {
  929. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight -
  930. withinOffset;
  931. position.top += overTop - newOverBottom;
  932. // Element is initially over bottom of within
  933. } else if ( overBottom > 0 && overTop <= 0 ) {
  934. position.top = withinOffset;
  935. // Element is initially over both top and bottom of within
  936. } else {
  937. if ( overTop > overBottom ) {
  938. position.top = withinOffset + outerHeight - data.collisionHeight;
  939. } else {
  940. position.top = withinOffset;
  941. }
  942. }
  943. // Too far up -> align with top
  944. } else if ( overTop > 0 ) {
  945. position.top += overTop;
  946. // Too far down -> align with bottom edge
  947. } else if ( overBottom > 0 ) {
  948. position.top -= overBottom;
  949. // Adjust based on position and margin
  950. } else {
  951. position.top = max( position.top - collisionPosTop, position.top );
  952. }
  953. }
  954. },
  955. flip: {
  956. left: function( position, data ) {
  957. var within = data.within,
  958. withinOffset = within.offset.left + within.scrollLeft,
  959. outerWidth = within.width,
  960. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  961. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  962. overLeft = collisionPosLeft - offsetLeft,
  963. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  964. myOffset = data.my[ 0 ] === "left" ?
  965. -data.elemWidth :
  966. data.my[ 0 ] === "right" ?
  967. data.elemWidth :
  968. 0,
  969. atOffset = data.at[ 0 ] === "left" ?
  970. data.targetWidth :
  971. data.at[ 0 ] === "right" ?
  972. -data.targetWidth :
  973. 0,
  974. offset = -2 * data.offset[ 0 ],
  975. newOverRight,
  976. newOverLeft;
  977. if ( overLeft < 0 ) {
  978. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth -
  979. outerWidth - withinOffset;
  980. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  981. position.left += myOffset + atOffset + offset;
  982. }
  983. } else if ( overRight > 0 ) {
  984. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset +
  985. atOffset + offset - offsetLeft;
  986. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  987. position.left += myOffset + atOffset + offset;
  988. }
  989. }
  990. },
  991. top: function( position, data ) {
  992. var within = data.within,
  993. withinOffset = within.offset.top + within.scrollTop,
  994. outerHeight = within.height,
  995. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  996. collisionPosTop = position.top - data.collisionPosition.marginTop,
  997. overTop = collisionPosTop - offsetTop,
  998. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  999. top = data.my[ 1 ] === "top",
  1000. myOffset = top ?
  1001. -data.elemHeight :
  1002. data.my[ 1 ] === "bottom" ?
  1003. data.elemHeight :
  1004. 0,
  1005. atOffset = data.at[ 1 ] === "top" ?
  1006. data.targetHeight :
  1007. data.at[ 1 ] === "bottom" ?
  1008. -data.targetHeight :
  1009. 0,
  1010. offset = -2 * data.offset[ 1 ],
  1011. newOverTop,
  1012. newOverBottom;
  1013. if ( overTop < 0 ) {
  1014. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight -
  1015. outerHeight - withinOffset;
  1016. if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) {
  1017. position.top += myOffset + atOffset + offset;
  1018. }
  1019. } else if ( overBottom > 0 ) {
  1020. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset +
  1021. offset - offsetTop;
  1022. if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) {
  1023. position.top += myOffset + atOffset + offset;
  1024. }
  1025. }
  1026. }
  1027. },
  1028. flipfit: {
  1029. left: function() {
  1030. $.ui.position.flip.left.apply( this, arguments );
  1031. $.ui.position.fit.left.apply( this, arguments );
  1032. },
  1033. top: function() {
  1034. $.ui.position.flip.top.apply( this, arguments );
  1035. $.ui.position.fit.top.apply( this, arguments );
  1036. }
  1037. }
  1038. };
  1039. } )();
  1040. var position = $.ui.position;
  1041. /*!
  1042. * jQuery UI Keycode 1.12.1
  1043. * http://jqueryui.com
  1044. *
  1045. * Copyright jQuery Foundation and other contributors
  1046. * Released under the MIT license.
  1047. * http://jquery.org/license
  1048. */
  1049. //>>label: Keycode
  1050. //>>group: Core
  1051. //>>description: Provide keycodes as keynames
  1052. //>>docs: http://api.jqueryui.com/jQuery.ui.keyCode/
  1053. var keycode = $.ui.keyCode = {
  1054. BACKSPACE: 8,
  1055. COMMA: 188,
  1056. DELETE: 46,
  1057. DOWN: 40,
  1058. END: 35,
  1059. ENTER: 13,
  1060. ESCAPE: 27,
  1061. HOME: 36,
  1062. LEFT: 37,
  1063. PAGE_DOWN: 34,
  1064. PAGE_UP: 33,
  1065. PERIOD: 190,
  1066. RIGHT: 39,
  1067. SPACE: 32,
  1068. TAB: 9,
  1069. UP: 38
  1070. };
  1071. /*!
  1072. * jQuery UI Scroll Parent 1.12.1
  1073. * http://jqueryui.com
  1074. *
  1075. * Copyright jQuery Foundation and other contributors
  1076. * Released under the MIT license.
  1077. * http://jquery.org/license
  1078. */
  1079. //>>label: scrollParent
  1080. //>>group: Core
  1081. //>>description: Get the closest ancestor element that is scrollable.
  1082. //>>docs: http://api.jqueryui.com/scrollParent/
  1083. var scrollParent = $.fn.scrollParent = function( includeHidden ) {
  1084. var position = this.css( "position" ),
  1085. excludeStaticParent = position === "absolute",
  1086. overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,
  1087. scrollParent = this.parents().filter( function() {
  1088. var parent = $( this );
  1089. if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
  1090. return false;
  1091. }
  1092. return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) +
  1093. parent.css( "overflow-x" ) );
  1094. } ).eq( 0 );
  1095. return position === "fixed" || !scrollParent.length ?
  1096. $( this[ 0 ].ownerDocument || document ) :
  1097. scrollParent;
  1098. };
  1099. /*!
  1100. * jQuery UI Unique ID 1.12.1
  1101. * http://jqueryui.com
  1102. *
  1103. * Copyright jQuery Foundation and other contributors
  1104. * Released under the MIT license.
  1105. * http://jquery.org/license
  1106. */
  1107. //>>label: uniqueId
  1108. //>>group: Core
  1109. //>>description: Functions to generate and remove uniqueId's
  1110. //>>docs: http://api.jqueryui.com/uniqueId/
  1111. var uniqueId = $.fn.extend( {
  1112. uniqueId: ( function() {
  1113. var uuid = 0;
  1114. return function() {
  1115. return this.each( function() {
  1116. if ( !this.id ) {
  1117. this.id = "ui-id-" + ( ++uuid );
  1118. }
  1119. } );
  1120. };
  1121. } )(),
  1122. removeUniqueId: function() {
  1123. return this.each( function() {
  1124. if ( /^ui-id-\d+$/.test( this.id ) ) {
  1125. $( this ).removeAttr( "id" );
  1126. }
  1127. } );
  1128. }
  1129. } );
  1130. // NOTE: Original jQuery UI wrapper was replaced. See README-Fancytree.md
  1131. // }));
  1132. })(jQuery);
  1133. (function( factory ) {
  1134. if ( typeof define === "function" && define.amd ) {
  1135. // AMD. Register as an anonymous module.
  1136. define( [ "jquery" ], factory );
  1137. } else if ( typeof module === "object" && module.exports ) {
  1138. // Node/CommonJS
  1139. module.exports = factory(require("jquery"));
  1140. } else {
  1141. // Browser globals
  1142. factory( jQuery );
  1143. }
  1144. }(function( $ ) {
  1145. /*! Fancytree Core *//*!
  1146. * jquery.fancytree.js
  1147. * Tree view control with support for lazy loading and much more.
  1148. * https://github.com/mar10/fancytree/
  1149. *
  1150. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  1151. * Released under the MIT license
  1152. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  1153. *
  1154. * @version 2.38.0
  1155. * @date 2021-02-09T20:03:49Z
  1156. */
  1157. /** Core Fancytree module.
  1158. */
  1159. // UMD wrapper for the Fancytree core module
  1160. (function(factory) {
  1161. if (typeof define === "function" && define.amd) {
  1162. // AMD. Register as an anonymous module.
  1163. define(["jquery", "./jquery.fancytree.ui-deps"], factory);
  1164. } else if (typeof module === "object" && module.exports) {
  1165. // Node/CommonJS
  1166. require("./jquery.fancytree.ui-deps");
  1167. module.exports = factory(require("jquery"));
  1168. } else {
  1169. // Browser globals
  1170. factory(jQuery);
  1171. }
  1172. })(function($) {
  1173. "use strict";
  1174. // prevent duplicate loading
  1175. if ($.ui && $.ui.fancytree) {
  1176. $.ui.fancytree.warn("Fancytree: ignored duplicate include");
  1177. return;
  1178. }
  1179. /******************************************************************************
  1180. * Private functions and variables
  1181. */
  1182. var i,
  1183. attr,
  1184. FT = null, // initialized below
  1185. TEST_IMG = new RegExp(/\.|\//), // strings are considered image urls if they contain '.' or '/'
  1186. REX_HTML = /[&<>"'/]/g, // Escape those characters
  1187. REX_TOOLTIP = /[<>"'/]/g, // Don't escape `&` in tooltips
  1188. RECURSIVE_REQUEST_ERROR = "$recursive_request",
  1189. INVALID_REQUEST_TARGET_ERROR = "$request_target_invalid",
  1190. ENTITY_MAP = {
  1191. "&": "&amp;",
  1192. "<": "&lt;",
  1193. ">": "&gt;",
  1194. '"': "&quot;",
  1195. "'": "&#39;",
  1196. "/": "&#x2F;",
  1197. },
  1198. IGNORE_KEYCODES = { 16: true, 17: true, 18: true },
  1199. SPECIAL_KEYCODES = {
  1200. 8: "backspace",
  1201. 9: "tab",
  1202. 10: "return",
  1203. 13: "return",
  1204. // 16: null, 17: null, 18: null, // ignore shift, ctrl, alt
  1205. 19: "pause",
  1206. 20: "capslock",
  1207. 27: "esc",
  1208. 32: "space",
  1209. 33: "pageup",
  1210. 34: "pagedown",
  1211. 35: "end",
  1212. 36: "home",
  1213. 37: "left",
  1214. 38: "up",
  1215. 39: "right",
  1216. 40: "down",
  1217. 45: "insert",
  1218. 46: "del",
  1219. 59: ";",
  1220. 61: "=",
  1221. // 91: null, 93: null, // ignore left and right meta
  1222. 96: "0",
  1223. 97: "1",
  1224. 98: "2",
  1225. 99: "3",
  1226. 100: "4",
  1227. 101: "5",
  1228. 102: "6",
  1229. 103: "7",
  1230. 104: "8",
  1231. 105: "9",
  1232. 106: "*",
  1233. 107: "+",
  1234. 109: "-",
  1235. 110: ".",
  1236. 111: "/",
  1237. 112: "f1",
  1238. 113: "f2",
  1239. 114: "f3",
  1240. 115: "f4",
  1241. 116: "f5",
  1242. 117: "f6",
  1243. 118: "f7",
  1244. 119: "f8",
  1245. 120: "f9",
  1246. 121: "f10",
  1247. 122: "f11",
  1248. 123: "f12",
  1249. 144: "numlock",
  1250. 145: "scroll",
  1251. 173: "-",
  1252. 186: ";",
  1253. 187: "=",
  1254. 188: ",",
  1255. 189: "-",
  1256. 190: ".",
  1257. 191: "/",
  1258. 192: "`",
  1259. 219: "[",
  1260. 220: "\\",
  1261. 221: "]",
  1262. 222: "'",
  1263. },
  1264. MODIFIERS = {
  1265. 16: "shift",
  1266. 17: "ctrl",
  1267. 18: "alt",
  1268. 91: "meta",
  1269. 93: "meta",
  1270. },
  1271. MOUSE_BUTTONS = { 0: "", 1: "left", 2: "middle", 3: "right" },
  1272. // Boolean attributes that can be set with equivalent class names in the LI tags
  1273. // Note: v2.23: checkbox and hideCheckbox are *not* in this list
  1274. CLASS_ATTRS = "active expanded focus folder lazy radiogroup selected unselectable unselectableIgnore".split(
  1275. " "
  1276. ),
  1277. CLASS_ATTR_MAP = {},
  1278. // Top-level Fancytree attributes, that can be set by dict
  1279. TREE_ATTRS = "columns types".split(" "),
  1280. // TREE_ATTR_MAP = {},
  1281. // Top-level FancytreeNode attributes, that can be set by dict
  1282. NODE_ATTRS = "checkbox expanded extraClasses folder icon iconTooltip key lazy partsel radiogroup refKey selected statusNodeType title tooltip type unselectable unselectableIgnore unselectableStatus".split(
  1283. " "
  1284. ),
  1285. NODE_ATTR_MAP = {},
  1286. // Mapping of lowercase -> real name (because HTML5 data-... attribute only supports lowercase)
  1287. NODE_ATTR_LOWERCASE_MAP = {},
  1288. // Attribute names that should NOT be added to node.data
  1289. NONE_NODE_DATA_MAP = {
  1290. active: true,
  1291. children: true,
  1292. data: true,
  1293. focus: true,
  1294. };
  1295. for (i = 0; i < CLASS_ATTRS.length; i++) {
  1296. CLASS_ATTR_MAP[CLASS_ATTRS[i]] = true;
  1297. }
  1298. for (i = 0; i < NODE_ATTRS.length; i++) {
  1299. attr = NODE_ATTRS[i];
  1300. NODE_ATTR_MAP[attr] = true;
  1301. if (attr !== attr.toLowerCase()) {
  1302. NODE_ATTR_LOWERCASE_MAP[attr.toLowerCase()] = attr;
  1303. }
  1304. }
  1305. // for(i=0; i<TREE_ATTRS.length; i++) {
  1306. // TREE_ATTR_MAP[TREE_ATTRS[i]] = true;
  1307. // }
  1308. function _assert(cond, msg) {
  1309. // TODO: see qunit.js extractStacktrace()
  1310. if (!cond) {
  1311. msg = msg ? ": " + msg : "";
  1312. msg = "Fancytree assertion failed" + msg;
  1313. // consoleApply("assert", [!!cond, msg]);
  1314. // #1041: Raised exceptions may not be visible in the browser
  1315. // console if inside promise chains, so we also print directly:
  1316. $.ui.fancytree.error(msg);
  1317. // Throw exception:
  1318. $.error(msg);
  1319. }
  1320. }
  1321. _assert($.ui, "Fancytree requires jQuery UI (http://jqueryui.com)");
  1322. function consoleApply(method, args) {
  1323. var i,
  1324. s,
  1325. fn = window.console ? window.console[method] : null;
  1326. if (fn) {
  1327. try {
  1328. fn.apply(window.console, args);
  1329. } catch (e) {
  1330. // IE 8?
  1331. s = "";
  1332. for (i = 0; i < args.length; i++) {
  1333. s += args[i];
  1334. }
  1335. fn(s);
  1336. }
  1337. }
  1338. }
  1339. /* support: IE8 Polyfil for Date.now() */
  1340. if (!Date.now) {
  1341. Date.now = function now() {
  1342. return new Date().getTime();
  1343. };
  1344. }
  1345. /*Return true if x is a FancytreeNode.*/
  1346. function _isNode(x) {
  1347. return !!(x.tree && x.statusNodeType !== undefined);
  1348. }
  1349. /** Return true if dotted version string is equal or higher than requested version.
  1350. *
  1351. * See http://jsfiddle.net/mar10/FjSAN/
  1352. */
  1353. function isVersionAtLeast(dottedVersion, major, minor, patch) {
  1354. var i,
  1355. v,
  1356. t,
  1357. verParts = $.map($.trim(dottedVersion).split("."), function(e) {
  1358. return parseInt(e, 10);
  1359. }),
  1360. testParts = $.map(
  1361. Array.prototype.slice.call(arguments, 1),
  1362. function(e) {
  1363. return parseInt(e, 10);
  1364. }
  1365. );
  1366. for (i = 0; i < testParts.length; i++) {
  1367. v = verParts[i] || 0;
  1368. t = testParts[i] || 0;
  1369. if (v !== t) {
  1370. return v > t;
  1371. }
  1372. }
  1373. return true;
  1374. }
  1375. /**
  1376. * Deep-merge a list of objects (but replace array-type options).
  1377. *
  1378. * jQuery's $.extend(true, ...) method does a deep merge, that also merges Arrays.
  1379. * This variant is used to merge extension defaults with user options, and should
  1380. * merge objects, but override arrays (for example the `triggerStart: [...]` option
  1381. * of ext-edit). Also `null` values are copied over and not skipped.
  1382. *
  1383. * See issue #876
  1384. *
  1385. * Example:
  1386. * _simpleDeepMerge({}, o1, o2);
  1387. */
  1388. function _simpleDeepMerge() {
  1389. var options,
  1390. name,
  1391. src,
  1392. copy,
  1393. clone,
  1394. target = arguments[0] || {},
  1395. i = 1,
  1396. length = arguments.length;
  1397. // Handle case when target is a string or something (possible in deep copy)
  1398. if (typeof target !== "object" && !$.isFunction(target)) {
  1399. target = {};
  1400. }
  1401. if (i === length) {
  1402. throw Error("need at least two args");
  1403. }
  1404. for (; i < length; i++) {
  1405. // Only deal with non-null/undefined values
  1406. if ((options = arguments[i]) != null) {
  1407. // Extend the base object
  1408. for (name in options) {
  1409. if (options.hasOwnProperty(name)) {
  1410. src = target[name];
  1411. copy = options[name];
  1412. // Prevent never-ending loop
  1413. if (target === copy) {
  1414. continue;
  1415. }
  1416. // Recurse if we're merging plain objects
  1417. // (NOTE: unlike $.extend, we don't merge arrays, but replace them)
  1418. if (copy && $.isPlainObject(copy)) {
  1419. clone = src && $.isPlainObject(src) ? src : {};
  1420. // Never move original objects, clone them
  1421. target[name] = _simpleDeepMerge(clone, copy);
  1422. // Don't bring in undefined values
  1423. } else if (copy !== undefined) {
  1424. target[name] = copy;
  1425. }
  1426. }
  1427. }
  1428. }
  1429. }
  1430. // Return the modified object
  1431. return target;
  1432. }
  1433. /** Return a wrapper that calls sub.methodName() and exposes
  1434. * this : tree
  1435. * this._local : tree.ext.EXTNAME
  1436. * this._super : base.methodName.call()
  1437. * this._superApply : base.methodName.apply()
  1438. */
  1439. function _makeVirtualFunction(methodName, tree, base, extension, extName) {
  1440. // $.ui.fancytree.debug("_makeVirtualFunction", methodName, tree, base, extension, extName);
  1441. // if(rexTestSuper && !rexTestSuper.test(func)){
  1442. // // extension.methodName() doesn't call _super(), so no wrapper required
  1443. // return func;
  1444. // }
  1445. // Use an immediate function as closure
  1446. var proxy = (function() {
  1447. var prevFunc = tree[methodName], // org. tree method or prev. proxy
  1448. baseFunc = extension[methodName], //
  1449. _local = tree.ext[extName],
  1450. _super = function() {
  1451. return prevFunc.apply(tree, arguments);
  1452. },
  1453. _superApply = function(args) {
  1454. return prevFunc.apply(tree, args);
  1455. };
  1456. // Return the wrapper function
  1457. return function() {
  1458. var prevLocal = tree._local,
  1459. prevSuper = tree._super,
  1460. prevSuperApply = tree._superApply;
  1461. try {
  1462. tree._local = _local;
  1463. tree._super = _super;
  1464. tree._superApply = _superApply;
  1465. return baseFunc.apply(tree, arguments);
  1466. } finally {
  1467. tree._local = prevLocal;
  1468. tree._super = prevSuper;
  1469. tree._superApply = prevSuperApply;
  1470. }
  1471. };
  1472. })(); // end of Immediate Function
  1473. return proxy;
  1474. }
  1475. /**
  1476. * Subclass `base` by creating proxy functions
  1477. */
  1478. function _subclassObject(tree, base, extension, extName) {
  1479. // $.ui.fancytree.debug("_subclassObject", tree, base, extension, extName);
  1480. for (var attrName in extension) {
  1481. if (typeof extension[attrName] === "function") {
  1482. if (typeof tree[attrName] === "function") {
  1483. // override existing method
  1484. tree[attrName] = _makeVirtualFunction(
  1485. attrName,
  1486. tree,
  1487. base,
  1488. extension,
  1489. extName
  1490. );
  1491. } else if (attrName.charAt(0) === "_") {
  1492. // Create private methods in tree.ext.EXTENSION namespace
  1493. tree.ext[extName][attrName] = _makeVirtualFunction(
  1494. attrName,
  1495. tree,
  1496. base,
  1497. extension,
  1498. extName
  1499. );
  1500. } else {
  1501. $.error(
  1502. "Could not override tree." +
  1503. attrName +
  1504. ". Use prefix '_' to create tree." +
  1505. extName +
  1506. "._" +
  1507. attrName
  1508. );
  1509. }
  1510. } else {
  1511. // Create member variables in tree.ext.EXTENSION namespace
  1512. if (attrName !== "options") {
  1513. tree.ext[extName][attrName] = extension[attrName];
  1514. }
  1515. }
  1516. }
  1517. }
  1518. function _getResolvedPromise(context, argArray) {
  1519. if (context === undefined) {
  1520. return $.Deferred(function() {
  1521. this.resolve();
  1522. }).promise();
  1523. }
  1524. return $.Deferred(function() {
  1525. this.resolveWith(context, argArray);
  1526. }).promise();
  1527. }
  1528. function _getRejectedPromise(context, argArray) {
  1529. if (context === undefined) {
  1530. return $.Deferred(function() {
  1531. this.reject();
  1532. }).promise();
  1533. }
  1534. return $.Deferred(function() {
  1535. this.rejectWith(context, argArray);
  1536. }).promise();
  1537. }
  1538. function _makeResolveFunc(deferred, context) {
  1539. return function() {
  1540. deferred.resolveWith(context);
  1541. };
  1542. }
  1543. function _getElementDataAsDict($el) {
  1544. // Evaluate 'data-NAME' attributes with special treatment for 'data-json'.
  1545. var d = $.extend({}, $el.data()),
  1546. json = d.json;
  1547. delete d.fancytree; // added to container by widget factory (old jQuery UI)
  1548. delete d.uiFancytree; // added to container by widget factory
  1549. if (json) {
  1550. delete d.json;
  1551. // <li data-json='...'> is already returned as object (http://api.jquery.com/data/#data-html5)
  1552. d = $.extend(d, json);
  1553. }
  1554. return d;
  1555. }
  1556. function _escapeTooltip(s) {
  1557. return ("" + s).replace(REX_TOOLTIP, function(s) {
  1558. return ENTITY_MAP[s];
  1559. });
  1560. }
  1561. // TODO: use currying
  1562. function _makeNodeTitleMatcher(s) {
  1563. s = s.toLowerCase();
  1564. return function(node) {
  1565. return node.title.toLowerCase().indexOf(s) >= 0;
  1566. };
  1567. }
  1568. function _makeNodeTitleStartMatcher(s) {
  1569. var reMatch = new RegExp("^" + s, "i");
  1570. return function(node) {
  1571. return reMatch.test(node.title);
  1572. };
  1573. }
  1574. /******************************************************************************
  1575. * FancytreeNode
  1576. */
  1577. /**
  1578. * Creates a new FancytreeNode
  1579. *
  1580. * @class FancytreeNode
  1581. * @classdesc A FancytreeNode represents the hierarchical data model and operations.
  1582. *
  1583. * @param {FancytreeNode} parent
  1584. * @param {NodeData} obj
  1585. *
  1586. * @property {Fancytree} tree The tree instance
  1587. * @property {FancytreeNode} parent The parent node
  1588. * @property {string} key Node id (must be unique inside the tree)
  1589. * @property {string} title Display name (may contain HTML)
  1590. * @property {object} data Contains all extra data that was passed on node creation
  1591. * @property {FancytreeNode[] | null | undefined} children Array of child nodes.<br>
  1592. * For lazy nodes, null or undefined means 'not yet loaded'. Use an empty array
  1593. * to define a node that has no children.
  1594. * @property {boolean} expanded Use isExpanded(), setExpanded() to access this property.
  1595. * @property {string} extraClasses Additional CSS classes, added to the node's `<span>`.<br>
  1596. * Note: use `node.add/remove/toggleClass()` to modify.
  1597. * @property {boolean} folder Folder nodes have different default icons and click behavior.<br>
  1598. * Note: Also non-folders may have children.
  1599. * @property {string} statusNodeType null for standard nodes. Otherwise type of special system node: 'error', 'loading', 'nodata', or 'paging'.
  1600. * @property {boolean} lazy True if this node is loaded on demand, i.e. on first expansion.
  1601. * @property {boolean} selected Use isSelected(), setSelected() to access this property.
  1602. * @property {string} tooltip Alternative description used as hover popup
  1603. * @property {string} iconTooltip Description used as hover popup for icon. @since 2.27
  1604. * @property {string} type Node type, used with tree.types map. @since 2.27
  1605. */
  1606. function FancytreeNode(parent, obj) {
  1607. var i, l, name, cl;
  1608. this.parent = parent;
  1609. this.tree = parent.tree;
  1610. this.ul = null;
  1611. this.li = null; // <li id='key' ftnode=this> tag
  1612. this.statusNodeType = null; // if this is a temp. node to display the status of its parent
  1613. this._isLoading = false; // if this node itself is loading
  1614. this._error = null; // {message: '...'} if a load error occurred
  1615. this.data = {};
  1616. // TODO: merge this code with node.toDict()
  1617. // copy attributes from obj object
  1618. for (i = 0, l = NODE_ATTRS.length; i < l; i++) {
  1619. name = NODE_ATTRS[i];
  1620. this[name] = obj[name];
  1621. }
  1622. // unselectableIgnore and unselectableStatus imply unselectable
  1623. if (
  1624. this.unselectableIgnore != null ||
  1625. this.unselectableStatus != null
  1626. ) {
  1627. this.unselectable = true;
  1628. }
  1629. if (obj.hideCheckbox) {
  1630. $.error(
  1631. "'hideCheckbox' node option was removed in v2.23.0: use 'checkbox: false'"
  1632. );
  1633. }
  1634. // node.data += obj.data
  1635. if (obj.data) {
  1636. $.extend(this.data, obj.data);
  1637. }
  1638. // Copy all other attributes to this.data.NAME
  1639. for (name in obj) {
  1640. if (
  1641. !NODE_ATTR_MAP[name] &&
  1642. (this.tree.options.copyFunctionsToData ||
  1643. !$.isFunction(obj[name])) &&
  1644. !NONE_NODE_DATA_MAP[name]
  1645. ) {
  1646. // node.data.NAME = obj.NAME
  1647. this.data[name] = obj[name];
  1648. }
  1649. }
  1650. // Fix missing key
  1651. if (this.key == null) {
  1652. // test for null OR undefined
  1653. if (this.tree.options.defaultKey) {
  1654. this.key = "" + this.tree.options.defaultKey(this);
  1655. _assert(this.key, "defaultKey() must return a unique key");
  1656. } else {
  1657. this.key = "_" + FT._nextNodeKey++;
  1658. }
  1659. } else {
  1660. this.key = "" + this.key; // Convert to string (#217)
  1661. }
  1662. // Fix tree.activeNode
  1663. // TODO: not elegant: we use obj.active as marker to set tree.activeNode
  1664. // when loading from a dictionary.
  1665. if (obj.active) {
  1666. _assert(
  1667. this.tree.activeNode === null,
  1668. "only one active node allowed"
  1669. );
  1670. this.tree.activeNode = this;
  1671. }
  1672. if (obj.selected) {
  1673. // #186
  1674. this.tree.lastSelectedNode = this;
  1675. }
  1676. // TODO: handle obj.focus = true
  1677. // Create child nodes
  1678. cl = obj.children;
  1679. if (cl) {
  1680. if (cl.length) {
  1681. this._setChildren(cl);
  1682. } else {
  1683. // if an empty array was passed for a lazy node, keep it, in order to mark it 'loaded'
  1684. this.children = this.lazy ? [] : null;
  1685. }
  1686. } else {
  1687. this.children = null;
  1688. }
  1689. // Add to key/ref map (except for root node)
  1690. // if( parent ) {
  1691. this.tree._callHook("treeRegisterNode", this.tree, true, this);
  1692. // }
  1693. }
  1694. FancytreeNode.prototype = /** @lends FancytreeNode# */ {
  1695. /* Return the direct child FancytreeNode with a given key, index. */
  1696. _findDirectChild: function(ptr) {
  1697. var i,
  1698. l,
  1699. cl = this.children;
  1700. if (cl) {
  1701. if (typeof ptr === "string") {
  1702. for (i = 0, l = cl.length; i < l; i++) {
  1703. if (cl[i].key === ptr) {
  1704. return cl[i];
  1705. }
  1706. }
  1707. } else if (typeof ptr === "number") {
  1708. return this.children[ptr];
  1709. } else if (ptr.parent === this) {
  1710. return ptr;
  1711. }
  1712. }
  1713. return null;
  1714. },
  1715. // TODO: activate()
  1716. // TODO: activateSilently()
  1717. /* Internal helper called in recursive addChildren sequence.*/
  1718. _setChildren: function(children) {
  1719. _assert(
  1720. children && (!this.children || this.children.length === 0),
  1721. "only init supported"
  1722. );
  1723. this.children = [];
  1724. for (var i = 0, l = children.length; i < l; i++) {
  1725. this.children.push(new FancytreeNode(this, children[i]));
  1726. }
  1727. this.tree._callHook(
  1728. "treeStructureChanged",
  1729. this.tree,
  1730. "setChildren"
  1731. );
  1732. },
  1733. /**
  1734. * Append (or insert) a list of child nodes.
  1735. *
  1736. * @param {NodeData[]} children array of child node definitions (also single child accepted)
  1737. * @param {FancytreeNode | string | Integer} [insertBefore] child node (or key or index of such).
  1738. * If omitted, the new children are appended.
  1739. * @returns {FancytreeNode} first child added
  1740. *
  1741. * @see FancytreeNode#applyPatch
  1742. */
  1743. addChildren: function(children, insertBefore) {
  1744. var i,
  1745. l,
  1746. pos,
  1747. origFirstChild = this.getFirstChild(),
  1748. origLastChild = this.getLastChild(),
  1749. firstNode = null,
  1750. nodeList = [];
  1751. if ($.isPlainObject(children)) {
  1752. children = [children];
  1753. }
  1754. if (!this.children) {
  1755. this.children = [];
  1756. }
  1757. for (i = 0, l = children.length; i < l; i++) {
  1758. nodeList.push(new FancytreeNode(this, children[i]));
  1759. }
  1760. firstNode = nodeList[0];
  1761. if (insertBefore == null) {
  1762. this.children = this.children.concat(nodeList);
  1763. } else {
  1764. // Returns null if insertBefore is not a direct child:
  1765. insertBefore = this._findDirectChild(insertBefore);
  1766. pos = $.inArray(insertBefore, this.children);
  1767. _assert(pos >= 0, "insertBefore must be an existing child");
  1768. // insert nodeList after children[pos]
  1769. this.children.splice.apply(
  1770. this.children,
  1771. [pos, 0].concat(nodeList)
  1772. );
  1773. }
  1774. if (origFirstChild && !insertBefore) {
  1775. // #708: Fast path -- don't render every child of root, just the new ones!
  1776. // #723, #729: but only if it's appended to an existing child list
  1777. for (i = 0, l = nodeList.length; i < l; i++) {
  1778. nodeList[i].render(); // New nodes were never rendered before
  1779. }
  1780. // Adjust classes where status may have changed
  1781. // Has a first child
  1782. if (origFirstChild !== this.getFirstChild()) {
  1783. // Different first child -- recompute classes
  1784. origFirstChild.renderStatus();
  1785. }
  1786. if (origLastChild !== this.getLastChild()) {
  1787. // Different last child -- recompute classes
  1788. origLastChild.renderStatus();
  1789. }
  1790. } else if (!this.parent || this.parent.ul || this.tr) {
  1791. // render if the parent was rendered (or this is a root node)
  1792. this.render();
  1793. }
  1794. if (this.tree.options.selectMode === 3) {
  1795. this.fixSelection3FromEndNodes();
  1796. }
  1797. this.triggerModifyChild(
  1798. "add",
  1799. nodeList.length === 1 ? nodeList[0] : null
  1800. );
  1801. return firstNode;
  1802. },
  1803. /**
  1804. * Add class to node's span tag and to .extraClasses.
  1805. *
  1806. * @param {string} className class name
  1807. *
  1808. * @since 2.17
  1809. */
  1810. addClass: function(className) {
  1811. return this.toggleClass(className, true);
  1812. },
  1813. /**
  1814. * Append or prepend a node, or append a child node.
  1815. *
  1816. * This a convenience function that calls addChildren()
  1817. *
  1818. * @param {NodeData} node node definition
  1819. * @param {string} [mode=child] 'before', 'after', 'firstChild', or 'child' ('over' is a synonym for 'child')
  1820. * @returns {FancytreeNode} new node
  1821. */
  1822. addNode: function(node, mode) {
  1823. if (mode === undefined || mode === "over") {
  1824. mode = "child";
  1825. }
  1826. switch (mode) {
  1827. case "after":
  1828. return this.getParent().addChildren(
  1829. node,
  1830. this.getNextSibling()
  1831. );
  1832. case "before":
  1833. return this.getParent().addChildren(node, this);
  1834. case "firstChild":
  1835. // Insert before the first child if any
  1836. var insertBefore = this.children ? this.children[0] : null;
  1837. return this.addChildren(node, insertBefore);
  1838. case "child":
  1839. case "over":
  1840. return this.addChildren(node);
  1841. }
  1842. _assert(false, "Invalid mode: " + mode);
  1843. },
  1844. /**Add child status nodes that indicate 'More...', etc.
  1845. *
  1846. * This also maintains the node's `partload` property.
  1847. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  1848. * @param {string} [mode='child'] 'child'|firstChild'
  1849. * @since 2.15
  1850. */
  1851. addPagingNode: function(node, mode) {
  1852. var i, n;
  1853. mode = mode || "child";
  1854. if (node === false) {
  1855. for (i = this.children.length - 1; i >= 0; i--) {
  1856. n = this.children[i];
  1857. if (n.statusNodeType === "paging") {
  1858. this.removeChild(n);
  1859. }
  1860. }
  1861. this.partload = false;
  1862. return;
  1863. }
  1864. node = $.extend(
  1865. {
  1866. title: this.tree.options.strings.moreData,
  1867. statusNodeType: "paging",
  1868. icon: false,
  1869. },
  1870. node
  1871. );
  1872. this.partload = true;
  1873. return this.addNode(node, mode);
  1874. },
  1875. /**
  1876. * Append new node after this.
  1877. *
  1878. * This a convenience function that calls addNode(node, 'after')
  1879. *
  1880. * @param {NodeData} node node definition
  1881. * @returns {FancytreeNode} new node
  1882. */
  1883. appendSibling: function(node) {
  1884. return this.addNode(node, "after");
  1885. },
  1886. /**
  1887. * (experimental) Apply a modification (or navigation) operation.
  1888. *
  1889. * @param {string} cmd
  1890. * @param {object} [opts]
  1891. * @see Fancytree#applyCommand
  1892. * @since 2.32
  1893. */
  1894. applyCommand: function(cmd, opts) {
  1895. return this.tree.applyCommand(cmd, this, opts);
  1896. },
  1897. /**
  1898. * Modify existing child nodes.
  1899. *
  1900. * @param {NodePatch} patch
  1901. * @returns {$.Promise}
  1902. * @see FancytreeNode#addChildren
  1903. */
  1904. applyPatch: function(patch) {
  1905. // patch [key, null] means 'remove'
  1906. if (patch === null) {
  1907. this.remove();
  1908. return _getResolvedPromise(this);
  1909. }
  1910. // TODO: make sure that root node is not collapsed or modified
  1911. // copy (most) attributes to node.ATTR or node.data.ATTR
  1912. var name,
  1913. promise,
  1914. v,
  1915. IGNORE_MAP = { children: true, expanded: true, parent: true }; // TODO: should be global
  1916. for (name in patch) {
  1917. if (patch.hasOwnProperty(name)) {
  1918. v = patch[name];
  1919. if (!IGNORE_MAP[name] && !$.isFunction(v)) {
  1920. if (NODE_ATTR_MAP[name]) {
  1921. this[name] = v;
  1922. } else {
  1923. this.data[name] = v;
  1924. }
  1925. }
  1926. }
  1927. }
  1928. // Remove and/or create children
  1929. if (patch.hasOwnProperty("children")) {
  1930. this.removeChildren();
  1931. if (patch.children) {
  1932. // only if not null and not empty list
  1933. // TODO: addChildren instead?
  1934. this._setChildren(patch.children);
  1935. }
  1936. // TODO: how can we APPEND or INSERT child nodes?
  1937. }
  1938. if (this.isVisible()) {
  1939. this.renderTitle();
  1940. this.renderStatus();
  1941. }
  1942. // Expand collapse (final step, since this may be async)
  1943. if (patch.hasOwnProperty("expanded")) {
  1944. promise = this.setExpanded(patch.expanded);
  1945. } else {
  1946. promise = _getResolvedPromise(this);
  1947. }
  1948. return promise;
  1949. },
  1950. /** Collapse all sibling nodes.
  1951. * @returns {$.Promise}
  1952. */
  1953. collapseSiblings: function() {
  1954. return this.tree._callHook("nodeCollapseSiblings", this);
  1955. },
  1956. /** Copy this node as sibling or child of `node`.
  1957. *
  1958. * @param {FancytreeNode} node source node
  1959. * @param {string} [mode=child] 'before' | 'after' | 'child'
  1960. * @param {Function} [map] callback function(NodeData, FancytreeNode) that could modify the new node
  1961. * @returns {FancytreeNode} new
  1962. */
  1963. copyTo: function(node, mode, map) {
  1964. return node.addNode(this.toDict(true, map), mode);
  1965. },
  1966. /** Count direct and indirect children.
  1967. *
  1968. * @param {boolean} [deep=true] pass 'false' to only count direct children
  1969. * @returns {int} number of child nodes
  1970. */
  1971. countChildren: function(deep) {
  1972. var cl = this.children,
  1973. i,
  1974. l,
  1975. n;
  1976. if (!cl) {
  1977. return 0;
  1978. }
  1979. n = cl.length;
  1980. if (deep !== false) {
  1981. for (i = 0, l = n; i < l; i++) {
  1982. n += cl[i].countChildren();
  1983. }
  1984. }
  1985. return n;
  1986. },
  1987. // TODO: deactivate()
  1988. /** Write to browser console if debugLevel >= 4 (prepending node info)
  1989. *
  1990. * @param {*} msg string or object or array of such
  1991. */
  1992. debug: function(msg) {
  1993. if (this.tree.options.debugLevel >= 4) {
  1994. Array.prototype.unshift.call(arguments, this.toString());
  1995. consoleApply("log", arguments);
  1996. }
  1997. },
  1998. /** Deprecated.
  1999. * @deprecated since 2014-02-16. Use resetLazy() instead.
  2000. */
  2001. discard: function() {
  2002. this.warn(
  2003. "FancytreeNode.discard() is deprecated since 2014-02-16. Use .resetLazy() instead."
  2004. );
  2005. return this.resetLazy();
  2006. },
  2007. /** Remove DOM elements for all descendents. May be called on .collapse event
  2008. * to keep the DOM small.
  2009. * @param {boolean} [includeSelf=false]
  2010. */
  2011. discardMarkup: function(includeSelf) {
  2012. var fn = includeSelf ? "nodeRemoveMarkup" : "nodeRemoveChildMarkup";
  2013. this.tree._callHook(fn, this);
  2014. },
  2015. /** Write error to browser console if debugLevel >= 1 (prepending tree info)
  2016. *
  2017. * @param {*} msg string or object or array of such
  2018. */
  2019. error: function(msg) {
  2020. if (this.tree.options.debugLevel >= 1) {
  2021. Array.prototype.unshift.call(arguments, this.toString());
  2022. consoleApply("error", arguments);
  2023. }
  2024. },
  2025. /**Find all nodes that match condition (excluding self).
  2026. *
  2027. * @param {string | function(node)} match title string to search for, or a
  2028. * callback function that returns `true` if a node is matched.
  2029. * @returns {FancytreeNode[]} array of nodes (may be empty)
  2030. */
  2031. findAll: function(match) {
  2032. match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
  2033. var res = [];
  2034. this.visit(function(n) {
  2035. if (match(n)) {
  2036. res.push(n);
  2037. }
  2038. });
  2039. return res;
  2040. },
  2041. /**Find first node that matches condition (excluding self).
  2042. *
  2043. * @param {string | function(node)} match title string to search for, or a
  2044. * callback function that returns `true` if a node is matched.
  2045. * @returns {FancytreeNode} matching node or null
  2046. * @see FancytreeNode#findAll
  2047. */
  2048. findFirst: function(match) {
  2049. match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
  2050. var res = null;
  2051. this.visit(function(n) {
  2052. if (match(n)) {
  2053. res = n;
  2054. return false;
  2055. }
  2056. });
  2057. return res;
  2058. },
  2059. /** Find a node relative to self.
  2060. *
  2061. * @param {number|string} where The keyCode that would normally trigger this move,
  2062. * or a keyword ('down', 'first', 'last', 'left', 'parent', 'right', 'up').
  2063. * @returns {FancytreeNode}
  2064. * @since v2.31
  2065. */
  2066. findRelatedNode: function(where, includeHidden) {
  2067. return this.tree.findRelatedNode(this, where, includeHidden);
  2068. },
  2069. /* Apply selection state (internal use only) */
  2070. _changeSelectStatusAttrs: function(state) {
  2071. var changed = false,
  2072. opts = this.tree.options,
  2073. unselectable = FT.evalOption(
  2074. "unselectable",
  2075. this,
  2076. this,
  2077. opts,
  2078. false
  2079. ),
  2080. unselectableStatus = FT.evalOption(
  2081. "unselectableStatus",
  2082. this,
  2083. this,
  2084. opts,
  2085. undefined
  2086. );
  2087. if (unselectable && unselectableStatus != null) {
  2088. state = unselectableStatus;
  2089. }
  2090. switch (state) {
  2091. case false:
  2092. changed = this.selected || this.partsel;
  2093. this.selected = false;
  2094. this.partsel = false;
  2095. break;
  2096. case true:
  2097. changed = !this.selected || !this.partsel;
  2098. this.selected = true;
  2099. this.partsel = true;
  2100. break;
  2101. case undefined:
  2102. changed = this.selected || !this.partsel;
  2103. this.selected = false;
  2104. this.partsel = true;
  2105. break;
  2106. default:
  2107. _assert(false, "invalid state: " + state);
  2108. }
  2109. // this.debug("fixSelection3AfterLoad() _changeSelectStatusAttrs()", state, changed);
  2110. if (changed) {
  2111. this.renderStatus();
  2112. }
  2113. return changed;
  2114. },
  2115. /**
  2116. * Fix selection status, after this node was (de)selected in multi-hier mode.
  2117. * This includes (de)selecting all children.
  2118. */
  2119. fixSelection3AfterClick: function(callOpts) {
  2120. var flag = this.isSelected();
  2121. // this.debug("fixSelection3AfterClick()");
  2122. this.visit(function(node) {
  2123. node._changeSelectStatusAttrs(flag);
  2124. if (node.radiogroup) {
  2125. // #931: don't (de)select this branch
  2126. return "skip";
  2127. }
  2128. });
  2129. this.fixSelection3FromEndNodes(callOpts);
  2130. },
  2131. /**
  2132. * Fix selection status for multi-hier mode.
  2133. * Only end-nodes are considered to update the descendants branch and parents.
  2134. * Should be called after this node has loaded new children or after
  2135. * children have been modified using the API.
  2136. */
  2137. fixSelection3FromEndNodes: function(callOpts) {
  2138. var opts = this.tree.options;
  2139. // this.debug("fixSelection3FromEndNodes()");
  2140. _assert(opts.selectMode === 3, "expected selectMode 3");
  2141. // Visit all end nodes and adjust their parent's `selected` and `partsel`
  2142. // attributes. Return selection state true, false, or undefined.
  2143. function _walk(node) {
  2144. var i,
  2145. l,
  2146. child,
  2147. s,
  2148. state,
  2149. allSelected,
  2150. someSelected,
  2151. unselIgnore,
  2152. unselState,
  2153. children = node.children;
  2154. if (children && children.length) {
  2155. // check all children recursively
  2156. allSelected = true;
  2157. someSelected = false;
  2158. for (i = 0, l = children.length; i < l; i++) {
  2159. child = children[i];
  2160. // the selection state of a node is not relevant; we need the end-nodes
  2161. s = _walk(child);
  2162. // if( !child.unselectableIgnore ) {
  2163. unselIgnore = FT.evalOption(
  2164. "unselectableIgnore",
  2165. child,
  2166. child,
  2167. opts,
  2168. false
  2169. );
  2170. if (!unselIgnore) {
  2171. if (s !== false) {
  2172. someSelected = true;
  2173. }
  2174. if (s !== true) {
  2175. allSelected = false;
  2176. }
  2177. }
  2178. }
  2179. // eslint-disable-next-line no-nested-ternary
  2180. state = allSelected
  2181. ? true
  2182. : someSelected
  2183. ? undefined
  2184. : false;
  2185. } else {
  2186. // This is an end-node: simply report the status
  2187. unselState = FT.evalOption(
  2188. "unselectableStatus",
  2189. node,
  2190. node,
  2191. opts,
  2192. undefined
  2193. );
  2194. state = unselState == null ? !!node.selected : !!unselState;
  2195. }
  2196. // #939: Keep a `partsel` flag that was explicitly set on a lazy node
  2197. if (
  2198. node.partsel &&
  2199. !node.selected &&
  2200. node.lazy &&
  2201. node.children == null
  2202. ) {
  2203. state = undefined;
  2204. }
  2205. node._changeSelectStatusAttrs(state);
  2206. return state;
  2207. }
  2208. _walk(this);
  2209. // Update parent's state
  2210. this.visitParents(function(node) {
  2211. var i,
  2212. l,
  2213. child,
  2214. state,
  2215. unselIgnore,
  2216. unselState,
  2217. children = node.children,
  2218. allSelected = true,
  2219. someSelected = false;
  2220. for (i = 0, l = children.length; i < l; i++) {
  2221. child = children[i];
  2222. unselIgnore = FT.evalOption(
  2223. "unselectableIgnore",
  2224. child,
  2225. child,
  2226. opts,
  2227. false
  2228. );
  2229. if (!unselIgnore) {
  2230. unselState = FT.evalOption(
  2231. "unselectableStatus",
  2232. child,
  2233. child,
  2234. opts,
  2235. undefined
  2236. );
  2237. state =
  2238. unselState == null
  2239. ? !!child.selected
  2240. : !!unselState;
  2241. // When fixing the parents, we trust the sibling status (i.e.
  2242. // we don't recurse)
  2243. if (state || child.partsel) {
  2244. someSelected = true;
  2245. }
  2246. if (!state) {
  2247. allSelected = false;
  2248. }
  2249. }
  2250. }
  2251. // eslint-disable-next-line no-nested-ternary
  2252. state = allSelected ? true : someSelected ? undefined : false;
  2253. node._changeSelectStatusAttrs(state);
  2254. });
  2255. },
  2256. // TODO: focus()
  2257. /**
  2258. * Update node data. If dict contains 'children', then also replace
  2259. * the hole sub tree.
  2260. * @param {NodeData} dict
  2261. *
  2262. * @see FancytreeNode#addChildren
  2263. * @see FancytreeNode#applyPatch
  2264. */
  2265. fromDict: function(dict) {
  2266. // copy all other attributes to this.data.xxx
  2267. for (var name in dict) {
  2268. if (NODE_ATTR_MAP[name]) {
  2269. // node.NAME = dict.NAME
  2270. this[name] = dict[name];
  2271. } else if (name === "data") {
  2272. // node.data += dict.data
  2273. $.extend(this.data, dict.data);
  2274. } else if (
  2275. !$.isFunction(dict[name]) &&
  2276. !NONE_NODE_DATA_MAP[name]
  2277. ) {
  2278. // node.data.NAME = dict.NAME
  2279. this.data[name] = dict[name];
  2280. }
  2281. }
  2282. if (dict.children) {
  2283. // recursively set children and render
  2284. this.removeChildren();
  2285. this.addChildren(dict.children);
  2286. }
  2287. this.renderTitle();
  2288. /*
  2289. var children = dict.children;
  2290. if(children === undefined){
  2291. this.data = $.extend(this.data, dict);
  2292. this.render();
  2293. return;
  2294. }
  2295. dict = $.extend({}, dict);
  2296. dict.children = undefined;
  2297. this.data = $.extend(this.data, dict);
  2298. this.removeChildren();
  2299. this.addChild(children);
  2300. */
  2301. },
  2302. /** Return the list of child nodes (undefined for unexpanded lazy nodes).
  2303. * @returns {FancytreeNode[] | undefined}
  2304. */
  2305. getChildren: function() {
  2306. if (this.hasChildren() === undefined) {
  2307. // TODO: only required for lazy nodes?
  2308. return undefined; // Lazy node: unloaded, currently loading, or load error
  2309. }
  2310. return this.children;
  2311. },
  2312. /** Return the first child node or null.
  2313. * @returns {FancytreeNode | null}
  2314. */
  2315. getFirstChild: function() {
  2316. return this.children ? this.children[0] : null;
  2317. },
  2318. /** Return the 0-based child index.
  2319. * @returns {int}
  2320. */
  2321. getIndex: function() {
  2322. // return this.parent.children.indexOf(this);
  2323. return $.inArray(this, this.parent.children); // indexOf doesn't work in IE7
  2324. },
  2325. /** Return the hierarchical child index (1-based, e.g. '3.2.4').
  2326. * @param {string} [separator="."]
  2327. * @param {int} [digits=1]
  2328. * @returns {string}
  2329. */
  2330. getIndexHier: function(separator, digits) {
  2331. separator = separator || ".";
  2332. var s,
  2333. res = [];
  2334. $.each(this.getParentList(false, true), function(i, o) {
  2335. s = "" + (o.getIndex() + 1);
  2336. if (digits) {
  2337. // prepend leading zeroes
  2338. s = ("0000000" + s).substr(-digits);
  2339. }
  2340. res.push(s);
  2341. });
  2342. return res.join(separator);
  2343. },
  2344. /** Return the parent keys separated by options.keyPathSeparator, e.g. "/id_1/id_17/id_32".
  2345. *
  2346. * (Unlike `node.getPath()`, this method prepends a "/" and inverts the first argument.)
  2347. *
  2348. * @see FancytreeNode#getPath
  2349. * @param {boolean} [excludeSelf=false]
  2350. * @returns {string}
  2351. */
  2352. getKeyPath: function(excludeSelf) {
  2353. var sep = this.tree.options.keyPathSeparator;
  2354. return sep + this.getPath(!excludeSelf, "key", sep);
  2355. },
  2356. /** Return the last child of this node or null.
  2357. * @returns {FancytreeNode | null}
  2358. */
  2359. getLastChild: function() {
  2360. return this.children
  2361. ? this.children[this.children.length - 1]
  2362. : null;
  2363. },
  2364. /** Return node depth. 0: System root node, 1: visible top-level node, 2: first sub-level, ... .
  2365. * @returns {int}
  2366. */
  2367. getLevel: function() {
  2368. var level = 0,
  2369. dtn = this.parent;
  2370. while (dtn) {
  2371. level++;
  2372. dtn = dtn.parent;
  2373. }
  2374. return level;
  2375. },
  2376. /** Return the successor node (under the same parent) or null.
  2377. * @returns {FancytreeNode | null}
  2378. */
  2379. getNextSibling: function() {
  2380. // TODO: use indexOf, if available: (not in IE6)
  2381. if (this.parent) {
  2382. var i,
  2383. l,
  2384. ac = this.parent.children;
  2385. for (i = 0, l = ac.length - 1; i < l; i++) {
  2386. // up to length-2, so next(last) = null
  2387. if (ac[i] === this) {
  2388. return ac[i + 1];
  2389. }
  2390. }
  2391. }
  2392. return null;
  2393. },
  2394. /** Return the parent node (null for the system root node).
  2395. * @returns {FancytreeNode | null}
  2396. */
  2397. getParent: function() {
  2398. // TODO: return null for top-level nodes?
  2399. return this.parent;
  2400. },
  2401. /** Return an array of all parent nodes (top-down).
  2402. * @param {boolean} [includeRoot=false] Include the invisible system root node.
  2403. * @param {boolean} [includeSelf=false] Include the node itself.
  2404. * @returns {FancytreeNode[]}
  2405. */
  2406. getParentList: function(includeRoot, includeSelf) {
  2407. var l = [],
  2408. dtn = includeSelf ? this : this.parent;
  2409. while (dtn) {
  2410. if (includeRoot || dtn.parent) {
  2411. l.unshift(dtn);
  2412. }
  2413. dtn = dtn.parent;
  2414. }
  2415. return l;
  2416. },
  2417. /** Return a string representing the hierachical node path, e.g. "a/b/c".
  2418. * @param {boolean} [includeSelf=true]
  2419. * @param {string | function} [part="title"] node property name or callback
  2420. * @param {string} [separator="/"]
  2421. * @returns {string}
  2422. * @since v2.31
  2423. */
  2424. getPath: function(includeSelf, part, separator) {
  2425. includeSelf = includeSelf !== false;
  2426. part = part || "title";
  2427. separator = separator || "/";
  2428. var val,
  2429. path = [],
  2430. isFunc = $.isFunction(part);
  2431. this.visitParents(function(n) {
  2432. if (n.parent) {
  2433. val = isFunc ? part(n) : n[part];
  2434. path.unshift(val);
  2435. }
  2436. }, includeSelf);
  2437. return path.join(separator);
  2438. },
  2439. /** Return the predecessor node (under the same parent) or null.
  2440. * @returns {FancytreeNode | null}
  2441. */
  2442. getPrevSibling: function() {
  2443. if (this.parent) {
  2444. var i,
  2445. l,
  2446. ac = this.parent.children;
  2447. for (i = 1, l = ac.length; i < l; i++) {
  2448. // start with 1, so prev(first) = null
  2449. if (ac[i] === this) {
  2450. return ac[i - 1];
  2451. }
  2452. }
  2453. }
  2454. return null;
  2455. },
  2456. /**
  2457. * Return an array of selected descendant nodes.
  2458. * @param {boolean} [stopOnParents=false] only return the topmost selected
  2459. * node (useful with selectMode 3)
  2460. * @returns {FancytreeNode[]}
  2461. */
  2462. getSelectedNodes: function(stopOnParents) {
  2463. var nodeList = [];
  2464. this.visit(function(node) {
  2465. if (node.selected) {
  2466. nodeList.push(node);
  2467. if (stopOnParents === true) {
  2468. return "skip"; // stop processing this branch
  2469. }
  2470. }
  2471. });
  2472. return nodeList;
  2473. },
  2474. /** Return true if node has children. Return undefined if not sure, i.e. the node is lazy and not yet loaded).
  2475. * @returns {boolean | undefined}
  2476. */
  2477. hasChildren: function() {
  2478. if (this.lazy) {
  2479. if (this.children == null) {
  2480. // null or undefined: Not yet loaded
  2481. return undefined;
  2482. } else if (this.children.length === 0) {
  2483. // Loaded, but response was empty
  2484. return false;
  2485. } else if (
  2486. this.children.length === 1 &&
  2487. this.children[0].isStatusNode()
  2488. ) {
  2489. // Currently loading or load error
  2490. return undefined;
  2491. }
  2492. return true;
  2493. }
  2494. return !!(this.children && this.children.length);
  2495. },
  2496. /**
  2497. * Return true if node has `className` defined in .extraClasses.
  2498. *
  2499. * @param {string} className class name (separate multiple classes by space)
  2500. * @returns {boolean}
  2501. *
  2502. * @since 2.32
  2503. */
  2504. hasClass: function(className) {
  2505. return (
  2506. (" " + (this.extraClasses || "") + " ").indexOf(
  2507. " " + className + " "
  2508. ) >= 0
  2509. );
  2510. },
  2511. /** Return true if node has keyboard focus.
  2512. * @returns {boolean}
  2513. */
  2514. hasFocus: function() {
  2515. return this.tree.hasFocus() && this.tree.focusNode === this;
  2516. },
  2517. /** Write to browser console if debugLevel >= 3 (prepending node info)
  2518. *
  2519. * @param {*} msg string or object or array of such
  2520. */
  2521. info: function(msg) {
  2522. if (this.tree.options.debugLevel >= 3) {
  2523. Array.prototype.unshift.call(arguments, this.toString());
  2524. consoleApply("info", arguments);
  2525. }
  2526. },
  2527. /** Return true if node is active (see also FancytreeNode#isSelected).
  2528. * @returns {boolean}
  2529. */
  2530. isActive: function() {
  2531. return this.tree.activeNode === this;
  2532. },
  2533. /** Return true if node is vertically below `otherNode`, i.e. rendered in a subsequent row.
  2534. * @param {FancytreeNode} otherNode
  2535. * @returns {boolean}
  2536. * @since 2.28
  2537. */
  2538. isBelowOf: function(otherNode) {
  2539. return this.getIndexHier(".", 5) > otherNode.getIndexHier(".", 5);
  2540. },
  2541. /** Return true if node is a direct child of otherNode.
  2542. * @param {FancytreeNode} otherNode
  2543. * @returns {boolean}
  2544. */
  2545. isChildOf: function(otherNode) {
  2546. return this.parent && this.parent === otherNode;
  2547. },
  2548. /** Return true, if node is a direct or indirect sub node of otherNode.
  2549. * @param {FancytreeNode} otherNode
  2550. * @returns {boolean}
  2551. */
  2552. isDescendantOf: function(otherNode) {
  2553. if (!otherNode || otherNode.tree !== this.tree) {
  2554. return false;
  2555. }
  2556. var p = this.parent;
  2557. while (p) {
  2558. if (p === otherNode) {
  2559. return true;
  2560. }
  2561. if (p === p.parent) {
  2562. $.error("Recursive parent link: " + p);
  2563. }
  2564. p = p.parent;
  2565. }
  2566. return false;
  2567. },
  2568. /** Return true if node is expanded.
  2569. * @returns {boolean}
  2570. */
  2571. isExpanded: function() {
  2572. return !!this.expanded;
  2573. },
  2574. /** Return true if node is the first node of its parent's children.
  2575. * @returns {boolean}
  2576. */
  2577. isFirstSibling: function() {
  2578. var p = this.parent;
  2579. return !p || p.children[0] === this;
  2580. },
  2581. /** Return true if node is a folder, i.e. has the node.folder attribute set.
  2582. * @returns {boolean}
  2583. */
  2584. isFolder: function() {
  2585. return !!this.folder;
  2586. },
  2587. /** Return true if node is the last node of its parent's children.
  2588. * @returns {boolean}
  2589. */
  2590. isLastSibling: function() {
  2591. var p = this.parent;
  2592. return !p || p.children[p.children.length - 1] === this;
  2593. },
  2594. /** Return true if node is lazy (even if data was already loaded)
  2595. * @returns {boolean}
  2596. */
  2597. isLazy: function() {
  2598. return !!this.lazy;
  2599. },
  2600. /** Return true if node is lazy and loaded. For non-lazy nodes always return true.
  2601. * @returns {boolean}
  2602. */
  2603. isLoaded: function() {
  2604. return !this.lazy || this.hasChildren() !== undefined; // Also checks if the only child is a status node
  2605. },
  2606. /** Return true if children are currently beeing loaded, i.e. a Ajax request is pending.
  2607. * @returns {boolean}
  2608. */
  2609. isLoading: function() {
  2610. return !!this._isLoading;
  2611. },
  2612. /*
  2613. * @deprecated since v2.4.0: Use isRootNode() instead
  2614. */
  2615. isRoot: function() {
  2616. return this.isRootNode();
  2617. },
  2618. /** Return true if node is partially selected (tri-state).
  2619. * @returns {boolean}
  2620. * @since 2.23
  2621. */
  2622. isPartsel: function() {
  2623. return !this.selected && !!this.partsel;
  2624. },
  2625. /** (experimental) Return true if this is partially loaded.
  2626. * @returns {boolean}
  2627. * @since 2.15
  2628. */
  2629. isPartload: function() {
  2630. return !!this.partload;
  2631. },
  2632. /** Return true if this is the (invisible) system root node.
  2633. * @returns {boolean}
  2634. * @since 2.4
  2635. */
  2636. isRootNode: function() {
  2637. return this.tree.rootNode === this;
  2638. },
  2639. /** Return true if node is selected, i.e. has a checkmark set (see also FancytreeNode#isActive).
  2640. * @returns {boolean}
  2641. */
  2642. isSelected: function() {
  2643. return !!this.selected;
  2644. },
  2645. /** Return true if this node is a temporarily generated system node like
  2646. * 'loading', 'paging', or 'error' (node.statusNodeType contains the type).
  2647. * @returns {boolean}
  2648. */
  2649. isStatusNode: function() {
  2650. return !!this.statusNodeType;
  2651. },
  2652. /** Return true if this node is a status node of type 'paging'.
  2653. * @returns {boolean}
  2654. * @since 2.15
  2655. */
  2656. isPagingNode: function() {
  2657. return this.statusNodeType === "paging";
  2658. },
  2659. /** Return true if this a top level node, i.e. a direct child of the (invisible) system root node.
  2660. * @returns {boolean}
  2661. * @since 2.4
  2662. */
  2663. isTopLevel: function() {
  2664. return this.tree.rootNode === this.parent;
  2665. },
  2666. /** Return true if node is lazy and not yet loaded. For non-lazy nodes always return false.
  2667. * @returns {boolean}
  2668. */
  2669. isUndefined: function() {
  2670. return this.hasChildren() === undefined; // also checks if the only child is a status node
  2671. },
  2672. /** Return true if all parent nodes are expanded. Note: this does not check
  2673. * whether the node is scrolled into the visible part of the screen.
  2674. * @returns {boolean}
  2675. */
  2676. isVisible: function() {
  2677. var i,
  2678. l,
  2679. n,
  2680. hasFilter = this.tree.enableFilter,
  2681. parents = this.getParentList(false, false);
  2682. // TODO: check $(n.span).is(":visible")
  2683. // i.e. return false for nodes (but not parents) that are hidden
  2684. // by a filter
  2685. if (hasFilter && !this.match && !this.subMatchCount) {
  2686. // this.debug( "isVisible: HIDDEN (" + hasFilter + ", " + this.match + ", " + this.match + ")" );
  2687. return false;
  2688. }
  2689. for (i = 0, l = parents.length; i < l; i++) {
  2690. n = parents[i];
  2691. if (!n.expanded) {
  2692. // this.debug("isVisible: HIDDEN (parent collapsed)");
  2693. return false;
  2694. }
  2695. // if (hasFilter && !n.match && !n.subMatchCount) {
  2696. // this.debug("isVisible: HIDDEN (" + hasFilter + ", " + this.match + ", " + this.match + ")");
  2697. // return false;
  2698. // }
  2699. }
  2700. // this.debug("isVisible: VISIBLE");
  2701. return true;
  2702. },
  2703. /** Deprecated.
  2704. * @deprecated since 2014-02-16: use load() instead.
  2705. */
  2706. lazyLoad: function(discard) {
  2707. $.error(
  2708. "FancytreeNode.lazyLoad() is deprecated since 2014-02-16. Use .load() instead."
  2709. );
  2710. },
  2711. /**
  2712. * Load all children of a lazy node if neccessary. The <i>expanded</i> state is maintained.
  2713. * @param {boolean} [forceReload=false] Pass true to discard any existing nodes before. Otherwise this method does nothing if the node was already loaded.
  2714. * @returns {$.Promise}
  2715. */
  2716. load: function(forceReload) {
  2717. var res,
  2718. source,
  2719. self = this,
  2720. wasExpanded = this.isExpanded();
  2721. _assert(this.isLazy(), "load() requires a lazy node");
  2722. // _assert( forceReload || this.isUndefined(), "Pass forceReload=true to re-load a lazy node" );
  2723. if (!forceReload && !this.isUndefined()) {
  2724. return _getResolvedPromise(this);
  2725. }
  2726. if (this.isLoaded()) {
  2727. this.resetLazy(); // also collapses
  2728. }
  2729. // This method is also called by setExpanded() and loadKeyPath(), so we
  2730. // have to avoid recursion.
  2731. source = this.tree._triggerNodeEvent("lazyLoad", this);
  2732. if (source === false) {
  2733. // #69
  2734. return _getResolvedPromise(this);
  2735. }
  2736. _assert(
  2737. typeof source !== "boolean",
  2738. "lazyLoad event must return source in data.result"
  2739. );
  2740. res = this.tree._callHook("nodeLoadChildren", this, source);
  2741. if (wasExpanded) {
  2742. this.expanded = true;
  2743. res.always(function() {
  2744. self.render();
  2745. });
  2746. } else {
  2747. res.always(function() {
  2748. self.renderStatus(); // fix expander icon to 'loaded'
  2749. });
  2750. }
  2751. return res;
  2752. },
  2753. /** Expand all parents and optionally scroll into visible area as neccessary.
  2754. * Promise is resolved, when lazy loading and animations are done.
  2755. * @param {object} [opts] passed to `setExpanded()`.
  2756. * Defaults to {noAnimation: false, noEvents: false, scrollIntoView: true}
  2757. * @returns {$.Promise}
  2758. */
  2759. makeVisible: function(opts) {
  2760. var i,
  2761. self = this,
  2762. deferreds = [],
  2763. dfd = new $.Deferred(),
  2764. parents = this.getParentList(false, false),
  2765. len = parents.length,
  2766. effects = !(opts && opts.noAnimation === true),
  2767. scroll = !(opts && opts.scrollIntoView === false);
  2768. // Expand bottom-up, so only the top node is animated
  2769. for (i = len - 1; i >= 0; i--) {
  2770. // self.debug("pushexpand" + parents[i]);
  2771. deferreds.push(parents[i].setExpanded(true, opts));
  2772. }
  2773. $.when.apply($, deferreds).done(function() {
  2774. // All expands have finished
  2775. // self.debug("expand DONE", scroll);
  2776. if (scroll) {
  2777. self.scrollIntoView(effects).done(function() {
  2778. // self.debug("scroll DONE");
  2779. dfd.resolve();
  2780. });
  2781. } else {
  2782. dfd.resolve();
  2783. }
  2784. });
  2785. return dfd.promise();
  2786. },
  2787. /** Move this node to targetNode.
  2788. * @param {FancytreeNode} targetNode
  2789. * @param {string} mode <pre>
  2790. * 'child': append this node as last child of targetNode.
  2791. * This is the default. To be compatble with the D'n'd
  2792. * hitMode, we also accept 'over'.
  2793. * 'firstChild': add this node as first child of targetNode.
  2794. * 'before': add this node as sibling before targetNode.
  2795. * 'after': add this node as sibling after targetNode.</pre>
  2796. * @param {function} [map] optional callback(FancytreeNode) to allow modifcations
  2797. */
  2798. moveTo: function(targetNode, mode, map) {
  2799. if (mode === undefined || mode === "over") {
  2800. mode = "child";
  2801. } else if (mode === "firstChild") {
  2802. if (targetNode.children && targetNode.children.length) {
  2803. mode = "before";
  2804. targetNode = targetNode.children[0];
  2805. } else {
  2806. mode = "child";
  2807. }
  2808. }
  2809. var pos,
  2810. tree = this.tree,
  2811. prevParent = this.parent,
  2812. targetParent =
  2813. mode === "child" ? targetNode : targetNode.parent;
  2814. if (this === targetNode) {
  2815. return;
  2816. } else if (!this.parent) {
  2817. $.error("Cannot move system root");
  2818. } else if (targetParent.isDescendantOf(this)) {
  2819. $.error("Cannot move a node to its own descendant");
  2820. }
  2821. if (targetParent !== prevParent) {
  2822. prevParent.triggerModifyChild("remove", this);
  2823. }
  2824. // Unlink this node from current parent
  2825. if (this.parent.children.length === 1) {
  2826. if (this.parent === targetParent) {
  2827. return; // #258
  2828. }
  2829. this.parent.children = this.parent.lazy ? [] : null;
  2830. this.parent.expanded = false;
  2831. } else {
  2832. pos = $.inArray(this, this.parent.children);
  2833. _assert(pos >= 0, "invalid source parent");
  2834. this.parent.children.splice(pos, 1);
  2835. }
  2836. // Remove from source DOM parent
  2837. // if(this.parent.ul){
  2838. // this.parent.ul.removeChild(this.li);
  2839. // }
  2840. // Insert this node to target parent's child list
  2841. this.parent = targetParent;
  2842. if (targetParent.hasChildren()) {
  2843. switch (mode) {
  2844. case "child":
  2845. // Append to existing target children
  2846. targetParent.children.push(this);
  2847. break;
  2848. case "before":
  2849. // Insert this node before target node
  2850. pos = $.inArray(targetNode, targetParent.children);
  2851. _assert(pos >= 0, "invalid target parent");
  2852. targetParent.children.splice(pos, 0, this);
  2853. break;
  2854. case "after":
  2855. // Insert this node after target node
  2856. pos = $.inArray(targetNode, targetParent.children);
  2857. _assert(pos >= 0, "invalid target parent");
  2858. targetParent.children.splice(pos + 1, 0, this);
  2859. break;
  2860. default:
  2861. $.error("Invalid mode " + mode);
  2862. }
  2863. } else {
  2864. targetParent.children = [this];
  2865. }
  2866. // Parent has no <ul> tag yet:
  2867. // if( !targetParent.ul ) {
  2868. // // This is the parent's first child: create UL tag
  2869. // // (Hidden, because it will be
  2870. // targetParent.ul = document.createElement("ul");
  2871. // targetParent.ul.style.display = "none";
  2872. // targetParent.li.appendChild(targetParent.ul);
  2873. // }
  2874. // // Issue 319: Add to target DOM parent (only if node was already rendered(expanded))
  2875. // if(this.li){
  2876. // targetParent.ul.appendChild(this.li);
  2877. // }
  2878. // Let caller modify the nodes
  2879. if (map) {
  2880. targetNode.visit(map, true);
  2881. }
  2882. if (targetParent === prevParent) {
  2883. targetParent.triggerModifyChild("move", this);
  2884. } else {
  2885. // prevParent.triggerModifyChild("remove", this);
  2886. targetParent.triggerModifyChild("add", this);
  2887. }
  2888. // Handle cross-tree moves
  2889. if (tree !== targetNode.tree) {
  2890. // Fix node.tree for all source nodes
  2891. // _assert(false, "Cross-tree move is not yet implemented.");
  2892. this.warn("Cross-tree moveTo is experimental!");
  2893. this.visit(function(n) {
  2894. // TODO: fix selection state and activation, ...
  2895. n.tree = targetNode.tree;
  2896. }, true);
  2897. }
  2898. // A collaposed node won't re-render children, so we have to remove it manually
  2899. // if( !targetParent.expanded ){
  2900. // prevParent.ul.removeChild(this.li);
  2901. // }
  2902. tree._callHook("treeStructureChanged", tree, "moveTo");
  2903. // Update HTML markup
  2904. if (!prevParent.isDescendantOf(targetParent)) {
  2905. prevParent.render();
  2906. }
  2907. if (
  2908. !targetParent.isDescendantOf(prevParent) &&
  2909. targetParent !== prevParent
  2910. ) {
  2911. targetParent.render();
  2912. }
  2913. // TODO: fix selection state
  2914. // TODO: fix active state
  2915. /*
  2916. var tree = this.tree;
  2917. var opts = tree.options;
  2918. var pers = tree.persistence;
  2919. // Always expand, if it's below minExpandLevel
  2920. // tree.logDebug ("%s._addChildNode(%o), l=%o", this, ftnode, ftnode.getLevel());
  2921. if ( opts.minExpandLevel >= ftnode.getLevel() ) {
  2922. // tree.logDebug ("Force expand for %o", ftnode);
  2923. this.bExpanded = true;
  2924. }
  2925. // In multi-hier mode, update the parents selection state
  2926. // DT issue #82: only if not initializing, because the children may not exist yet
  2927. // if( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing )
  2928. // ftnode._fixSelectionState();
  2929. // In multi-hier mode, update the parents selection state
  2930. if( ftnode.bSelected && opts.selectMode==3 ) {
  2931. var p = this;
  2932. while( p ) {
  2933. if( !p.hasSubSel )
  2934. p._setSubSel(true);
  2935. p = p.parent;
  2936. }
  2937. }
  2938. // render this node and the new child
  2939. if ( tree.bEnableUpdate )
  2940. this.render();
  2941. return ftnode;
  2942. */
  2943. },
  2944. /** Set focus relative to this node and optionally activate.
  2945. *
  2946. * 'left' collapses the node if it is expanded, or move to the parent
  2947. * otherwise.
  2948. * 'right' expands the node if it is collapsed, or move to the first
  2949. * child otherwise.
  2950. *
  2951. * @param {string|number} where 'down', 'first', 'last', 'left', 'parent', 'right', or 'up'.
  2952. * (Alternatively the keyCode that would normally trigger this move,
  2953. * e.g. `$.ui.keyCode.LEFT` = 'left'.
  2954. * @param {boolean} [activate=true]
  2955. * @returns {$.Promise}
  2956. */
  2957. navigate: function(where, activate) {
  2958. var node,
  2959. KC = $.ui.keyCode;
  2960. // Handle optional expand/collapse action for LEFT/RIGHT
  2961. switch (where) {
  2962. case "left":
  2963. case KC.LEFT:
  2964. if (this.expanded) {
  2965. return this.setExpanded(false);
  2966. }
  2967. break;
  2968. case "right":
  2969. case KC.RIGHT:
  2970. if (!this.expanded && (this.children || this.lazy)) {
  2971. return this.setExpanded();
  2972. }
  2973. break;
  2974. }
  2975. // Otherwise activate or focus the related node
  2976. node = this.findRelatedNode(where);
  2977. if (node) {
  2978. // setFocus/setActive will scroll later (if autoScroll is specified)
  2979. try {
  2980. node.makeVisible({ scrollIntoView: false });
  2981. } catch (e) {} // #272
  2982. if (activate === false) {
  2983. node.setFocus();
  2984. return _getResolvedPromise();
  2985. }
  2986. return node.setActive();
  2987. }
  2988. this.warn("Could not find related node '" + where + "'.");
  2989. return _getResolvedPromise();
  2990. },
  2991. /**
  2992. * Remove this node (not allowed for system root).
  2993. */
  2994. remove: function() {
  2995. return this.parent.removeChild(this);
  2996. },
  2997. /**
  2998. * Remove childNode from list of direct children.
  2999. * @param {FancytreeNode} childNode
  3000. */
  3001. removeChild: function(childNode) {
  3002. return this.tree._callHook("nodeRemoveChild", this, childNode);
  3003. },
  3004. /**
  3005. * Remove all child nodes and descendents. This converts the node into a leaf.<br>
  3006. * If this was a lazy node, it is still considered 'loaded'; call node.resetLazy()
  3007. * in order to trigger lazyLoad on next expand.
  3008. */
  3009. removeChildren: function() {
  3010. return this.tree._callHook("nodeRemoveChildren", this);
  3011. },
  3012. /**
  3013. * Remove class from node's span tag and .extraClasses.
  3014. *
  3015. * @param {string} className class name
  3016. *
  3017. * @since 2.17
  3018. */
  3019. removeClass: function(className) {
  3020. return this.toggleClass(className, false);
  3021. },
  3022. /**
  3023. * This method renders and updates all HTML markup that is required
  3024. * to display this node in its current state.<br>
  3025. * Note:
  3026. * <ul>
  3027. * <li>It should only be neccessary to call this method after the node object
  3028. * was modified by direct access to its properties, because the common
  3029. * API methods (node.setTitle(), moveTo(), addChildren(), remove(), ...)
  3030. * already handle this.
  3031. * <li> {@link FancytreeNode#renderTitle} and {@link FancytreeNode#renderStatus}
  3032. * are implied. If changes are more local, calling only renderTitle() or
  3033. * renderStatus() may be sufficient and faster.
  3034. * </ul>
  3035. *
  3036. * @param {boolean} [force=false] re-render, even if html markup was already created
  3037. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  3038. */
  3039. render: function(force, deep) {
  3040. return this.tree._callHook("nodeRender", this, force, deep);
  3041. },
  3042. /** Create HTML markup for the node's outer `<span>` (expander, checkbox, icon, and title).
  3043. * Implies {@link FancytreeNode#renderStatus}.
  3044. * @see Fancytree_Hooks#nodeRenderTitle
  3045. */
  3046. renderTitle: function() {
  3047. return this.tree._callHook("nodeRenderTitle", this);
  3048. },
  3049. /** Update element's CSS classes according to node state.
  3050. * @see Fancytree_Hooks#nodeRenderStatus
  3051. */
  3052. renderStatus: function() {
  3053. return this.tree._callHook("nodeRenderStatus", this);
  3054. },
  3055. /**
  3056. * (experimental) Replace this node with `source`.
  3057. * (Currently only available for paging nodes.)
  3058. * @param {NodeData[]} source List of child node definitions
  3059. * @since 2.15
  3060. */
  3061. replaceWith: function(source) {
  3062. var res,
  3063. parent = this.parent,
  3064. pos = $.inArray(this, parent.children),
  3065. self = this;
  3066. _assert(
  3067. this.isPagingNode(),
  3068. "replaceWith() currently requires a paging status node"
  3069. );
  3070. res = this.tree._callHook("nodeLoadChildren", this, source);
  3071. res.done(function(data) {
  3072. // New nodes are currently children of `this`.
  3073. var children = self.children;
  3074. // Prepend newly loaded child nodes to `this`
  3075. // Move new children after self
  3076. for (i = 0; i < children.length; i++) {
  3077. children[i].parent = parent;
  3078. }
  3079. parent.children.splice.apply(
  3080. parent.children,
  3081. [pos + 1, 0].concat(children)
  3082. );
  3083. // Remove self
  3084. self.children = null;
  3085. self.remove();
  3086. // Redraw new nodes
  3087. parent.render();
  3088. // TODO: set node.partload = false if this was tha last paging node?
  3089. // parent.addPagingNode(false);
  3090. }).fail(function() {
  3091. self.setExpanded();
  3092. });
  3093. return res;
  3094. // $.error("Not implemented: replaceWith()");
  3095. },
  3096. /**
  3097. * Remove all children, collapse, and set the lazy-flag, so that the lazyLoad
  3098. * event is triggered on next expand.
  3099. */
  3100. resetLazy: function() {
  3101. this.removeChildren();
  3102. this.expanded = false;
  3103. this.lazy = true;
  3104. this.children = undefined;
  3105. this.renderStatus();
  3106. },
  3107. /** Schedule activity for delayed execution (cancel any pending request).
  3108. * scheduleAction('cancel') will only cancel a pending request (if any).
  3109. * @param {string} mode
  3110. * @param {number} ms
  3111. */
  3112. scheduleAction: function(mode, ms) {
  3113. if (this.tree.timer) {
  3114. clearTimeout(this.tree.timer);
  3115. this.tree.debug("clearTimeout(%o)", this.tree.timer);
  3116. }
  3117. this.tree.timer = null;
  3118. var self = this; // required for closures
  3119. switch (mode) {
  3120. case "cancel":
  3121. // Simply made sure that timer was cleared
  3122. break;
  3123. case "expand":
  3124. this.tree.timer = setTimeout(function() {
  3125. self.tree.debug("setTimeout: trigger expand");
  3126. self.setExpanded(true);
  3127. }, ms);
  3128. break;
  3129. case "activate":
  3130. this.tree.timer = setTimeout(function() {
  3131. self.tree.debug("setTimeout: trigger activate");
  3132. self.setActive(true);
  3133. }, ms);
  3134. break;
  3135. default:
  3136. $.error("Invalid mode " + mode);
  3137. }
  3138. // this.tree.debug("setTimeout(%s, %s): %s", mode, ms, this.tree.timer);
  3139. },
  3140. /**
  3141. *
  3142. * @param {boolean | PlainObject} [effects=false] animation options.
  3143. * @param {object} [options=null] {topNode: null, effects: ..., parent: ...} this node will remain visible in
  3144. * any case, even if `this` is outside the scroll pane.
  3145. * @returns {$.Promise}
  3146. */
  3147. scrollIntoView: function(effects, options) {
  3148. if (options !== undefined && _isNode(options)) {
  3149. throw Error(
  3150. "scrollIntoView() with 'topNode' option is deprecated since 2014-05-08. Use 'options.topNode' instead."
  3151. );
  3152. }
  3153. // The scroll parent is typically the plain tree's <UL> container.
  3154. // For ext-table, we choose the nearest parent that has `position: relative`
  3155. // and `overflow` set.
  3156. // (This default can be overridden by the local or global `scrollParent` option.)
  3157. var opts = $.extend(
  3158. {
  3159. effects:
  3160. effects === true
  3161. ? { duration: 200, queue: false }
  3162. : effects,
  3163. scrollOfs: this.tree.options.scrollOfs,
  3164. scrollParent: this.tree.options.scrollParent,
  3165. topNode: null,
  3166. },
  3167. options
  3168. ),
  3169. $scrollParent = opts.scrollParent,
  3170. $container = this.tree.$container,
  3171. overflowY = $container.css("overflow-y");
  3172. if (!$scrollParent) {
  3173. if (this.tree.tbody) {
  3174. $scrollParent = $container.scrollParent();
  3175. } else if (overflowY === "scroll" || overflowY === "auto") {
  3176. $scrollParent = $container;
  3177. } else {
  3178. // #922 plain tree in a non-fixed-sized UL scrolls inside its parent
  3179. $scrollParent = $container.scrollParent();
  3180. }
  3181. } else if (!$scrollParent.jquery) {
  3182. // Make sure we have a jQuery object
  3183. $scrollParent = $($scrollParent);
  3184. }
  3185. if (
  3186. $scrollParent[0] === document ||
  3187. $scrollParent[0] === document.body
  3188. ) {
  3189. // `document` may be returned by $().scrollParent(), if nothing is found,
  3190. // but would not work: (see #894)
  3191. this.debug(
  3192. "scrollIntoView(): normalizing scrollParent to 'window':",
  3193. $scrollParent[0]
  3194. );
  3195. $scrollParent = $(window);
  3196. }
  3197. // eslint-disable-next-line one-var
  3198. var topNodeY,
  3199. nodeY,
  3200. horzScrollbarHeight,
  3201. containerOffsetTop,
  3202. dfd = new $.Deferred(),
  3203. self = this,
  3204. nodeHeight = $(this.span).height(),
  3205. topOfs = opts.scrollOfs.top || 0,
  3206. bottomOfs = opts.scrollOfs.bottom || 0,
  3207. containerHeight = $scrollParent.height(),
  3208. scrollTop = $scrollParent.scrollTop(),
  3209. $animateTarget = $scrollParent,
  3210. isParentWindow = $scrollParent[0] === window,
  3211. topNode = opts.topNode || null,
  3212. newScrollTop = null;
  3213. // this.debug("scrollIntoView(), scrollTop=" + scrollTop, opts.scrollOfs);
  3214. // _assert($(this.span).is(":visible"), "scrollIntoView node is invisible"); // otherwise we cannot calc offsets
  3215. if (this.isRootNode() || !this.isVisible()) {
  3216. // We cannot calc offsets for hidden elements
  3217. this.info("scrollIntoView(): node is invisible.");
  3218. return _getResolvedPromise();
  3219. }
  3220. if (isParentWindow) {
  3221. nodeY = $(this.span).offset().top;
  3222. topNodeY =
  3223. topNode && topNode.span ? $(topNode.span).offset().top : 0;
  3224. $animateTarget = $("html,body");
  3225. } else {
  3226. _assert(
  3227. $scrollParent[0] !== document &&
  3228. $scrollParent[0] !== document.body,
  3229. "scrollParent should be a simple element or `window`, not document or body."
  3230. );
  3231. containerOffsetTop = $scrollParent.offset().top;
  3232. nodeY =
  3233. $(this.span).offset().top - containerOffsetTop + scrollTop; // relative to scroll parent
  3234. topNodeY = topNode
  3235. ? $(topNode.span).offset().top -
  3236. containerOffsetTop +
  3237. scrollTop
  3238. : 0;
  3239. horzScrollbarHeight = Math.max(
  3240. 0,
  3241. $scrollParent.innerHeight() - $scrollParent[0].clientHeight
  3242. );
  3243. containerHeight -= horzScrollbarHeight;
  3244. }
  3245. // this.debug(" scrollIntoView(), nodeY=" + nodeY + ", containerHeight=" + containerHeight);
  3246. if (nodeY < scrollTop + topOfs) {
  3247. // Node is above visible container area
  3248. newScrollTop = nodeY - topOfs;
  3249. // this.debug(" scrollIntoView(), UPPER newScrollTop=" + newScrollTop);
  3250. } else if (
  3251. nodeY + nodeHeight >
  3252. scrollTop + containerHeight - bottomOfs
  3253. ) {
  3254. newScrollTop = nodeY + nodeHeight - containerHeight + bottomOfs;
  3255. // this.debug(" scrollIntoView(), LOWER newScrollTop=" + newScrollTop);
  3256. // If a topNode was passed, make sure that it is never scrolled
  3257. // outside the upper border
  3258. if (topNode) {
  3259. _assert(
  3260. topNode.isRootNode() || topNode.isVisible(),
  3261. "topNode must be visible"
  3262. );
  3263. if (topNodeY < newScrollTop) {
  3264. newScrollTop = topNodeY - topOfs;
  3265. // this.debug(" scrollIntoView(), TOP newScrollTop=" + newScrollTop);
  3266. }
  3267. }
  3268. }
  3269. if (newScrollTop === null) {
  3270. dfd.resolveWith(this);
  3271. } else {
  3272. // this.debug(" scrollIntoView(), SET newScrollTop=" + newScrollTop);
  3273. if (opts.effects) {
  3274. opts.effects.complete = function() {
  3275. dfd.resolveWith(self);
  3276. };
  3277. $animateTarget.stop(true).animate(
  3278. {
  3279. scrollTop: newScrollTop,
  3280. },
  3281. opts.effects
  3282. );
  3283. } else {
  3284. $animateTarget[0].scrollTop = newScrollTop;
  3285. dfd.resolveWith(this);
  3286. }
  3287. }
  3288. return dfd.promise();
  3289. },
  3290. /**Activate this node.
  3291. *
  3292. * The `cell` option requires the ext-table and ext-ariagrid extensions.
  3293. *
  3294. * @param {boolean} [flag=true] pass false to deactivate
  3295. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false, cell: null}
  3296. * @returns {$.Promise}
  3297. */
  3298. setActive: function(flag, opts) {
  3299. return this.tree._callHook("nodeSetActive", this, flag, opts);
  3300. },
  3301. /**Expand or collapse this node. Promise is resolved, when lazy loading and animations are done.
  3302. * @param {boolean} [flag=true] pass false to collapse
  3303. * @param {object} [opts] additional options. Defaults to {noAnimation: false, noEvents: false}
  3304. * @returns {$.Promise}
  3305. */
  3306. setExpanded: function(flag, opts) {
  3307. return this.tree._callHook("nodeSetExpanded", this, flag, opts);
  3308. },
  3309. /**Set keyboard focus to this node.
  3310. * @param {boolean} [flag=true] pass false to blur
  3311. * @see Fancytree#setFocus
  3312. */
  3313. setFocus: function(flag) {
  3314. return this.tree._callHook("nodeSetFocus", this, flag);
  3315. },
  3316. /**Select this node, i.e. check the checkbox.
  3317. * @param {boolean} [flag=true] pass false to deselect
  3318. * @param {object} [opts] additional options. Defaults to {noEvents: false, p
  3319. * propagateDown: null, propagateUp: null, callback: null }
  3320. */
  3321. setSelected: function(flag, opts) {
  3322. return this.tree._callHook("nodeSetSelected", this, flag, opts);
  3323. },
  3324. /**Mark a lazy node as 'error', 'loading', 'nodata', or 'ok'.
  3325. * @param {string} status 'error'|'loading'|'nodata'|'ok'
  3326. * @param {string} [message]
  3327. * @param {string} [details]
  3328. */
  3329. setStatus: function(status, message, details) {
  3330. return this.tree._callHook(
  3331. "nodeSetStatus",
  3332. this,
  3333. status,
  3334. message,
  3335. details
  3336. );
  3337. },
  3338. /**Rename this node.
  3339. * @param {string} title
  3340. */
  3341. setTitle: function(title) {
  3342. this.title = title;
  3343. this.renderTitle();
  3344. this.triggerModify("rename");
  3345. },
  3346. /**Sort child list by title.
  3347. * @param {function} [cmp] custom compare function(a, b) that returns -1, 0, or 1 (defaults to sort by title).
  3348. * @param {boolean} [deep=false] pass true to sort all descendant nodes
  3349. */
  3350. sortChildren: function(cmp, deep) {
  3351. var i,
  3352. l,
  3353. cl = this.children;
  3354. if (!cl) {
  3355. return;
  3356. }
  3357. cmp =
  3358. cmp ||
  3359. function(a, b) {
  3360. var x = a.title.toLowerCase(),
  3361. y = b.title.toLowerCase();
  3362. // eslint-disable-next-line no-nested-ternary
  3363. return x === y ? 0 : x > y ? 1 : -1;
  3364. };
  3365. cl.sort(cmp);
  3366. if (deep) {
  3367. for (i = 0, l = cl.length; i < l; i++) {
  3368. if (cl[i].children) {
  3369. cl[i].sortChildren(cmp, "$norender$");
  3370. }
  3371. }
  3372. }
  3373. if (deep !== "$norender$") {
  3374. this.render();
  3375. }
  3376. this.triggerModifyChild("sort");
  3377. },
  3378. /** Convert node (or whole branch) into a plain object.
  3379. *
  3380. * The result is compatible with node.addChildren().
  3381. *
  3382. * @param {boolean} [recursive=false] include child nodes
  3383. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications.
  3384. * Return `false` to ignore this node or `"skip"` to include this node without its children.
  3385. * @returns {NodeData}
  3386. */
  3387. toDict: function(recursive, callback) {
  3388. var i,
  3389. l,
  3390. node,
  3391. res,
  3392. dict = {},
  3393. self = this;
  3394. $.each(NODE_ATTRS, function(i, a) {
  3395. if (self[a] || self[a] === false) {
  3396. dict[a] = self[a];
  3397. }
  3398. });
  3399. if (!$.isEmptyObject(this.data)) {
  3400. dict.data = $.extend({}, this.data);
  3401. if ($.isEmptyObject(dict.data)) {
  3402. delete dict.data;
  3403. }
  3404. }
  3405. if (callback) {
  3406. res = callback(dict, self);
  3407. if (res === false) {
  3408. return false; // Don't include this node nor its children
  3409. }
  3410. if (res === "skip") {
  3411. recursive = false; // Include this node, but not the children
  3412. }
  3413. }
  3414. if (recursive) {
  3415. if ($.isArray(this.children)) {
  3416. dict.children = [];
  3417. for (i = 0, l = this.children.length; i < l; i++) {
  3418. node = this.children[i];
  3419. if (!node.isStatusNode()) {
  3420. res = node.toDict(true, callback);
  3421. if (res !== false) {
  3422. dict.children.push(res);
  3423. }
  3424. }
  3425. }
  3426. }
  3427. }
  3428. return dict;
  3429. },
  3430. /**
  3431. * Set, clear, or toggle class of node's span tag and .extraClasses.
  3432. *
  3433. * @param {string} className class name (separate multiple classes by space)
  3434. * @param {boolean} [flag] true/false to add/remove class. If omitted, class is toggled.
  3435. * @returns {boolean} true if a class was added
  3436. *
  3437. * @since 2.17
  3438. */
  3439. toggleClass: function(value, flag) {
  3440. var className,
  3441. hasClass,
  3442. rnotwhite = /\S+/g,
  3443. classNames = value.match(rnotwhite) || [],
  3444. i = 0,
  3445. wasAdded = false,
  3446. statusElem = this[this.tree.statusClassPropName],
  3447. curClasses = " " + (this.extraClasses || "") + " ";
  3448. // this.info("toggleClass('" + value + "', " + flag + ")", curClasses);
  3449. // Modify DOM element directly if it already exists
  3450. if (statusElem) {
  3451. $(statusElem).toggleClass(value, flag);
  3452. }
  3453. // Modify node.extraClasses to make this change persistent
  3454. // Toggle if flag was not passed
  3455. while ((className = classNames[i++])) {
  3456. hasClass = curClasses.indexOf(" " + className + " ") >= 0;
  3457. flag = flag === undefined ? !hasClass : !!flag;
  3458. if (flag) {
  3459. if (!hasClass) {
  3460. curClasses += className + " ";
  3461. wasAdded = true;
  3462. }
  3463. } else {
  3464. while (curClasses.indexOf(" " + className + " ") > -1) {
  3465. curClasses = curClasses.replace(
  3466. " " + className + " ",
  3467. " "
  3468. );
  3469. }
  3470. }
  3471. }
  3472. this.extraClasses = $.trim(curClasses);
  3473. // this.info("-> toggleClass('" + value + "', " + flag + "): '" + this.extraClasses + "'");
  3474. return wasAdded;
  3475. },
  3476. /** Flip expanded status. */
  3477. toggleExpanded: function() {
  3478. return this.tree._callHook("nodeToggleExpanded", this);
  3479. },
  3480. /** Flip selection status. */
  3481. toggleSelected: function() {
  3482. return this.tree._callHook("nodeToggleSelected", this);
  3483. },
  3484. toString: function() {
  3485. return "FancytreeNode@" + this.key + "[title='" + this.title + "']";
  3486. // return "<FancytreeNode(#" + this.key + ", '" + this.title + "')>";
  3487. },
  3488. /**
  3489. * Trigger `modifyChild` event on a parent to signal that a child was modified.
  3490. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  3491. * @param {FancytreeNode} [childNode]
  3492. * @param {object} [extra]
  3493. */
  3494. triggerModifyChild: function(operation, childNode, extra) {
  3495. var data,
  3496. modifyChild = this.tree.options.modifyChild;
  3497. if (modifyChild) {
  3498. if (childNode && childNode.parent !== this) {
  3499. $.error(
  3500. "childNode " + childNode + " is not a child of " + this
  3501. );
  3502. }
  3503. data = {
  3504. node: this,
  3505. tree: this.tree,
  3506. operation: operation,
  3507. childNode: childNode || null,
  3508. };
  3509. if (extra) {
  3510. $.extend(data, extra);
  3511. }
  3512. modifyChild({ type: "modifyChild" }, data);
  3513. }
  3514. },
  3515. /**
  3516. * Trigger `modifyChild` event on node.parent(!).
  3517. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  3518. * @param {object} [extra]
  3519. */
  3520. triggerModify: function(operation, extra) {
  3521. this.parent.triggerModifyChild(operation, this, extra);
  3522. },
  3523. /** Call fn(node) for all child nodes in hierarchical order (depth-first).<br>
  3524. * Stop iteration, if fn() returns false. Skip current branch, if fn() returns "skip".<br>
  3525. * Return false if iteration was stopped.
  3526. *
  3527. * @param {function} fn the callback function.
  3528. * Return false to stop iteration, return "skip" to skip this node and
  3529. * its children only.
  3530. * @param {boolean} [includeSelf=false]
  3531. * @returns {boolean}
  3532. */
  3533. visit: function(fn, includeSelf) {
  3534. var i,
  3535. l,
  3536. res = true,
  3537. children = this.children;
  3538. if (includeSelf === true) {
  3539. res = fn(this);
  3540. if (res === false || res === "skip") {
  3541. return res;
  3542. }
  3543. }
  3544. if (children) {
  3545. for (i = 0, l = children.length; i < l; i++) {
  3546. res = children[i].visit(fn, true);
  3547. if (res === false) {
  3548. break;
  3549. }
  3550. }
  3551. }
  3552. return res;
  3553. },
  3554. /** Call fn(node) for all child nodes and recursively load lazy children.<br>
  3555. * <b>Note:</b> If you need this method, you probably should consider to review
  3556. * your architecture! Recursivley loading nodes is a perfect way for lazy
  3557. * programmers to flood the server with requests ;-)
  3558. *
  3559. * @param {function} [fn] optional callback function.
  3560. * Return false to stop iteration, return "skip" to skip this node and
  3561. * its children only.
  3562. * @param {boolean} [includeSelf=false]
  3563. * @returns {$.Promise}
  3564. * @since 2.4
  3565. */
  3566. visitAndLoad: function(fn, includeSelf, _recursion) {
  3567. var dfd,
  3568. res,
  3569. loaders,
  3570. node = this;
  3571. // node.debug("visitAndLoad");
  3572. if (fn && includeSelf === true) {
  3573. res = fn(node);
  3574. if (res === false || res === "skip") {
  3575. return _recursion ? res : _getResolvedPromise();
  3576. }
  3577. }
  3578. if (!node.children && !node.lazy) {
  3579. return _getResolvedPromise();
  3580. }
  3581. dfd = new $.Deferred();
  3582. loaders = [];
  3583. // node.debug("load()...");
  3584. node.load().done(function() {
  3585. // node.debug("load()... done.");
  3586. for (var i = 0, l = node.children.length; i < l; i++) {
  3587. res = node.children[i].visitAndLoad(fn, true, true);
  3588. if (res === false) {
  3589. dfd.reject();
  3590. break;
  3591. } else if (res !== "skip") {
  3592. loaders.push(res); // Add promise to the list
  3593. }
  3594. }
  3595. $.when.apply(this, loaders).then(function() {
  3596. dfd.resolve();
  3597. });
  3598. });
  3599. return dfd.promise();
  3600. },
  3601. /** Call fn(node) for all parent nodes, bottom-up, including invisible system root.<br>
  3602. * Stop iteration, if fn() returns false.<br>
  3603. * Return false if iteration was stopped.
  3604. *
  3605. * @param {function} fn the callback function.
  3606. * Return false to stop iteration, return "skip" to skip this node and children only.
  3607. * @param {boolean} [includeSelf=false]
  3608. * @returns {boolean}
  3609. */
  3610. visitParents: function(fn, includeSelf) {
  3611. // Visit parent nodes (bottom up)
  3612. if (includeSelf && fn(this) === false) {
  3613. return false;
  3614. }
  3615. var p = this.parent;
  3616. while (p) {
  3617. if (fn(p) === false) {
  3618. return false;
  3619. }
  3620. p = p.parent;
  3621. }
  3622. return true;
  3623. },
  3624. /** Call fn(node) for all sibling nodes.<br>
  3625. * Stop iteration, if fn() returns false.<br>
  3626. * Return false if iteration was stopped.
  3627. *
  3628. * @param {function} fn the callback function.
  3629. * Return false to stop iteration.
  3630. * @param {boolean} [includeSelf=false]
  3631. * @returns {boolean}
  3632. */
  3633. visitSiblings: function(fn, includeSelf) {
  3634. var i,
  3635. l,
  3636. n,
  3637. ac = this.parent.children;
  3638. for (i = 0, l = ac.length; i < l; i++) {
  3639. n = ac[i];
  3640. if (includeSelf || n !== this) {
  3641. if (fn(n) === false) {
  3642. return false;
  3643. }
  3644. }
  3645. }
  3646. return true;
  3647. },
  3648. /** Write warning to browser console if debugLevel >= 2 (prepending node info)
  3649. *
  3650. * @param {*} msg string or object or array of such
  3651. */
  3652. warn: function(msg) {
  3653. if (this.tree.options.debugLevel >= 2) {
  3654. Array.prototype.unshift.call(arguments, this.toString());
  3655. consoleApply("warn", arguments);
  3656. }
  3657. },
  3658. };
  3659. /******************************************************************************
  3660. * Fancytree
  3661. */
  3662. /**
  3663. * Construct a new tree object.
  3664. *
  3665. * @class Fancytree
  3666. * @classdesc The controller behind a fancytree.
  3667. * This class also contains 'hook methods': see {@link Fancytree_Hooks}.
  3668. *
  3669. * @param {Widget} widget
  3670. *
  3671. * @property {string} _id Automatically generated unique tree instance ID, e.g. "1".
  3672. * @property {string} _ns Automatically generated unique tree namespace, e.g. ".fancytree-1".
  3673. * @property {FancytreeNode} activeNode Currently active node or null.
  3674. * @property {string} ariaPropName Property name of FancytreeNode that contains the element which will receive the aria attributes.
  3675. * Typically "li", but "tr" for table extension.
  3676. * @property {jQueryObject} $container Outer `<ul>` element (or `<table>` element for ext-table).
  3677. * @property {jQueryObject} $div A jQuery object containing the element used to instantiate the tree widget (`widget.element`)
  3678. * @property {object|array} columns Recommended place to store shared column meta data. @since 2.27
  3679. * @property {object} data Metadata, i.e. properties that may be passed to `source` in addition to a children array.
  3680. * @property {object} ext Hash of all active plugin instances.
  3681. * @property {FancytreeNode} focusNode Currently focused node or null.
  3682. * @property {FancytreeNode} lastSelectedNode Used to implement selectMode 1 (single select)
  3683. * @property {string} nodeContainerAttrName Property name of FancytreeNode that contains the outer element of single nodes.
  3684. * Typically "li", but "tr" for table extension.
  3685. * @property {FancytreeOptions} options Current options, i.e. default options + options passed to constructor.
  3686. * @property {FancytreeNode} rootNode Invisible system root node.
  3687. * @property {string} statusClassPropName Property name of FancytreeNode that contains the element which will receive the status classes.
  3688. * Typically "span", but "tr" for table extension.
  3689. * @property {object} types Map for shared type specific meta data, used with node.type attribute. @since 2.27
  3690. * @property {object} viewport See ext-vieport. @since v2.31
  3691. * @property {object} widget Base widget instance.
  3692. */
  3693. function Fancytree(widget) {
  3694. this.widget = widget;
  3695. this.$div = widget.element;
  3696. this.options = widget.options;
  3697. if (this.options) {
  3698. if (this.options.lazyload !== undefined) {
  3699. $.error(
  3700. "The 'lazyload' event is deprecated since 2014-02-25. Use 'lazyLoad' (with uppercase L) instead."
  3701. );
  3702. }
  3703. if (this.options.loaderror !== undefined) {
  3704. $.error(
  3705. "The 'loaderror' event was renamed since 2014-07-03. Use 'loadError' (with uppercase E) instead."
  3706. );
  3707. }
  3708. if (this.options.fx !== undefined) {
  3709. $.error(
  3710. "The 'fx' option was replaced by 'toggleEffect' since 2014-11-30."
  3711. );
  3712. }
  3713. if (this.options.removeNode !== undefined) {
  3714. $.error(
  3715. "The 'removeNode' event was replaced by 'modifyChild' since 2.20 (2016-09-10)."
  3716. );
  3717. }
  3718. }
  3719. this.ext = {}; // Active extension instances
  3720. this.types = {};
  3721. this.columns = {};
  3722. // allow to init tree.data.foo from <div data-foo=''>
  3723. this.data = _getElementDataAsDict(this.$div);
  3724. // TODO: use widget.uuid instead?
  3725. this._id = "" + (this.options.treeId || $.ui.fancytree._nextId++);
  3726. // TODO: use widget.eventNamespace instead?
  3727. this._ns = ".fancytree-" + this._id; // append for namespaced events
  3728. this.activeNode = null;
  3729. this.focusNode = null;
  3730. this._hasFocus = null;
  3731. this._tempCache = {};
  3732. this._lastMousedownNode = null;
  3733. this._enableUpdate = true;
  3734. this.lastSelectedNode = null;
  3735. this.systemFocusElement = null;
  3736. this.lastQuicksearchTerm = "";
  3737. this.lastQuicksearchTime = 0;
  3738. this.viewport = null; // ext-grid
  3739. this.statusClassPropName = "span";
  3740. this.ariaPropName = "li";
  3741. this.nodeContainerAttrName = "li";
  3742. // Remove previous markup if any
  3743. this.$div.find(">ul.fancytree-container").remove();
  3744. // Create a node without parent.
  3745. var fakeParent = { tree: this },
  3746. $ul;
  3747. this.rootNode = new FancytreeNode(fakeParent, {
  3748. title: "root",
  3749. key: "root_" + this._id,
  3750. children: null,
  3751. expanded: true,
  3752. });
  3753. this.rootNode.parent = null;
  3754. // Create root markup
  3755. $ul = $("<ul>", {
  3756. id: "ft-id-" + this._id,
  3757. class: "ui-fancytree fancytree-container fancytree-plain",
  3758. }).appendTo(this.$div);
  3759. this.$container = $ul;
  3760. this.rootNode.ul = $ul[0];
  3761. if (this.options.debugLevel == null) {
  3762. this.options.debugLevel = FT.debugLevel;
  3763. }
  3764. // // Add container to the TAB chain
  3765. // // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  3766. // // #577: Allow to set tabindex to "0", "-1" and ""
  3767. // this.$container.attr("tabindex", this.options.tabindex);
  3768. // if( this.options.rtl ) {
  3769. // this.$container.attr("DIR", "RTL").addClass("fancytree-rtl");
  3770. // // }else{
  3771. // // this.$container.attr("DIR", null).removeClass("fancytree-rtl");
  3772. // }
  3773. // if(this.options.aria){
  3774. // this.$container.attr("role", "tree");
  3775. // if( this.options.selectMode !== 1 ) {
  3776. // this.$container.attr("aria-multiselectable", true);
  3777. // }
  3778. // }
  3779. }
  3780. Fancytree.prototype = /** @lends Fancytree# */ {
  3781. /* Return a context object that can be re-used for _callHook().
  3782. * @param {Fancytree | FancytreeNode | EventData} obj
  3783. * @param {Event} originalEvent
  3784. * @param {Object} extra
  3785. * @returns {EventData}
  3786. */
  3787. _makeHookContext: function(obj, originalEvent, extra) {
  3788. var ctx, tree;
  3789. if (obj.node !== undefined) {
  3790. // obj is already a context object
  3791. if (originalEvent && obj.originalEvent !== originalEvent) {
  3792. $.error("invalid args");
  3793. }
  3794. ctx = obj;
  3795. } else if (obj.tree) {
  3796. // obj is a FancytreeNode
  3797. tree = obj.tree;
  3798. ctx = {
  3799. node: obj,
  3800. tree: tree,
  3801. widget: tree.widget,
  3802. options: tree.widget.options,
  3803. originalEvent: originalEvent,
  3804. typeInfo: tree.types[obj.type] || {},
  3805. };
  3806. } else if (obj.widget) {
  3807. // obj is a Fancytree
  3808. ctx = {
  3809. node: null,
  3810. tree: obj,
  3811. widget: obj.widget,
  3812. options: obj.widget.options,
  3813. originalEvent: originalEvent,
  3814. };
  3815. } else {
  3816. $.error("invalid args");
  3817. }
  3818. if (extra) {
  3819. $.extend(ctx, extra);
  3820. }
  3821. return ctx;
  3822. },
  3823. /* Trigger a hook function: funcName(ctx, [...]).
  3824. *
  3825. * @param {string} funcName
  3826. * @param {Fancytree|FancytreeNode|EventData} contextObject
  3827. * @param {any} [_extraArgs] optional additional arguments
  3828. * @returns {any}
  3829. */
  3830. _callHook: function(funcName, contextObject, _extraArgs) {
  3831. var ctx = this._makeHookContext(contextObject),
  3832. fn = this[funcName],
  3833. args = Array.prototype.slice.call(arguments, 2);
  3834. if (!$.isFunction(fn)) {
  3835. $.error("_callHook('" + funcName + "') is not a function");
  3836. }
  3837. args.unshift(ctx);
  3838. // this.debug("_hook", funcName, ctx.node && ctx.node.toString() || ctx.tree.toString(), args);
  3839. return fn.apply(this, args);
  3840. },
  3841. _setExpiringValue: function(key, value, ms) {
  3842. this._tempCache[key] = {
  3843. value: value,
  3844. expire: Date.now() + (+ms || 50),
  3845. };
  3846. },
  3847. _getExpiringValue: function(key) {
  3848. var entry = this._tempCache[key];
  3849. if (entry && entry.expire > Date.now()) {
  3850. return entry.value;
  3851. }
  3852. delete this._tempCache[key];
  3853. return null;
  3854. },
  3855. /* Check if this tree has extension `name` enabled.
  3856. *
  3857. * @param {string} name name of the required extension
  3858. */
  3859. _usesExtension: function(name) {
  3860. return $.inArray(name, this.options.extensions) >= 0;
  3861. },
  3862. /* Check if current extensions dependencies are met and throw an error if not.
  3863. *
  3864. * This method may be called inside the `treeInit` hook for custom extensions.
  3865. *
  3866. * @param {string} name name of the required extension
  3867. * @param {boolean} [required=true] pass `false` if the extension is optional, but we want to check for order if it is present
  3868. * @param {boolean} [before] `true` if `name` must be included before this, `false` otherwise (use `null` if order doesn't matter)
  3869. * @param {string} [message] optional error message (defaults to a descriptve error message)
  3870. */
  3871. _requireExtension: function(name, required, before, message) {
  3872. if (before != null) {
  3873. before = !!before;
  3874. }
  3875. var thisName = this._local.name,
  3876. extList = this.options.extensions,
  3877. isBefore =
  3878. $.inArray(name, extList) < $.inArray(thisName, extList),
  3879. isMissing = required && this.ext[name] == null,
  3880. badOrder = !isMissing && before != null && before !== isBefore;
  3881. _assert(
  3882. thisName && thisName !== name,
  3883. "invalid or same name '" + thisName + "' (require yourself?)"
  3884. );
  3885. if (isMissing || badOrder) {
  3886. if (!message) {
  3887. if (isMissing || required) {
  3888. message =
  3889. "'" +
  3890. thisName +
  3891. "' extension requires '" +
  3892. name +
  3893. "'";
  3894. if (badOrder) {
  3895. message +=
  3896. " to be registered " +
  3897. (before ? "before" : "after") +
  3898. " itself";
  3899. }
  3900. } else {
  3901. message =
  3902. "If used together, `" +
  3903. name +
  3904. "` must be registered " +
  3905. (before ? "before" : "after") +
  3906. " `" +
  3907. thisName +
  3908. "`";
  3909. }
  3910. }
  3911. $.error(message);
  3912. return false;
  3913. }
  3914. return true;
  3915. },
  3916. /** Activate node with a given key and fire focus and activate events.
  3917. *
  3918. * A previously activated node will be deactivated.
  3919. * If activeVisible option is set, all parents will be expanded as necessary.
  3920. * Pass key = false, to deactivate the current node only.
  3921. * @param {string} key
  3922. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  3923. * @returns {FancytreeNode} activated node (null, if not found)
  3924. */
  3925. activateKey: function(key, opts) {
  3926. var node = this.getNodeByKey(key);
  3927. if (node) {
  3928. node.setActive(true, opts);
  3929. } else if (this.activeNode) {
  3930. this.activeNode.setActive(false, opts);
  3931. }
  3932. return node;
  3933. },
  3934. /** (experimental) Add child status nodes that indicate 'More...', ....
  3935. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  3936. * @param {string} [mode='append'] 'child'|firstChild'
  3937. * @since 2.15
  3938. */
  3939. addPagingNode: function(node, mode) {
  3940. return this.rootNode.addPagingNode(node, mode);
  3941. },
  3942. /**
  3943. * (experimental) Apply a modification (or navigation) operation.
  3944. *
  3945. * Valid commands:
  3946. * - 'moveUp', 'moveDown'
  3947. * - 'indent', 'outdent'
  3948. * - 'remove'
  3949. * - 'edit', 'addChild', 'addSibling': (reqires ext-edit extension)
  3950. * - 'cut', 'copy', 'paste': (use an internal singleton 'clipboard')
  3951. * - 'down', 'first', 'last', 'left', 'parent', 'right', 'up': navigate
  3952. *
  3953. * @param {string} cmd
  3954. * @param {FancytreeNode} [node=active_node]
  3955. * @param {object} [opts] Currently unused
  3956. *
  3957. * @since 2.32
  3958. */
  3959. applyCommand: function(cmd, node, opts_) {
  3960. var // clipboard,
  3961. refNode;
  3962. // opts = $.extend(
  3963. // { setActive: true, clipboard: CLIPBOARD },
  3964. // opts_
  3965. // );
  3966. node = node || this.getActiveNode();
  3967. // clipboard = opts.clipboard;
  3968. switch (cmd) {
  3969. // Sorting and indentation:
  3970. case "moveUp":
  3971. refNode = node.getPrevSibling();
  3972. if (refNode) {
  3973. node.moveTo(refNode, "before");
  3974. node.setActive();
  3975. }
  3976. break;
  3977. case "moveDown":
  3978. refNode = node.getNextSibling();
  3979. if (refNode) {
  3980. node.moveTo(refNode, "after");
  3981. node.setActive();
  3982. }
  3983. break;
  3984. case "indent":
  3985. refNode = node.getPrevSibling();
  3986. if (refNode) {
  3987. node.moveTo(refNode, "child");
  3988. refNode.setExpanded();
  3989. node.setActive();
  3990. }
  3991. break;
  3992. case "outdent":
  3993. if (!node.isTopLevel()) {
  3994. node.moveTo(node.getParent(), "after");
  3995. node.setActive();
  3996. }
  3997. break;
  3998. // Remove:
  3999. case "remove":
  4000. refNode = node.getPrevSibling() || node.getParent();
  4001. node.remove();
  4002. if (refNode) {
  4003. refNode.setActive();
  4004. }
  4005. break;
  4006. // Add, edit (requires ext-edit):
  4007. case "addChild":
  4008. node.editCreateNode("child", "");
  4009. break;
  4010. case "addSibling":
  4011. node.editCreateNode("after", "");
  4012. break;
  4013. case "rename":
  4014. node.editStart();
  4015. break;
  4016. // Simple clipboard simulation:
  4017. // case "cut":
  4018. // clipboard = { mode: cmd, data: node };
  4019. // break;
  4020. // case "copy":
  4021. // clipboard = {
  4022. // mode: cmd,
  4023. // data: node.toDict(function(d, n) {
  4024. // delete d.key;
  4025. // }),
  4026. // };
  4027. // break;
  4028. // case "clear":
  4029. // clipboard = null;
  4030. // break;
  4031. // case "paste":
  4032. // if (clipboard.mode === "cut") {
  4033. // // refNode = node.getPrevSibling();
  4034. // clipboard.data.moveTo(node, "child");
  4035. // clipboard.data.setActive();
  4036. // } else if (clipboard.mode === "copy") {
  4037. // node.addChildren(clipboard.data).setActive();
  4038. // }
  4039. // break;
  4040. // Navigation commands:
  4041. case "down":
  4042. case "first":
  4043. case "last":
  4044. case "left":
  4045. case "parent":
  4046. case "right":
  4047. case "up":
  4048. return node.navigate(cmd);
  4049. default:
  4050. $.error("Unhandled command: '" + cmd + "'");
  4051. }
  4052. },
  4053. /** (experimental) Modify existing data model.
  4054. *
  4055. * @param {Array} patchList array of [key, NodePatch] arrays
  4056. * @returns {$.Promise} resolved, when all patches have been applied
  4057. * @see TreePatch
  4058. */
  4059. applyPatch: function(patchList) {
  4060. var dfd,
  4061. i,
  4062. p2,
  4063. key,
  4064. patch,
  4065. node,
  4066. patchCount = patchList.length,
  4067. deferredList = [];
  4068. for (i = 0; i < patchCount; i++) {
  4069. p2 = patchList[i];
  4070. _assert(
  4071. p2.length === 2,
  4072. "patchList must be an array of length-2-arrays"
  4073. );
  4074. key = p2[0];
  4075. patch = p2[1];
  4076. node = key === null ? this.rootNode : this.getNodeByKey(key);
  4077. if (node) {
  4078. dfd = new $.Deferred();
  4079. deferredList.push(dfd);
  4080. node.applyPatch(patch).always(_makeResolveFunc(dfd, node));
  4081. } else {
  4082. this.warn("could not find node with key '" + key + "'");
  4083. }
  4084. }
  4085. // Return a promise that is resolved, when ALL patches were applied
  4086. return $.when.apply($, deferredList).promise();
  4087. },
  4088. /* TODO: implement in dnd extension
  4089. cancelDrag: function() {
  4090. var dd = $.ui.ddmanager.current;
  4091. if(dd){
  4092. dd.cancel();
  4093. }
  4094. },
  4095. */
  4096. /** Remove all nodes.
  4097. * @since 2.14
  4098. */
  4099. clear: function(source) {
  4100. this._callHook("treeClear", this);
  4101. },
  4102. /** Return the number of nodes.
  4103. * @returns {integer}
  4104. */
  4105. count: function() {
  4106. return this.rootNode.countChildren();
  4107. },
  4108. /** Write to browser console if debugLevel >= 4 (prepending tree name)
  4109. *
  4110. * @param {*} msg string or object or array of such
  4111. */
  4112. debug: function(msg) {
  4113. if (this.options.debugLevel >= 4) {
  4114. Array.prototype.unshift.call(arguments, this.toString());
  4115. consoleApply("log", arguments);
  4116. }
  4117. },
  4118. /** Destroy this widget, restore previous markup and cleanup resources.
  4119. *
  4120. * @since 2.34
  4121. */
  4122. destroy: function() {
  4123. this.widget.destroy();
  4124. },
  4125. /** Enable (or disable) the tree control.
  4126. *
  4127. * @param {boolean} [flag=true] pass false to disable
  4128. * @since 2.30
  4129. */
  4130. enable: function(flag) {
  4131. if (flag === false) {
  4132. this.widget.disable();
  4133. } else {
  4134. this.widget.enable();
  4135. }
  4136. },
  4137. /** Temporarily suppress rendering to improve performance on bulk-updates.
  4138. *
  4139. * @param {boolean} flag
  4140. * @returns {boolean} previous status
  4141. * @since 2.19
  4142. */
  4143. enableUpdate: function(flag) {
  4144. flag = flag !== false;
  4145. if (!!this._enableUpdate === !!flag) {
  4146. return flag;
  4147. }
  4148. this._enableUpdate = flag;
  4149. if (flag) {
  4150. this.debug("enableUpdate(true): redraw "); //, this._dirtyRoots);
  4151. this._callHook("treeStructureChanged", this, "enableUpdate");
  4152. this.render();
  4153. } else {
  4154. // this._dirtyRoots = null;
  4155. this.debug("enableUpdate(false)...");
  4156. }
  4157. return !flag; // return previous value
  4158. },
  4159. /** Write error to browser console if debugLevel >= 1 (prepending tree info)
  4160. *
  4161. * @param {*} msg string or object or array of such
  4162. */
  4163. error: function(msg) {
  4164. if (this.options.debugLevel >= 1) {
  4165. Array.prototype.unshift.call(arguments, this.toString());
  4166. consoleApply("error", arguments);
  4167. }
  4168. },
  4169. /** Expand (or collapse) all parent nodes.
  4170. *
  4171. * This convenience method uses `tree.visit()` and `tree.setExpanded()`
  4172. * internally.
  4173. *
  4174. * @param {boolean} [flag=true] pass false to collapse
  4175. * @param {object} [opts] passed to setExpanded()
  4176. * @since 2.30
  4177. */
  4178. expandAll: function(flag, opts) {
  4179. var prev = this.enableUpdate(false);
  4180. flag = flag !== false;
  4181. this.visit(function(node) {
  4182. if (
  4183. node.hasChildren() !== false &&
  4184. node.isExpanded() !== flag
  4185. ) {
  4186. node.setExpanded(flag, opts);
  4187. }
  4188. });
  4189. this.enableUpdate(prev);
  4190. },
  4191. /**Find all nodes that matches condition.
  4192. *
  4193. * @param {string | function(node)} match title string to search for, or a
  4194. * callback function that returns `true` if a node is matched.
  4195. * @returns {FancytreeNode[]} array of nodes (may be empty)
  4196. * @see FancytreeNode#findAll
  4197. * @since 2.12
  4198. */
  4199. findAll: function(match) {
  4200. return this.rootNode.findAll(match);
  4201. },
  4202. /**Find first node that matches condition.
  4203. *
  4204. * @param {string | function(node)} match title string to search for, or a
  4205. * callback function that returns `true` if a node is matched.
  4206. * @returns {FancytreeNode} matching node or null
  4207. * @see FancytreeNode#findFirst
  4208. * @since 2.12
  4209. */
  4210. findFirst: function(match) {
  4211. return this.rootNode.findFirst(match);
  4212. },
  4213. /** Find the next visible node that starts with `match`, starting at `startNode`
  4214. * and wrap-around at the end.
  4215. *
  4216. * @param {string|function} match
  4217. * @param {FancytreeNode} [startNode] defaults to first node
  4218. * @returns {FancytreeNode} matching node or null
  4219. */
  4220. findNextNode: function(match, startNode) {
  4221. //, visibleOnly) {
  4222. var res = null,
  4223. firstNode = this.getFirstChild();
  4224. match =
  4225. typeof match === "string"
  4226. ? _makeNodeTitleStartMatcher(match)
  4227. : match;
  4228. startNode = startNode || firstNode;
  4229. function _checkNode(n) {
  4230. // console.log("_check " + n)
  4231. if (match(n)) {
  4232. res = n;
  4233. }
  4234. if (res || n === startNode) {
  4235. return false;
  4236. }
  4237. }
  4238. this.visitRows(_checkNode, {
  4239. start: startNode,
  4240. includeSelf: false,
  4241. });
  4242. // Wrap around search
  4243. if (!res && startNode !== firstNode) {
  4244. this.visitRows(_checkNode, {
  4245. start: firstNode,
  4246. includeSelf: true,
  4247. });
  4248. }
  4249. return res;
  4250. },
  4251. /** Find a node relative to another node.
  4252. *
  4253. * @param {FancytreeNode} node
  4254. * @param {string|number} where 'down', 'first', 'last', 'left', 'parent', 'right', or 'up'.
  4255. * (Alternatively the keyCode that would normally trigger this move,
  4256. * e.g. `$.ui.keyCode.LEFT` = 'left'.
  4257. * @param {boolean} [includeHidden=false] Not yet implemented
  4258. * @returns {FancytreeNode|null}
  4259. * @since v2.31
  4260. */
  4261. findRelatedNode: function(node, where, includeHidden) {
  4262. var res = null,
  4263. KC = $.ui.keyCode;
  4264. switch (where) {
  4265. case "parent":
  4266. case KC.BACKSPACE:
  4267. if (node.parent && node.parent.parent) {
  4268. res = node.parent;
  4269. }
  4270. break;
  4271. case "first":
  4272. case KC.HOME:
  4273. // First visible node
  4274. this.visit(function(n) {
  4275. if (n.isVisible()) {
  4276. res = n;
  4277. return false;
  4278. }
  4279. });
  4280. break;
  4281. case "last":
  4282. case KC.END:
  4283. this.visit(function(n) {
  4284. // last visible node
  4285. if (n.isVisible()) {
  4286. res = n;
  4287. }
  4288. });
  4289. break;
  4290. case "left":
  4291. case KC.LEFT:
  4292. if (node.expanded) {
  4293. node.setExpanded(false);
  4294. } else if (node.parent && node.parent.parent) {
  4295. res = node.parent;
  4296. }
  4297. break;
  4298. case "right":
  4299. case KC.RIGHT:
  4300. if (!node.expanded && (node.children || node.lazy)) {
  4301. node.setExpanded();
  4302. res = node;
  4303. } else if (node.children && node.children.length) {
  4304. res = node.children[0];
  4305. }
  4306. break;
  4307. case "up":
  4308. case KC.UP:
  4309. this.visitRows(
  4310. function(n) {
  4311. res = n;
  4312. return false;
  4313. },
  4314. { start: node, reverse: true, includeSelf: false }
  4315. );
  4316. break;
  4317. case "down":
  4318. case KC.DOWN:
  4319. this.visitRows(
  4320. function(n) {
  4321. res = n;
  4322. return false;
  4323. },
  4324. { start: node, includeSelf: false }
  4325. );
  4326. break;
  4327. default:
  4328. this.tree.warn("Unknown relation '" + where + "'.");
  4329. }
  4330. return res;
  4331. },
  4332. // TODO: fromDict
  4333. /**
  4334. * Generate INPUT elements that can be submitted with html forms.
  4335. *
  4336. * In selectMode 3 only the topmost selected nodes are considered, unless
  4337. * `opts.stopOnParents: false` is passed.
  4338. *
  4339. * @example
  4340. * // Generate input elements for active and selected nodes
  4341. * tree.generateFormElements();
  4342. * // Generate input elements selected nodes, using a custom `name` attribute
  4343. * tree.generateFormElements("cust_sel", false);
  4344. * // Generate input elements using a custom filter
  4345. * tree.generateFormElements(true, true, { filter: function(node) {
  4346. * return node.isSelected() && node.data.yes;
  4347. * }});
  4348. *
  4349. * @param {boolean | string} [selected=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID[]')
  4350. * @param {boolean | string} [active=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID_active')
  4351. * @param {object} [opts] default { filter: null, stopOnParents: true }
  4352. */
  4353. generateFormElements: function(selected, active, opts) {
  4354. opts = opts || {};
  4355. var nodeList,
  4356. selectedName =
  4357. typeof selected === "string"
  4358. ? selected
  4359. : "ft_" + this._id + "[]",
  4360. activeName =
  4361. typeof active === "string"
  4362. ? active
  4363. : "ft_" + this._id + "_active",
  4364. id = "fancytree_result_" + this._id,
  4365. $result = $("#" + id),
  4366. stopOnParents =
  4367. this.options.selectMode === 3 &&
  4368. opts.stopOnParents !== false;
  4369. if ($result.length) {
  4370. $result.empty();
  4371. } else {
  4372. $result = $("<div>", {
  4373. id: id,
  4374. })
  4375. .hide()
  4376. .insertAfter(this.$container);
  4377. }
  4378. if (active !== false && this.activeNode) {
  4379. $result.append(
  4380. $("<input>", {
  4381. type: "radio",
  4382. name: activeName,
  4383. value: this.activeNode.key,
  4384. checked: true,
  4385. })
  4386. );
  4387. }
  4388. function _appender(node) {
  4389. $result.append(
  4390. $("<input>", {
  4391. type: "checkbox",
  4392. name: selectedName,
  4393. value: node.key,
  4394. checked: true,
  4395. })
  4396. );
  4397. }
  4398. if (opts.filter) {
  4399. this.visit(function(node) {
  4400. var res = opts.filter(node);
  4401. if (res === "skip") {
  4402. return res;
  4403. }
  4404. if (res !== false) {
  4405. _appender(node);
  4406. }
  4407. });
  4408. } else if (selected !== false) {
  4409. nodeList = this.getSelectedNodes(stopOnParents);
  4410. $.each(nodeList, function(idx, node) {
  4411. _appender(node);
  4412. });
  4413. }
  4414. },
  4415. /**
  4416. * Return the currently active node or null.
  4417. * @returns {FancytreeNode}
  4418. */
  4419. getActiveNode: function() {
  4420. return this.activeNode;
  4421. },
  4422. /** Return the first top level node if any (not the invisible root node).
  4423. * @returns {FancytreeNode | null}
  4424. */
  4425. getFirstChild: function() {
  4426. return this.rootNode.getFirstChild();
  4427. },
  4428. /**
  4429. * Return node that has keyboard focus or null.
  4430. * @returns {FancytreeNode}
  4431. */
  4432. getFocusNode: function() {
  4433. return this.focusNode;
  4434. },
  4435. /**
  4436. * Return current option value.
  4437. * (Note: this is the preferred variant of `$().fancytree("option", "KEY")`)
  4438. *
  4439. * @param {string} name option name (may contain '.')
  4440. * @returns {any}
  4441. */
  4442. getOption: function(optionName) {
  4443. return this.widget.option(optionName);
  4444. },
  4445. /**
  4446. * Return node with a given key or null if not found.
  4447. *
  4448. * @param {string} key
  4449. * @param {FancytreeNode} [searchRoot] only search below this node
  4450. * @returns {FancytreeNode | null}
  4451. */
  4452. getNodeByKey: function(key, searchRoot) {
  4453. // Search the DOM by element ID (assuming this is faster than traversing all nodes).
  4454. var el, match;
  4455. // TODO: use tree.keyMap if available
  4456. // TODO: check opts.generateIds === true
  4457. if (!searchRoot) {
  4458. el = document.getElementById(this.options.idPrefix + key);
  4459. if (el) {
  4460. return el.ftnode ? el.ftnode : null;
  4461. }
  4462. }
  4463. // Not found in the DOM, but still may be in an unrendered part of tree
  4464. searchRoot = searchRoot || this.rootNode;
  4465. match = null;
  4466. key = "" + key; // Convert to string (#1005)
  4467. searchRoot.visit(function(node) {
  4468. if (node.key === key) {
  4469. match = node;
  4470. return false; // Stop iteration
  4471. }
  4472. }, true);
  4473. return match;
  4474. },
  4475. /** Return the invisible system root node.
  4476. * @returns {FancytreeNode}
  4477. */
  4478. getRootNode: function() {
  4479. return this.rootNode;
  4480. },
  4481. /**
  4482. * Return an array of selected nodes.
  4483. *
  4484. * Note: you cannot send this result via Ajax directly. Instead the
  4485. * node object need to be converted to plain objects, for example
  4486. * by using `$.map()` and `node.toDict()`.
  4487. * @param {boolean} [stopOnParents=false] only return the topmost selected
  4488. * node (useful with selectMode 3)
  4489. * @returns {FancytreeNode[]}
  4490. */
  4491. getSelectedNodes: function(stopOnParents) {
  4492. return this.rootNode.getSelectedNodes(stopOnParents);
  4493. },
  4494. /** Return true if the tree control has keyboard focus
  4495. * @returns {boolean}
  4496. */
  4497. hasFocus: function() {
  4498. // var ae = document.activeElement,
  4499. // hasFocus = !!(
  4500. // ae && $(ae).closest(".fancytree-container").length
  4501. // );
  4502. // if (hasFocus !== !!this._hasFocus) {
  4503. // this.warn(
  4504. // "hasFocus(): fix inconsistent container state, now: " +
  4505. // hasFocus
  4506. // );
  4507. // this._hasFocus = hasFocus;
  4508. // this.$container.toggleClass("fancytree-treefocus", hasFocus);
  4509. // }
  4510. // return hasFocus;
  4511. return !!this._hasFocus;
  4512. },
  4513. /** Write to browser console if debugLevel >= 3 (prepending tree name)
  4514. * @param {*} msg string or object or array of such
  4515. */
  4516. info: function(msg) {
  4517. if (this.options.debugLevel >= 3) {
  4518. Array.prototype.unshift.call(arguments, this.toString());
  4519. consoleApply("info", arguments);
  4520. }
  4521. },
  4522. /** Return true if any node is currently beeing loaded, i.e. a Ajax request is pending.
  4523. * @returns {boolean}
  4524. * @since 2.32
  4525. */
  4526. isLoading: function() {
  4527. var res = false;
  4528. this.rootNode.visit(function(n) {
  4529. // also visit rootNode
  4530. if (n._isLoading || n._requestId) {
  4531. res = true;
  4532. return false;
  4533. }
  4534. }, true);
  4535. return res;
  4536. },
  4537. /*
  4538. TODO: isInitializing: function() {
  4539. return ( this.phase=="init" || this.phase=="postInit" );
  4540. },
  4541. TODO: isReloading: function() {
  4542. return ( this.phase=="init" || this.phase=="postInit" ) && this.options.persist && this.persistence.cookiesFound;
  4543. },
  4544. TODO: isUserEvent: function() {
  4545. return ( this.phase=="userEvent" );
  4546. },
  4547. */
  4548. /**
  4549. * Make sure that a node with a given ID is loaded, by traversing - and
  4550. * loading - its parents. This method is meant for lazy hierarchies.
  4551. * A callback is executed for every node as we go.
  4552. * @example
  4553. * // Resolve using node.key:
  4554. * tree.loadKeyPath("/_3/_23/_26/_27", function(node, status){
  4555. * if(status === "loaded") {
  4556. * console.log("loaded intermediate node " + node);
  4557. * }else if(status === "ok") {
  4558. * node.activate();
  4559. * }
  4560. * });
  4561. * // Use deferred promise:
  4562. * tree.loadKeyPath("/_3/_23/_26/_27").progress(function(data){
  4563. * if(data.status === "loaded") {
  4564. * console.log("loaded intermediate node " + data.node);
  4565. * }else if(data.status === "ok") {
  4566. * node.activate();
  4567. * }
  4568. * }).done(function(){
  4569. * ...
  4570. * });
  4571. * // Custom path segment resolver:
  4572. * tree.loadKeyPath("/321/431/21/2", {
  4573. * matchKey: function(node, key){
  4574. * return node.data.refKey === key;
  4575. * },
  4576. * callback: function(node, status){
  4577. * if(status === "loaded") {
  4578. * console.log("loaded intermediate node " + node);
  4579. * }else if(status === "ok") {
  4580. * node.activate();
  4581. * }
  4582. * }
  4583. * });
  4584. * @param {string | string[]} keyPathList one or more key paths (e.g. '/3/2_1/7')
  4585. * @param {function | object} optsOrCallback callback(node, status) is called for every visited node ('loading', 'loaded', 'ok', 'error').
  4586. * Pass an object to define custom key matchers for the path segments: {callback: function, matchKey: function}.
  4587. * @returns {$.Promise}
  4588. */
  4589. loadKeyPath: function(keyPathList, optsOrCallback) {
  4590. var callback,
  4591. i,
  4592. path,
  4593. self = this,
  4594. dfd = new $.Deferred(),
  4595. parent = this.getRootNode(),
  4596. sep = this.options.keyPathSeparator,
  4597. pathSegList = [],
  4598. opts = $.extend({}, optsOrCallback);
  4599. // Prepare options
  4600. if (typeof optsOrCallback === "function") {
  4601. callback = optsOrCallback;
  4602. } else if (optsOrCallback && optsOrCallback.callback) {
  4603. callback = optsOrCallback.callback;
  4604. }
  4605. opts.callback = function(ctx, node, status) {
  4606. if (callback) {
  4607. callback.call(ctx, node, status);
  4608. }
  4609. dfd.notifyWith(ctx, [{ node: node, status: status }]);
  4610. };
  4611. if (opts.matchKey == null) {
  4612. opts.matchKey = function(node, key) {
  4613. return node.key === key;
  4614. };
  4615. }
  4616. // Convert array of path strings to array of segment arrays
  4617. if (!$.isArray(keyPathList)) {
  4618. keyPathList = [keyPathList];
  4619. }
  4620. for (i = 0; i < keyPathList.length; i++) {
  4621. path = keyPathList[i];
  4622. // strip leading slash
  4623. if (path.charAt(0) === sep) {
  4624. path = path.substr(1);
  4625. }
  4626. // segListMap[path] = { parent: parent, segList: path.split(sep) };
  4627. pathSegList.push(path.split(sep));
  4628. // targetList.push({ parent: parent, segList: path.split(sep)/* , path: path*/});
  4629. }
  4630. // The timeout forces async behavior always (even if nodes are all loaded)
  4631. // This way a potential progress() event will fire.
  4632. setTimeout(function() {
  4633. self._loadKeyPathImpl(dfd, opts, parent, pathSegList).done(
  4634. function() {
  4635. dfd.resolve();
  4636. }
  4637. );
  4638. }, 0);
  4639. return dfd.promise();
  4640. },
  4641. /*
  4642. * Resolve a list of paths, relative to one parent node.
  4643. */
  4644. _loadKeyPathImpl: function(dfd, opts, parent, pathSegList) {
  4645. var deferredList,
  4646. i,
  4647. key,
  4648. node,
  4649. nodeKey,
  4650. remain,
  4651. remainMap,
  4652. tmpParent,
  4653. segList,
  4654. subDfd,
  4655. self = this;
  4656. function __findChild(parent, key) {
  4657. // console.log("__findChild", key, parent);
  4658. var i,
  4659. l,
  4660. cl = parent.children;
  4661. if (cl) {
  4662. for (i = 0, l = cl.length; i < l; i++) {
  4663. if (opts.matchKey(cl[i], key)) {
  4664. return cl[i];
  4665. }
  4666. }
  4667. }
  4668. return null;
  4669. }
  4670. // console.log("_loadKeyPathImpl, parent=", parent, ", pathSegList=", pathSegList);
  4671. // Pass 1:
  4672. // Handle all path segments for nodes that are already loaded.
  4673. // Collect distinct top-most lazy nodes in a map.
  4674. // Note that we can use node.key to de-dupe entries, even if a custom matcher would
  4675. // look for other node attributes.
  4676. // map[node.key] => {node: node, pathList: [list of remaining rest-paths]}
  4677. remainMap = {};
  4678. for (i = 0; i < pathSegList.length; i++) {
  4679. segList = pathSegList[i];
  4680. // target = targetList[i];
  4681. // Traverse and pop path segments (i.e. keys), until we hit a lazy, unloaded node
  4682. tmpParent = parent;
  4683. while (segList.length) {
  4684. key = segList.shift();
  4685. node = __findChild(tmpParent, key);
  4686. if (!node) {
  4687. this.warn(
  4688. "loadKeyPath: key not found: " +
  4689. key +
  4690. " (parent: " +
  4691. tmpParent +
  4692. ")"
  4693. );
  4694. opts.callback(this, key, "error");
  4695. break;
  4696. } else if (segList.length === 0) {
  4697. opts.callback(this, node, "ok");
  4698. break;
  4699. } else if (!node.lazy || node.hasChildren() !== undefined) {
  4700. opts.callback(this, node, "loaded");
  4701. tmpParent = node;
  4702. } else {
  4703. opts.callback(this, node, "loaded");
  4704. key = node.key; //target.segList.join(sep);
  4705. if (remainMap[key]) {
  4706. remainMap[key].pathSegList.push(segList);
  4707. } else {
  4708. remainMap[key] = {
  4709. parent: node,
  4710. pathSegList: [segList],
  4711. };
  4712. }
  4713. break;
  4714. }
  4715. }
  4716. }
  4717. // console.log("_loadKeyPathImpl AFTER pass 1, remainMap=", remainMap);
  4718. // Now load all lazy nodes and continue iteration for remaining paths
  4719. deferredList = [];
  4720. // Avoid jshint warning 'Don't make functions within a loop.':
  4721. function __lazyload(dfd, parent, pathSegList) {
  4722. // console.log("__lazyload", parent, "pathSegList=", pathSegList);
  4723. opts.callback(self, parent, "loading");
  4724. parent
  4725. .load()
  4726. .done(function() {
  4727. self._loadKeyPathImpl
  4728. .call(self, dfd, opts, parent, pathSegList)
  4729. .always(_makeResolveFunc(dfd, self));
  4730. })
  4731. .fail(function(errMsg) {
  4732. self.warn("loadKeyPath: error loading lazy " + parent);
  4733. opts.callback(self, node, "error");
  4734. dfd.rejectWith(self);
  4735. });
  4736. }
  4737. // remainMap contains parent nodes, each with a list of relative sub-paths.
  4738. // We start loading all of them now, and pass the the list to each loader.
  4739. for (nodeKey in remainMap) {
  4740. if (remainMap.hasOwnProperty(nodeKey)) {
  4741. remain = remainMap[nodeKey];
  4742. // console.log("for(): remain=", remain, "remainMap=", remainMap);
  4743. // key = remain.segList.shift();
  4744. // node = __findChild(remain.parent, key);
  4745. // if (node == null) { // #576
  4746. // // Issue #576, refactored for v2.27:
  4747. // // The root cause was, that sometimes the wrong parent was used here
  4748. // // to find the next segment.
  4749. // // Falling back to getNodeByKey() was a hack that no longer works if a custom
  4750. // // matcher is used, because we cannot assume that a single segment-key is unique
  4751. // // throughout the tree.
  4752. // self.error("loadKeyPath: error loading child by key '" + key + "' (parent: " + target.parent + ")", target);
  4753. // // node = self.getNodeByKey(key);
  4754. // continue;
  4755. // }
  4756. subDfd = new $.Deferred();
  4757. deferredList.push(subDfd);
  4758. __lazyload(subDfd, remain.parent, remain.pathSegList);
  4759. }
  4760. }
  4761. // Return a promise that is resolved, when ALL paths were loaded
  4762. return $.when.apply($, deferredList).promise();
  4763. },
  4764. /** Re-fire beforeActivate, activate, and (optional) focus events.
  4765. * Calling this method in the `init` event, will activate the node that
  4766. * was marked 'active' in the source data, and optionally set the keyboard
  4767. * focus.
  4768. * @param [setFocus=false]
  4769. */
  4770. reactivate: function(setFocus) {
  4771. var res,
  4772. node = this.activeNode;
  4773. if (!node) {
  4774. return _getResolvedPromise();
  4775. }
  4776. this.activeNode = null; // Force re-activating
  4777. res = node.setActive(true, { noFocus: true });
  4778. if (setFocus) {
  4779. node.setFocus();
  4780. }
  4781. return res;
  4782. },
  4783. /** Reload tree from source and return a promise.
  4784. * @param [source] optional new source (defaults to initial source data)
  4785. * @returns {$.Promise}
  4786. */
  4787. reload: function(source) {
  4788. this._callHook("treeClear", this);
  4789. return this._callHook("treeLoad", this, source);
  4790. },
  4791. /**Render tree (i.e. create DOM elements for all top-level nodes).
  4792. * @param {boolean} [force=false] create DOM elemnts, even if parent is collapsed
  4793. * @param {boolean} [deep=false]
  4794. */
  4795. render: function(force, deep) {
  4796. return this.rootNode.render(force, deep);
  4797. },
  4798. /**(De)select all nodes.
  4799. * @param {boolean} [flag=true]
  4800. * @since 2.28
  4801. */
  4802. selectAll: function(flag) {
  4803. this.visit(function(node) {
  4804. node.setSelected(flag);
  4805. });
  4806. },
  4807. // TODO: selectKey: function(key, select)
  4808. // TODO: serializeArray: function(stopOnParents)
  4809. /**
  4810. * @param {boolean} [flag=true]
  4811. */
  4812. setFocus: function(flag) {
  4813. return this._callHook("treeSetFocus", this, flag);
  4814. },
  4815. /**
  4816. * Set current option value.
  4817. * (Note: this is the preferred variant of `$().fancytree("option", "KEY", VALUE)`)
  4818. * @param {string} name option name (may contain '.')
  4819. * @param {any} new value
  4820. */
  4821. setOption: function(optionName, value) {
  4822. return this.widget.option(optionName, value);
  4823. },
  4824. /**
  4825. * Call console.time() when in debug mode (verbose >= 4).
  4826. *
  4827. * @param {string} label
  4828. */
  4829. debugTime: function(label) {
  4830. if (this.options.debugLevel >= 4) {
  4831. window.console.time(this + " - " + label);
  4832. }
  4833. },
  4834. /**
  4835. * Call console.timeEnd() when in debug mode (verbose >= 4).
  4836. *
  4837. * @param {string} label
  4838. */
  4839. debugTimeEnd: function(label) {
  4840. if (this.options.debugLevel >= 4) {
  4841. window.console.timeEnd(this + " - " + label);
  4842. }
  4843. },
  4844. /**
  4845. * Return all nodes as nested list of {@link NodeData}.
  4846. *
  4847. * @param {boolean} [includeRoot=false] Returns the hidden system root node (and its children)
  4848. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications.
  4849. * Return `false` to ignore this node or "skip" to include this node without its children.
  4850. * @returns {Array | object}
  4851. * @see FancytreeNode#toDict
  4852. */
  4853. toDict: function(includeRoot, callback) {
  4854. var res = this.rootNode.toDict(true, callback);
  4855. return includeRoot ? res : res.children;
  4856. },
  4857. /* Implicitly called for string conversions.
  4858. * @returns {string}
  4859. */
  4860. toString: function() {
  4861. return "Fancytree@" + this._id;
  4862. // return "<Fancytree(#" + this._id + ")>";
  4863. },
  4864. /* _trigger a widget event with additional node ctx.
  4865. * @see EventData
  4866. */
  4867. _triggerNodeEvent: function(type, node, originalEvent, extra) {
  4868. // this.debug("_trigger(" + type + "): '" + ctx.node.title + "'", ctx);
  4869. var ctx = this._makeHookContext(node, originalEvent, extra),
  4870. res = this.widget._trigger(type, originalEvent, ctx);
  4871. if (res !== false && ctx.result !== undefined) {
  4872. return ctx.result;
  4873. }
  4874. return res;
  4875. },
  4876. /* _trigger a widget event with additional tree data. */
  4877. _triggerTreeEvent: function(type, originalEvent, extra) {
  4878. // this.debug("_trigger(" + type + ")", ctx);
  4879. var ctx = this._makeHookContext(this, originalEvent, extra),
  4880. res = this.widget._trigger(type, originalEvent, ctx);
  4881. if (res !== false && ctx.result !== undefined) {
  4882. return ctx.result;
  4883. }
  4884. return res;
  4885. },
  4886. /** Call fn(node) for all nodes in hierarchical order (depth-first).
  4887. *
  4888. * @param {function} fn the callback function.
  4889. * Return false to stop iteration, return "skip" to skip this node and children only.
  4890. * @returns {boolean} false, if the iterator was stopped.
  4891. */
  4892. visit: function(fn) {
  4893. return this.rootNode.visit(fn, false);
  4894. },
  4895. /** Call fn(node) for all nodes in vertical order, top down (or bottom up).<br>
  4896. * Stop iteration, if fn() returns false.<br>
  4897. * Return false if iteration was stopped.
  4898. *
  4899. * @param {function} fn the callback function.
  4900. * Return false to stop iteration, return "skip" to skip this node and children only.
  4901. * @param {object} [options]
  4902. * Defaults:
  4903. * {start: First top node, reverse: false, includeSelf: true, includeHidden: false}
  4904. * @returns {boolean} false if iteration was cancelled
  4905. * @since 2.28
  4906. */
  4907. visitRows: function(fn, opts) {
  4908. if (!this.rootNode.hasChildren()) {
  4909. return false;
  4910. }
  4911. if (opts && opts.reverse) {
  4912. delete opts.reverse;
  4913. return this._visitRowsUp(fn, opts);
  4914. }
  4915. opts = opts || {};
  4916. var i,
  4917. nextIdx,
  4918. parent,
  4919. res,
  4920. siblings,
  4921. siblingOfs = 0,
  4922. skipFirstNode = opts.includeSelf === false,
  4923. includeHidden = !!opts.includeHidden,
  4924. checkFilter = !includeHidden && this.enableFilter,
  4925. node = opts.start || this.rootNode.children[0];
  4926. parent = node.parent;
  4927. while (parent) {
  4928. // visit siblings
  4929. siblings = parent.children;
  4930. nextIdx = siblings.indexOf(node) + siblingOfs;
  4931. _assert(
  4932. nextIdx >= 0,
  4933. "Could not find " +
  4934. node +
  4935. " in parent's children: " +
  4936. parent
  4937. );
  4938. for (i = nextIdx; i < siblings.length; i++) {
  4939. node = siblings[i];
  4940. if (checkFilter && !node.match && !node.subMatchCount) {
  4941. continue;
  4942. }
  4943. if (!skipFirstNode && fn(node) === false) {
  4944. return false;
  4945. }
  4946. skipFirstNode = false;
  4947. // Dive into node's child nodes
  4948. if (
  4949. node.children &&
  4950. node.children.length &&
  4951. (includeHidden || node.expanded)
  4952. ) {
  4953. // Disable warning: Functions declared within loops referencing an outer
  4954. // scoped variable may lead to confusing semantics:
  4955. /*jshint -W083 */
  4956. res = node.visit(function(n) {
  4957. if (checkFilter && !n.match && !n.subMatchCount) {
  4958. return "skip";
  4959. }
  4960. if (fn(n) === false) {
  4961. return false;
  4962. }
  4963. if (!includeHidden && n.children && !n.expanded) {
  4964. return "skip";
  4965. }
  4966. }, false);
  4967. /*jshint +W083 */
  4968. if (res === false) {
  4969. return false;
  4970. }
  4971. }
  4972. }
  4973. // Visit parent nodes (bottom up)
  4974. node = parent;
  4975. parent = parent.parent;
  4976. siblingOfs = 1; //
  4977. }
  4978. return true;
  4979. },
  4980. /* Call fn(node) for all nodes in vertical order, bottom up.
  4981. */
  4982. _visitRowsUp: function(fn, opts) {
  4983. var children,
  4984. idx,
  4985. parent,
  4986. includeHidden = !!opts.includeHidden,
  4987. node = opts.start || this.rootNode.children[0];
  4988. while (true) {
  4989. parent = node.parent;
  4990. children = parent.children;
  4991. if (children[0] === node) {
  4992. // If this is already the first sibling, goto parent
  4993. node = parent;
  4994. if (!node.parent) {
  4995. break; // first node of the tree
  4996. }
  4997. children = parent.children;
  4998. } else {
  4999. // Otherwise, goto prev. sibling
  5000. idx = children.indexOf(node);
  5001. node = children[idx - 1];
  5002. // If the prev. sibling has children, follow down to last descendant
  5003. while (
  5004. // See: https://github.com/eslint/eslint/issues/11302
  5005. // eslint-disable-next-line no-unmodified-loop-condition
  5006. (includeHidden || node.expanded) &&
  5007. node.children &&
  5008. node.children.length
  5009. ) {
  5010. children = node.children;
  5011. parent = node;
  5012. node = children[children.length - 1];
  5013. }
  5014. }
  5015. // Skip invisible
  5016. if (!includeHidden && !node.isVisible()) {
  5017. continue;
  5018. }
  5019. if (fn(node) === false) {
  5020. return false;
  5021. }
  5022. }
  5023. },
  5024. /** Write warning to browser console if debugLevel >= 2 (prepending tree info)
  5025. *
  5026. * @param {*} msg string or object or array of such
  5027. */
  5028. warn: function(msg) {
  5029. if (this.options.debugLevel >= 2) {
  5030. Array.prototype.unshift.call(arguments, this.toString());
  5031. consoleApply("warn", arguments);
  5032. }
  5033. },
  5034. };
  5035. /**
  5036. * These additional methods of the {@link Fancytree} class are 'hook functions'
  5037. * that can be used and overloaded by extensions.
  5038. *
  5039. * @see [writing extensions](https://github.com/mar10/fancytree/wiki/TutorialExtensions)
  5040. * @mixin Fancytree_Hooks
  5041. */
  5042. $.extend(
  5043. Fancytree.prototype,
  5044. /** @lends Fancytree_Hooks# */
  5045. {
  5046. /** Default handling for mouse click events.
  5047. *
  5048. * @param {EventData} ctx
  5049. */
  5050. nodeClick: function(ctx) {
  5051. var activate,
  5052. expand,
  5053. // event = ctx.originalEvent,
  5054. targetType = ctx.targetType,
  5055. node = ctx.node;
  5056. // this.debug("ftnode.onClick(" + event.type + "): ftnode:" + this + ", button:" + event.button + ", which: " + event.which, ctx);
  5057. // TODO: use switch
  5058. // TODO: make sure clicks on embedded <input> doesn't steal focus (see table sample)
  5059. if (targetType === "expander") {
  5060. if (node.isLoading()) {
  5061. // #495: we probably got a click event while a lazy load is pending.
  5062. // The 'expanded' state is not yet set, so 'toggle' would expand
  5063. // and trigger lazyLoad again.
  5064. // It would be better to allow to collapse/expand the status node
  5065. // while loading (instead of ignoring), but that would require some
  5066. // more work.
  5067. node.debug("Got 2nd click while loading: ignored");
  5068. return;
  5069. }
  5070. // Clicking the expander icon always expands/collapses
  5071. this._callHook("nodeToggleExpanded", ctx);
  5072. } else if (targetType === "checkbox") {
  5073. // Clicking the checkbox always (de)selects
  5074. this._callHook("nodeToggleSelected", ctx);
  5075. if (ctx.options.focusOnSelect) {
  5076. // #358
  5077. this._callHook("nodeSetFocus", ctx, true);
  5078. }
  5079. } else {
  5080. // Honor `clickFolderMode` for
  5081. expand = false;
  5082. activate = true;
  5083. if (node.folder) {
  5084. switch (ctx.options.clickFolderMode) {
  5085. case 2: // expand only
  5086. expand = true;
  5087. activate = false;
  5088. break;
  5089. case 3: // expand and activate
  5090. activate = true;
  5091. expand = true; //!node.isExpanded();
  5092. break;
  5093. // else 1 or 4: just activate
  5094. }
  5095. }
  5096. if (activate) {
  5097. this.nodeSetFocus(ctx);
  5098. this._callHook("nodeSetActive", ctx, true);
  5099. }
  5100. if (expand) {
  5101. if (!activate) {
  5102. // this._callHook("nodeSetFocus", ctx);
  5103. }
  5104. // this._callHook("nodeSetExpanded", ctx, true);
  5105. this._callHook("nodeToggleExpanded", ctx);
  5106. }
  5107. }
  5108. // Make sure that clicks stop, otherwise <a href='#'> jumps to the top
  5109. // if(event.target.localName === "a" && event.target.className === "fancytree-title"){
  5110. // event.preventDefault();
  5111. // }
  5112. // TODO: return promise?
  5113. },
  5114. /** Collapse all other children of same parent.
  5115. *
  5116. * @param {EventData} ctx
  5117. * @param {object} callOpts
  5118. */
  5119. nodeCollapseSiblings: function(ctx, callOpts) {
  5120. // TODO: return promise?
  5121. var ac,
  5122. i,
  5123. l,
  5124. node = ctx.node;
  5125. if (node.parent) {
  5126. ac = node.parent.children;
  5127. for (i = 0, l = ac.length; i < l; i++) {
  5128. if (ac[i] !== node && ac[i].expanded) {
  5129. this._callHook(
  5130. "nodeSetExpanded",
  5131. ac[i],
  5132. false,
  5133. callOpts
  5134. );
  5135. }
  5136. }
  5137. }
  5138. },
  5139. /** Default handling for mouse douleclick events.
  5140. * @param {EventData} ctx
  5141. */
  5142. nodeDblclick: function(ctx) {
  5143. // TODO: return promise?
  5144. if (
  5145. ctx.targetType === "title" &&
  5146. ctx.options.clickFolderMode === 4
  5147. ) {
  5148. // this.nodeSetFocus(ctx);
  5149. // this._callHook("nodeSetActive", ctx, true);
  5150. this._callHook("nodeToggleExpanded", ctx);
  5151. }
  5152. // TODO: prevent text selection on dblclicks
  5153. if (ctx.targetType === "title") {
  5154. ctx.originalEvent.preventDefault();
  5155. }
  5156. },
  5157. /** Default handling for mouse keydown events.
  5158. *
  5159. * NOTE: this may be called with node == null if tree (but no node) has focus.
  5160. * @param {EventData} ctx
  5161. */
  5162. nodeKeydown: function(ctx) {
  5163. // TODO: return promise?
  5164. var matchNode,
  5165. stamp,
  5166. _res,
  5167. focusNode,
  5168. event = ctx.originalEvent,
  5169. node = ctx.node,
  5170. tree = ctx.tree,
  5171. opts = ctx.options,
  5172. which = event.which,
  5173. // #909: Use event.key, to get unicode characters.
  5174. // We can't use `/\w/.test(key)`, because that would
  5175. // only detect plain ascii alpha-numerics. But we still need
  5176. // to ignore modifier-only, whitespace, cursor-keys, etc.
  5177. key = event.key || String.fromCharCode(which),
  5178. specialModifiers = !!(
  5179. event.altKey ||
  5180. event.ctrlKey ||
  5181. event.metaKey
  5182. ),
  5183. isAlnum =
  5184. !MODIFIERS[which] &&
  5185. !SPECIAL_KEYCODES[which] &&
  5186. !specialModifiers,
  5187. $target = $(event.target),
  5188. handled = true,
  5189. activate = !(event.ctrlKey || !opts.autoActivate);
  5190. // (node || FT).debug("ftnode.nodeKeydown(" + event.type + "): ftnode:" + this + ", charCode:" + event.charCode + ", keyCode: " + event.keyCode + ", which: " + event.which);
  5191. // FT.debug( "eventToString(): " + FT.eventToString(event) + ", key='" + key + "', isAlnum: " + isAlnum );
  5192. // Set focus to active (or first node) if no other node has the focus yet
  5193. if (!node) {
  5194. focusNode = this.getActiveNode() || this.getFirstChild();
  5195. if (focusNode) {
  5196. focusNode.setFocus();
  5197. node = ctx.node = this.focusNode;
  5198. node.debug("Keydown force focus on active node");
  5199. }
  5200. }
  5201. if (
  5202. opts.quicksearch &&
  5203. isAlnum &&
  5204. !$target.is(":input:enabled")
  5205. ) {
  5206. // Allow to search for longer streaks if typed in quickly
  5207. stamp = Date.now();
  5208. if (stamp - tree.lastQuicksearchTime > 500) {
  5209. tree.lastQuicksearchTerm = "";
  5210. }
  5211. tree.lastQuicksearchTime = stamp;
  5212. tree.lastQuicksearchTerm += key;
  5213. // tree.debug("quicksearch find", tree.lastQuicksearchTerm);
  5214. matchNode = tree.findNextNode(
  5215. tree.lastQuicksearchTerm,
  5216. tree.getActiveNode()
  5217. );
  5218. if (matchNode) {
  5219. matchNode.setActive();
  5220. }
  5221. event.preventDefault();
  5222. return;
  5223. }
  5224. switch (FT.eventToString(event)) {
  5225. case "+":
  5226. case "=": // 187: '+' @ Chrome, Safari
  5227. tree.nodeSetExpanded(ctx, true);
  5228. break;
  5229. case "-":
  5230. tree.nodeSetExpanded(ctx, false);
  5231. break;
  5232. case "space":
  5233. if (node.isPagingNode()) {
  5234. tree._triggerNodeEvent("clickPaging", ctx, event);
  5235. } else if (
  5236. FT.evalOption("checkbox", node, node, opts, false)
  5237. ) {
  5238. // #768
  5239. tree.nodeToggleSelected(ctx);
  5240. } else {
  5241. tree.nodeSetActive(ctx, true);
  5242. }
  5243. break;
  5244. case "return":
  5245. tree.nodeSetActive(ctx, true);
  5246. break;
  5247. case "home":
  5248. case "end":
  5249. case "backspace":
  5250. case "left":
  5251. case "right":
  5252. case "up":
  5253. case "down":
  5254. _res = node.navigate(event.which, activate);
  5255. break;
  5256. default:
  5257. handled = false;
  5258. }
  5259. if (handled) {
  5260. event.preventDefault();
  5261. }
  5262. },
  5263. // /** Default handling for mouse keypress events. */
  5264. // nodeKeypress: function(ctx) {
  5265. // var event = ctx.originalEvent;
  5266. // },
  5267. // /** Trigger lazyLoad event (async). */
  5268. // nodeLazyLoad: function(ctx) {
  5269. // var node = ctx.node;
  5270. // if(this._triggerNodeEvent())
  5271. // },
  5272. /** Load child nodes (async).
  5273. *
  5274. * @param {EventData} ctx
  5275. * @param {object[]|object|string|$.Promise|function} source
  5276. * @returns {$.Promise} The deferred will be resolved as soon as the (ajax)
  5277. * data was rendered.
  5278. */
  5279. nodeLoadChildren: function(ctx, source) {
  5280. var ajax,
  5281. delay,
  5282. ajaxDfd = null,
  5283. resultDfd,
  5284. isAsync = true,
  5285. tree = ctx.tree,
  5286. node = ctx.node,
  5287. nodePrevParent = node.parent,
  5288. tag = "nodeLoadChildren",
  5289. requestId = Date.now();
  5290. // `source` is a callback: use the returned result instead:
  5291. if ($.isFunction(source)) {
  5292. source = source.call(tree, { type: "source" }, ctx);
  5293. _assert(
  5294. !$.isFunction(source),
  5295. "source callback must not return another function"
  5296. );
  5297. }
  5298. // `source` is already a promise:
  5299. if ($.isFunction(source.then)) {
  5300. // _assert($.isFunction(source.always), "Expected jQuery?");
  5301. ajaxDfd = source;
  5302. } else if (source.url) {
  5303. // `source` is an Ajax options object
  5304. ajax = $.extend({}, ctx.options.ajax, source);
  5305. if (ajax.debugDelay) {
  5306. // Simulate a slow server
  5307. delay = ajax.debugDelay;
  5308. delete ajax.debugDelay; // remove debug option
  5309. if ($.isArray(delay)) {
  5310. // random delay range [min..max]
  5311. delay =
  5312. delay[0] +
  5313. Math.random() * (delay[1] - delay[0]);
  5314. }
  5315. node.warn(
  5316. "nodeLoadChildren waiting debugDelay " +
  5317. Math.round(delay) +
  5318. " ms ..."
  5319. );
  5320. ajaxDfd = $.Deferred(function(ajaxDfd) {
  5321. setTimeout(function() {
  5322. $.ajax(ajax)
  5323. .done(function() {
  5324. ajaxDfd.resolveWith(this, arguments);
  5325. })
  5326. .fail(function() {
  5327. ajaxDfd.rejectWith(this, arguments);
  5328. });
  5329. }, delay);
  5330. });
  5331. } else {
  5332. ajaxDfd = $.ajax(ajax);
  5333. }
  5334. } else if ($.isPlainObject(source) || $.isArray(source)) {
  5335. // `source` is already a constant dict or list, but we convert
  5336. // to a thenable for unified processing.
  5337. // 2020-01-03: refactored.
  5338. // `ajaxDfd = $.when(source)` would do the trick, but the returned
  5339. // promise will resolve async, which broke some tests and
  5340. // would probably also break current implementations out there.
  5341. // So we mock-up a thenable that resolves synchronously:
  5342. ajaxDfd = {
  5343. then: function(resolve, reject) {
  5344. resolve(source, null, null);
  5345. },
  5346. };
  5347. isAsync = false;
  5348. } else {
  5349. $.error("Invalid source type: " + source);
  5350. }
  5351. // Check for overlapping requests
  5352. if (node._requestId) {
  5353. node.warn(
  5354. "Recursive load request #" +
  5355. requestId +
  5356. " while #" +
  5357. node._requestId +
  5358. " is pending."
  5359. );
  5360. node._requestId = requestId;
  5361. // node.debug("Send load request #" + requestId);
  5362. }
  5363. if (isAsync) {
  5364. tree.debugTime(tag);
  5365. tree.nodeSetStatus(ctx, "loading");
  5366. }
  5367. // The async Ajax request has now started...
  5368. // Defer the deferred:
  5369. // we want to be able to reject invalid responses, even if
  5370. // the raw HTTP Ajax XHR resolved as Ok.
  5371. // We use the ajaxDfd.then() syntax here, which is compatible with
  5372. // jQuery and ECMA6.
  5373. // However resultDfd is a jQuery deferred, which is currently the
  5374. // expected result type of nodeLoadChildren()
  5375. resultDfd = new $.Deferred();
  5376. ajaxDfd.then(
  5377. function(data, textStatus, jqXHR) {
  5378. // ajaxDfd was resolved, but we reject or resolve resultDfd
  5379. // depending on the response data
  5380. var errorObj, res;
  5381. if (
  5382. (source.dataType === "json" ||
  5383. source.dataType === "jsonp") &&
  5384. typeof data === "string"
  5385. ) {
  5386. $.error(
  5387. "Ajax request returned a string (did you get the JSON dataType wrong?)."
  5388. );
  5389. }
  5390. if (node._requestId && node._requestId > requestId) {
  5391. // The expected request time stamp is later than `requestId`
  5392. // (which was kept as as closure variable to this handler function)
  5393. // node.warn("Ignored load response for obsolete request #" + requestId + " (expected #" + node._requestId + ")");
  5394. resultDfd.rejectWith(this, [
  5395. RECURSIVE_REQUEST_ERROR,
  5396. ]);
  5397. return;
  5398. // } else {
  5399. // node.debug("Response returned for load request #" + requestId);
  5400. }
  5401. if (node.parent === null && nodePrevParent !== null) {
  5402. resultDfd.rejectWith(this, [
  5403. INVALID_REQUEST_TARGET_ERROR,
  5404. ]);
  5405. return;
  5406. }
  5407. // Allow to adjust the received response data in the `postProcess` event.
  5408. if (ctx.options.postProcess) {
  5409. // The handler may either
  5410. // - modify `ctx.response` in-place (and leave `ctx.result` undefined)
  5411. // => res = undefined
  5412. // - return a replacement in `ctx.result`
  5413. // => res = <new data>
  5414. // If res contains an `error` property, an error status is displayed
  5415. try {
  5416. res = tree._triggerNodeEvent(
  5417. "postProcess",
  5418. ctx,
  5419. ctx.originalEvent,
  5420. {
  5421. response: data,
  5422. error: null,
  5423. dataType: source.dataType,
  5424. }
  5425. );
  5426. if (res.error) {
  5427. tree.warn(
  5428. "postProcess returned error:",
  5429. res
  5430. );
  5431. }
  5432. } catch (e) {
  5433. res = {
  5434. error: e,
  5435. message: "" + e,
  5436. details: "postProcess failed",
  5437. };
  5438. }
  5439. if (res.error) {
  5440. // Either postProcess failed with an exception, or the returned
  5441. // result object has an 'error' property attached:
  5442. errorObj = $.isPlainObject(res.error)
  5443. ? res.error
  5444. : { message: res.error };
  5445. errorObj = tree._makeHookContext(
  5446. node,
  5447. null,
  5448. errorObj
  5449. );
  5450. resultDfd.rejectWith(this, [errorObj]);
  5451. return;
  5452. }
  5453. if (
  5454. $.isArray(res) ||
  5455. ($.isPlainObject(res) &&
  5456. $.isArray(res.children))
  5457. ) {
  5458. // Use `ctx.result` if valid
  5459. // (otherwise use existing data, which may have been modified in-place)
  5460. data = res;
  5461. }
  5462. } else if (
  5463. data &&
  5464. data.hasOwnProperty("d") &&
  5465. ctx.options.enableAspx
  5466. ) {
  5467. // Process ASPX WebMethod JSON object inside "d" property
  5468. // (only if no postProcess event was defined)
  5469. if (ctx.options.enableAspx === 42) {
  5470. tree.warn(
  5471. "The default for enableAspx will change to `false` in the fututure. " +
  5472. "Pass `enableAspx: true` or implement postProcess to silence this warning."
  5473. );
  5474. }
  5475. data =
  5476. typeof data.d === "string"
  5477. ? $.parseJSON(data.d)
  5478. : data.d;
  5479. }
  5480. resultDfd.resolveWith(this, [data]);
  5481. },
  5482. function(jqXHR, textStatus, errorThrown) {
  5483. // ajaxDfd was rejected, so we reject resultDfd as well
  5484. var errorObj = tree._makeHookContext(node, null, {
  5485. error: jqXHR,
  5486. args: Array.prototype.slice.call(arguments),
  5487. message: errorThrown,
  5488. details: jqXHR.status + ": " + errorThrown,
  5489. });
  5490. resultDfd.rejectWith(this, [errorObj]);
  5491. }
  5492. );
  5493. // The async Ajax request has now started.
  5494. // resultDfd will be resolved/rejected after the response arrived,
  5495. // was postProcessed, and checked.
  5496. // Now we implement the UI update and add the data to the tree.
  5497. // We also return this promise to the caller.
  5498. resultDfd
  5499. .done(function(data) {
  5500. tree.nodeSetStatus(ctx, "ok");
  5501. var children, metaData, noDataRes;
  5502. if ($.isPlainObject(data)) {
  5503. // We got {foo: 'abc', children: [...]}
  5504. // Copy extra properties to tree.data.foo
  5505. _assert(
  5506. node.isRootNode(),
  5507. "source may only be an object for root nodes (expecting an array of child objects otherwise)"
  5508. );
  5509. _assert(
  5510. $.isArray(data.children),
  5511. "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')"
  5512. );
  5513. metaData = data;
  5514. children = data.children;
  5515. delete metaData.children;
  5516. // Copy some attributes to tree.data
  5517. $.each(TREE_ATTRS, function(i, attr) {
  5518. if (metaData[attr] !== undefined) {
  5519. tree[attr] = metaData[attr];
  5520. delete metaData[attr];
  5521. }
  5522. });
  5523. // Copy all other attributes to tree.data.NAME
  5524. $.extend(tree.data, metaData);
  5525. } else {
  5526. children = data;
  5527. }
  5528. _assert(
  5529. $.isArray(children),
  5530. "expected array of children"
  5531. );
  5532. node._setChildren(children);
  5533. if (tree.options.nodata && children.length === 0) {
  5534. if ($.isFunction(tree.options.nodata)) {
  5535. noDataRes = tree.options.nodata.call(
  5536. tree,
  5537. { type: "nodata" },
  5538. ctx
  5539. );
  5540. } else if (
  5541. tree.options.nodata === true &&
  5542. node.isRootNode()
  5543. ) {
  5544. noDataRes = tree.options.strings.noData;
  5545. } else if (
  5546. typeof tree.options.nodata === "string" &&
  5547. node.isRootNode()
  5548. ) {
  5549. noDataRes = tree.options.nodata;
  5550. }
  5551. if (noDataRes) {
  5552. node.setStatus("nodata", noDataRes);
  5553. }
  5554. }
  5555. // trigger fancytreeloadchildren
  5556. tree._triggerNodeEvent("loadChildren", node);
  5557. })
  5558. .fail(function(error) {
  5559. var ctxErr;
  5560. if (error === RECURSIVE_REQUEST_ERROR) {
  5561. node.warn(
  5562. "Ignored response for obsolete load request #" +
  5563. requestId +
  5564. " (expected #" +
  5565. node._requestId +
  5566. ")"
  5567. );
  5568. return;
  5569. } else if (error === INVALID_REQUEST_TARGET_ERROR) {
  5570. node.warn(
  5571. "Lazy parent node was removed while loading: discarding response."
  5572. );
  5573. return;
  5574. } else if (error.node && error.error && error.message) {
  5575. // error is already a context object
  5576. ctxErr = error;
  5577. } else {
  5578. ctxErr = tree._makeHookContext(node, null, {
  5579. error: error, // it can be jqXHR or any custom error
  5580. args: Array.prototype.slice.call(arguments),
  5581. message: error
  5582. ? error.message || error.toString()
  5583. : "",
  5584. });
  5585. if (ctxErr.message === "[object Object]") {
  5586. ctxErr.message = "";
  5587. }
  5588. }
  5589. node.warn(
  5590. "Load children failed (" + ctxErr.message + ")",
  5591. ctxErr
  5592. );
  5593. if (
  5594. tree._triggerNodeEvent(
  5595. "loadError",
  5596. ctxErr,
  5597. null
  5598. ) !== false
  5599. ) {
  5600. tree.nodeSetStatus(
  5601. ctx,
  5602. "error",
  5603. ctxErr.message,
  5604. ctxErr.details
  5605. );
  5606. }
  5607. })
  5608. .always(function() {
  5609. node._requestId = null;
  5610. if (isAsync) {
  5611. tree.debugTimeEnd(tag);
  5612. }
  5613. });
  5614. return resultDfd.promise();
  5615. },
  5616. /** [Not Implemented] */
  5617. nodeLoadKeyPath: function(ctx, keyPathList) {
  5618. // TODO: implement and improve
  5619. // http://code.google.com/p/dynatree/issues/detail?id=222
  5620. },
  5621. /**
  5622. * Remove a single direct child of ctx.node.
  5623. * @param {EventData} ctx
  5624. * @param {FancytreeNode} childNode dircect child of ctx.node
  5625. */
  5626. nodeRemoveChild: function(ctx, childNode) {
  5627. var idx,
  5628. node = ctx.node,
  5629. // opts = ctx.options,
  5630. subCtx = $.extend({}, ctx, { node: childNode }),
  5631. children = node.children;
  5632. // FT.debug("nodeRemoveChild()", node.toString(), childNode.toString());
  5633. if (children.length === 1) {
  5634. _assert(childNode === children[0], "invalid single child");
  5635. return this.nodeRemoveChildren(ctx);
  5636. }
  5637. if (
  5638. this.activeNode &&
  5639. (childNode === this.activeNode ||
  5640. this.activeNode.isDescendantOf(childNode))
  5641. ) {
  5642. this.activeNode.setActive(false); // TODO: don't fire events
  5643. }
  5644. if (
  5645. this.focusNode &&
  5646. (childNode === this.focusNode ||
  5647. this.focusNode.isDescendantOf(childNode))
  5648. ) {
  5649. this.focusNode = null;
  5650. }
  5651. // TODO: persist must take care to clear select and expand cookies
  5652. this.nodeRemoveMarkup(subCtx);
  5653. this.nodeRemoveChildren(subCtx);
  5654. idx = $.inArray(childNode, children);
  5655. _assert(idx >= 0, "invalid child");
  5656. // Notify listeners
  5657. node.triggerModifyChild("remove", childNode);
  5658. // Unlink to support GC
  5659. childNode.visit(function(n) {
  5660. n.parent = null;
  5661. }, true);
  5662. this._callHook("treeRegisterNode", this, false, childNode);
  5663. // remove from child list
  5664. children.splice(idx, 1);
  5665. },
  5666. /**Remove HTML markup for all descendents of ctx.node.
  5667. * @param {EventData} ctx
  5668. */
  5669. nodeRemoveChildMarkup: function(ctx) {
  5670. var node = ctx.node;
  5671. // FT.debug("nodeRemoveChildMarkup()", node.toString());
  5672. // TODO: Unlink attr.ftnode to support GC
  5673. if (node.ul) {
  5674. if (node.isRootNode()) {
  5675. $(node.ul).empty();
  5676. } else {
  5677. $(node.ul).remove();
  5678. node.ul = null;
  5679. }
  5680. node.visit(function(n) {
  5681. n.li = n.ul = null;
  5682. });
  5683. }
  5684. },
  5685. /**Remove all descendants of ctx.node.
  5686. * @param {EventData} ctx
  5687. */
  5688. nodeRemoveChildren: function(ctx) {
  5689. var //subCtx,
  5690. tree = ctx.tree,
  5691. node = ctx.node,
  5692. children = node.children;
  5693. // opts = ctx.options;
  5694. // FT.debug("nodeRemoveChildren()", node.toString());
  5695. if (!children) {
  5696. return;
  5697. }
  5698. if (this.activeNode && this.activeNode.isDescendantOf(node)) {
  5699. this.activeNode.setActive(false); // TODO: don't fire events
  5700. }
  5701. if (this.focusNode && this.focusNode.isDescendantOf(node)) {
  5702. this.focusNode = null;
  5703. }
  5704. // TODO: persist must take care to clear select and expand cookies
  5705. this.nodeRemoveChildMarkup(ctx);
  5706. // Unlink children to support GC
  5707. // TODO: also delete this.children (not possible using visit())
  5708. // subCtx = $.extend({}, ctx);
  5709. node.triggerModifyChild("remove", null);
  5710. node.visit(function(n) {
  5711. n.parent = null;
  5712. tree._callHook("treeRegisterNode", tree, false, n);
  5713. });
  5714. if (node.lazy) {
  5715. // 'undefined' would be interpreted as 'not yet loaded' for lazy nodes
  5716. node.children = [];
  5717. } else {
  5718. node.children = null;
  5719. }
  5720. if (!node.isRootNode()) {
  5721. node.expanded = false; // #449, #459
  5722. }
  5723. this.nodeRenderStatus(ctx);
  5724. },
  5725. /**Remove HTML markup for ctx.node and all its descendents.
  5726. * @param {EventData} ctx
  5727. */
  5728. nodeRemoveMarkup: function(ctx) {
  5729. var node = ctx.node;
  5730. // FT.debug("nodeRemoveMarkup()", node.toString());
  5731. // TODO: Unlink attr.ftnode to support GC
  5732. if (node.li) {
  5733. $(node.li).remove();
  5734. node.li = null;
  5735. }
  5736. this.nodeRemoveChildMarkup(ctx);
  5737. },
  5738. /**
  5739. * Create `<li><span>..</span> .. </li>` tags for this node.
  5740. *
  5741. * This method takes care that all HTML markup is created that is required
  5742. * to display this node in its current state.
  5743. *
  5744. * Call this method to create new nodes, or after the strucuture
  5745. * was changed (e.g. after moving this node or adding/removing children)
  5746. * nodeRenderTitle() and nodeRenderStatus() are implied.
  5747. *
  5748. * ```html
  5749. * <li id='KEY' ftnode=NODE>
  5750. * <span class='fancytree-node fancytree-expanded fancytree-has-children fancytree-lastsib fancytree-exp-el fancytree-ico-e'>
  5751. * <span class="fancytree-expander"></span>
  5752. * <span class="fancytree-checkbox"></span> // only present in checkbox mode
  5753. * <span class="fancytree-icon"></span>
  5754. * <a href="#" class="fancytree-title"> Node 1 </a>
  5755. * </span>
  5756. * <ul> // only present if node has children
  5757. * <li id='KEY' ftnode=NODE> child1 ... </li>
  5758. * <li id='KEY' ftnode=NODE> child2 ... </li>
  5759. * </ul>
  5760. * </li>
  5761. * ```
  5762. *
  5763. * @param {EventData} ctx
  5764. * @param {boolean} [force=false] re-render, even if html markup was already created
  5765. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  5766. * @param {boolean} [collapsed=false] force root node to be collapsed, so we can apply animated expand later
  5767. */
  5768. nodeRender: function(ctx, force, deep, collapsed, _recursive) {
  5769. /* This method must take care of all cases where the current data mode
  5770. * (i.e. node hierarchy) does not match the current markup.
  5771. *
  5772. * - node was not yet rendered:
  5773. * create markup
  5774. * - node was rendered: exit fast
  5775. * - children have been added
  5776. * - children have been removed
  5777. */
  5778. var childLI,
  5779. childNode1,
  5780. childNode2,
  5781. i,
  5782. l,
  5783. next,
  5784. subCtx,
  5785. node = ctx.node,
  5786. tree = ctx.tree,
  5787. opts = ctx.options,
  5788. aria = opts.aria,
  5789. firstTime = false,
  5790. parent = node.parent,
  5791. isRootNode = !parent,
  5792. children = node.children,
  5793. successorLi = null;
  5794. // FT.debug("nodeRender(" + !!force + ", " + !!deep + ")", node.toString());
  5795. if (tree._enableUpdate === false) {
  5796. // tree.debug("no render", tree._enableUpdate);
  5797. return;
  5798. }
  5799. if (!isRootNode && !parent.ul) {
  5800. // Calling node.collapse on a deep, unrendered node
  5801. return;
  5802. }
  5803. _assert(isRootNode || parent.ul, "parent UL must exist");
  5804. // Render the node
  5805. if (!isRootNode) {
  5806. // Discard markup on force-mode, or if it is not linked to parent <ul>
  5807. if (
  5808. node.li &&
  5809. (force || node.li.parentNode !== node.parent.ul)
  5810. ) {
  5811. if (node.li.parentNode === node.parent.ul) {
  5812. // #486: store following node, so we can insert the new markup there later
  5813. successorLi = node.li.nextSibling;
  5814. } else {
  5815. // May happen, when a top-level node was dropped over another
  5816. this.debug(
  5817. "Unlinking " +
  5818. node +
  5819. " (must be child of " +
  5820. node.parent +
  5821. ")"
  5822. );
  5823. }
  5824. // this.debug("nodeRemoveMarkup...");
  5825. this.nodeRemoveMarkup(ctx);
  5826. }
  5827. // Create <li><span /> </li>
  5828. // node.debug("render...");
  5829. if (node.li) {
  5830. // this.nodeRenderTitle(ctx);
  5831. this.nodeRenderStatus(ctx);
  5832. } else {
  5833. // node.debug("render... really");
  5834. firstTime = true;
  5835. node.li = document.createElement("li");
  5836. node.li.ftnode = node;
  5837. if (node.key && opts.generateIds) {
  5838. node.li.id = opts.idPrefix + node.key;
  5839. }
  5840. node.span = document.createElement("span");
  5841. node.span.className = "fancytree-node";
  5842. if (aria && !node.tr) {
  5843. $(node.li).attr("role", "treeitem");
  5844. }
  5845. node.li.appendChild(node.span);
  5846. // Create inner HTML for the <span> (expander, checkbox, icon, and title)
  5847. this.nodeRenderTitle(ctx);
  5848. // Allow tweaking and binding, after node was created for the first time
  5849. if (opts.createNode) {
  5850. opts.createNode.call(
  5851. tree,
  5852. { type: "createNode" },
  5853. ctx
  5854. );
  5855. }
  5856. }
  5857. // Allow tweaking after node state was rendered
  5858. if (opts.renderNode) {
  5859. opts.renderNode.call(tree, { type: "renderNode" }, ctx);
  5860. }
  5861. }
  5862. // Visit child nodes
  5863. if (children) {
  5864. if (isRootNode || node.expanded || deep === true) {
  5865. // Create a UL to hold the children
  5866. if (!node.ul) {
  5867. node.ul = document.createElement("ul");
  5868. if (
  5869. (collapsed === true && !_recursive) ||
  5870. !node.expanded
  5871. ) {
  5872. // hide top UL, so we can use an animation to show it later
  5873. node.ul.style.display = "none";
  5874. }
  5875. if (aria) {
  5876. $(node.ul).attr("role", "group");
  5877. }
  5878. if (node.li) {
  5879. // issue #67
  5880. node.li.appendChild(node.ul);
  5881. } else {
  5882. node.tree.$div.append(node.ul);
  5883. }
  5884. }
  5885. // Add child markup
  5886. for (i = 0, l = children.length; i < l; i++) {
  5887. subCtx = $.extend({}, ctx, { node: children[i] });
  5888. this.nodeRender(subCtx, force, deep, false, true);
  5889. }
  5890. // Remove <li> if nodes have moved to another parent
  5891. childLI = node.ul.firstChild;
  5892. while (childLI) {
  5893. childNode2 = childLI.ftnode;
  5894. if (childNode2 && childNode2.parent !== node) {
  5895. node.debug(
  5896. "_fixParent: remove missing " + childNode2,
  5897. childLI
  5898. );
  5899. next = childLI.nextSibling;
  5900. childLI.parentNode.removeChild(childLI);
  5901. childLI = next;
  5902. } else {
  5903. childLI = childLI.nextSibling;
  5904. }
  5905. }
  5906. // Make sure, that <li> order matches node.children order.
  5907. childLI = node.ul.firstChild;
  5908. for (i = 0, l = children.length - 1; i < l; i++) {
  5909. childNode1 = children[i];
  5910. childNode2 = childLI.ftnode;
  5911. if (childNode1 === childNode2) {
  5912. childLI = childLI.nextSibling;
  5913. } else {
  5914. // node.debug("_fixOrder: mismatch at index " + i + ": " + childNode1 + " != " + childNode2);
  5915. node.ul.insertBefore(
  5916. childNode1.li,
  5917. childNode2.li
  5918. );
  5919. }
  5920. }
  5921. }
  5922. } else {
  5923. // No children: remove markup if any
  5924. if (node.ul) {
  5925. // alert("remove child markup for " + node);
  5926. this.warn("remove child markup for " + node);
  5927. this.nodeRemoveChildMarkup(ctx);
  5928. }
  5929. }
  5930. if (!isRootNode) {
  5931. // Update element classes according to node state
  5932. // this.nodeRenderStatus(ctx);
  5933. // Finally add the whole structure to the DOM, so the browser can render
  5934. if (firstTime) {
  5935. // #486: successorLi is set, if we re-rendered (i.e. discarded)
  5936. // existing markup, which we want to insert at the same position.
  5937. // (null is equivalent to append)
  5938. // parent.ul.appendChild(node.li);
  5939. parent.ul.insertBefore(node.li, successorLi);
  5940. }
  5941. }
  5942. },
  5943. /** Create HTML inside the node's outer `<span>` (i.e. expander, checkbox,
  5944. * icon, and title).
  5945. *
  5946. * nodeRenderStatus() is implied.
  5947. * @param {EventData} ctx
  5948. * @param {string} [title] optinal new title
  5949. */
  5950. nodeRenderTitle: function(ctx, title) {
  5951. // set node connector images, links and text
  5952. var checkbox,
  5953. className,
  5954. icon,
  5955. nodeTitle,
  5956. role,
  5957. tabindex,
  5958. tooltip,
  5959. iconTooltip,
  5960. node = ctx.node,
  5961. tree = ctx.tree,
  5962. opts = ctx.options,
  5963. aria = opts.aria,
  5964. level = node.getLevel(),
  5965. ares = [];
  5966. if (title !== undefined) {
  5967. node.title = title;
  5968. }
  5969. if (!node.span || tree._enableUpdate === false) {
  5970. // Silently bail out if node was not rendered yet, assuming
  5971. // node.render() will be called as the node becomes visible
  5972. return;
  5973. }
  5974. // Connector (expanded, expandable or simple)
  5975. role =
  5976. aria && node.hasChildren() !== false
  5977. ? " role='button'"
  5978. : "";
  5979. if (level < opts.minExpandLevel) {
  5980. if (!node.lazy) {
  5981. node.expanded = true;
  5982. }
  5983. if (level > 1) {
  5984. ares.push(
  5985. "<span " +
  5986. role +
  5987. " class='fancytree-expander fancytree-expander-fixed'></span>"
  5988. );
  5989. }
  5990. // .. else (i.e. for root level) skip expander/connector alltogether
  5991. } else {
  5992. ares.push(
  5993. "<span " + role + " class='fancytree-expander'></span>"
  5994. );
  5995. }
  5996. // Checkbox mode
  5997. checkbox = FT.evalOption("checkbox", node, node, opts, false);
  5998. if (checkbox && !node.isStatusNode()) {
  5999. role = aria ? " role='checkbox'" : "";
  6000. className = "fancytree-checkbox";
  6001. if (
  6002. checkbox === "radio" ||
  6003. (node.parent && node.parent.radiogroup)
  6004. ) {
  6005. className += " fancytree-radio";
  6006. }
  6007. ares.push(
  6008. "<span " + role + " class='" + className + "'></span>"
  6009. );
  6010. }
  6011. // Folder or doctype icon
  6012. if (node.data.iconClass !== undefined) {
  6013. // 2015-11-16
  6014. // Handle / warn about backward compatibility
  6015. if (node.icon) {
  6016. $.error(
  6017. "'iconClass' node option is deprecated since v2.14.0: use 'icon' only instead"
  6018. );
  6019. } else {
  6020. node.warn(
  6021. "'iconClass' node option is deprecated since v2.14.0: use 'icon' instead"
  6022. );
  6023. node.icon = node.data.iconClass;
  6024. }
  6025. }
  6026. // If opts.icon is a callback and returns something other than undefined, use that
  6027. // else if node.icon is a boolean or string, use that
  6028. // else if opts.icon is a boolean or string, use that
  6029. // else show standard icon (which may be different for folders or documents)
  6030. icon = FT.evalOption("icon", node, node, opts, true);
  6031. // if( typeof icon !== "boolean" ) {
  6032. // // icon is defined, but not true/false: must be a string
  6033. // icon = "" + icon;
  6034. // }
  6035. if (icon !== false) {
  6036. role = aria ? " role='presentation'" : "";
  6037. iconTooltip = FT.evalOption(
  6038. "iconTooltip",
  6039. node,
  6040. node,
  6041. opts,
  6042. null
  6043. );
  6044. iconTooltip = iconTooltip
  6045. ? " title='" + _escapeTooltip(iconTooltip) + "'"
  6046. : "";
  6047. if (typeof icon === "string") {
  6048. if (TEST_IMG.test(icon)) {
  6049. // node.icon is an image url. Prepend imagePath
  6050. icon =
  6051. icon.charAt(0) === "/"
  6052. ? icon
  6053. : (opts.imagePath || "") + icon;
  6054. ares.push(
  6055. "<img src='" +
  6056. icon +
  6057. "' class='fancytree-icon'" +
  6058. iconTooltip +
  6059. " alt='' />"
  6060. );
  6061. } else {
  6062. ares.push(
  6063. "<span " +
  6064. role +
  6065. " class='fancytree-custom-icon " +
  6066. icon +
  6067. "'" +
  6068. iconTooltip +
  6069. "></span>"
  6070. );
  6071. }
  6072. } else if (icon.text) {
  6073. ares.push(
  6074. "<span " +
  6075. role +
  6076. " class='fancytree-custom-icon " +
  6077. (icon.addClass || "") +
  6078. "'" +
  6079. iconTooltip +
  6080. ">" +
  6081. FT.escapeHtml(icon.text) +
  6082. "</span>"
  6083. );
  6084. } else if (icon.html) {
  6085. ares.push(
  6086. "<span " +
  6087. role +
  6088. " class='fancytree-custom-icon " +
  6089. (icon.addClass || "") +
  6090. "'" +
  6091. iconTooltip +
  6092. ">" +
  6093. icon.html +
  6094. "</span>"
  6095. );
  6096. } else {
  6097. // standard icon: theme css will take care of this
  6098. ares.push(
  6099. "<span " +
  6100. role +
  6101. " class='fancytree-icon'" +
  6102. iconTooltip +
  6103. "></span>"
  6104. );
  6105. }
  6106. }
  6107. // Node title
  6108. nodeTitle = "";
  6109. if (opts.renderTitle) {
  6110. nodeTitle =
  6111. opts.renderTitle.call(
  6112. tree,
  6113. { type: "renderTitle" },
  6114. ctx
  6115. ) || "";
  6116. }
  6117. if (!nodeTitle) {
  6118. tooltip = FT.evalOption("tooltip", node, node, opts, null);
  6119. if (tooltip === true) {
  6120. tooltip = node.title;
  6121. }
  6122. // if( node.tooltip ) {
  6123. // tooltip = node.tooltip;
  6124. // } else if ( opts.tooltip ) {
  6125. // tooltip = opts.tooltip === true ? node.title : opts.tooltip.call(tree, node);
  6126. // }
  6127. tooltip = tooltip
  6128. ? " title='" + _escapeTooltip(tooltip) + "'"
  6129. : "";
  6130. tabindex = opts.titlesTabbable ? " tabindex='0'" : "";
  6131. nodeTitle =
  6132. "<span class='fancytree-title'" +
  6133. tooltip +
  6134. tabindex +
  6135. ">" +
  6136. (opts.escapeTitles
  6137. ? FT.escapeHtml(node.title)
  6138. : node.title) +
  6139. "</span>";
  6140. }
  6141. ares.push(nodeTitle);
  6142. // Note: this will trigger focusout, if node had the focus
  6143. //$(node.span).html(ares.join("")); // it will cleanup the jQuery data currently associated with SPAN (if any), but it executes more slowly
  6144. node.span.innerHTML = ares.join("");
  6145. // Update CSS classes
  6146. this.nodeRenderStatus(ctx);
  6147. if (opts.enhanceTitle) {
  6148. ctx.$title = $(">span.fancytree-title", node.span);
  6149. nodeTitle =
  6150. opts.enhanceTitle.call(
  6151. tree,
  6152. { type: "enhanceTitle" },
  6153. ctx
  6154. ) || "";
  6155. }
  6156. },
  6157. /** Update element classes according to node state.
  6158. * @param {EventData} ctx
  6159. */
  6160. nodeRenderStatus: function(ctx) {
  6161. // Set classes for current status
  6162. var $ariaElem,
  6163. node = ctx.node,
  6164. tree = ctx.tree,
  6165. opts = ctx.options,
  6166. // nodeContainer = node[tree.nodeContainerAttrName],
  6167. hasChildren = node.hasChildren(),
  6168. isLastSib = node.isLastSibling(),
  6169. aria = opts.aria,
  6170. cn = opts._classNames,
  6171. cnList = [],
  6172. statusElem = node[tree.statusClassPropName];
  6173. if (!statusElem || tree._enableUpdate === false) {
  6174. // if this function is called for an unrendered node, ignore it (will be updated on nect render anyway)
  6175. return;
  6176. }
  6177. if (aria) {
  6178. $ariaElem = $(node.tr || node.li);
  6179. }
  6180. // Build a list of class names that we will add to the node <span>
  6181. cnList.push(cn.node);
  6182. if (tree.activeNode === node) {
  6183. cnList.push(cn.active);
  6184. // $(">span.fancytree-title", statusElem).attr("tabindex", "0");
  6185. // tree.$container.removeAttr("tabindex");
  6186. // }else{
  6187. // $(">span.fancytree-title", statusElem).removeAttr("tabindex");
  6188. // tree.$container.attr("tabindex", "0");
  6189. }
  6190. if (tree.focusNode === node) {
  6191. cnList.push(cn.focused);
  6192. }
  6193. if (node.expanded) {
  6194. cnList.push(cn.expanded);
  6195. }
  6196. if (aria) {
  6197. if (hasChildren === false) {
  6198. $ariaElem.removeAttr("aria-expanded");
  6199. } else {
  6200. $ariaElem.attr("aria-expanded", Boolean(node.expanded));
  6201. }
  6202. }
  6203. if (node.folder) {
  6204. cnList.push(cn.folder);
  6205. }
  6206. if (hasChildren !== false) {
  6207. cnList.push(cn.hasChildren);
  6208. }
  6209. // TODO: required?
  6210. if (isLastSib) {
  6211. cnList.push(cn.lastsib);
  6212. }
  6213. if (node.lazy && node.children == null) {
  6214. cnList.push(cn.lazy);
  6215. }
  6216. if (node.partload) {
  6217. cnList.push(cn.partload);
  6218. }
  6219. if (node.partsel) {
  6220. cnList.push(cn.partsel);
  6221. }
  6222. if (FT.evalOption("unselectable", node, node, opts, false)) {
  6223. cnList.push(cn.unselectable);
  6224. }
  6225. if (node._isLoading) {
  6226. cnList.push(cn.loading);
  6227. }
  6228. if (node._error) {
  6229. cnList.push(cn.error);
  6230. }
  6231. if (node.statusNodeType) {
  6232. cnList.push(cn.statusNodePrefix + node.statusNodeType);
  6233. }
  6234. if (node.selected) {
  6235. cnList.push(cn.selected);
  6236. if (aria) {
  6237. $ariaElem.attr("aria-selected", true);
  6238. }
  6239. } else if (aria) {
  6240. $ariaElem.attr("aria-selected", false);
  6241. }
  6242. if (node.extraClasses) {
  6243. cnList.push(node.extraClasses);
  6244. }
  6245. // IE6 doesn't correctly evaluate multiple class names,
  6246. // so we create combined class names that can be used in the CSS
  6247. if (hasChildren === false) {
  6248. cnList.push(
  6249. cn.combinedExpanderPrefix + "n" + (isLastSib ? "l" : "")
  6250. );
  6251. } else {
  6252. cnList.push(
  6253. cn.combinedExpanderPrefix +
  6254. (node.expanded ? "e" : "c") +
  6255. (node.lazy && node.children == null ? "d" : "") +
  6256. (isLastSib ? "l" : "")
  6257. );
  6258. }
  6259. cnList.push(
  6260. cn.combinedIconPrefix +
  6261. (node.expanded ? "e" : "c") +
  6262. (node.folder ? "f" : "")
  6263. );
  6264. // node.span.className = cnList.join(" ");
  6265. statusElem.className = cnList.join(" ");
  6266. // TODO: we should not set this in the <span> tag also, if we set it here:
  6267. // Maybe most (all) of the classes should be set in LI instead of SPAN?
  6268. if (node.li) {
  6269. // #719: we have to consider that there may be already other classes:
  6270. $(node.li).toggleClass(cn.lastsib, isLastSib);
  6271. }
  6272. },
  6273. /** Activate node.
  6274. * flag defaults to true.
  6275. * If flag is true, the node is activated (must be a synchronous operation)
  6276. * If flag is false, the node is deactivated (must be a synchronous operation)
  6277. * @param {EventData} ctx
  6278. * @param {boolean} [flag=true]
  6279. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  6280. * @returns {$.Promise}
  6281. */
  6282. nodeSetActive: function(ctx, flag, callOpts) {
  6283. // Handle user click / [space] / [enter], according to clickFolderMode.
  6284. callOpts = callOpts || {};
  6285. var subCtx,
  6286. node = ctx.node,
  6287. tree = ctx.tree,
  6288. opts = ctx.options,
  6289. noEvents = callOpts.noEvents === true,
  6290. noFocus = callOpts.noFocus === true,
  6291. scroll = callOpts.scrollIntoView !== false,
  6292. isActive = node === tree.activeNode;
  6293. // flag defaults to true
  6294. flag = flag !== false;
  6295. // node.debug("nodeSetActive", flag);
  6296. if (isActive === flag) {
  6297. // Nothing to do
  6298. return _getResolvedPromise(node);
  6299. }
  6300. // #1042: don't scroll between mousedown/-up when clicking an embedded link
  6301. if (
  6302. scroll &&
  6303. ctx.originalEvent &&
  6304. $(ctx.originalEvent.target).is("a,:checkbox")
  6305. ) {
  6306. node.info("Not scrolling while clicking an embedded link.");
  6307. scroll = false;
  6308. }
  6309. if (
  6310. flag &&
  6311. !noEvents &&
  6312. this._triggerNodeEvent(
  6313. "beforeActivate",
  6314. node,
  6315. ctx.originalEvent
  6316. ) === false
  6317. ) {
  6318. // Callback returned false
  6319. return _getRejectedPromise(node, ["rejected"]);
  6320. }
  6321. if (flag) {
  6322. if (tree.activeNode) {
  6323. _assert(
  6324. tree.activeNode !== node,
  6325. "node was active (inconsistency)"
  6326. );
  6327. subCtx = $.extend({}, ctx, { node: tree.activeNode });
  6328. tree.nodeSetActive(subCtx, false);
  6329. _assert(
  6330. tree.activeNode === null,
  6331. "deactivate was out of sync?"
  6332. );
  6333. }
  6334. if (opts.activeVisible) {
  6335. // If no focus is set (noFocus: true) and there is no focused node, this node is made visible.
  6336. // scroll = noFocus && tree.focusNode == null;
  6337. // #863: scroll by default (unless `scrollIntoView: false` was passed)
  6338. node.makeVisible({ scrollIntoView: scroll });
  6339. }
  6340. tree.activeNode = node;
  6341. tree.nodeRenderStatus(ctx);
  6342. if (!noFocus) {
  6343. tree.nodeSetFocus(ctx);
  6344. }
  6345. if (!noEvents) {
  6346. tree._triggerNodeEvent(
  6347. "activate",
  6348. node,
  6349. ctx.originalEvent
  6350. );
  6351. }
  6352. } else {
  6353. _assert(
  6354. tree.activeNode === node,
  6355. "node was not active (inconsistency)"
  6356. );
  6357. tree.activeNode = null;
  6358. this.nodeRenderStatus(ctx);
  6359. if (!noEvents) {
  6360. ctx.tree._triggerNodeEvent(
  6361. "deactivate",
  6362. node,
  6363. ctx.originalEvent
  6364. );
  6365. }
  6366. }
  6367. return _getResolvedPromise(node);
  6368. },
  6369. /** Expand or collapse node, return Deferred.promise.
  6370. *
  6371. * @param {EventData} ctx
  6372. * @param {boolean} [flag=true]
  6373. * @param {object} [opts] additional options. Defaults to `{noAnimation: false, noEvents: false}`
  6374. * @returns {$.Promise} The deferred will be resolved as soon as the (lazy)
  6375. * data was retrieved, rendered, and the expand animation finished.
  6376. */
  6377. nodeSetExpanded: function(ctx, flag, callOpts) {
  6378. callOpts = callOpts || {};
  6379. var _afterLoad,
  6380. dfd,
  6381. i,
  6382. l,
  6383. parents,
  6384. prevAC,
  6385. node = ctx.node,
  6386. tree = ctx.tree,
  6387. opts = ctx.options,
  6388. noAnimation = callOpts.noAnimation === true,
  6389. noEvents = callOpts.noEvents === true;
  6390. // flag defaults to true
  6391. flag = flag !== false;
  6392. // node.debug("nodeSetExpanded(" + flag + ")");
  6393. if ($(node.li).hasClass(opts._classNames.animating)) {
  6394. node.warn(
  6395. "setExpanded(" + flag + ") while animating: ignored."
  6396. );
  6397. return _getRejectedPromise(node, ["recursion"]);
  6398. }
  6399. if ((node.expanded && flag) || (!node.expanded && !flag)) {
  6400. // Nothing to do
  6401. // node.debug("nodeSetExpanded(" + flag + "): nothing to do");
  6402. return _getResolvedPromise(node);
  6403. } else if (flag && !node.lazy && !node.hasChildren()) {
  6404. // Prevent expanding of empty nodes
  6405. // return _getRejectedPromise(node, ["empty"]);
  6406. return _getResolvedPromise(node);
  6407. } else if (!flag && node.getLevel() < opts.minExpandLevel) {
  6408. // Prevent collapsing locked levels
  6409. return _getRejectedPromise(node, ["locked"]);
  6410. } else if (
  6411. !noEvents &&
  6412. this._triggerNodeEvent(
  6413. "beforeExpand",
  6414. node,
  6415. ctx.originalEvent
  6416. ) === false
  6417. ) {
  6418. // Callback returned false
  6419. return _getRejectedPromise(node, ["rejected"]);
  6420. }
  6421. // If this node inside a collpased node, no animation and scrolling is needed
  6422. if (!noAnimation && !node.isVisible()) {
  6423. noAnimation = callOpts.noAnimation = true;
  6424. }
  6425. dfd = new $.Deferred();
  6426. // Auto-collapse mode: collapse all siblings
  6427. if (flag && !node.expanded && opts.autoCollapse) {
  6428. parents = node.getParentList(false, true);
  6429. prevAC = opts.autoCollapse;
  6430. try {
  6431. opts.autoCollapse = false;
  6432. for (i = 0, l = parents.length; i < l; i++) {
  6433. // TODO: should return promise?
  6434. this._callHook(
  6435. "nodeCollapseSiblings",
  6436. parents[i],
  6437. callOpts
  6438. );
  6439. }
  6440. } finally {
  6441. opts.autoCollapse = prevAC;
  6442. }
  6443. }
  6444. // Trigger expand/collapse after expanding
  6445. dfd.done(function() {
  6446. var lastChild = node.getLastChild();
  6447. if (
  6448. flag &&
  6449. opts.autoScroll &&
  6450. !noAnimation &&
  6451. lastChild &&
  6452. tree._enableUpdate
  6453. ) {
  6454. // Scroll down to last child, but keep current node visible
  6455. lastChild
  6456. .scrollIntoView(true, { topNode: node })
  6457. .always(function() {
  6458. if (!noEvents) {
  6459. ctx.tree._triggerNodeEvent(
  6460. flag ? "expand" : "collapse",
  6461. ctx
  6462. );
  6463. }
  6464. });
  6465. } else {
  6466. if (!noEvents) {
  6467. ctx.tree._triggerNodeEvent(
  6468. flag ? "expand" : "collapse",
  6469. ctx
  6470. );
  6471. }
  6472. }
  6473. });
  6474. // vvv Code below is executed after loading finished:
  6475. _afterLoad = function(callback) {
  6476. var cn = opts._classNames,
  6477. isVisible,
  6478. isExpanded,
  6479. effect = opts.toggleEffect;
  6480. node.expanded = flag;
  6481. tree._callHook(
  6482. "treeStructureChanged",
  6483. ctx,
  6484. flag ? "expand" : "collapse"
  6485. );
  6486. // Create required markup, but make sure the top UL is hidden, so we
  6487. // can animate later
  6488. tree._callHook("nodeRender", ctx, false, false, true);
  6489. // Hide children, if node is collapsed
  6490. if (node.ul) {
  6491. isVisible = node.ul.style.display !== "none";
  6492. isExpanded = !!node.expanded;
  6493. if (isVisible === isExpanded) {
  6494. node.warn(
  6495. "nodeSetExpanded: UL.style.display already set"
  6496. );
  6497. } else if (!effect || noAnimation) {
  6498. node.ul.style.display =
  6499. node.expanded || !parent ? "" : "none";
  6500. } else {
  6501. // The UI toggle() effect works with the ext-wide extension,
  6502. // while jQuery.animate() has problems when the title span
  6503. // has position: absolute.
  6504. // Since jQuery UI 1.12, the blind effect requires the parent
  6505. // element to have 'position: relative'.
  6506. // See #716, #717
  6507. $(node.li).addClass(cn.animating); // #717
  6508. if ($.isFunction($(node.ul)[effect.effect])) {
  6509. // tree.debug( "use jquery." + effect.effect + " method" );
  6510. $(node.ul)[effect.effect]({
  6511. duration: effect.duration,
  6512. always: function() {
  6513. // node.debug("fancytree-animating end: " + node.li.className);
  6514. $(this).removeClass(cn.animating); // #716
  6515. $(node.li).removeClass(cn.animating); // #717
  6516. callback();
  6517. },
  6518. });
  6519. } else {
  6520. // The UI toggle() effect works with the ext-wide extension,
  6521. // while jQuery.animate() has problems when the title span
  6522. // has positon: absolute.
  6523. // Since jQuery UI 1.12, the blind effect requires the parent
  6524. // element to have 'position: relative'.
  6525. // See #716, #717
  6526. // tree.debug("use specified effect (" + effect.effect + ") with the jqueryui.toggle method");
  6527. // try to stop an animation that might be already in progress
  6528. $(node.ul).stop(true, true); //< does not work after resetLazy has been called for a node whose animation wasn't complete and effect was "blind"
  6529. // dirty fix to remove a defunct animation (effect: "blind") after resetLazy has been called
  6530. $(node.ul)
  6531. .parent()
  6532. .find(".ui-effects-placeholder")
  6533. .remove();
  6534. $(node.ul).toggle(
  6535. effect.effect,
  6536. effect.options,
  6537. effect.duration,
  6538. function() {
  6539. // node.debug("fancytree-animating end: " + node.li.className);
  6540. $(this).removeClass(cn.animating); // #716
  6541. $(node.li).removeClass(cn.animating); // #717
  6542. callback();
  6543. }
  6544. );
  6545. }
  6546. return;
  6547. }
  6548. }
  6549. callback();
  6550. };
  6551. // ^^^ Code above is executed after loading finshed.
  6552. // Load lazy nodes, if any. Then continue with _afterLoad()
  6553. if (flag && node.lazy && node.hasChildren() === undefined) {
  6554. // node.debug("nodeSetExpanded: load start...");
  6555. node.load()
  6556. .done(function() {
  6557. // node.debug("nodeSetExpanded: load done");
  6558. if (dfd.notifyWith) {
  6559. // requires jQuery 1.6+
  6560. dfd.notifyWith(node, ["loaded"]);
  6561. }
  6562. _afterLoad(function() {
  6563. dfd.resolveWith(node);
  6564. });
  6565. })
  6566. .fail(function(errMsg) {
  6567. _afterLoad(function() {
  6568. dfd.rejectWith(node, [
  6569. "load failed (" + errMsg + ")",
  6570. ]);
  6571. });
  6572. });
  6573. /*
  6574. var source = tree._triggerNodeEvent("lazyLoad", node, ctx.originalEvent);
  6575. _assert(typeof source !== "boolean", "lazyLoad event must return source in data.result");
  6576. node.debug("nodeSetExpanded: load start...");
  6577. this._callHook("nodeLoadChildren", ctx, source).done(function(){
  6578. node.debug("nodeSetExpanded: load done");
  6579. if(dfd.notifyWith){ // requires jQuery 1.6+
  6580. dfd.notifyWith(node, ["loaded"]);
  6581. }
  6582. _afterLoad.call(tree);
  6583. }).fail(function(errMsg){
  6584. dfd.rejectWith(node, ["load failed (" + errMsg + ")"]);
  6585. });
  6586. */
  6587. } else {
  6588. _afterLoad(function() {
  6589. dfd.resolveWith(node);
  6590. });
  6591. }
  6592. // node.debug("nodeSetExpanded: returns");
  6593. return dfd.promise();
  6594. },
  6595. /** Focus or blur this node.
  6596. * @param {EventData} ctx
  6597. * @param {boolean} [flag=true]
  6598. */
  6599. nodeSetFocus: function(ctx, flag) {
  6600. // ctx.node.debug("nodeSetFocus(" + flag + ")");
  6601. var ctx2,
  6602. tree = ctx.tree,
  6603. node = ctx.node,
  6604. opts = tree.options,
  6605. // et = ctx.originalEvent && ctx.originalEvent.type,
  6606. isInput = ctx.originalEvent
  6607. ? $(ctx.originalEvent.target).is(":input")
  6608. : false;
  6609. flag = flag !== false;
  6610. // (node || tree).debug("nodeSetFocus(" + flag + "), event: " + et + ", isInput: "+ isInput);
  6611. // Blur previous node if any
  6612. if (tree.focusNode) {
  6613. if (tree.focusNode === node && flag) {
  6614. // node.debug("nodeSetFocus(" + flag + "): nothing to do");
  6615. return;
  6616. }
  6617. ctx2 = $.extend({}, ctx, { node: tree.focusNode });
  6618. tree.focusNode = null;
  6619. this._triggerNodeEvent("blur", ctx2);
  6620. this._callHook("nodeRenderStatus", ctx2);
  6621. }
  6622. // Set focus to container and node
  6623. if (flag) {
  6624. if (!this.hasFocus()) {
  6625. node.debug("nodeSetFocus: forcing container focus");
  6626. this._callHook("treeSetFocus", ctx, true, {
  6627. calledByNode: true,
  6628. });
  6629. }
  6630. node.makeVisible({ scrollIntoView: false });
  6631. tree.focusNode = node;
  6632. if (opts.titlesTabbable) {
  6633. if (!isInput) {
  6634. // #621
  6635. $(node.span)
  6636. .find(".fancytree-title")
  6637. .focus();
  6638. }
  6639. }
  6640. if (opts.aria) {
  6641. // Set active descendant to node's span ID (create one, if needed)
  6642. $(tree.$container).attr(
  6643. "aria-activedescendant",
  6644. $(node.tr || node.li)
  6645. .uniqueId()
  6646. .attr("id")
  6647. );
  6648. // "ftal_" + opts.idPrefix + node.key);
  6649. }
  6650. // $(node.span).find(".fancytree-title").focus();
  6651. this._triggerNodeEvent("focus", ctx);
  6652. // determine if we have focus on or inside tree container
  6653. var hasFancytreeFocus =
  6654. document.activeElement === tree.$container.get(0) ||
  6655. $(document.activeElement, tree.$container).length >= 1;
  6656. if (!hasFancytreeFocus) {
  6657. // We cannot set KB focus to a node, so use the tree container
  6658. // #563, #570: IE scrolls on every call to .focus(), if the container
  6659. // is partially outside the viewport. So do it only, when absolutely
  6660. // necessary.
  6661. $(tree.$container).focus();
  6662. }
  6663. // if( opts.autoActivate ){
  6664. // tree.nodeSetActive(ctx, true);
  6665. // }
  6666. if (opts.autoScroll) {
  6667. node.scrollIntoView();
  6668. }
  6669. this._callHook("nodeRenderStatus", ctx);
  6670. }
  6671. },
  6672. /** (De)Select node, return new status (sync).
  6673. *
  6674. * @param {EventData} ctx
  6675. * @param {boolean} [flag=true]
  6676. * @param {object} [opts] additional options. Defaults to {noEvents: false,
  6677. * propagateDown: null, propagateUp: null,
  6678. * callback: null,
  6679. * }
  6680. * @returns {boolean} previous status
  6681. */
  6682. nodeSetSelected: function(ctx, flag, callOpts) {
  6683. callOpts = callOpts || {};
  6684. var node = ctx.node,
  6685. tree = ctx.tree,
  6686. opts = ctx.options,
  6687. noEvents = callOpts.noEvents === true,
  6688. parent = node.parent;
  6689. // flag defaults to true
  6690. flag = flag !== false;
  6691. // node.debug("nodeSetSelected(" + flag + ")", ctx);
  6692. // Cannot (de)select unselectable nodes directly (only by propagation or
  6693. // by setting the `.selected` property)
  6694. if (FT.evalOption("unselectable", node, node, opts, false)) {
  6695. return;
  6696. }
  6697. // Remember the user's intent, in case down -> up propagation prevents
  6698. // applying it to node.selected
  6699. node._lastSelectIntent = flag; // Confusing use of '!'
  6700. // Nothing to do?
  6701. if (!!node.selected === flag) {
  6702. if (opts.selectMode === 3 && node.partsel && !flag) {
  6703. // If propagation prevented selecting this node last time, we still
  6704. // want to allow to apply setSelected(false) now
  6705. } else {
  6706. return flag;
  6707. }
  6708. }
  6709. if (
  6710. !noEvents &&
  6711. this._triggerNodeEvent(
  6712. "beforeSelect",
  6713. node,
  6714. ctx.originalEvent
  6715. ) === false
  6716. ) {
  6717. return !!node.selected;
  6718. }
  6719. if (flag && opts.selectMode === 1) {
  6720. // single selection mode (we don't uncheck all tree nodes, for performance reasons)
  6721. if (tree.lastSelectedNode) {
  6722. tree.lastSelectedNode.setSelected(false);
  6723. }
  6724. node.selected = flag;
  6725. } else if (
  6726. opts.selectMode === 3 &&
  6727. parent &&
  6728. !parent.radiogroup &&
  6729. !node.radiogroup
  6730. ) {
  6731. // multi-hierarchical selection mode
  6732. node.selected = flag;
  6733. node.fixSelection3AfterClick(callOpts);
  6734. } else if (parent && parent.radiogroup) {
  6735. node.visitSiblings(function(n) {
  6736. n._changeSelectStatusAttrs(flag && n === node);
  6737. }, true);
  6738. } else {
  6739. // default: selectMode: 2, multi selection mode
  6740. node.selected = flag;
  6741. }
  6742. this.nodeRenderStatus(ctx);
  6743. tree.lastSelectedNode = flag ? node : null;
  6744. if (!noEvents) {
  6745. tree._triggerNodeEvent("select", ctx);
  6746. }
  6747. },
  6748. /** Show node status (ok, loading, error, nodata) using styles and a dummy child node.
  6749. *
  6750. * @param {EventData} ctx
  6751. * @param status
  6752. * @param message
  6753. * @param details
  6754. * @since 2.3
  6755. */
  6756. nodeSetStatus: function(ctx, status, message, details) {
  6757. var node = ctx.node,
  6758. tree = ctx.tree;
  6759. function _clearStatusNode() {
  6760. // Remove dedicated dummy node, if any
  6761. var firstChild = node.children ? node.children[0] : null;
  6762. if (firstChild && firstChild.isStatusNode()) {
  6763. try {
  6764. // I've seen exceptions here with loadKeyPath...
  6765. if (node.ul) {
  6766. node.ul.removeChild(firstChild.li);
  6767. firstChild.li = null; // avoid leaks (DT issue 215)
  6768. }
  6769. } catch (e) {}
  6770. if (node.children.length === 1) {
  6771. node.children = [];
  6772. } else {
  6773. node.children.shift();
  6774. }
  6775. tree._callHook(
  6776. "treeStructureChanged",
  6777. ctx,
  6778. "clearStatusNode"
  6779. );
  6780. }
  6781. }
  6782. function _setStatusNode(data, type) {
  6783. // Create/modify the dedicated dummy node for 'loading...' or
  6784. // 'error!' status. (only called for direct child of the invisible
  6785. // system root)
  6786. var firstChild = node.children ? node.children[0] : null;
  6787. if (firstChild && firstChild.isStatusNode()) {
  6788. $.extend(firstChild, data);
  6789. firstChild.statusNodeType = type;
  6790. tree._callHook("nodeRenderTitle", firstChild);
  6791. } else {
  6792. node._setChildren([data]);
  6793. tree._callHook(
  6794. "treeStructureChanged",
  6795. ctx,
  6796. "setStatusNode"
  6797. );
  6798. node.children[0].statusNodeType = type;
  6799. tree.render();
  6800. }
  6801. return node.children[0];
  6802. }
  6803. switch (status) {
  6804. case "ok":
  6805. _clearStatusNode();
  6806. node._isLoading = false;
  6807. node._error = null;
  6808. node.renderStatus();
  6809. break;
  6810. case "loading":
  6811. if (!node.parent) {
  6812. _setStatusNode(
  6813. {
  6814. title:
  6815. tree.options.strings.loading +
  6816. (message ? " (" + message + ")" : ""),
  6817. // icon: true, // needed for 'loding' icon
  6818. checkbox: false,
  6819. tooltip: details,
  6820. },
  6821. status
  6822. );
  6823. }
  6824. node._isLoading = true;
  6825. node._error = null;
  6826. node.renderStatus();
  6827. break;
  6828. case "error":
  6829. _setStatusNode(
  6830. {
  6831. title:
  6832. tree.options.strings.loadError +
  6833. (message ? " (" + message + ")" : ""),
  6834. // icon: false,
  6835. checkbox: false,
  6836. tooltip: details,
  6837. },
  6838. status
  6839. );
  6840. node._isLoading = false;
  6841. node._error = { message: message, details: details };
  6842. node.renderStatus();
  6843. break;
  6844. case "nodata":
  6845. _setStatusNode(
  6846. {
  6847. title: message || tree.options.strings.noData,
  6848. // icon: false,
  6849. checkbox: false,
  6850. tooltip: details,
  6851. },
  6852. status
  6853. );
  6854. node._isLoading = false;
  6855. node._error = null;
  6856. node.renderStatus();
  6857. break;
  6858. default:
  6859. $.error("invalid node status " + status);
  6860. }
  6861. },
  6862. /**
  6863. *
  6864. * @param {EventData} ctx
  6865. */
  6866. nodeToggleExpanded: function(ctx) {
  6867. return this.nodeSetExpanded(ctx, !ctx.node.expanded);
  6868. },
  6869. /**
  6870. * @param {EventData} ctx
  6871. */
  6872. nodeToggleSelected: function(ctx) {
  6873. var node = ctx.node,
  6874. flag = !node.selected;
  6875. // In selectMode: 3 this node may be unselected+partsel, even if
  6876. // setSelected(true) was called before, due to `unselectable` children.
  6877. // In this case, we now toggle as `setSelected(false)`
  6878. if (
  6879. node.partsel &&
  6880. !node.selected &&
  6881. node._lastSelectIntent === true
  6882. ) {
  6883. flag = false;
  6884. node.selected = true; // so it is not considered 'nothing to do'
  6885. }
  6886. node._lastSelectIntent = flag;
  6887. return this.nodeSetSelected(ctx, flag);
  6888. },
  6889. /** Remove all nodes.
  6890. * @param {EventData} ctx
  6891. */
  6892. treeClear: function(ctx) {
  6893. var tree = ctx.tree;
  6894. tree.activeNode = null;
  6895. tree.focusNode = null;
  6896. tree.$div.find(">ul.fancytree-container").empty();
  6897. // TODO: call destructors and remove reference loops
  6898. tree.rootNode.children = null;
  6899. tree._callHook("treeStructureChanged", ctx, "clear");
  6900. },
  6901. /** Widget was created (called only once, even it re-initialized).
  6902. * @param {EventData} ctx
  6903. */
  6904. treeCreate: function(ctx) {},
  6905. /** Widget was destroyed.
  6906. * @param {EventData} ctx
  6907. */
  6908. treeDestroy: function(ctx) {
  6909. this.$div.find(">ul.fancytree-container").remove();
  6910. if (this.$source) {
  6911. this.$source.removeClass("fancytree-helper-hidden");
  6912. }
  6913. },
  6914. /** Widget was (re-)initialized.
  6915. * @param {EventData} ctx
  6916. */
  6917. treeInit: function(ctx) {
  6918. var tree = ctx.tree,
  6919. opts = tree.options;
  6920. //this.debug("Fancytree.treeInit()");
  6921. // Add container to the TAB chain
  6922. // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  6923. // #577: Allow to set tabindex to "0", "-1" and ""
  6924. tree.$container.attr("tabindex", opts.tabindex);
  6925. // Copy some attributes to tree.data
  6926. $.each(TREE_ATTRS, function(i, attr) {
  6927. if (opts[attr] !== undefined) {
  6928. tree.info("Move option " + attr + " to tree");
  6929. tree[attr] = opts[attr];
  6930. delete opts[attr];
  6931. }
  6932. });
  6933. if (opts.checkboxAutoHide) {
  6934. tree.$container.addClass("fancytree-checkbox-auto-hide");
  6935. }
  6936. if (opts.rtl) {
  6937. tree.$container
  6938. .attr("DIR", "RTL")
  6939. .addClass("fancytree-rtl");
  6940. } else {
  6941. tree.$container
  6942. .removeAttr("DIR")
  6943. .removeClass("fancytree-rtl");
  6944. }
  6945. if (opts.aria) {
  6946. tree.$container.attr("role", "tree");
  6947. if (opts.selectMode !== 1) {
  6948. tree.$container.attr("aria-multiselectable", true);
  6949. }
  6950. }
  6951. this.treeLoad(ctx);
  6952. },
  6953. /** Parse Fancytree from source, as configured in the options.
  6954. * @param {EventData} ctx
  6955. * @param {object} [source] optional new source (use last data otherwise)
  6956. */
  6957. treeLoad: function(ctx, source) {
  6958. var metaData,
  6959. type,
  6960. $ul,
  6961. tree = ctx.tree,
  6962. $container = ctx.widget.element,
  6963. dfd,
  6964. // calling context for root node
  6965. rootCtx = $.extend({}, ctx, { node: this.rootNode });
  6966. if (tree.rootNode.children) {
  6967. this.treeClear(ctx);
  6968. }
  6969. source = source || this.options.source;
  6970. if (!source) {
  6971. type = $container.data("type") || "html";
  6972. switch (type) {
  6973. case "html":
  6974. // There should be an embedded `<ul>` with initial nodes,
  6975. // but another `<ul class='fancytree-container'>` is appended
  6976. // to the tree's <div> on startup anyway.
  6977. $ul = $container
  6978. .find(">ul")
  6979. .not(".fancytree-container")
  6980. .first();
  6981. if ($ul.length) {
  6982. $ul.addClass(
  6983. "ui-fancytree-source fancytree-helper-hidden"
  6984. );
  6985. source = $.ui.fancytree.parseHtml($ul);
  6986. // allow to init tree.data.foo from <ul data-foo=''>
  6987. this.data = $.extend(
  6988. this.data,
  6989. _getElementDataAsDict($ul)
  6990. );
  6991. } else {
  6992. FT.warn(
  6993. "No `source` option was passed and container does not contain `<ul>`: assuming `source: []`."
  6994. );
  6995. source = [];
  6996. }
  6997. break;
  6998. case "json":
  6999. source = $.parseJSON($container.text());
  7000. // $container already contains the <ul>, but we remove the plain (json) text
  7001. // $container.empty();
  7002. $container
  7003. .contents()
  7004. .filter(function() {
  7005. return this.nodeType === 3;
  7006. })
  7007. .remove();
  7008. if ($.isPlainObject(source)) {
  7009. // We got {foo: 'abc', children: [...]}
  7010. _assert(
  7011. $.isArray(source.children),
  7012. "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')"
  7013. );
  7014. metaData = source;
  7015. source = source.children;
  7016. delete metaData.children;
  7017. // Copy some attributes to tree.data
  7018. $.each(TREE_ATTRS, function(i, attr) {
  7019. if (metaData[attr] !== undefined) {
  7020. tree[attr] = metaData[attr];
  7021. delete metaData[attr];
  7022. }
  7023. });
  7024. // Copy extra properties to tree.data.foo
  7025. $.extend(tree.data, metaData);
  7026. }
  7027. break;
  7028. default:
  7029. $.error("Invalid data-type: " + type);
  7030. }
  7031. } else if (typeof source === "string") {
  7032. // TODO: source is an element ID
  7033. $.error("Not implemented");
  7034. }
  7035. // preInit is fired when the widget markup is created, but nodes
  7036. // not yet loaded
  7037. tree._triggerTreeEvent("preInit", null);
  7038. // Trigger fancytreeinit after nodes have been loaded
  7039. dfd = this.nodeLoadChildren(rootCtx, source)
  7040. .done(function() {
  7041. tree._callHook(
  7042. "treeStructureChanged",
  7043. ctx,
  7044. "loadChildren"
  7045. );
  7046. tree.render();
  7047. if (ctx.options.selectMode === 3) {
  7048. tree.rootNode.fixSelection3FromEndNodes();
  7049. }
  7050. if (tree.activeNode && tree.options.activeVisible) {
  7051. tree.activeNode.makeVisible();
  7052. }
  7053. tree._triggerTreeEvent("init", null, { status: true });
  7054. })
  7055. .fail(function() {
  7056. tree.render();
  7057. tree._triggerTreeEvent("init", null, { status: false });
  7058. });
  7059. return dfd;
  7060. },
  7061. /** Node was inserted into or removed from the tree.
  7062. * @param {EventData} ctx
  7063. * @param {boolean} add
  7064. * @param {FancytreeNode} node
  7065. */
  7066. treeRegisterNode: function(ctx, add, node) {
  7067. ctx.tree._callHook(
  7068. "treeStructureChanged",
  7069. ctx,
  7070. add ? "addNode" : "removeNode"
  7071. );
  7072. },
  7073. /** Widget got focus.
  7074. * @param {EventData} ctx
  7075. * @param {boolean} [flag=true]
  7076. */
  7077. treeSetFocus: function(ctx, flag, callOpts) {
  7078. var targetNode;
  7079. flag = flag !== false;
  7080. // this.debug("treeSetFocus(" + flag + "), callOpts: ", callOpts, this.hasFocus());
  7081. // this.debug(" focusNode: " + this.focusNode);
  7082. // this.debug(" activeNode: " + this.activeNode);
  7083. if (flag !== this.hasFocus()) {
  7084. this._hasFocus = flag;
  7085. if (!flag && this.focusNode) {
  7086. // Node also looses focus if widget blurs
  7087. this.focusNode.setFocus(false);
  7088. } else if (flag && (!callOpts || !callOpts.calledByNode)) {
  7089. $(this.$container).focus();
  7090. }
  7091. this.$container.toggleClass("fancytree-treefocus", flag);
  7092. this._triggerTreeEvent(flag ? "focusTree" : "blurTree");
  7093. if (flag && !this.activeNode) {
  7094. // #712: Use last mousedowned node ('click' event fires after focusin)
  7095. targetNode =
  7096. this._lastMousedownNode || this.getFirstChild();
  7097. if (targetNode) {
  7098. targetNode.setFocus();
  7099. }
  7100. }
  7101. }
  7102. },
  7103. /** Widget option was set using `$().fancytree("option", "KEY", VALUE)`.
  7104. *
  7105. * Note: `key` may reference a nested option, e.g. 'dnd5.scroll'.
  7106. * In this case `value`contains the complete, modified `dnd5` option hash.
  7107. * We can check for changed values like
  7108. * if( value.scroll !== tree.options.dnd5.scroll ) {...}
  7109. *
  7110. * @param {EventData} ctx
  7111. * @param {string} key option name
  7112. * @param {any} value option value
  7113. */
  7114. treeSetOption: function(ctx, key, value) {
  7115. var tree = ctx.tree,
  7116. callDefault = true,
  7117. callCreate = false,
  7118. callRender = false;
  7119. switch (key) {
  7120. case "aria":
  7121. case "checkbox":
  7122. case "icon":
  7123. case "minExpandLevel":
  7124. case "tabindex":
  7125. // tree._callHook("treeCreate", tree);
  7126. callCreate = true;
  7127. callRender = true;
  7128. break;
  7129. case "checkboxAutoHide":
  7130. tree.$container.toggleClass(
  7131. "fancytree-checkbox-auto-hide",
  7132. !!value
  7133. );
  7134. break;
  7135. case "escapeTitles":
  7136. case "tooltip":
  7137. callRender = true;
  7138. break;
  7139. case "rtl":
  7140. if (value === false) {
  7141. tree.$container
  7142. .removeAttr("DIR")
  7143. .removeClass("fancytree-rtl");
  7144. } else {
  7145. tree.$container
  7146. .attr("DIR", "RTL")
  7147. .addClass("fancytree-rtl");
  7148. }
  7149. callRender = true;
  7150. break;
  7151. case "source":
  7152. callDefault = false;
  7153. tree._callHook("treeLoad", tree, value);
  7154. callRender = true;
  7155. break;
  7156. }
  7157. tree.debug(
  7158. "set option " +
  7159. key +
  7160. "=" +
  7161. value +
  7162. " <" +
  7163. typeof value +
  7164. ">"
  7165. );
  7166. if (callDefault) {
  7167. if (this.widget._super) {
  7168. // jQuery UI 1.9+
  7169. this.widget._super.call(this.widget, key, value);
  7170. } else {
  7171. // jQuery UI <= 1.8, we have to manually invoke the _setOption method from the base widget
  7172. $.Widget.prototype._setOption.call(
  7173. this.widget,
  7174. key,
  7175. value
  7176. );
  7177. }
  7178. }
  7179. if (callCreate) {
  7180. tree._callHook("treeCreate", tree);
  7181. }
  7182. if (callRender) {
  7183. tree.render(true, false); // force, not-deep
  7184. }
  7185. },
  7186. /** A Node was added, removed, moved, or it's visibility changed.
  7187. * @param {EventData} ctx
  7188. */
  7189. treeStructureChanged: function(ctx, type) {},
  7190. }
  7191. );
  7192. /*******************************************************************************
  7193. * jQuery UI widget boilerplate
  7194. */
  7195. /**
  7196. * The plugin (derrived from [jQuery.Widget](http://api.jqueryui.com/jQuery.widget/)).
  7197. *
  7198. * **Note:**
  7199. * These methods implement the standard jQuery UI widget API.
  7200. * It is recommended to use methods of the {Fancytree} instance instead
  7201. *
  7202. * @example
  7203. * // DEPRECATED: Access jQuery UI widget methods and members:
  7204. * var tree = $("#tree").fancytree("getTree", "#myTree");
  7205. * var node = $.ui.fancytree.getTree("#tree").getActiveNode();
  7206. *
  7207. * // RECOMMENDED: Use the Fancytree object API
  7208. * var tree = $.ui.fancytree.getTree("#myTree");
  7209. * var node = tree.getActiveNode();
  7210. *
  7211. * // or you may already have stored the tree instance upon creation:
  7212. * import {createTree, version} from 'jquery.fancytree'
  7213. * const tree = createTree('#tree', { ... });
  7214. * var node = tree.getActiveNode();
  7215. *
  7216. * @see {Fancytree_Static#getTree}
  7217. * @deprecated Use methods of the {Fancytree} instance instead
  7218. * @mixin Fancytree_Widget
  7219. */
  7220. $.widget(
  7221. "ui.fancytree",
  7222. /** @lends Fancytree_Widget# */
  7223. {
  7224. /**These options will be used as defaults
  7225. * @type {FancytreeOptions}
  7226. */
  7227. options: {
  7228. activeVisible: true,
  7229. ajax: {
  7230. type: "GET",
  7231. cache: false, // false: Append random '_' argument to the request url to prevent caching.
  7232. // timeout: 0, // >0: Make sure we get an ajax error if server is unreachable
  7233. dataType: "json", // Expect json format and pass json object to callbacks.
  7234. },
  7235. aria: true,
  7236. autoActivate: true,
  7237. autoCollapse: false,
  7238. autoScroll: false,
  7239. checkbox: false,
  7240. clickFolderMode: 4,
  7241. copyFunctionsToData: false,
  7242. debugLevel: null, // 0..4 (null: use global setting $.ui.fancytree.debugLevel)
  7243. disabled: false, // TODO: required anymore?
  7244. enableAspx: 42, // TODO: this is truethy, but distinguishable from true: default will change to false in the future
  7245. escapeTitles: false,
  7246. extensions: [],
  7247. focusOnSelect: false,
  7248. generateIds: false,
  7249. icon: true,
  7250. idPrefix: "ft_",
  7251. keyboard: true,
  7252. keyPathSeparator: "/",
  7253. minExpandLevel: 1,
  7254. nodata: true, // (bool, string, or callback) display message, when no data available
  7255. quicksearch: false,
  7256. rtl: false,
  7257. scrollOfs: { top: 0, bottom: 0 },
  7258. scrollParent: null,
  7259. selectMode: 2,
  7260. strings: {
  7261. loading: "Loading...", // &#8230; would be escaped when escapeTitles is true
  7262. loadError: "Load error!",
  7263. moreData: "More...",
  7264. noData: "No data.",
  7265. },
  7266. tabindex: "0",
  7267. titlesTabbable: false,
  7268. toggleEffect: { effect: "slideToggle", duration: 200 }, //< "toggle" or "slideToggle" to use jQuery instead of jQueryUI for toggleEffect animation
  7269. tooltip: false,
  7270. treeId: null,
  7271. _classNames: {
  7272. active: "fancytree-active",
  7273. animating: "fancytree-animating",
  7274. combinedExpanderPrefix: "fancytree-exp-",
  7275. combinedIconPrefix: "fancytree-ico-",
  7276. error: "fancytree-error",
  7277. expanded: "fancytree-expanded",
  7278. focused: "fancytree-focused",
  7279. folder: "fancytree-folder",
  7280. hasChildren: "fancytree-has-children",
  7281. lastsib: "fancytree-lastsib",
  7282. lazy: "fancytree-lazy",
  7283. loading: "fancytree-loading",
  7284. node: "fancytree-node",
  7285. partload: "fancytree-partload",
  7286. partsel: "fancytree-partsel",
  7287. radio: "fancytree-radio",
  7288. selected: "fancytree-selected",
  7289. statusNodePrefix: "fancytree-statusnode-",
  7290. unselectable: "fancytree-unselectable",
  7291. },
  7292. // events
  7293. lazyLoad: null,
  7294. postProcess: null,
  7295. },
  7296. _deprecationWarning: function(name) {
  7297. var tree = this.tree;
  7298. if (tree && tree.options.debugLevel >= 3) {
  7299. tree.warn(
  7300. "$().fancytree('" +
  7301. name +
  7302. "') is deprecated (see https://wwwendt.de/tech/fancytree/doc/jsdoc/Fancytree_Widget.html"
  7303. );
  7304. }
  7305. },
  7306. /* Set up the widget, Called on first $().fancytree() */
  7307. _create: function() {
  7308. this.tree = new Fancytree(this);
  7309. this.$source =
  7310. this.source || this.element.data("type") === "json"
  7311. ? this.element
  7312. : this.element.find(">ul").first();
  7313. // Subclass Fancytree instance with all enabled extensions
  7314. var extension,
  7315. extName,
  7316. i,
  7317. opts = this.options,
  7318. extensions = opts.extensions,
  7319. base = this.tree;
  7320. for (i = 0; i < extensions.length; i++) {
  7321. extName = extensions[i];
  7322. extension = $.ui.fancytree._extensions[extName];
  7323. if (!extension) {
  7324. $.error(
  7325. "Could not apply extension '" +
  7326. extName +
  7327. "' (it is not registered, did you forget to include it?)"
  7328. );
  7329. }
  7330. // Add extension options as tree.options.EXTENSION
  7331. // _assert(!this.tree.options[extName], "Extension name must not exist as option name: " + extName);
  7332. // console.info("extend " + extName, extension.options, this.tree.options[extName])
  7333. // issue #876: we want to replace custom array-options, not merge them
  7334. this.tree.options[extName] = _simpleDeepMerge(
  7335. {},
  7336. extension.options,
  7337. this.tree.options[extName]
  7338. );
  7339. // this.tree.options[extName] = $.extend(true, {}, extension.options, this.tree.options[extName]);
  7340. // console.info("extend " + extName + " =>", this.tree.options[extName])
  7341. // console.info("extend " + extName + " org default =>", extension.options)
  7342. // Add a namespace tree.ext.EXTENSION, to hold instance data
  7343. _assert(
  7344. this.tree.ext[extName] === undefined,
  7345. "Extension name must not exist as Fancytree.ext attribute: '" +
  7346. extName +
  7347. "'"
  7348. );
  7349. // this.tree[extName] = extension;
  7350. this.tree.ext[extName] = {};
  7351. // Subclass Fancytree methods using proxies.
  7352. _subclassObject(this.tree, base, extension, extName);
  7353. // current extension becomes base for the next extension
  7354. base = extension;
  7355. }
  7356. //
  7357. if (opts.icons !== undefined) {
  7358. // 2015-11-16
  7359. if (opts.icon === true) {
  7360. this.tree.warn(
  7361. "'icons' tree option is deprecated since v2.14.0: use 'icon' instead"
  7362. );
  7363. opts.icon = opts.icons;
  7364. } else {
  7365. $.error(
  7366. "'icons' tree option is deprecated since v2.14.0: use 'icon' only instead"
  7367. );
  7368. }
  7369. }
  7370. if (opts.iconClass !== undefined) {
  7371. // 2015-11-16
  7372. if (opts.icon) {
  7373. $.error(
  7374. "'iconClass' tree option is deprecated since v2.14.0: use 'icon' only instead"
  7375. );
  7376. } else {
  7377. this.tree.warn(
  7378. "'iconClass' tree option is deprecated since v2.14.0: use 'icon' instead"
  7379. );
  7380. opts.icon = opts.iconClass;
  7381. }
  7382. }
  7383. if (opts.tabbable !== undefined) {
  7384. // 2016-04-04
  7385. opts.tabindex = opts.tabbable ? "0" : "-1";
  7386. this.tree.warn(
  7387. "'tabbable' tree option is deprecated since v2.17.0: use 'tabindex='" +
  7388. opts.tabindex +
  7389. "' instead"
  7390. );
  7391. }
  7392. //
  7393. this.tree._callHook("treeCreate", this.tree);
  7394. // Note: 'fancytreecreate' event is fired by widget base class
  7395. // this.tree._triggerTreeEvent("create");
  7396. },
  7397. /* Called on every $().fancytree() */
  7398. _init: function() {
  7399. this.tree._callHook("treeInit", this.tree);
  7400. // TODO: currently we call bind after treeInit, because treeInit
  7401. // might change tree.$container.
  7402. // It would be better, to move event binding into hooks altogether
  7403. this._bind();
  7404. },
  7405. /* Use the _setOption method to respond to changes to options. */
  7406. _setOption: function(key, value) {
  7407. return this.tree._callHook(
  7408. "treeSetOption",
  7409. this.tree,
  7410. key,
  7411. value
  7412. );
  7413. },
  7414. /** Use the destroy method to clean up any modifications your widget has made to the DOM */
  7415. _destroy: function() {
  7416. this._unbind();
  7417. this.tree._callHook("treeDestroy", this.tree);
  7418. // In jQuery UI 1.8, you must invoke the destroy method from the base widget
  7419. // $.Widget.prototype.destroy.call(this);
  7420. // TODO: delete tree and nodes to make garbage collect easier?
  7421. // TODO: In jQuery UI 1.9 and above, you would define _destroy instead of destroy and not call the base method
  7422. },
  7423. // -------------------------------------------------------------------------
  7424. /* Remove all event handlers for our namespace */
  7425. _unbind: function() {
  7426. var ns = this.tree._ns;
  7427. this.element.off(ns);
  7428. this.tree.$container.off(ns);
  7429. $(document).off(ns);
  7430. },
  7431. /* Add mouse and kyboard handlers to the container */
  7432. _bind: function() {
  7433. var self = this,
  7434. opts = this.options,
  7435. tree = this.tree,
  7436. ns = tree._ns;
  7437. // selstartEvent = ( $.support.selectstart ? "selectstart" : "mousedown" )
  7438. // Remove all previuous handlers for this tree
  7439. this._unbind();
  7440. //alert("keydown" + ns + "foc=" + tree.hasFocus() + tree.$container);
  7441. // tree.debug("bind events; container: ", tree.$container);
  7442. tree.$container
  7443. .on("focusin" + ns + " focusout" + ns, function(event) {
  7444. var node = FT.getNode(event),
  7445. flag = event.type === "focusin";
  7446. if (!flag && node && $(event.target).is("a")) {
  7447. // #764
  7448. node.debug(
  7449. "Ignored focusout on embedded <a> element."
  7450. );
  7451. return;
  7452. }
  7453. // tree.treeOnFocusInOut.call(tree, event);
  7454. // tree.debug("Tree container got event " + event.type, node, event, FT.getEventTarget(event));
  7455. if (flag) {
  7456. if (tree._getExpiringValue("focusin")) {
  7457. // #789: IE 11 may send duplicate focusin events
  7458. tree.debug("Ignored double focusin.");
  7459. return;
  7460. }
  7461. tree._setExpiringValue("focusin", true, 50);
  7462. if (!node) {
  7463. // #789: IE 11 may send focusin before mousdown(?)
  7464. node = tree._getExpiringValue("mouseDownNode");
  7465. if (node) {
  7466. tree.debug(
  7467. "Reconstruct mouse target for focusin from recent event."
  7468. );
  7469. }
  7470. }
  7471. }
  7472. if (node) {
  7473. // For example clicking into an <input> that is part of a node
  7474. tree._callHook(
  7475. "nodeSetFocus",
  7476. tree._makeHookContext(node, event),
  7477. flag
  7478. );
  7479. } else {
  7480. if (
  7481. tree.tbody &&
  7482. $(event.target).parents(
  7483. "table.fancytree-container > thead"
  7484. ).length
  7485. ) {
  7486. // #767: ignore events in the table's header
  7487. tree.debug(
  7488. "Ignore focus event outside table body.",
  7489. event
  7490. );
  7491. } else {
  7492. tree._callHook("treeSetFocus", tree, flag);
  7493. }
  7494. }
  7495. })
  7496. .on("selectstart" + ns, "span.fancytree-title", function(
  7497. event
  7498. ) {
  7499. // prevent mouse-drags to select text ranges
  7500. // tree.debug("<span title> got event " + event.type);
  7501. event.preventDefault();
  7502. })
  7503. .on("keydown" + ns, function(event) {
  7504. // TODO: also bind keyup and keypress
  7505. // tree.debug("got event " + event.type + ", hasFocus:" + tree.hasFocus());
  7506. // if(opts.disabled || opts.keyboard === false || !tree.hasFocus() ){
  7507. if (opts.disabled || opts.keyboard === false) {
  7508. return true;
  7509. }
  7510. var res,
  7511. node = tree.focusNode, // node may be null
  7512. ctx = tree._makeHookContext(node || tree, event),
  7513. prevPhase = tree.phase;
  7514. try {
  7515. tree.phase = "userEvent";
  7516. // If a 'fancytreekeydown' handler returns false, skip the default
  7517. // handling (implemented by tree.nodeKeydown()).
  7518. if (node) {
  7519. res = tree._triggerNodeEvent(
  7520. "keydown",
  7521. node,
  7522. event
  7523. );
  7524. } else {
  7525. res = tree._triggerTreeEvent("keydown", event);
  7526. }
  7527. if (res === "preventNav") {
  7528. res = true; // prevent keyboard navigation, but don't prevent default handling of embedded input controls
  7529. } else if (res !== false) {
  7530. res = tree._callHook("nodeKeydown", ctx);
  7531. }
  7532. return res;
  7533. } finally {
  7534. tree.phase = prevPhase;
  7535. }
  7536. })
  7537. .on("mousedown" + ns, function(event) {
  7538. var et = FT.getEventTarget(event);
  7539. // self.tree.debug("event(" + event.type + "): node: ", et.node);
  7540. // #712: Store the clicked node, so we can use it when we get a focusin event
  7541. // ('click' event fires after focusin)
  7542. // tree.debug("event(" + event.type + "): node: ", et.node);
  7543. tree._lastMousedownNode = et ? et.node : null;
  7544. // #789: Store the node also for a short period, so we can use it
  7545. // in a *resulting* focusin event
  7546. tree._setExpiringValue(
  7547. "mouseDownNode",
  7548. tree._lastMousedownNode
  7549. );
  7550. })
  7551. .on("click" + ns + " dblclick" + ns, function(event) {
  7552. if (opts.disabled) {
  7553. return true;
  7554. }
  7555. var ctx,
  7556. et = FT.getEventTarget(event),
  7557. node = et.node,
  7558. tree = self.tree,
  7559. prevPhase = tree.phase;
  7560. // self.tree.debug("event(" + event.type + "): node: ", node);
  7561. if (!node) {
  7562. return true; // Allow bubbling of other events
  7563. }
  7564. ctx = tree._makeHookContext(node, event);
  7565. // self.tree.debug("event(" + event.type + "): node: ", node);
  7566. try {
  7567. tree.phase = "userEvent";
  7568. switch (event.type) {
  7569. case "click":
  7570. ctx.targetType = et.type;
  7571. if (node.isPagingNode()) {
  7572. return (
  7573. tree._triggerNodeEvent(
  7574. "clickPaging",
  7575. ctx,
  7576. event
  7577. ) === true
  7578. );
  7579. }
  7580. return tree._triggerNodeEvent(
  7581. "click",
  7582. ctx,
  7583. event
  7584. ) === false
  7585. ? false
  7586. : tree._callHook("nodeClick", ctx);
  7587. case "dblclick":
  7588. ctx.targetType = et.type;
  7589. return tree._triggerNodeEvent(
  7590. "dblclick",
  7591. ctx,
  7592. event
  7593. ) === false
  7594. ? false
  7595. : tree._callHook("nodeDblclick", ctx);
  7596. }
  7597. } finally {
  7598. tree.phase = prevPhase;
  7599. }
  7600. });
  7601. },
  7602. /** Return the active node or null.
  7603. * @returns {FancytreeNode}
  7604. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7605. */
  7606. getActiveNode: function() {
  7607. this._deprecationWarning("getActiveNode");
  7608. return this.tree.activeNode;
  7609. },
  7610. /** Return the matching node or null.
  7611. * @param {string} key
  7612. * @returns {FancytreeNode}
  7613. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7614. */
  7615. getNodeByKey: function(key) {
  7616. this._deprecationWarning("getNodeByKey");
  7617. return this.tree.getNodeByKey(key);
  7618. },
  7619. /** Return the invisible system root node.
  7620. * @returns {FancytreeNode}
  7621. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7622. */
  7623. getRootNode: function() {
  7624. this._deprecationWarning("getRootNode");
  7625. return this.tree.rootNode;
  7626. },
  7627. /** Return the current tree instance.
  7628. * @returns {Fancytree}
  7629. * @deprecated Use `$.ui.fancytree.getTree()` instead (<a href="Fancytree_Widget.html">example above</a>).
  7630. */
  7631. getTree: function() {
  7632. this._deprecationWarning("getTree");
  7633. return this.tree;
  7634. },
  7635. }
  7636. );
  7637. // $.ui.fancytree was created by the widget factory. Create a local shortcut:
  7638. FT = $.ui.fancytree;
  7639. /**
  7640. * Static members in the `$.ui.fancytree` namespace.
  7641. * This properties and methods can be accessed without instantiating a concrete
  7642. * Fancytree instance.
  7643. *
  7644. * @example
  7645. * // Access static members:
  7646. * var node = $.ui.fancytree.getNode(element);
  7647. * alert($.ui.fancytree.version);
  7648. *
  7649. * @mixin Fancytree_Static
  7650. */
  7651. $.extend(
  7652. $.ui.fancytree,
  7653. /** @lends Fancytree_Static# */
  7654. {
  7655. /** Version number `"MAJOR.MINOR.PATCH"`
  7656. * @type {string} */
  7657. version: "2.38.0", // Set to semver by 'grunt release'
  7658. /** @type {string}
  7659. * @description `"production" for release builds` */
  7660. buildType: "production", // Set to 'production' by 'grunt build'
  7661. /** @type {int}
  7662. * @description 0: silent .. 5: verbose (default: 3 for release builds). */
  7663. debugLevel: 3, // Set to 3 by 'grunt build'
  7664. // Used by $.ui.fancytree.debug() and as default for tree.options.debugLevel
  7665. _nextId: 1,
  7666. _nextNodeKey: 1,
  7667. _extensions: {},
  7668. // focusTree: null,
  7669. /** Expose class object as `$.ui.fancytree._FancytreeClass`.
  7670. * Useful to extend `$.ui.fancytree._FancytreeClass.prototype`.
  7671. * @type {Fancytree}
  7672. */
  7673. _FancytreeClass: Fancytree,
  7674. /** Expose class object as $.ui.fancytree._FancytreeNodeClass
  7675. * Useful to extend `$.ui.fancytree._FancytreeNodeClass.prototype`.
  7676. * @type {FancytreeNode}
  7677. */
  7678. _FancytreeNodeClass: FancytreeNode,
  7679. /* Feature checks to provide backwards compatibility */
  7680. jquerySupports: {
  7681. // http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7682. positionMyOfs: isVersionAtLeast($.ui.version, 1, 9),
  7683. },
  7684. /** Throw an error if condition fails (debug method).
  7685. * @param {boolean} cond
  7686. * @param {string} msg
  7687. */
  7688. assert: function(cond, msg) {
  7689. return _assert(cond, msg);
  7690. },
  7691. /** Create a new Fancytree instance on a target element.
  7692. *
  7693. * @param {Element | jQueryObject | string} el Target DOM element or selector
  7694. * @param {FancytreeOptions} [opts] Fancytree options
  7695. * @returns {Fancytree} new tree instance
  7696. * @example
  7697. * var tree = $.ui.fancytree.createTree("#tree", {
  7698. * source: {url: "my/webservice"}
  7699. * }); // Create tree for this matching element
  7700. *
  7701. * @since 2.25
  7702. */
  7703. createTree: function(el, opts) {
  7704. var $tree = $(el).fancytree(opts);
  7705. return FT.getTree($tree);
  7706. },
  7707. /** Return a function that executes *fn* at most every *timeout* ms.
  7708. * @param {integer} timeout
  7709. * @param {function} fn
  7710. * @param {boolean} [invokeAsap=false]
  7711. * @param {any} [ctx]
  7712. */
  7713. debounce: function(timeout, fn, invokeAsap, ctx) {
  7714. var timer;
  7715. if (arguments.length === 3 && typeof invokeAsap !== "boolean") {
  7716. ctx = invokeAsap;
  7717. invokeAsap = false;
  7718. }
  7719. return function() {
  7720. var args = arguments;
  7721. ctx = ctx || this;
  7722. // eslint-disable-next-line no-unused-expressions
  7723. invokeAsap && !timer && fn.apply(ctx, args);
  7724. clearTimeout(timer);
  7725. timer = setTimeout(function() {
  7726. // eslint-disable-next-line no-unused-expressions
  7727. invokeAsap || fn.apply(ctx, args);
  7728. timer = null;
  7729. }, timeout);
  7730. };
  7731. },
  7732. /** Write message to console if debugLevel >= 4
  7733. * @param {string} msg
  7734. */
  7735. debug: function(msg) {
  7736. if ($.ui.fancytree.debugLevel >= 4) {
  7737. consoleApply("log", arguments);
  7738. }
  7739. },
  7740. /** Write error message to console if debugLevel >= 1.
  7741. * @param {string} msg
  7742. */
  7743. error: function(msg) {
  7744. if ($.ui.fancytree.debugLevel >= 1) {
  7745. consoleApply("error", arguments);
  7746. }
  7747. },
  7748. /** Convert `<`, `>`, `&`, `"`, `'`, and `/` to the equivalent entities.
  7749. *
  7750. * @param {string} s
  7751. * @returns {string}
  7752. */
  7753. escapeHtml: function(s) {
  7754. return ("" + s).replace(REX_HTML, function(s) {
  7755. return ENTITY_MAP[s];
  7756. });
  7757. },
  7758. /** Make jQuery.position() arguments backwards compatible, i.e. if
  7759. * jQuery UI version <= 1.8, convert
  7760. * { my: "left+3 center", at: "left bottom", of: $target }
  7761. * to
  7762. * { my: "left center", at: "left bottom", of: $target, offset: "3 0" }
  7763. *
  7764. * See http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7765. * and http://jsfiddle.net/mar10/6xtu9a4e/
  7766. *
  7767. * @param {object} opts
  7768. * @returns {object} the (potentially modified) original opts hash object
  7769. */
  7770. fixPositionOptions: function(opts) {
  7771. if (opts.offset || ("" + opts.my + opts.at).indexOf("%") >= 0) {
  7772. $.error(
  7773. "expected new position syntax (but '%' is not supported)"
  7774. );
  7775. }
  7776. if (!$.ui.fancytree.jquerySupports.positionMyOfs) {
  7777. var // parse 'left+3 center' into ['left+3 center', 'left', '+3', 'center', undefined]
  7778. myParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(
  7779. opts.my
  7780. ),
  7781. atParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(
  7782. opts.at
  7783. ),
  7784. // convert to numbers
  7785. dx =
  7786. (myParts[2] ? +myParts[2] : 0) +
  7787. (atParts[2] ? +atParts[2] : 0),
  7788. dy =
  7789. (myParts[4] ? +myParts[4] : 0) +
  7790. (atParts[4] ? +atParts[4] : 0);
  7791. opts = $.extend({}, opts, {
  7792. // make a copy and overwrite
  7793. my: myParts[1] + " " + myParts[3],
  7794. at: atParts[1] + " " + atParts[3],
  7795. });
  7796. if (dx || dy) {
  7797. opts.offset = "" + dx + " " + dy;
  7798. }
  7799. }
  7800. return opts;
  7801. },
  7802. /** Return a {node: FancytreeNode, type: TYPE} object for a mouse event.
  7803. *
  7804. * @param {Event} event Mouse event, e.g. click, ...
  7805. * @returns {object} Return a {node: FancytreeNode, type: TYPE} object
  7806. * TYPE: 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7807. */
  7808. getEventTarget: function(event) {
  7809. var $target,
  7810. tree,
  7811. tcn = event && event.target ? event.target.className : "",
  7812. res = { node: this.getNode(event.target), type: undefined };
  7813. // We use a fast version of $(res.node).hasClass()
  7814. // See http://jsperf.com/test-for-classname/2
  7815. if (/\bfancytree-title\b/.test(tcn)) {
  7816. res.type = "title";
  7817. } else if (/\bfancytree-expander\b/.test(tcn)) {
  7818. res.type =
  7819. res.node.hasChildren() === false
  7820. ? "prefix"
  7821. : "expander";
  7822. // }else if( /\bfancytree-checkbox\b/.test(tcn) || /\bfancytree-radio\b/.test(tcn) ){
  7823. } else if (/\bfancytree-checkbox\b/.test(tcn)) {
  7824. res.type = "checkbox";
  7825. } else if (/\bfancytree(-custom)?-icon\b/.test(tcn)) {
  7826. res.type = "icon";
  7827. } else if (/\bfancytree-node\b/.test(tcn)) {
  7828. // Somewhere near the title
  7829. res.type = "title";
  7830. } else if (event && event.target) {
  7831. $target = $(event.target);
  7832. if ($target.is("ul[role=group]")) {
  7833. // #nnn: Clicking right to a node may hit the surrounding UL
  7834. tree = res.node && res.node.tree;
  7835. (tree || FT).debug("Ignoring click on outer UL.");
  7836. res.node = null;
  7837. } else if ($target.closest(".fancytree-title").length) {
  7838. // #228: clicking an embedded element inside a title
  7839. res.type = "title";
  7840. } else if ($target.closest(".fancytree-checkbox").length) {
  7841. // E.g. <svg> inside checkbox span
  7842. res.type = "checkbox";
  7843. } else if ($target.closest(".fancytree-expander").length) {
  7844. res.type = "expander";
  7845. }
  7846. }
  7847. return res;
  7848. },
  7849. /** Return a string describing the affected node region for a mouse event.
  7850. *
  7851. * @param {Event} event Mouse event, e.g. click, mousemove, ...
  7852. * @returns {string} 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7853. */
  7854. getEventTargetType: function(event) {
  7855. return this.getEventTarget(event).type;
  7856. },
  7857. /** Return a FancytreeNode instance from element, event, or jQuery object.
  7858. *
  7859. * @param {Element | jQueryObject | Event} el
  7860. * @returns {FancytreeNode} matching node or null
  7861. */
  7862. getNode: function(el) {
  7863. if (el instanceof FancytreeNode) {
  7864. return el; // el already was a FancytreeNode
  7865. } else if (el instanceof $) {
  7866. el = el[0]; // el was a jQuery object: use the DOM element
  7867. } else if (el.originalEvent !== undefined) {
  7868. el = el.target; // el was an Event
  7869. }
  7870. while (el) {
  7871. if (el.ftnode) {
  7872. return el.ftnode;
  7873. }
  7874. el = el.parentNode;
  7875. }
  7876. return null;
  7877. },
  7878. /** Return a Fancytree instance, from element, index, event, or jQueryObject.
  7879. *
  7880. * @param {Element | jQueryObject | Event | integer | string} [el]
  7881. * @returns {Fancytree} matching tree or null
  7882. * @example
  7883. * $.ui.fancytree.getTree(); // Get first Fancytree instance on page
  7884. * $.ui.fancytree.getTree(1); // Get second Fancytree instance on page
  7885. * $.ui.fancytree.getTree(event); // Get tree for this mouse- or keyboard event
  7886. * $.ui.fancytree.getTree("foo"); // Get tree for this `opts.treeId`
  7887. * $.ui.fancytree.getTree("#tree"); // Get tree for this matching element
  7888. *
  7889. * @since 2.13
  7890. */
  7891. getTree: function(el) {
  7892. var widget,
  7893. orgEl = el;
  7894. if (el instanceof Fancytree) {
  7895. return el; // el already was a Fancytree
  7896. }
  7897. if (el === undefined) {
  7898. el = 0; // get first tree
  7899. }
  7900. if (typeof el === "number") {
  7901. el = $(".fancytree-container").eq(el); // el was an integer: return nth instance
  7902. } else if (typeof el === "string") {
  7903. // `el` may be a treeId or a selector:
  7904. el = $("#ft-id-" + orgEl).eq(0);
  7905. if (!el.length) {
  7906. el = $(orgEl).eq(0); // el was a selector: use first match
  7907. }
  7908. } else if (
  7909. el instanceof Element ||
  7910. el instanceof HTMLDocument
  7911. ) {
  7912. el = $(el);
  7913. } else if (el instanceof $) {
  7914. el = el.eq(0); // el was a jQuery object: use the first
  7915. } else if (el.originalEvent !== undefined) {
  7916. el = $(el.target); // el was an Event
  7917. }
  7918. // el is a jQuery object wit one element here
  7919. el = el.closest(":ui-fancytree");
  7920. widget = el.data("ui-fancytree") || el.data("fancytree"); // the latter is required by jQuery <= 1.8
  7921. return widget ? widget.tree : null;
  7922. },
  7923. /** Return an option value that has a default, but may be overridden by a
  7924. * callback or a node instance attribute.
  7925. *
  7926. * Evaluation sequence:
  7927. *
  7928. * If `tree.options.<optionName>` is a callback that returns something, use that.
  7929. * Else if `node.<optionName>` is defined, use that.
  7930. * Else if `tree.options.<optionName>` is a value, use that.
  7931. * Else use `defaultValue`.
  7932. *
  7933. * @param {string} optionName name of the option property (on node and tree)
  7934. * @param {FancytreeNode} node passed to the callback
  7935. * @param {object} nodeObject where to look for the local option property, e.g. `node` or `node.data`
  7936. * @param {object} treeOption where to look for the tree option, e.g. `tree.options` or `tree.options.dnd5`
  7937. * @param {any} [defaultValue]
  7938. * @returns {any}
  7939. *
  7940. * @example
  7941. * // Check for node.foo, tree,options.foo(), and tree.options.foo:
  7942. * $.ui.fancytree.evalOption("foo", node, node, tree.options);
  7943. * // Check for node.data.bar, tree,options.qux.bar(), and tree.options.qux.bar:
  7944. * $.ui.fancytree.evalOption("bar", node, node.data, tree.options.qux);
  7945. *
  7946. * @since 2.22
  7947. */
  7948. evalOption: function(
  7949. optionName,
  7950. node,
  7951. nodeObject,
  7952. treeOptions,
  7953. defaultValue
  7954. ) {
  7955. var ctx,
  7956. res,
  7957. tree = node.tree,
  7958. treeOpt = treeOptions[optionName],
  7959. nodeOpt = nodeObject[optionName];
  7960. if ($.isFunction(treeOpt)) {
  7961. ctx = {
  7962. node: node,
  7963. tree: tree,
  7964. widget: tree.widget,
  7965. options: tree.widget.options,
  7966. typeInfo: tree.types[node.type] || {},
  7967. };
  7968. res = treeOpt.call(tree, { type: optionName }, ctx);
  7969. if (res == null) {
  7970. res = nodeOpt;
  7971. }
  7972. } else {
  7973. res = nodeOpt == null ? treeOpt : nodeOpt;
  7974. }
  7975. if (res == null) {
  7976. res = defaultValue; // no option set at all: return default
  7977. }
  7978. return res;
  7979. },
  7980. /** Set expander, checkbox, or node icon, supporting string and object format.
  7981. *
  7982. * @param {Element | jQueryObject} span
  7983. * @param {string} baseClass
  7984. * @param {string | object} icon
  7985. * @since 2.27
  7986. */
  7987. setSpanIcon: function(span, baseClass, icon) {
  7988. var $span = $(span);
  7989. if (typeof icon === "string") {
  7990. $span.attr("class", baseClass + " " + icon);
  7991. } else {
  7992. // support object syntax: { text: ligature, addClasse: classname }
  7993. if (icon.text) {
  7994. $span.text("" + icon.text);
  7995. } else if (icon.html) {
  7996. span.innerHTML = icon.html;
  7997. }
  7998. $span.attr(
  7999. "class",
  8000. baseClass + " " + (icon.addClass || "")
  8001. );
  8002. }
  8003. },
  8004. /** Convert a keydown or mouse event to a canonical string like 'ctrl+a',
  8005. * 'ctrl+shift+f2', 'shift+leftdblclick'.
  8006. *
  8007. * This is especially handy for switch-statements in event handlers.
  8008. *
  8009. * @param {event}
  8010. * @returns {string}
  8011. *
  8012. * @example
  8013. switch( $.ui.fancytree.eventToString(event) ) {
  8014. case "-":
  8015. tree.nodeSetExpanded(ctx, false);
  8016. break;
  8017. case "shift+return":
  8018. tree.nodeSetActive(ctx, true);
  8019. break;
  8020. case "down":
  8021. res = node.navigate(event.which, activate);
  8022. break;
  8023. default:
  8024. handled = false;
  8025. }
  8026. if( handled ){
  8027. event.preventDefault();
  8028. }
  8029. */
  8030. eventToString: function(event) {
  8031. // Poor-man's hotkeys. See here for a complete implementation:
  8032. // https://github.com/jeresig/jquery.hotkeys
  8033. var which = event.which,
  8034. et = event.type,
  8035. s = [];
  8036. if (event.altKey) {
  8037. s.push("alt");
  8038. }
  8039. if (event.ctrlKey) {
  8040. s.push("ctrl");
  8041. }
  8042. if (event.metaKey) {
  8043. s.push("meta");
  8044. }
  8045. if (event.shiftKey) {
  8046. s.push("shift");
  8047. }
  8048. if (et === "click" || et === "dblclick") {
  8049. s.push(MOUSE_BUTTONS[event.button] + et);
  8050. } else if (et === "wheel") {
  8051. s.push(et);
  8052. } else if (!IGNORE_KEYCODES[which]) {
  8053. s.push(
  8054. SPECIAL_KEYCODES[which] ||
  8055. String.fromCharCode(which).toLowerCase()
  8056. );
  8057. }
  8058. return s.join("+");
  8059. },
  8060. /** Write message to console if debugLevel >= 3
  8061. * @param {string} msg
  8062. */
  8063. info: function(msg) {
  8064. if ($.ui.fancytree.debugLevel >= 3) {
  8065. consoleApply("info", arguments);
  8066. }
  8067. },
  8068. /* @deprecated: use eventToString(event) instead.
  8069. */
  8070. keyEventToString: function(event) {
  8071. this.warn(
  8072. "keyEventToString() is deprecated: use eventToString()"
  8073. );
  8074. return this.eventToString(event);
  8075. },
  8076. /** Return a wrapped handler method, that provides `this._super`.
  8077. *
  8078. * @example
  8079. // Implement `opts.createNode` event to add the 'draggable' attribute
  8080. $.ui.fancytree.overrideMethod(ctx.options, "createNode", function(event, data) {
  8081. // Default processing if any
  8082. this._super.apply(this, arguments);
  8083. // Add 'draggable' attribute
  8084. data.node.span.draggable = true;
  8085. });
  8086. *
  8087. * @param {object} instance
  8088. * @param {string} methodName
  8089. * @param {function} handler
  8090. * @param {object} [context] optional context
  8091. */
  8092. overrideMethod: function(instance, methodName, handler, context) {
  8093. var prevSuper,
  8094. _super = instance[methodName] || $.noop;
  8095. instance[methodName] = function() {
  8096. var self = context || this;
  8097. try {
  8098. prevSuper = self._super;
  8099. self._super = _super;
  8100. return handler.apply(self, arguments);
  8101. } finally {
  8102. self._super = prevSuper;
  8103. }
  8104. };
  8105. },
  8106. /**
  8107. * Parse tree data from HTML <ul> markup
  8108. *
  8109. * @param {jQueryObject} $ul
  8110. * @returns {NodeData[]}
  8111. */
  8112. parseHtml: function($ul) {
  8113. var classes,
  8114. className,
  8115. extraClasses,
  8116. i,
  8117. iPos,
  8118. l,
  8119. tmp,
  8120. tmp2,
  8121. $children = $ul.find(">li"),
  8122. children = [];
  8123. $children.each(function() {
  8124. var allData,
  8125. lowerCaseAttr,
  8126. $li = $(this),
  8127. $liSpan = $li.find(">span", this).first(),
  8128. $liA = $liSpan.length ? null : $li.find(">a").first(),
  8129. d = { tooltip: null, data: {} };
  8130. if ($liSpan.length) {
  8131. d.title = $liSpan.html();
  8132. } else if ($liA && $liA.length) {
  8133. // If a <li><a> tag is specified, use it literally and extract href/target.
  8134. d.title = $liA.html();
  8135. d.data.href = $liA.attr("href");
  8136. d.data.target = $liA.attr("target");
  8137. d.tooltip = $liA.attr("title");
  8138. } else {
  8139. // If only a <li> tag is specified, use the trimmed string up to
  8140. // the next child <ul> tag.
  8141. d.title = $li.html();
  8142. iPos = d.title.search(/<ul/i);
  8143. if (iPos >= 0) {
  8144. d.title = d.title.substring(0, iPos);
  8145. }
  8146. }
  8147. d.title = $.trim(d.title);
  8148. // Make sure all fields exist
  8149. for (i = 0, l = CLASS_ATTRS.length; i < l; i++) {
  8150. d[CLASS_ATTRS[i]] = undefined;
  8151. }
  8152. // Initialize to `true`, if class is set and collect extraClasses
  8153. classes = this.className.split(" ");
  8154. extraClasses = [];
  8155. for (i = 0, l = classes.length; i < l; i++) {
  8156. className = classes[i];
  8157. if (CLASS_ATTR_MAP[className]) {
  8158. d[className] = true;
  8159. } else {
  8160. extraClasses.push(className);
  8161. }
  8162. }
  8163. d.extraClasses = extraClasses.join(" ");
  8164. // Parse node options from ID, title and class attributes
  8165. tmp = $li.attr("title");
  8166. if (tmp) {
  8167. d.tooltip = tmp; // overrides <a title='...'>
  8168. }
  8169. tmp = $li.attr("id");
  8170. if (tmp) {
  8171. d.key = tmp;
  8172. }
  8173. // Translate hideCheckbox -> checkbox:false
  8174. if ($li.attr("hideCheckbox")) {
  8175. d.checkbox = false;
  8176. }
  8177. // Add <li data-NAME='...'> as node.data.NAME
  8178. allData = _getElementDataAsDict($li);
  8179. if (allData && !$.isEmptyObject(allData)) {
  8180. // #507: convert data-hidecheckbox (lower case) to hideCheckbox
  8181. for (lowerCaseAttr in NODE_ATTR_LOWERCASE_MAP) {
  8182. if (allData.hasOwnProperty(lowerCaseAttr)) {
  8183. allData[
  8184. NODE_ATTR_LOWERCASE_MAP[lowerCaseAttr]
  8185. ] = allData[lowerCaseAttr];
  8186. delete allData[lowerCaseAttr];
  8187. }
  8188. }
  8189. // #56: Allow to set special node.attributes from data-...
  8190. for (i = 0, l = NODE_ATTRS.length; i < l; i++) {
  8191. tmp = NODE_ATTRS[i];
  8192. tmp2 = allData[tmp];
  8193. if (tmp2 != null) {
  8194. delete allData[tmp];
  8195. d[tmp] = tmp2;
  8196. }
  8197. }
  8198. // All other data-... goes to node.data...
  8199. $.extend(d.data, allData);
  8200. }
  8201. // Recursive reading of child nodes, if LI tag contains an UL tag
  8202. $ul = $li.find(">ul").first();
  8203. if ($ul.length) {
  8204. d.children = $.ui.fancytree.parseHtml($ul);
  8205. } else {
  8206. d.children = d.lazy ? undefined : null;
  8207. }
  8208. children.push(d);
  8209. // FT.debug("parse ", d, children);
  8210. });
  8211. return children;
  8212. },
  8213. /** Add Fancytree extension definition to the list of globally available extensions.
  8214. *
  8215. * @param {object} definition
  8216. */
  8217. registerExtension: function(definition) {
  8218. _assert(
  8219. definition.name != null,
  8220. "extensions must have a `name` property."
  8221. );
  8222. _assert(
  8223. definition.version != null,
  8224. "extensions must have a `version` property."
  8225. );
  8226. $.ui.fancytree._extensions[definition.name] = definition;
  8227. },
  8228. /** Inverse of escapeHtml().
  8229. *
  8230. * @param {string} s
  8231. * @returns {string}
  8232. */
  8233. unescapeHtml: function(s) {
  8234. var e = document.createElement("div");
  8235. e.innerHTML = s;
  8236. return e.childNodes.length === 0
  8237. ? ""
  8238. : e.childNodes[0].nodeValue;
  8239. },
  8240. /** Write warning message to console if debugLevel >= 2.
  8241. * @param {string} msg
  8242. */
  8243. warn: function(msg) {
  8244. if ($.ui.fancytree.debugLevel >= 2) {
  8245. consoleApply("warn", arguments);
  8246. }
  8247. },
  8248. }
  8249. );
  8250. // Value returned by `require('jquery.fancytree')`
  8251. return $.ui.fancytree;
  8252. }); // End of closure
  8253. /*! Extension 'jquery.fancytree.childcounter.js' */// Extending Fancytree
  8254. // ===================
  8255. //
  8256. // See also the [live demo](https://wwWendt.de/tech/fancytree/demo/sample-ext-childcounter.html) of this code.
  8257. //
  8258. // Every extension should have a comment header containing some information
  8259. // about the author, copyright and licensing. Also a pointer to the latest
  8260. // source code.
  8261. // Prefix with `/*!` so the comment is not removed by the minifier.
  8262. /*!
  8263. * jquery.fancytree.childcounter.js
  8264. *
  8265. * Add a child counter bubble to tree nodes.
  8266. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8267. *
  8268. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  8269. *
  8270. * Released under the MIT license
  8271. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8272. *
  8273. * @version 2.38.0
  8274. * @date 2021-02-09T20:03:49Z
  8275. */
  8276. // To keep the global namespace clean, we wrap everything in a closure.
  8277. // The UMD wrapper pattern defines the dependencies on jQuery and the
  8278. // Fancytree core module, and makes sure that we can use the `require()`
  8279. // syntax with package loaders.
  8280. (function(factory) {
  8281. if (typeof define === "function" && define.amd) {
  8282. // AMD. Register as an anonymous module.
  8283. define(["jquery", "./jquery.fancytree"], factory);
  8284. } else if (typeof module === "object" && module.exports) {
  8285. // Node/CommonJS
  8286. require("./jquery.fancytree");
  8287. module.exports = factory(require("jquery"));
  8288. } else {
  8289. // Browser globals
  8290. factory(jQuery);
  8291. }
  8292. })(function($) {
  8293. // Consider to use [strict mode](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)
  8294. "use strict";
  8295. // The [coding guidelines](http://contribute.jquery.org/style-guide/js/)
  8296. // require jshint /eslint compliance.
  8297. // But for this sample, we want to allow unused variables for demonstration purpose.
  8298. /*eslint-disable no-unused-vars */
  8299. // Adding methods
  8300. // --------------
  8301. // New member functions can be added to the `Fancytree` class.
  8302. // This function will be available for every tree instance:
  8303. //
  8304. // var tree = $.ui.fancytree.getTree("#tree");
  8305. // tree.countSelected(false);
  8306. $.ui.fancytree._FancytreeClass.prototype.countSelected = function(topOnly) {
  8307. var tree = this,
  8308. treeOptions = tree.options;
  8309. return tree.getSelectedNodes(topOnly).length;
  8310. };
  8311. // The `FancytreeNode` class can also be easily extended. This would be called
  8312. // like
  8313. // node.updateCounters();
  8314. //
  8315. // It is also good practice to add a docstring comment.
  8316. /**
  8317. * [ext-childcounter] Update counter badges for `node` and its parents.
  8318. * May be called in the `loadChildren` event, to update parents of lazy loaded
  8319. * nodes.
  8320. * @alias FancytreeNode#updateCounters
  8321. * @requires jquery.fancytree.childcounters.js
  8322. */
  8323. $.ui.fancytree._FancytreeNodeClass.prototype.updateCounters = function() {
  8324. var node = this,
  8325. $badge = $("span.fancytree-childcounter", node.span),
  8326. extOpts = node.tree.options.childcounter,
  8327. count = node.countChildren(extOpts.deep);
  8328. node.data.childCounter = count;
  8329. if (
  8330. (count || !extOpts.hideZeros) &&
  8331. (!node.isExpanded() || !extOpts.hideExpanded)
  8332. ) {
  8333. if (!$badge.length) {
  8334. $badge = $("<span class='fancytree-childcounter'/>").appendTo(
  8335. $(
  8336. "span.fancytree-icon,span.fancytree-custom-icon",
  8337. node.span
  8338. )
  8339. );
  8340. }
  8341. $badge.text(count);
  8342. } else {
  8343. $badge.remove();
  8344. }
  8345. if (extOpts.deep && !node.isTopLevel() && !node.isRootNode()) {
  8346. node.parent.updateCounters();
  8347. }
  8348. };
  8349. // Finally, we can extend the widget API and create functions that are called
  8350. // like so:
  8351. //
  8352. // $("#tree").fancytree("widgetMethod1", "abc");
  8353. $.ui.fancytree.prototype.widgetMethod1 = function(arg1) {
  8354. var tree = this.tree;
  8355. return arg1;
  8356. };
  8357. // Register a Fancytree extension
  8358. // ------------------------------
  8359. // A full blown extension, extension is available for all trees and can be
  8360. // enabled like so (see also the [live demo](https://wwWendt.de/tech/fancytree/demo/sample-ext-childcounter.html)):
  8361. //
  8362. // <script src="../src/jquery.fancytree.js"></script>
  8363. // <script src="../src/jquery.fancytree.childcounter.js"></script>
  8364. // ...
  8365. //
  8366. // $("#tree").fancytree({
  8367. // extensions: ["childcounter"],
  8368. // childcounter: {
  8369. // hideExpanded: true
  8370. // },
  8371. // ...
  8372. // });
  8373. //
  8374. /* 'childcounter' extension */
  8375. $.ui.fancytree.registerExtension({
  8376. // Every extension must be registered by a unique name.
  8377. name: "childcounter",
  8378. // Version information should be compliant with [semver](http://semver.org)
  8379. version: "2.38.0",
  8380. // Extension specific options and their defaults.
  8381. // This options will be available as `tree.options.childcounter.hideExpanded`
  8382. options: {
  8383. deep: true,
  8384. hideZeros: true,
  8385. hideExpanded: false,
  8386. },
  8387. // Attributes other than `options` (or functions) can be defined here, and
  8388. // will be added to the tree.ext.EXTNAME namespace, in this case `tree.ext.childcounter.foo`.
  8389. // They can also be accessed as `this._local.foo` from within the extension
  8390. // methods.
  8391. foo: 42,
  8392. // Local functions are prefixed with an underscore '_'.
  8393. // Callable as `this._local._appendCounter()`.
  8394. _appendCounter: function(bar) {
  8395. var tree = this;
  8396. },
  8397. // **Override virtual methods for this extension.**
  8398. //
  8399. // Fancytree implements a number of 'hook methods', prefixed by 'node...' or 'tree...'.
  8400. // with a `ctx` argument (see [EventData](https://wwWendt.de/tech/fancytree/doc/jsdoc/global.html#EventData)
  8401. // for details) and an extended calling context:<br>
  8402. // `this` : the Fancytree instance<br>
  8403. // `this._local`: the namespace that contains extension attributes and private methods (same as this.ext.EXTNAME)<br>
  8404. // `this._super`: the virtual function that was overridden (member of previous extension or Fancytree)
  8405. //
  8406. // See also the [complete list of available hook functions](https://wwWendt.de/tech/fancytree/doc/jsdoc/Fancytree_Hooks.html).
  8407. /* Init */
  8408. // `treeInit` is triggered when a tree is initalized. We can set up classes or
  8409. // bind event handlers here...
  8410. treeInit: function(ctx) {
  8411. var tree = this, // same as ctx.tree,
  8412. opts = ctx.options,
  8413. extOpts = ctx.options.childcounter;
  8414. // Optionally check for dependencies with other extensions
  8415. /* this._requireExtension("glyph", false, false); */
  8416. // Call the base implementation
  8417. this._superApply(arguments);
  8418. // Add a class to the tree container
  8419. this.$container.addClass("fancytree-ext-childcounter");
  8420. },
  8421. // Destroy this tree instance (we only call the default implementation, so
  8422. // this method could as well be omitted).
  8423. treeDestroy: function(ctx) {
  8424. this._superApply(arguments);
  8425. },
  8426. // Overload the `renderTitle` hook, to append a counter badge
  8427. nodeRenderTitle: function(ctx, title) {
  8428. var node = ctx.node,
  8429. extOpts = ctx.options.childcounter,
  8430. count =
  8431. node.data.childCounter == null
  8432. ? node.countChildren(extOpts.deep)
  8433. : +node.data.childCounter;
  8434. // Let the base implementation render the title
  8435. // We use `_super()` instead of `_superApply()` here, since it is a little bit
  8436. // more performant when called often
  8437. this._super(ctx, title);
  8438. // Append a counter badge
  8439. if (
  8440. (count || !extOpts.hideZeros) &&
  8441. (!node.isExpanded() || !extOpts.hideExpanded)
  8442. ) {
  8443. $(
  8444. "span.fancytree-icon,span.fancytree-custom-icon",
  8445. node.span
  8446. ).append(
  8447. $("<span class='fancytree-childcounter'/>").text(count)
  8448. );
  8449. }
  8450. },
  8451. // Overload the `setExpanded` hook, so the counters are updated
  8452. nodeSetExpanded: function(ctx, flag, callOpts) {
  8453. var tree = ctx.tree,
  8454. node = ctx.node;
  8455. // Let the base implementation expand/collapse the node, then redraw the title
  8456. // after the animation has finished
  8457. return this._superApply(arguments).always(function() {
  8458. tree.nodeRenderTitle(ctx);
  8459. });
  8460. },
  8461. // End of extension definition
  8462. });
  8463. // Value returned by `require('jquery.fancytree..')`
  8464. return $.ui.fancytree;
  8465. }); // End of closure
  8466. /*! Extension 'jquery.fancytree.clones.js' *//*!
  8467. *
  8468. * jquery.fancytree.clones.js
  8469. * Support faster lookup of nodes by key and shared ref-ids.
  8470. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8471. *
  8472. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  8473. *
  8474. * Released under the MIT license
  8475. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8476. *
  8477. * @version 2.38.0
  8478. * @date 2021-02-09T20:03:49Z
  8479. */
  8480. (function(factory) {
  8481. if (typeof define === "function" && define.amd) {
  8482. // AMD. Register as an anonymous module.
  8483. define(["jquery", "./jquery.fancytree"], factory);
  8484. } else if (typeof module === "object" && module.exports) {
  8485. // Node/CommonJS
  8486. require("./jquery.fancytree");
  8487. module.exports = factory(require("jquery"));
  8488. } else {
  8489. // Browser globals
  8490. factory(jQuery);
  8491. }
  8492. })(function($) {
  8493. "use strict";
  8494. /*******************************************************************************
  8495. * Private functions and variables
  8496. */
  8497. var _assert = $.ui.fancytree.assert;
  8498. /* Return first occurrence of member from array. */
  8499. function _removeArrayMember(arr, elem) {
  8500. // TODO: use Array.indexOf for IE >= 9
  8501. var i;
  8502. for (i = arr.length - 1; i >= 0; i--) {
  8503. if (arr[i] === elem) {
  8504. arr.splice(i, 1);
  8505. return true;
  8506. }
  8507. }
  8508. return false;
  8509. }
  8510. /**
  8511. * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)
  8512. *
  8513. * @author <a href="mailto:[email protected]">Gary Court</a>
  8514. * @see http://github.com/garycourt/murmurhash-js
  8515. * @author <a href="mailto:[email protected]">Austin Appleby</a>
  8516. * @see http://sites.google.com/site/murmurhash/
  8517. *
  8518. * @param {string} key ASCII only
  8519. * @param {boolean} [asString=false]
  8520. * @param {number} seed Positive integer only
  8521. * @return {number} 32-bit positive integer hash
  8522. */
  8523. function hashMurmur3(key, asString, seed) {
  8524. /*eslint-disable no-bitwise */
  8525. var h1b,
  8526. k1,
  8527. remainder = key.length & 3,
  8528. bytes = key.length - remainder,
  8529. h1 = seed,
  8530. c1 = 0xcc9e2d51,
  8531. c2 = 0x1b873593,
  8532. i = 0;
  8533. while (i < bytes) {
  8534. k1 =
  8535. (key.charCodeAt(i) & 0xff) |
  8536. ((key.charCodeAt(++i) & 0xff) << 8) |
  8537. ((key.charCodeAt(++i) & 0xff) << 16) |
  8538. ((key.charCodeAt(++i) & 0xff) << 24);
  8539. ++i;
  8540. k1 =
  8541. ((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
  8542. 0xffffffff;
  8543. k1 = (k1 << 15) | (k1 >>> 17);
  8544. k1 =
  8545. ((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
  8546. 0xffffffff;
  8547. h1 ^= k1;
  8548. h1 = (h1 << 13) | (h1 >>> 19);
  8549. h1b =
  8550. ((h1 & 0xffff) * 5 + ((((h1 >>> 16) * 5) & 0xffff) << 16)) &
  8551. 0xffffffff;
  8552. h1 =
  8553. (h1b & 0xffff) +
  8554. 0x6b64 +
  8555. ((((h1b >>> 16) + 0xe654) & 0xffff) << 16);
  8556. }
  8557. k1 = 0;
  8558. switch (remainder) {
  8559. case 3:
  8560. k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
  8561. // fall through
  8562. case 2:
  8563. k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
  8564. // fall through
  8565. case 1:
  8566. k1 ^= key.charCodeAt(i) & 0xff;
  8567. k1 =
  8568. ((k1 & 0xffff) * c1 +
  8569. ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
  8570. 0xffffffff;
  8571. k1 = (k1 << 15) | (k1 >>> 17);
  8572. k1 =
  8573. ((k1 & 0xffff) * c2 +
  8574. ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
  8575. 0xffffffff;
  8576. h1 ^= k1;
  8577. }
  8578. h1 ^= key.length;
  8579. h1 ^= h1 >>> 16;
  8580. h1 =
  8581. ((h1 & 0xffff) * 0x85ebca6b +
  8582. ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) &
  8583. 0xffffffff;
  8584. h1 ^= h1 >>> 13;
  8585. h1 =
  8586. ((h1 & 0xffff) * 0xc2b2ae35 +
  8587. ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16)) &
  8588. 0xffffffff;
  8589. h1 ^= h1 >>> 16;
  8590. if (asString) {
  8591. // Convert to 8 digit hex string
  8592. return ("0000000" + (h1 >>> 0).toString(16)).substr(-8);
  8593. }
  8594. return h1 >>> 0;
  8595. /*eslint-enable no-bitwise */
  8596. }
  8597. /*
  8598. * Return a unique key for node by calculating the hash of the parents refKey-list.
  8599. */
  8600. function calcUniqueKey(node) {
  8601. var key,
  8602. h1,
  8603. path = $.map(node.getParentList(false, true), function(e) {
  8604. return e.refKey || e.key;
  8605. });
  8606. path = path.join("/");
  8607. // 32-bit has a high probability of collisions, so we pump up to 64-bit
  8608. // https://security.stackexchange.com/q/209882/207588
  8609. h1 = hashMurmur3(path, true);
  8610. key = "id_" + h1 + hashMurmur3(h1 + path, true);
  8611. return key;
  8612. }
  8613. /**
  8614. * [ext-clones] Return a list of clone-nodes (i.e. same refKey) or null.
  8615. * @param {boolean} [includeSelf=false]
  8616. * @returns {FancytreeNode[] | null}
  8617. *
  8618. * @alias FancytreeNode#getCloneList
  8619. * @requires jquery.fancytree.clones.js
  8620. */
  8621. $.ui.fancytree._FancytreeNodeClass.prototype.getCloneList = function(
  8622. includeSelf
  8623. ) {
  8624. var key,
  8625. tree = this.tree,
  8626. refList = tree.refMap[this.refKey] || null,
  8627. keyMap = tree.keyMap;
  8628. if (refList) {
  8629. key = this.key;
  8630. // Convert key list to node list
  8631. if (includeSelf) {
  8632. refList = $.map(refList, function(val) {
  8633. return keyMap[val];
  8634. });
  8635. } else {
  8636. refList = $.map(refList, function(val) {
  8637. return val === key ? null : keyMap[val];
  8638. });
  8639. if (refList.length < 1) {
  8640. refList = null;
  8641. }
  8642. }
  8643. }
  8644. return refList;
  8645. };
  8646. /**
  8647. * [ext-clones] Return true if this node has at least another clone with same refKey.
  8648. * @returns {boolean}
  8649. *
  8650. * @alias FancytreeNode#isClone
  8651. * @requires jquery.fancytree.clones.js
  8652. */
  8653. $.ui.fancytree._FancytreeNodeClass.prototype.isClone = function() {
  8654. var refKey = this.refKey || null,
  8655. refList = (refKey && this.tree.refMap[refKey]) || null;
  8656. return !!(refList && refList.length > 1);
  8657. };
  8658. /**
  8659. * [ext-clones] Update key and/or refKey for an existing node.
  8660. * @param {string} key
  8661. * @param {string} refKey
  8662. * @returns {boolean}
  8663. *
  8664. * @alias FancytreeNode#reRegister
  8665. * @requires jquery.fancytree.clones.js
  8666. */
  8667. $.ui.fancytree._FancytreeNodeClass.prototype.reRegister = function(
  8668. key,
  8669. refKey
  8670. ) {
  8671. key = key == null ? null : "" + key;
  8672. refKey = refKey == null ? null : "" + refKey;
  8673. // this.debug("reRegister", key, refKey);
  8674. var tree = this.tree,
  8675. prevKey = this.key,
  8676. prevRefKey = this.refKey,
  8677. keyMap = tree.keyMap,
  8678. refMap = tree.refMap,
  8679. refList = refMap[prevRefKey] || null,
  8680. // curCloneKeys = refList ? node.getCloneList(true),
  8681. modified = false;
  8682. // Key has changed: update all references
  8683. if (key != null && key !== this.key) {
  8684. if (keyMap[key]) {
  8685. $.error(
  8686. "[ext-clones] reRegister(" +
  8687. key +
  8688. "): already exists: " +
  8689. this
  8690. );
  8691. }
  8692. // Update keyMap
  8693. delete keyMap[prevKey];
  8694. keyMap[key] = this;
  8695. // Update refMap
  8696. if (refList) {
  8697. refMap[prevRefKey] = $.map(refList, function(e) {
  8698. return e === prevKey ? key : e;
  8699. });
  8700. }
  8701. this.key = key;
  8702. modified = true;
  8703. }
  8704. // refKey has changed
  8705. if (refKey != null && refKey !== this.refKey) {
  8706. // Remove previous refKeys
  8707. if (refList) {
  8708. if (refList.length === 1) {
  8709. delete refMap[prevRefKey];
  8710. } else {
  8711. refMap[prevRefKey] = $.map(refList, function(e) {
  8712. return e === prevKey ? null : e;
  8713. });
  8714. }
  8715. }
  8716. // Add refKey
  8717. if (refMap[refKey]) {
  8718. refMap[refKey].append(key);
  8719. } else {
  8720. refMap[refKey] = [this.key];
  8721. }
  8722. this.refKey = refKey;
  8723. modified = true;
  8724. }
  8725. return modified;
  8726. };
  8727. /**
  8728. * [ext-clones] Define a refKey for an existing node.
  8729. * @param {string} refKey
  8730. * @returns {boolean}
  8731. *
  8732. * @alias FancytreeNode#setRefKey
  8733. * @requires jquery.fancytree.clones.js
  8734. * @since 2.16
  8735. */
  8736. $.ui.fancytree._FancytreeNodeClass.prototype.setRefKey = function(refKey) {
  8737. return this.reRegister(null, refKey);
  8738. };
  8739. /**
  8740. * [ext-clones] Return all nodes with a given refKey (null if not found).
  8741. * @param {string} refKey
  8742. * @param {FancytreeNode} [rootNode] optionally restrict results to descendants of this node
  8743. * @returns {FancytreeNode[] | null}
  8744. * @alias Fancytree#getNodesByRef
  8745. * @requires jquery.fancytree.clones.js
  8746. */
  8747. $.ui.fancytree._FancytreeClass.prototype.getNodesByRef = function(
  8748. refKey,
  8749. rootNode
  8750. ) {
  8751. var keyMap = this.keyMap,
  8752. refList = this.refMap[refKey] || null;
  8753. if (refList) {
  8754. // Convert key list to node list
  8755. if (rootNode) {
  8756. refList = $.map(refList, function(val) {
  8757. var node = keyMap[val];
  8758. return node.isDescendantOf(rootNode) ? node : null;
  8759. });
  8760. } else {
  8761. refList = $.map(refList, function(val) {
  8762. return keyMap[val];
  8763. });
  8764. }
  8765. if (refList.length < 1) {
  8766. refList = null;
  8767. }
  8768. }
  8769. return refList;
  8770. };
  8771. /**
  8772. * [ext-clones] Replace a refKey with a new one.
  8773. * @param {string} oldRefKey
  8774. * @param {string} newRefKey
  8775. * @alias Fancytree#changeRefKey
  8776. * @requires jquery.fancytree.clones.js
  8777. */
  8778. $.ui.fancytree._FancytreeClass.prototype.changeRefKey = function(
  8779. oldRefKey,
  8780. newRefKey
  8781. ) {
  8782. var i,
  8783. node,
  8784. keyMap = this.keyMap,
  8785. refList = this.refMap[oldRefKey] || null;
  8786. if (refList) {
  8787. for (i = 0; i < refList.length; i++) {
  8788. node = keyMap[refList[i]];
  8789. node.refKey = newRefKey;
  8790. }
  8791. delete this.refMap[oldRefKey];
  8792. this.refMap[newRefKey] = refList;
  8793. }
  8794. };
  8795. /*******************************************************************************
  8796. * Extension code
  8797. */
  8798. $.ui.fancytree.registerExtension({
  8799. name: "clones",
  8800. version: "2.38.0",
  8801. // Default options for this extension.
  8802. options: {
  8803. highlightActiveClones: true, // set 'fancytree-active-clone' on active clones and all peers
  8804. highlightClones: false, // set 'fancytree-clone' class on any node that has at least one clone
  8805. },
  8806. treeCreate: function(ctx) {
  8807. this._superApply(arguments);
  8808. ctx.tree.refMap = {};
  8809. ctx.tree.keyMap = {};
  8810. },
  8811. treeInit: function(ctx) {
  8812. this.$container.addClass("fancytree-ext-clones");
  8813. _assert(ctx.options.defaultKey == null);
  8814. // Generate unique / reproducible default keys
  8815. ctx.options.defaultKey = function(node) {
  8816. return calcUniqueKey(node);
  8817. };
  8818. // The default implementation loads initial data
  8819. this._superApply(arguments);
  8820. },
  8821. treeClear: function(ctx) {
  8822. ctx.tree.refMap = {};
  8823. ctx.tree.keyMap = {};
  8824. return this._superApply(arguments);
  8825. },
  8826. treeRegisterNode: function(ctx, add, node) {
  8827. var refList,
  8828. len,
  8829. tree = ctx.tree,
  8830. keyMap = tree.keyMap,
  8831. refMap = tree.refMap,
  8832. key = node.key,
  8833. refKey = node && node.refKey != null ? "" + node.refKey : null;
  8834. // ctx.tree.debug("clones.treeRegisterNode", add, node);
  8835. if (node.isStatusNode()) {
  8836. return this._super(ctx, add, node);
  8837. }
  8838. if (add) {
  8839. if (keyMap[node.key] != null) {
  8840. var other = keyMap[node.key],
  8841. msg =
  8842. "clones.treeRegisterNode: duplicate key '" +
  8843. node.key +
  8844. "': /" +
  8845. node.getPath(true) +
  8846. " => " +
  8847. other.getPath(true);
  8848. // Sometimes this exception is not visible in the console,
  8849. // so we also write it:
  8850. tree.error(msg);
  8851. $.error(msg);
  8852. }
  8853. keyMap[key] = node;
  8854. if (refKey) {
  8855. refList = refMap[refKey];
  8856. if (refList) {
  8857. refList.push(key);
  8858. if (
  8859. refList.length === 2 &&
  8860. ctx.options.clones.highlightClones
  8861. ) {
  8862. // Mark peer node, if it just became a clone (no need to
  8863. // mark current node, since it will be rendered later anyway)
  8864. keyMap[refList[0]].renderStatus();
  8865. }
  8866. } else {
  8867. refMap[refKey] = [key];
  8868. }
  8869. // node.debug("clones.treeRegisterNode: add clone =>", refMap[refKey]);
  8870. }
  8871. } else {
  8872. if (keyMap[key] == null) {
  8873. $.error(
  8874. "clones.treeRegisterNode: node.key not registered: " +
  8875. node.key
  8876. );
  8877. }
  8878. delete keyMap[key];
  8879. if (refKey) {
  8880. refList = refMap[refKey];
  8881. // node.debug("clones.treeRegisterNode: remove clone BEFORE =>", refMap[refKey]);
  8882. if (refList) {
  8883. len = refList.length;
  8884. if (len <= 1) {
  8885. _assert(len === 1);
  8886. _assert(refList[0] === key);
  8887. delete refMap[refKey];
  8888. } else {
  8889. _removeArrayMember(refList, key);
  8890. // Unmark peer node, if this was the only clone
  8891. if (
  8892. len === 2 &&
  8893. ctx.options.clones.highlightClones
  8894. ) {
  8895. // node.debug("clones.treeRegisterNode: last =>", node.getCloneList());
  8896. keyMap[refList[0]].renderStatus();
  8897. }
  8898. }
  8899. // node.debug("clones.treeRegisterNode: remove clone =>", refMap[refKey]);
  8900. }
  8901. }
  8902. }
  8903. return this._super(ctx, add, node);
  8904. },
  8905. nodeRenderStatus: function(ctx) {
  8906. var $span,
  8907. res,
  8908. node = ctx.node;
  8909. res = this._super(ctx);
  8910. if (ctx.options.clones.highlightClones) {
  8911. $span = $(node[ctx.tree.statusClassPropName]);
  8912. // Only if span already exists
  8913. if ($span.length && node.isClone()) {
  8914. // node.debug("clones.nodeRenderStatus: ", ctx.options.clones.highlightClones);
  8915. $span.addClass("fancytree-clone");
  8916. }
  8917. }
  8918. return res;
  8919. },
  8920. nodeSetActive: function(ctx, flag, callOpts) {
  8921. var res,
  8922. scpn = ctx.tree.statusClassPropName,
  8923. node = ctx.node;
  8924. res = this._superApply(arguments);
  8925. if (ctx.options.clones.highlightActiveClones && node.isClone()) {
  8926. $.each(node.getCloneList(true), function(idx, n) {
  8927. // n.debug("clones.nodeSetActive: ", flag !== false);
  8928. $(n[scpn]).toggleClass(
  8929. "fancytree-active-clone",
  8930. flag !== false
  8931. );
  8932. });
  8933. }
  8934. return res;
  8935. },
  8936. });
  8937. // Value returned by `require('jquery.fancytree..')`
  8938. return $.ui.fancytree;
  8939. }); // End of closure
  8940. /*! Extension 'jquery.fancytree.dnd5.js' *//*!
  8941. * jquery.fancytree.dnd5.js
  8942. *
  8943. * Drag-and-drop support (native HTML5).
  8944. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8945. *
  8946. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  8947. *
  8948. * Released under the MIT license
  8949. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8950. *
  8951. * @version 2.38.0
  8952. * @date 2021-02-09T20:03:49Z
  8953. */
  8954. /*
  8955. #TODO
  8956. Compatiblity when dragging between *separate* windows:
  8957. Drag from Chrome Edge FF IE11 Safari
  8958. To Chrome ok ok ok NO ?
  8959. Edge ok ok ok NO ?
  8960. FF ok ok ok NO ?
  8961. IE 11 ok ok ok ok ?
  8962. Safari ? ? ? ? ok
  8963. */
  8964. (function(factory) {
  8965. if (typeof define === "function" && define.amd) {
  8966. // AMD. Register as an anonymous module.
  8967. define(["jquery", "./jquery.fancytree"], factory);
  8968. } else if (typeof module === "object" && module.exports) {
  8969. // Node/CommonJS
  8970. require("./jquery.fancytree");
  8971. module.exports = factory(require("jquery"));
  8972. } else {
  8973. // Browser globals
  8974. factory(jQuery);
  8975. }
  8976. })(function($) {
  8977. "use strict";
  8978. /******************************************************************************
  8979. * Private functions and variables
  8980. */
  8981. var FT = $.ui.fancytree,
  8982. isMac = /Mac/.test(navigator.platform),
  8983. classDragSource = "fancytree-drag-source",
  8984. classDragRemove = "fancytree-drag-remove",
  8985. classDropAccept = "fancytree-drop-accept",
  8986. classDropAfter = "fancytree-drop-after",
  8987. classDropBefore = "fancytree-drop-before",
  8988. classDropOver = "fancytree-drop-over",
  8989. classDropReject = "fancytree-drop-reject",
  8990. classDropTarget = "fancytree-drop-target",
  8991. nodeMimeType = "application/x-fancytree-node",
  8992. $dropMarker = null,
  8993. $dragImage,
  8994. $extraHelper,
  8995. SOURCE_NODE = null,
  8996. SOURCE_NODE_LIST = null,
  8997. $sourceList = null,
  8998. DRAG_ENTER_RESPONSE = null,
  8999. // SESSION_DATA = null, // plain object passed to events as `data`
  9000. SUGGESTED_DROP_EFFECT = null,
  9001. REQUESTED_DROP_EFFECT = null,
  9002. REQUESTED_EFFECT_ALLOWED = null,
  9003. LAST_HIT_MODE = null,
  9004. DRAG_OVER_STAMP = null; // Time when a node entered the 'over' hitmode
  9005. /* */
  9006. function _clearGlobals() {
  9007. DRAG_ENTER_RESPONSE = null;
  9008. DRAG_OVER_STAMP = null;
  9009. REQUESTED_DROP_EFFECT = null;
  9010. REQUESTED_EFFECT_ALLOWED = null;
  9011. SUGGESTED_DROP_EFFECT = null;
  9012. SOURCE_NODE = null;
  9013. SOURCE_NODE_LIST = null;
  9014. if ($sourceList) {
  9015. $sourceList.removeClass(classDragSource + " " + classDragRemove);
  9016. }
  9017. $sourceList = null;
  9018. if ($dropMarker) {
  9019. $dropMarker.hide();
  9020. }
  9021. // Take this badge off of me - I can't use it anymore:
  9022. if ($extraHelper) {
  9023. $extraHelper.remove();
  9024. $extraHelper = null;
  9025. }
  9026. }
  9027. /* Convert number to string and prepend +/-; return empty string for 0.*/
  9028. function offsetString(n) {
  9029. // eslint-disable-next-line no-nested-ternary
  9030. return n === 0 ? "" : n > 0 ? "+" + n : "" + n;
  9031. }
  9032. /* Convert a dragEnter() or dragOver() response to a canonical form.
  9033. * Return false or plain object
  9034. * @param {string|object|boolean} r
  9035. * @return {object|false}
  9036. */
  9037. function normalizeDragEnterResponse(r) {
  9038. var res;
  9039. if (!r) {
  9040. return false;
  9041. }
  9042. if ($.isPlainObject(r)) {
  9043. res = {
  9044. over: !!r.over,
  9045. before: !!r.before,
  9046. after: !!r.after,
  9047. };
  9048. } else if ($.isArray(r)) {
  9049. res = {
  9050. over: $.inArray("over", r) >= 0,
  9051. before: $.inArray("before", r) >= 0,
  9052. after: $.inArray("after", r) >= 0,
  9053. };
  9054. } else {
  9055. res = {
  9056. over: r === true || r === "over",
  9057. before: r === true || r === "before",
  9058. after: r === true || r === "after",
  9059. };
  9060. }
  9061. if (Object.keys(res).length === 0) {
  9062. return false;
  9063. }
  9064. // if( Object.keys(res).length === 1 ) {
  9065. // res.unique = res[0];
  9066. // }
  9067. return res;
  9068. }
  9069. /* Convert a dataTransfer.effectAllowed to a canonical form.
  9070. * Return false or plain object
  9071. * @param {string|boolean} r
  9072. * @return {object|false}
  9073. */
  9074. // function normalizeEffectAllowed(r) {
  9075. // if (!r || r === "none") {
  9076. // return false;
  9077. // }
  9078. // var all = r === "all",
  9079. // res = {
  9080. // copy: all || /copy/i.test(r),
  9081. // link: all || /link/i.test(r),
  9082. // move: all || /move/i.test(r),
  9083. // };
  9084. // return res;
  9085. // }
  9086. /* Implement auto scrolling when drag cursor is in top/bottom area of scroll parent. */
  9087. function autoScroll(tree, event) {
  9088. var spOfs,
  9089. scrollTop,
  9090. delta,
  9091. dndOpts = tree.options.dnd5,
  9092. sp = tree.$scrollParent[0],
  9093. sensitivity = dndOpts.scrollSensitivity,
  9094. speed = dndOpts.scrollSpeed,
  9095. scrolled = 0;
  9096. if (sp !== document && sp.tagName !== "HTML") {
  9097. spOfs = tree.$scrollParent.offset();
  9098. scrollTop = sp.scrollTop;
  9099. if (spOfs.top + sp.offsetHeight - event.pageY < sensitivity) {
  9100. delta =
  9101. sp.scrollHeight -
  9102. tree.$scrollParent.innerHeight() -
  9103. scrollTop;
  9104. // console.log ("sp.offsetHeight: " + sp.offsetHeight
  9105. // + ", spOfs.top: " + spOfs.top
  9106. // + ", scrollTop: " + scrollTop
  9107. // + ", innerHeight: " + tree.$scrollParent.innerHeight()
  9108. // + ", scrollHeight: " + sp.scrollHeight
  9109. // + ", delta: " + delta
  9110. // );
  9111. if (delta > 0) {
  9112. sp.scrollTop = scrolled = scrollTop + speed;
  9113. }
  9114. } else if (scrollTop > 0 && event.pageY - spOfs.top < sensitivity) {
  9115. sp.scrollTop = scrolled = scrollTop - speed;
  9116. }
  9117. } else {
  9118. scrollTop = $(document).scrollTop();
  9119. if (scrollTop > 0 && event.pageY - scrollTop < sensitivity) {
  9120. scrolled = scrollTop - speed;
  9121. $(document).scrollTop(scrolled);
  9122. } else if (
  9123. $(window).height() - (event.pageY - scrollTop) <
  9124. sensitivity
  9125. ) {
  9126. scrolled = scrollTop + speed;
  9127. $(document).scrollTop(scrolled);
  9128. }
  9129. }
  9130. if (scrolled) {
  9131. tree.debug("autoScroll: " + scrolled + "px");
  9132. }
  9133. return scrolled;
  9134. }
  9135. /* Guess dropEffect from modifier keys.
  9136. * Using rules suggested here:
  9137. * https://ux.stackexchange.com/a/83769
  9138. * @returns
  9139. * 'copy', 'link', 'move', or 'none'
  9140. */
  9141. function evalEffectModifiers(tree, event, effectDefault) {
  9142. var res = effectDefault;
  9143. if (isMac) {
  9144. if (event.metaKey && event.altKey) {
  9145. // Mac: [Control] + [Option]
  9146. res = "link";
  9147. } else if (event.ctrlKey) {
  9148. // Chrome on Mac: [Control]
  9149. res = "link";
  9150. } else if (event.metaKey) {
  9151. // Mac: [Command]
  9152. res = "move";
  9153. } else if (event.altKey) {
  9154. // Mac: [Option]
  9155. res = "copy";
  9156. }
  9157. } else {
  9158. if (event.ctrlKey) {
  9159. // Windows: [Ctrl]
  9160. res = "copy";
  9161. } else if (event.shiftKey) {
  9162. // Windows: [Shift]
  9163. res = "move";
  9164. } else if (event.altKey) {
  9165. // Windows: [Alt]
  9166. res = "link";
  9167. }
  9168. }
  9169. if (res !== SUGGESTED_DROP_EFFECT) {
  9170. tree.info(
  9171. "evalEffectModifiers: " +
  9172. event.type +
  9173. " - evalEffectModifiers(): " +
  9174. SUGGESTED_DROP_EFFECT +
  9175. " -> " +
  9176. res
  9177. );
  9178. }
  9179. SUGGESTED_DROP_EFFECT = res;
  9180. // tree.debug("evalEffectModifiers: " + res);
  9181. return res;
  9182. }
  9183. /*
  9184. * Check if the previous callback (dragEnter, dragOver, ...) has changed
  9185. * the `data` object and apply those settings.
  9186. *
  9187. * Safari:
  9188. * It seems that `dataTransfer.dropEffect` can only be set on dragStart, and will remain
  9189. * even if the cursor changes when [Alt] or [Ctrl] are pressed (?)
  9190. * Using rules suggested here:
  9191. * https://ux.stackexchange.com/a/83769
  9192. * @returns
  9193. * 'copy', 'link', 'move', or 'none'
  9194. */
  9195. function prepareDropEffectCallback(event, data) {
  9196. var tree = data.tree,
  9197. dataTransfer = data.dataTransfer;
  9198. if (event.type === "dragstart") {
  9199. data.effectAllowed = tree.options.dnd5.effectAllowed;
  9200. data.dropEffect = tree.options.dnd5.dropEffectDefault;
  9201. } else {
  9202. data.effectAllowed = REQUESTED_EFFECT_ALLOWED;
  9203. data.dropEffect = REQUESTED_DROP_EFFECT;
  9204. }
  9205. data.dropEffectSuggested = evalEffectModifiers(
  9206. tree,
  9207. event,
  9208. tree.options.dnd5.dropEffectDefault
  9209. );
  9210. data.isMove = data.dropEffect === "move";
  9211. data.files = dataTransfer.files || [];
  9212. // if (REQUESTED_EFFECT_ALLOWED !== dataTransfer.effectAllowed) {
  9213. // tree.warn(
  9214. // "prepareDropEffectCallback(" +
  9215. // event.type +
  9216. // "): dataTransfer.effectAllowed changed from " +
  9217. // REQUESTED_EFFECT_ALLOWED +
  9218. // " -> " +
  9219. // dataTransfer.effectAllowed
  9220. // );
  9221. // }
  9222. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9223. // tree.warn(
  9224. // "prepareDropEffectCallback(" +
  9225. // event.type +
  9226. // "): dataTransfer.dropEffect changed from requested " +
  9227. // REQUESTED_DROP_EFFECT +
  9228. // " to " +
  9229. // dataTransfer.dropEffect
  9230. // );
  9231. // }
  9232. }
  9233. function applyDropEffectCallback(event, data, allowDrop) {
  9234. var tree = data.tree,
  9235. dataTransfer = data.dataTransfer;
  9236. if (
  9237. event.type !== "dragstart" &&
  9238. REQUESTED_EFFECT_ALLOWED !== data.effectAllowed
  9239. ) {
  9240. tree.warn(
  9241. "effectAllowed should only be changed in dragstart event: " +
  9242. event.type +
  9243. ": data.effectAllowed changed from " +
  9244. REQUESTED_EFFECT_ALLOWED +
  9245. " -> " +
  9246. data.effectAllowed
  9247. );
  9248. }
  9249. if (allowDrop === false) {
  9250. tree.info("applyDropEffectCallback: allowDrop === false");
  9251. data.effectAllowed = "none";
  9252. data.dropEffect = "none";
  9253. }
  9254. // if (REQUESTED_DROP_EFFECT !== data.dropEffect) {
  9255. // tree.debug(
  9256. // "applyDropEffectCallback(" +
  9257. // event.type +
  9258. // "): data.dropEffect changed from previous " +
  9259. // REQUESTED_DROP_EFFECT +
  9260. // " to " +
  9261. // data.dropEffect
  9262. // );
  9263. // }
  9264. data.isMove = data.dropEffect === "move";
  9265. // data.isMove = data.dropEffectSuggested === "move";
  9266. // `effectAllowed` must only be defined in dragstart event, so we
  9267. // store it in a global variable for reference
  9268. if (event.type === "dragstart") {
  9269. REQUESTED_EFFECT_ALLOWED = data.effectAllowed;
  9270. REQUESTED_DROP_EFFECT = data.dropEffect;
  9271. }
  9272. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9273. // data.tree.info(
  9274. // "applyDropEffectCallback(" +
  9275. // event.type +
  9276. // "): dataTransfer.dropEffect changed from " +
  9277. // REQUESTED_DROP_EFFECT +
  9278. // " -> " +
  9279. // dataTransfer.dropEffect
  9280. // );
  9281. // }
  9282. dataTransfer.effectAllowed = REQUESTED_EFFECT_ALLOWED;
  9283. dataTransfer.dropEffect = REQUESTED_DROP_EFFECT;
  9284. // tree.debug(
  9285. // "applyDropEffectCallback(" +
  9286. // event.type +
  9287. // "): set " +
  9288. // dataTransfer.dropEffect +
  9289. // "/" +
  9290. // dataTransfer.effectAllowed
  9291. // );
  9292. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9293. // data.tree.warn(
  9294. // "applyDropEffectCallback(" +
  9295. // event.type +
  9296. // "): could not set dataTransfer.dropEffect to " +
  9297. // REQUESTED_DROP_EFFECT +
  9298. // ": got " +
  9299. // dataTransfer.dropEffect
  9300. // );
  9301. // }
  9302. return REQUESTED_DROP_EFFECT;
  9303. }
  9304. /* Handle dragover event (fired every x ms) on valid drop targets.
  9305. *
  9306. * - Auto-scroll when cursor is in border regions
  9307. * - Apply restrictioan like 'preventVoidMoves'
  9308. * - Calculate hit mode
  9309. * - Calculate drop effect
  9310. * - Trigger dragOver() callback to let user modify hit mode and drop effect
  9311. * - Adjust the drop marker accordingly
  9312. *
  9313. * @returns hitMode
  9314. */
  9315. function handleDragOver(event, data) {
  9316. // Implement auto-scrolling
  9317. if (data.options.dnd5.scroll) {
  9318. autoScroll(data.tree, event);
  9319. }
  9320. // Bail out with previous response if we get an invalid dragover
  9321. if (!data.node) {
  9322. data.tree.warn("Ignored dragover for non-node"); //, event, data);
  9323. return LAST_HIT_MODE;
  9324. }
  9325. var markerOffsetX,
  9326. nodeOfs,
  9327. pos,
  9328. relPosY,
  9329. hitMode = null,
  9330. tree = data.tree,
  9331. options = tree.options,
  9332. dndOpts = options.dnd5,
  9333. targetNode = data.node,
  9334. sourceNode = data.otherNode,
  9335. markerAt = "center",
  9336. $target = $(targetNode.span),
  9337. $targetTitle = $target.find("span.fancytree-title");
  9338. if (DRAG_ENTER_RESPONSE === false) {
  9339. tree.debug("Ignored dragover, since dragenter returned false.");
  9340. return false;
  9341. } else if (typeof DRAG_ENTER_RESPONSE === "string") {
  9342. $.error("assert failed: dragenter returned string");
  9343. }
  9344. // Calculate hitMode from relative cursor position.
  9345. nodeOfs = $target.offset();
  9346. relPosY = (event.pageY - nodeOfs.top) / $target.height();
  9347. if (event.pageY === undefined) {
  9348. tree.warn("event.pageY is undefined: see issue #1013.");
  9349. }
  9350. if (DRAG_ENTER_RESPONSE.after && relPosY > 0.75) {
  9351. hitMode = "after";
  9352. } else if (
  9353. !DRAG_ENTER_RESPONSE.over &&
  9354. DRAG_ENTER_RESPONSE.after &&
  9355. relPosY > 0.5
  9356. ) {
  9357. hitMode = "after";
  9358. } else if (DRAG_ENTER_RESPONSE.before && relPosY <= 0.25) {
  9359. hitMode = "before";
  9360. } else if (
  9361. !DRAG_ENTER_RESPONSE.over &&
  9362. DRAG_ENTER_RESPONSE.before &&
  9363. relPosY <= 0.5
  9364. ) {
  9365. hitMode = "before";
  9366. } else if (DRAG_ENTER_RESPONSE.over) {
  9367. hitMode = "over";
  9368. }
  9369. // Prevent no-ops like 'before source node'
  9370. // TODO: these are no-ops when moving nodes, but not in copy mode
  9371. if (dndOpts.preventVoidMoves && data.dropEffect === "move") {
  9372. if (targetNode === sourceNode) {
  9373. targetNode.debug("Drop over source node prevented.");
  9374. hitMode = null;
  9375. } else if (
  9376. hitMode === "before" &&
  9377. sourceNode &&
  9378. targetNode === sourceNode.getNextSibling()
  9379. ) {
  9380. targetNode.debug("Drop after source node prevented.");
  9381. hitMode = null;
  9382. } else if (
  9383. hitMode === "after" &&
  9384. sourceNode &&
  9385. targetNode === sourceNode.getPrevSibling()
  9386. ) {
  9387. targetNode.debug("Drop before source node prevented.");
  9388. hitMode = null;
  9389. } else if (
  9390. hitMode === "over" &&
  9391. sourceNode &&
  9392. sourceNode.parent === targetNode &&
  9393. sourceNode.isLastSibling()
  9394. ) {
  9395. targetNode.debug("Drop last child over own parent prevented.");
  9396. hitMode = null;
  9397. }
  9398. }
  9399. // Let callback modify the calculated hitMode
  9400. data.hitMode = hitMode;
  9401. if (hitMode && dndOpts.dragOver) {
  9402. prepareDropEffectCallback(event, data);
  9403. dndOpts.dragOver(targetNode, data);
  9404. var allowDrop = !!hitMode;
  9405. applyDropEffectCallback(event, data, allowDrop);
  9406. hitMode = data.hitMode;
  9407. }
  9408. LAST_HIT_MODE = hitMode;
  9409. //
  9410. if (hitMode === "after" || hitMode === "before" || hitMode === "over") {
  9411. markerOffsetX = dndOpts.dropMarkerOffsetX || 0;
  9412. switch (hitMode) {
  9413. case "before":
  9414. markerAt = "top";
  9415. markerOffsetX += dndOpts.dropMarkerInsertOffsetX || 0;
  9416. break;
  9417. case "after":
  9418. markerAt = "bottom";
  9419. markerOffsetX += dndOpts.dropMarkerInsertOffsetX || 0;
  9420. break;
  9421. }
  9422. pos = {
  9423. my: "left" + offsetString(markerOffsetX) + " center",
  9424. at: "left " + markerAt,
  9425. of: $targetTitle,
  9426. };
  9427. if (options.rtl) {
  9428. pos.my = "right" + offsetString(-markerOffsetX) + " center";
  9429. pos.at = "right " + markerAt;
  9430. // console.log("rtl", pos);
  9431. }
  9432. $dropMarker
  9433. .toggleClass(classDropAfter, hitMode === "after")
  9434. .toggleClass(classDropOver, hitMode === "over")
  9435. .toggleClass(classDropBefore, hitMode === "before")
  9436. .show()
  9437. .position(FT.fixPositionOptions(pos));
  9438. } else {
  9439. $dropMarker.hide();
  9440. // console.log("hide dropmarker")
  9441. }
  9442. $(targetNode.span)
  9443. .toggleClass(
  9444. classDropTarget,
  9445. hitMode === "after" ||
  9446. hitMode === "before" ||
  9447. hitMode === "over"
  9448. )
  9449. .toggleClass(classDropAfter, hitMode === "after")
  9450. .toggleClass(classDropBefore, hitMode === "before")
  9451. .toggleClass(classDropAccept, hitMode === "over")
  9452. .toggleClass(classDropReject, hitMode === false);
  9453. return hitMode;
  9454. }
  9455. /*
  9456. * Handle dragstart drag dragend events on the container
  9457. */
  9458. function onDragEvent(event) {
  9459. var json,
  9460. tree = this,
  9461. dndOpts = tree.options.dnd5,
  9462. node = FT.getNode(event),
  9463. dataTransfer =
  9464. event.dataTransfer || event.originalEvent.dataTransfer,
  9465. data = {
  9466. tree: tree,
  9467. node: node,
  9468. options: tree.options,
  9469. originalEvent: event.originalEvent,
  9470. widget: tree.widget,
  9471. dataTransfer: dataTransfer,
  9472. useDefaultImage: true,
  9473. dropEffect: undefined,
  9474. dropEffectSuggested: undefined,
  9475. effectAllowed: undefined, // set by dragstart
  9476. files: undefined, // only for drop events
  9477. isCancelled: undefined, // set by dragend
  9478. isMove: undefined,
  9479. };
  9480. switch (event.type) {
  9481. case "dragstart":
  9482. if (!node) {
  9483. tree.info("Ignored dragstart on a non-node.");
  9484. return false;
  9485. }
  9486. // Store current source node in different formats
  9487. SOURCE_NODE = node;
  9488. // Also optionally store selected nodes
  9489. if (dndOpts.multiSource === false) {
  9490. SOURCE_NODE_LIST = [node];
  9491. } else if (dndOpts.multiSource === true) {
  9492. if (node.isSelected()) {
  9493. SOURCE_NODE_LIST = tree.getSelectedNodes();
  9494. } else {
  9495. SOURCE_NODE_LIST = [node];
  9496. }
  9497. } else {
  9498. SOURCE_NODE_LIST = dndOpts.multiSource(node, data);
  9499. }
  9500. // Cache as array of jQuery objects for faster access:
  9501. $sourceList = $(
  9502. $.map(SOURCE_NODE_LIST, function(n) {
  9503. return n.span;
  9504. })
  9505. );
  9506. // Set visual feedback
  9507. $sourceList.addClass(classDragSource);
  9508. // Set payload
  9509. // Note:
  9510. // Transfer data is only accessible on dragstart and drop!
  9511. // For all other events the formats and kinds in the drag
  9512. // data store list of items representing dragged data can be
  9513. // enumerated, but the data itself is unavailable and no new
  9514. // data can be added.
  9515. var nodeData = node.toDict(true, dndOpts.sourceCopyHook);
  9516. nodeData.treeId = node.tree._id;
  9517. json = JSON.stringify(nodeData);
  9518. try {
  9519. dataTransfer.setData(nodeMimeType, json);
  9520. dataTransfer.setData("text/html", $(node.span).html());
  9521. dataTransfer.setData("text/plain", node.title);
  9522. } catch (ex) {
  9523. // IE only accepts 'text' type
  9524. tree.warn(
  9525. "Could not set data (IE only accepts 'text') - " + ex
  9526. );
  9527. }
  9528. // We always need to set the 'text' type if we want to drag
  9529. // Because IE 11 only accepts this single type.
  9530. // If we pass JSON here, IE can can access all node properties,
  9531. // even when the source lives in another window. (D'n'd inside
  9532. // the same window will always work.)
  9533. // The drawback is, that in this case ALL browsers will see
  9534. // the JSON representation as 'text', so dragging
  9535. // to a text field will insert the JSON string instead of
  9536. // the node title.
  9537. if (dndOpts.setTextTypeJson) {
  9538. dataTransfer.setData("text", json);
  9539. } else {
  9540. dataTransfer.setData("text", node.title);
  9541. }
  9542. // Set the allowed drag modes (combinations of move, copy, and link)
  9543. // (effectAllowed can only be set in the dragstart event.)
  9544. // This can be overridden in the dragStart() callback
  9545. prepareDropEffectCallback(event, data);
  9546. // Let user cancel or modify above settings
  9547. // Realize potential changes by previous callback
  9548. if (dndOpts.dragStart(node, data) === false) {
  9549. // Cancel dragging
  9550. // dataTransfer.dropEffect = "none";
  9551. _clearGlobals();
  9552. return false;
  9553. }
  9554. applyDropEffectCallback(event, data);
  9555. // Unless user set `data.useDefaultImage` to false in dragStart,
  9556. // generata a default drag image now:
  9557. $extraHelper = null;
  9558. if (data.useDefaultImage) {
  9559. // Set the title as drag image (otherwise it would contain the expander)
  9560. $dragImage = $(node.span).find(".fancytree-title");
  9561. if (SOURCE_NODE_LIST && SOURCE_NODE_LIST.length > 1) {
  9562. // Add a counter badge to node title if dragging more than one node.
  9563. // We want this, because the element that is used as drag image
  9564. // must be *visible* in the DOM, so we cannot create some hidden
  9565. // custom markup.
  9566. // See https://kryogenix.org/code/browser/custom-drag-image.html
  9567. // Also, since IE 11 and Edge don't support setDragImage() alltogether,
  9568. // it gives som feedback to the user.
  9569. // The badge will be removed later on drag end.
  9570. $extraHelper = $(
  9571. "<span class='fancytree-childcounter'/>"
  9572. )
  9573. .text("+" + (SOURCE_NODE_LIST.length - 1))
  9574. .appendTo($dragImage);
  9575. }
  9576. if (dataTransfer.setDragImage) {
  9577. // IE 11 and Edge do not support this
  9578. dataTransfer.setDragImage($dragImage[0], -10, -10);
  9579. }
  9580. }
  9581. return true;
  9582. case "drag":
  9583. // Called every few milliseconds (no matter if the
  9584. // cursor is over a valid drop target)
  9585. // data.tree.info("drag", SOURCE_NODE)
  9586. prepareDropEffectCallback(event, data);
  9587. dndOpts.dragDrag(node, data);
  9588. applyDropEffectCallback(event, data);
  9589. $sourceList.toggleClass(classDragRemove, data.isMove);
  9590. break;
  9591. case "dragend":
  9592. // Called at the end of a d'n'd process (after drop)
  9593. // Note caveat: If drop removed the dragged source element,
  9594. // we may not get this event, since the target does not exist
  9595. // anymore
  9596. prepareDropEffectCallback(event, data);
  9597. _clearGlobals();
  9598. data.isCancelled = !LAST_HIT_MODE;
  9599. dndOpts.dragEnd(node, data, !LAST_HIT_MODE);
  9600. // applyDropEffectCallback(event, data);
  9601. break;
  9602. }
  9603. }
  9604. /*
  9605. * Handle dragenter dragover dragleave drop events on the container
  9606. */
  9607. function onDropEvent(event) {
  9608. var json,
  9609. allowAutoExpand,
  9610. nodeData,
  9611. isSourceFtNode,
  9612. r,
  9613. res,
  9614. tree = this,
  9615. dndOpts = tree.options.dnd5,
  9616. allowDrop = null,
  9617. node = FT.getNode(event),
  9618. dataTransfer =
  9619. event.dataTransfer || event.originalEvent.dataTransfer,
  9620. data = {
  9621. tree: tree,
  9622. node: node,
  9623. options: tree.options,
  9624. originalEvent: event.originalEvent,
  9625. widget: tree.widget,
  9626. hitMode: DRAG_ENTER_RESPONSE,
  9627. dataTransfer: dataTransfer,
  9628. otherNode: SOURCE_NODE || null,
  9629. otherNodeList: SOURCE_NODE_LIST || null,
  9630. otherNodeData: null, // set by drop event
  9631. useDefaultImage: true,
  9632. dropEffect: undefined,
  9633. dropEffectSuggested: undefined,
  9634. effectAllowed: undefined, // set by dragstart
  9635. files: null, // list of File objects (may be [])
  9636. isCancelled: undefined, // set by drop event
  9637. isMove: undefined,
  9638. };
  9639. // data.isMove = dropEffect === "move";
  9640. switch (event.type) {
  9641. case "dragenter":
  9642. // The dragenter event is fired when a dragged element or
  9643. // text selection enters a valid drop target.
  9644. DRAG_OVER_STAMP = null;
  9645. if (!node) {
  9646. // Sometimes we get dragenter for the container element
  9647. tree.debug(
  9648. "Ignore non-node " +
  9649. event.type +
  9650. ": " +
  9651. event.target.tagName +
  9652. "." +
  9653. event.target.className
  9654. );
  9655. DRAG_ENTER_RESPONSE = false;
  9656. break;
  9657. }
  9658. $(node.span)
  9659. .addClass(classDropOver)
  9660. .removeClass(classDropAccept + " " + classDropReject);
  9661. // Data is only readable in the dragstart and drop event,
  9662. // but we can check for the type:
  9663. isSourceFtNode =
  9664. $.inArray(nodeMimeType, dataTransfer.types) >= 0;
  9665. if (dndOpts.preventNonNodes && !isSourceFtNode) {
  9666. node.debug("Reject dropping a non-node.");
  9667. DRAG_ENTER_RESPONSE = false;
  9668. break;
  9669. } else if (
  9670. dndOpts.preventForeignNodes &&
  9671. (!SOURCE_NODE || SOURCE_NODE.tree !== node.tree)
  9672. ) {
  9673. node.debug("Reject dropping a foreign node.");
  9674. DRAG_ENTER_RESPONSE = false;
  9675. break;
  9676. } else if (
  9677. dndOpts.preventSameParent &&
  9678. data.otherNode &&
  9679. data.otherNode.tree === node.tree &&
  9680. node.parent === data.otherNode.parent
  9681. ) {
  9682. node.debug("Reject dropping as sibling (same parent).");
  9683. DRAG_ENTER_RESPONSE = false;
  9684. break;
  9685. } else if (
  9686. dndOpts.preventRecursion &&
  9687. data.otherNode &&
  9688. data.otherNode.tree === node.tree &&
  9689. node.isDescendantOf(data.otherNode)
  9690. ) {
  9691. node.debug("Reject dropping below own ancestor.");
  9692. DRAG_ENTER_RESPONSE = false;
  9693. break;
  9694. } else if (dndOpts.preventLazyParents && !node.isLoaded()) {
  9695. node.warn("Drop over unloaded target node prevented.");
  9696. DRAG_ENTER_RESPONSE = false;
  9697. break;
  9698. }
  9699. $dropMarker.show();
  9700. // Call dragEnter() to figure out if (and where) dropping is allowed
  9701. prepareDropEffectCallback(event, data);
  9702. r = dndOpts.dragEnter(node, data);
  9703. res = normalizeDragEnterResponse(r);
  9704. // alert("res:" + JSON.stringify(res))
  9705. DRAG_ENTER_RESPONSE = res;
  9706. allowDrop = res && (res.over || res.before || res.after);
  9707. applyDropEffectCallback(event, data, allowDrop);
  9708. break;
  9709. case "dragover":
  9710. if (!node) {
  9711. tree.debug(
  9712. "Ignore non-node " +
  9713. event.type +
  9714. ": " +
  9715. event.target.tagName +
  9716. "." +
  9717. event.target.className
  9718. );
  9719. break;
  9720. }
  9721. // The dragover event is fired when an element or text
  9722. // selection is being dragged over a valid drop target
  9723. // (every few hundred milliseconds).
  9724. // tree.debug(
  9725. // event.type +
  9726. // ": dropEffect: " +
  9727. // dataTransfer.dropEffect
  9728. // );
  9729. prepareDropEffectCallback(event, data);
  9730. LAST_HIT_MODE = handleDragOver(event, data);
  9731. // The flag controls the preventDefault() below:
  9732. allowDrop = !!LAST_HIT_MODE;
  9733. allowAutoExpand =
  9734. LAST_HIT_MODE === "over" || LAST_HIT_MODE === false;
  9735. if (
  9736. allowAutoExpand &&
  9737. !node.expanded &&
  9738. node.hasChildren() !== false
  9739. ) {
  9740. if (!DRAG_OVER_STAMP) {
  9741. DRAG_OVER_STAMP = Date.now();
  9742. } else if (
  9743. dndOpts.autoExpandMS &&
  9744. Date.now() - DRAG_OVER_STAMP > dndOpts.autoExpandMS &&
  9745. !node.isLoading() &&
  9746. (!dndOpts.dragExpand ||
  9747. dndOpts.dragExpand(node, data) !== false)
  9748. ) {
  9749. node.setExpanded();
  9750. }
  9751. } else {
  9752. DRAG_OVER_STAMP = null;
  9753. }
  9754. break;
  9755. case "dragleave":
  9756. // NOTE: dragleave is fired AFTER the dragenter event of the
  9757. // FOLLOWING element.
  9758. if (!node) {
  9759. tree.debug(
  9760. "Ignore non-node " +
  9761. event.type +
  9762. ": " +
  9763. event.target.tagName +
  9764. "." +
  9765. event.target.className
  9766. );
  9767. break;
  9768. }
  9769. if (!$(node.span).hasClass(classDropOver)) {
  9770. node.debug("Ignore dragleave (multi).");
  9771. break;
  9772. }
  9773. $(node.span).removeClass(
  9774. classDropOver +
  9775. " " +
  9776. classDropAccept +
  9777. " " +
  9778. classDropReject
  9779. );
  9780. node.scheduleAction("cancel");
  9781. dndOpts.dragLeave(node, data);
  9782. $dropMarker.hide();
  9783. break;
  9784. case "drop":
  9785. // Data is only readable in the (dragstart and) drop event:
  9786. if ($.inArray(nodeMimeType, dataTransfer.types) >= 0) {
  9787. nodeData = dataTransfer.getData(nodeMimeType);
  9788. tree.info(
  9789. event.type +
  9790. ": getData('application/x-fancytree-node'): '" +
  9791. nodeData +
  9792. "'"
  9793. );
  9794. }
  9795. if (!nodeData) {
  9796. // 1. Source is not a Fancytree node, or
  9797. // 2. If the FT mime type was set, but returns '', this
  9798. // is probably IE 11 (which only supports 'text')
  9799. nodeData = dataTransfer.getData("text");
  9800. tree.info(
  9801. event.type + ": getData('text'): '" + nodeData + "'"
  9802. );
  9803. }
  9804. if (nodeData) {
  9805. try {
  9806. // 'text' type may contain JSON if IE is involved
  9807. // and setTextTypeJson option was set
  9808. json = JSON.parse(nodeData);
  9809. if (json.title !== undefined) {
  9810. data.otherNodeData = json;
  9811. }
  9812. } catch (ex) {
  9813. // assume 'text' type contains plain text, so `otherNodeData`
  9814. // should not be set
  9815. }
  9816. }
  9817. tree.debug(
  9818. event.type +
  9819. ": nodeData: '" +
  9820. nodeData +
  9821. "', otherNodeData: ",
  9822. data.otherNodeData
  9823. );
  9824. $(node.span).removeClass(
  9825. classDropOver +
  9826. " " +
  9827. classDropAccept +
  9828. " " +
  9829. classDropReject
  9830. );
  9831. // Let user implement the actual drop operation
  9832. data.hitMode = LAST_HIT_MODE;
  9833. prepareDropEffectCallback(event, data, !LAST_HIT_MODE);
  9834. data.isCancelled = !LAST_HIT_MODE;
  9835. var orgSourceElem = SOURCE_NODE && SOURCE_NODE.span,
  9836. orgSourceTree = SOURCE_NODE && SOURCE_NODE.tree;
  9837. dndOpts.dragDrop(node, data);
  9838. // applyDropEffectCallback(event, data);
  9839. // Prevent browser's default drop handling, i.e. open as link, ...
  9840. event.preventDefault();
  9841. if (orgSourceElem && !document.body.contains(orgSourceElem)) {
  9842. // The drop handler removed the original drag source from
  9843. // the DOM, so the dragend event will probaly not fire.
  9844. if (orgSourceTree === tree) {
  9845. tree.debug(
  9846. "Drop handler removed source element: generating dragEnd."
  9847. );
  9848. dndOpts.dragEnd(SOURCE_NODE, data);
  9849. } else {
  9850. tree.warn(
  9851. "Drop handler removed source element: dragend event may be lost."
  9852. );
  9853. }
  9854. }
  9855. _clearGlobals();
  9856. break;
  9857. }
  9858. // Dnd API madness: we must PREVENT default handling to enable dropping
  9859. if (allowDrop) {
  9860. event.preventDefault();
  9861. return false;
  9862. }
  9863. }
  9864. /** [ext-dnd5] Return a Fancytree instance, from element, index, event, or jQueryObject.
  9865. *
  9866. * @returns {FancytreeNode[]} List of nodes (empty if no drag operation)
  9867. * @example
  9868. * $.ui.fancytree.getDragNodeList();
  9869. *
  9870. * @alias Fancytree_Static#getDragNodeList
  9871. * @requires jquery.fancytree.dnd5.js
  9872. * @since 2.31
  9873. */
  9874. $.ui.fancytree.getDragNodeList = function() {
  9875. return SOURCE_NODE_LIST || [];
  9876. };
  9877. /** [ext-dnd5] Return the FancytreeNode that is currently being dragged.
  9878. *
  9879. * If multiple nodes are dragged, only the first is returned.
  9880. *
  9881. * @returns {FancytreeNode | null} dragged nodes or null if no drag operation
  9882. * @example
  9883. * $.ui.fancytree.getDragNode();
  9884. *
  9885. * @alias Fancytree_Static#getDragNode
  9886. * @requires jquery.fancytree.dnd5.js
  9887. * @since 2.31
  9888. */
  9889. $.ui.fancytree.getDragNode = function() {
  9890. return SOURCE_NODE;
  9891. };
  9892. /******************************************************************************
  9893. *
  9894. */
  9895. $.ui.fancytree.registerExtension({
  9896. name: "dnd5",
  9897. version: "2.38.0",
  9898. // Default options for this extension.
  9899. options: {
  9900. autoExpandMS: 1500, // Expand nodes after n milliseconds of hovering
  9901. dropMarkerInsertOffsetX: -16, // Additional offset for drop-marker with hitMode = "before"/"after"
  9902. dropMarkerOffsetX: -24, // Absolute position offset for .fancytree-drop-marker relatively to ..fancytree-title (icon/img near a node accepting drop)
  9903. // #1021 `document.body` is not available yet
  9904. dropMarkerParent: "body", // Root Container used for drop marker (could be a shadow root)
  9905. multiSource: false, // true: Drag multiple (i.e. selected) nodes. Also a callback() is allowed
  9906. effectAllowed: "all", // Restrict the possible cursor shapes and modifier operations (can also be set in the dragStart event)
  9907. // dropEffect: "auto", // 'copy'|'link'|'move'|'auto'(calculate from `effectAllowed`+modifier keys) or callback(node, data) that returns such string.
  9908. dropEffectDefault: "move", // Default dropEffect ('copy', 'link', or 'move') when no modifier is pressed (overide in dragDrag, dragOver).
  9909. preventForeignNodes: false, // Prevent dropping nodes from different Fancytrees
  9910. preventLazyParents: true, // Prevent dropping items on unloaded lazy Fancytree nodes
  9911. preventNonNodes: false, // Prevent dropping items other than Fancytree nodes
  9912. preventRecursion: true, // Prevent dropping nodes on own descendants
  9913. preventSameParent: false, // Prevent dropping nodes under same direct parent
  9914. preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
  9915. scroll: true, // Enable auto-scrolling while dragging
  9916. scrollSensitivity: 20, // Active top/bottom margin in pixel
  9917. scrollSpeed: 5, // Pixel per event
  9918. setTextTypeJson: false, // Allow dragging of nodes to different IE windows
  9919. sourceCopyHook: null, // Optional callback passed to `toDict` on dragStart @since 2.38
  9920. // Events (drag support)
  9921. dragStart: null, // Callback(sourceNode, data), return true, to enable dnd drag
  9922. dragDrag: $.noop, // Callback(sourceNode, data)
  9923. dragEnd: $.noop, // Callback(sourceNode, data)
  9924. // Events (drop support)
  9925. dragEnter: null, // Callback(targetNode, data), return true, to enable dnd drop
  9926. dragOver: $.noop, // Callback(targetNode, data)
  9927. dragExpand: $.noop, // Callback(targetNode, data), return false to prevent autoExpand
  9928. dragDrop: $.noop, // Callback(targetNode, data)
  9929. dragLeave: $.noop, // Callback(targetNode, data)
  9930. },
  9931. treeInit: function(ctx) {
  9932. var $temp,
  9933. tree = ctx.tree,
  9934. opts = ctx.options,
  9935. glyph = opts.glyph || null,
  9936. dndOpts = opts.dnd5;
  9937. if ($.inArray("dnd", opts.extensions) >= 0) {
  9938. $.error("Extensions 'dnd' and 'dnd5' are mutually exclusive.");
  9939. }
  9940. if (dndOpts.dragStop) {
  9941. $.error(
  9942. "dragStop is not used by ext-dnd5. Use dragEnd instead."
  9943. );
  9944. }
  9945. if (dndOpts.preventRecursiveMoves != null) {
  9946. $.error(
  9947. "preventRecursiveMoves was renamed to preventRecursion."
  9948. );
  9949. }
  9950. // Implement `opts.createNode` event to add the 'draggable' attribute
  9951. // #680: this must happen before calling super.treeInit()
  9952. if (dndOpts.dragStart) {
  9953. FT.overrideMethod(ctx.options, "createNode", function(
  9954. event,
  9955. data
  9956. ) {
  9957. // Default processing if any
  9958. this._super.apply(this, arguments);
  9959. if (data.node.span) {
  9960. data.node.span.draggable = true;
  9961. } else {
  9962. data.node.warn("Cannot add `draggable`: no span tag");
  9963. }
  9964. });
  9965. }
  9966. this._superApply(arguments);
  9967. this.$container.addClass("fancytree-ext-dnd5");
  9968. // Store the current scroll parent, which may be the tree
  9969. // container, any enclosing div, or the document.
  9970. // #761: scrollParent() always needs a container child
  9971. $temp = $("<span>").appendTo(this.$container);
  9972. this.$scrollParent = $temp.scrollParent();
  9973. $temp.remove();
  9974. $dropMarker = $("#fancytree-drop-marker");
  9975. if (!$dropMarker.length) {
  9976. $dropMarker = $("<div id='fancytree-drop-marker'></div>")
  9977. .hide()
  9978. .css({
  9979. "z-index": 1000,
  9980. // Drop marker should not steal dragenter/dragover events:
  9981. "pointer-events": "none",
  9982. })
  9983. .prependTo(dndOpts.dropMarkerParent);
  9984. if (glyph) {
  9985. FT.setSpanIcon(
  9986. $dropMarker[0],
  9987. glyph.map._addClass,
  9988. glyph.map.dropMarker
  9989. );
  9990. }
  9991. }
  9992. $dropMarker.toggleClass("fancytree-rtl", !!opts.rtl);
  9993. // Enable drag support if dragStart() is specified:
  9994. if (dndOpts.dragStart) {
  9995. // Bind drag event handlers
  9996. tree.$container.on(
  9997. "dragstart drag dragend",
  9998. onDragEvent.bind(tree)
  9999. );
  10000. }
  10001. // Enable drop support if dragEnter() is specified:
  10002. if (dndOpts.dragEnter) {
  10003. // Bind drop event handlers
  10004. tree.$container.on(
  10005. "dragenter dragover dragleave drop",
  10006. onDropEvent.bind(tree)
  10007. );
  10008. }
  10009. },
  10010. });
  10011. // Value returned by `require('jquery.fancytree..')`
  10012. return $.ui.fancytree;
  10013. }); // End of closure
  10014. /*! Extension 'jquery.fancytree.edit.js' *//*!
  10015. * jquery.fancytree.edit.js
  10016. *
  10017. * Make node titles editable.
  10018. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10019. *
  10020. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  10021. *
  10022. * Released under the MIT license
  10023. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10024. *
  10025. * @version 2.38.0
  10026. * @date 2021-02-09T20:03:49Z
  10027. */
  10028. (function(factory) {
  10029. if (typeof define === "function" && define.amd) {
  10030. // AMD. Register as an anonymous module.
  10031. define(["jquery", "./jquery.fancytree"], factory);
  10032. } else if (typeof module === "object" && module.exports) {
  10033. // Node/CommonJS
  10034. require("./jquery.fancytree");
  10035. module.exports = factory(require("jquery"));
  10036. } else {
  10037. // Browser globals
  10038. factory(jQuery);
  10039. }
  10040. })(function($) {
  10041. "use strict";
  10042. /*******************************************************************************
  10043. * Private functions and variables
  10044. */
  10045. var isMac = /Mac/.test(navigator.platform),
  10046. escapeHtml = $.ui.fancytree.escapeHtml,
  10047. unescapeHtml = $.ui.fancytree.unescapeHtml;
  10048. /**
  10049. * [ext-edit] Start inline editing of current node title.
  10050. *
  10051. * @alias FancytreeNode#editStart
  10052. * @requires Fancytree
  10053. */
  10054. $.ui.fancytree._FancytreeNodeClass.prototype.editStart = function() {
  10055. var $input,
  10056. node = this,
  10057. tree = this.tree,
  10058. local = tree.ext.edit,
  10059. instOpts = tree.options.edit,
  10060. $title = $(".fancytree-title", node.span),
  10061. eventData = {
  10062. node: node,
  10063. tree: tree,
  10064. options: tree.options,
  10065. isNew: $(node[tree.statusClassPropName]).hasClass(
  10066. "fancytree-edit-new"
  10067. ),
  10068. orgTitle: node.title,
  10069. input: null,
  10070. dirty: false,
  10071. };
  10072. // beforeEdit may want to modify the title before editing
  10073. if (
  10074. instOpts.beforeEdit.call(
  10075. node,
  10076. { type: "beforeEdit" },
  10077. eventData
  10078. ) === false
  10079. ) {
  10080. return false;
  10081. }
  10082. $.ui.fancytree.assert(!local.currentNode, "recursive edit");
  10083. local.currentNode = this;
  10084. local.eventData = eventData;
  10085. // Disable standard Fancytree mouse- and key handling
  10086. tree.widget._unbind();
  10087. local.lastDraggableAttrValue = node.span.draggable;
  10088. if (local.lastDraggableAttrValue) {
  10089. node.span.draggable = false;
  10090. }
  10091. // #116: ext-dnd prevents the blur event, so we have to catch outer clicks
  10092. $(document).on("mousedown.fancytree-edit", function(event) {
  10093. if (!$(event.target).hasClass("fancytree-edit-input")) {
  10094. node.editEnd(true, event);
  10095. }
  10096. });
  10097. // Replace node with <input>
  10098. $input = $("<input />", {
  10099. class: "fancytree-edit-input",
  10100. type: "text",
  10101. value: tree.options.escapeTitles
  10102. ? eventData.orgTitle
  10103. : unescapeHtml(eventData.orgTitle),
  10104. });
  10105. local.eventData.input = $input;
  10106. if (instOpts.adjustWidthOfs != null) {
  10107. $input.width($title.width() + instOpts.adjustWidthOfs);
  10108. }
  10109. if (instOpts.inputCss != null) {
  10110. $input.css(instOpts.inputCss);
  10111. }
  10112. $title.html($input);
  10113. // Focus <input> and bind keyboard handler
  10114. $input
  10115. .focus()
  10116. .change(function(event) {
  10117. $input.addClass("fancytree-edit-dirty");
  10118. })
  10119. .on("keydown", function(event) {
  10120. switch (event.which) {
  10121. case $.ui.keyCode.ESCAPE:
  10122. node.editEnd(false, event);
  10123. break;
  10124. case $.ui.keyCode.ENTER:
  10125. node.editEnd(true, event);
  10126. return false; // so we don't start editmode on Mac
  10127. }
  10128. event.stopPropagation();
  10129. })
  10130. .blur(function(event) {
  10131. return node.editEnd(true, event);
  10132. });
  10133. instOpts.edit.call(node, { type: "edit" }, eventData);
  10134. };
  10135. /**
  10136. * [ext-edit] Stop inline editing.
  10137. * @param {Boolean} [applyChanges=false] false: cancel edit, true: save (if modified)
  10138. * @alias FancytreeNode#editEnd
  10139. * @requires jquery.fancytree.edit.js
  10140. */
  10141. $.ui.fancytree._FancytreeNodeClass.prototype.editEnd = function(
  10142. applyChanges,
  10143. _event
  10144. ) {
  10145. var newVal,
  10146. node = this,
  10147. tree = this.tree,
  10148. local = tree.ext.edit,
  10149. eventData = local.eventData,
  10150. instOpts = tree.options.edit,
  10151. $title = $(".fancytree-title", node.span),
  10152. $input = $title.find("input.fancytree-edit-input");
  10153. if (instOpts.trim) {
  10154. $input.val($.trim($input.val()));
  10155. }
  10156. newVal = $input.val();
  10157. eventData.dirty = newVal !== node.title;
  10158. eventData.originalEvent = _event;
  10159. // Find out, if saving is required
  10160. if (applyChanges === false) {
  10161. // If true/false was passed, honor this (except in rename mode, if unchanged)
  10162. eventData.save = false;
  10163. } else if (eventData.isNew) {
  10164. // In create mode, we save everything, except for empty text
  10165. eventData.save = newVal !== "";
  10166. } else {
  10167. // In rename mode, we save everyting, except for empty or unchanged text
  10168. eventData.save = eventData.dirty && newVal !== "";
  10169. }
  10170. // Allow to break (keep editor open), modify input, or re-define data.save
  10171. if (
  10172. instOpts.beforeClose.call(
  10173. node,
  10174. { type: "beforeClose" },
  10175. eventData
  10176. ) === false
  10177. ) {
  10178. return false;
  10179. }
  10180. if (
  10181. eventData.save &&
  10182. instOpts.save.call(node, { type: "save" }, eventData) === false
  10183. ) {
  10184. return false;
  10185. }
  10186. $input.removeClass("fancytree-edit-dirty").off();
  10187. // Unbind outer-click handler
  10188. $(document).off(".fancytree-edit");
  10189. if (eventData.save) {
  10190. // # 171: escape user input (not required if global escaping is on)
  10191. node.setTitle(
  10192. tree.options.escapeTitles ? newVal : escapeHtml(newVal)
  10193. );
  10194. node.setFocus();
  10195. } else {
  10196. if (eventData.isNew) {
  10197. node.remove();
  10198. node = eventData.node = null;
  10199. local.relatedNode.setFocus();
  10200. } else {
  10201. node.renderTitle();
  10202. node.setFocus();
  10203. }
  10204. }
  10205. local.eventData = null;
  10206. local.currentNode = null;
  10207. local.relatedNode = null;
  10208. // Re-enable mouse and keyboard handling
  10209. tree.widget._bind();
  10210. if (node && local.lastDraggableAttrValue) {
  10211. node.span.draggable = true;
  10212. }
  10213. // Set keyboard focus, even if setFocus() claims 'nothing to do'
  10214. tree.$container.get(0).focus({ preventScroll: true });
  10215. eventData.input = null;
  10216. instOpts.close.call(node, { type: "close" }, eventData);
  10217. return true;
  10218. };
  10219. /**
  10220. * [ext-edit] Create a new child or sibling node and start edit mode.
  10221. *
  10222. * @param {String} [mode='child'] 'before', 'after', or 'child'
  10223. * @param {Object} [init] NodeData (or simple title string)
  10224. * @alias FancytreeNode#editCreateNode
  10225. * @requires jquery.fancytree.edit.js
  10226. * @since 2.4
  10227. */
  10228. $.ui.fancytree._FancytreeNodeClass.prototype.editCreateNode = function(
  10229. mode,
  10230. init
  10231. ) {
  10232. var newNode,
  10233. tree = this.tree,
  10234. self = this;
  10235. mode = mode || "child";
  10236. if (init == null) {
  10237. init = { title: "" };
  10238. } else if (typeof init === "string") {
  10239. init = { title: init };
  10240. } else {
  10241. $.ui.fancytree.assert($.isPlainObject(init));
  10242. }
  10243. // Make sure node is expanded (and loaded) in 'child' mode
  10244. if (
  10245. mode === "child" &&
  10246. !this.isExpanded() &&
  10247. this.hasChildren() !== false
  10248. ) {
  10249. this.setExpanded().done(function() {
  10250. self.editCreateNode(mode, init);
  10251. });
  10252. return;
  10253. }
  10254. newNode = this.addNode(init, mode);
  10255. // #644: Don't filter new nodes.
  10256. newNode.match = true;
  10257. $(newNode[tree.statusClassPropName])
  10258. .removeClass("fancytree-hide")
  10259. .addClass("fancytree-match");
  10260. newNode.makeVisible(/*{noAnimation: true}*/).done(function() {
  10261. $(newNode[tree.statusClassPropName]).addClass("fancytree-edit-new");
  10262. self.tree.ext.edit.relatedNode = self;
  10263. newNode.editStart();
  10264. });
  10265. };
  10266. /**
  10267. * [ext-edit] Check if any node in this tree in edit mode.
  10268. *
  10269. * @returns {FancytreeNode | null}
  10270. * @alias Fancytree#isEditing
  10271. * @requires jquery.fancytree.edit.js
  10272. */
  10273. $.ui.fancytree._FancytreeClass.prototype.isEditing = function() {
  10274. return this.ext.edit ? this.ext.edit.currentNode : null;
  10275. };
  10276. /**
  10277. * [ext-edit] Check if this node is in edit mode.
  10278. * @returns {Boolean} true if node is currently beeing edited
  10279. * @alias FancytreeNode#isEditing
  10280. * @requires jquery.fancytree.edit.js
  10281. */
  10282. $.ui.fancytree._FancytreeNodeClass.prototype.isEditing = function() {
  10283. return this.tree.ext.edit
  10284. ? this.tree.ext.edit.currentNode === this
  10285. : false;
  10286. };
  10287. /*******************************************************************************
  10288. * Extension code
  10289. */
  10290. $.ui.fancytree.registerExtension({
  10291. name: "edit",
  10292. version: "2.38.0",
  10293. // Default options for this extension.
  10294. options: {
  10295. adjustWidthOfs: 4, // null: don't adjust input size to content
  10296. allowEmpty: false, // Prevent empty input
  10297. inputCss: { minWidth: "3em" },
  10298. // triggerCancel: ["esc", "tab", "click"],
  10299. triggerStart: ["f2", "mac+enter", "shift+click"],
  10300. trim: true, // Trim whitespace before save
  10301. // Events:
  10302. beforeClose: $.noop, // Return false to prevent cancel/save (data.input is available)
  10303. beforeEdit: $.noop, // Return false to prevent edit mode
  10304. close: $.noop, // Editor was removed
  10305. edit: $.noop, // Editor was opened (available as data.input)
  10306. // keypress: $.noop, // Not yet implemented
  10307. save: $.noop, // Save data.input.val() or return false to keep editor open
  10308. },
  10309. // Local attributes
  10310. currentNode: null,
  10311. treeInit: function(ctx) {
  10312. var tree = ctx.tree;
  10313. this._superApply(arguments);
  10314. this.$container
  10315. .addClass("fancytree-ext-edit")
  10316. .on("fancytreebeforeupdateviewport", function(event, data) {
  10317. var editNode = tree.isEditing();
  10318. // When scrolling, the TR may be re-used by another node, so the
  10319. // active cell marker an
  10320. if (editNode) {
  10321. editNode.info("Cancel edit due to scroll event.");
  10322. editNode.editEnd(false, event);
  10323. }
  10324. });
  10325. },
  10326. nodeClick: function(ctx) {
  10327. var eventStr = $.ui.fancytree.eventToString(ctx.originalEvent),
  10328. triggerStart = ctx.options.edit.triggerStart;
  10329. if (
  10330. eventStr === "shift+click" &&
  10331. $.inArray("shift+click", triggerStart) >= 0
  10332. ) {
  10333. if (ctx.originalEvent.shiftKey) {
  10334. ctx.node.editStart();
  10335. return false;
  10336. }
  10337. }
  10338. if (
  10339. eventStr === "click" &&
  10340. $.inArray("clickActive", triggerStart) >= 0
  10341. ) {
  10342. // Only when click was inside title text (not aynwhere else in the row)
  10343. if (
  10344. ctx.node.isActive() &&
  10345. !ctx.node.isEditing() &&
  10346. $(ctx.originalEvent.target).hasClass("fancytree-title")
  10347. ) {
  10348. ctx.node.editStart();
  10349. return false;
  10350. }
  10351. }
  10352. return this._superApply(arguments);
  10353. },
  10354. nodeDblclick: function(ctx) {
  10355. if ($.inArray("dblclick", ctx.options.edit.triggerStart) >= 0) {
  10356. ctx.node.editStart();
  10357. return false;
  10358. }
  10359. return this._superApply(arguments);
  10360. },
  10361. nodeKeydown: function(ctx) {
  10362. switch (ctx.originalEvent.which) {
  10363. case 113: // [F2]
  10364. if ($.inArray("f2", ctx.options.edit.triggerStart) >= 0) {
  10365. ctx.node.editStart();
  10366. return false;
  10367. }
  10368. break;
  10369. case $.ui.keyCode.ENTER:
  10370. if (
  10371. $.inArray("mac+enter", ctx.options.edit.triggerStart) >=
  10372. 0 &&
  10373. isMac
  10374. ) {
  10375. ctx.node.editStart();
  10376. return false;
  10377. }
  10378. break;
  10379. }
  10380. return this._superApply(arguments);
  10381. },
  10382. });
  10383. // Value returned by `require('jquery.fancytree..')`
  10384. return $.ui.fancytree;
  10385. }); // End of closure
  10386. /*! Extension 'jquery.fancytree.filter.js' *//*!
  10387. * jquery.fancytree.filter.js
  10388. *
  10389. * Remove or highlight tree nodes, based on a filter.
  10390. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10391. *
  10392. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  10393. *
  10394. * Released under the MIT license
  10395. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10396. *
  10397. * @version 2.38.0
  10398. * @date 2021-02-09T20:03:49Z
  10399. */
  10400. (function(factory) {
  10401. if (typeof define === "function" && define.amd) {
  10402. // AMD. Register as an anonymous module.
  10403. define(["jquery", "./jquery.fancytree"], factory);
  10404. } else if (typeof module === "object" && module.exports) {
  10405. // Node/CommonJS
  10406. require("./jquery.fancytree");
  10407. module.exports = factory(require("jquery"));
  10408. } else {
  10409. // Browser globals
  10410. factory(jQuery);
  10411. }
  10412. })(function($) {
  10413. "use strict";
  10414. /*******************************************************************************
  10415. * Private functions and variables
  10416. */
  10417. var KeyNoData = "__not_found__",
  10418. escapeHtml = $.ui.fancytree.escapeHtml,
  10419. exoticStartChar = "\uFFF7",
  10420. exoticEndChar = "\uFFF8";
  10421. function _escapeRegex(str) {
  10422. return (str + "").replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
  10423. }
  10424. function extractHtmlText(s) {
  10425. if (s.indexOf(">") >= 0) {
  10426. return $("<div/>")
  10427. .html(s)
  10428. .text();
  10429. }
  10430. return s;
  10431. }
  10432. /**
  10433. * @description Marks the matching charecters of `text` either by `mark` or
  10434. * by exotic*Chars (if `escapeTitles` is `true`) based on `regexMatchArray`
  10435. * which is an array of matching groups.
  10436. * @param {string} text
  10437. * @param {RegExpMatchArray} regexMatchArray
  10438. */
  10439. function _markFuzzyMatchedChars(text, regexMatchArray, escapeTitles) {
  10440. // It is extremely infuriating that we can not use `let` or `const` or arrow functions.
  10441. // Damn you IE!!!
  10442. var matchingIndices = [];
  10443. // get the indices of matched characters (Iterate through `RegExpMatchArray`)
  10444. for (
  10445. var _matchingArrIdx = 1;
  10446. _matchingArrIdx < regexMatchArray.length;
  10447. _matchingArrIdx++
  10448. ) {
  10449. var _mIdx =
  10450. // get matching char index by cumulatively adding
  10451. // the matched group length
  10452. regexMatchArray[_matchingArrIdx].length +
  10453. (_matchingArrIdx === 1 ? 0 : 1) +
  10454. (matchingIndices[matchingIndices.length - 1] || 0);
  10455. matchingIndices.push(_mIdx);
  10456. }
  10457. // Map each `text` char to its position and store in `textPoses`.
  10458. var textPoses = text.split("");
  10459. if (escapeTitles) {
  10460. // If escaping the title, then wrap the matchng char within exotic chars
  10461. matchingIndices.forEach(function(v) {
  10462. textPoses[v] = exoticStartChar + textPoses[v] + exoticEndChar;
  10463. });
  10464. } else {
  10465. // Otherwise, Wrap the matching chars within `mark`.
  10466. matchingIndices.forEach(function(v) {
  10467. textPoses[v] = "<mark>" + textPoses[v] + "</mark>";
  10468. });
  10469. }
  10470. // Join back the modified `textPoses` to create final highlight markup.
  10471. return textPoses.join("");
  10472. }
  10473. $.ui.fancytree._FancytreeClass.prototype._applyFilterImpl = function(
  10474. filter,
  10475. branchMode,
  10476. _opts
  10477. ) {
  10478. var match,
  10479. statusNode,
  10480. re,
  10481. reHighlight,
  10482. reExoticStartChar,
  10483. reExoticEndChar,
  10484. temp,
  10485. prevEnableUpdate,
  10486. count = 0,
  10487. treeOpts = this.options,
  10488. escapeTitles = treeOpts.escapeTitles,
  10489. prevAutoCollapse = treeOpts.autoCollapse,
  10490. opts = $.extend({}, treeOpts.filter, _opts),
  10491. hideMode = opts.mode === "hide",
  10492. leavesOnly = !!opts.leavesOnly && !branchMode;
  10493. // Default to 'match title substring (not case sensitive)'
  10494. if (typeof filter === "string") {
  10495. if (filter === "") {
  10496. this.warn(
  10497. "Fancytree passing an empty string as a filter is handled as clearFilter()."
  10498. );
  10499. this.clearFilter();
  10500. return;
  10501. }
  10502. if (opts.fuzzy) {
  10503. // See https://codereview.stackexchange.com/questions/23899/faster-javascript-fuzzy-string-matching-function/23905#23905
  10504. // and http://www.quora.com/How-is-the-fuzzy-search-algorithm-in-Sublime-Text-designed
  10505. // and http://www.dustindiaz.com/autocomplete-fuzzy-matching
  10506. match = filter
  10507. .split("")
  10508. // Escaping the `filter` will not work because,
  10509. // it gets further split into individual characters. So,
  10510. // escape each character after splitting
  10511. .map(_escapeRegex)
  10512. .reduce(function(a, b) {
  10513. // create capture groups for parts that comes before
  10514. // the character
  10515. return a + "([^" + b + "]*)" + b;
  10516. }, "");
  10517. } else {
  10518. match = _escapeRegex(filter); // make sure a '.' is treated literally
  10519. }
  10520. re = new RegExp(match, "i");
  10521. reHighlight = new RegExp(_escapeRegex(filter), "gi");
  10522. if (escapeTitles) {
  10523. reExoticStartChar = new RegExp(
  10524. _escapeRegex(exoticStartChar),
  10525. "g"
  10526. );
  10527. reExoticEndChar = new RegExp(_escapeRegex(exoticEndChar), "g");
  10528. }
  10529. filter = function(node) {
  10530. if (!node.title) {
  10531. return false;
  10532. }
  10533. var text = escapeTitles
  10534. ? node.title
  10535. : extractHtmlText(node.title),
  10536. // `.match` instead of `.test` to get the capture groups
  10537. res = text.match(re);
  10538. if (res && opts.highlight) {
  10539. if (escapeTitles) {
  10540. if (opts.fuzzy) {
  10541. temp = _markFuzzyMatchedChars(
  10542. text,
  10543. res,
  10544. escapeTitles
  10545. );
  10546. } else {
  10547. // #740: we must not apply the marks to escaped entity names, e.g. `&quot;`
  10548. // Use some exotic characters to mark matches:
  10549. temp = text.replace(reHighlight, function(s) {
  10550. return exoticStartChar + s + exoticEndChar;
  10551. });
  10552. }
  10553. // now we can escape the title...
  10554. node.titleWithHighlight = escapeHtml(temp)
  10555. // ... and finally insert the desired `<mark>` tags
  10556. .replace(reExoticStartChar, "<mark>")
  10557. .replace(reExoticEndChar, "</mark>");
  10558. } else {
  10559. if (opts.fuzzy) {
  10560. node.titleWithHighlight = _markFuzzyMatchedChars(
  10561. text,
  10562. res
  10563. );
  10564. } else {
  10565. node.titleWithHighlight = text.replace(
  10566. reHighlight,
  10567. function(s) {
  10568. return "<mark>" + s + "</mark>";
  10569. }
  10570. );
  10571. }
  10572. }
  10573. // node.debug("filter", escapeTitles, text, node.titleWithHighlight);
  10574. }
  10575. return !!res;
  10576. };
  10577. }
  10578. this.enableFilter = true;
  10579. this.lastFilterArgs = arguments;
  10580. prevEnableUpdate = this.enableUpdate(false);
  10581. this.$div.addClass("fancytree-ext-filter");
  10582. if (hideMode) {
  10583. this.$div.addClass("fancytree-ext-filter-hide");
  10584. } else {
  10585. this.$div.addClass("fancytree-ext-filter-dimm");
  10586. }
  10587. this.$div.toggleClass(
  10588. "fancytree-ext-filter-hide-expanders",
  10589. !!opts.hideExpanders
  10590. );
  10591. // Reset current filter
  10592. this.rootNode.subMatchCount = 0;
  10593. this.visit(function(node) {
  10594. delete node.match;
  10595. delete node.titleWithHighlight;
  10596. node.subMatchCount = 0;
  10597. });
  10598. statusNode = this.getRootNode()._findDirectChild(KeyNoData);
  10599. if (statusNode) {
  10600. statusNode.remove();
  10601. }
  10602. // Adjust node.hide, .match, and .subMatchCount properties
  10603. treeOpts.autoCollapse = false; // #528
  10604. this.visit(function(node) {
  10605. if (leavesOnly && node.children != null) {
  10606. return;
  10607. }
  10608. var res = filter(node),
  10609. matchedByBranch = false;
  10610. if (res === "skip") {
  10611. node.visit(function(c) {
  10612. c.match = false;
  10613. }, true);
  10614. return "skip";
  10615. }
  10616. if (!res && (branchMode || res === "branch") && node.parent.match) {
  10617. res = true;
  10618. matchedByBranch = true;
  10619. }
  10620. if (res) {
  10621. count++;
  10622. node.match = true;
  10623. node.visitParents(function(p) {
  10624. if (p !== node) {
  10625. p.subMatchCount += 1;
  10626. }
  10627. // Expand match (unless this is no real match, but only a node in a matched branch)
  10628. if (opts.autoExpand && !matchedByBranch && !p.expanded) {
  10629. p.setExpanded(true, {
  10630. noAnimation: true,
  10631. noEvents: true,
  10632. scrollIntoView: false,
  10633. });
  10634. p._filterAutoExpanded = true;
  10635. }
  10636. }, true);
  10637. }
  10638. });
  10639. treeOpts.autoCollapse = prevAutoCollapse;
  10640. if (count === 0 && opts.nodata && hideMode) {
  10641. statusNode = opts.nodata;
  10642. if ($.isFunction(statusNode)) {
  10643. statusNode = statusNode();
  10644. }
  10645. if (statusNode === true) {
  10646. statusNode = {};
  10647. } else if (typeof statusNode === "string") {
  10648. statusNode = { title: statusNode };
  10649. }
  10650. statusNode = $.extend(
  10651. {
  10652. statusNodeType: "nodata",
  10653. key: KeyNoData,
  10654. title: this.options.strings.noData,
  10655. },
  10656. statusNode
  10657. );
  10658. this.getRootNode().addNode(statusNode).match = true;
  10659. }
  10660. // Redraw whole tree
  10661. this._callHook("treeStructureChanged", this, "applyFilter");
  10662. // this.render();
  10663. this.enableUpdate(prevEnableUpdate);
  10664. return count;
  10665. };
  10666. /**
  10667. * [ext-filter] Dimm or hide nodes.
  10668. *
  10669. * @param {function | string} filter
  10670. * @param {boolean} [opts={autoExpand: false, leavesOnly: false}]
  10671. * @returns {integer} count
  10672. * @alias Fancytree#filterNodes
  10673. * @requires jquery.fancytree.filter.js
  10674. */
  10675. $.ui.fancytree._FancytreeClass.prototype.filterNodes = function(
  10676. filter,
  10677. opts
  10678. ) {
  10679. if (typeof opts === "boolean") {
  10680. opts = { leavesOnly: opts };
  10681. this.warn(
  10682. "Fancytree.filterNodes() leavesOnly option is deprecated since 2.9.0 / 2015-04-19. Use opts.leavesOnly instead."
  10683. );
  10684. }
  10685. return this._applyFilterImpl(filter, false, opts);
  10686. };
  10687. /**
  10688. * [ext-filter] Dimm or hide whole branches.
  10689. *
  10690. * @param {function | string} filter
  10691. * @param {boolean} [opts={autoExpand: false}]
  10692. * @returns {integer} count
  10693. * @alias Fancytree#filterBranches
  10694. * @requires jquery.fancytree.filter.js
  10695. */
  10696. $.ui.fancytree._FancytreeClass.prototype.filterBranches = function(
  10697. filter,
  10698. opts
  10699. ) {
  10700. return this._applyFilterImpl(filter, true, opts);
  10701. };
  10702. /**
  10703. * [ext-filter] Re-apply current filter.
  10704. *
  10705. * @returns {integer} count
  10706. * @alias Fancytree#updateFilter
  10707. * @requires jquery.fancytree.filter.js
  10708. * @since 2.38
  10709. */
  10710. $.ui.fancytree._FancytreeClass.prototype.updateFilter = function() {
  10711. if (
  10712. this.enableFilter &&
  10713. this.lastFilterArgs &&
  10714. this.options.filter.autoApply
  10715. ) {
  10716. this._applyFilterImpl.apply(this, this.lastFilterArgs);
  10717. } else {
  10718. this.warn("updateFilter(): no filter active.");
  10719. }
  10720. };
  10721. /**
  10722. * [ext-filter] Reset the filter.
  10723. *
  10724. * @alias Fancytree#clearFilter
  10725. * @requires jquery.fancytree.filter.js
  10726. */
  10727. $.ui.fancytree._FancytreeClass.prototype.clearFilter = function() {
  10728. var $title,
  10729. statusNode = this.getRootNode()._findDirectChild(KeyNoData),
  10730. escapeTitles = this.options.escapeTitles,
  10731. enhanceTitle = this.options.enhanceTitle,
  10732. prevEnableUpdate = this.enableUpdate(false);
  10733. if (statusNode) {
  10734. statusNode.remove();
  10735. }
  10736. // we also counted root node's subMatchCount
  10737. delete this.rootNode.match;
  10738. delete this.rootNode.subMatchCount;
  10739. this.visit(function(node) {
  10740. if (node.match && node.span) {
  10741. // #491, #601
  10742. $title = $(node.span).find(">span.fancytree-title");
  10743. if (escapeTitles) {
  10744. $title.text(node.title);
  10745. } else {
  10746. $title.html(node.title);
  10747. }
  10748. if (enhanceTitle) {
  10749. enhanceTitle(
  10750. { type: "enhanceTitle" },
  10751. { node: node, $title: $title }
  10752. );
  10753. }
  10754. }
  10755. delete node.match;
  10756. delete node.subMatchCount;
  10757. delete node.titleWithHighlight;
  10758. if (node.$subMatchBadge) {
  10759. node.$subMatchBadge.remove();
  10760. delete node.$subMatchBadge;
  10761. }
  10762. if (node._filterAutoExpanded && node.expanded) {
  10763. node.setExpanded(false, {
  10764. noAnimation: true,
  10765. noEvents: true,
  10766. scrollIntoView: false,
  10767. });
  10768. }
  10769. delete node._filterAutoExpanded;
  10770. });
  10771. this.enableFilter = false;
  10772. this.lastFilterArgs = null;
  10773. this.$div.removeClass(
  10774. "fancytree-ext-filter fancytree-ext-filter-dimm fancytree-ext-filter-hide"
  10775. );
  10776. this._callHook("treeStructureChanged", this, "clearFilter");
  10777. // this.render();
  10778. this.enableUpdate(prevEnableUpdate);
  10779. };
  10780. /**
  10781. * [ext-filter] Return true if a filter is currently applied.
  10782. *
  10783. * @returns {Boolean}
  10784. * @alias Fancytree#isFilterActive
  10785. * @requires jquery.fancytree.filter.js
  10786. * @since 2.13
  10787. */
  10788. $.ui.fancytree._FancytreeClass.prototype.isFilterActive = function() {
  10789. return !!this.enableFilter;
  10790. };
  10791. /**
  10792. * [ext-filter] Return true if this node is matched by current filter (or no filter is active).
  10793. *
  10794. * @returns {Boolean}
  10795. * @alias FancytreeNode#isMatched
  10796. * @requires jquery.fancytree.filter.js
  10797. * @since 2.13
  10798. */
  10799. $.ui.fancytree._FancytreeNodeClass.prototype.isMatched = function() {
  10800. return !(this.tree.enableFilter && !this.match);
  10801. };
  10802. /*******************************************************************************
  10803. * Extension code
  10804. */
  10805. $.ui.fancytree.registerExtension({
  10806. name: "filter",
  10807. version: "2.38.0",
  10808. // Default options for this extension.
  10809. options: {
  10810. autoApply: true, // Re-apply last filter if lazy data is loaded
  10811. autoExpand: false, // Expand all branches that contain matches while filtered
  10812. counter: true, // Show a badge with number of matching child nodes near parent icons
  10813. fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar'
  10814. hideExpandedCounter: true, // Hide counter badge if parent is expanded
  10815. hideExpanders: false, // Hide expanders if all child nodes are hidden by filter
  10816. highlight: true, // Highlight matches by wrapping inside <mark> tags
  10817. leavesOnly: false, // Match end nodes only
  10818. nodata: true, // Display a 'no data' status node if result is empty
  10819. mode: "dimm", // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
  10820. },
  10821. nodeLoadChildren: function(ctx, source) {
  10822. var tree = ctx.tree;
  10823. return this._superApply(arguments).done(function() {
  10824. if (
  10825. tree.enableFilter &&
  10826. tree.lastFilterArgs &&
  10827. ctx.options.filter.autoApply
  10828. ) {
  10829. tree._applyFilterImpl.apply(tree, tree.lastFilterArgs);
  10830. }
  10831. });
  10832. },
  10833. nodeSetExpanded: function(ctx, flag, callOpts) {
  10834. var node = ctx.node;
  10835. delete node._filterAutoExpanded;
  10836. // Make sure counter badge is displayed again, when node is beeing collapsed
  10837. if (
  10838. !flag &&
  10839. ctx.options.filter.hideExpandedCounter &&
  10840. node.$subMatchBadge
  10841. ) {
  10842. node.$subMatchBadge.show();
  10843. }
  10844. return this._superApply(arguments);
  10845. },
  10846. nodeRenderStatus: function(ctx) {
  10847. // Set classes for current status
  10848. var res,
  10849. node = ctx.node,
  10850. tree = ctx.tree,
  10851. opts = ctx.options.filter,
  10852. $title = $(node.span).find("span.fancytree-title"),
  10853. $span = $(node[tree.statusClassPropName]),
  10854. enhanceTitle = ctx.options.enhanceTitle,
  10855. escapeTitles = ctx.options.escapeTitles;
  10856. res = this._super(ctx);
  10857. // nothing to do, if node was not yet rendered
  10858. if (!$span.length || !tree.enableFilter) {
  10859. return res;
  10860. }
  10861. $span
  10862. .toggleClass("fancytree-match", !!node.match)
  10863. .toggleClass("fancytree-submatch", !!node.subMatchCount)
  10864. .toggleClass(
  10865. "fancytree-hide",
  10866. !(node.match || node.subMatchCount)
  10867. );
  10868. // Add/update counter badge
  10869. if (
  10870. opts.counter &&
  10871. node.subMatchCount &&
  10872. (!node.isExpanded() || !opts.hideExpandedCounter)
  10873. ) {
  10874. if (!node.$subMatchBadge) {
  10875. node.$subMatchBadge = $(
  10876. "<span class='fancytree-childcounter'/>"
  10877. );
  10878. $(
  10879. "span.fancytree-icon, span.fancytree-custom-icon",
  10880. node.span
  10881. ).append(node.$subMatchBadge);
  10882. }
  10883. node.$subMatchBadge.show().text(node.subMatchCount);
  10884. } else if (node.$subMatchBadge) {
  10885. node.$subMatchBadge.hide();
  10886. }
  10887. // node.debug("nodeRenderStatus", node.titleWithHighlight, node.title)
  10888. // #601: also check for $title.length, because we don't need to render
  10889. // if node.span is null (i.e. not rendered)
  10890. if (node.span && (!node.isEditing || !node.isEditing.call(node))) {
  10891. if (node.titleWithHighlight) {
  10892. $title.html(node.titleWithHighlight);
  10893. } else if (escapeTitles) {
  10894. $title.text(node.title);
  10895. } else {
  10896. $title.html(node.title);
  10897. }
  10898. if (enhanceTitle) {
  10899. enhanceTitle(
  10900. { type: "enhanceTitle" },
  10901. { node: node, $title: $title }
  10902. );
  10903. }
  10904. }
  10905. return res;
  10906. },
  10907. });
  10908. // Value returned by `require('jquery.fancytree..')`
  10909. return $.ui.fancytree;
  10910. }); // End of closure
  10911. /*! Extension 'jquery.fancytree.glyph.js' *//*!
  10912. * jquery.fancytree.glyph.js
  10913. *
  10914. * Use glyph-fonts, ligature-fonts, or SVG icons instead of icon sprites.
  10915. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10916. *
  10917. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  10918. *
  10919. * Released under the MIT license
  10920. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10921. *
  10922. * @version 2.38.0
  10923. * @date 2021-02-09T20:03:49Z
  10924. */
  10925. (function(factory) {
  10926. if (typeof define === "function" && define.amd) {
  10927. // AMD. Register as an anonymous module.
  10928. define(["jquery", "./jquery.fancytree"], factory);
  10929. } else if (typeof module === "object" && module.exports) {
  10930. // Node/CommonJS
  10931. require("./jquery.fancytree");
  10932. module.exports = factory(require("jquery"));
  10933. } else {
  10934. // Browser globals
  10935. factory(jQuery);
  10936. }
  10937. })(function($) {
  10938. "use strict";
  10939. /******************************************************************************
  10940. * Private functions and variables
  10941. */
  10942. var FT = $.ui.fancytree,
  10943. PRESETS = {
  10944. awesome3: {
  10945. // Outdated!
  10946. _addClass: "",
  10947. checkbox: "icon-check-empty",
  10948. checkboxSelected: "icon-check",
  10949. checkboxUnknown: "icon-check icon-muted",
  10950. dragHelper: "icon-caret-right",
  10951. dropMarker: "icon-caret-right",
  10952. error: "icon-exclamation-sign",
  10953. expanderClosed: "icon-caret-right",
  10954. expanderLazy: "icon-angle-right",
  10955. expanderOpen: "icon-caret-down",
  10956. loading: "icon-refresh icon-spin",
  10957. nodata: "icon-meh",
  10958. noExpander: "",
  10959. radio: "icon-circle-blank",
  10960. radioSelected: "icon-circle",
  10961. // radioUnknown: "icon-circle icon-muted",
  10962. // Default node icons.
  10963. // (Use tree.options.icon callback to define custom icons based on node data)
  10964. doc: "icon-file-alt",
  10965. docOpen: "icon-file-alt",
  10966. folder: "icon-folder-close-alt",
  10967. folderOpen: "icon-folder-open-alt",
  10968. },
  10969. awesome4: {
  10970. _addClass: "fa",
  10971. checkbox: "fa-square-o",
  10972. checkboxSelected: "fa-check-square-o",
  10973. checkboxUnknown: "fa-square fancytree-helper-indeterminate-cb",
  10974. dragHelper: "fa-arrow-right",
  10975. dropMarker: "fa-long-arrow-right",
  10976. error: "fa-warning",
  10977. expanderClosed: "fa-caret-right",
  10978. expanderLazy: "fa-angle-right",
  10979. expanderOpen: "fa-caret-down",
  10980. // We may prevent wobbling rotations on FF by creating a separate sub element:
  10981. loading: { html: "<span class='fa fa-spinner fa-pulse' />" },
  10982. nodata: "fa-meh-o",
  10983. noExpander: "",
  10984. radio: "fa-circle-thin", // "fa-circle-o"
  10985. radioSelected: "fa-circle",
  10986. // radioUnknown: "fa-dot-circle-o",
  10987. // Default node icons.
  10988. // (Use tree.options.icon callback to define custom icons based on node data)
  10989. doc: "fa-file-o",
  10990. docOpen: "fa-file-o",
  10991. folder: "fa-folder-o",
  10992. folderOpen: "fa-folder-open-o",
  10993. },
  10994. awesome5: {
  10995. // fontawesome 5 have several different base classes
  10996. // "far, fas, fal and fab" The rendered svg puts that prefix
  10997. // in a different location so we have to keep them separate here
  10998. _addClass: "",
  10999. checkbox: "far fa-square",
  11000. checkboxSelected: "far fa-check-square",
  11001. // checkboxUnknown: "far fa-window-close",
  11002. checkboxUnknown:
  11003. "fas fa-square fancytree-helper-indeterminate-cb",
  11004. radio: "far fa-circle",
  11005. radioSelected: "fas fa-circle",
  11006. radioUnknown: "far fa-dot-circle",
  11007. dragHelper: "fas fa-arrow-right",
  11008. dropMarker: "fas fa-long-arrow-alt-right",
  11009. error: "fas fa-exclamation-triangle",
  11010. expanderClosed: "fas fa-caret-right",
  11011. expanderLazy: "fas fa-angle-right",
  11012. expanderOpen: "fas fa-caret-down",
  11013. loading: "fas fa-spinner fa-pulse",
  11014. nodata: "far fa-meh",
  11015. noExpander: "",
  11016. // Default node icons.
  11017. // (Use tree.options.icon callback to define custom icons based on node data)
  11018. doc: "far fa-file",
  11019. docOpen: "far fa-file",
  11020. folder: "far fa-folder",
  11021. folderOpen: "far fa-folder-open",
  11022. },
  11023. bootstrap3: {
  11024. _addClass: "glyphicon",
  11025. checkbox: "glyphicon-unchecked",
  11026. checkboxSelected: "glyphicon-check",
  11027. checkboxUnknown:
  11028. "glyphicon-expand fancytree-helper-indeterminate-cb", // "glyphicon-share",
  11029. dragHelper: "glyphicon-play",
  11030. dropMarker: "glyphicon-arrow-right",
  11031. error: "glyphicon-warning-sign",
  11032. expanderClosed: "glyphicon-menu-right", // glyphicon-plus-sign
  11033. expanderLazy: "glyphicon-menu-right", // glyphicon-plus-sign
  11034. expanderOpen: "glyphicon-menu-down", // glyphicon-minus-sign
  11035. loading: "glyphicon-refresh fancytree-helper-spin",
  11036. nodata: "glyphicon-info-sign",
  11037. noExpander: "",
  11038. radio: "glyphicon-remove-circle", // "glyphicon-unchecked",
  11039. radioSelected: "glyphicon-ok-circle", // "glyphicon-check",
  11040. // radioUnknown: "glyphicon-ban-circle",
  11041. // Default node icons.
  11042. // (Use tree.options.icon callback to define custom icons based on node data)
  11043. doc: "glyphicon-file",
  11044. docOpen: "glyphicon-file",
  11045. folder: "glyphicon-folder-close",
  11046. folderOpen: "glyphicon-folder-open",
  11047. },
  11048. material: {
  11049. _addClass: "material-icons",
  11050. checkbox: { text: "check_box_outline_blank" },
  11051. checkboxSelected: { text: "check_box" },
  11052. checkboxUnknown: { text: "indeterminate_check_box" },
  11053. dragHelper: { text: "play_arrow" },
  11054. dropMarker: { text: "arrow-forward" },
  11055. error: { text: "warning" },
  11056. expanderClosed: { text: "chevron_right" },
  11057. expanderLazy: { text: "last_page" },
  11058. expanderOpen: { text: "expand_more" },
  11059. loading: {
  11060. text: "autorenew",
  11061. addClass: "fancytree-helper-spin",
  11062. },
  11063. nodata: { text: "info" },
  11064. noExpander: { text: "" },
  11065. radio: { text: "radio_button_unchecked" },
  11066. radioSelected: { text: "radio_button_checked" },
  11067. // Default node icons.
  11068. // (Use tree.options.icon callback to define custom icons based on node data)
  11069. doc: { text: "insert_drive_file" },
  11070. docOpen: { text: "insert_drive_file" },
  11071. folder: { text: "folder" },
  11072. folderOpen: { text: "folder_open" },
  11073. },
  11074. };
  11075. function setIcon(node, span, baseClass, opts, type) {
  11076. var map = opts.map,
  11077. icon = map[type],
  11078. $span = $(span),
  11079. $counter = $span.find(".fancytree-childcounter"),
  11080. setClass = baseClass + " " + (map._addClass || "");
  11081. // #871 Allow a callback
  11082. if ($.isFunction(icon)) {
  11083. icon = icon.call(this, node, span, type);
  11084. }
  11085. // node.debug( "setIcon(" + baseClass + ", " + type + "): " + "oldIcon" + " -> " + icon );
  11086. // #871: propsed this, but I am not sure how robust this is, e.g.
  11087. // the prefix (fas, far) class changes are not considered?
  11088. // if (span.tagName === "svg" && opts.preset === "awesome5") {
  11089. // // fa5 script converts <i> to <svg> so call a specific handler.
  11090. // var oldIcon = "fa-" + $span.data("icon");
  11091. // // node.debug( "setIcon(" + baseClass + ", " + type + "): " + oldIcon + " -> " + icon );
  11092. // if (typeof oldIcon === "string") {
  11093. // $span.removeClass(oldIcon);
  11094. // }
  11095. // if (typeof icon === "string") {
  11096. // $span.addClass(icon);
  11097. // }
  11098. // return;
  11099. // }
  11100. if (typeof icon === "string") {
  11101. // #883: remove inner html that may be added by prev. mode
  11102. // #1081: keep inner html to fix childcounter issues in IE11
  11103. // span.innerHTML = "";
  11104. $span.attr("class", setClass + " " + icon).append($counter);
  11105. } else if (icon) {
  11106. if (icon.text) {
  11107. span.textContent = "" + icon.text;
  11108. } else if (icon.html) {
  11109. span.innerHTML = icon.html;
  11110. } else {
  11111. span.innerHTML = "";
  11112. }
  11113. $span
  11114. .attr("class", setClass + " " + (icon.addClass || ""))
  11115. .append($counter);
  11116. }
  11117. }
  11118. $.ui.fancytree.registerExtension({
  11119. name: "glyph",
  11120. version: "2.38.0",
  11121. // Default options for this extension.
  11122. options: {
  11123. preset: null, // 'awesome3', 'awesome4', 'bootstrap3', 'material'
  11124. map: {},
  11125. },
  11126. treeInit: function(ctx) {
  11127. var tree = ctx.tree,
  11128. opts = ctx.options.glyph;
  11129. if (opts.preset) {
  11130. FT.assert(
  11131. !!PRESETS[opts.preset],
  11132. "Invalid value for `options.glyph.preset`: " + opts.preset
  11133. );
  11134. opts.map = $.extend({}, PRESETS[opts.preset], opts.map);
  11135. } else {
  11136. tree.warn("ext-glyph: missing `preset` option.");
  11137. }
  11138. this._superApply(arguments);
  11139. tree.$container.addClass("fancytree-ext-glyph");
  11140. },
  11141. nodeRenderStatus: function(ctx) {
  11142. var checkbox,
  11143. icon,
  11144. res,
  11145. span,
  11146. node = ctx.node,
  11147. $span = $(node.span),
  11148. opts = ctx.options.glyph;
  11149. res = this._super(ctx);
  11150. if (node.isRootNode()) {
  11151. return res;
  11152. }
  11153. span = $span.children(".fancytree-expander").get(0);
  11154. if (span) {
  11155. // if( node.isLoading() ){
  11156. // icon = "loading";
  11157. if (node.expanded && node.hasChildren()) {
  11158. icon = "expanderOpen";
  11159. } else if (node.isUndefined()) {
  11160. icon = "expanderLazy";
  11161. } else if (node.hasChildren()) {
  11162. icon = "expanderClosed";
  11163. } else {
  11164. icon = "noExpander";
  11165. }
  11166. // span.className = "fancytree-expander " + map[icon];
  11167. setIcon(node, span, "fancytree-expander", opts, icon);
  11168. }
  11169. if (node.tr) {
  11170. span = $("td", node.tr)
  11171. .find(".fancytree-checkbox")
  11172. .get(0);
  11173. } else {
  11174. span = $span.children(".fancytree-checkbox").get(0);
  11175. }
  11176. if (span) {
  11177. checkbox = FT.evalOption("checkbox", node, node, opts, false);
  11178. if (
  11179. (node.parent && node.parent.radiogroup) ||
  11180. checkbox === "radio"
  11181. ) {
  11182. icon = node.selected ? "radioSelected" : "radio";
  11183. setIcon(
  11184. node,
  11185. span,
  11186. "fancytree-checkbox fancytree-radio",
  11187. opts,
  11188. icon
  11189. );
  11190. } else {
  11191. // eslint-disable-next-line no-nested-ternary
  11192. icon = node.selected
  11193. ? "checkboxSelected"
  11194. : node.partsel
  11195. ? "checkboxUnknown"
  11196. : "checkbox";
  11197. // span.className = "fancytree-checkbox " + map[icon];
  11198. setIcon(node, span, "fancytree-checkbox", opts, icon);
  11199. }
  11200. }
  11201. // Standard icon (note that this does not match .fancytree-custom-icon,
  11202. // that might be set by opts.icon callbacks)
  11203. span = $span.children(".fancytree-icon").get(0);
  11204. if (span) {
  11205. if (node.statusNodeType) {
  11206. icon = node.statusNodeType; // loading, error
  11207. } else if (node.folder) {
  11208. icon =
  11209. node.expanded && node.hasChildren()
  11210. ? "folderOpen"
  11211. : "folder";
  11212. } else {
  11213. icon = node.expanded ? "docOpen" : "doc";
  11214. }
  11215. setIcon(node, span, "fancytree-icon", opts, icon);
  11216. }
  11217. return res;
  11218. },
  11219. nodeSetStatus: function(ctx, status, message, details) {
  11220. var res,
  11221. span,
  11222. opts = ctx.options.glyph,
  11223. node = ctx.node;
  11224. res = this._superApply(arguments);
  11225. if (
  11226. status === "error" ||
  11227. status === "loading" ||
  11228. status === "nodata"
  11229. ) {
  11230. if (node.parent) {
  11231. span = $(".fancytree-expander", node.span).get(0);
  11232. if (span) {
  11233. setIcon(node, span, "fancytree-expander", opts, status);
  11234. }
  11235. } else {
  11236. //
  11237. span = $(
  11238. ".fancytree-statusnode-" + status,
  11239. node[this.nodeContainerAttrName]
  11240. )
  11241. .find(".fancytree-icon")
  11242. .get(0);
  11243. if (span) {
  11244. setIcon(node, span, "fancytree-icon", opts, status);
  11245. }
  11246. }
  11247. }
  11248. return res;
  11249. },
  11250. });
  11251. // Value returned by `require('jquery.fancytree..')`
  11252. return $.ui.fancytree;
  11253. }); // End of closure
  11254. /*! Extension 'jquery.fancytree.gridnav.js' *//*!
  11255. * jquery.fancytree.gridnav.js
  11256. *
  11257. * Support keyboard navigation for trees with embedded input controls.
  11258. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11259. *
  11260. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  11261. *
  11262. * Released under the MIT license
  11263. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11264. *
  11265. * @version 2.38.0
  11266. * @date 2021-02-09T20:03:49Z
  11267. */
  11268. (function(factory) {
  11269. if (typeof define === "function" && define.amd) {
  11270. // AMD. Register as an anonymous module.
  11271. define([
  11272. "jquery",
  11273. "./jquery.fancytree",
  11274. "./jquery.fancytree.table",
  11275. ], factory);
  11276. } else if (typeof module === "object" && module.exports) {
  11277. // Node/CommonJS
  11278. require("./jquery.fancytree.table"); // core + table
  11279. module.exports = factory(require("jquery"));
  11280. } else {
  11281. // Browser globals
  11282. factory(jQuery);
  11283. }
  11284. })(function($) {
  11285. "use strict";
  11286. /*******************************************************************************
  11287. * Private functions and variables
  11288. */
  11289. // Allow these navigation keys even when input controls are focused
  11290. var KC = $.ui.keyCode,
  11291. // which keys are *not* handled by embedded control, but passed to tree
  11292. // navigation handler:
  11293. NAV_KEYS = {
  11294. text: [KC.UP, KC.DOWN],
  11295. checkbox: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11296. link: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11297. radiobutton: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11298. "select-one": [KC.LEFT, KC.RIGHT],
  11299. "select-multiple": [KC.LEFT, KC.RIGHT],
  11300. };
  11301. /* Calculate TD column index (considering colspans).*/
  11302. function getColIdx($tr, $td) {
  11303. var colspan,
  11304. td = $td.get(0),
  11305. idx = 0;
  11306. $tr.children().each(function() {
  11307. if (this === td) {
  11308. return false;
  11309. }
  11310. colspan = $(this).prop("colspan");
  11311. idx += colspan ? colspan : 1;
  11312. });
  11313. return idx;
  11314. }
  11315. /* Find TD at given column index (considering colspans).*/
  11316. function findTdAtColIdx($tr, colIdx) {
  11317. var colspan,
  11318. res = null,
  11319. idx = 0;
  11320. $tr.children().each(function() {
  11321. if (idx >= colIdx) {
  11322. res = $(this);
  11323. return false;
  11324. }
  11325. colspan = $(this).prop("colspan");
  11326. idx += colspan ? colspan : 1;
  11327. });
  11328. return res;
  11329. }
  11330. /* Find adjacent cell for a given direction. Skip empty cells and consider merged cells */
  11331. function findNeighbourTd($target, keyCode) {
  11332. var $tr,
  11333. colIdx,
  11334. $td = $target.closest("td"),
  11335. $tdNext = null;
  11336. switch (keyCode) {
  11337. case KC.LEFT:
  11338. $tdNext = $td.prev();
  11339. break;
  11340. case KC.RIGHT:
  11341. $tdNext = $td.next();
  11342. break;
  11343. case KC.UP:
  11344. case KC.DOWN:
  11345. $tr = $td.parent();
  11346. colIdx = getColIdx($tr, $td);
  11347. while (true) {
  11348. $tr = keyCode === KC.UP ? $tr.prev() : $tr.next();
  11349. if (!$tr.length) {
  11350. break;
  11351. }
  11352. // Skip hidden rows
  11353. if ($tr.is(":hidden")) {
  11354. continue;
  11355. }
  11356. // Find adjacent cell in the same column
  11357. $tdNext = findTdAtColIdx($tr, colIdx);
  11358. // Skip cells that don't conatain a focusable element
  11359. if ($tdNext && $tdNext.find(":input,a").length) {
  11360. break;
  11361. }
  11362. }
  11363. break;
  11364. }
  11365. return $tdNext;
  11366. }
  11367. /*******************************************************************************
  11368. * Extension code
  11369. */
  11370. $.ui.fancytree.registerExtension({
  11371. name: "gridnav",
  11372. version: "2.38.0",
  11373. // Default options for this extension.
  11374. options: {
  11375. autofocusInput: false, // Focus first embedded input if node gets activated
  11376. handleCursorKeys: true, // Allow UP/DOWN in inputs to move to prev/next node
  11377. },
  11378. treeInit: function(ctx) {
  11379. // gridnav requires the table extension to be loaded before itself
  11380. this._requireExtension("table", true, true);
  11381. this._superApply(arguments);
  11382. this.$container.addClass("fancytree-ext-gridnav");
  11383. // Activate node if embedded input gets focus (due to a click)
  11384. this.$container.on("focusin", function(event) {
  11385. var ctx2,
  11386. node = $.ui.fancytree.getNode(event.target);
  11387. if (node && !node.isActive()) {
  11388. // Call node.setActive(), but also pass the event
  11389. ctx2 = ctx.tree._makeHookContext(node, event);
  11390. ctx.tree._callHook("nodeSetActive", ctx2, true);
  11391. }
  11392. });
  11393. },
  11394. nodeSetActive: function(ctx, flag, callOpts) {
  11395. var $outer,
  11396. opts = ctx.options.gridnav,
  11397. node = ctx.node,
  11398. event = ctx.originalEvent || {},
  11399. triggeredByInput = $(event.target).is(":input");
  11400. flag = flag !== false;
  11401. this._superApply(arguments);
  11402. if (flag) {
  11403. if (ctx.options.titlesTabbable) {
  11404. if (!triggeredByInput) {
  11405. $(node.span)
  11406. .find("span.fancytree-title")
  11407. .focus();
  11408. node.setFocus();
  11409. }
  11410. // If one node is tabbable, the container no longer needs to be
  11411. ctx.tree.$container.attr("tabindex", "-1");
  11412. // ctx.tree.$container.removeAttr("tabindex");
  11413. } else if (opts.autofocusInput && !triggeredByInput) {
  11414. // Set focus to input sub input (if node was clicked, but not
  11415. // when TAB was pressed )
  11416. $outer = $(node.tr || node.span);
  11417. $outer
  11418. .find(":input:enabled")
  11419. .first()
  11420. .focus();
  11421. }
  11422. }
  11423. },
  11424. nodeKeydown: function(ctx) {
  11425. var inputType,
  11426. handleKeys,
  11427. $td,
  11428. opts = ctx.options.gridnav,
  11429. event = ctx.originalEvent,
  11430. $target = $(event.target);
  11431. if ($target.is(":input:enabled")) {
  11432. inputType = $target.prop("type");
  11433. } else if ($target.is("a")) {
  11434. inputType = "link";
  11435. }
  11436. // ctx.tree.debug("ext-gridnav nodeKeydown", event, inputType);
  11437. if (inputType && opts.handleCursorKeys) {
  11438. handleKeys = NAV_KEYS[inputType];
  11439. if (handleKeys && $.inArray(event.which, handleKeys) >= 0) {
  11440. $td = findNeighbourTd($target, event.which);
  11441. if ($td && $td.length) {
  11442. // ctx.node.debug("ignore keydown in input", event.which, handleKeys);
  11443. $td.find(":input:enabled,a").focus();
  11444. // Prevent Fancytree default navigation
  11445. return false;
  11446. }
  11447. }
  11448. return true;
  11449. }
  11450. // ctx.tree.debug("ext-gridnav NOT HANDLED", event, inputType);
  11451. return this._superApply(arguments);
  11452. },
  11453. });
  11454. // Value returned by `require('jquery.fancytree..')`
  11455. return $.ui.fancytree;
  11456. }); // End of closure
  11457. /*! Extension 'jquery.fancytree.multi.js' *//*!
  11458. * jquery.fancytree.multi.js
  11459. *
  11460. * Allow multiple selection of nodes by mouse or keyboard.
  11461. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11462. *
  11463. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  11464. *
  11465. * Released under the MIT license
  11466. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11467. *
  11468. * @version 2.38.0
  11469. * @date 2021-02-09T20:03:49Z
  11470. */
  11471. (function(factory) {
  11472. if (typeof define === "function" && define.amd) {
  11473. // AMD. Register as an anonymous module.
  11474. define(["jquery", "./jquery.fancytree"], factory);
  11475. } else if (typeof module === "object" && module.exports) {
  11476. // Node/CommonJS
  11477. require("./jquery.fancytree");
  11478. module.exports = factory(require("jquery"));
  11479. } else {
  11480. // Browser globals
  11481. factory(jQuery);
  11482. }
  11483. })(function($) {
  11484. "use strict";
  11485. /*******************************************************************************
  11486. * Private functions and variables
  11487. */
  11488. // var isMac = /Mac/.test(navigator.platform);
  11489. /*******************************************************************************
  11490. * Extension code
  11491. */
  11492. $.ui.fancytree.registerExtension({
  11493. name: "multi",
  11494. version: "2.38.0",
  11495. // Default options for this extension.
  11496. options: {
  11497. allowNoSelect: false, //
  11498. mode: "sameParent", //
  11499. // Events:
  11500. // beforeSelect: $.noop // Return false to prevent cancel/save (data.input is available)
  11501. },
  11502. treeInit: function(ctx) {
  11503. this._superApply(arguments);
  11504. this.$container.addClass("fancytree-ext-multi");
  11505. if (ctx.options.selectMode === 1) {
  11506. $.error(
  11507. "Fancytree ext-multi: selectMode: 1 (single) is not compatible."
  11508. );
  11509. }
  11510. },
  11511. nodeClick: function(ctx) {
  11512. var //pluginOpts = ctx.options.multi,
  11513. tree = ctx.tree,
  11514. node = ctx.node,
  11515. activeNode = tree.getActiveNode() || tree.getFirstChild(),
  11516. isCbClick = ctx.targetType === "checkbox",
  11517. isExpanderClick = ctx.targetType === "expander",
  11518. eventStr = $.ui.fancytree.eventToString(ctx.originalEvent);
  11519. switch (eventStr) {
  11520. case "click":
  11521. if (isExpanderClick) {
  11522. break;
  11523. } // Default handler will expand/collapse
  11524. if (!isCbClick) {
  11525. tree.selectAll(false);
  11526. // Select clicked node (radio-button mode)
  11527. node.setSelected();
  11528. }
  11529. // Default handler will toggle checkbox clicks and activate
  11530. break;
  11531. case "shift+click":
  11532. // node.debug("click")
  11533. tree.visitRows(
  11534. function(n) {
  11535. // n.debug("click2", n===node, node)
  11536. n.setSelected();
  11537. if (n === node) {
  11538. return false;
  11539. }
  11540. },
  11541. {
  11542. start: activeNode,
  11543. reverse: activeNode.isBelowOf(node),
  11544. }
  11545. );
  11546. break;
  11547. case "ctrl+click":
  11548. case "meta+click": // Mac: [Command]
  11549. node.toggleSelected();
  11550. return;
  11551. }
  11552. return this._superApply(arguments);
  11553. },
  11554. nodeKeydown: function(ctx) {
  11555. var tree = ctx.tree,
  11556. node = ctx.node,
  11557. event = ctx.originalEvent,
  11558. eventStr = $.ui.fancytree.eventToString(event);
  11559. switch (eventStr) {
  11560. case "up":
  11561. case "down":
  11562. tree.selectAll(false);
  11563. node.navigate(event.which, true);
  11564. tree.getActiveNode().setSelected();
  11565. break;
  11566. case "shift+up":
  11567. case "shift+down":
  11568. node.navigate(event.which, true);
  11569. tree.getActiveNode().setSelected();
  11570. break;
  11571. }
  11572. return this._superApply(arguments);
  11573. },
  11574. });
  11575. // Value returned by `require('jquery.fancytree..')`
  11576. return $.ui.fancytree;
  11577. }); // End of closure
  11578. /*! Extension 'jquery.fancytree.persist.js' *//*!
  11579. * jquery.fancytree.persist.js
  11580. *
  11581. * Persist tree status in cookiesRemove or highlight tree nodes, based on a filter.
  11582. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11583. *
  11584. * @depends: js-cookie or jquery-cookie
  11585. *
  11586. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  11587. *
  11588. * Released under the MIT license
  11589. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11590. *
  11591. * @version 2.38.0
  11592. * @date 2021-02-09T20:03:49Z
  11593. */
  11594. (function(factory) {
  11595. if (typeof define === "function" && define.amd) {
  11596. // AMD. Register as an anonymous module.
  11597. define(["jquery", "./jquery.fancytree"], factory);
  11598. } else if (typeof module === "object" && module.exports) {
  11599. // Node/CommonJS
  11600. require("./jquery.fancytree");
  11601. module.exports = factory(require("jquery"));
  11602. } else {
  11603. // Browser globals
  11604. factory(jQuery);
  11605. }
  11606. })(function($) {
  11607. "use strict";
  11608. /* global Cookies:false */
  11609. /*******************************************************************************
  11610. * Private functions and variables
  11611. */
  11612. var cookieStore = null,
  11613. localStorageStore = null,
  11614. sessionStorageStore = null,
  11615. _assert = $.ui.fancytree.assert,
  11616. ACTIVE = "active",
  11617. EXPANDED = "expanded",
  11618. FOCUS = "focus",
  11619. SELECTED = "selected";
  11620. // Accessing window.xxxStorage may raise security exceptions (see #1022)
  11621. try {
  11622. _assert(window.localStorage && window.localStorage.getItem);
  11623. localStorageStore = {
  11624. get: function(key) {
  11625. return window.localStorage.getItem(key);
  11626. },
  11627. set: function(key, value) {
  11628. window.localStorage.setItem(key, value);
  11629. },
  11630. remove: function(key) {
  11631. window.localStorage.removeItem(key);
  11632. },
  11633. };
  11634. } catch (e) {
  11635. $.ui.fancytree.warn("Could not access window.localStorage", e);
  11636. }
  11637. try {
  11638. _assert(window.sessionStorage && window.sessionStorage.getItem);
  11639. sessionStorageStore = {
  11640. get: function(key) {
  11641. return window.sessionStorage.getItem(key);
  11642. },
  11643. set: function(key, value) {
  11644. window.sessionStorage.setItem(key, value);
  11645. },
  11646. remove: function(key) {
  11647. window.sessionStorage.removeItem(key);
  11648. },
  11649. };
  11650. } catch (e) {
  11651. $.ui.fancytree.warn("Could not access window.sessionStorage", e);
  11652. }
  11653. if (typeof Cookies === "function") {
  11654. // Assume https://github.com/js-cookie/js-cookie
  11655. cookieStore = {
  11656. get: Cookies.get,
  11657. set: function(key, value) {
  11658. Cookies.set(key, value, this.options.persist.cookie);
  11659. },
  11660. remove: Cookies.remove,
  11661. };
  11662. } else if ($ && typeof $.cookie === "function") {
  11663. // Fall back to https://github.com/carhartl/jquery-cookie
  11664. cookieStore = {
  11665. get: $.cookie,
  11666. set: function(key, value) {
  11667. $.cookie.set(key, value, this.options.persist.cookie);
  11668. },
  11669. remove: $.removeCookie,
  11670. };
  11671. }
  11672. /* Recursively load lazy nodes
  11673. * @param {string} mode 'load', 'expand', false
  11674. */
  11675. function _loadLazyNodes(tree, local, keyList, mode, dfd) {
  11676. var i,
  11677. key,
  11678. l,
  11679. node,
  11680. foundOne = false,
  11681. expandOpts = tree.options.persist.expandOpts,
  11682. deferredList = [],
  11683. missingKeyList = [];
  11684. keyList = keyList || [];
  11685. dfd = dfd || $.Deferred();
  11686. for (i = 0, l = keyList.length; i < l; i++) {
  11687. key = keyList[i];
  11688. node = tree.getNodeByKey(key);
  11689. if (node) {
  11690. if (mode && node.isUndefined()) {
  11691. foundOne = true;
  11692. tree.debug(
  11693. "_loadLazyNodes: " + node + " is lazy: loading..."
  11694. );
  11695. if (mode === "expand") {
  11696. deferredList.push(node.setExpanded(true, expandOpts));
  11697. } else {
  11698. deferredList.push(node.load());
  11699. }
  11700. } else {
  11701. tree.debug("_loadLazyNodes: " + node + " already loaded.");
  11702. node.setExpanded(true, expandOpts);
  11703. }
  11704. } else {
  11705. missingKeyList.push(key);
  11706. tree.debug("_loadLazyNodes: " + node + " was not yet found.");
  11707. }
  11708. }
  11709. $.when.apply($, deferredList).always(function() {
  11710. // All lazy-expands have finished
  11711. if (foundOne && missingKeyList.length > 0) {
  11712. // If we read new nodes from server, try to resolve yet-missing keys
  11713. _loadLazyNodes(tree, local, missingKeyList, mode, dfd);
  11714. } else {
  11715. if (missingKeyList.length) {
  11716. tree.warn(
  11717. "_loadLazyNodes: could not load those keys: ",
  11718. missingKeyList
  11719. );
  11720. for (i = 0, l = missingKeyList.length; i < l; i++) {
  11721. key = keyList[i];
  11722. local._appendKey(EXPANDED, keyList[i], false);
  11723. }
  11724. }
  11725. dfd.resolve();
  11726. }
  11727. });
  11728. return dfd;
  11729. }
  11730. /**
  11731. * [ext-persist] Remove persistence data of the given type(s).
  11732. * Called like
  11733. * $.ui.fancytree.getTree("#tree").clearCookies("active expanded focus selected");
  11734. *
  11735. * @alias Fancytree#clearPersistData
  11736. * @requires jquery.fancytree.persist.js
  11737. */
  11738. $.ui.fancytree._FancytreeClass.prototype.clearPersistData = function(
  11739. types
  11740. ) {
  11741. var local = this.ext.persist,
  11742. prefix = local.cookiePrefix;
  11743. types = types || "active expanded focus selected";
  11744. if (types.indexOf(ACTIVE) >= 0) {
  11745. local._data(prefix + ACTIVE, null);
  11746. }
  11747. if (types.indexOf(EXPANDED) >= 0) {
  11748. local._data(prefix + EXPANDED, null);
  11749. }
  11750. if (types.indexOf(FOCUS) >= 0) {
  11751. local._data(prefix + FOCUS, null);
  11752. }
  11753. if (types.indexOf(SELECTED) >= 0) {
  11754. local._data(prefix + SELECTED, null);
  11755. }
  11756. };
  11757. $.ui.fancytree._FancytreeClass.prototype.clearCookies = function(types) {
  11758. this.warn(
  11759. "'tree.clearCookies()' is deprecated since v2.27.0: use 'clearPersistData()' instead."
  11760. );
  11761. return this.clearPersistData(types);
  11762. };
  11763. /**
  11764. * [ext-persist] Return persistence information from cookies
  11765. *
  11766. * Called like
  11767. * $.ui.fancytree.getTree("#tree").getPersistData();
  11768. *
  11769. * @alias Fancytree#getPersistData
  11770. * @requires jquery.fancytree.persist.js
  11771. */
  11772. $.ui.fancytree._FancytreeClass.prototype.getPersistData = function() {
  11773. var local = this.ext.persist,
  11774. prefix = local.cookiePrefix,
  11775. delim = local.cookieDelimiter,
  11776. res = {};
  11777. res[ACTIVE] = local._data(prefix + ACTIVE);
  11778. res[EXPANDED] = (local._data(prefix + EXPANDED) || "").split(delim);
  11779. res[SELECTED] = (local._data(prefix + SELECTED) || "").split(delim);
  11780. res[FOCUS] = local._data(prefix + FOCUS);
  11781. return res;
  11782. };
  11783. /******************************************************************************
  11784. * Extension code
  11785. */
  11786. $.ui.fancytree.registerExtension({
  11787. name: "persist",
  11788. version: "2.38.0",
  11789. // Default options for this extension.
  11790. options: {
  11791. cookieDelimiter: "~",
  11792. cookiePrefix: undefined, // 'fancytree-<treeId>-' by default
  11793. cookie: {
  11794. raw: false,
  11795. expires: "",
  11796. path: "",
  11797. domain: "",
  11798. secure: false,
  11799. },
  11800. expandLazy: false, // true: recursively expand and load lazy nodes
  11801. expandOpts: undefined, // optional `opts` argument passed to setExpanded()
  11802. fireActivate: true, // false: suppress `activate` event after active node was restored
  11803. overrideSource: true, // true: cookie takes precedence over `source` data attributes.
  11804. store: "auto", // 'cookie': force cookie, 'local': force localStore, 'session': force sessionStore
  11805. types: "active expanded focus selected",
  11806. },
  11807. /* Generic read/write string data to cookie, sessionStorage or localStorage. */
  11808. _data: function(key, value) {
  11809. var store = this._local.store;
  11810. if (value === undefined) {
  11811. return store.get.call(this, key);
  11812. } else if (value === null) {
  11813. store.remove.call(this, key);
  11814. } else {
  11815. store.set.call(this, key, value);
  11816. }
  11817. },
  11818. /* Append `key` to a cookie. */
  11819. _appendKey: function(type, key, flag) {
  11820. key = "" + key; // #90
  11821. var local = this._local,
  11822. instOpts = this.options.persist,
  11823. delim = instOpts.cookieDelimiter,
  11824. cookieName = local.cookiePrefix + type,
  11825. data = local._data(cookieName),
  11826. keyList = data ? data.split(delim) : [],
  11827. idx = $.inArray(key, keyList);
  11828. // Remove, even if we add a key, so the key is always the last entry
  11829. if (idx >= 0) {
  11830. keyList.splice(idx, 1);
  11831. }
  11832. // Append key to cookie
  11833. if (flag) {
  11834. keyList.push(key);
  11835. }
  11836. local._data(cookieName, keyList.join(delim));
  11837. },
  11838. treeInit: function(ctx) {
  11839. var tree = ctx.tree,
  11840. opts = ctx.options,
  11841. local = this._local,
  11842. instOpts = this.options.persist;
  11843. // // For 'auto' or 'cookie' mode, the cookie plugin must be available
  11844. // _assert((instOpts.store !== "auto" && instOpts.store !== "cookie") || cookieStore,
  11845. // "Missing required plugin for 'persist' extension: js.cookie.js or jquery.cookie.js");
  11846. local.cookiePrefix =
  11847. instOpts.cookiePrefix || "fancytree-" + tree._id + "-";
  11848. local.storeActive = instOpts.types.indexOf(ACTIVE) >= 0;
  11849. local.storeExpanded = instOpts.types.indexOf(EXPANDED) >= 0;
  11850. local.storeSelected = instOpts.types.indexOf(SELECTED) >= 0;
  11851. local.storeFocus = instOpts.types.indexOf(FOCUS) >= 0;
  11852. local.store = null;
  11853. if (instOpts.store === "auto") {
  11854. instOpts.store = localStorageStore ? "local" : "cookie";
  11855. }
  11856. if ($.isPlainObject(instOpts.store)) {
  11857. local.store = instOpts.store;
  11858. } else if (instOpts.store === "cookie") {
  11859. local.store = cookieStore;
  11860. } else if (instOpts.store === "local") {
  11861. local.store =
  11862. instOpts.store === "local"
  11863. ? localStorageStore
  11864. : sessionStorageStore;
  11865. } else if (instOpts.store === "session") {
  11866. local.store =
  11867. instOpts.store === "local"
  11868. ? localStorageStore
  11869. : sessionStorageStore;
  11870. }
  11871. _assert(local.store, "Need a valid store.");
  11872. // Bind init-handler to apply cookie state
  11873. tree.$div.on("fancytreeinit", function(event) {
  11874. if (
  11875. tree._triggerTreeEvent("beforeRestore", null, {}) === false
  11876. ) {
  11877. return;
  11878. }
  11879. var cookie,
  11880. dfd,
  11881. i,
  11882. keyList,
  11883. node,
  11884. prevFocus = local._data(local.cookiePrefix + FOCUS), // record this before node.setActive() overrides it;
  11885. noEvents = instOpts.fireActivate === false;
  11886. // tree.debug("document.cookie:", document.cookie);
  11887. cookie = local._data(local.cookiePrefix + EXPANDED);
  11888. keyList = cookie && cookie.split(instOpts.cookieDelimiter);
  11889. if (local.storeExpanded) {
  11890. // Recursively load nested lazy nodes if expandLazy is 'expand' or 'load'
  11891. // Also remove expand-cookies for unmatched nodes
  11892. dfd = _loadLazyNodes(
  11893. tree,
  11894. local,
  11895. keyList,
  11896. instOpts.expandLazy ? "expand" : false,
  11897. null
  11898. );
  11899. } else {
  11900. // nothing to do
  11901. dfd = new $.Deferred().resolve();
  11902. }
  11903. dfd.done(function() {
  11904. if (local.storeSelected) {
  11905. cookie = local._data(local.cookiePrefix + SELECTED);
  11906. if (cookie) {
  11907. keyList = cookie.split(instOpts.cookieDelimiter);
  11908. for (i = 0; i < keyList.length; i++) {
  11909. node = tree.getNodeByKey(keyList[i]);
  11910. if (node) {
  11911. if (
  11912. node.selected === undefined ||
  11913. (instOpts.overrideSource &&
  11914. node.selected === false)
  11915. ) {
  11916. // node.setSelected();
  11917. node.selected = true;
  11918. node.renderStatus();
  11919. }
  11920. } else {
  11921. // node is no longer member of the tree: remove from cookie also
  11922. local._appendKey(
  11923. SELECTED,
  11924. keyList[i],
  11925. false
  11926. );
  11927. }
  11928. }
  11929. }
  11930. // In selectMode 3 we have to fix the child nodes, since we
  11931. // only stored the selected *top* nodes
  11932. if (tree.options.selectMode === 3) {
  11933. tree.visit(function(n) {
  11934. if (n.selected) {
  11935. n.fixSelection3AfterClick();
  11936. return "skip";
  11937. }
  11938. });
  11939. }
  11940. }
  11941. if (local.storeActive) {
  11942. cookie = local._data(local.cookiePrefix + ACTIVE);
  11943. if (
  11944. cookie &&
  11945. (opts.persist.overrideSource || !tree.activeNode)
  11946. ) {
  11947. node = tree.getNodeByKey(cookie);
  11948. if (node) {
  11949. node.debug("persist: set active", cookie);
  11950. // We only want to set the focus if the container
  11951. // had the keyboard focus before
  11952. node.setActive(true, {
  11953. noFocus: true,
  11954. noEvents: noEvents,
  11955. });
  11956. }
  11957. }
  11958. }
  11959. if (local.storeFocus && prevFocus) {
  11960. node = tree.getNodeByKey(prevFocus);
  11961. if (node) {
  11962. // node.debug("persist: set focus", cookie);
  11963. if (tree.options.titlesTabbable) {
  11964. $(node.span)
  11965. .find(".fancytree-title")
  11966. .focus();
  11967. } else {
  11968. $(tree.$container).focus();
  11969. }
  11970. // node.setFocus();
  11971. }
  11972. }
  11973. tree._triggerTreeEvent("restore", null, {});
  11974. });
  11975. });
  11976. // Init the tree
  11977. return this._superApply(arguments);
  11978. },
  11979. nodeSetActive: function(ctx, flag, callOpts) {
  11980. var res,
  11981. local = this._local;
  11982. flag = flag !== false;
  11983. res = this._superApply(arguments);
  11984. if (local.storeActive) {
  11985. local._data(
  11986. local.cookiePrefix + ACTIVE,
  11987. this.activeNode ? this.activeNode.key : null
  11988. );
  11989. }
  11990. return res;
  11991. },
  11992. nodeSetExpanded: function(ctx, flag, callOpts) {
  11993. var res,
  11994. node = ctx.node,
  11995. local = this._local;
  11996. flag = flag !== false;
  11997. res = this._superApply(arguments);
  11998. if (local.storeExpanded) {
  11999. local._appendKey(EXPANDED, node.key, flag);
  12000. }
  12001. return res;
  12002. },
  12003. nodeSetFocus: function(ctx, flag) {
  12004. var res,
  12005. local = this._local;
  12006. flag = flag !== false;
  12007. res = this._superApply(arguments);
  12008. if (local.storeFocus) {
  12009. local._data(
  12010. local.cookiePrefix + FOCUS,
  12011. this.focusNode ? this.focusNode.key : null
  12012. );
  12013. }
  12014. return res;
  12015. },
  12016. nodeSetSelected: function(ctx, flag, callOpts) {
  12017. var res,
  12018. selNodes,
  12019. tree = ctx.tree,
  12020. node = ctx.node,
  12021. local = this._local;
  12022. flag = flag !== false;
  12023. res = this._superApply(arguments);
  12024. if (local.storeSelected) {
  12025. if (tree.options.selectMode === 3) {
  12026. // In selectMode 3 we only store the the selected *top* nodes.
  12027. // De-selecting a node may also de-select some parents, so we
  12028. // calculate the current status again
  12029. selNodes = $.map(tree.getSelectedNodes(true), function(n) {
  12030. return n.key;
  12031. });
  12032. selNodes = selNodes.join(
  12033. ctx.options.persist.cookieDelimiter
  12034. );
  12035. local._data(local.cookiePrefix + SELECTED, selNodes);
  12036. } else {
  12037. // beforeSelect can prevent the change - flag doesn't reflect the node.selected state
  12038. local._appendKey(SELECTED, node.key, node.selected);
  12039. }
  12040. }
  12041. return res;
  12042. },
  12043. });
  12044. // Value returned by `require('jquery.fancytree..')`
  12045. return $.ui.fancytree;
  12046. }); // End of closure
  12047. /*! Extension 'jquery.fancytree.table.js' *//*!
  12048. * jquery.fancytree.table.js
  12049. *
  12050. * Render tree as table (aka 'tree grid', 'table tree').
  12051. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12052. *
  12053. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  12054. *
  12055. * Released under the MIT license
  12056. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12057. *
  12058. * @version 2.38.0
  12059. * @date 2021-02-09T20:03:49Z
  12060. */
  12061. (function(factory) {
  12062. if (typeof define === "function" && define.amd) {
  12063. // AMD. Register as an anonymous module.
  12064. define(["jquery", "./jquery.fancytree"], factory);
  12065. } else if (typeof module === "object" && module.exports) {
  12066. // Node/CommonJS
  12067. require("./jquery.fancytree");
  12068. module.exports = factory(require("jquery"));
  12069. } else {
  12070. // Browser globals
  12071. factory(jQuery);
  12072. }
  12073. })(function($) {
  12074. "use strict";
  12075. /******************************************************************************
  12076. * Private functions and variables
  12077. */
  12078. var _assert = $.ui.fancytree.assert;
  12079. function insertFirstChild(referenceNode, newNode) {
  12080. referenceNode.insertBefore(newNode, referenceNode.firstChild);
  12081. }
  12082. function insertSiblingAfter(referenceNode, newNode) {
  12083. referenceNode.parentNode.insertBefore(
  12084. newNode,
  12085. referenceNode.nextSibling
  12086. );
  12087. }
  12088. /* Show/hide all rows that are structural descendants of `parent`. */
  12089. function setChildRowVisibility(parent, flag) {
  12090. parent.visit(function(node) {
  12091. var tr = node.tr;
  12092. // currentFlag = node.hide ? false : flag; // fix for ext-filter
  12093. if (tr) {
  12094. tr.style.display = node.hide || !flag ? "none" : "";
  12095. }
  12096. if (!node.expanded) {
  12097. return "skip";
  12098. }
  12099. });
  12100. }
  12101. /* Find node that is rendered in previous row. */
  12102. function findPrevRowNode(node) {
  12103. var i,
  12104. last,
  12105. prev,
  12106. parent = node.parent,
  12107. siblings = parent ? parent.children : null;
  12108. if (siblings && siblings.length > 1 && siblings[0] !== node) {
  12109. // use the lowest descendant of the preceeding sibling
  12110. i = $.inArray(node, siblings);
  12111. prev = siblings[i - 1];
  12112. _assert(prev.tr);
  12113. // descend to lowest child (with a <tr> tag)
  12114. while (prev.children && prev.children.length) {
  12115. last = prev.children[prev.children.length - 1];
  12116. if (!last.tr) {
  12117. break;
  12118. }
  12119. prev = last;
  12120. }
  12121. } else {
  12122. // if there is no preceding sibling, use the direct parent
  12123. prev = parent;
  12124. }
  12125. return prev;
  12126. }
  12127. $.ui.fancytree.registerExtension({
  12128. name: "table",
  12129. version: "2.38.0",
  12130. // Default options for this extension.
  12131. options: {
  12132. checkboxColumnIdx: null, // render the checkboxes into the this column index (default: nodeColumnIdx)
  12133. indentation: 16, // indent every node level by 16px
  12134. mergeStatusColumns: true, // display 'nodata', 'loading', 'error' centered in a single, merged TR
  12135. nodeColumnIdx: 0, // render node expander, icon, and title to this column (default: #0)
  12136. },
  12137. // Overide virtual methods for this extension.
  12138. // `this` : is this extension object
  12139. // `this._super`: the virtual function that was overriden (member of prev. extension or Fancytree)
  12140. treeInit: function(ctx) {
  12141. var i,
  12142. n,
  12143. $row,
  12144. $tbody,
  12145. tree = ctx.tree,
  12146. opts = ctx.options,
  12147. tableOpts = opts.table,
  12148. $table = tree.widget.element;
  12149. if (tableOpts.customStatus != null) {
  12150. if (opts.renderStatusColumns == null) {
  12151. tree.warn(
  12152. "The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' instead."
  12153. );
  12154. opts.renderStatusColumns = tableOpts.customStatus;
  12155. } else {
  12156. $.error(
  12157. "The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' only instead."
  12158. );
  12159. }
  12160. }
  12161. if (opts.renderStatusColumns) {
  12162. if (opts.renderStatusColumns === true) {
  12163. opts.renderStatusColumns = opts.renderColumns;
  12164. // } else if( opts.renderStatusColumns === "wide" ) {
  12165. // opts.renderStatusColumns = _renderStatusNodeWide;
  12166. }
  12167. }
  12168. $table.addClass("fancytree-container fancytree-ext-table");
  12169. $tbody = $table.find(">tbody");
  12170. if (!$tbody.length) {
  12171. // TODO: not sure if we can rely on browsers to insert missing <tbody> before <tr>s:
  12172. if ($table.find(">tr").length) {
  12173. $.error(
  12174. "Expected table > tbody > tr. If you see this please open an issue."
  12175. );
  12176. }
  12177. $tbody = $("<tbody>").appendTo($table);
  12178. }
  12179. tree.tbody = $tbody[0];
  12180. // Prepare row templates:
  12181. // Determine column count from table header if any
  12182. tree.columnCount = $("thead >tr", $table)
  12183. .last()
  12184. .find(">th", $table).length;
  12185. // Read TR templates from tbody if any
  12186. $row = $tbody.children("tr").first();
  12187. if ($row.length) {
  12188. n = $row.children("td").length;
  12189. if (tree.columnCount && n !== tree.columnCount) {
  12190. tree.warn(
  12191. "Column count mismatch between thead (" +
  12192. tree.columnCount +
  12193. ") and tbody (" +
  12194. n +
  12195. "): using tbody."
  12196. );
  12197. tree.columnCount = n;
  12198. }
  12199. $row = $row.clone();
  12200. } else {
  12201. // Only thead is defined: create default row markup
  12202. _assert(
  12203. tree.columnCount >= 1,
  12204. "Need either <thead> or <tbody> with <td> elements to determine column count."
  12205. );
  12206. $row = $("<tr />");
  12207. for (i = 0; i < tree.columnCount; i++) {
  12208. $row.append("<td />");
  12209. }
  12210. }
  12211. $row.find(">td")
  12212. .eq(tableOpts.nodeColumnIdx)
  12213. .html("<span class='fancytree-node' />");
  12214. if (opts.aria) {
  12215. $row.attr("role", "row");
  12216. $row.find("td").attr("role", "gridcell");
  12217. }
  12218. tree.rowFragment = document.createDocumentFragment();
  12219. tree.rowFragment.appendChild($row.get(0));
  12220. // // If tbody contains a second row, use this as status node template
  12221. // $row = $tbody.children("tr").eq(1);
  12222. // if( $row.length === 0 ) {
  12223. // tree.statusRowFragment = tree.rowFragment;
  12224. // } else {
  12225. // $row = $row.clone();
  12226. // tree.statusRowFragment = document.createDocumentFragment();
  12227. // tree.statusRowFragment.appendChild($row.get(0));
  12228. // }
  12229. //
  12230. $tbody.empty();
  12231. // Make sure that status classes are set on the node's <tr> elements
  12232. tree.statusClassPropName = "tr";
  12233. tree.ariaPropName = "tr";
  12234. this.nodeContainerAttrName = "tr";
  12235. // #489: make sure $container is set to <table>, even if ext-dnd is listed before ext-table
  12236. tree.$container = $table;
  12237. this._superApply(arguments);
  12238. // standard Fancytree created a root UL
  12239. $(tree.rootNode.ul).remove();
  12240. tree.rootNode.ul = null;
  12241. // Add container to the TAB chain
  12242. // #577: Allow to set tabindex to "0", "-1" and ""
  12243. this.$container.attr("tabindex", opts.tabindex);
  12244. // this.$container.attr("tabindex", opts.tabbable ? "0" : "-1");
  12245. if (opts.aria) {
  12246. tree.$container
  12247. .attr("role", "treegrid")
  12248. .attr("aria-readonly", true);
  12249. }
  12250. },
  12251. nodeRemoveChildMarkup: function(ctx) {
  12252. var node = ctx.node;
  12253. // node.debug("nodeRemoveChildMarkup()");
  12254. node.visit(function(n) {
  12255. if (n.tr) {
  12256. $(n.tr).remove();
  12257. n.tr = null;
  12258. }
  12259. });
  12260. },
  12261. nodeRemoveMarkup: function(ctx) {
  12262. var node = ctx.node;
  12263. // node.debug("nodeRemoveMarkup()");
  12264. if (node.tr) {
  12265. $(node.tr).remove();
  12266. node.tr = null;
  12267. }
  12268. this.nodeRemoveChildMarkup(ctx);
  12269. },
  12270. /* Override standard render. */
  12271. nodeRender: function(ctx, force, deep, collapsed, _recursive) {
  12272. var children,
  12273. firstTr,
  12274. i,
  12275. l,
  12276. newRow,
  12277. prevNode,
  12278. prevTr,
  12279. subCtx,
  12280. tree = ctx.tree,
  12281. node = ctx.node,
  12282. opts = ctx.options,
  12283. isRootNode = !node.parent;
  12284. if (tree._enableUpdate === false) {
  12285. // $.ui.fancytree.debug("*** nodeRender _enableUpdate: false");
  12286. return;
  12287. }
  12288. if (!_recursive) {
  12289. ctx.hasCollapsedParents = node.parent && !node.parent.expanded;
  12290. }
  12291. // $.ui.fancytree.debug("*** nodeRender " + node + ", isRoot=" + isRootNode, "tr=" + node.tr, "hcp=" + ctx.hasCollapsedParents, "parent.tr=" + (node.parent && node.parent.tr));
  12292. if (!isRootNode) {
  12293. if (node.tr && force) {
  12294. this.nodeRemoveMarkup(ctx);
  12295. }
  12296. if (node.tr) {
  12297. if (force) {
  12298. // Set icon, link, and title (normally this is only required on initial render)
  12299. this.nodeRenderTitle(ctx); // triggers renderColumns()
  12300. } else {
  12301. // Update element classes according to node state
  12302. this.nodeRenderStatus(ctx);
  12303. }
  12304. } else {
  12305. if (ctx.hasCollapsedParents && !deep) {
  12306. // #166: we assume that the parent will be (recursively) rendered
  12307. // later anyway.
  12308. // node.debug("nodeRender ignored due to unrendered parent");
  12309. return;
  12310. }
  12311. // Create new <tr> after previous row
  12312. // if( node.isStatusNode() ) {
  12313. // newRow = tree.statusRowFragment.firstChild.cloneNode(true);
  12314. // } else {
  12315. newRow = tree.rowFragment.firstChild.cloneNode(true);
  12316. // }
  12317. prevNode = findPrevRowNode(node);
  12318. // $.ui.fancytree.debug("*** nodeRender " + node + ": prev: " + prevNode.key);
  12319. _assert(prevNode);
  12320. if (collapsed === true && _recursive) {
  12321. // hide all child rows, so we can use an animation to show it later
  12322. newRow.style.display = "none";
  12323. } else if (deep && ctx.hasCollapsedParents) {
  12324. // also hide this row if deep === true but any parent is collapsed
  12325. newRow.style.display = "none";
  12326. // newRow.style.color = "red";
  12327. }
  12328. if (prevNode.tr) {
  12329. insertSiblingAfter(prevNode.tr, newRow);
  12330. } else {
  12331. _assert(
  12332. !prevNode.parent,
  12333. "prev. row must have a tr, or be system root"
  12334. );
  12335. // tree.tbody.appendChild(newRow);
  12336. insertFirstChild(tree.tbody, newRow); // #675
  12337. }
  12338. node.tr = newRow;
  12339. if (node.key && opts.generateIds) {
  12340. node.tr.id = opts.idPrefix + node.key;
  12341. }
  12342. node.tr.ftnode = node;
  12343. // if(opts.aria){
  12344. // $(node.tr).attr("aria-labelledby", "ftal_" + opts.idPrefix + node.key);
  12345. // }
  12346. node.span = $("span.fancytree-node", node.tr).get(0);
  12347. // Set icon, link, and title (normally this is only required on initial render)
  12348. this.nodeRenderTitle(ctx);
  12349. // Allow tweaking, binding, after node was created for the first time
  12350. // tree._triggerNodeEvent("createNode", ctx);
  12351. if (opts.createNode) {
  12352. opts.createNode.call(tree, { type: "createNode" }, ctx);
  12353. }
  12354. }
  12355. }
  12356. // Allow tweaking after node state was rendered
  12357. // tree._triggerNodeEvent("renderNode", ctx);
  12358. if (opts.renderNode) {
  12359. opts.renderNode.call(tree, { type: "renderNode" }, ctx);
  12360. }
  12361. // Visit child nodes
  12362. // Add child markup
  12363. children = node.children;
  12364. if (children && (isRootNode || deep || node.expanded)) {
  12365. for (i = 0, l = children.length; i < l; i++) {
  12366. subCtx = $.extend({}, ctx, { node: children[i] });
  12367. subCtx.hasCollapsedParents =
  12368. subCtx.hasCollapsedParents || !node.expanded;
  12369. this.nodeRender(subCtx, force, deep, collapsed, true);
  12370. }
  12371. }
  12372. // Make sure, that <tr> order matches node.children order.
  12373. if (children && !_recursive) {
  12374. // we only have to do it once, for the root branch
  12375. prevTr = node.tr || null;
  12376. firstTr = tree.tbody.firstChild;
  12377. // Iterate over all descendants
  12378. node.visit(function(n) {
  12379. if (n.tr) {
  12380. if (
  12381. !n.parent.expanded &&
  12382. n.tr.style.display !== "none"
  12383. ) {
  12384. // fix after a node was dropped over a collapsed
  12385. n.tr.style.display = "none";
  12386. setChildRowVisibility(n, false);
  12387. }
  12388. if (n.tr.previousSibling !== prevTr) {
  12389. node.debug("_fixOrder: mismatch at node: " + n);
  12390. var nextTr = prevTr ? prevTr.nextSibling : firstTr;
  12391. tree.tbody.insertBefore(n.tr, nextTr);
  12392. }
  12393. prevTr = n.tr;
  12394. }
  12395. });
  12396. }
  12397. // Update element classes according to node state
  12398. // if(!isRootNode){
  12399. // this.nodeRenderStatus(ctx);
  12400. // }
  12401. },
  12402. nodeRenderTitle: function(ctx, title) {
  12403. var $cb,
  12404. res,
  12405. tree = ctx.tree,
  12406. node = ctx.node,
  12407. opts = ctx.options,
  12408. isStatusNode = node.isStatusNode();
  12409. res = this._super(ctx, title);
  12410. if (node.isRootNode()) {
  12411. return res;
  12412. }
  12413. // Move checkbox to custom column
  12414. if (
  12415. opts.checkbox &&
  12416. !isStatusNode &&
  12417. opts.table.checkboxColumnIdx != null
  12418. ) {
  12419. $cb = $("span.fancytree-checkbox", node.span); //.detach();
  12420. $(node.tr)
  12421. .find("td")
  12422. .eq(+opts.table.checkboxColumnIdx)
  12423. .html($cb);
  12424. }
  12425. // Update element classes according to node state
  12426. this.nodeRenderStatus(ctx);
  12427. if (isStatusNode) {
  12428. if (opts.renderStatusColumns) {
  12429. // Let user code write column content
  12430. opts.renderStatusColumns.call(
  12431. tree,
  12432. { type: "renderStatusColumns" },
  12433. ctx
  12434. );
  12435. } else if (opts.table.mergeStatusColumns && node.isTopLevel()) {
  12436. $(node.tr)
  12437. .find(">td")
  12438. .eq(0)
  12439. .prop("colspan", tree.columnCount)
  12440. .text(node.title)
  12441. .addClass("fancytree-status-merged")
  12442. .nextAll()
  12443. .remove();
  12444. } // else: default rendering for status node: leave other cells empty
  12445. } else if (opts.renderColumns) {
  12446. opts.renderColumns.call(tree, { type: "renderColumns" }, ctx);
  12447. }
  12448. return res;
  12449. },
  12450. nodeRenderStatus: function(ctx) {
  12451. var indent,
  12452. node = ctx.node,
  12453. opts = ctx.options;
  12454. this._super(ctx);
  12455. $(node.tr).removeClass("fancytree-node");
  12456. // indent
  12457. indent = (node.getLevel() - 1) * opts.table.indentation;
  12458. if (opts.rtl) {
  12459. $(node.span).css({ paddingRight: indent + "px" });
  12460. } else {
  12461. $(node.span).css({ paddingLeft: indent + "px" });
  12462. }
  12463. },
  12464. /* Expand node, return Deferred.promise. */
  12465. nodeSetExpanded: function(ctx, flag, callOpts) {
  12466. // flag defaults to true
  12467. flag = flag !== false;
  12468. if ((ctx.node.expanded && flag) || (!ctx.node.expanded && !flag)) {
  12469. // Expanded state isn't changed - just call base implementation
  12470. return this._superApply(arguments);
  12471. }
  12472. var dfd = new $.Deferred(),
  12473. subOpts = $.extend({}, callOpts, {
  12474. noEvents: true,
  12475. noAnimation: true,
  12476. });
  12477. callOpts = callOpts || {};
  12478. function _afterExpand(ok) {
  12479. setChildRowVisibility(ctx.node, flag);
  12480. if (ok) {
  12481. if (
  12482. flag &&
  12483. ctx.options.autoScroll &&
  12484. !callOpts.noAnimation &&
  12485. ctx.node.hasChildren()
  12486. ) {
  12487. // Scroll down to last child, but keep current node visible
  12488. ctx.node
  12489. .getLastChild()
  12490. .scrollIntoView(true, { topNode: ctx.node })
  12491. .always(function() {
  12492. if (!callOpts.noEvents) {
  12493. ctx.tree._triggerNodeEvent(
  12494. flag ? "expand" : "collapse",
  12495. ctx
  12496. );
  12497. }
  12498. dfd.resolveWith(ctx.node);
  12499. });
  12500. } else {
  12501. if (!callOpts.noEvents) {
  12502. ctx.tree._triggerNodeEvent(
  12503. flag ? "expand" : "collapse",
  12504. ctx
  12505. );
  12506. }
  12507. dfd.resolveWith(ctx.node);
  12508. }
  12509. } else {
  12510. if (!callOpts.noEvents) {
  12511. ctx.tree._triggerNodeEvent(
  12512. flag ? "expand" : "collapse",
  12513. ctx
  12514. );
  12515. }
  12516. dfd.rejectWith(ctx.node);
  12517. }
  12518. }
  12519. // Call base-expand with disabled events and animation
  12520. this._super(ctx, flag, subOpts)
  12521. .done(function() {
  12522. _afterExpand(true);
  12523. })
  12524. .fail(function() {
  12525. _afterExpand(false);
  12526. });
  12527. return dfd.promise();
  12528. },
  12529. nodeSetStatus: function(ctx, status, message, details) {
  12530. if (status === "ok") {
  12531. var node = ctx.node,
  12532. firstChild = node.children ? node.children[0] : null;
  12533. if (firstChild && firstChild.isStatusNode()) {
  12534. $(firstChild.tr).remove();
  12535. }
  12536. }
  12537. return this._superApply(arguments);
  12538. },
  12539. treeClear: function(ctx) {
  12540. this.nodeRemoveChildMarkup(this._makeHookContext(this.rootNode));
  12541. return this._superApply(arguments);
  12542. },
  12543. treeDestroy: function(ctx) {
  12544. this.$container.find("tbody").empty();
  12545. if (this.$source) {
  12546. this.$source.removeClass("fancytree-helper-hidden");
  12547. }
  12548. return this._superApply(arguments);
  12549. },
  12550. /*,
  12551. treeSetFocus: function(ctx, flag) {
  12552. // alert("treeSetFocus" + ctx.tree.$container);
  12553. ctx.tree.$container.focus();
  12554. $.ui.fancytree.focusTree = ctx.tree;
  12555. }*/
  12556. });
  12557. // Value returned by `require('jquery.fancytree..')`
  12558. return $.ui.fancytree;
  12559. }); // End of closure
  12560. /*! Extension 'jquery.fancytree.themeroller.js' *//*!
  12561. * jquery.fancytree.themeroller.js
  12562. *
  12563. * Enable jQuery UI ThemeRoller styles.
  12564. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12565. *
  12566. * @see http://jqueryui.com/themeroller/
  12567. *
  12568. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  12569. *
  12570. * Released under the MIT license
  12571. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12572. *
  12573. * @version 2.38.0
  12574. * @date 2021-02-09T20:03:49Z
  12575. */
  12576. (function(factory) {
  12577. if (typeof define === "function" && define.amd) {
  12578. // AMD. Register as an anonymous module.
  12579. define(["jquery", "./jquery.fancytree"], factory);
  12580. } else if (typeof module === "object" && module.exports) {
  12581. // Node/CommonJS
  12582. require("./jquery.fancytree");
  12583. module.exports = factory(require("jquery"));
  12584. } else {
  12585. // Browser globals
  12586. factory(jQuery);
  12587. }
  12588. })(function($) {
  12589. "use strict";
  12590. /*******************************************************************************
  12591. * Extension code
  12592. */
  12593. $.ui.fancytree.registerExtension({
  12594. name: "themeroller",
  12595. version: "2.38.0",
  12596. // Default options for this extension.
  12597. options: {
  12598. activeClass: "ui-state-active", // Class added to active node
  12599. // activeClass: "ui-state-highlight",
  12600. addClass: "ui-corner-all", // Class added to all nodes
  12601. focusClass: "ui-state-focus", // Class added to focused node
  12602. hoverClass: "ui-state-hover", // Class added to hovered node
  12603. selectedClass: "ui-state-highlight", // Class added to selected nodes
  12604. // selectedClass: "ui-state-active"
  12605. },
  12606. treeInit: function(ctx) {
  12607. var $el = ctx.widget.element,
  12608. opts = ctx.options.themeroller;
  12609. this._superApply(arguments);
  12610. if ($el[0].nodeName === "TABLE") {
  12611. $el.addClass("ui-widget ui-corner-all");
  12612. $el.find(">thead tr").addClass("ui-widget-header");
  12613. $el.find(">tbody").addClass("ui-widget-conent");
  12614. } else {
  12615. $el.addClass("ui-widget ui-widget-content ui-corner-all");
  12616. }
  12617. $el.on("mouseenter mouseleave", ".fancytree-node", function(event) {
  12618. var node = $.ui.fancytree.getNode(event.target),
  12619. flag = event.type === "mouseenter";
  12620. $(node.tr ? node.tr : node.span).toggleClass(
  12621. opts.hoverClass + " " + opts.addClass,
  12622. flag
  12623. );
  12624. });
  12625. },
  12626. treeDestroy: function(ctx) {
  12627. this._superApply(arguments);
  12628. ctx.widget.element.removeClass(
  12629. "ui-widget ui-widget-content ui-corner-all"
  12630. );
  12631. },
  12632. nodeRenderStatus: function(ctx) {
  12633. var classes = {},
  12634. node = ctx.node,
  12635. $el = $(node.tr ? node.tr : node.span),
  12636. opts = ctx.options.themeroller;
  12637. this._super(ctx);
  12638. /*
  12639. .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.
  12640. .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.
  12641. .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.
  12642. .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.
  12643. .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.
  12644. .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.
  12645. .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.
  12646. */
  12647. // Set ui-state-* class (handle the case that the same class is assigned
  12648. // to different states)
  12649. classes[opts.activeClass] = false;
  12650. classes[opts.focusClass] = false;
  12651. classes[opts.selectedClass] = false;
  12652. if (node.isActive()) {
  12653. classes[opts.activeClass] = true;
  12654. }
  12655. if (node.hasFocus()) {
  12656. classes[opts.focusClass] = true;
  12657. }
  12658. // activeClass takes precedence before selectedClass:
  12659. if (node.isSelected() && !node.isActive()) {
  12660. classes[opts.selectedClass] = true;
  12661. }
  12662. $el.toggleClass(opts.activeClass, classes[opts.activeClass]);
  12663. $el.toggleClass(opts.focusClass, classes[opts.focusClass]);
  12664. $el.toggleClass(opts.selectedClass, classes[opts.selectedClass]);
  12665. // Additional classes (e.g. 'ui-corner-all')
  12666. $el.addClass(opts.addClass);
  12667. },
  12668. });
  12669. // Value returned by `require('jquery.fancytree..')`
  12670. return $.ui.fancytree;
  12671. }); // End of closure
  12672. /*! Extension 'jquery.fancytree.wide.js' *//*!
  12673. * jquery.fancytree.wide.js
  12674. * Support for 100% wide selection bars.
  12675. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12676. *
  12677. * Copyright (c) 2008-2021, Martin Wendt (https://wwWendt.de)
  12678. *
  12679. * Released under the MIT license
  12680. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12681. *
  12682. * @version 2.38.0
  12683. * @date 2021-02-09T20:03:49Z
  12684. */
  12685. (function(factory) {
  12686. if (typeof define === "function" && define.amd) {
  12687. // AMD. Register as an anonymous module.
  12688. define(["jquery", "./jquery.fancytree"], factory);
  12689. } else if (typeof module === "object" && module.exports) {
  12690. // Node/CommonJS
  12691. require("./jquery.fancytree");
  12692. module.exports = factory(require("jquery"));
  12693. } else {
  12694. // Browser globals
  12695. factory(jQuery);
  12696. }
  12697. })(function($) {
  12698. "use strict";
  12699. var reNumUnit = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/; // split "1.5em" to ["1.5", "em"]
  12700. /*******************************************************************************
  12701. * Private functions and variables
  12702. */
  12703. // var _assert = $.ui.fancytree.assert;
  12704. /* Calculate inner width without scrollbar */
  12705. // function realInnerWidth($el) {
  12706. // // http://blog.jquery.com/2012/08/16/jquery-1-8-box-sizing-width-csswidth-and-outerwidth/
  12707. // // inst.contWidth = parseFloat(this.$container.css("width"), 10);
  12708. // // 'Client width without scrollbar' - 'padding'
  12709. // return $el[0].clientWidth - ($el.innerWidth() - parseFloat($el.css("width"), 10));
  12710. // }
  12711. /* Create a global embedded CSS style for the tree. */
  12712. function defineHeadStyleElement(id, cssText) {
  12713. id = "fancytree-style-" + id;
  12714. var $headStyle = $("#" + id);
  12715. if (!cssText) {
  12716. $headStyle.remove();
  12717. return null;
  12718. }
  12719. if (!$headStyle.length) {
  12720. $headStyle = $("<style />")
  12721. .attr("id", id)
  12722. .addClass("fancytree-style")
  12723. .prop("type", "text/css")
  12724. .appendTo("head");
  12725. }
  12726. try {
  12727. $headStyle.html(cssText);
  12728. } catch (e) {
  12729. // fix for IE 6-8
  12730. $headStyle[0].styleSheet.cssText = cssText;
  12731. }
  12732. return $headStyle;
  12733. }
  12734. /* Calculate the CSS rules that indent title spans. */
  12735. function renderLevelCss(
  12736. containerId,
  12737. depth,
  12738. levelOfs,
  12739. lineOfs,
  12740. labelOfs,
  12741. measureUnit
  12742. ) {
  12743. var i,
  12744. prefix = "#" + containerId + " span.fancytree-level-",
  12745. rules = [];
  12746. for (i = 0; i < depth; i++) {
  12747. rules.push(
  12748. prefix +
  12749. (i + 1) +
  12750. " span.fancytree-title { padding-left: " +
  12751. (i * levelOfs + lineOfs) +
  12752. measureUnit +
  12753. "; }"
  12754. );
  12755. }
  12756. // Some UI animations wrap the UL inside a DIV and set position:relative on both.
  12757. // This breaks the left:0 and padding-left:nn settings of the title
  12758. rules.push(
  12759. "#" +
  12760. containerId +
  12761. " div.ui-effects-wrapper ul li span.fancytree-title, " +
  12762. "#" +
  12763. containerId +
  12764. " li.fancytree-animating span.fancytree-title " + // #716
  12765. "{ padding-left: " +
  12766. labelOfs +
  12767. measureUnit +
  12768. "; position: static; width: auto; }"
  12769. );
  12770. return rules.join("\n");
  12771. }
  12772. // /**
  12773. // * [ext-wide] Recalculate the width of the selection bar after the tree container
  12774. // * was resized.<br>
  12775. // * May be called explicitly on container resize, since there is no resize event
  12776. // * for DIV tags.
  12777. // *
  12778. // * @alias Fancytree#wideUpdate
  12779. // * @requires jquery.fancytree.wide.js
  12780. // */
  12781. // $.ui.fancytree._FancytreeClass.prototype.wideUpdate = function(){
  12782. // var inst = this.ext.wide,
  12783. // prevCw = inst.contWidth,
  12784. // prevLo = inst.lineOfs;
  12785. // inst.contWidth = realInnerWidth(this.$container);
  12786. // // Each title is precceeded by 2 or 3 icons (16px + 3 margin)
  12787. // // + 1px title border and 3px title padding
  12788. // // TODO: use code from treeInit() below
  12789. // inst.lineOfs = (this.options.checkbox ? 3 : 2) * 19;
  12790. // if( prevCw !== inst.contWidth || prevLo !== inst.lineOfs ) {
  12791. // this.debug("wideUpdate: " + inst.contWidth);
  12792. // this.visit(function(node){
  12793. // node.tree._callHook("nodeRenderTitle", node);
  12794. // });
  12795. // }
  12796. // };
  12797. /*******************************************************************************
  12798. * Extension code
  12799. */
  12800. $.ui.fancytree.registerExtension({
  12801. name: "wide",
  12802. version: "2.38.0",
  12803. // Default options for this extension.
  12804. options: {
  12805. iconWidth: null, // Adjust this if @fancy-icon-width != "16px"
  12806. iconSpacing: null, // Adjust this if @fancy-icon-spacing != "3px"
  12807. labelSpacing: null, // Adjust this if padding between icon and label != "3px"
  12808. levelOfs: null, // Adjust this if ul padding != "16px"
  12809. },
  12810. treeCreate: function(ctx) {
  12811. this._superApply(arguments);
  12812. this.$container.addClass("fancytree-ext-wide");
  12813. var containerId,
  12814. cssText,
  12815. iconSpacingUnit,
  12816. labelSpacingUnit,
  12817. iconWidthUnit,
  12818. levelOfsUnit,
  12819. instOpts = ctx.options.wide,
  12820. // css sniffing
  12821. $dummyLI = $(
  12822. "<li id='fancytreeTemp'><span class='fancytree-node'><span class='fancytree-icon' /><span class='fancytree-title' /></span><ul />"
  12823. ).appendTo(ctx.tree.$container),
  12824. $dummyIcon = $dummyLI.find(".fancytree-icon"),
  12825. $dummyUL = $dummyLI.find("ul"),
  12826. // $dummyTitle = $dummyLI.find(".fancytree-title"),
  12827. iconSpacing =
  12828. instOpts.iconSpacing || $dummyIcon.css("margin-left"),
  12829. iconWidth = instOpts.iconWidth || $dummyIcon.css("width"),
  12830. labelSpacing = instOpts.labelSpacing || "3px",
  12831. levelOfs = instOpts.levelOfs || $dummyUL.css("padding-left");
  12832. $dummyLI.remove();
  12833. iconSpacingUnit = iconSpacing.match(reNumUnit)[2];
  12834. iconSpacing = parseFloat(iconSpacing, 10);
  12835. labelSpacingUnit = labelSpacing.match(reNumUnit)[2];
  12836. labelSpacing = parseFloat(labelSpacing, 10);
  12837. iconWidthUnit = iconWidth.match(reNumUnit)[2];
  12838. iconWidth = parseFloat(iconWidth, 10);
  12839. levelOfsUnit = levelOfs.match(reNumUnit)[2];
  12840. if (
  12841. iconSpacingUnit !== iconWidthUnit ||
  12842. levelOfsUnit !== iconWidthUnit ||
  12843. labelSpacingUnit !== iconWidthUnit
  12844. ) {
  12845. $.error(
  12846. "iconWidth, iconSpacing, and levelOfs must have the same css measure unit"
  12847. );
  12848. }
  12849. this._local.measureUnit = iconWidthUnit;
  12850. this._local.levelOfs = parseFloat(levelOfs);
  12851. this._local.lineOfs =
  12852. (1 +
  12853. (ctx.options.checkbox ? 1 : 0) +
  12854. (ctx.options.icon === false ? 0 : 1)) *
  12855. (iconWidth + iconSpacing) +
  12856. iconSpacing;
  12857. this._local.labelOfs = labelSpacing;
  12858. this._local.maxDepth = 10;
  12859. // Get/Set a unique Id on the container (if not already exists)
  12860. containerId = this.$container.uniqueId().attr("id");
  12861. // Generated css rules for some levels (extended on demand)
  12862. cssText = renderLevelCss(
  12863. containerId,
  12864. this._local.maxDepth,
  12865. this._local.levelOfs,
  12866. this._local.lineOfs,
  12867. this._local.labelOfs,
  12868. this._local.measureUnit
  12869. );
  12870. defineHeadStyleElement(containerId, cssText);
  12871. },
  12872. treeDestroy: function(ctx) {
  12873. // Remove generated css rules
  12874. defineHeadStyleElement(this.$container.attr("id"), null);
  12875. return this._superApply(arguments);
  12876. },
  12877. nodeRenderStatus: function(ctx) {
  12878. var containerId,
  12879. cssText,
  12880. res,
  12881. node = ctx.node,
  12882. level = node.getLevel();
  12883. res = this._super(ctx);
  12884. // Generate some more level-n rules if required
  12885. if (level > this._local.maxDepth) {
  12886. containerId = this.$container.attr("id");
  12887. this._local.maxDepth *= 2;
  12888. node.debug(
  12889. "Define global ext-wide css up to level " +
  12890. this._local.maxDepth
  12891. );
  12892. cssText = renderLevelCss(
  12893. containerId,
  12894. this._local.maxDepth,
  12895. this._local.levelOfs,
  12896. this._local.lineOfs,
  12897. this._local.labelSpacing,
  12898. this._local.measureUnit
  12899. );
  12900. defineHeadStyleElement(containerId, cssText);
  12901. }
  12902. // Add level-n class to apply indentation padding.
  12903. // (Setting element style would not work, since it cannot easily be
  12904. // overriden while animations run)
  12905. $(node.span).addClass("fancytree-level-" + level);
  12906. return res;
  12907. },
  12908. });
  12909. // Value returned by `require('jquery.fancytree..')`
  12910. return $.ui.fancytree;
  12911. }); // End of closure
  12912. // Value returned by `require('jquery.fancytree')`
  12913. return $.ui.fancytree;
  12914. })); // End of closure