jquery.fancytree-all-deps.js 388 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618
  1. /*! jQuery Fancytree Plugin - 2.37.0 - 2020-09-11T18:58:08Z
  2. * https://github.com/mar10/fancytree
  3. * Copyright (c) 2020 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-2020, Martin Wendt (https://wwWendt.de)
  1151. * Released under the MIT license
  1152. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  1153. *
  1154. * @version 2.37.0
  1155. * @date 2020-09-11T18:58:08Z
  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. // consoleApply("assert", [!!cond, msg]);
  1313. $.error("Fancytree assertion failed" + msg);
  1314. }
  1315. }
  1316. _assert($.ui, "Fancytree requires jQuery UI (http://jqueryui.com)");
  1317. function consoleApply(method, args) {
  1318. var i,
  1319. s,
  1320. fn = window.console ? window.console[method] : null;
  1321. if (fn) {
  1322. try {
  1323. fn.apply(window.console, args);
  1324. } catch (e) {
  1325. // IE 8?
  1326. s = "";
  1327. for (i = 0; i < args.length; i++) {
  1328. s += args[i];
  1329. }
  1330. fn(s);
  1331. }
  1332. }
  1333. }
  1334. /* support: IE8 Polyfil for Date.now() */
  1335. if (!Date.now) {
  1336. Date.now = function now() {
  1337. return new Date().getTime();
  1338. };
  1339. }
  1340. /*Return true if x is a FancytreeNode.*/
  1341. function _isNode(x) {
  1342. return !!(x.tree && x.statusNodeType !== undefined);
  1343. }
  1344. /** Return true if dotted version string is equal or higher than requested version.
  1345. *
  1346. * See http://jsfiddle.net/mar10/FjSAN/
  1347. */
  1348. function isVersionAtLeast(dottedVersion, major, minor, patch) {
  1349. var i,
  1350. v,
  1351. t,
  1352. verParts = $.map($.trim(dottedVersion).split("."), function(e) {
  1353. return parseInt(e, 10);
  1354. }),
  1355. testParts = $.map(
  1356. Array.prototype.slice.call(arguments, 1),
  1357. function(e) {
  1358. return parseInt(e, 10);
  1359. }
  1360. );
  1361. for (i = 0; i < testParts.length; i++) {
  1362. v = verParts[i] || 0;
  1363. t = testParts[i] || 0;
  1364. if (v !== t) {
  1365. return v > t;
  1366. }
  1367. }
  1368. return true;
  1369. }
  1370. /**
  1371. * Deep-merge a list of objects (but replace array-type options).
  1372. *
  1373. * jQuery's $.extend(true, ...) method does a deep merge, that also merges Arrays.
  1374. * This variant is used to merge extension defaults with user options, and should
  1375. * merge objects, but override arrays (for example the `triggerStart: [...]` option
  1376. * of ext-edit). Also `null` values are copied over and not skipped.
  1377. *
  1378. * See issue #876
  1379. *
  1380. * Example:
  1381. * _simpleDeepMerge({}, o1, o2);
  1382. */
  1383. function _simpleDeepMerge() {
  1384. var options,
  1385. name,
  1386. src,
  1387. copy,
  1388. clone,
  1389. target = arguments[0] || {},
  1390. i = 1,
  1391. length = arguments.length;
  1392. // Handle case when target is a string or something (possible in deep copy)
  1393. if (typeof target !== "object" && !$.isFunction(target)) {
  1394. target = {};
  1395. }
  1396. if (i === length) {
  1397. throw Error("need at least two args");
  1398. }
  1399. for (; i < length; i++) {
  1400. // Only deal with non-null/undefined values
  1401. if ((options = arguments[i]) != null) {
  1402. // Extend the base object
  1403. for (name in options) {
  1404. if (options.hasOwnProperty(name)) {
  1405. src = target[name];
  1406. copy = options[name];
  1407. // Prevent never-ending loop
  1408. if (target === copy) {
  1409. continue;
  1410. }
  1411. // Recurse if we're merging plain objects
  1412. // (NOTE: unlike $.extend, we don't merge arrays, but replace them)
  1413. if (copy && $.isPlainObject(copy)) {
  1414. clone = src && $.isPlainObject(src) ? src : {};
  1415. // Never move original objects, clone them
  1416. target[name] = _simpleDeepMerge(clone, copy);
  1417. // Don't bring in undefined values
  1418. } else if (copy !== undefined) {
  1419. target[name] = copy;
  1420. }
  1421. }
  1422. }
  1423. }
  1424. }
  1425. // Return the modified object
  1426. return target;
  1427. }
  1428. /** Return a wrapper that calls sub.methodName() and exposes
  1429. * this : tree
  1430. * this._local : tree.ext.EXTNAME
  1431. * this._super : base.methodName.call()
  1432. * this._superApply : base.methodName.apply()
  1433. */
  1434. function _makeVirtualFunction(methodName, tree, base, extension, extName) {
  1435. // $.ui.fancytree.debug("_makeVirtualFunction", methodName, tree, base, extension, extName);
  1436. // if(rexTestSuper && !rexTestSuper.test(func)){
  1437. // // extension.methodName() doesn't call _super(), so no wrapper required
  1438. // return func;
  1439. // }
  1440. // Use an immediate function as closure
  1441. var proxy = (function() {
  1442. var prevFunc = tree[methodName], // org. tree method or prev. proxy
  1443. baseFunc = extension[methodName], //
  1444. _local = tree.ext[extName],
  1445. _super = function() {
  1446. return prevFunc.apply(tree, arguments);
  1447. },
  1448. _superApply = function(args) {
  1449. return prevFunc.apply(tree, args);
  1450. };
  1451. // Return the wrapper function
  1452. return function() {
  1453. var prevLocal = tree._local,
  1454. prevSuper = tree._super,
  1455. prevSuperApply = tree._superApply;
  1456. try {
  1457. tree._local = _local;
  1458. tree._super = _super;
  1459. tree._superApply = _superApply;
  1460. return baseFunc.apply(tree, arguments);
  1461. } finally {
  1462. tree._local = prevLocal;
  1463. tree._super = prevSuper;
  1464. tree._superApply = prevSuperApply;
  1465. }
  1466. };
  1467. })(); // end of Immediate Function
  1468. return proxy;
  1469. }
  1470. /**
  1471. * Subclass `base` by creating proxy functions
  1472. */
  1473. function _subclassObject(tree, base, extension, extName) {
  1474. // $.ui.fancytree.debug("_subclassObject", tree, base, extension, extName);
  1475. for (var attrName in extension) {
  1476. if (typeof extension[attrName] === "function") {
  1477. if (typeof tree[attrName] === "function") {
  1478. // override existing method
  1479. tree[attrName] = _makeVirtualFunction(
  1480. attrName,
  1481. tree,
  1482. base,
  1483. extension,
  1484. extName
  1485. );
  1486. } else if (attrName.charAt(0) === "_") {
  1487. // Create private methods in tree.ext.EXTENSION namespace
  1488. tree.ext[extName][attrName] = _makeVirtualFunction(
  1489. attrName,
  1490. tree,
  1491. base,
  1492. extension,
  1493. extName
  1494. );
  1495. } else {
  1496. $.error(
  1497. "Could not override tree." +
  1498. attrName +
  1499. ". Use prefix '_' to create tree." +
  1500. extName +
  1501. "._" +
  1502. attrName
  1503. );
  1504. }
  1505. } else {
  1506. // Create member variables in tree.ext.EXTENSION namespace
  1507. if (attrName !== "options") {
  1508. tree.ext[extName][attrName] = extension[attrName];
  1509. }
  1510. }
  1511. }
  1512. }
  1513. function _getResolvedPromise(context, argArray) {
  1514. if (context === undefined) {
  1515. return $.Deferred(function() {
  1516. this.resolve();
  1517. }).promise();
  1518. }
  1519. return $.Deferred(function() {
  1520. this.resolveWith(context, argArray);
  1521. }).promise();
  1522. }
  1523. function _getRejectedPromise(context, argArray) {
  1524. if (context === undefined) {
  1525. return $.Deferred(function() {
  1526. this.reject();
  1527. }).promise();
  1528. }
  1529. return $.Deferred(function() {
  1530. this.rejectWith(context, argArray);
  1531. }).promise();
  1532. }
  1533. function _makeResolveFunc(deferred, context) {
  1534. return function() {
  1535. deferred.resolveWith(context);
  1536. };
  1537. }
  1538. function _getElementDataAsDict($el) {
  1539. // Evaluate 'data-NAME' attributes with special treatment for 'data-json'.
  1540. var d = $.extend({}, $el.data()),
  1541. json = d.json;
  1542. delete d.fancytree; // added to container by widget factory (old jQuery UI)
  1543. delete d.uiFancytree; // added to container by widget factory
  1544. if (json) {
  1545. delete d.json;
  1546. // <li data-json='...'> is already returned as object (http://api.jquery.com/data/#data-html5)
  1547. d = $.extend(d, json);
  1548. }
  1549. return d;
  1550. }
  1551. function _escapeTooltip(s) {
  1552. return ("" + s).replace(REX_TOOLTIP, function(s) {
  1553. return ENTITY_MAP[s];
  1554. });
  1555. }
  1556. // TODO: use currying
  1557. function _makeNodeTitleMatcher(s) {
  1558. s = s.toLowerCase();
  1559. return function(node) {
  1560. return node.title.toLowerCase().indexOf(s) >= 0;
  1561. };
  1562. }
  1563. function _makeNodeTitleStartMatcher(s) {
  1564. var reMatch = new RegExp("^" + s, "i");
  1565. return function(node) {
  1566. return reMatch.test(node.title);
  1567. };
  1568. }
  1569. /******************************************************************************
  1570. * FancytreeNode
  1571. */
  1572. /**
  1573. * Creates a new FancytreeNode
  1574. *
  1575. * @class FancytreeNode
  1576. * @classdesc A FancytreeNode represents the hierarchical data model and operations.
  1577. *
  1578. * @param {FancytreeNode} parent
  1579. * @param {NodeData} obj
  1580. *
  1581. * @property {Fancytree} tree The tree instance
  1582. * @property {FancytreeNode} parent The parent node
  1583. * @property {string} key Node id (must be unique inside the tree)
  1584. * @property {string} title Display name (may contain HTML)
  1585. * @property {object} data Contains all extra data that was passed on node creation
  1586. * @property {FancytreeNode[] | null | undefined} children Array of child nodes.<br>
  1587. * For lazy nodes, null or undefined means 'not yet loaded'. Use an empty array
  1588. * to define a node that has no children.
  1589. * @property {boolean} expanded Use isExpanded(), setExpanded() to access this property.
  1590. * @property {string} extraClasses Additional CSS classes, added to the node's `<span>`.<br>
  1591. * Note: use `node.add/remove/toggleClass()` to modify.
  1592. * @property {boolean} folder Folder nodes have different default icons and click behavior.<br>
  1593. * Note: Also non-folders may have children.
  1594. * @property {string} statusNodeType null for standard nodes. Otherwise type of special system node: 'error', 'loading', 'nodata', or 'paging'.
  1595. * @property {boolean} lazy True if this node is loaded on demand, i.e. on first expansion.
  1596. * @property {boolean} selected Use isSelected(), setSelected() to access this property.
  1597. * @property {string} tooltip Alternative description used as hover popup
  1598. * @property {string} iconTooltip Description used as hover popup for icon. @since 2.27
  1599. * @property {string} type Node type, used with tree.types map. @since 2.27
  1600. */
  1601. function FancytreeNode(parent, obj) {
  1602. var i, l, name, cl;
  1603. this.parent = parent;
  1604. this.tree = parent.tree;
  1605. this.ul = null;
  1606. this.li = null; // <li id='key' ftnode=this> tag
  1607. this.statusNodeType = null; // if this is a temp. node to display the status of its parent
  1608. this._isLoading = false; // if this node itself is loading
  1609. this._error = null; // {message: '...'} if a load error occurred
  1610. this.data = {};
  1611. // TODO: merge this code with node.toDict()
  1612. // copy attributes from obj object
  1613. for (i = 0, l = NODE_ATTRS.length; i < l; i++) {
  1614. name = NODE_ATTRS[i];
  1615. this[name] = obj[name];
  1616. }
  1617. // unselectableIgnore and unselectableStatus imply unselectable
  1618. if (
  1619. this.unselectableIgnore != null ||
  1620. this.unselectableStatus != null
  1621. ) {
  1622. this.unselectable = true;
  1623. }
  1624. if (obj.hideCheckbox) {
  1625. $.error(
  1626. "'hideCheckbox' node option was removed in v2.23.0: use 'checkbox: false'"
  1627. );
  1628. }
  1629. // node.data += obj.data
  1630. if (obj.data) {
  1631. $.extend(this.data, obj.data);
  1632. }
  1633. // Copy all other attributes to this.data.NAME
  1634. for (name in obj) {
  1635. if (
  1636. !NODE_ATTR_MAP[name] &&
  1637. (this.tree.options.copyFunctionsToData ||
  1638. !$.isFunction(obj[name])) &&
  1639. !NONE_NODE_DATA_MAP[name]
  1640. ) {
  1641. // node.data.NAME = obj.NAME
  1642. this.data[name] = obj[name];
  1643. }
  1644. }
  1645. // Fix missing key
  1646. if (this.key == null) {
  1647. // test for null OR undefined
  1648. if (this.tree.options.defaultKey) {
  1649. this.key = "" + this.tree.options.defaultKey(this);
  1650. _assert(this.key, "defaultKey() must return a unique key");
  1651. } else {
  1652. this.key = "_" + FT._nextNodeKey++;
  1653. }
  1654. } else {
  1655. this.key = "" + this.key; // Convert to string (#217)
  1656. }
  1657. // Fix tree.activeNode
  1658. // TODO: not elegant: we use obj.active as marker to set tree.activeNode
  1659. // when loading from a dictionary.
  1660. if (obj.active) {
  1661. _assert(
  1662. this.tree.activeNode === null,
  1663. "only one active node allowed"
  1664. );
  1665. this.tree.activeNode = this;
  1666. }
  1667. if (obj.selected) {
  1668. // #186
  1669. this.tree.lastSelectedNode = this;
  1670. }
  1671. // TODO: handle obj.focus = true
  1672. // Create child nodes
  1673. cl = obj.children;
  1674. if (cl) {
  1675. if (cl.length) {
  1676. this._setChildren(cl);
  1677. } else {
  1678. // if an empty array was passed for a lazy node, keep it, in order to mark it 'loaded'
  1679. this.children = this.lazy ? [] : null;
  1680. }
  1681. } else {
  1682. this.children = null;
  1683. }
  1684. // Add to key/ref map (except for root node)
  1685. // if( parent ) {
  1686. this.tree._callHook("treeRegisterNode", this.tree, true, this);
  1687. // }
  1688. }
  1689. FancytreeNode.prototype = /** @lends FancytreeNode# */ {
  1690. /* Return the direct child FancytreeNode with a given key, index. */
  1691. _findDirectChild: function(ptr) {
  1692. var i,
  1693. l,
  1694. cl = this.children;
  1695. if (cl) {
  1696. if (typeof ptr === "string") {
  1697. for (i = 0, l = cl.length; i < l; i++) {
  1698. if (cl[i].key === ptr) {
  1699. return cl[i];
  1700. }
  1701. }
  1702. } else if (typeof ptr === "number") {
  1703. return this.children[ptr];
  1704. } else if (ptr.parent === this) {
  1705. return ptr;
  1706. }
  1707. }
  1708. return null;
  1709. },
  1710. // TODO: activate()
  1711. // TODO: activateSilently()
  1712. /* Internal helper called in recursive addChildren sequence.*/
  1713. _setChildren: function(children) {
  1714. _assert(
  1715. children && (!this.children || this.children.length === 0),
  1716. "only init supported"
  1717. );
  1718. this.children = [];
  1719. for (var i = 0, l = children.length; i < l; i++) {
  1720. this.children.push(new FancytreeNode(this, children[i]));
  1721. }
  1722. this.tree._callHook(
  1723. "treeStructureChanged",
  1724. this.tree,
  1725. "setChildren"
  1726. );
  1727. },
  1728. /**
  1729. * Append (or insert) a list of child nodes.
  1730. *
  1731. * @param {NodeData[]} children array of child node definitions (also single child accepted)
  1732. * @param {FancytreeNode | string | Integer} [insertBefore] child node (or key or index of such).
  1733. * If omitted, the new children are appended.
  1734. * @returns {FancytreeNode} first child added
  1735. *
  1736. * @see FancytreeNode#applyPatch
  1737. */
  1738. addChildren: function(children, insertBefore) {
  1739. var i,
  1740. l,
  1741. pos,
  1742. origFirstChild = this.getFirstChild(),
  1743. origLastChild = this.getLastChild(),
  1744. firstNode = null,
  1745. nodeList = [];
  1746. if ($.isPlainObject(children)) {
  1747. children = [children];
  1748. }
  1749. if (!this.children) {
  1750. this.children = [];
  1751. }
  1752. for (i = 0, l = children.length; i < l; i++) {
  1753. nodeList.push(new FancytreeNode(this, children[i]));
  1754. }
  1755. firstNode = nodeList[0];
  1756. if (insertBefore == null) {
  1757. this.children = this.children.concat(nodeList);
  1758. } else {
  1759. // Returns null if insertBefore is not a direct child:
  1760. insertBefore = this._findDirectChild(insertBefore);
  1761. pos = $.inArray(insertBefore, this.children);
  1762. _assert(pos >= 0, "insertBefore must be an existing child");
  1763. // insert nodeList after children[pos]
  1764. this.children.splice.apply(
  1765. this.children,
  1766. [pos, 0].concat(nodeList)
  1767. );
  1768. }
  1769. if (origFirstChild && !insertBefore) {
  1770. // #708: Fast path -- don't render every child of root, just the new ones!
  1771. // #723, #729: but only if it's appended to an existing child list
  1772. for (i = 0, l = nodeList.length; i < l; i++) {
  1773. nodeList[i].render(); // New nodes were never rendered before
  1774. }
  1775. // Adjust classes where status may have changed
  1776. // Has a first child
  1777. if (origFirstChild !== this.getFirstChild()) {
  1778. // Different first child -- recompute classes
  1779. origFirstChild.renderStatus();
  1780. }
  1781. if (origLastChild !== this.getLastChild()) {
  1782. // Different last child -- recompute classes
  1783. origLastChild.renderStatus();
  1784. }
  1785. } else if (!this.parent || this.parent.ul || this.tr) {
  1786. // render if the parent was rendered (or this is a root node)
  1787. this.render();
  1788. }
  1789. if (this.tree.options.selectMode === 3) {
  1790. this.fixSelection3FromEndNodes();
  1791. }
  1792. this.triggerModifyChild(
  1793. "add",
  1794. nodeList.length === 1 ? nodeList[0] : null
  1795. );
  1796. return firstNode;
  1797. },
  1798. /**
  1799. * Add class to node's span tag and to .extraClasses.
  1800. *
  1801. * @param {string} className class name
  1802. *
  1803. * @since 2.17
  1804. */
  1805. addClass: function(className) {
  1806. return this.toggleClass(className, true);
  1807. },
  1808. /**
  1809. * Append or prepend a node, or append a child node.
  1810. *
  1811. * This a convenience function that calls addChildren()
  1812. *
  1813. * @param {NodeData} node node definition
  1814. * @param {string} [mode=child] 'before', 'after', 'firstChild', or 'child' ('over' is a synonym for 'child')
  1815. * @returns {FancytreeNode} new node
  1816. */
  1817. addNode: function(node, mode) {
  1818. if (mode === undefined || mode === "over") {
  1819. mode = "child";
  1820. }
  1821. switch (mode) {
  1822. case "after":
  1823. return this.getParent().addChildren(
  1824. node,
  1825. this.getNextSibling()
  1826. );
  1827. case "before":
  1828. return this.getParent().addChildren(node, this);
  1829. case "firstChild":
  1830. // Insert before the first child if any
  1831. var insertBefore = this.children ? this.children[0] : null;
  1832. return this.addChildren(node, insertBefore);
  1833. case "child":
  1834. case "over":
  1835. return this.addChildren(node);
  1836. }
  1837. _assert(false, "Invalid mode: " + mode);
  1838. },
  1839. /**Add child status nodes that indicate 'More...', etc.
  1840. *
  1841. * This also maintains the node's `partload` property.
  1842. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  1843. * @param {string} [mode='child'] 'child'|firstChild'
  1844. * @since 2.15
  1845. */
  1846. addPagingNode: function(node, mode) {
  1847. var i, n;
  1848. mode = mode || "child";
  1849. if (node === false) {
  1850. for (i = this.children.length - 1; i >= 0; i--) {
  1851. n = this.children[i];
  1852. if (n.statusNodeType === "paging") {
  1853. this.removeChild(n);
  1854. }
  1855. }
  1856. this.partload = false;
  1857. return;
  1858. }
  1859. node = $.extend(
  1860. {
  1861. title: this.tree.options.strings.moreData,
  1862. statusNodeType: "paging",
  1863. icon: false,
  1864. },
  1865. node
  1866. );
  1867. this.partload = true;
  1868. return this.addNode(node, mode);
  1869. },
  1870. /**
  1871. * Append new node after this.
  1872. *
  1873. * This a convenience function that calls addNode(node, 'after')
  1874. *
  1875. * @param {NodeData} node node definition
  1876. * @returns {FancytreeNode} new node
  1877. */
  1878. appendSibling: function(node) {
  1879. return this.addNode(node, "after");
  1880. },
  1881. /**
  1882. * (experimental) Apply a modification (or navigation) operation.
  1883. *
  1884. * @param {string} cmd
  1885. * @param {object} [opts]
  1886. * @see Fancytree#applyCommand
  1887. * @since 2.32
  1888. */
  1889. applyCommand: function(cmd, opts) {
  1890. return this.tree.applyCommand(cmd, this, opts);
  1891. },
  1892. /**
  1893. * Modify existing child nodes.
  1894. *
  1895. * @param {NodePatch} patch
  1896. * @returns {$.Promise}
  1897. * @see FancytreeNode#addChildren
  1898. */
  1899. applyPatch: function(patch) {
  1900. // patch [key, null] means 'remove'
  1901. if (patch === null) {
  1902. this.remove();
  1903. return _getResolvedPromise(this);
  1904. }
  1905. // TODO: make sure that root node is not collapsed or modified
  1906. // copy (most) attributes to node.ATTR or node.data.ATTR
  1907. var name,
  1908. promise,
  1909. v,
  1910. IGNORE_MAP = { children: true, expanded: true, parent: true }; // TODO: should be global
  1911. for (name in patch) {
  1912. if (patch.hasOwnProperty(name)) {
  1913. v = patch[name];
  1914. if (!IGNORE_MAP[name] && !$.isFunction(v)) {
  1915. if (NODE_ATTR_MAP[name]) {
  1916. this[name] = v;
  1917. } else {
  1918. this.data[name] = v;
  1919. }
  1920. }
  1921. }
  1922. }
  1923. // Remove and/or create children
  1924. if (patch.hasOwnProperty("children")) {
  1925. this.removeChildren();
  1926. if (patch.children) {
  1927. // only if not null and not empty list
  1928. // TODO: addChildren instead?
  1929. this._setChildren(patch.children);
  1930. }
  1931. // TODO: how can we APPEND or INSERT child nodes?
  1932. }
  1933. if (this.isVisible()) {
  1934. this.renderTitle();
  1935. this.renderStatus();
  1936. }
  1937. // Expand collapse (final step, since this may be async)
  1938. if (patch.hasOwnProperty("expanded")) {
  1939. promise = this.setExpanded(patch.expanded);
  1940. } else {
  1941. promise = _getResolvedPromise(this);
  1942. }
  1943. return promise;
  1944. },
  1945. /** Collapse all sibling nodes.
  1946. * @returns {$.Promise}
  1947. */
  1948. collapseSiblings: function() {
  1949. return this.tree._callHook("nodeCollapseSiblings", this);
  1950. },
  1951. /** Copy this node as sibling or child of `node`.
  1952. *
  1953. * @param {FancytreeNode} node source node
  1954. * @param {string} [mode=child] 'before' | 'after' | 'child'
  1955. * @param {Function} [map] callback function(NodeData, FancytreeNode) that could modify the new node
  1956. * @returns {FancytreeNode} new
  1957. */
  1958. copyTo: function(node, mode, map) {
  1959. return node.addNode(this.toDict(true, map), mode);
  1960. },
  1961. /** Count direct and indirect children.
  1962. *
  1963. * @param {boolean} [deep=true] pass 'false' to only count direct children
  1964. * @returns {int} number of child nodes
  1965. */
  1966. countChildren: function(deep) {
  1967. var cl = this.children,
  1968. i,
  1969. l,
  1970. n;
  1971. if (!cl) {
  1972. return 0;
  1973. }
  1974. n = cl.length;
  1975. if (deep !== false) {
  1976. for (i = 0, l = n; i < l; i++) {
  1977. n += cl[i].countChildren();
  1978. }
  1979. }
  1980. return n;
  1981. },
  1982. // TODO: deactivate()
  1983. /** Write to browser console if debugLevel >= 4 (prepending node info)
  1984. *
  1985. * @param {*} msg string or object or array of such
  1986. */
  1987. debug: function(msg) {
  1988. if (this.tree.options.debugLevel >= 4) {
  1989. Array.prototype.unshift.call(arguments, this.toString());
  1990. consoleApply("log", arguments);
  1991. }
  1992. },
  1993. /** Deprecated.
  1994. * @deprecated since 2014-02-16. Use resetLazy() instead.
  1995. */
  1996. discard: function() {
  1997. this.warn(
  1998. "FancytreeNode.discard() is deprecated since 2014-02-16. Use .resetLazy() instead."
  1999. );
  2000. return this.resetLazy();
  2001. },
  2002. /** Remove DOM elements for all descendents. May be called on .collapse event
  2003. * to keep the DOM small.
  2004. * @param {boolean} [includeSelf=false]
  2005. */
  2006. discardMarkup: function(includeSelf) {
  2007. var fn = includeSelf ? "nodeRemoveMarkup" : "nodeRemoveChildMarkup";
  2008. this.tree._callHook(fn, this);
  2009. },
  2010. /** Write error to browser console if debugLevel >= 1 (prepending tree info)
  2011. *
  2012. * @param {*} msg string or object or array of such
  2013. */
  2014. error: function(msg) {
  2015. if (this.tree.options.debugLevel >= 1) {
  2016. Array.prototype.unshift.call(arguments, this.toString());
  2017. consoleApply("error", arguments);
  2018. }
  2019. },
  2020. /**Find all nodes that match condition (excluding self).
  2021. *
  2022. * @param {string | function(node)} match title string to search for, or a
  2023. * callback function that returns `true` if a node is matched.
  2024. * @returns {FancytreeNode[]} array of nodes (may be empty)
  2025. */
  2026. findAll: function(match) {
  2027. match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
  2028. var res = [];
  2029. this.visit(function(n) {
  2030. if (match(n)) {
  2031. res.push(n);
  2032. }
  2033. });
  2034. return res;
  2035. },
  2036. /**Find first node that matches condition (excluding self).
  2037. *
  2038. * @param {string | function(node)} match title string to search for, or a
  2039. * callback function that returns `true` if a node is matched.
  2040. * @returns {FancytreeNode} matching node or null
  2041. * @see FancytreeNode#findAll
  2042. */
  2043. findFirst: function(match) {
  2044. match = $.isFunction(match) ? match : _makeNodeTitleMatcher(match);
  2045. var res = null;
  2046. this.visit(function(n) {
  2047. if (match(n)) {
  2048. res = n;
  2049. return false;
  2050. }
  2051. });
  2052. return res;
  2053. },
  2054. /** Find a node relative to self.
  2055. *
  2056. * @param {number|string} where The keyCode that would normally trigger this move,
  2057. * or a keyword ('down', 'first', 'last', 'left', 'parent', 'right', 'up').
  2058. * @returns {FancytreeNode}
  2059. * @since v2.31
  2060. */
  2061. findRelatedNode: function(where, includeHidden) {
  2062. return this.tree.findRelatedNode(this, where, includeHidden);
  2063. },
  2064. /* Apply selection state (internal use only) */
  2065. _changeSelectStatusAttrs: function(state) {
  2066. var changed = false,
  2067. opts = this.tree.options,
  2068. unselectable = FT.evalOption(
  2069. "unselectable",
  2070. this,
  2071. this,
  2072. opts,
  2073. false
  2074. ),
  2075. unselectableStatus = FT.evalOption(
  2076. "unselectableStatus",
  2077. this,
  2078. this,
  2079. opts,
  2080. undefined
  2081. );
  2082. if (unselectable && unselectableStatus != null) {
  2083. state = unselectableStatus;
  2084. }
  2085. switch (state) {
  2086. case false:
  2087. changed = this.selected || this.partsel;
  2088. this.selected = false;
  2089. this.partsel = false;
  2090. break;
  2091. case true:
  2092. changed = !this.selected || !this.partsel;
  2093. this.selected = true;
  2094. this.partsel = true;
  2095. break;
  2096. case undefined:
  2097. changed = this.selected || !this.partsel;
  2098. this.selected = false;
  2099. this.partsel = true;
  2100. break;
  2101. default:
  2102. _assert(false, "invalid state: " + state);
  2103. }
  2104. // this.debug("fixSelection3AfterLoad() _changeSelectStatusAttrs()", state, changed);
  2105. if (changed) {
  2106. this.renderStatus();
  2107. }
  2108. return changed;
  2109. },
  2110. /**
  2111. * Fix selection status, after this node was (de)selected in multi-hier mode.
  2112. * This includes (de)selecting all children.
  2113. */
  2114. fixSelection3AfterClick: function(callOpts) {
  2115. var flag = this.isSelected();
  2116. // this.debug("fixSelection3AfterClick()");
  2117. this.visit(function(node) {
  2118. node._changeSelectStatusAttrs(flag);
  2119. if (node.radiogroup) {
  2120. // #931: don't (de)select this branch
  2121. return "skip";
  2122. }
  2123. });
  2124. this.fixSelection3FromEndNodes(callOpts);
  2125. },
  2126. /**
  2127. * Fix selection status for multi-hier mode.
  2128. * Only end-nodes are considered to update the descendants branch and parents.
  2129. * Should be called after this node has loaded new children or after
  2130. * children have been modified using the API.
  2131. */
  2132. fixSelection3FromEndNodes: function(callOpts) {
  2133. var opts = this.tree.options;
  2134. // this.debug("fixSelection3FromEndNodes()");
  2135. _assert(opts.selectMode === 3, "expected selectMode 3");
  2136. // Visit all end nodes and adjust their parent's `selected` and `partsel`
  2137. // attributes. Return selection state true, false, or undefined.
  2138. function _walk(node) {
  2139. var i,
  2140. l,
  2141. child,
  2142. s,
  2143. state,
  2144. allSelected,
  2145. someSelected,
  2146. unselIgnore,
  2147. unselState,
  2148. children = node.children;
  2149. if (children && children.length) {
  2150. // check all children recursively
  2151. allSelected = true;
  2152. someSelected = false;
  2153. for (i = 0, l = children.length; i < l; i++) {
  2154. child = children[i];
  2155. // the selection state of a node is not relevant; we need the end-nodes
  2156. s = _walk(child);
  2157. // if( !child.unselectableIgnore ) {
  2158. unselIgnore = FT.evalOption(
  2159. "unselectableIgnore",
  2160. child,
  2161. child,
  2162. opts,
  2163. false
  2164. );
  2165. if (!unselIgnore) {
  2166. if (s !== false) {
  2167. someSelected = true;
  2168. }
  2169. if (s !== true) {
  2170. allSelected = false;
  2171. }
  2172. }
  2173. }
  2174. // eslint-disable-next-line no-nested-ternary
  2175. state = allSelected
  2176. ? true
  2177. : someSelected
  2178. ? undefined
  2179. : false;
  2180. } else {
  2181. // This is an end-node: simply report the status
  2182. unselState = FT.evalOption(
  2183. "unselectableStatus",
  2184. node,
  2185. node,
  2186. opts,
  2187. undefined
  2188. );
  2189. state = unselState == null ? !!node.selected : !!unselState;
  2190. }
  2191. // #939: Keep a `partsel` flag that was explicitly set on a lazy node
  2192. if (
  2193. node.partsel &&
  2194. !node.selected &&
  2195. node.lazy &&
  2196. node.children == null
  2197. ) {
  2198. state = undefined;
  2199. }
  2200. node._changeSelectStatusAttrs(state);
  2201. return state;
  2202. }
  2203. _walk(this);
  2204. // Update parent's state
  2205. this.visitParents(function(node) {
  2206. var i,
  2207. l,
  2208. child,
  2209. state,
  2210. unselIgnore,
  2211. unselState,
  2212. children = node.children,
  2213. allSelected = true,
  2214. someSelected = false;
  2215. for (i = 0, l = children.length; i < l; i++) {
  2216. child = children[i];
  2217. unselIgnore = FT.evalOption(
  2218. "unselectableIgnore",
  2219. child,
  2220. child,
  2221. opts,
  2222. false
  2223. );
  2224. if (!unselIgnore) {
  2225. unselState = FT.evalOption(
  2226. "unselectableStatus",
  2227. child,
  2228. child,
  2229. opts,
  2230. undefined
  2231. );
  2232. state =
  2233. unselState == null
  2234. ? !!child.selected
  2235. : !!unselState;
  2236. // When fixing the parents, we trust the sibling status (i.e.
  2237. // we don't recurse)
  2238. if (state || child.partsel) {
  2239. someSelected = true;
  2240. }
  2241. if (!state) {
  2242. allSelected = false;
  2243. }
  2244. }
  2245. }
  2246. // eslint-disable-next-line no-nested-ternary
  2247. state = allSelected ? true : someSelected ? undefined : false;
  2248. node._changeSelectStatusAttrs(state);
  2249. });
  2250. },
  2251. // TODO: focus()
  2252. /**
  2253. * Update node data. If dict contains 'children', then also replace
  2254. * the hole sub tree.
  2255. * @param {NodeData} dict
  2256. *
  2257. * @see FancytreeNode#addChildren
  2258. * @see FancytreeNode#applyPatch
  2259. */
  2260. fromDict: function(dict) {
  2261. // copy all other attributes to this.data.xxx
  2262. for (var name in dict) {
  2263. if (NODE_ATTR_MAP[name]) {
  2264. // node.NAME = dict.NAME
  2265. this[name] = dict[name];
  2266. } else if (name === "data") {
  2267. // node.data += dict.data
  2268. $.extend(this.data, dict.data);
  2269. } else if (
  2270. !$.isFunction(dict[name]) &&
  2271. !NONE_NODE_DATA_MAP[name]
  2272. ) {
  2273. // node.data.NAME = dict.NAME
  2274. this.data[name] = dict[name];
  2275. }
  2276. }
  2277. if (dict.children) {
  2278. // recursively set children and render
  2279. this.removeChildren();
  2280. this.addChildren(dict.children);
  2281. }
  2282. this.renderTitle();
  2283. /*
  2284. var children = dict.children;
  2285. if(children === undefined){
  2286. this.data = $.extend(this.data, dict);
  2287. this.render();
  2288. return;
  2289. }
  2290. dict = $.extend({}, dict);
  2291. dict.children = undefined;
  2292. this.data = $.extend(this.data, dict);
  2293. this.removeChildren();
  2294. this.addChild(children);
  2295. */
  2296. },
  2297. /** Return the list of child nodes (undefined for unexpanded lazy nodes).
  2298. * @returns {FancytreeNode[] | undefined}
  2299. */
  2300. getChildren: function() {
  2301. if (this.hasChildren() === undefined) {
  2302. // TODO: only required for lazy nodes?
  2303. return undefined; // Lazy node: unloaded, currently loading, or load error
  2304. }
  2305. return this.children;
  2306. },
  2307. /** Return the first child node or null.
  2308. * @returns {FancytreeNode | null}
  2309. */
  2310. getFirstChild: function() {
  2311. return this.children ? this.children[0] : null;
  2312. },
  2313. /** Return the 0-based child index.
  2314. * @returns {int}
  2315. */
  2316. getIndex: function() {
  2317. // return this.parent.children.indexOf(this);
  2318. return $.inArray(this, this.parent.children); // indexOf doesn't work in IE7
  2319. },
  2320. /** Return the hierarchical child index (1-based, e.g. '3.2.4').
  2321. * @param {string} [separator="."]
  2322. * @param {int} [digits=1]
  2323. * @returns {string}
  2324. */
  2325. getIndexHier: function(separator, digits) {
  2326. separator = separator || ".";
  2327. var s,
  2328. res = [];
  2329. $.each(this.getParentList(false, true), function(i, o) {
  2330. s = "" + (o.getIndex() + 1);
  2331. if (digits) {
  2332. // prepend leading zeroes
  2333. s = ("0000000" + s).substr(-digits);
  2334. }
  2335. res.push(s);
  2336. });
  2337. return res.join(separator);
  2338. },
  2339. /** Return the parent keys separated by options.keyPathSeparator, e.g. "/id_1/id_17/id_32".
  2340. *
  2341. * (Unlike `node.getPath()`, this method prepends a "/" and inverts the first argument.)
  2342. *
  2343. * @see FancytreeNode#getPath
  2344. * @param {boolean} [excludeSelf=false]
  2345. * @returns {string}
  2346. */
  2347. getKeyPath: function(excludeSelf) {
  2348. var sep = this.tree.options.keyPathSeparator;
  2349. return sep + this.getPath(!excludeSelf, "key", sep);
  2350. },
  2351. /** Return the last child of this node or null.
  2352. * @returns {FancytreeNode | null}
  2353. */
  2354. getLastChild: function() {
  2355. return this.children
  2356. ? this.children[this.children.length - 1]
  2357. : null;
  2358. },
  2359. /** Return node depth. 0: System root node, 1: visible top-level node, 2: first sub-level, ... .
  2360. * @returns {int}
  2361. */
  2362. getLevel: function() {
  2363. var level = 0,
  2364. dtn = this.parent;
  2365. while (dtn) {
  2366. level++;
  2367. dtn = dtn.parent;
  2368. }
  2369. return level;
  2370. },
  2371. /** Return the successor node (under the same parent) or null.
  2372. * @returns {FancytreeNode | null}
  2373. */
  2374. getNextSibling: function() {
  2375. // TODO: use indexOf, if available: (not in IE6)
  2376. if (this.parent) {
  2377. var i,
  2378. l,
  2379. ac = this.parent.children;
  2380. for (i = 0, l = ac.length - 1; i < l; i++) {
  2381. // up to length-2, so next(last) = null
  2382. if (ac[i] === this) {
  2383. return ac[i + 1];
  2384. }
  2385. }
  2386. }
  2387. return null;
  2388. },
  2389. /** Return the parent node (null for the system root node).
  2390. * @returns {FancytreeNode | null}
  2391. */
  2392. getParent: function() {
  2393. // TODO: return null for top-level nodes?
  2394. return this.parent;
  2395. },
  2396. /** Return an array of all parent nodes (top-down).
  2397. * @param {boolean} [includeRoot=false] Include the invisible system root node.
  2398. * @param {boolean} [includeSelf=false] Include the node itself.
  2399. * @returns {FancytreeNode[]}
  2400. */
  2401. getParentList: function(includeRoot, includeSelf) {
  2402. var l = [],
  2403. dtn = includeSelf ? this : this.parent;
  2404. while (dtn) {
  2405. if (includeRoot || dtn.parent) {
  2406. l.unshift(dtn);
  2407. }
  2408. dtn = dtn.parent;
  2409. }
  2410. return l;
  2411. },
  2412. /** Return a string representing the hierachical node path, e.g. "a/b/c".
  2413. * @param {boolean} [includeSelf=true]
  2414. * @param {string | function} [part="title"] node property name or callback
  2415. * @param {string} [separator="/"]
  2416. * @returns {string}
  2417. * @since v2.31
  2418. */
  2419. getPath: function(includeSelf, part, separator) {
  2420. includeSelf = includeSelf !== false;
  2421. part = part || "title";
  2422. separator = separator || "/";
  2423. var val,
  2424. path = [],
  2425. isFunc = $.isFunction(part);
  2426. this.visitParents(function(n) {
  2427. if (n.parent) {
  2428. val = isFunc ? part(n) : n[part];
  2429. path.unshift(val);
  2430. }
  2431. }, includeSelf);
  2432. return path.join(separator);
  2433. },
  2434. /** Return the predecessor node (under the same parent) or null.
  2435. * @returns {FancytreeNode | null}
  2436. */
  2437. getPrevSibling: function() {
  2438. if (this.parent) {
  2439. var i,
  2440. l,
  2441. ac = this.parent.children;
  2442. for (i = 1, l = ac.length; i < l; i++) {
  2443. // start with 1, so prev(first) = null
  2444. if (ac[i] === this) {
  2445. return ac[i - 1];
  2446. }
  2447. }
  2448. }
  2449. return null;
  2450. },
  2451. /**
  2452. * Return an array of selected descendant nodes.
  2453. * @param {boolean} [stopOnParents=false] only return the topmost selected
  2454. * node (useful with selectMode 3)
  2455. * @returns {FancytreeNode[]}
  2456. */
  2457. getSelectedNodes: function(stopOnParents) {
  2458. var nodeList = [];
  2459. this.visit(function(node) {
  2460. if (node.selected) {
  2461. nodeList.push(node);
  2462. if (stopOnParents === true) {
  2463. return "skip"; // stop processing this branch
  2464. }
  2465. }
  2466. });
  2467. return nodeList;
  2468. },
  2469. /** Return true if node has children. Return undefined if not sure, i.e. the node is lazy and not yet loaded).
  2470. * @returns {boolean | undefined}
  2471. */
  2472. hasChildren: function() {
  2473. if (this.lazy) {
  2474. if (this.children == null) {
  2475. // null or undefined: Not yet loaded
  2476. return undefined;
  2477. } else if (this.children.length === 0) {
  2478. // Loaded, but response was empty
  2479. return false;
  2480. } else if (
  2481. this.children.length === 1 &&
  2482. this.children[0].isStatusNode()
  2483. ) {
  2484. // Currently loading or load error
  2485. return undefined;
  2486. }
  2487. return true;
  2488. }
  2489. return !!(this.children && this.children.length);
  2490. },
  2491. /**
  2492. * Return true if node has `className` defined in .extraClasses.
  2493. *
  2494. * @param {string} className class name (separate multiple classes by space)
  2495. * @returns {boolean}
  2496. *
  2497. * @since 2.32
  2498. */
  2499. hasClass: function(className) {
  2500. return (
  2501. (" " + (this.extraClasses || "") + " ").indexOf(
  2502. " " + className + " "
  2503. ) >= 0
  2504. );
  2505. },
  2506. /** Return true if node has keyboard focus.
  2507. * @returns {boolean}
  2508. */
  2509. hasFocus: function() {
  2510. return this.tree.hasFocus() && this.tree.focusNode === this;
  2511. },
  2512. /** Write to browser console if debugLevel >= 3 (prepending node info)
  2513. *
  2514. * @param {*} msg string or object or array of such
  2515. */
  2516. info: function(msg) {
  2517. if (this.tree.options.debugLevel >= 3) {
  2518. Array.prototype.unshift.call(arguments, this.toString());
  2519. consoleApply("info", arguments);
  2520. }
  2521. },
  2522. /** Return true if node is active (see also FancytreeNode#isSelected).
  2523. * @returns {boolean}
  2524. */
  2525. isActive: function() {
  2526. return this.tree.activeNode === this;
  2527. },
  2528. /** Return true if node is vertically below `otherNode`, i.e. rendered in a subsequent row.
  2529. * @param {FancytreeNode} otherNode
  2530. * @returns {boolean}
  2531. * @since 2.28
  2532. */
  2533. isBelowOf: function(otherNode) {
  2534. return this.getIndexHier(".", 5) > otherNode.getIndexHier(".", 5);
  2535. },
  2536. /** Return true if node is a direct child of otherNode.
  2537. * @param {FancytreeNode} otherNode
  2538. * @returns {boolean}
  2539. */
  2540. isChildOf: function(otherNode) {
  2541. return this.parent && this.parent === otherNode;
  2542. },
  2543. /** Return true, if node is a direct or indirect sub node of otherNode.
  2544. * @param {FancytreeNode} otherNode
  2545. * @returns {boolean}
  2546. */
  2547. isDescendantOf: function(otherNode) {
  2548. if (!otherNode || otherNode.tree !== this.tree) {
  2549. return false;
  2550. }
  2551. var p = this.parent;
  2552. while (p) {
  2553. if (p === otherNode) {
  2554. return true;
  2555. }
  2556. if (p === p.parent) {
  2557. $.error("Recursive parent link: " + p);
  2558. }
  2559. p = p.parent;
  2560. }
  2561. return false;
  2562. },
  2563. /** Return true if node is expanded.
  2564. * @returns {boolean}
  2565. */
  2566. isExpanded: function() {
  2567. return !!this.expanded;
  2568. },
  2569. /** Return true if node is the first node of its parent's children.
  2570. * @returns {boolean}
  2571. */
  2572. isFirstSibling: function() {
  2573. var p = this.parent;
  2574. return !p || p.children[0] === this;
  2575. },
  2576. /** Return true if node is a folder, i.e. has the node.folder attribute set.
  2577. * @returns {boolean}
  2578. */
  2579. isFolder: function() {
  2580. return !!this.folder;
  2581. },
  2582. /** Return true if node is the last node of its parent's children.
  2583. * @returns {boolean}
  2584. */
  2585. isLastSibling: function() {
  2586. var p = this.parent;
  2587. return !p || p.children[p.children.length - 1] === this;
  2588. },
  2589. /** Return true if node is lazy (even if data was already loaded)
  2590. * @returns {boolean}
  2591. */
  2592. isLazy: function() {
  2593. return !!this.lazy;
  2594. },
  2595. /** Return true if node is lazy and loaded. For non-lazy nodes always return true.
  2596. * @returns {boolean}
  2597. */
  2598. isLoaded: function() {
  2599. return !this.lazy || this.hasChildren() !== undefined; // Also checks if the only child is a status node
  2600. },
  2601. /** Return true if children are currently beeing loaded, i.e. a Ajax request is pending.
  2602. * @returns {boolean}
  2603. */
  2604. isLoading: function() {
  2605. return !!this._isLoading;
  2606. },
  2607. /*
  2608. * @deprecated since v2.4.0: Use isRootNode() instead
  2609. */
  2610. isRoot: function() {
  2611. return this.isRootNode();
  2612. },
  2613. /** Return true if node is partially selected (tri-state).
  2614. * @returns {boolean}
  2615. * @since 2.23
  2616. */
  2617. isPartsel: function() {
  2618. return !this.selected && !!this.partsel;
  2619. },
  2620. /** (experimental) Return true if this is partially loaded.
  2621. * @returns {boolean}
  2622. * @since 2.15
  2623. */
  2624. isPartload: function() {
  2625. return !!this.partload;
  2626. },
  2627. /** Return true if this is the (invisible) system root node.
  2628. * @returns {boolean}
  2629. * @since 2.4
  2630. */
  2631. isRootNode: function() {
  2632. return this.tree.rootNode === this;
  2633. },
  2634. /** Return true if node is selected, i.e. has a checkmark set (see also FancytreeNode#isActive).
  2635. * @returns {boolean}
  2636. */
  2637. isSelected: function() {
  2638. return !!this.selected;
  2639. },
  2640. /** Return true if this node is a temporarily generated system node like
  2641. * 'loading', 'paging', or 'error' (node.statusNodeType contains the type).
  2642. * @returns {boolean}
  2643. */
  2644. isStatusNode: function() {
  2645. return !!this.statusNodeType;
  2646. },
  2647. /** Return true if this node is a status node of type 'paging'.
  2648. * @returns {boolean}
  2649. * @since 2.15
  2650. */
  2651. isPagingNode: function() {
  2652. return this.statusNodeType === "paging";
  2653. },
  2654. /** Return true if this a top level node, i.e. a direct child of the (invisible) system root node.
  2655. * @returns {boolean}
  2656. * @since 2.4
  2657. */
  2658. isTopLevel: function() {
  2659. return this.tree.rootNode === this.parent;
  2660. },
  2661. /** Return true if node is lazy and not yet loaded. For non-lazy nodes always return false.
  2662. * @returns {boolean}
  2663. */
  2664. isUndefined: function() {
  2665. return this.hasChildren() === undefined; // also checks if the only child is a status node
  2666. },
  2667. /** Return true if all parent nodes are expanded. Note: this does not check
  2668. * whether the node is scrolled into the visible part of the screen.
  2669. * @returns {boolean}
  2670. */
  2671. isVisible: function() {
  2672. var i,
  2673. l,
  2674. n,
  2675. hasFilter = this.tree.enableFilter,
  2676. parents = this.getParentList(false, false);
  2677. // TODO: check $(n.span).is(":visible")
  2678. // i.e. return false for nodes (but not parents) that are hidden
  2679. // by a filter
  2680. if (hasFilter && !this.match && !this.subMatchCount) {
  2681. // this.debug( "isVisible: HIDDEN (" + hasFilter + ", " + this.match + ", " + this.match + ")" );
  2682. return false;
  2683. }
  2684. for (i = 0, l = parents.length; i < l; i++) {
  2685. n = parents[i];
  2686. if (!n.expanded) {
  2687. // this.debug("isVisible: HIDDEN (parent collapsed)");
  2688. return false;
  2689. }
  2690. // if (hasFilter && !n.match && !n.subMatchCount) {
  2691. // this.debug("isVisible: HIDDEN (" + hasFilter + ", " + this.match + ", " + this.match + ")");
  2692. // return false;
  2693. // }
  2694. }
  2695. // this.debug("isVisible: VISIBLE");
  2696. return true;
  2697. },
  2698. /** Deprecated.
  2699. * @deprecated since 2014-02-16: use load() instead.
  2700. */
  2701. lazyLoad: function(discard) {
  2702. $.error(
  2703. "FancytreeNode.lazyLoad() is deprecated since 2014-02-16. Use .load() instead."
  2704. );
  2705. },
  2706. /**
  2707. * Load all children of a lazy node if neccessary. The <i>expanded</i> state is maintained.
  2708. * @param {boolean} [forceReload=false] Pass true to discard any existing nodes before. Otherwise this method does nothing if the node was already loaded.
  2709. * @returns {$.Promise}
  2710. */
  2711. load: function(forceReload) {
  2712. var res,
  2713. source,
  2714. self = this,
  2715. wasExpanded = this.isExpanded();
  2716. _assert(this.isLazy(), "load() requires a lazy node");
  2717. // _assert( forceReload || this.isUndefined(), "Pass forceReload=true to re-load a lazy node" );
  2718. if (!forceReload && !this.isUndefined()) {
  2719. return _getResolvedPromise(this);
  2720. }
  2721. if (this.isLoaded()) {
  2722. this.resetLazy(); // also collapses
  2723. }
  2724. // This method is also called by setExpanded() and loadKeyPath(), so we
  2725. // have to avoid recursion.
  2726. source = this.tree._triggerNodeEvent("lazyLoad", this);
  2727. if (source === false) {
  2728. // #69
  2729. return _getResolvedPromise(this);
  2730. }
  2731. _assert(
  2732. typeof source !== "boolean",
  2733. "lazyLoad event must return source in data.result"
  2734. );
  2735. res = this.tree._callHook("nodeLoadChildren", this, source);
  2736. if (wasExpanded) {
  2737. this.expanded = true;
  2738. res.always(function() {
  2739. self.render();
  2740. });
  2741. } else {
  2742. res.always(function() {
  2743. self.renderStatus(); // fix expander icon to 'loaded'
  2744. });
  2745. }
  2746. return res;
  2747. },
  2748. /** Expand all parents and optionally scroll into visible area as neccessary.
  2749. * Promise is resolved, when lazy loading and animations are done.
  2750. * @param {object} [opts] passed to `setExpanded()`.
  2751. * Defaults to {noAnimation: false, noEvents: false, scrollIntoView: true}
  2752. * @returns {$.Promise}
  2753. */
  2754. makeVisible: function(opts) {
  2755. var i,
  2756. self = this,
  2757. deferreds = [],
  2758. dfd = new $.Deferred(),
  2759. parents = this.getParentList(false, false),
  2760. len = parents.length,
  2761. effects = !(opts && opts.noAnimation === true),
  2762. scroll = !(opts && opts.scrollIntoView === false);
  2763. // Expand bottom-up, so only the top node is animated
  2764. for (i = len - 1; i >= 0; i--) {
  2765. // self.debug("pushexpand" + parents[i]);
  2766. deferreds.push(parents[i].setExpanded(true, opts));
  2767. }
  2768. $.when.apply($, deferreds).done(function() {
  2769. // All expands have finished
  2770. // self.debug("expand DONE", scroll);
  2771. if (scroll) {
  2772. self.scrollIntoView(effects).done(function() {
  2773. // self.debug("scroll DONE");
  2774. dfd.resolve();
  2775. });
  2776. } else {
  2777. dfd.resolve();
  2778. }
  2779. });
  2780. return dfd.promise();
  2781. },
  2782. /** Move this node to targetNode.
  2783. * @param {FancytreeNode} targetNode
  2784. * @param {string} mode <pre>
  2785. * 'child': append this node as last child of targetNode.
  2786. * This is the default. To be compatble with the D'n'd
  2787. * hitMode, we also accept 'over'.
  2788. * 'firstChild': add this node as first child of targetNode.
  2789. * 'before': add this node as sibling before targetNode.
  2790. * 'after': add this node as sibling after targetNode.</pre>
  2791. * @param {function} [map] optional callback(FancytreeNode) to allow modifcations
  2792. */
  2793. moveTo: function(targetNode, mode, map) {
  2794. if (mode === undefined || mode === "over") {
  2795. mode = "child";
  2796. } else if (mode === "firstChild") {
  2797. if (targetNode.children && targetNode.children.length) {
  2798. mode = "before";
  2799. targetNode = targetNode.children[0];
  2800. } else {
  2801. mode = "child";
  2802. }
  2803. }
  2804. var pos,
  2805. tree = this.tree,
  2806. prevParent = this.parent,
  2807. targetParent =
  2808. mode === "child" ? targetNode : targetNode.parent;
  2809. if (this === targetNode) {
  2810. return;
  2811. } else if (!this.parent) {
  2812. $.error("Cannot move system root");
  2813. } else if (targetParent.isDescendantOf(this)) {
  2814. $.error("Cannot move a node to its own descendant");
  2815. }
  2816. if (targetParent !== prevParent) {
  2817. prevParent.triggerModifyChild("remove", this);
  2818. }
  2819. // Unlink this node from current parent
  2820. if (this.parent.children.length === 1) {
  2821. if (this.parent === targetParent) {
  2822. return; // #258
  2823. }
  2824. this.parent.children = this.parent.lazy ? [] : null;
  2825. this.parent.expanded = false;
  2826. } else {
  2827. pos = $.inArray(this, this.parent.children);
  2828. _assert(pos >= 0, "invalid source parent");
  2829. this.parent.children.splice(pos, 1);
  2830. }
  2831. // Remove from source DOM parent
  2832. // if(this.parent.ul){
  2833. // this.parent.ul.removeChild(this.li);
  2834. // }
  2835. // Insert this node to target parent's child list
  2836. this.parent = targetParent;
  2837. if (targetParent.hasChildren()) {
  2838. switch (mode) {
  2839. case "child":
  2840. // Append to existing target children
  2841. targetParent.children.push(this);
  2842. break;
  2843. case "before":
  2844. // Insert this node before target node
  2845. pos = $.inArray(targetNode, targetParent.children);
  2846. _assert(pos >= 0, "invalid target parent");
  2847. targetParent.children.splice(pos, 0, this);
  2848. break;
  2849. case "after":
  2850. // Insert this node after target node
  2851. pos = $.inArray(targetNode, targetParent.children);
  2852. _assert(pos >= 0, "invalid target parent");
  2853. targetParent.children.splice(pos + 1, 0, this);
  2854. break;
  2855. default:
  2856. $.error("Invalid mode " + mode);
  2857. }
  2858. } else {
  2859. targetParent.children = [this];
  2860. }
  2861. // Parent has no <ul> tag yet:
  2862. // if( !targetParent.ul ) {
  2863. // // This is the parent's first child: create UL tag
  2864. // // (Hidden, because it will be
  2865. // targetParent.ul = document.createElement("ul");
  2866. // targetParent.ul.style.display = "none";
  2867. // targetParent.li.appendChild(targetParent.ul);
  2868. // }
  2869. // // Issue 319: Add to target DOM parent (only if node was already rendered(expanded))
  2870. // if(this.li){
  2871. // targetParent.ul.appendChild(this.li);
  2872. // }
  2873. // Let caller modify the nodes
  2874. if (map) {
  2875. targetNode.visit(map, true);
  2876. }
  2877. if (targetParent === prevParent) {
  2878. targetParent.triggerModifyChild("move", this);
  2879. } else {
  2880. // prevParent.triggerModifyChild("remove", this);
  2881. targetParent.triggerModifyChild("add", this);
  2882. }
  2883. // Handle cross-tree moves
  2884. if (tree !== targetNode.tree) {
  2885. // Fix node.tree for all source nodes
  2886. // _assert(false, "Cross-tree move is not yet implemented.");
  2887. this.warn("Cross-tree moveTo is experimental!");
  2888. this.visit(function(n) {
  2889. // TODO: fix selection state and activation, ...
  2890. n.tree = targetNode.tree;
  2891. }, true);
  2892. }
  2893. // A collaposed node won't re-render children, so we have to remove it manually
  2894. // if( !targetParent.expanded ){
  2895. // prevParent.ul.removeChild(this.li);
  2896. // }
  2897. tree._callHook("treeStructureChanged", tree, "moveTo");
  2898. // Update HTML markup
  2899. if (!prevParent.isDescendantOf(targetParent)) {
  2900. prevParent.render();
  2901. }
  2902. if (
  2903. !targetParent.isDescendantOf(prevParent) &&
  2904. targetParent !== prevParent
  2905. ) {
  2906. targetParent.render();
  2907. }
  2908. // TODO: fix selection state
  2909. // TODO: fix active state
  2910. /*
  2911. var tree = this.tree;
  2912. var opts = tree.options;
  2913. var pers = tree.persistence;
  2914. // Always expand, if it's below minExpandLevel
  2915. // tree.logDebug ("%s._addChildNode(%o), l=%o", this, ftnode, ftnode.getLevel());
  2916. if ( opts.minExpandLevel >= ftnode.getLevel() ) {
  2917. // tree.logDebug ("Force expand for %o", ftnode);
  2918. this.bExpanded = true;
  2919. }
  2920. // In multi-hier mode, update the parents selection state
  2921. // DT issue #82: only if not initializing, because the children may not exist yet
  2922. // if( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing )
  2923. // ftnode._fixSelectionState();
  2924. // In multi-hier mode, update the parents selection state
  2925. if( ftnode.bSelected && opts.selectMode==3 ) {
  2926. var p = this;
  2927. while( p ) {
  2928. if( !p.hasSubSel )
  2929. p._setSubSel(true);
  2930. p = p.parent;
  2931. }
  2932. }
  2933. // render this node and the new child
  2934. if ( tree.bEnableUpdate )
  2935. this.render();
  2936. return ftnode;
  2937. */
  2938. },
  2939. /** Set focus relative to this node and optionally activate.
  2940. *
  2941. * 'left' collapses the node if it is expanded, or move to the parent
  2942. * otherwise.
  2943. * 'right' expands the node if it is collapsed, or move to the first
  2944. * child otherwise.
  2945. *
  2946. * @param {string|number} where 'down', 'first', 'last', 'left', 'parent', 'right', or 'up'.
  2947. * (Alternatively the keyCode that would normally trigger this move,
  2948. * e.g. `$.ui.keyCode.LEFT` = 'left'.
  2949. * @param {boolean} [activate=true]
  2950. * @returns {$.Promise}
  2951. */
  2952. navigate: function(where, activate) {
  2953. var node,
  2954. KC = $.ui.keyCode;
  2955. // Handle optional expand/collapse action for LEFT/RIGHT
  2956. switch (where) {
  2957. case "left":
  2958. case KC.LEFT:
  2959. if (this.expanded) {
  2960. return this.setExpanded(false);
  2961. }
  2962. break;
  2963. case "right":
  2964. case KC.RIGHT:
  2965. if (!this.expanded && (this.children || this.lazy)) {
  2966. return this.setExpanded();
  2967. }
  2968. break;
  2969. }
  2970. // Otherwise activate or focus the related node
  2971. node = this.findRelatedNode(where);
  2972. if (node) {
  2973. // setFocus/setActive will scroll later (if autoScroll is specified)
  2974. try {
  2975. node.makeVisible({ scrollIntoView: false });
  2976. } catch (e) {} // #272
  2977. if (activate === false) {
  2978. node.setFocus();
  2979. return _getResolvedPromise();
  2980. }
  2981. return node.setActive();
  2982. }
  2983. this.warn("Could not find related node '" + where + "'.");
  2984. return _getResolvedPromise();
  2985. },
  2986. /**
  2987. * Remove this node (not allowed for system root).
  2988. */
  2989. remove: function() {
  2990. return this.parent.removeChild(this);
  2991. },
  2992. /**
  2993. * Remove childNode from list of direct children.
  2994. * @param {FancytreeNode} childNode
  2995. */
  2996. removeChild: function(childNode) {
  2997. return this.tree._callHook("nodeRemoveChild", this, childNode);
  2998. },
  2999. /**
  3000. * Remove all child nodes and descendents. This converts the node into a leaf.<br>
  3001. * If this was a lazy node, it is still considered 'loaded'; call node.resetLazy()
  3002. * in order to trigger lazyLoad on next expand.
  3003. */
  3004. removeChildren: function() {
  3005. return this.tree._callHook("nodeRemoveChildren", this);
  3006. },
  3007. /**
  3008. * Remove class from node's span tag and .extraClasses.
  3009. *
  3010. * @param {string} className class name
  3011. *
  3012. * @since 2.17
  3013. */
  3014. removeClass: function(className) {
  3015. return this.toggleClass(className, false);
  3016. },
  3017. /**
  3018. * This method renders and updates all HTML markup that is required
  3019. * to display this node in its current state.<br>
  3020. * Note:
  3021. * <ul>
  3022. * <li>It should only be neccessary to call this method after the node object
  3023. * was modified by direct access to its properties, because the common
  3024. * API methods (node.setTitle(), moveTo(), addChildren(), remove(), ...)
  3025. * already handle this.
  3026. * <li> {@link FancytreeNode#renderTitle} and {@link FancytreeNode#renderStatus}
  3027. * are implied. If changes are more local, calling only renderTitle() or
  3028. * renderStatus() may be sufficient and faster.
  3029. * </ul>
  3030. *
  3031. * @param {boolean} [force=false] re-render, even if html markup was already created
  3032. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  3033. */
  3034. render: function(force, deep) {
  3035. return this.tree._callHook("nodeRender", this, force, deep);
  3036. },
  3037. /** Create HTML markup for the node's outer `<span>` (expander, checkbox, icon, and title).
  3038. * Implies {@link FancytreeNode#renderStatus}.
  3039. * @see Fancytree_Hooks#nodeRenderTitle
  3040. */
  3041. renderTitle: function() {
  3042. return this.tree._callHook("nodeRenderTitle", this);
  3043. },
  3044. /** Update element's CSS classes according to node state.
  3045. * @see Fancytree_Hooks#nodeRenderStatus
  3046. */
  3047. renderStatus: function() {
  3048. return this.tree._callHook("nodeRenderStatus", this);
  3049. },
  3050. /**
  3051. * (experimental) Replace this node with `source`.
  3052. * (Currently only available for paging nodes.)
  3053. * @param {NodeData[]} source List of child node definitions
  3054. * @since 2.15
  3055. */
  3056. replaceWith: function(source) {
  3057. var res,
  3058. parent = this.parent,
  3059. pos = $.inArray(this, parent.children),
  3060. self = this;
  3061. _assert(
  3062. this.isPagingNode(),
  3063. "replaceWith() currently requires a paging status node"
  3064. );
  3065. res = this.tree._callHook("nodeLoadChildren", this, source);
  3066. res.done(function(data) {
  3067. // New nodes are currently children of `this`.
  3068. var children = self.children;
  3069. // Prepend newly loaded child nodes to `this`
  3070. // Move new children after self
  3071. for (i = 0; i < children.length; i++) {
  3072. children[i].parent = parent;
  3073. }
  3074. parent.children.splice.apply(
  3075. parent.children,
  3076. [pos + 1, 0].concat(children)
  3077. );
  3078. // Remove self
  3079. self.children = null;
  3080. self.remove();
  3081. // Redraw new nodes
  3082. parent.render();
  3083. // TODO: set node.partload = false if this was tha last paging node?
  3084. // parent.addPagingNode(false);
  3085. }).fail(function() {
  3086. self.setExpanded();
  3087. });
  3088. return res;
  3089. // $.error("Not implemented: replaceWith()");
  3090. },
  3091. /**
  3092. * Remove all children, collapse, and set the lazy-flag, so that the lazyLoad
  3093. * event is triggered on next expand.
  3094. */
  3095. resetLazy: function() {
  3096. this.removeChildren();
  3097. this.expanded = false;
  3098. this.lazy = true;
  3099. this.children = undefined;
  3100. this.renderStatus();
  3101. },
  3102. /** Schedule activity for delayed execution (cancel any pending request).
  3103. * scheduleAction('cancel') will only cancel a pending request (if any).
  3104. * @param {string} mode
  3105. * @param {number} ms
  3106. */
  3107. scheduleAction: function(mode, ms) {
  3108. if (this.tree.timer) {
  3109. clearTimeout(this.tree.timer);
  3110. this.tree.debug("clearTimeout(%o)", this.tree.timer);
  3111. }
  3112. this.tree.timer = null;
  3113. var self = this; // required for closures
  3114. switch (mode) {
  3115. case "cancel":
  3116. // Simply made sure that timer was cleared
  3117. break;
  3118. case "expand":
  3119. this.tree.timer = setTimeout(function() {
  3120. self.tree.debug("setTimeout: trigger expand");
  3121. self.setExpanded(true);
  3122. }, ms);
  3123. break;
  3124. case "activate":
  3125. this.tree.timer = setTimeout(function() {
  3126. self.tree.debug("setTimeout: trigger activate");
  3127. self.setActive(true);
  3128. }, ms);
  3129. break;
  3130. default:
  3131. $.error("Invalid mode " + mode);
  3132. }
  3133. // this.tree.debug("setTimeout(%s, %s): %s", mode, ms, this.tree.timer);
  3134. },
  3135. /**
  3136. *
  3137. * @param {boolean | PlainObject} [effects=false] animation options.
  3138. * @param {object} [options=null] {topNode: null, effects: ..., parent: ...} this node will remain visible in
  3139. * any case, even if `this` is outside the scroll pane.
  3140. * @returns {$.Promise}
  3141. */
  3142. scrollIntoView: function(effects, options) {
  3143. if (options !== undefined && _isNode(options)) {
  3144. throw Error(
  3145. "scrollIntoView() with 'topNode' option is deprecated since 2014-05-08. Use 'options.topNode' instead."
  3146. );
  3147. }
  3148. // The scroll parent is typically the plain tree's <UL> container.
  3149. // For ext-table, we choose the nearest parent that has `position: relative`
  3150. // and `overflow` set.
  3151. // (This default can be overridden by the local or global `scrollParent` option.)
  3152. var opts = $.extend(
  3153. {
  3154. effects:
  3155. effects === true
  3156. ? { duration: 200, queue: false }
  3157. : effects,
  3158. scrollOfs: this.tree.options.scrollOfs,
  3159. scrollParent: this.tree.options.scrollParent,
  3160. topNode: null,
  3161. },
  3162. options
  3163. ),
  3164. $scrollParent = opts.scrollParent,
  3165. $container = this.tree.$container,
  3166. overflowY = $container.css("overflow-y");
  3167. if (!$scrollParent) {
  3168. if (this.tree.tbody) {
  3169. $scrollParent = $container.scrollParent();
  3170. } else if (overflowY === "scroll" || overflowY === "auto") {
  3171. $scrollParent = $container;
  3172. } else {
  3173. // #922 plain tree in a non-fixed-sized UL scrolls inside its parent
  3174. $scrollParent = $container.scrollParent();
  3175. }
  3176. } else if (!$scrollParent.jquery) {
  3177. // Make sure we have a jQuery object
  3178. $scrollParent = $($scrollParent);
  3179. }
  3180. if (
  3181. $scrollParent[0] === document ||
  3182. $scrollParent[0] === document.body
  3183. ) {
  3184. // `document` may be returned by $().scrollParent(), if nothing is found,
  3185. // but would not work: (see #894)
  3186. this.debug(
  3187. "scrollIntoView(): normalizing scrollParent to 'window':",
  3188. $scrollParent[0]
  3189. );
  3190. $scrollParent = $(window);
  3191. }
  3192. // eslint-disable-next-line one-var
  3193. var topNodeY,
  3194. nodeY,
  3195. horzScrollbarHeight,
  3196. containerOffsetTop,
  3197. dfd = new $.Deferred(),
  3198. self = this,
  3199. nodeHeight = $(this.span).height(),
  3200. topOfs = opts.scrollOfs.top || 0,
  3201. bottomOfs = opts.scrollOfs.bottom || 0,
  3202. containerHeight = $scrollParent.height(),
  3203. scrollTop = $scrollParent.scrollTop(),
  3204. $animateTarget = $scrollParent,
  3205. isParentWindow = $scrollParent[0] === window,
  3206. topNode = opts.topNode || null,
  3207. newScrollTop = null;
  3208. // this.debug("scrollIntoView(), scrollTop=" + scrollTop, opts.scrollOfs);
  3209. // _assert($(this.span).is(":visible"), "scrollIntoView node is invisible"); // otherwise we cannot calc offsets
  3210. if (this.isRootNode() || !this.isVisible()) {
  3211. // We cannot calc offsets for hidden elements
  3212. this.info("scrollIntoView(): node is invisible.");
  3213. return _getResolvedPromise();
  3214. }
  3215. if (isParentWindow) {
  3216. nodeY = $(this.span).offset().top;
  3217. topNodeY =
  3218. topNode && topNode.span ? $(topNode.span).offset().top : 0;
  3219. $animateTarget = $("html,body");
  3220. } else {
  3221. _assert(
  3222. $scrollParent[0] !== document &&
  3223. $scrollParent[0] !== document.body,
  3224. "scrollParent should be a simple element or `window`, not document or body."
  3225. );
  3226. containerOffsetTop = $scrollParent.offset().top;
  3227. nodeY =
  3228. $(this.span).offset().top - containerOffsetTop + scrollTop; // relative to scroll parent
  3229. topNodeY = topNode
  3230. ? $(topNode.span).offset().top -
  3231. containerOffsetTop +
  3232. scrollTop
  3233. : 0;
  3234. horzScrollbarHeight = Math.max(
  3235. 0,
  3236. $scrollParent.innerHeight() - $scrollParent[0].clientHeight
  3237. );
  3238. containerHeight -= horzScrollbarHeight;
  3239. }
  3240. // this.debug(" scrollIntoView(), nodeY=" + nodeY + ", containerHeight=" + containerHeight);
  3241. if (nodeY < scrollTop + topOfs) {
  3242. // Node is above visible container area
  3243. newScrollTop = nodeY - topOfs;
  3244. // this.debug(" scrollIntoView(), UPPER newScrollTop=" + newScrollTop);
  3245. } else if (
  3246. nodeY + nodeHeight >
  3247. scrollTop + containerHeight - bottomOfs
  3248. ) {
  3249. newScrollTop = nodeY + nodeHeight - containerHeight + bottomOfs;
  3250. // this.debug(" scrollIntoView(), LOWER newScrollTop=" + newScrollTop);
  3251. // If a topNode was passed, make sure that it is never scrolled
  3252. // outside the upper border
  3253. if (topNode) {
  3254. _assert(
  3255. topNode.isRootNode() || topNode.isVisible(),
  3256. "topNode must be visible"
  3257. );
  3258. if (topNodeY < newScrollTop) {
  3259. newScrollTop = topNodeY - topOfs;
  3260. // this.debug(" scrollIntoView(), TOP newScrollTop=" + newScrollTop);
  3261. }
  3262. }
  3263. }
  3264. if (newScrollTop === null) {
  3265. dfd.resolveWith(this);
  3266. } else {
  3267. // this.debug(" scrollIntoView(), SET newScrollTop=" + newScrollTop);
  3268. if (opts.effects) {
  3269. opts.effects.complete = function() {
  3270. dfd.resolveWith(self);
  3271. };
  3272. $animateTarget.stop(true).animate(
  3273. {
  3274. scrollTop: newScrollTop,
  3275. },
  3276. opts.effects
  3277. );
  3278. } else {
  3279. $animateTarget[0].scrollTop = newScrollTop;
  3280. dfd.resolveWith(this);
  3281. }
  3282. }
  3283. return dfd.promise();
  3284. },
  3285. /**Activate this node.
  3286. *
  3287. * The `cell` option requires the ext-table and ext-ariagrid extensions.
  3288. *
  3289. * @param {boolean} [flag=true] pass false to deactivate
  3290. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false, cell: null}
  3291. * @returns {$.Promise}
  3292. */
  3293. setActive: function(flag, opts) {
  3294. return this.tree._callHook("nodeSetActive", this, flag, opts);
  3295. },
  3296. /**Expand or collapse this node. Promise is resolved, when lazy loading and animations are done.
  3297. * @param {boolean} [flag=true] pass false to collapse
  3298. * @param {object} [opts] additional options. Defaults to {noAnimation: false, noEvents: false}
  3299. * @returns {$.Promise}
  3300. */
  3301. setExpanded: function(flag, opts) {
  3302. return this.tree._callHook("nodeSetExpanded", this, flag, opts);
  3303. },
  3304. /**Set keyboard focus to this node.
  3305. * @param {boolean} [flag=true] pass false to blur
  3306. * @see Fancytree#setFocus
  3307. */
  3308. setFocus: function(flag) {
  3309. return this.tree._callHook("nodeSetFocus", this, flag);
  3310. },
  3311. /**Select this node, i.e. check the checkbox.
  3312. * @param {boolean} [flag=true] pass false to deselect
  3313. * @param {object} [opts] additional options. Defaults to {noEvents: false, p
  3314. * propagateDown: null, propagateUp: null, callback: null }
  3315. */
  3316. setSelected: function(flag, opts) {
  3317. return this.tree._callHook("nodeSetSelected", this, flag, opts);
  3318. },
  3319. /**Mark a lazy node as 'error', 'loading', 'nodata', or 'ok'.
  3320. * @param {string} status 'error'|'loading'|'nodata'|'ok'
  3321. * @param {string} [message]
  3322. * @param {string} [details]
  3323. */
  3324. setStatus: function(status, message, details) {
  3325. return this.tree._callHook(
  3326. "nodeSetStatus",
  3327. this,
  3328. status,
  3329. message,
  3330. details
  3331. );
  3332. },
  3333. /**Rename this node.
  3334. * @param {string} title
  3335. */
  3336. setTitle: function(title) {
  3337. this.title = title;
  3338. this.renderTitle();
  3339. this.triggerModify("rename");
  3340. },
  3341. /**Sort child list by title.
  3342. * @param {function} [cmp] custom compare function(a, b) that returns -1, 0, or 1 (defaults to sort by title).
  3343. * @param {boolean} [deep=false] pass true to sort all descendant nodes
  3344. */
  3345. sortChildren: function(cmp, deep) {
  3346. var i,
  3347. l,
  3348. cl = this.children;
  3349. if (!cl) {
  3350. return;
  3351. }
  3352. cmp =
  3353. cmp ||
  3354. function(a, b) {
  3355. var x = a.title.toLowerCase(),
  3356. y = b.title.toLowerCase();
  3357. // eslint-disable-next-line no-nested-ternary
  3358. return x === y ? 0 : x > y ? 1 : -1;
  3359. };
  3360. cl.sort(cmp);
  3361. if (deep) {
  3362. for (i = 0, l = cl.length; i < l; i++) {
  3363. if (cl[i].children) {
  3364. cl[i].sortChildren(cmp, "$norender$");
  3365. }
  3366. }
  3367. }
  3368. if (deep !== "$norender$") {
  3369. this.render();
  3370. }
  3371. this.triggerModifyChild("sort");
  3372. },
  3373. /** Convert node (or whole branch) into a plain object.
  3374. *
  3375. * The result is compatible with node.addChildren().
  3376. *
  3377. * @param {boolean} [recursive=false] include child nodes
  3378. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications.
  3379. * Return `false` to ignore this node or `"skip"` to include this node without its children.
  3380. * @returns {NodeData}
  3381. */
  3382. toDict: function(recursive, callback) {
  3383. var i,
  3384. l,
  3385. node,
  3386. res,
  3387. dict = {},
  3388. self = this;
  3389. $.each(NODE_ATTRS, function(i, a) {
  3390. if (self[a] || self[a] === false) {
  3391. dict[a] = self[a];
  3392. }
  3393. });
  3394. if (!$.isEmptyObject(this.data)) {
  3395. dict.data = $.extend({}, this.data);
  3396. if ($.isEmptyObject(dict.data)) {
  3397. delete dict.data;
  3398. }
  3399. }
  3400. if (callback) {
  3401. res = callback(dict, self);
  3402. if (res === false) {
  3403. return false; // Don't include this node nor its children
  3404. }
  3405. if (res === "skip") {
  3406. recursive = false; // Include this node, but not the children
  3407. }
  3408. }
  3409. if (recursive) {
  3410. if ($.isArray(this.children)) {
  3411. dict.children = [];
  3412. for (i = 0, l = this.children.length; i < l; i++) {
  3413. node = this.children[i];
  3414. if (!node.isStatusNode()) {
  3415. res = node.toDict(true, callback);
  3416. if (res !== false) {
  3417. dict.children.push(res);
  3418. }
  3419. }
  3420. }
  3421. }
  3422. }
  3423. return dict;
  3424. },
  3425. /**
  3426. * Set, clear, or toggle class of node's span tag and .extraClasses.
  3427. *
  3428. * @param {string} className class name (separate multiple classes by space)
  3429. * @param {boolean} [flag] true/false to add/remove class. If omitted, class is toggled.
  3430. * @returns {boolean} true if a class was added
  3431. *
  3432. * @since 2.17
  3433. */
  3434. toggleClass: function(value, flag) {
  3435. var className,
  3436. hasClass,
  3437. rnotwhite = /\S+/g,
  3438. classNames = value.match(rnotwhite) || [],
  3439. i = 0,
  3440. wasAdded = false,
  3441. statusElem = this[this.tree.statusClassPropName],
  3442. curClasses = " " + (this.extraClasses || "") + " ";
  3443. // this.info("toggleClass('" + value + "', " + flag + ")", curClasses);
  3444. // Modify DOM element directly if it already exists
  3445. if (statusElem) {
  3446. $(statusElem).toggleClass(value, flag);
  3447. }
  3448. // Modify node.extraClasses to make this change persistent
  3449. // Toggle if flag was not passed
  3450. while ((className = classNames[i++])) {
  3451. hasClass = curClasses.indexOf(" " + className + " ") >= 0;
  3452. flag = flag === undefined ? !hasClass : !!flag;
  3453. if (flag) {
  3454. if (!hasClass) {
  3455. curClasses += className + " ";
  3456. wasAdded = true;
  3457. }
  3458. } else {
  3459. while (curClasses.indexOf(" " + className + " ") > -1) {
  3460. curClasses = curClasses.replace(
  3461. " " + className + " ",
  3462. " "
  3463. );
  3464. }
  3465. }
  3466. }
  3467. this.extraClasses = $.trim(curClasses);
  3468. // this.info("-> toggleClass('" + value + "', " + flag + "): '" + this.extraClasses + "'");
  3469. return wasAdded;
  3470. },
  3471. /** Flip expanded status. */
  3472. toggleExpanded: function() {
  3473. return this.tree._callHook("nodeToggleExpanded", this);
  3474. },
  3475. /** Flip selection status. */
  3476. toggleSelected: function() {
  3477. return this.tree._callHook("nodeToggleSelected", this);
  3478. },
  3479. toString: function() {
  3480. return "FancytreeNode@" + this.key + "[title='" + this.title + "']";
  3481. // return "<FancytreeNode(#" + this.key + ", '" + this.title + "')>";
  3482. },
  3483. /**
  3484. * Trigger `modifyChild` event on a parent to signal that a child was modified.
  3485. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  3486. * @param {FancytreeNode} [childNode]
  3487. * @param {object} [extra]
  3488. */
  3489. triggerModifyChild: function(operation, childNode, extra) {
  3490. var data,
  3491. modifyChild = this.tree.options.modifyChild;
  3492. if (modifyChild) {
  3493. if (childNode && childNode.parent !== this) {
  3494. $.error(
  3495. "childNode " + childNode + " is not a child of " + this
  3496. );
  3497. }
  3498. data = {
  3499. node: this,
  3500. tree: this.tree,
  3501. operation: operation,
  3502. childNode: childNode || null,
  3503. };
  3504. if (extra) {
  3505. $.extend(data, extra);
  3506. }
  3507. modifyChild({ type: "modifyChild" }, data);
  3508. }
  3509. },
  3510. /**
  3511. * Trigger `modifyChild` event on node.parent(!).
  3512. * @param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
  3513. * @param {object} [extra]
  3514. */
  3515. triggerModify: function(operation, extra) {
  3516. this.parent.triggerModifyChild(operation, this, extra);
  3517. },
  3518. /** Call fn(node) for all child nodes in hierarchical order (depth-first).<br>
  3519. * Stop iteration, if fn() returns false. Skip current branch, if fn() returns "skip".<br>
  3520. * Return false if iteration was stopped.
  3521. *
  3522. * @param {function} fn the callback function.
  3523. * Return false to stop iteration, return "skip" to skip this node and
  3524. * its children only.
  3525. * @param {boolean} [includeSelf=false]
  3526. * @returns {boolean}
  3527. */
  3528. visit: function(fn, includeSelf) {
  3529. var i,
  3530. l,
  3531. res = true,
  3532. children = this.children;
  3533. if (includeSelf === true) {
  3534. res = fn(this);
  3535. if (res === false || res === "skip") {
  3536. return res;
  3537. }
  3538. }
  3539. if (children) {
  3540. for (i = 0, l = children.length; i < l; i++) {
  3541. res = children[i].visit(fn, true);
  3542. if (res === false) {
  3543. break;
  3544. }
  3545. }
  3546. }
  3547. return res;
  3548. },
  3549. /** Call fn(node) for all child nodes and recursively load lazy children.<br>
  3550. * <b>Note:</b> If you need this method, you probably should consider to review
  3551. * your architecture! Recursivley loading nodes is a perfect way for lazy
  3552. * programmers to flood the server with requests ;-)
  3553. *
  3554. * @param {function} [fn] optional callback function.
  3555. * Return false to stop iteration, return "skip" to skip this node and
  3556. * its children only.
  3557. * @param {boolean} [includeSelf=false]
  3558. * @returns {$.Promise}
  3559. * @since 2.4
  3560. */
  3561. visitAndLoad: function(fn, includeSelf, _recursion) {
  3562. var dfd,
  3563. res,
  3564. loaders,
  3565. node = this;
  3566. // node.debug("visitAndLoad");
  3567. if (fn && includeSelf === true) {
  3568. res = fn(node);
  3569. if (res === false || res === "skip") {
  3570. return _recursion ? res : _getResolvedPromise();
  3571. }
  3572. }
  3573. if (!node.children && !node.lazy) {
  3574. return _getResolvedPromise();
  3575. }
  3576. dfd = new $.Deferred();
  3577. loaders = [];
  3578. // node.debug("load()...");
  3579. node.load().done(function() {
  3580. // node.debug("load()... done.");
  3581. for (var i = 0, l = node.children.length; i < l; i++) {
  3582. res = node.children[i].visitAndLoad(fn, true, true);
  3583. if (res === false) {
  3584. dfd.reject();
  3585. break;
  3586. } else if (res !== "skip") {
  3587. loaders.push(res); // Add promise to the list
  3588. }
  3589. }
  3590. $.when.apply(this, loaders).then(function() {
  3591. dfd.resolve();
  3592. });
  3593. });
  3594. return dfd.promise();
  3595. },
  3596. /** Call fn(node) for all parent nodes, bottom-up, including invisible system root.<br>
  3597. * Stop iteration, if fn() returns false.<br>
  3598. * Return false if iteration was stopped.
  3599. *
  3600. * @param {function} fn the callback function.
  3601. * Return false to stop iteration, return "skip" to skip this node and children only.
  3602. * @param {boolean} [includeSelf=false]
  3603. * @returns {boolean}
  3604. */
  3605. visitParents: function(fn, includeSelf) {
  3606. // Visit parent nodes (bottom up)
  3607. if (includeSelf && fn(this) === false) {
  3608. return false;
  3609. }
  3610. var p = this.parent;
  3611. while (p) {
  3612. if (fn(p) === false) {
  3613. return false;
  3614. }
  3615. p = p.parent;
  3616. }
  3617. return true;
  3618. },
  3619. /** Call fn(node) for all sibling nodes.<br>
  3620. * Stop iteration, if fn() returns false.<br>
  3621. * Return false if iteration was stopped.
  3622. *
  3623. * @param {function} fn the callback function.
  3624. * Return false to stop iteration.
  3625. * @param {boolean} [includeSelf=false]
  3626. * @returns {boolean}
  3627. */
  3628. visitSiblings: function(fn, includeSelf) {
  3629. var i,
  3630. l,
  3631. n,
  3632. ac = this.parent.children;
  3633. for (i = 0, l = ac.length; i < l; i++) {
  3634. n = ac[i];
  3635. if (includeSelf || n !== this) {
  3636. if (fn(n) === false) {
  3637. return false;
  3638. }
  3639. }
  3640. }
  3641. return true;
  3642. },
  3643. /** Write warning to browser console if debugLevel >= 2 (prepending node info)
  3644. *
  3645. * @param {*} msg string or object or array of such
  3646. */
  3647. warn: function(msg) {
  3648. if (this.tree.options.debugLevel >= 2) {
  3649. Array.prototype.unshift.call(arguments, this.toString());
  3650. consoleApply("warn", arguments);
  3651. }
  3652. },
  3653. };
  3654. /******************************************************************************
  3655. * Fancytree
  3656. */
  3657. /**
  3658. * Construct a new tree object.
  3659. *
  3660. * @class Fancytree
  3661. * @classdesc The controller behind a fancytree.
  3662. * This class also contains 'hook methods': see {@link Fancytree_Hooks}.
  3663. *
  3664. * @param {Widget} widget
  3665. *
  3666. * @property {string} _id Automatically generated unique tree instance ID, e.g. "1".
  3667. * @property {string} _ns Automatically generated unique tree namespace, e.g. ".fancytree-1".
  3668. * @property {FancytreeNode} activeNode Currently active node or null.
  3669. * @property {string} ariaPropName Property name of FancytreeNode that contains the element which will receive the aria attributes.
  3670. * Typically "li", but "tr" for table extension.
  3671. * @property {jQueryObject} $container Outer `<ul>` element (or `<table>` element for ext-table).
  3672. * @property {jQueryObject} $div A jQuery object containing the element used to instantiate the tree widget (`widget.element`)
  3673. * @property {object|array} columns Recommended place to store shared column meta data. @since 2.27
  3674. * @property {object} data Metadata, i.e. properties that may be passed to `source` in addition to a children array.
  3675. * @property {object} ext Hash of all active plugin instances.
  3676. * @property {FancytreeNode} focusNode Currently focused node or null.
  3677. * @property {FancytreeNode} lastSelectedNode Used to implement selectMode 1 (single select)
  3678. * @property {string} nodeContainerAttrName Property name of FancytreeNode that contains the outer element of single nodes.
  3679. * Typically "li", but "tr" for table extension.
  3680. * @property {FancytreeOptions} options Current options, i.e. default options + options passed to constructor.
  3681. * @property {FancytreeNode} rootNode Invisible system root node.
  3682. * @property {string} statusClassPropName Property name of FancytreeNode that contains the element which will receive the status classes.
  3683. * Typically "span", but "tr" for table extension.
  3684. * @property {object} types Map for shared type specific meta data, used with node.type attribute. @since 2.27
  3685. * @property {object} viewport See ext-vieport. @since v2.31
  3686. * @property {object} widget Base widget instance.
  3687. */
  3688. function Fancytree(widget) {
  3689. this.widget = widget;
  3690. this.$div = widget.element;
  3691. this.options = widget.options;
  3692. if (this.options) {
  3693. if (this.options.lazyload !== undefined) {
  3694. $.error(
  3695. "The 'lazyload' event is deprecated since 2014-02-25. Use 'lazyLoad' (with uppercase L) instead."
  3696. );
  3697. }
  3698. if (this.options.loaderror !== undefined) {
  3699. $.error(
  3700. "The 'loaderror' event was renamed since 2014-07-03. Use 'loadError' (with uppercase E) instead."
  3701. );
  3702. }
  3703. if (this.options.fx !== undefined) {
  3704. $.error(
  3705. "The 'fx' option was replaced by 'toggleEffect' since 2014-11-30."
  3706. );
  3707. }
  3708. if (this.options.removeNode !== undefined) {
  3709. $.error(
  3710. "The 'removeNode' event was replaced by 'modifyChild' since 2.20 (2016-09-10)."
  3711. );
  3712. }
  3713. }
  3714. this.ext = {}; // Active extension instances
  3715. this.types = {};
  3716. this.columns = {};
  3717. // allow to init tree.data.foo from <div data-foo=''>
  3718. this.data = _getElementDataAsDict(this.$div);
  3719. // TODO: use widget.uuid instead?
  3720. this._id = "" + (this.options.treeId || $.ui.fancytree._nextId++);
  3721. // TODO: use widget.eventNamespace instead?
  3722. this._ns = ".fancytree-" + this._id; // append for namespaced events
  3723. this.activeNode = null;
  3724. this.focusNode = null;
  3725. this._hasFocus = null;
  3726. this._tempCache = {};
  3727. this._lastMousedownNode = null;
  3728. this._enableUpdate = true;
  3729. this.lastSelectedNode = null;
  3730. this.systemFocusElement = null;
  3731. this.lastQuicksearchTerm = "";
  3732. this.lastQuicksearchTime = 0;
  3733. this.viewport = null; // ext-grid
  3734. this.statusClassPropName = "span";
  3735. this.ariaPropName = "li";
  3736. this.nodeContainerAttrName = "li";
  3737. // Remove previous markup if any
  3738. this.$div.find(">ul.fancytree-container").remove();
  3739. // Create a node without parent.
  3740. var fakeParent = { tree: this },
  3741. $ul;
  3742. this.rootNode = new FancytreeNode(fakeParent, {
  3743. title: "root",
  3744. key: "root_" + this._id,
  3745. children: null,
  3746. expanded: true,
  3747. });
  3748. this.rootNode.parent = null;
  3749. // Create root markup
  3750. $ul = $("<ul>", {
  3751. id: "ft-id-" + this._id,
  3752. class: "ui-fancytree fancytree-container fancytree-plain",
  3753. }).appendTo(this.$div);
  3754. this.$container = $ul;
  3755. this.rootNode.ul = $ul[0];
  3756. if (this.options.debugLevel == null) {
  3757. this.options.debugLevel = FT.debugLevel;
  3758. }
  3759. // // Add container to the TAB chain
  3760. // // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  3761. // // #577: Allow to set tabindex to "0", "-1" and ""
  3762. // this.$container.attr("tabindex", this.options.tabindex);
  3763. // if( this.options.rtl ) {
  3764. // this.$container.attr("DIR", "RTL").addClass("fancytree-rtl");
  3765. // // }else{
  3766. // // this.$container.attr("DIR", null).removeClass("fancytree-rtl");
  3767. // }
  3768. // if(this.options.aria){
  3769. // this.$container.attr("role", "tree");
  3770. // if( this.options.selectMode !== 1 ) {
  3771. // this.$container.attr("aria-multiselectable", true);
  3772. // }
  3773. // }
  3774. }
  3775. Fancytree.prototype = /** @lends Fancytree# */ {
  3776. /* Return a context object that can be re-used for _callHook().
  3777. * @param {Fancytree | FancytreeNode | EventData} obj
  3778. * @param {Event} originalEvent
  3779. * @param {Object} extra
  3780. * @returns {EventData}
  3781. */
  3782. _makeHookContext: function(obj, originalEvent, extra) {
  3783. var ctx, tree;
  3784. if (obj.node !== undefined) {
  3785. // obj is already a context object
  3786. if (originalEvent && obj.originalEvent !== originalEvent) {
  3787. $.error("invalid args");
  3788. }
  3789. ctx = obj;
  3790. } else if (obj.tree) {
  3791. // obj is a FancytreeNode
  3792. tree = obj.tree;
  3793. ctx = {
  3794. node: obj,
  3795. tree: tree,
  3796. widget: tree.widget,
  3797. options: tree.widget.options,
  3798. originalEvent: originalEvent,
  3799. typeInfo: tree.types[obj.type] || {},
  3800. };
  3801. } else if (obj.widget) {
  3802. // obj is a Fancytree
  3803. ctx = {
  3804. node: null,
  3805. tree: obj,
  3806. widget: obj.widget,
  3807. options: obj.widget.options,
  3808. originalEvent: originalEvent,
  3809. };
  3810. } else {
  3811. $.error("invalid args");
  3812. }
  3813. if (extra) {
  3814. $.extend(ctx, extra);
  3815. }
  3816. return ctx;
  3817. },
  3818. /* Trigger a hook function: funcName(ctx, [...]).
  3819. *
  3820. * @param {string} funcName
  3821. * @param {Fancytree|FancytreeNode|EventData} contextObject
  3822. * @param {any} [_extraArgs] optional additional arguments
  3823. * @returns {any}
  3824. */
  3825. _callHook: function(funcName, contextObject, _extraArgs) {
  3826. var ctx = this._makeHookContext(contextObject),
  3827. fn = this[funcName],
  3828. args = Array.prototype.slice.call(arguments, 2);
  3829. if (!$.isFunction(fn)) {
  3830. $.error("_callHook('" + funcName + "') is not a function");
  3831. }
  3832. args.unshift(ctx);
  3833. // this.debug("_hook", funcName, ctx.node && ctx.node.toString() || ctx.tree.toString(), args);
  3834. return fn.apply(this, args);
  3835. },
  3836. _setExpiringValue: function(key, value, ms) {
  3837. this._tempCache[key] = {
  3838. value: value,
  3839. expire: Date.now() + (+ms || 50),
  3840. };
  3841. },
  3842. _getExpiringValue: function(key) {
  3843. var entry = this._tempCache[key];
  3844. if (entry && entry.expire > Date.now()) {
  3845. return entry.value;
  3846. }
  3847. delete this._tempCache[key];
  3848. return null;
  3849. },
  3850. /* Check if this tree has extension `name` enabled.
  3851. *
  3852. * @param {string} name name of the required extension
  3853. */
  3854. _usesExtension: function(name) {
  3855. return $.inArray(name, this.options.extensions) >= 0;
  3856. },
  3857. /* Check if current extensions dependencies are met and throw an error if not.
  3858. *
  3859. * This method may be called inside the `treeInit` hook for custom extensions.
  3860. *
  3861. * @param {string} name name of the required extension
  3862. * @param {boolean} [required=true] pass `false` if the extension is optional, but we want to check for order if it is present
  3863. * @param {boolean} [before] `true` if `name` must be included before this, `false` otherwise (use `null` if order doesn't matter)
  3864. * @param {string} [message] optional error message (defaults to a descriptve error message)
  3865. */
  3866. _requireExtension: function(name, required, before, message) {
  3867. if (before != null) {
  3868. before = !!before;
  3869. }
  3870. var thisName = this._local.name,
  3871. extList = this.options.extensions,
  3872. isBefore =
  3873. $.inArray(name, extList) < $.inArray(thisName, extList),
  3874. isMissing = required && this.ext[name] == null,
  3875. badOrder = !isMissing && before != null && before !== isBefore;
  3876. _assert(
  3877. thisName && thisName !== name,
  3878. "invalid or same name '" + thisName + "' (require yourself?)"
  3879. );
  3880. if (isMissing || badOrder) {
  3881. if (!message) {
  3882. if (isMissing || required) {
  3883. message =
  3884. "'" +
  3885. thisName +
  3886. "' extension requires '" +
  3887. name +
  3888. "'";
  3889. if (badOrder) {
  3890. message +=
  3891. " to be registered " +
  3892. (before ? "before" : "after") +
  3893. " itself";
  3894. }
  3895. } else {
  3896. message =
  3897. "If used together, `" +
  3898. name +
  3899. "` must be registered " +
  3900. (before ? "before" : "after") +
  3901. " `" +
  3902. thisName +
  3903. "`";
  3904. }
  3905. }
  3906. $.error(message);
  3907. return false;
  3908. }
  3909. return true;
  3910. },
  3911. /** Activate node with a given key and fire focus and activate events.
  3912. *
  3913. * A previously activated node will be deactivated.
  3914. * If activeVisible option is set, all parents will be expanded as necessary.
  3915. * Pass key = false, to deactivate the current node only.
  3916. * @param {string} key
  3917. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  3918. * @returns {FancytreeNode} activated node (null, if not found)
  3919. */
  3920. activateKey: function(key, opts) {
  3921. var node = this.getNodeByKey(key);
  3922. if (node) {
  3923. node.setActive(true, opts);
  3924. } else if (this.activeNode) {
  3925. this.activeNode.setActive(false, opts);
  3926. }
  3927. return node;
  3928. },
  3929. /** (experimental) Add child status nodes that indicate 'More...', ....
  3930. * @param {boolean|object} node optional node definition. Pass `false` to remove all paging nodes.
  3931. * @param {string} [mode='append'] 'child'|firstChild'
  3932. * @since 2.15
  3933. */
  3934. addPagingNode: function(node, mode) {
  3935. return this.rootNode.addPagingNode(node, mode);
  3936. },
  3937. /**
  3938. * (experimental) Apply a modification (or navigation) operation.
  3939. *
  3940. * Valid commands:
  3941. * - 'moveUp', 'moveDown'
  3942. * - 'indent', 'outdent'
  3943. * - 'remove'
  3944. * - 'edit', 'addChild', 'addSibling': (reqires ext-edit extension)
  3945. * - 'cut', 'copy', 'paste': (use an internal singleton 'clipboard')
  3946. * - 'down', 'first', 'last', 'left', 'parent', 'right', 'up': navigate
  3947. *
  3948. * @param {string} cmd
  3949. * @param {FancytreeNode} [node=active_node]
  3950. * @param {object} [opts] Currently unused
  3951. *
  3952. * @since 2.32
  3953. */
  3954. applyCommand: function(cmd, node, opts_) {
  3955. var // clipboard,
  3956. refNode;
  3957. // opts = $.extend(
  3958. // { setActive: true, clipboard: CLIPBOARD },
  3959. // opts_
  3960. // );
  3961. node = node || this.getActiveNode();
  3962. // clipboard = opts.clipboard;
  3963. switch (cmd) {
  3964. // Sorting and indentation:
  3965. case "moveUp":
  3966. refNode = node.getPrevSibling();
  3967. if (refNode) {
  3968. node.moveTo(refNode, "before");
  3969. node.setActive();
  3970. }
  3971. break;
  3972. case "moveDown":
  3973. refNode = node.getNextSibling();
  3974. if (refNode) {
  3975. node.moveTo(refNode, "after");
  3976. node.setActive();
  3977. }
  3978. break;
  3979. case "indent":
  3980. refNode = node.getPrevSibling();
  3981. if (refNode) {
  3982. node.moveTo(refNode, "child");
  3983. refNode.setExpanded();
  3984. node.setActive();
  3985. }
  3986. break;
  3987. case "outdent":
  3988. if (!node.isTopLevel()) {
  3989. node.moveTo(node.getParent(), "after");
  3990. node.setActive();
  3991. }
  3992. break;
  3993. // Remove:
  3994. case "remove":
  3995. refNode = node.getPrevSibling() || node.getParent();
  3996. node.remove();
  3997. if (refNode) {
  3998. refNode.setActive();
  3999. }
  4000. break;
  4001. // Add, edit (requires ext-edit):
  4002. case "addChild":
  4003. node.editCreateNode("child", "");
  4004. break;
  4005. case "addSibling":
  4006. node.editCreateNode("after", "");
  4007. break;
  4008. case "rename":
  4009. node.editStart();
  4010. break;
  4011. // Simple clipboard simulation:
  4012. // case "cut":
  4013. // clipboard = { mode: cmd, data: node };
  4014. // break;
  4015. // case "copy":
  4016. // clipboard = {
  4017. // mode: cmd,
  4018. // data: node.toDict(function(d, n) {
  4019. // delete d.key;
  4020. // }),
  4021. // };
  4022. // break;
  4023. // case "clear":
  4024. // clipboard = null;
  4025. // break;
  4026. // case "paste":
  4027. // if (clipboard.mode === "cut") {
  4028. // // refNode = node.getPrevSibling();
  4029. // clipboard.data.moveTo(node, "child");
  4030. // clipboard.data.setActive();
  4031. // } else if (clipboard.mode === "copy") {
  4032. // node.addChildren(clipboard.data).setActive();
  4033. // }
  4034. // break;
  4035. // Navigation commands:
  4036. case "down":
  4037. case "first":
  4038. case "last":
  4039. case "left":
  4040. case "parent":
  4041. case "right":
  4042. case "up":
  4043. return node.navigate(cmd);
  4044. default:
  4045. $.error("Unhandled command: '" + cmd + "'");
  4046. }
  4047. },
  4048. /** (experimental) Modify existing data model.
  4049. *
  4050. * @param {Array} patchList array of [key, NodePatch] arrays
  4051. * @returns {$.Promise} resolved, when all patches have been applied
  4052. * @see TreePatch
  4053. */
  4054. applyPatch: function(patchList) {
  4055. var dfd,
  4056. i,
  4057. p2,
  4058. key,
  4059. patch,
  4060. node,
  4061. patchCount = patchList.length,
  4062. deferredList = [];
  4063. for (i = 0; i < patchCount; i++) {
  4064. p2 = patchList[i];
  4065. _assert(
  4066. p2.length === 2,
  4067. "patchList must be an array of length-2-arrays"
  4068. );
  4069. key = p2[0];
  4070. patch = p2[1];
  4071. node = key === null ? this.rootNode : this.getNodeByKey(key);
  4072. if (node) {
  4073. dfd = new $.Deferred();
  4074. deferredList.push(dfd);
  4075. node.applyPatch(patch).always(_makeResolveFunc(dfd, node));
  4076. } else {
  4077. this.warn("could not find node with key '" + key + "'");
  4078. }
  4079. }
  4080. // Return a promise that is resolved, when ALL patches were applied
  4081. return $.when.apply($, deferredList).promise();
  4082. },
  4083. /* TODO: implement in dnd extension
  4084. cancelDrag: function() {
  4085. var dd = $.ui.ddmanager.current;
  4086. if(dd){
  4087. dd.cancel();
  4088. }
  4089. },
  4090. */
  4091. /** Remove all nodes.
  4092. * @since 2.14
  4093. */
  4094. clear: function(source) {
  4095. this._callHook("treeClear", this);
  4096. },
  4097. /** Return the number of nodes.
  4098. * @returns {integer}
  4099. */
  4100. count: function() {
  4101. return this.rootNode.countChildren();
  4102. },
  4103. /** Write to browser console if debugLevel >= 4 (prepending tree name)
  4104. *
  4105. * @param {*} msg string or object or array of such
  4106. */
  4107. debug: function(msg) {
  4108. if (this.options.debugLevel >= 4) {
  4109. Array.prototype.unshift.call(arguments, this.toString());
  4110. consoleApply("log", arguments);
  4111. }
  4112. },
  4113. /** Destroy this widget, restore previous markup and cleanup resources.
  4114. *
  4115. * @since 2.34
  4116. */
  4117. destroy: function() {
  4118. this.widget.destroy();
  4119. },
  4120. /** Enable (or disable) the tree control.
  4121. *
  4122. * @param {boolean} [flag=true] pass false to disable
  4123. * @since 2.30
  4124. */
  4125. enable: function(flag) {
  4126. if (flag === false) {
  4127. this.widget.disable();
  4128. } else {
  4129. this.widget.enable();
  4130. }
  4131. },
  4132. /** Temporarily suppress rendering to improve performance on bulk-updates.
  4133. *
  4134. * @param {boolean} flag
  4135. * @returns {boolean} previous status
  4136. * @since 2.19
  4137. */
  4138. enableUpdate: function(flag) {
  4139. flag = flag !== false;
  4140. if (!!this._enableUpdate === !!flag) {
  4141. return flag;
  4142. }
  4143. this._enableUpdate = flag;
  4144. if (flag) {
  4145. this.debug("enableUpdate(true): redraw "); //, this._dirtyRoots);
  4146. this._callHook("treeStructureChanged", this, "enableUpdate");
  4147. this.render();
  4148. } else {
  4149. // this._dirtyRoots = null;
  4150. this.debug("enableUpdate(false)...");
  4151. }
  4152. return !flag; // return previous value
  4153. },
  4154. /** Write error to browser console if debugLevel >= 1 (prepending tree info)
  4155. *
  4156. * @param {*} msg string or object or array of such
  4157. */
  4158. error: function(msg) {
  4159. if (this.options.debugLevel >= 1) {
  4160. Array.prototype.unshift.call(arguments, this.toString());
  4161. consoleApply("error", arguments);
  4162. }
  4163. },
  4164. /** Expand (or collapse) all parent nodes.
  4165. *
  4166. * This convenience method uses `tree.visit()` and `tree.setExpanded()`
  4167. * internally.
  4168. *
  4169. * @param {boolean} [flag=true] pass false to collapse
  4170. * @param {object} [opts] passed to setExpanded()
  4171. * @since 2.30
  4172. */
  4173. expandAll: function(flag, opts) {
  4174. var prev = this.enableUpdate(false);
  4175. flag = flag !== false;
  4176. this.visit(function(node) {
  4177. if (
  4178. node.hasChildren() !== false &&
  4179. node.isExpanded() !== flag
  4180. ) {
  4181. node.setExpanded(flag, opts);
  4182. }
  4183. });
  4184. this.enableUpdate(prev);
  4185. },
  4186. /**Find all nodes that matches condition.
  4187. *
  4188. * @param {string | function(node)} match title string to search for, or a
  4189. * callback function that returns `true` if a node is matched.
  4190. * @returns {FancytreeNode[]} array of nodes (may be empty)
  4191. * @see FancytreeNode#findAll
  4192. * @since 2.12
  4193. */
  4194. findAll: function(match) {
  4195. return this.rootNode.findAll(match);
  4196. },
  4197. /**Find first node that matches condition.
  4198. *
  4199. * @param {string | function(node)} match title string to search for, or a
  4200. * callback function that returns `true` if a node is matched.
  4201. * @returns {FancytreeNode} matching node or null
  4202. * @see FancytreeNode#findFirst
  4203. * @since 2.12
  4204. */
  4205. findFirst: function(match) {
  4206. return this.rootNode.findFirst(match);
  4207. },
  4208. /** Find the next visible node that starts with `match`, starting at `startNode`
  4209. * and wrap-around at the end.
  4210. *
  4211. * @param {string|function} match
  4212. * @param {FancytreeNode} [startNode] defaults to first node
  4213. * @returns {FancytreeNode} matching node or null
  4214. */
  4215. findNextNode: function(match, startNode) {
  4216. //, visibleOnly) {
  4217. var res = null,
  4218. firstNode = this.getFirstChild();
  4219. match =
  4220. typeof match === "string"
  4221. ? _makeNodeTitleStartMatcher(match)
  4222. : match;
  4223. startNode = startNode || firstNode;
  4224. function _checkNode(n) {
  4225. // console.log("_check " + n)
  4226. if (match(n)) {
  4227. res = n;
  4228. }
  4229. if (res || n === startNode) {
  4230. return false;
  4231. }
  4232. }
  4233. this.visitRows(_checkNode, {
  4234. start: startNode,
  4235. includeSelf: false,
  4236. });
  4237. // Wrap around search
  4238. if (!res && startNode !== firstNode) {
  4239. this.visitRows(_checkNode, {
  4240. start: firstNode,
  4241. includeSelf: true,
  4242. });
  4243. }
  4244. return res;
  4245. },
  4246. /** Find a node relative to another node.
  4247. *
  4248. * @param {FancytreeNode} node
  4249. * @param {string|number} where 'down', 'first', 'last', 'left', 'parent', 'right', or 'up'.
  4250. * (Alternatively the keyCode that would normally trigger this move,
  4251. * e.g. `$.ui.keyCode.LEFT` = 'left'.
  4252. * @param {boolean} [includeHidden=false] Not yet implemented
  4253. * @returns {FancytreeNode|null}
  4254. * @since v2.31
  4255. */
  4256. findRelatedNode: function(node, where, includeHidden) {
  4257. var res = null,
  4258. KC = $.ui.keyCode;
  4259. switch (where) {
  4260. case "parent":
  4261. case KC.BACKSPACE:
  4262. if (node.parent && node.parent.parent) {
  4263. res = node.parent;
  4264. }
  4265. break;
  4266. case "first":
  4267. case KC.HOME:
  4268. // First visible node
  4269. this.visit(function(n) {
  4270. if (n.isVisible()) {
  4271. res = n;
  4272. return false;
  4273. }
  4274. });
  4275. break;
  4276. case "last":
  4277. case KC.END:
  4278. this.visit(function(n) {
  4279. // last visible node
  4280. if (n.isVisible()) {
  4281. res = n;
  4282. }
  4283. });
  4284. break;
  4285. case "left":
  4286. case KC.LEFT:
  4287. if (node.expanded) {
  4288. node.setExpanded(false);
  4289. } else if (node.parent && node.parent.parent) {
  4290. res = node.parent;
  4291. }
  4292. break;
  4293. case "right":
  4294. case KC.RIGHT:
  4295. if (!node.expanded && (node.children || node.lazy)) {
  4296. node.setExpanded();
  4297. res = node;
  4298. } else if (node.children && node.children.length) {
  4299. res = node.children[0];
  4300. }
  4301. break;
  4302. case "up":
  4303. case KC.UP:
  4304. this.visitRows(
  4305. function(n) {
  4306. res = n;
  4307. return false;
  4308. },
  4309. { start: node, reverse: true, includeSelf: false }
  4310. );
  4311. break;
  4312. case "down":
  4313. case KC.DOWN:
  4314. this.visitRows(
  4315. function(n) {
  4316. res = n;
  4317. return false;
  4318. },
  4319. { start: node, includeSelf: false }
  4320. );
  4321. break;
  4322. default:
  4323. this.tree.warn("Unknown relation '" + where + "'.");
  4324. }
  4325. return res;
  4326. },
  4327. // TODO: fromDict
  4328. /**
  4329. * Generate INPUT elements that can be submitted with html forms.
  4330. *
  4331. * In selectMode 3 only the topmost selected nodes are considered, unless
  4332. * `opts.stopOnParents: false` is passed.
  4333. *
  4334. * @example
  4335. * // Generate input elements for active and selected nodes
  4336. * tree.generateFormElements();
  4337. * // Generate input elements selected nodes, using a custom `name` attribute
  4338. * tree.generateFormElements("cust_sel", false);
  4339. * // Generate input elements using a custom filter
  4340. * tree.generateFormElements(true, true, { filter: function(node) {
  4341. * return node.isSelected() && node.data.yes;
  4342. * }});
  4343. *
  4344. * @param {boolean | string} [selected=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID[]')
  4345. * @param {boolean | string} [active=true] Pass false to disable, pass a string to override the field name (default: 'ft_ID_active')
  4346. * @param {object} [opts] default { filter: null, stopOnParents: true }
  4347. */
  4348. generateFormElements: function(selected, active, opts) {
  4349. opts = opts || {};
  4350. var nodeList,
  4351. selectedName =
  4352. typeof selected === "string"
  4353. ? selected
  4354. : "ft_" + this._id + "[]",
  4355. activeName =
  4356. typeof active === "string"
  4357. ? active
  4358. : "ft_" + this._id + "_active",
  4359. id = "fancytree_result_" + this._id,
  4360. $result = $("#" + id),
  4361. stopOnParents =
  4362. this.options.selectMode === 3 &&
  4363. opts.stopOnParents !== false;
  4364. if ($result.length) {
  4365. $result.empty();
  4366. } else {
  4367. $result = $("<div>", {
  4368. id: id,
  4369. })
  4370. .hide()
  4371. .insertAfter(this.$container);
  4372. }
  4373. if (active !== false && this.activeNode) {
  4374. $result.append(
  4375. $("<input>", {
  4376. type: "radio",
  4377. name: activeName,
  4378. value: this.activeNode.key,
  4379. checked: true,
  4380. })
  4381. );
  4382. }
  4383. function _appender(node) {
  4384. $result.append(
  4385. $("<input>", {
  4386. type: "checkbox",
  4387. name: selectedName,
  4388. value: node.key,
  4389. checked: true,
  4390. })
  4391. );
  4392. }
  4393. if (opts.filter) {
  4394. this.visit(function(node) {
  4395. var res = opts.filter(node);
  4396. if (res === "skip") {
  4397. return res;
  4398. }
  4399. if (res !== false) {
  4400. _appender(node);
  4401. }
  4402. });
  4403. } else if (selected !== false) {
  4404. nodeList = this.getSelectedNodes(stopOnParents);
  4405. $.each(nodeList, function(idx, node) {
  4406. _appender(node);
  4407. });
  4408. }
  4409. },
  4410. /**
  4411. * Return the currently active node or null.
  4412. * @returns {FancytreeNode}
  4413. */
  4414. getActiveNode: function() {
  4415. return this.activeNode;
  4416. },
  4417. /** Return the first top level node if any (not the invisible root node).
  4418. * @returns {FancytreeNode | null}
  4419. */
  4420. getFirstChild: function() {
  4421. return this.rootNode.getFirstChild();
  4422. },
  4423. /**
  4424. * Return node that has keyboard focus or null.
  4425. * @returns {FancytreeNode}
  4426. */
  4427. getFocusNode: function() {
  4428. return this.focusNode;
  4429. },
  4430. /**
  4431. * Return current option value.
  4432. * (Note: this is the preferred variant of `$().fancytree("option", "KEY")`)
  4433. *
  4434. * @param {string} name option name (may contain '.')
  4435. * @returns {any}
  4436. */
  4437. getOption: function(optionName) {
  4438. return this.widget.option(optionName);
  4439. },
  4440. /**
  4441. * Return node with a given key or null if not found.
  4442. *
  4443. * @param {string} key
  4444. * @param {FancytreeNode} [searchRoot] only search below this node
  4445. * @returns {FancytreeNode | null}
  4446. */
  4447. getNodeByKey: function(key, searchRoot) {
  4448. // Search the DOM by element ID (assuming this is faster than traversing all nodes).
  4449. var el, match;
  4450. // TODO: use tree.keyMap if available
  4451. // TODO: check opts.generateIds === true
  4452. if (!searchRoot) {
  4453. el = document.getElementById(this.options.idPrefix + key);
  4454. if (el) {
  4455. return el.ftnode ? el.ftnode : null;
  4456. }
  4457. }
  4458. // Not found in the DOM, but still may be in an unrendered part of tree
  4459. searchRoot = searchRoot || this.rootNode;
  4460. match = null;
  4461. key = "" + key; // Convert to string (#1005)
  4462. searchRoot.visit(function(node) {
  4463. if (node.key === key) {
  4464. match = node;
  4465. return false; // Stop iteration
  4466. }
  4467. }, true);
  4468. return match;
  4469. },
  4470. /** Return the invisible system root node.
  4471. * @returns {FancytreeNode}
  4472. */
  4473. getRootNode: function() {
  4474. return this.rootNode;
  4475. },
  4476. /**
  4477. * Return an array of selected nodes.
  4478. *
  4479. * Note: you cannot send this result via Ajax directly. Instead the
  4480. * node object need to be converted to plain objects, for example
  4481. * by using `$.map()` and `node.toDict()`.
  4482. * @param {boolean} [stopOnParents=false] only return the topmost selected
  4483. * node (useful with selectMode 3)
  4484. * @returns {FancytreeNode[]}
  4485. */
  4486. getSelectedNodes: function(stopOnParents) {
  4487. return this.rootNode.getSelectedNodes(stopOnParents);
  4488. },
  4489. /** Return true if the tree control has keyboard focus
  4490. * @returns {boolean}
  4491. */
  4492. hasFocus: function() {
  4493. // var ae = document.activeElement,
  4494. // hasFocus = !!(
  4495. // ae && $(ae).closest(".fancytree-container").length
  4496. // );
  4497. // if (hasFocus !== !!this._hasFocus) {
  4498. // this.warn(
  4499. // "hasFocus(): fix inconsistent container state, now: " +
  4500. // hasFocus
  4501. // );
  4502. // this._hasFocus = hasFocus;
  4503. // this.$container.toggleClass("fancytree-treefocus", hasFocus);
  4504. // }
  4505. // return hasFocus;
  4506. return !!this._hasFocus;
  4507. },
  4508. /** Write to browser console if debugLevel >= 3 (prepending tree name)
  4509. * @param {*} msg string or object or array of such
  4510. */
  4511. info: function(msg) {
  4512. if (this.options.debugLevel >= 3) {
  4513. Array.prototype.unshift.call(arguments, this.toString());
  4514. consoleApply("info", arguments);
  4515. }
  4516. },
  4517. /** Return true if any node is currently beeing loaded, i.e. a Ajax request is pending.
  4518. * @returns {boolean}
  4519. * @since 2.32
  4520. */
  4521. isLoading: function() {
  4522. var res = false;
  4523. this.rootNode.visit(function(n) {
  4524. // also visit rootNode
  4525. if (n._isLoading || n._requestId) {
  4526. res = true;
  4527. return false;
  4528. }
  4529. }, true);
  4530. return res;
  4531. },
  4532. /*
  4533. TODO: isInitializing: function() {
  4534. return ( this.phase=="init" || this.phase=="postInit" );
  4535. },
  4536. TODO: isReloading: function() {
  4537. return ( this.phase=="init" || this.phase=="postInit" ) && this.options.persist && this.persistence.cookiesFound;
  4538. },
  4539. TODO: isUserEvent: function() {
  4540. return ( this.phase=="userEvent" );
  4541. },
  4542. */
  4543. /**
  4544. * Make sure that a node with a given ID is loaded, by traversing - and
  4545. * loading - its parents. This method is meant for lazy hierarchies.
  4546. * A callback is executed for every node as we go.
  4547. * @example
  4548. * // Resolve using node.key:
  4549. * tree.loadKeyPath("/_3/_23/_26/_27", function(node, status){
  4550. * if(status === "loaded") {
  4551. * console.log("loaded intermediate node " + node);
  4552. * }else if(status === "ok") {
  4553. * node.activate();
  4554. * }
  4555. * });
  4556. * // Use deferred promise:
  4557. * tree.loadKeyPath("/_3/_23/_26/_27").progress(function(data){
  4558. * if(data.status === "loaded") {
  4559. * console.log("loaded intermediate node " + data.node);
  4560. * }else if(data.status === "ok") {
  4561. * node.activate();
  4562. * }
  4563. * }).done(function(){
  4564. * ...
  4565. * });
  4566. * // Custom path segment resolver:
  4567. * tree.loadKeyPath("/321/431/21/2", {
  4568. * matchKey: function(node, key){
  4569. * return node.data.refKey === key;
  4570. * },
  4571. * callback: function(node, status){
  4572. * if(status === "loaded") {
  4573. * console.log("loaded intermediate node " + node);
  4574. * }else if(status === "ok") {
  4575. * node.activate();
  4576. * }
  4577. * }
  4578. * });
  4579. * @param {string | string[]} keyPathList one or more key paths (e.g. '/3/2_1/7')
  4580. * @param {function | object} optsOrCallback callback(node, status) is called for every visited node ('loading', 'loaded', 'ok', 'error').
  4581. * Pass an object to define custom key matchers for the path segments: {callback: function, matchKey: function}.
  4582. * @returns {$.Promise}
  4583. */
  4584. loadKeyPath: function(keyPathList, optsOrCallback) {
  4585. var callback,
  4586. i,
  4587. path,
  4588. self = this,
  4589. dfd = new $.Deferred(),
  4590. parent = this.getRootNode(),
  4591. sep = this.options.keyPathSeparator,
  4592. pathSegList = [],
  4593. opts = $.extend({}, optsOrCallback);
  4594. // Prepare options
  4595. if (typeof optsOrCallback === "function") {
  4596. callback = optsOrCallback;
  4597. } else if (optsOrCallback && optsOrCallback.callback) {
  4598. callback = optsOrCallback.callback;
  4599. }
  4600. opts.callback = function(ctx, node, status) {
  4601. if (callback) {
  4602. callback.call(ctx, node, status);
  4603. }
  4604. dfd.notifyWith(ctx, [{ node: node, status: status }]);
  4605. };
  4606. if (opts.matchKey == null) {
  4607. opts.matchKey = function(node, key) {
  4608. return node.key === key;
  4609. };
  4610. }
  4611. // Convert array of path strings to array of segment arrays
  4612. if (!$.isArray(keyPathList)) {
  4613. keyPathList = [keyPathList];
  4614. }
  4615. for (i = 0; i < keyPathList.length; i++) {
  4616. path = keyPathList[i];
  4617. // strip leading slash
  4618. if (path.charAt(0) === sep) {
  4619. path = path.substr(1);
  4620. }
  4621. // segListMap[path] = { parent: parent, segList: path.split(sep) };
  4622. pathSegList.push(path.split(sep));
  4623. // targetList.push({ parent: parent, segList: path.split(sep)/* , path: path*/});
  4624. }
  4625. // The timeout forces async behavior always (even if nodes are all loaded)
  4626. // This way a potential progress() event will fire.
  4627. setTimeout(function() {
  4628. self._loadKeyPathImpl(dfd, opts, parent, pathSegList).done(
  4629. function() {
  4630. dfd.resolve();
  4631. }
  4632. );
  4633. }, 0);
  4634. return dfd.promise();
  4635. },
  4636. /*
  4637. * Resolve a list of paths, relative to one parent node.
  4638. */
  4639. _loadKeyPathImpl: function(dfd, opts, parent, pathSegList) {
  4640. var deferredList,
  4641. i,
  4642. key,
  4643. node,
  4644. nodeKey,
  4645. remain,
  4646. remainMap,
  4647. tmpParent,
  4648. segList,
  4649. subDfd,
  4650. self = this;
  4651. function __findChild(parent, key) {
  4652. // console.log("__findChild", key, parent);
  4653. var i,
  4654. l,
  4655. cl = parent.children;
  4656. if (cl) {
  4657. for (i = 0, l = cl.length; i < l; i++) {
  4658. if (opts.matchKey(cl[i], key)) {
  4659. return cl[i];
  4660. }
  4661. }
  4662. }
  4663. return null;
  4664. }
  4665. // console.log("_loadKeyPathImpl, parent=", parent, ", pathSegList=", pathSegList);
  4666. // Pass 1:
  4667. // Handle all path segments for nodes that are already loaded.
  4668. // Collect distinct top-most lazy nodes in a map.
  4669. // Note that we can use node.key to de-dupe entries, even if a custom matcher would
  4670. // look for other node attributes.
  4671. // map[node.key] => {node: node, pathList: [list of remaining rest-paths]}
  4672. remainMap = {};
  4673. for (i = 0; i < pathSegList.length; i++) {
  4674. segList = pathSegList[i];
  4675. // target = targetList[i];
  4676. // Traverse and pop path segments (i.e. keys), until we hit a lazy, unloaded node
  4677. tmpParent = parent;
  4678. while (segList.length) {
  4679. key = segList.shift();
  4680. node = __findChild(tmpParent, key);
  4681. if (!node) {
  4682. this.warn(
  4683. "loadKeyPath: key not found: " +
  4684. key +
  4685. " (parent: " +
  4686. tmpParent +
  4687. ")"
  4688. );
  4689. opts.callback(this, key, "error");
  4690. break;
  4691. } else if (segList.length === 0) {
  4692. opts.callback(this, node, "ok");
  4693. break;
  4694. } else if (!node.lazy || node.hasChildren() !== undefined) {
  4695. opts.callback(this, node, "loaded");
  4696. tmpParent = node;
  4697. } else {
  4698. opts.callback(this, node, "loaded");
  4699. key = node.key; //target.segList.join(sep);
  4700. if (remainMap[key]) {
  4701. remainMap[key].pathSegList.push(segList);
  4702. } else {
  4703. remainMap[key] = {
  4704. parent: node,
  4705. pathSegList: [segList],
  4706. };
  4707. }
  4708. break;
  4709. }
  4710. }
  4711. }
  4712. // console.log("_loadKeyPathImpl AFTER pass 1, remainMap=", remainMap);
  4713. // Now load all lazy nodes and continue iteration for remaining paths
  4714. deferredList = [];
  4715. // Avoid jshint warning 'Don't make functions within a loop.':
  4716. function __lazyload(dfd, parent, pathSegList) {
  4717. // console.log("__lazyload", parent, "pathSegList=", pathSegList);
  4718. opts.callback(self, parent, "loading");
  4719. parent
  4720. .load()
  4721. .done(function() {
  4722. self._loadKeyPathImpl
  4723. .call(self, dfd, opts, parent, pathSegList)
  4724. .always(_makeResolveFunc(dfd, self));
  4725. })
  4726. .fail(function(errMsg) {
  4727. self.warn("loadKeyPath: error loading lazy " + parent);
  4728. opts.callback(self, node, "error");
  4729. dfd.rejectWith(self);
  4730. });
  4731. }
  4732. // remainMap contains parent nodes, each with a list of relative sub-paths.
  4733. // We start loading all of them now, and pass the the list to each loader.
  4734. for (nodeKey in remainMap) {
  4735. if (remainMap.hasOwnProperty(nodeKey)) {
  4736. remain = remainMap[nodeKey];
  4737. // console.log("for(): remain=", remain, "remainMap=", remainMap);
  4738. // key = remain.segList.shift();
  4739. // node = __findChild(remain.parent, key);
  4740. // if (node == null) { // #576
  4741. // // Issue #576, refactored for v2.27:
  4742. // // The root cause was, that sometimes the wrong parent was used here
  4743. // // to find the next segment.
  4744. // // Falling back to getNodeByKey() was a hack that no longer works if a custom
  4745. // // matcher is used, because we cannot assume that a single segment-key is unique
  4746. // // throughout the tree.
  4747. // self.error("loadKeyPath: error loading child by key '" + key + "' (parent: " + target.parent + ")", target);
  4748. // // node = self.getNodeByKey(key);
  4749. // continue;
  4750. // }
  4751. subDfd = new $.Deferred();
  4752. deferredList.push(subDfd);
  4753. __lazyload(subDfd, remain.parent, remain.pathSegList);
  4754. }
  4755. }
  4756. // Return a promise that is resolved, when ALL paths were loaded
  4757. return $.when.apply($, deferredList).promise();
  4758. },
  4759. /** Re-fire beforeActivate, activate, and (optional) focus events.
  4760. * Calling this method in the `init` event, will activate the node that
  4761. * was marked 'active' in the source data, and optionally set the keyboard
  4762. * focus.
  4763. * @param [setFocus=false]
  4764. */
  4765. reactivate: function(setFocus) {
  4766. var res,
  4767. node = this.activeNode;
  4768. if (!node) {
  4769. return _getResolvedPromise();
  4770. }
  4771. this.activeNode = null; // Force re-activating
  4772. res = node.setActive(true, { noFocus: true });
  4773. if (setFocus) {
  4774. node.setFocus();
  4775. }
  4776. return res;
  4777. },
  4778. /** Reload tree from source and return a promise.
  4779. * @param [source] optional new source (defaults to initial source data)
  4780. * @returns {$.Promise}
  4781. */
  4782. reload: function(source) {
  4783. this._callHook("treeClear", this);
  4784. return this._callHook("treeLoad", this, source);
  4785. },
  4786. /**Render tree (i.e. create DOM elements for all top-level nodes).
  4787. * @param {boolean} [force=false] create DOM elemnts, even if parent is collapsed
  4788. * @param {boolean} [deep=false]
  4789. */
  4790. render: function(force, deep) {
  4791. return this.rootNode.render(force, deep);
  4792. },
  4793. /**(De)select all nodes.
  4794. * @param {boolean} [flag=true]
  4795. * @since 2.28
  4796. */
  4797. selectAll: function(flag) {
  4798. this.visit(function(node) {
  4799. node.setSelected(flag);
  4800. });
  4801. },
  4802. // TODO: selectKey: function(key, select)
  4803. // TODO: serializeArray: function(stopOnParents)
  4804. /**
  4805. * @param {boolean} [flag=true]
  4806. */
  4807. setFocus: function(flag) {
  4808. return this._callHook("treeSetFocus", this, flag);
  4809. },
  4810. /**
  4811. * Set current option value.
  4812. * (Note: this is the preferred variant of `$().fancytree("option", "KEY", VALUE)`)
  4813. * @param {string} name option name (may contain '.')
  4814. * @param {any} new value
  4815. */
  4816. setOption: function(optionName, value) {
  4817. return this.widget.option(optionName, value);
  4818. },
  4819. /**
  4820. * Call console.time() when in debug mode (verbose >= 4).
  4821. *
  4822. * @param {string} label
  4823. */
  4824. debugTime: function(label) {
  4825. if (this.options.debugLevel >= 4) {
  4826. window.console.time(this + " - " + label);
  4827. }
  4828. },
  4829. /**
  4830. * Call console.timeEnd() when in debug mode (verbose >= 4).
  4831. *
  4832. * @param {string} label
  4833. */
  4834. debugTimeEnd: function(label) {
  4835. if (this.options.debugLevel >= 4) {
  4836. window.console.timeEnd(this + " - " + label);
  4837. }
  4838. },
  4839. /**
  4840. * Return all nodes as nested list of {@link NodeData}.
  4841. *
  4842. * @param {boolean} [includeRoot=false] Returns the hidden system root node (and its children)
  4843. * @param {function} [callback] callback(dict, node) is called for every node, in order to allow modifications.
  4844. * Return `false` to ignore this node or "skip" to include this node without its children.
  4845. * @returns {Array | object}
  4846. * @see FancytreeNode#toDict
  4847. */
  4848. toDict: function(includeRoot, callback) {
  4849. var res = this.rootNode.toDict(true, callback);
  4850. return includeRoot ? res : res.children;
  4851. },
  4852. /* Implicitly called for string conversions.
  4853. * @returns {string}
  4854. */
  4855. toString: function() {
  4856. return "Fancytree@" + this._id;
  4857. // return "<Fancytree(#" + this._id + ")>";
  4858. },
  4859. /* _trigger a widget event with additional node ctx.
  4860. * @see EventData
  4861. */
  4862. _triggerNodeEvent: function(type, node, originalEvent, extra) {
  4863. // this.debug("_trigger(" + type + "): '" + ctx.node.title + "'", ctx);
  4864. var ctx = this._makeHookContext(node, originalEvent, extra),
  4865. res = this.widget._trigger(type, originalEvent, ctx);
  4866. if (res !== false && ctx.result !== undefined) {
  4867. return ctx.result;
  4868. }
  4869. return res;
  4870. },
  4871. /* _trigger a widget event with additional tree data. */
  4872. _triggerTreeEvent: function(type, originalEvent, extra) {
  4873. // this.debug("_trigger(" + type + ")", ctx);
  4874. var ctx = this._makeHookContext(this, originalEvent, extra),
  4875. res = this.widget._trigger(type, originalEvent, ctx);
  4876. if (res !== false && ctx.result !== undefined) {
  4877. return ctx.result;
  4878. }
  4879. return res;
  4880. },
  4881. /** Call fn(node) for all nodes in hierarchical order (depth-first).
  4882. *
  4883. * @param {function} fn the callback function.
  4884. * Return false to stop iteration, return "skip" to skip this node and children only.
  4885. * @returns {boolean} false, if the iterator was stopped.
  4886. */
  4887. visit: function(fn) {
  4888. return this.rootNode.visit(fn, false);
  4889. },
  4890. /** Call fn(node) for all nodes in vertical order, top down (or bottom up).<br>
  4891. * Stop iteration, if fn() returns false.<br>
  4892. * Return false if iteration was stopped.
  4893. *
  4894. * @param {function} fn the callback function.
  4895. * Return false to stop iteration, return "skip" to skip this node and children only.
  4896. * @param {object} [options]
  4897. * Defaults:
  4898. * {start: First top node, reverse: false, includeSelf: true, includeHidden: false}
  4899. * @returns {boolean} false if iteration was cancelled
  4900. * @since 2.28
  4901. */
  4902. visitRows: function(fn, opts) {
  4903. if (!this.rootNode.hasChildren()) {
  4904. return false;
  4905. }
  4906. if (opts && opts.reverse) {
  4907. delete opts.reverse;
  4908. return this._visitRowsUp(fn, opts);
  4909. }
  4910. opts = opts || {};
  4911. var i,
  4912. nextIdx,
  4913. parent,
  4914. res,
  4915. siblings,
  4916. siblingOfs = 0,
  4917. skipFirstNode = opts.includeSelf === false,
  4918. includeHidden = !!opts.includeHidden,
  4919. checkFilter = !includeHidden && this.enableFilter,
  4920. node = opts.start || this.rootNode.children[0];
  4921. parent = node.parent;
  4922. while (parent) {
  4923. // visit siblings
  4924. siblings = parent.children;
  4925. nextIdx = siblings.indexOf(node) + siblingOfs;
  4926. for (i = nextIdx; i < siblings.length; i++) {
  4927. node = siblings[i];
  4928. if (checkFilter && !node.match && !node.subMatchCount) {
  4929. continue;
  4930. }
  4931. if (!skipFirstNode && fn(node) === false) {
  4932. return false;
  4933. }
  4934. skipFirstNode = false;
  4935. // Dive into node's child nodes
  4936. if (
  4937. node.children &&
  4938. node.children.length &&
  4939. (includeHidden || node.expanded)
  4940. ) {
  4941. // Disable warning: Functions declared within loops referencing an outer
  4942. // scoped variable may lead to confusing semantics:
  4943. /*jshint -W083 */
  4944. res = node.visit(function(n) {
  4945. if (checkFilter && !n.match && !n.subMatchCount) {
  4946. return "skip";
  4947. }
  4948. if (fn(n) === false) {
  4949. return false;
  4950. }
  4951. if (!includeHidden && n.children && !n.expanded) {
  4952. return "skip";
  4953. }
  4954. }, false);
  4955. /*jshint +W083 */
  4956. if (res === false) {
  4957. return false;
  4958. }
  4959. }
  4960. }
  4961. // Visit parent nodes (bottom up)
  4962. node = parent;
  4963. parent = parent.parent;
  4964. siblingOfs = 1; //
  4965. }
  4966. return true;
  4967. },
  4968. /* Call fn(node) for all nodes in vertical order, bottom up.
  4969. */
  4970. _visitRowsUp: function(fn, opts) {
  4971. var children,
  4972. idx,
  4973. parent,
  4974. includeHidden = !!opts.includeHidden,
  4975. node = opts.start || this.rootNode.children[0];
  4976. while (true) {
  4977. parent = node.parent;
  4978. children = parent.children;
  4979. if (children[0] === node) {
  4980. // If this is already the first sibling, goto parent
  4981. node = parent;
  4982. if (!node.parent) {
  4983. break; // first node of the tree
  4984. }
  4985. children = parent.children;
  4986. } else {
  4987. // Otherwise, goto prev. sibling
  4988. idx = children.indexOf(node);
  4989. node = children[idx - 1];
  4990. // If the prev. sibling has children, follow down to last descendant
  4991. while (
  4992. // See: https://github.com/eslint/eslint/issues/11302
  4993. // eslint-disable-next-line no-unmodified-loop-condition
  4994. (includeHidden || node.expanded) &&
  4995. node.children &&
  4996. node.children.length
  4997. ) {
  4998. children = node.children;
  4999. parent = node;
  5000. node = children[children.length - 1];
  5001. }
  5002. }
  5003. // Skip invisible
  5004. if (!includeHidden && !node.isVisible()) {
  5005. continue;
  5006. }
  5007. if (fn(node) === false) {
  5008. return false;
  5009. }
  5010. }
  5011. },
  5012. /** Write warning to browser console if debugLevel >= 2 (prepending tree info)
  5013. *
  5014. * @param {*} msg string or object or array of such
  5015. */
  5016. warn: function(msg) {
  5017. if (this.options.debugLevel >= 2) {
  5018. Array.prototype.unshift.call(arguments, this.toString());
  5019. consoleApply("warn", arguments);
  5020. }
  5021. },
  5022. };
  5023. /**
  5024. * These additional methods of the {@link Fancytree} class are 'hook functions'
  5025. * that can be used and overloaded by extensions.
  5026. *
  5027. * @see [writing extensions](https://github.com/mar10/fancytree/wiki/TutorialExtensions)
  5028. * @mixin Fancytree_Hooks
  5029. */
  5030. $.extend(
  5031. Fancytree.prototype,
  5032. /** @lends Fancytree_Hooks# */
  5033. {
  5034. /** Default handling for mouse click events.
  5035. *
  5036. * @param {EventData} ctx
  5037. */
  5038. nodeClick: function(ctx) {
  5039. var activate,
  5040. expand,
  5041. // event = ctx.originalEvent,
  5042. targetType = ctx.targetType,
  5043. node = ctx.node;
  5044. // this.debug("ftnode.onClick(" + event.type + "): ftnode:" + this + ", button:" + event.button + ", which: " + event.which, ctx);
  5045. // TODO: use switch
  5046. // TODO: make sure clicks on embedded <input> doesn't steal focus (see table sample)
  5047. if (targetType === "expander") {
  5048. if (node.isLoading()) {
  5049. // #495: we probably got a click event while a lazy load is pending.
  5050. // The 'expanded' state is not yet set, so 'toggle' would expand
  5051. // and trigger lazyLoad again.
  5052. // It would be better to allow to collapse/expand the status node
  5053. // while loading (instead of ignoring), but that would require some
  5054. // more work.
  5055. node.debug("Got 2nd click while loading: ignored");
  5056. return;
  5057. }
  5058. // Clicking the expander icon always expands/collapses
  5059. this._callHook("nodeToggleExpanded", ctx);
  5060. } else if (targetType === "checkbox") {
  5061. // Clicking the checkbox always (de)selects
  5062. this._callHook("nodeToggleSelected", ctx);
  5063. if (ctx.options.focusOnSelect) {
  5064. // #358
  5065. this._callHook("nodeSetFocus", ctx, true);
  5066. }
  5067. } else {
  5068. // Honor `clickFolderMode` for
  5069. expand = false;
  5070. activate = true;
  5071. if (node.folder) {
  5072. switch (ctx.options.clickFolderMode) {
  5073. case 2: // expand only
  5074. expand = true;
  5075. activate = false;
  5076. break;
  5077. case 3: // expand and activate
  5078. activate = true;
  5079. expand = true; //!node.isExpanded();
  5080. break;
  5081. // else 1 or 4: just activate
  5082. }
  5083. }
  5084. if (activate) {
  5085. this.nodeSetFocus(ctx);
  5086. this._callHook("nodeSetActive", ctx, true);
  5087. }
  5088. if (expand) {
  5089. if (!activate) {
  5090. // this._callHook("nodeSetFocus", ctx);
  5091. }
  5092. // this._callHook("nodeSetExpanded", ctx, true);
  5093. this._callHook("nodeToggleExpanded", ctx);
  5094. }
  5095. }
  5096. // Make sure that clicks stop, otherwise <a href='#'> jumps to the top
  5097. // if(event.target.localName === "a" && event.target.className === "fancytree-title"){
  5098. // event.preventDefault();
  5099. // }
  5100. // TODO: return promise?
  5101. },
  5102. /** Collapse all other children of same parent.
  5103. *
  5104. * @param {EventData} ctx
  5105. * @param {object} callOpts
  5106. */
  5107. nodeCollapseSiblings: function(ctx, callOpts) {
  5108. // TODO: return promise?
  5109. var ac,
  5110. i,
  5111. l,
  5112. node = ctx.node;
  5113. if (node.parent) {
  5114. ac = node.parent.children;
  5115. for (i = 0, l = ac.length; i < l; i++) {
  5116. if (ac[i] !== node && ac[i].expanded) {
  5117. this._callHook(
  5118. "nodeSetExpanded",
  5119. ac[i],
  5120. false,
  5121. callOpts
  5122. );
  5123. }
  5124. }
  5125. }
  5126. },
  5127. /** Default handling for mouse douleclick events.
  5128. * @param {EventData} ctx
  5129. */
  5130. nodeDblclick: function(ctx) {
  5131. // TODO: return promise?
  5132. if (
  5133. ctx.targetType === "title" &&
  5134. ctx.options.clickFolderMode === 4
  5135. ) {
  5136. // this.nodeSetFocus(ctx);
  5137. // this._callHook("nodeSetActive", ctx, true);
  5138. this._callHook("nodeToggleExpanded", ctx);
  5139. }
  5140. // TODO: prevent text selection on dblclicks
  5141. if (ctx.targetType === "title") {
  5142. ctx.originalEvent.preventDefault();
  5143. }
  5144. },
  5145. /** Default handling for mouse keydown events.
  5146. *
  5147. * NOTE: this may be called with node == null if tree (but no node) has focus.
  5148. * @param {EventData} ctx
  5149. */
  5150. nodeKeydown: function(ctx) {
  5151. // TODO: return promise?
  5152. var matchNode,
  5153. stamp,
  5154. _res,
  5155. focusNode,
  5156. event = ctx.originalEvent,
  5157. node = ctx.node,
  5158. tree = ctx.tree,
  5159. opts = ctx.options,
  5160. which = event.which,
  5161. // #909: Use event.key, to get unicode characters.
  5162. // We can't use `/\w/.test(key)`, because that would
  5163. // only detect plain ascii alpha-numerics. But we still need
  5164. // to ignore modifier-only, whitespace, cursor-keys, etc.
  5165. key = event.key || String.fromCharCode(which),
  5166. specialModifiers = !!(
  5167. event.altKey ||
  5168. event.ctrlKey ||
  5169. event.metaKey
  5170. ),
  5171. isAlnum =
  5172. !MODIFIERS[which] &&
  5173. !SPECIAL_KEYCODES[which] &&
  5174. !specialModifiers,
  5175. $target = $(event.target),
  5176. handled = true,
  5177. activate = !(event.ctrlKey || !opts.autoActivate);
  5178. // (node || FT).debug("ftnode.nodeKeydown(" + event.type + "): ftnode:" + this + ", charCode:" + event.charCode + ", keyCode: " + event.keyCode + ", which: " + event.which);
  5179. // FT.debug( "eventToString(): " + FT.eventToString(event) + ", key='" + key + "', isAlnum: " + isAlnum );
  5180. // Set focus to active (or first node) if no other node has the focus yet
  5181. if (!node) {
  5182. focusNode = this.getActiveNode() || this.getFirstChild();
  5183. if (focusNode) {
  5184. focusNode.setFocus();
  5185. node = ctx.node = this.focusNode;
  5186. node.debug("Keydown force focus on active node");
  5187. }
  5188. }
  5189. if (
  5190. opts.quicksearch &&
  5191. isAlnum &&
  5192. !$target.is(":input:enabled")
  5193. ) {
  5194. // Allow to search for longer streaks if typed in quickly
  5195. stamp = Date.now();
  5196. if (stamp - tree.lastQuicksearchTime > 500) {
  5197. tree.lastQuicksearchTerm = "";
  5198. }
  5199. tree.lastQuicksearchTime = stamp;
  5200. tree.lastQuicksearchTerm += key;
  5201. // tree.debug("quicksearch find", tree.lastQuicksearchTerm);
  5202. matchNode = tree.findNextNode(
  5203. tree.lastQuicksearchTerm,
  5204. tree.getActiveNode()
  5205. );
  5206. if (matchNode) {
  5207. matchNode.setActive();
  5208. }
  5209. event.preventDefault();
  5210. return;
  5211. }
  5212. switch (FT.eventToString(event)) {
  5213. case "+":
  5214. case "=": // 187: '+' @ Chrome, Safari
  5215. tree.nodeSetExpanded(ctx, true);
  5216. break;
  5217. case "-":
  5218. tree.nodeSetExpanded(ctx, false);
  5219. break;
  5220. case "space":
  5221. if (node.isPagingNode()) {
  5222. tree._triggerNodeEvent("clickPaging", ctx, event);
  5223. } else if (
  5224. FT.evalOption("checkbox", node, node, opts, false)
  5225. ) {
  5226. // #768
  5227. tree.nodeToggleSelected(ctx);
  5228. } else {
  5229. tree.nodeSetActive(ctx, true);
  5230. }
  5231. break;
  5232. case "return":
  5233. tree.nodeSetActive(ctx, true);
  5234. break;
  5235. case "home":
  5236. case "end":
  5237. case "backspace":
  5238. case "left":
  5239. case "right":
  5240. case "up":
  5241. case "down":
  5242. _res = node.navigate(event.which, activate);
  5243. break;
  5244. default:
  5245. handled = false;
  5246. }
  5247. if (handled) {
  5248. event.preventDefault();
  5249. }
  5250. },
  5251. // /** Default handling for mouse keypress events. */
  5252. // nodeKeypress: function(ctx) {
  5253. // var event = ctx.originalEvent;
  5254. // },
  5255. // /** Trigger lazyLoad event (async). */
  5256. // nodeLazyLoad: function(ctx) {
  5257. // var node = ctx.node;
  5258. // if(this._triggerNodeEvent())
  5259. // },
  5260. /** Load child nodes (async).
  5261. *
  5262. * @param {EventData} ctx
  5263. * @param {object[]|object|string|$.Promise|function} source
  5264. * @returns {$.Promise} The deferred will be resolved as soon as the (ajax)
  5265. * data was rendered.
  5266. */
  5267. nodeLoadChildren: function(ctx, source) {
  5268. var ajax,
  5269. delay,
  5270. ajaxDfd = null,
  5271. resultDfd,
  5272. isAsync = true,
  5273. tree = ctx.tree,
  5274. node = ctx.node,
  5275. nodePrevParent = node.parent,
  5276. tag = "nodeLoadChildren",
  5277. requestId = Date.now();
  5278. // `source` is a callback: use the returned result instead:
  5279. if ($.isFunction(source)) {
  5280. source = source.call(tree, { type: "source" }, ctx);
  5281. _assert(
  5282. !$.isFunction(source),
  5283. "source callback must not return another function"
  5284. );
  5285. }
  5286. // `source` is already a promise:
  5287. if ($.isFunction(source.then)) {
  5288. // _assert($.isFunction(source.always), "Expected jQuery?");
  5289. ajaxDfd = source;
  5290. } else if (source.url) {
  5291. // `source` is an Ajax options object
  5292. ajax = $.extend({}, ctx.options.ajax, source);
  5293. if (ajax.debugDelay) {
  5294. // Simulate a slow server
  5295. delay = ajax.debugDelay;
  5296. delete ajax.debugDelay; // remove debug option
  5297. if ($.isArray(delay)) {
  5298. // random delay range [min..max]
  5299. delay =
  5300. delay[0] +
  5301. Math.random() * (delay[1] - delay[0]);
  5302. }
  5303. node.warn(
  5304. "nodeLoadChildren waiting debugDelay " +
  5305. Math.round(delay) +
  5306. " ms ..."
  5307. );
  5308. ajaxDfd = $.Deferred(function(ajaxDfd) {
  5309. setTimeout(function() {
  5310. $.ajax(ajax)
  5311. .done(function() {
  5312. ajaxDfd.resolveWith(this, arguments);
  5313. })
  5314. .fail(function() {
  5315. ajaxDfd.rejectWith(this, arguments);
  5316. });
  5317. }, delay);
  5318. });
  5319. } else {
  5320. ajaxDfd = $.ajax(ajax);
  5321. }
  5322. } else if ($.isPlainObject(source) || $.isArray(source)) {
  5323. // `source` is already a constant dict or list, but we convert
  5324. // to a thenable for unified processing.
  5325. // 2020-01-03: refactored.
  5326. // `ajaxDfd = $.when(source)` would do the trick, but the returned
  5327. // promise will resolve async, which broke some tests and
  5328. // would probably also break current implementations out there.
  5329. // So we mock-up a thenable that resolves synchronously:
  5330. ajaxDfd = {
  5331. then: function(resolve, reject) {
  5332. resolve(source, null, null);
  5333. },
  5334. };
  5335. isAsync = false;
  5336. } else {
  5337. $.error("Invalid source type: " + source);
  5338. }
  5339. // Check for overlapping requests
  5340. if (node._requestId) {
  5341. node.warn(
  5342. "Recursive load request #" +
  5343. requestId +
  5344. " while #" +
  5345. node._requestId +
  5346. " is pending."
  5347. );
  5348. node._requestId = requestId;
  5349. // node.debug("Send load request #" + requestId);
  5350. }
  5351. if (isAsync) {
  5352. tree.debugTime(tag);
  5353. tree.nodeSetStatus(ctx, "loading");
  5354. }
  5355. // The async Ajax request has now started...
  5356. // Defer the deferred:
  5357. // we want to be able to reject invalid responses, even if
  5358. // the raw HTTP Ajax XHR resolved as Ok.
  5359. // We use the ajaxDfd.then() syntax here, which is compatible with
  5360. // jQuery and ECMA6.
  5361. // However resultDfd is a jQuery deferred, which is currently the
  5362. // expected result type of nodeLoadChildren()
  5363. resultDfd = new $.Deferred();
  5364. ajaxDfd.then(
  5365. function(data, textStatus, jqXHR) {
  5366. // ajaxDfd was resolved, but we reject or resolve resultDfd
  5367. // depending on the response data
  5368. var errorObj, res;
  5369. if (
  5370. (source.dataType === "json" ||
  5371. source.dataType === "jsonp") &&
  5372. typeof data === "string"
  5373. ) {
  5374. $.error(
  5375. "Ajax request returned a string (did you get the JSON dataType wrong?)."
  5376. );
  5377. }
  5378. if (node._requestId && node._requestId > requestId) {
  5379. // The expected request time stamp is later than `requestId`
  5380. // (which was kept as as closure variable to this handler function)
  5381. // node.warn("Ignored load response for obsolete request #" + requestId + " (expected #" + node._requestId + ")");
  5382. resultDfd.rejectWith(this, [
  5383. RECURSIVE_REQUEST_ERROR,
  5384. ]);
  5385. return;
  5386. // } else {
  5387. // node.debug("Response returned for load request #" + requestId);
  5388. }
  5389. if (node.parent === null && nodePrevParent !== null) {
  5390. resultDfd.rejectWith(this, [
  5391. INVALID_REQUEST_TARGET_ERROR,
  5392. ]);
  5393. return;
  5394. }
  5395. // Allow to adjust the received response data in the `postProcess` event.
  5396. if (ctx.options.postProcess) {
  5397. // The handler may either
  5398. // - modify `ctx.response` in-place (and leave `ctx.result` undefined)
  5399. // => res = undefined
  5400. // - return a replacement in `ctx.result`
  5401. // => res = <new data>
  5402. // If res contains an `error` property, an error status is displayed
  5403. try {
  5404. res = tree._triggerNodeEvent(
  5405. "postProcess",
  5406. ctx,
  5407. ctx.originalEvent,
  5408. {
  5409. response: data,
  5410. error: null,
  5411. dataType: source.dataType,
  5412. }
  5413. );
  5414. if (res.error) {
  5415. tree.warn(
  5416. "postProcess returned error:",
  5417. res
  5418. );
  5419. }
  5420. } catch (e) {
  5421. res = {
  5422. error: e,
  5423. message: "" + e,
  5424. details: "postProcess failed",
  5425. };
  5426. }
  5427. if (res.error) {
  5428. // Either postProcess failed with an exception, or the returned
  5429. // result object has an 'error' property attached:
  5430. errorObj = $.isPlainObject(res.error)
  5431. ? res.error
  5432. : { message: res.error };
  5433. errorObj = tree._makeHookContext(
  5434. node,
  5435. null,
  5436. errorObj
  5437. );
  5438. resultDfd.rejectWith(this, [errorObj]);
  5439. return;
  5440. }
  5441. if (
  5442. $.isArray(res) ||
  5443. ($.isPlainObject(res) &&
  5444. $.isArray(res.children))
  5445. ) {
  5446. // Use `ctx.result` if valid
  5447. // (otherwise use existing data, which may have been modified in-place)
  5448. data = res;
  5449. }
  5450. } else if (
  5451. data &&
  5452. data.hasOwnProperty("d") &&
  5453. ctx.options.enableAspx
  5454. ) {
  5455. // Process ASPX WebMethod JSON object inside "d" property
  5456. // (only if no postProcess event was defined)
  5457. if (ctx.options.enableAspx === 42) {
  5458. tree.warn(
  5459. "The default for enableAspx will change to `false` in the fututure. " +
  5460. "Pass `enableAspx: true` or implement postProcess to silence this warning."
  5461. );
  5462. }
  5463. data =
  5464. typeof data.d === "string"
  5465. ? $.parseJSON(data.d)
  5466. : data.d;
  5467. }
  5468. resultDfd.resolveWith(this, [data]);
  5469. },
  5470. function(jqXHR, textStatus, errorThrown) {
  5471. // ajaxDfd was rejected, so we reject resultDfd as well
  5472. var errorObj = tree._makeHookContext(node, null, {
  5473. error: jqXHR,
  5474. args: Array.prototype.slice.call(arguments),
  5475. message: errorThrown,
  5476. details: jqXHR.status + ": " + errorThrown,
  5477. });
  5478. resultDfd.rejectWith(this, [errorObj]);
  5479. }
  5480. );
  5481. // The async Ajax request has now started.
  5482. // resultDfd will be resolved/rejected after the response arrived,
  5483. // was postProcessed, and checked.
  5484. // Now we implement the UI update and add the data to the tree.
  5485. // We also return this promise to the caller.
  5486. resultDfd
  5487. .done(function(data) {
  5488. tree.nodeSetStatus(ctx, "ok");
  5489. var children, metaData, noDataRes;
  5490. if ($.isPlainObject(data)) {
  5491. // We got {foo: 'abc', children: [...]}
  5492. // Copy extra properties to tree.data.foo
  5493. _assert(
  5494. node.isRootNode(),
  5495. "source may only be an object for root nodes (expecting an array of child objects otherwise)"
  5496. );
  5497. _assert(
  5498. $.isArray(data.children),
  5499. "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')"
  5500. );
  5501. metaData = data;
  5502. children = data.children;
  5503. delete metaData.children;
  5504. // Copy some attributes to tree.data
  5505. $.each(TREE_ATTRS, function(i, attr) {
  5506. if (metaData[attr] !== undefined) {
  5507. tree[attr] = metaData[attr];
  5508. delete metaData[attr];
  5509. }
  5510. });
  5511. // Copy all other attributes to tree.data.NAME
  5512. $.extend(tree.data, metaData);
  5513. } else {
  5514. children = data;
  5515. }
  5516. _assert(
  5517. $.isArray(children),
  5518. "expected array of children"
  5519. );
  5520. node._setChildren(children);
  5521. if (tree.options.nodata && children.length === 0) {
  5522. if ($.isFunction(tree.options.nodata)) {
  5523. noDataRes = tree.options.nodata.call(
  5524. tree,
  5525. { type: "nodata" },
  5526. ctx
  5527. );
  5528. } else if (
  5529. tree.options.nodata === true &&
  5530. node.isRootNode()
  5531. ) {
  5532. noDataRes = tree.options.strings.noData;
  5533. } else if (
  5534. typeof tree.options.nodata === "string" &&
  5535. node.isRootNode()
  5536. ) {
  5537. noDataRes = tree.options.nodata;
  5538. }
  5539. if (noDataRes) {
  5540. node.setStatus("nodata", noDataRes);
  5541. }
  5542. }
  5543. // trigger fancytreeloadchildren
  5544. tree._triggerNodeEvent("loadChildren", node);
  5545. })
  5546. .fail(function(error) {
  5547. var ctxErr;
  5548. if (error === RECURSIVE_REQUEST_ERROR) {
  5549. node.warn(
  5550. "Ignored response for obsolete load request #" +
  5551. requestId +
  5552. " (expected #" +
  5553. node._requestId +
  5554. ")"
  5555. );
  5556. return;
  5557. } else if (error === INVALID_REQUEST_TARGET_ERROR) {
  5558. node.warn(
  5559. "Lazy parent node was removed while loading: discarding response."
  5560. );
  5561. return;
  5562. } else if (error.node && error.error && error.message) {
  5563. // error is already a context object
  5564. ctxErr = error;
  5565. } else {
  5566. ctxErr = tree._makeHookContext(node, null, {
  5567. error: error, // it can be jqXHR or any custom error
  5568. args: Array.prototype.slice.call(arguments),
  5569. message: error
  5570. ? error.message || error.toString()
  5571. : "",
  5572. });
  5573. if (ctxErr.message === "[object Object]") {
  5574. ctxErr.message = "";
  5575. }
  5576. }
  5577. node.warn(
  5578. "Load children failed (" + ctxErr.message + ")",
  5579. ctxErr
  5580. );
  5581. if (
  5582. tree._triggerNodeEvent(
  5583. "loadError",
  5584. ctxErr,
  5585. null
  5586. ) !== false
  5587. ) {
  5588. tree.nodeSetStatus(
  5589. ctx,
  5590. "error",
  5591. ctxErr.message,
  5592. ctxErr.details
  5593. );
  5594. }
  5595. })
  5596. .always(function() {
  5597. node._requestId = null;
  5598. if (isAsync) {
  5599. tree.debugTimeEnd(tag);
  5600. }
  5601. });
  5602. return resultDfd.promise();
  5603. },
  5604. /** [Not Implemented] */
  5605. nodeLoadKeyPath: function(ctx, keyPathList) {
  5606. // TODO: implement and improve
  5607. // http://code.google.com/p/dynatree/issues/detail?id=222
  5608. },
  5609. /**
  5610. * Remove a single direct child of ctx.node.
  5611. * @param {EventData} ctx
  5612. * @param {FancytreeNode} childNode dircect child of ctx.node
  5613. */
  5614. nodeRemoveChild: function(ctx, childNode) {
  5615. var idx,
  5616. node = ctx.node,
  5617. // opts = ctx.options,
  5618. subCtx = $.extend({}, ctx, { node: childNode }),
  5619. children = node.children;
  5620. // FT.debug("nodeRemoveChild()", node.toString(), childNode.toString());
  5621. if (children.length === 1) {
  5622. _assert(childNode === children[0], "invalid single child");
  5623. return this.nodeRemoveChildren(ctx);
  5624. }
  5625. if (
  5626. this.activeNode &&
  5627. (childNode === this.activeNode ||
  5628. this.activeNode.isDescendantOf(childNode))
  5629. ) {
  5630. this.activeNode.setActive(false); // TODO: don't fire events
  5631. }
  5632. if (
  5633. this.focusNode &&
  5634. (childNode === this.focusNode ||
  5635. this.focusNode.isDescendantOf(childNode))
  5636. ) {
  5637. this.focusNode = null;
  5638. }
  5639. // TODO: persist must take care to clear select and expand cookies
  5640. this.nodeRemoveMarkup(subCtx);
  5641. this.nodeRemoveChildren(subCtx);
  5642. idx = $.inArray(childNode, children);
  5643. _assert(idx >= 0, "invalid child");
  5644. // Notify listeners
  5645. node.triggerModifyChild("remove", childNode);
  5646. // Unlink to support GC
  5647. childNode.visit(function(n) {
  5648. n.parent = null;
  5649. }, true);
  5650. this._callHook("treeRegisterNode", this, false, childNode);
  5651. // remove from child list
  5652. children.splice(idx, 1);
  5653. },
  5654. /**Remove HTML markup for all descendents of ctx.node.
  5655. * @param {EventData} ctx
  5656. */
  5657. nodeRemoveChildMarkup: function(ctx) {
  5658. var node = ctx.node;
  5659. // FT.debug("nodeRemoveChildMarkup()", node.toString());
  5660. // TODO: Unlink attr.ftnode to support GC
  5661. if (node.ul) {
  5662. if (node.isRootNode()) {
  5663. $(node.ul).empty();
  5664. } else {
  5665. $(node.ul).remove();
  5666. node.ul = null;
  5667. }
  5668. node.visit(function(n) {
  5669. n.li = n.ul = null;
  5670. });
  5671. }
  5672. },
  5673. /**Remove all descendants of ctx.node.
  5674. * @param {EventData} ctx
  5675. */
  5676. nodeRemoveChildren: function(ctx) {
  5677. var //subCtx,
  5678. tree = ctx.tree,
  5679. node = ctx.node,
  5680. children = node.children;
  5681. // opts = ctx.options;
  5682. // FT.debug("nodeRemoveChildren()", node.toString());
  5683. if (!children) {
  5684. return;
  5685. }
  5686. if (this.activeNode && this.activeNode.isDescendantOf(node)) {
  5687. this.activeNode.setActive(false); // TODO: don't fire events
  5688. }
  5689. if (this.focusNode && this.focusNode.isDescendantOf(node)) {
  5690. this.focusNode = null;
  5691. }
  5692. // TODO: persist must take care to clear select and expand cookies
  5693. this.nodeRemoveChildMarkup(ctx);
  5694. // Unlink children to support GC
  5695. // TODO: also delete this.children (not possible using visit())
  5696. // subCtx = $.extend({}, ctx);
  5697. node.triggerModifyChild("remove", null);
  5698. node.visit(function(n) {
  5699. n.parent = null;
  5700. tree._callHook("treeRegisterNode", tree, false, n);
  5701. });
  5702. if (node.lazy) {
  5703. // 'undefined' would be interpreted as 'not yet loaded' for lazy nodes
  5704. node.children = [];
  5705. } else {
  5706. node.children = null;
  5707. }
  5708. if (!node.isRootNode()) {
  5709. node.expanded = false; // #449, #459
  5710. }
  5711. this.nodeRenderStatus(ctx);
  5712. },
  5713. /**Remove HTML markup for ctx.node and all its descendents.
  5714. * @param {EventData} ctx
  5715. */
  5716. nodeRemoveMarkup: function(ctx) {
  5717. var node = ctx.node;
  5718. // FT.debug("nodeRemoveMarkup()", node.toString());
  5719. // TODO: Unlink attr.ftnode to support GC
  5720. if (node.li) {
  5721. $(node.li).remove();
  5722. node.li = null;
  5723. }
  5724. this.nodeRemoveChildMarkup(ctx);
  5725. },
  5726. /**
  5727. * Create `<li><span>..</span> .. </li>` tags for this node.
  5728. *
  5729. * This method takes care that all HTML markup is created that is required
  5730. * to display this node in its current state.
  5731. *
  5732. * Call this method to create new nodes, or after the strucuture
  5733. * was changed (e.g. after moving this node or adding/removing children)
  5734. * nodeRenderTitle() and nodeRenderStatus() are implied.
  5735. *
  5736. * ```html
  5737. * <li id='KEY' ftnode=NODE>
  5738. * <span class='fancytree-node fancytree-expanded fancytree-has-children fancytree-lastsib fancytree-exp-el fancytree-ico-e'>
  5739. * <span class="fancytree-expander"></span>
  5740. * <span class="fancytree-checkbox"></span> // only present in checkbox mode
  5741. * <span class="fancytree-icon"></span>
  5742. * <a href="#" class="fancytree-title"> Node 1 </a>
  5743. * </span>
  5744. * <ul> // only present if node has children
  5745. * <li id='KEY' ftnode=NODE> child1 ... </li>
  5746. * <li id='KEY' ftnode=NODE> child2 ... </li>
  5747. * </ul>
  5748. * </li>
  5749. * ```
  5750. *
  5751. * @param {EventData} ctx
  5752. * @param {boolean} [force=false] re-render, even if html markup was already created
  5753. * @param {boolean} [deep=false] also render all descendants, even if parent is collapsed
  5754. * @param {boolean} [collapsed=false] force root node to be collapsed, so we can apply animated expand later
  5755. */
  5756. nodeRender: function(ctx, force, deep, collapsed, _recursive) {
  5757. /* This method must take care of all cases where the current data mode
  5758. * (i.e. node hierarchy) does not match the current markup.
  5759. *
  5760. * - node was not yet rendered:
  5761. * create markup
  5762. * - node was rendered: exit fast
  5763. * - children have been added
  5764. * - children have been removed
  5765. */
  5766. var childLI,
  5767. childNode1,
  5768. childNode2,
  5769. i,
  5770. l,
  5771. next,
  5772. subCtx,
  5773. node = ctx.node,
  5774. tree = ctx.tree,
  5775. opts = ctx.options,
  5776. aria = opts.aria,
  5777. firstTime = false,
  5778. parent = node.parent,
  5779. isRootNode = !parent,
  5780. children = node.children,
  5781. successorLi = null;
  5782. // FT.debug("nodeRender(" + !!force + ", " + !!deep + ")", node.toString());
  5783. if (tree._enableUpdate === false) {
  5784. // tree.debug("no render", tree._enableUpdate);
  5785. return;
  5786. }
  5787. if (!isRootNode && !parent.ul) {
  5788. // Calling node.collapse on a deep, unrendered node
  5789. return;
  5790. }
  5791. _assert(isRootNode || parent.ul, "parent UL must exist");
  5792. // Render the node
  5793. if (!isRootNode) {
  5794. // Discard markup on force-mode, or if it is not linked to parent <ul>
  5795. if (
  5796. node.li &&
  5797. (force || node.li.parentNode !== node.parent.ul)
  5798. ) {
  5799. if (node.li.parentNode === node.parent.ul) {
  5800. // #486: store following node, so we can insert the new markup there later
  5801. successorLi = node.li.nextSibling;
  5802. } else {
  5803. // May happen, when a top-level node was dropped over another
  5804. this.debug(
  5805. "Unlinking " +
  5806. node +
  5807. " (must be child of " +
  5808. node.parent +
  5809. ")"
  5810. );
  5811. }
  5812. // this.debug("nodeRemoveMarkup...");
  5813. this.nodeRemoveMarkup(ctx);
  5814. }
  5815. // Create <li><span /> </li>
  5816. // node.debug("render...");
  5817. if (node.li) {
  5818. // this.nodeRenderTitle(ctx);
  5819. this.nodeRenderStatus(ctx);
  5820. } else {
  5821. // node.debug("render... really");
  5822. firstTime = true;
  5823. node.li = document.createElement("li");
  5824. node.li.ftnode = node;
  5825. if (node.key && opts.generateIds) {
  5826. node.li.id = opts.idPrefix + node.key;
  5827. }
  5828. node.span = document.createElement("span");
  5829. node.span.className = "fancytree-node";
  5830. if (aria && !node.tr) {
  5831. $(node.li).attr("role", "treeitem");
  5832. }
  5833. node.li.appendChild(node.span);
  5834. // Create inner HTML for the <span> (expander, checkbox, icon, and title)
  5835. this.nodeRenderTitle(ctx);
  5836. // Allow tweaking and binding, after node was created for the first time
  5837. if (opts.createNode) {
  5838. opts.createNode.call(
  5839. tree,
  5840. { type: "createNode" },
  5841. ctx
  5842. );
  5843. }
  5844. }
  5845. // Allow tweaking after node state was rendered
  5846. if (opts.renderNode) {
  5847. opts.renderNode.call(tree, { type: "renderNode" }, ctx);
  5848. }
  5849. }
  5850. // Visit child nodes
  5851. if (children) {
  5852. if (isRootNode || node.expanded || deep === true) {
  5853. // Create a UL to hold the children
  5854. if (!node.ul) {
  5855. node.ul = document.createElement("ul");
  5856. if (
  5857. (collapsed === true && !_recursive) ||
  5858. !node.expanded
  5859. ) {
  5860. // hide top UL, so we can use an animation to show it later
  5861. node.ul.style.display = "none";
  5862. }
  5863. if (aria) {
  5864. $(node.ul).attr("role", "group");
  5865. }
  5866. if (node.li) {
  5867. // issue #67
  5868. node.li.appendChild(node.ul);
  5869. } else {
  5870. node.tree.$div.append(node.ul);
  5871. }
  5872. }
  5873. // Add child markup
  5874. for (i = 0, l = children.length; i < l; i++) {
  5875. subCtx = $.extend({}, ctx, { node: children[i] });
  5876. this.nodeRender(subCtx, force, deep, false, true);
  5877. }
  5878. // Remove <li> if nodes have moved to another parent
  5879. childLI = node.ul.firstChild;
  5880. while (childLI) {
  5881. childNode2 = childLI.ftnode;
  5882. if (childNode2 && childNode2.parent !== node) {
  5883. node.debug(
  5884. "_fixParent: remove missing " + childNode2,
  5885. childLI
  5886. );
  5887. next = childLI.nextSibling;
  5888. childLI.parentNode.removeChild(childLI);
  5889. childLI = next;
  5890. } else {
  5891. childLI = childLI.nextSibling;
  5892. }
  5893. }
  5894. // Make sure, that <li> order matches node.children order.
  5895. childLI = node.ul.firstChild;
  5896. for (i = 0, l = children.length - 1; i < l; i++) {
  5897. childNode1 = children[i];
  5898. childNode2 = childLI.ftnode;
  5899. if (childNode1 === childNode2) {
  5900. childLI = childLI.nextSibling;
  5901. } else {
  5902. // node.debug("_fixOrder: mismatch at index " + i + ": " + childNode1 + " != " + childNode2);
  5903. node.ul.insertBefore(
  5904. childNode1.li,
  5905. childNode2.li
  5906. );
  5907. }
  5908. }
  5909. }
  5910. } else {
  5911. // No children: remove markup if any
  5912. if (node.ul) {
  5913. // alert("remove child markup for " + node);
  5914. this.warn("remove child markup for " + node);
  5915. this.nodeRemoveChildMarkup(ctx);
  5916. }
  5917. }
  5918. if (!isRootNode) {
  5919. // Update element classes according to node state
  5920. // this.nodeRenderStatus(ctx);
  5921. // Finally add the whole structure to the DOM, so the browser can render
  5922. if (firstTime) {
  5923. // #486: successorLi is set, if we re-rendered (i.e. discarded)
  5924. // existing markup, which we want to insert at the same position.
  5925. // (null is equivalent to append)
  5926. // parent.ul.appendChild(node.li);
  5927. parent.ul.insertBefore(node.li, successorLi);
  5928. }
  5929. }
  5930. },
  5931. /** Create HTML inside the node's outer `<span>` (i.e. expander, checkbox,
  5932. * icon, and title).
  5933. *
  5934. * nodeRenderStatus() is implied.
  5935. * @param {EventData} ctx
  5936. * @param {string} [title] optinal new title
  5937. */
  5938. nodeRenderTitle: function(ctx, title) {
  5939. // set node connector images, links and text
  5940. var checkbox,
  5941. className,
  5942. icon,
  5943. nodeTitle,
  5944. role,
  5945. tabindex,
  5946. tooltip,
  5947. iconTooltip,
  5948. node = ctx.node,
  5949. tree = ctx.tree,
  5950. opts = ctx.options,
  5951. aria = opts.aria,
  5952. level = node.getLevel(),
  5953. ares = [];
  5954. if (title !== undefined) {
  5955. node.title = title;
  5956. }
  5957. if (!node.span || tree._enableUpdate === false) {
  5958. // Silently bail out if node was not rendered yet, assuming
  5959. // node.render() will be called as the node becomes visible
  5960. return;
  5961. }
  5962. // Connector (expanded, expandable or simple)
  5963. role =
  5964. aria && node.hasChildren() !== false
  5965. ? " role='button'"
  5966. : "";
  5967. if (level < opts.minExpandLevel) {
  5968. if (!node.lazy) {
  5969. node.expanded = true;
  5970. }
  5971. if (level > 1) {
  5972. ares.push(
  5973. "<span " +
  5974. role +
  5975. " class='fancytree-expander fancytree-expander-fixed'></span>"
  5976. );
  5977. }
  5978. // .. else (i.e. for root level) skip expander/connector alltogether
  5979. } else {
  5980. ares.push(
  5981. "<span " + role + " class='fancytree-expander'></span>"
  5982. );
  5983. }
  5984. // Checkbox mode
  5985. checkbox = FT.evalOption("checkbox", node, node, opts, false);
  5986. if (checkbox && !node.isStatusNode()) {
  5987. role = aria ? " role='checkbox'" : "";
  5988. className = "fancytree-checkbox";
  5989. if (
  5990. checkbox === "radio" ||
  5991. (node.parent && node.parent.radiogroup)
  5992. ) {
  5993. className += " fancytree-radio";
  5994. }
  5995. ares.push(
  5996. "<span " + role + " class='" + className + "'></span>"
  5997. );
  5998. }
  5999. // Folder or doctype icon
  6000. if (node.data.iconClass !== undefined) {
  6001. // 2015-11-16
  6002. // Handle / warn about backward compatibility
  6003. if (node.icon) {
  6004. $.error(
  6005. "'iconClass' node option is deprecated since v2.14.0: use 'icon' only instead"
  6006. );
  6007. } else {
  6008. node.warn(
  6009. "'iconClass' node option is deprecated since v2.14.0: use 'icon' instead"
  6010. );
  6011. node.icon = node.data.iconClass;
  6012. }
  6013. }
  6014. // If opts.icon is a callback and returns something other than undefined, use that
  6015. // else if node.icon is a boolean or string, use that
  6016. // else if opts.icon is a boolean or string, use that
  6017. // else show standard icon (which may be different for folders or documents)
  6018. icon = FT.evalOption("icon", node, node, opts, true);
  6019. // if( typeof icon !== "boolean" ) {
  6020. // // icon is defined, but not true/false: must be a string
  6021. // icon = "" + icon;
  6022. // }
  6023. if (icon !== false) {
  6024. role = aria ? " role='presentation'" : "";
  6025. iconTooltip = FT.evalOption(
  6026. "iconTooltip",
  6027. node,
  6028. node,
  6029. opts,
  6030. null
  6031. );
  6032. iconTooltip = iconTooltip
  6033. ? " title='" + _escapeTooltip(iconTooltip) + "'"
  6034. : "";
  6035. if (typeof icon === "string") {
  6036. if (TEST_IMG.test(icon)) {
  6037. // node.icon is an image url. Prepend imagePath
  6038. icon =
  6039. icon.charAt(0) === "/"
  6040. ? icon
  6041. : (opts.imagePath || "") + icon;
  6042. ares.push(
  6043. "<img src='" +
  6044. icon +
  6045. "' class='fancytree-icon'" +
  6046. iconTooltip +
  6047. " alt='' />"
  6048. );
  6049. } else {
  6050. ares.push(
  6051. "<span " +
  6052. role +
  6053. " class='fancytree-custom-icon " +
  6054. icon +
  6055. "'" +
  6056. iconTooltip +
  6057. "></span>"
  6058. );
  6059. }
  6060. } else if (icon.text) {
  6061. ares.push(
  6062. "<span " +
  6063. role +
  6064. " class='fancytree-custom-icon " +
  6065. (icon.addClass || "") +
  6066. "'" +
  6067. iconTooltip +
  6068. ">" +
  6069. FT.escapeHtml(icon.text) +
  6070. "</span>"
  6071. );
  6072. } else if (icon.html) {
  6073. ares.push(
  6074. "<span " +
  6075. role +
  6076. " class='fancytree-custom-icon " +
  6077. (icon.addClass || "") +
  6078. "'" +
  6079. iconTooltip +
  6080. ">" +
  6081. icon.html +
  6082. "</span>"
  6083. );
  6084. } else {
  6085. // standard icon: theme css will take care of this
  6086. ares.push(
  6087. "<span " +
  6088. role +
  6089. " class='fancytree-icon'" +
  6090. iconTooltip +
  6091. "></span>"
  6092. );
  6093. }
  6094. }
  6095. // Node title
  6096. nodeTitle = "";
  6097. if (opts.renderTitle) {
  6098. nodeTitle =
  6099. opts.renderTitle.call(
  6100. tree,
  6101. { type: "renderTitle" },
  6102. ctx
  6103. ) || "";
  6104. }
  6105. if (!nodeTitle) {
  6106. tooltip = FT.evalOption("tooltip", node, node, opts, null);
  6107. if (tooltip === true) {
  6108. tooltip = node.title;
  6109. }
  6110. // if( node.tooltip ) {
  6111. // tooltip = node.tooltip;
  6112. // } else if ( opts.tooltip ) {
  6113. // tooltip = opts.tooltip === true ? node.title : opts.tooltip.call(tree, node);
  6114. // }
  6115. tooltip = tooltip
  6116. ? " title='" + _escapeTooltip(tooltip) + "'"
  6117. : "";
  6118. tabindex = opts.titlesTabbable ? " tabindex='0'" : "";
  6119. nodeTitle =
  6120. "<span class='fancytree-title'" +
  6121. tooltip +
  6122. tabindex +
  6123. ">" +
  6124. (opts.escapeTitles
  6125. ? FT.escapeHtml(node.title)
  6126. : node.title) +
  6127. "</span>";
  6128. }
  6129. ares.push(nodeTitle);
  6130. // Note: this will trigger focusout, if node had the focus
  6131. //$(node.span).html(ares.join("")); // it will cleanup the jQuery data currently associated with SPAN (if any), but it executes more slowly
  6132. node.span.innerHTML = ares.join("");
  6133. // Update CSS classes
  6134. this.nodeRenderStatus(ctx);
  6135. if (opts.enhanceTitle) {
  6136. ctx.$title = $(">span.fancytree-title", node.span);
  6137. nodeTitle =
  6138. opts.enhanceTitle.call(
  6139. tree,
  6140. { type: "enhanceTitle" },
  6141. ctx
  6142. ) || "";
  6143. }
  6144. },
  6145. /** Update element classes according to node state.
  6146. * @param {EventData} ctx
  6147. */
  6148. nodeRenderStatus: function(ctx) {
  6149. // Set classes for current status
  6150. var $ariaElem,
  6151. node = ctx.node,
  6152. tree = ctx.tree,
  6153. opts = ctx.options,
  6154. // nodeContainer = node[tree.nodeContainerAttrName],
  6155. hasChildren = node.hasChildren(),
  6156. isLastSib = node.isLastSibling(),
  6157. aria = opts.aria,
  6158. cn = opts._classNames,
  6159. cnList = [],
  6160. statusElem = node[tree.statusClassPropName];
  6161. if (!statusElem || tree._enableUpdate === false) {
  6162. // if this function is called for an unrendered node, ignore it (will be updated on nect render anyway)
  6163. return;
  6164. }
  6165. if (aria) {
  6166. $ariaElem = $(node.tr || node.li);
  6167. }
  6168. // Build a list of class names that we will add to the node <span>
  6169. cnList.push(cn.node);
  6170. if (tree.activeNode === node) {
  6171. cnList.push(cn.active);
  6172. // $(">span.fancytree-title", statusElem).attr("tabindex", "0");
  6173. // tree.$container.removeAttr("tabindex");
  6174. // }else{
  6175. // $(">span.fancytree-title", statusElem).removeAttr("tabindex");
  6176. // tree.$container.attr("tabindex", "0");
  6177. }
  6178. if (tree.focusNode === node) {
  6179. cnList.push(cn.focused);
  6180. }
  6181. if (node.expanded) {
  6182. cnList.push(cn.expanded);
  6183. }
  6184. if (aria) {
  6185. if (hasChildren === false) {
  6186. $ariaElem.removeAttr("aria-expanded");
  6187. } else {
  6188. $ariaElem.attr("aria-expanded", Boolean(node.expanded));
  6189. }
  6190. }
  6191. if (node.folder) {
  6192. cnList.push(cn.folder);
  6193. }
  6194. if (hasChildren !== false) {
  6195. cnList.push(cn.hasChildren);
  6196. }
  6197. // TODO: required?
  6198. if (isLastSib) {
  6199. cnList.push(cn.lastsib);
  6200. }
  6201. if (node.lazy && node.children == null) {
  6202. cnList.push(cn.lazy);
  6203. }
  6204. if (node.partload) {
  6205. cnList.push(cn.partload);
  6206. }
  6207. if (node.partsel) {
  6208. cnList.push(cn.partsel);
  6209. }
  6210. if (FT.evalOption("unselectable", node, node, opts, false)) {
  6211. cnList.push(cn.unselectable);
  6212. }
  6213. if (node._isLoading) {
  6214. cnList.push(cn.loading);
  6215. }
  6216. if (node._error) {
  6217. cnList.push(cn.error);
  6218. }
  6219. if (node.statusNodeType) {
  6220. cnList.push(cn.statusNodePrefix + node.statusNodeType);
  6221. }
  6222. if (node.selected) {
  6223. cnList.push(cn.selected);
  6224. if (aria) {
  6225. $ariaElem.attr("aria-selected", true);
  6226. }
  6227. } else if (aria) {
  6228. $ariaElem.attr("aria-selected", false);
  6229. }
  6230. if (node.extraClasses) {
  6231. cnList.push(node.extraClasses);
  6232. }
  6233. // IE6 doesn't correctly evaluate multiple class names,
  6234. // so we create combined class names that can be used in the CSS
  6235. if (hasChildren === false) {
  6236. cnList.push(
  6237. cn.combinedExpanderPrefix + "n" + (isLastSib ? "l" : "")
  6238. );
  6239. } else {
  6240. cnList.push(
  6241. cn.combinedExpanderPrefix +
  6242. (node.expanded ? "e" : "c") +
  6243. (node.lazy && node.children == null ? "d" : "") +
  6244. (isLastSib ? "l" : "")
  6245. );
  6246. }
  6247. cnList.push(
  6248. cn.combinedIconPrefix +
  6249. (node.expanded ? "e" : "c") +
  6250. (node.folder ? "f" : "")
  6251. );
  6252. // node.span.className = cnList.join(" ");
  6253. statusElem.className = cnList.join(" ");
  6254. // TODO: we should not set this in the <span> tag also, if we set it here:
  6255. // Maybe most (all) of the classes should be set in LI instead of SPAN?
  6256. if (node.li) {
  6257. // #719: we have to consider that there may be already other classes:
  6258. $(node.li).toggleClass(cn.lastsib, isLastSib);
  6259. }
  6260. },
  6261. /** Activate node.
  6262. * flag defaults to true.
  6263. * If flag is true, the node is activated (must be a synchronous operation)
  6264. * If flag is false, the node is deactivated (must be a synchronous operation)
  6265. * @param {EventData} ctx
  6266. * @param {boolean} [flag=true]
  6267. * @param {object} [opts] additional options. Defaults to {noEvents: false, noFocus: false}
  6268. * @returns {$.Promise}
  6269. */
  6270. nodeSetActive: function(ctx, flag, callOpts) {
  6271. // Handle user click / [space] / [enter], according to clickFolderMode.
  6272. callOpts = callOpts || {};
  6273. var subCtx,
  6274. node = ctx.node,
  6275. tree = ctx.tree,
  6276. opts = ctx.options,
  6277. noEvents = callOpts.noEvents === true,
  6278. noFocus = callOpts.noFocus === true,
  6279. scroll = callOpts.scrollIntoView !== false,
  6280. isActive = node === tree.activeNode;
  6281. // flag defaults to true
  6282. flag = flag !== false;
  6283. // node.debug("nodeSetActive", flag);
  6284. if (isActive === flag) {
  6285. // Nothing to do
  6286. return _getResolvedPromise(node);
  6287. } else if (
  6288. flag &&
  6289. !noEvents &&
  6290. this._triggerNodeEvent(
  6291. "beforeActivate",
  6292. node,
  6293. ctx.originalEvent
  6294. ) === false
  6295. ) {
  6296. // Callback returned false
  6297. return _getRejectedPromise(node, ["rejected"]);
  6298. }
  6299. if (flag) {
  6300. if (tree.activeNode) {
  6301. _assert(
  6302. tree.activeNode !== node,
  6303. "node was active (inconsistency)"
  6304. );
  6305. subCtx = $.extend({}, ctx, { node: tree.activeNode });
  6306. tree.nodeSetActive(subCtx, false);
  6307. _assert(
  6308. tree.activeNode === null,
  6309. "deactivate was out of sync?"
  6310. );
  6311. }
  6312. if (opts.activeVisible) {
  6313. // If no focus is set (noFocus: true) and there is no focused node, this node is made visible.
  6314. // scroll = noFocus && tree.focusNode == null;
  6315. // #863: scroll by default (unless `scrollIntoView: false` was passed)
  6316. node.makeVisible({ scrollIntoView: scroll });
  6317. }
  6318. tree.activeNode = node;
  6319. tree.nodeRenderStatus(ctx);
  6320. if (!noFocus) {
  6321. tree.nodeSetFocus(ctx);
  6322. }
  6323. if (!noEvents) {
  6324. tree._triggerNodeEvent(
  6325. "activate",
  6326. node,
  6327. ctx.originalEvent
  6328. );
  6329. }
  6330. } else {
  6331. _assert(
  6332. tree.activeNode === node,
  6333. "node was not active (inconsistency)"
  6334. );
  6335. tree.activeNode = null;
  6336. this.nodeRenderStatus(ctx);
  6337. if (!noEvents) {
  6338. ctx.tree._triggerNodeEvent(
  6339. "deactivate",
  6340. node,
  6341. ctx.originalEvent
  6342. );
  6343. }
  6344. }
  6345. return _getResolvedPromise(node);
  6346. },
  6347. /** Expand or collapse node, return Deferred.promise.
  6348. *
  6349. * @param {EventData} ctx
  6350. * @param {boolean} [flag=true]
  6351. * @param {object} [opts] additional options. Defaults to `{noAnimation: false, noEvents: false}`
  6352. * @returns {$.Promise} The deferred will be resolved as soon as the (lazy)
  6353. * data was retrieved, rendered, and the expand animation finished.
  6354. */
  6355. nodeSetExpanded: function(ctx, flag, callOpts) {
  6356. callOpts = callOpts || {};
  6357. var _afterLoad,
  6358. dfd,
  6359. i,
  6360. l,
  6361. parents,
  6362. prevAC,
  6363. node = ctx.node,
  6364. tree = ctx.tree,
  6365. opts = ctx.options,
  6366. noAnimation = callOpts.noAnimation === true,
  6367. noEvents = callOpts.noEvents === true;
  6368. // flag defaults to true
  6369. flag = flag !== false;
  6370. // node.debug("nodeSetExpanded(" + flag + ")");
  6371. if ($(node.li).hasClass(opts._classNames.animating)) {
  6372. node.warn(
  6373. "setExpanded(" + flag + ") while animating: ignored."
  6374. );
  6375. return _getRejectedPromise(node, ["recursion"]);
  6376. }
  6377. if ((node.expanded && flag) || (!node.expanded && !flag)) {
  6378. // Nothing to do
  6379. // node.debug("nodeSetExpanded(" + flag + "): nothing to do");
  6380. return _getResolvedPromise(node);
  6381. } else if (flag && !node.lazy && !node.hasChildren()) {
  6382. // Prevent expanding of empty nodes
  6383. // return _getRejectedPromise(node, ["empty"]);
  6384. return _getResolvedPromise(node);
  6385. } else if (!flag && node.getLevel() < opts.minExpandLevel) {
  6386. // Prevent collapsing locked levels
  6387. return _getRejectedPromise(node, ["locked"]);
  6388. } else if (
  6389. !noEvents &&
  6390. this._triggerNodeEvent(
  6391. "beforeExpand",
  6392. node,
  6393. ctx.originalEvent
  6394. ) === false
  6395. ) {
  6396. // Callback returned false
  6397. return _getRejectedPromise(node, ["rejected"]);
  6398. }
  6399. // If this node inside a collpased node, no animation and scrolling is needed
  6400. if (!noAnimation && !node.isVisible()) {
  6401. noAnimation = callOpts.noAnimation = true;
  6402. }
  6403. dfd = new $.Deferred();
  6404. // Auto-collapse mode: collapse all siblings
  6405. if (flag && !node.expanded && opts.autoCollapse) {
  6406. parents = node.getParentList(false, true);
  6407. prevAC = opts.autoCollapse;
  6408. try {
  6409. opts.autoCollapse = false;
  6410. for (i = 0, l = parents.length; i < l; i++) {
  6411. // TODO: should return promise?
  6412. this._callHook(
  6413. "nodeCollapseSiblings",
  6414. parents[i],
  6415. callOpts
  6416. );
  6417. }
  6418. } finally {
  6419. opts.autoCollapse = prevAC;
  6420. }
  6421. }
  6422. // Trigger expand/collapse after expanding
  6423. dfd.done(function() {
  6424. var lastChild = node.getLastChild();
  6425. if (
  6426. flag &&
  6427. opts.autoScroll &&
  6428. !noAnimation &&
  6429. lastChild &&
  6430. tree._enableUpdate
  6431. ) {
  6432. // Scroll down to last child, but keep current node visible
  6433. lastChild
  6434. .scrollIntoView(true, { topNode: node })
  6435. .always(function() {
  6436. if (!noEvents) {
  6437. ctx.tree._triggerNodeEvent(
  6438. flag ? "expand" : "collapse",
  6439. ctx
  6440. );
  6441. }
  6442. });
  6443. } else {
  6444. if (!noEvents) {
  6445. ctx.tree._triggerNodeEvent(
  6446. flag ? "expand" : "collapse",
  6447. ctx
  6448. );
  6449. }
  6450. }
  6451. });
  6452. // vvv Code below is executed after loading finished:
  6453. _afterLoad = function(callback) {
  6454. var cn = opts._classNames,
  6455. isVisible,
  6456. isExpanded,
  6457. effect = opts.toggleEffect;
  6458. node.expanded = flag;
  6459. tree._callHook(
  6460. "treeStructureChanged",
  6461. ctx,
  6462. flag ? "expand" : "collapse"
  6463. );
  6464. // Create required markup, but make sure the top UL is hidden, so we
  6465. // can animate later
  6466. tree._callHook("nodeRender", ctx, false, false, true);
  6467. // Hide children, if node is collapsed
  6468. if (node.ul) {
  6469. isVisible = node.ul.style.display !== "none";
  6470. isExpanded = !!node.expanded;
  6471. if (isVisible === isExpanded) {
  6472. node.warn(
  6473. "nodeSetExpanded: UL.style.display already set"
  6474. );
  6475. } else if (!effect || noAnimation) {
  6476. node.ul.style.display =
  6477. node.expanded || !parent ? "" : "none";
  6478. } else {
  6479. // The UI toggle() effect works with the ext-wide extension,
  6480. // while jQuery.animate() has problems when the title span
  6481. // has position: absolute.
  6482. // Since jQuery UI 1.12, the blind effect requires the parent
  6483. // element to have 'position: relative'.
  6484. // See #716, #717
  6485. $(node.li).addClass(cn.animating); // #717
  6486. if ($.isFunction($(node.ul)[effect.effect])) {
  6487. // tree.debug( "use jquery." + effect.effect + " method" );
  6488. $(node.ul)[effect.effect]({
  6489. duration: effect.duration,
  6490. always: function() {
  6491. // node.debug("fancytree-animating end: " + node.li.className);
  6492. $(this).removeClass(cn.animating); // #716
  6493. $(node.li).removeClass(cn.animating); // #717
  6494. callback();
  6495. },
  6496. });
  6497. } else {
  6498. // The UI toggle() effect works with the ext-wide extension,
  6499. // while jQuery.animate() has problems when the title span
  6500. // has positon: absolute.
  6501. // Since jQuery UI 1.12, the blind effect requires the parent
  6502. // element to have 'position: relative'.
  6503. // See #716, #717
  6504. // tree.debug("use specified effect (" + effect.effect + ") with the jqueryui.toggle method");
  6505. // try to stop an animation that might be already in progress
  6506. $(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"
  6507. // dirty fix to remove a defunct animation (effect: "blind") after resetLazy has been called
  6508. $(node.ul)
  6509. .parent()
  6510. .find(".ui-effects-placeholder")
  6511. .remove();
  6512. $(node.ul).toggle(
  6513. effect.effect,
  6514. effect.options,
  6515. effect.duration,
  6516. function() {
  6517. // node.debug("fancytree-animating end: " + node.li.className);
  6518. $(this).removeClass(cn.animating); // #716
  6519. $(node.li).removeClass(cn.animating); // #717
  6520. callback();
  6521. }
  6522. );
  6523. }
  6524. return;
  6525. }
  6526. }
  6527. callback();
  6528. };
  6529. // ^^^ Code above is executed after loading finshed.
  6530. // Load lazy nodes, if any. Then continue with _afterLoad()
  6531. if (flag && node.lazy && node.hasChildren() === undefined) {
  6532. // node.debug("nodeSetExpanded: load start...");
  6533. node.load()
  6534. .done(function() {
  6535. // node.debug("nodeSetExpanded: load done");
  6536. if (dfd.notifyWith) {
  6537. // requires jQuery 1.6+
  6538. dfd.notifyWith(node, ["loaded"]);
  6539. }
  6540. _afterLoad(function() {
  6541. dfd.resolveWith(node);
  6542. });
  6543. })
  6544. .fail(function(errMsg) {
  6545. _afterLoad(function() {
  6546. dfd.rejectWith(node, [
  6547. "load failed (" + errMsg + ")",
  6548. ]);
  6549. });
  6550. });
  6551. /*
  6552. var source = tree._triggerNodeEvent("lazyLoad", node, ctx.originalEvent);
  6553. _assert(typeof source !== "boolean", "lazyLoad event must return source in data.result");
  6554. node.debug("nodeSetExpanded: load start...");
  6555. this._callHook("nodeLoadChildren", ctx, source).done(function(){
  6556. node.debug("nodeSetExpanded: load done");
  6557. if(dfd.notifyWith){ // requires jQuery 1.6+
  6558. dfd.notifyWith(node, ["loaded"]);
  6559. }
  6560. _afterLoad.call(tree);
  6561. }).fail(function(errMsg){
  6562. dfd.rejectWith(node, ["load failed (" + errMsg + ")"]);
  6563. });
  6564. */
  6565. } else {
  6566. _afterLoad(function() {
  6567. dfd.resolveWith(node);
  6568. });
  6569. }
  6570. // node.debug("nodeSetExpanded: returns");
  6571. return dfd.promise();
  6572. },
  6573. /** Focus or blur this node.
  6574. * @param {EventData} ctx
  6575. * @param {boolean} [flag=true]
  6576. */
  6577. nodeSetFocus: function(ctx, flag) {
  6578. // ctx.node.debug("nodeSetFocus(" + flag + ")");
  6579. var ctx2,
  6580. tree = ctx.tree,
  6581. node = ctx.node,
  6582. opts = tree.options,
  6583. // et = ctx.originalEvent && ctx.originalEvent.type,
  6584. isInput = ctx.originalEvent
  6585. ? $(ctx.originalEvent.target).is(":input")
  6586. : false;
  6587. flag = flag !== false;
  6588. // (node || tree).debug("nodeSetFocus(" + flag + "), event: " + et + ", isInput: "+ isInput);
  6589. // Blur previous node if any
  6590. if (tree.focusNode) {
  6591. if (tree.focusNode === node && flag) {
  6592. // node.debug("nodeSetFocus(" + flag + "): nothing to do");
  6593. return;
  6594. }
  6595. ctx2 = $.extend({}, ctx, { node: tree.focusNode });
  6596. tree.focusNode = null;
  6597. this._triggerNodeEvent("blur", ctx2);
  6598. this._callHook("nodeRenderStatus", ctx2);
  6599. }
  6600. // Set focus to container and node
  6601. if (flag) {
  6602. if (!this.hasFocus()) {
  6603. node.debug("nodeSetFocus: forcing container focus");
  6604. this._callHook("treeSetFocus", ctx, true, {
  6605. calledByNode: true,
  6606. });
  6607. }
  6608. node.makeVisible({ scrollIntoView: false });
  6609. tree.focusNode = node;
  6610. if (opts.titlesTabbable) {
  6611. if (!isInput) {
  6612. // #621
  6613. $(node.span)
  6614. .find(".fancytree-title")
  6615. .focus();
  6616. }
  6617. }
  6618. if (opts.aria) {
  6619. // Set active descendant to node's span ID (create one, if needed)
  6620. $(tree.$container).attr(
  6621. "aria-activedescendant",
  6622. $(node.tr || node.li)
  6623. .uniqueId()
  6624. .attr("id")
  6625. );
  6626. // "ftal_" + opts.idPrefix + node.key);
  6627. }
  6628. // $(node.span).find(".fancytree-title").focus();
  6629. this._triggerNodeEvent("focus", ctx);
  6630. // determine if we have focus on or inside tree container
  6631. var hasFancytreeFocus =
  6632. document.activeElement === tree.$container.get(0) ||
  6633. $(document.activeElement, tree.$container).length >= 1;
  6634. if (!hasFancytreeFocus) {
  6635. // We cannot set KB focus to a node, so use the tree container
  6636. // #563, #570: IE scrolls on every call to .focus(), if the container
  6637. // is partially outside the viewport. So do it only, when absolutely
  6638. // necessary.
  6639. $(tree.$container).focus();
  6640. }
  6641. // if( opts.autoActivate ){
  6642. // tree.nodeSetActive(ctx, true);
  6643. // }
  6644. if (opts.autoScroll) {
  6645. node.scrollIntoView();
  6646. }
  6647. this._callHook("nodeRenderStatus", ctx);
  6648. }
  6649. },
  6650. /** (De)Select node, return new status (sync).
  6651. *
  6652. * @param {EventData} ctx
  6653. * @param {boolean} [flag=true]
  6654. * @param {object} [opts] additional options. Defaults to {noEvents: false,
  6655. * propagateDown: null, propagateUp: null,
  6656. * callback: null,
  6657. * }
  6658. * @returns {boolean} previous status
  6659. */
  6660. nodeSetSelected: function(ctx, flag, callOpts) {
  6661. callOpts = callOpts || {};
  6662. var node = ctx.node,
  6663. tree = ctx.tree,
  6664. opts = ctx.options,
  6665. noEvents = callOpts.noEvents === true,
  6666. parent = node.parent;
  6667. // flag defaults to true
  6668. flag = flag !== false;
  6669. // node.debug("nodeSetSelected(" + flag + ")", ctx);
  6670. // Cannot (de)select unselectable nodes directly (only by propagation or
  6671. // by setting the `.selected` property)
  6672. if (FT.evalOption("unselectable", node, node, opts, false)) {
  6673. return;
  6674. }
  6675. // Remember the user's intent, in case down -> up propagation prevents
  6676. // applying it to node.selected
  6677. node._lastSelectIntent = flag; // Confusing use of '!'
  6678. // Nothing to do?
  6679. if (!!node.selected === flag) {
  6680. if (opts.selectMode === 3 && node.partsel && !flag) {
  6681. // If propagation prevented selecting this node last time, we still
  6682. // want to allow to apply setSelected(false) now
  6683. } else {
  6684. return flag;
  6685. }
  6686. }
  6687. if (
  6688. !noEvents &&
  6689. this._triggerNodeEvent(
  6690. "beforeSelect",
  6691. node,
  6692. ctx.originalEvent
  6693. ) === false
  6694. ) {
  6695. return !!node.selected;
  6696. }
  6697. if (flag && opts.selectMode === 1) {
  6698. // single selection mode (we don't uncheck all tree nodes, for performance reasons)
  6699. if (tree.lastSelectedNode) {
  6700. tree.lastSelectedNode.setSelected(false);
  6701. }
  6702. node.selected = flag;
  6703. } else if (
  6704. opts.selectMode === 3 &&
  6705. parent &&
  6706. !parent.radiogroup &&
  6707. !node.radiogroup
  6708. ) {
  6709. // multi-hierarchical selection mode
  6710. node.selected = flag;
  6711. node.fixSelection3AfterClick(callOpts);
  6712. } else if (parent && parent.radiogroup) {
  6713. node.visitSiblings(function(n) {
  6714. n._changeSelectStatusAttrs(flag && n === node);
  6715. }, true);
  6716. } else {
  6717. // default: selectMode: 2, multi selection mode
  6718. node.selected = flag;
  6719. }
  6720. this.nodeRenderStatus(ctx);
  6721. tree.lastSelectedNode = flag ? node : null;
  6722. if (!noEvents) {
  6723. tree._triggerNodeEvent("select", ctx);
  6724. }
  6725. },
  6726. /** Show node status (ok, loading, error, nodata) using styles and a dummy child node.
  6727. *
  6728. * @param {EventData} ctx
  6729. * @param status
  6730. * @param message
  6731. * @param details
  6732. * @since 2.3
  6733. */
  6734. nodeSetStatus: function(ctx, status, message, details) {
  6735. var node = ctx.node,
  6736. tree = ctx.tree;
  6737. function _clearStatusNode() {
  6738. // Remove dedicated dummy node, if any
  6739. var firstChild = node.children ? node.children[0] : null;
  6740. if (firstChild && firstChild.isStatusNode()) {
  6741. try {
  6742. // I've seen exceptions here with loadKeyPath...
  6743. if (node.ul) {
  6744. node.ul.removeChild(firstChild.li);
  6745. firstChild.li = null; // avoid leaks (DT issue 215)
  6746. }
  6747. } catch (e) {}
  6748. if (node.children.length === 1) {
  6749. node.children = [];
  6750. } else {
  6751. node.children.shift();
  6752. }
  6753. tree._callHook(
  6754. "treeStructureChanged",
  6755. ctx,
  6756. "clearStatusNode"
  6757. );
  6758. }
  6759. }
  6760. function _setStatusNode(data, type) {
  6761. // Create/modify the dedicated dummy node for 'loading...' or
  6762. // 'error!' status. (only called for direct child of the invisible
  6763. // system root)
  6764. var firstChild = node.children ? node.children[0] : null;
  6765. if (firstChild && firstChild.isStatusNode()) {
  6766. $.extend(firstChild, data);
  6767. firstChild.statusNodeType = type;
  6768. tree._callHook("nodeRenderTitle", firstChild);
  6769. } else {
  6770. node._setChildren([data]);
  6771. tree._callHook(
  6772. "treeStructureChanged",
  6773. ctx,
  6774. "setStatusNode"
  6775. );
  6776. node.children[0].statusNodeType = type;
  6777. tree.render();
  6778. }
  6779. return node.children[0];
  6780. }
  6781. switch (status) {
  6782. case "ok":
  6783. _clearStatusNode();
  6784. node._isLoading = false;
  6785. node._error = null;
  6786. node.renderStatus();
  6787. break;
  6788. case "loading":
  6789. if (!node.parent) {
  6790. _setStatusNode(
  6791. {
  6792. title:
  6793. tree.options.strings.loading +
  6794. (message ? " (" + message + ")" : ""),
  6795. // icon: true, // needed for 'loding' icon
  6796. checkbox: false,
  6797. tooltip: details,
  6798. },
  6799. status
  6800. );
  6801. }
  6802. node._isLoading = true;
  6803. node._error = null;
  6804. node.renderStatus();
  6805. break;
  6806. case "error":
  6807. _setStatusNode(
  6808. {
  6809. title:
  6810. tree.options.strings.loadError +
  6811. (message ? " (" + message + ")" : ""),
  6812. // icon: false,
  6813. checkbox: false,
  6814. tooltip: details,
  6815. },
  6816. status
  6817. );
  6818. node._isLoading = false;
  6819. node._error = { message: message, details: details };
  6820. node.renderStatus();
  6821. break;
  6822. case "nodata":
  6823. _setStatusNode(
  6824. {
  6825. title: message || tree.options.strings.noData,
  6826. // icon: false,
  6827. checkbox: false,
  6828. tooltip: details,
  6829. },
  6830. status
  6831. );
  6832. node._isLoading = false;
  6833. node._error = null;
  6834. node.renderStatus();
  6835. break;
  6836. default:
  6837. $.error("invalid node status " + status);
  6838. }
  6839. },
  6840. /**
  6841. *
  6842. * @param {EventData} ctx
  6843. */
  6844. nodeToggleExpanded: function(ctx) {
  6845. return this.nodeSetExpanded(ctx, !ctx.node.expanded);
  6846. },
  6847. /**
  6848. * @param {EventData} ctx
  6849. */
  6850. nodeToggleSelected: function(ctx) {
  6851. var node = ctx.node,
  6852. flag = !node.selected;
  6853. // In selectMode: 3 this node may be unselected+partsel, even if
  6854. // setSelected(true) was called before, due to `unselectable` children.
  6855. // In this case, we now toggle as `setSelected(false)`
  6856. if (
  6857. node.partsel &&
  6858. !node.selected &&
  6859. node._lastSelectIntent === true
  6860. ) {
  6861. flag = false;
  6862. node.selected = true; // so it is not considered 'nothing to do'
  6863. }
  6864. node._lastSelectIntent = flag;
  6865. return this.nodeSetSelected(ctx, flag);
  6866. },
  6867. /** Remove all nodes.
  6868. * @param {EventData} ctx
  6869. */
  6870. treeClear: function(ctx) {
  6871. var tree = ctx.tree;
  6872. tree.activeNode = null;
  6873. tree.focusNode = null;
  6874. tree.$div.find(">ul.fancytree-container").empty();
  6875. // TODO: call destructors and remove reference loops
  6876. tree.rootNode.children = null;
  6877. tree._callHook("treeStructureChanged", ctx, "clear");
  6878. },
  6879. /** Widget was created (called only once, even it re-initialized).
  6880. * @param {EventData} ctx
  6881. */
  6882. treeCreate: function(ctx) {},
  6883. /** Widget was destroyed.
  6884. * @param {EventData} ctx
  6885. */
  6886. treeDestroy: function(ctx) {
  6887. this.$div.find(">ul.fancytree-container").remove();
  6888. if (this.$source) {
  6889. this.$source.removeClass("fancytree-helper-hidden");
  6890. }
  6891. },
  6892. /** Widget was (re-)initialized.
  6893. * @param {EventData} ctx
  6894. */
  6895. treeInit: function(ctx) {
  6896. var tree = ctx.tree,
  6897. opts = tree.options;
  6898. //this.debug("Fancytree.treeInit()");
  6899. // Add container to the TAB chain
  6900. // See http://www.w3.org/TR/wai-aria-practices/#focus_activedescendant
  6901. // #577: Allow to set tabindex to "0", "-1" and ""
  6902. tree.$container.attr("tabindex", opts.tabindex);
  6903. // Copy some attributes to tree.data
  6904. $.each(TREE_ATTRS, function(i, attr) {
  6905. if (opts[attr] !== undefined) {
  6906. tree.info("Move option " + attr + " to tree");
  6907. tree[attr] = opts[attr];
  6908. delete opts[attr];
  6909. }
  6910. });
  6911. if (opts.checkboxAutoHide) {
  6912. tree.$container.addClass("fancytree-checkbox-auto-hide");
  6913. }
  6914. if (opts.rtl) {
  6915. tree.$container
  6916. .attr("DIR", "RTL")
  6917. .addClass("fancytree-rtl");
  6918. } else {
  6919. tree.$container
  6920. .removeAttr("DIR")
  6921. .removeClass("fancytree-rtl");
  6922. }
  6923. if (opts.aria) {
  6924. tree.$container.attr("role", "tree");
  6925. if (opts.selectMode !== 1) {
  6926. tree.$container.attr("aria-multiselectable", true);
  6927. }
  6928. }
  6929. this.treeLoad(ctx);
  6930. },
  6931. /** Parse Fancytree from source, as configured in the options.
  6932. * @param {EventData} ctx
  6933. * @param {object} [source] optional new source (use last data otherwise)
  6934. */
  6935. treeLoad: function(ctx, source) {
  6936. var metaData,
  6937. type,
  6938. $ul,
  6939. tree = ctx.tree,
  6940. $container = ctx.widget.element,
  6941. dfd,
  6942. // calling context for root node
  6943. rootCtx = $.extend({}, ctx, { node: this.rootNode });
  6944. if (tree.rootNode.children) {
  6945. this.treeClear(ctx);
  6946. }
  6947. source = source || this.options.source;
  6948. if (!source) {
  6949. type = $container.data("type") || "html";
  6950. switch (type) {
  6951. case "html":
  6952. // There should be an embedded `<ul>` with initial nodes,
  6953. // but another `<ul class='fancytree-container'>` is appended
  6954. // to the tree's <div> on startup anyway.
  6955. $ul = $container
  6956. .find(">ul")
  6957. .not(".fancytree-container")
  6958. .first();
  6959. if ($ul.length) {
  6960. $ul.addClass(
  6961. "ui-fancytree-source fancytree-helper-hidden"
  6962. );
  6963. source = $.ui.fancytree.parseHtml($ul);
  6964. // allow to init tree.data.foo from <ul data-foo=''>
  6965. this.data = $.extend(
  6966. this.data,
  6967. _getElementDataAsDict($ul)
  6968. );
  6969. } else {
  6970. FT.warn(
  6971. "No `source` option was passed and container does not contain `<ul>`: assuming `source: []`."
  6972. );
  6973. source = [];
  6974. }
  6975. break;
  6976. case "json":
  6977. source = $.parseJSON($container.text());
  6978. // $container already contains the <ul>, but we remove the plain (json) text
  6979. // $container.empty();
  6980. $container
  6981. .contents()
  6982. .filter(function() {
  6983. return this.nodeType === 3;
  6984. })
  6985. .remove();
  6986. if ($.isPlainObject(source)) {
  6987. // We got {foo: 'abc', children: [...]}
  6988. _assert(
  6989. $.isArray(source.children),
  6990. "if an object is passed as source, it must contain a 'children' array (all other properties are added to 'tree.data')"
  6991. );
  6992. metaData = source;
  6993. source = source.children;
  6994. delete metaData.children;
  6995. // Copy some attributes to tree.data
  6996. $.each(TREE_ATTRS, function(i, attr) {
  6997. if (metaData[attr] !== undefined) {
  6998. tree[attr] = metaData[attr];
  6999. delete metaData[attr];
  7000. }
  7001. });
  7002. // Copy extra properties to tree.data.foo
  7003. $.extend(tree.data, metaData);
  7004. }
  7005. break;
  7006. default:
  7007. $.error("Invalid data-type: " + type);
  7008. }
  7009. } else if (typeof source === "string") {
  7010. // TODO: source is an element ID
  7011. $.error("Not implemented");
  7012. }
  7013. // preInit is fired when the widget markup is created, but nodes
  7014. // not yet loaded
  7015. tree._triggerTreeEvent("preInit", null);
  7016. // Trigger fancytreeinit after nodes have been loaded
  7017. dfd = this.nodeLoadChildren(rootCtx, source)
  7018. .done(function() {
  7019. tree._callHook(
  7020. "treeStructureChanged",
  7021. ctx,
  7022. "loadChildren"
  7023. );
  7024. tree.render();
  7025. if (ctx.options.selectMode === 3) {
  7026. tree.rootNode.fixSelection3FromEndNodes();
  7027. }
  7028. if (tree.activeNode && tree.options.activeVisible) {
  7029. tree.activeNode.makeVisible();
  7030. }
  7031. tree._triggerTreeEvent("init", null, { status: true });
  7032. })
  7033. .fail(function() {
  7034. tree.render();
  7035. tree._triggerTreeEvent("init", null, { status: false });
  7036. });
  7037. return dfd;
  7038. },
  7039. /** Node was inserted into or removed from the tree.
  7040. * @param {EventData} ctx
  7041. * @param {boolean} add
  7042. * @param {FancytreeNode} node
  7043. */
  7044. treeRegisterNode: function(ctx, add, node) {
  7045. ctx.tree._callHook(
  7046. "treeStructureChanged",
  7047. ctx,
  7048. add ? "addNode" : "removeNode"
  7049. );
  7050. },
  7051. /** Widget got focus.
  7052. * @param {EventData} ctx
  7053. * @param {boolean} [flag=true]
  7054. */
  7055. treeSetFocus: function(ctx, flag, callOpts) {
  7056. var targetNode;
  7057. flag = flag !== false;
  7058. // this.debug("treeSetFocus(" + flag + "), callOpts: ", callOpts, this.hasFocus());
  7059. // this.debug(" focusNode: " + this.focusNode);
  7060. // this.debug(" activeNode: " + this.activeNode);
  7061. if (flag !== this.hasFocus()) {
  7062. this._hasFocus = flag;
  7063. if (!flag && this.focusNode) {
  7064. // Node also looses focus if widget blurs
  7065. this.focusNode.setFocus(false);
  7066. } else if (flag && (!callOpts || !callOpts.calledByNode)) {
  7067. $(this.$container).focus();
  7068. }
  7069. this.$container.toggleClass("fancytree-treefocus", flag);
  7070. this._triggerTreeEvent(flag ? "focusTree" : "blurTree");
  7071. if (flag && !this.activeNode) {
  7072. // #712: Use last mousedowned node ('click' event fires after focusin)
  7073. targetNode =
  7074. this._lastMousedownNode || this.getFirstChild();
  7075. if (targetNode) {
  7076. targetNode.setFocus();
  7077. }
  7078. }
  7079. }
  7080. },
  7081. /** Widget option was set using `$().fancytree("option", "KEY", VALUE)`.
  7082. *
  7083. * Note: `key` may reference a nested option, e.g. 'dnd5.scroll'.
  7084. * In this case `value`contains the complete, modified `dnd5` option hash.
  7085. * We can check for changed values like
  7086. * if( value.scroll !== tree.options.dnd5.scroll ) {...}
  7087. *
  7088. * @param {EventData} ctx
  7089. * @param {string} key option name
  7090. * @param {any} value option value
  7091. */
  7092. treeSetOption: function(ctx, key, value) {
  7093. var tree = ctx.tree,
  7094. callDefault = true,
  7095. callCreate = false,
  7096. callRender = false;
  7097. switch (key) {
  7098. case "aria":
  7099. case "checkbox":
  7100. case "icon":
  7101. case "minExpandLevel":
  7102. case "tabindex":
  7103. // tree._callHook("treeCreate", tree);
  7104. callCreate = true;
  7105. callRender = true;
  7106. break;
  7107. case "checkboxAutoHide":
  7108. tree.$container.toggleClass(
  7109. "fancytree-checkbox-auto-hide",
  7110. !!value
  7111. );
  7112. break;
  7113. case "escapeTitles":
  7114. case "tooltip":
  7115. callRender = true;
  7116. break;
  7117. case "rtl":
  7118. if (value === false) {
  7119. tree.$container
  7120. .removeAttr("DIR")
  7121. .removeClass("fancytree-rtl");
  7122. } else {
  7123. tree.$container
  7124. .attr("DIR", "RTL")
  7125. .addClass("fancytree-rtl");
  7126. }
  7127. callRender = true;
  7128. break;
  7129. case "source":
  7130. callDefault = false;
  7131. tree._callHook("treeLoad", tree, value);
  7132. callRender = true;
  7133. break;
  7134. }
  7135. tree.debug(
  7136. "set option " +
  7137. key +
  7138. "=" +
  7139. value +
  7140. " <" +
  7141. typeof value +
  7142. ">"
  7143. );
  7144. if (callDefault) {
  7145. if (this.widget._super) {
  7146. // jQuery UI 1.9+
  7147. this.widget._super.call(this.widget, key, value);
  7148. } else {
  7149. // jQuery UI <= 1.8, we have to manually invoke the _setOption method from the base widget
  7150. $.Widget.prototype._setOption.call(
  7151. this.widget,
  7152. key,
  7153. value
  7154. );
  7155. }
  7156. }
  7157. if (callCreate) {
  7158. tree._callHook("treeCreate", tree);
  7159. }
  7160. if (callRender) {
  7161. tree.render(true, false); // force, not-deep
  7162. }
  7163. },
  7164. /** A Node was added, removed, moved, or it's visibility changed.
  7165. * @param {EventData} ctx
  7166. */
  7167. treeStructureChanged: function(ctx, type) {},
  7168. }
  7169. );
  7170. /*******************************************************************************
  7171. * jQuery UI widget boilerplate
  7172. */
  7173. /**
  7174. * The plugin (derrived from [jQuery.Widget](http://api.jqueryui.com/jQuery.widget/)).
  7175. *
  7176. * **Note:**
  7177. * These methods implement the standard jQuery UI widget API.
  7178. * It is recommended to use methods of the {Fancytree} instance instead
  7179. *
  7180. * @example
  7181. * // DEPRECATED: Access jQuery UI widget methods and members:
  7182. * var tree = $("#tree").fancytree("getTree", "#myTree");
  7183. * var node = $.ui.fancytree.getTree("#tree").getActiveNode();
  7184. *
  7185. * // RECOMMENDED: Use the Fancytree object API
  7186. * var tree = $.ui.fancytree.getTree("#myTree");
  7187. * var node = tree.getActiveNode();
  7188. *
  7189. * // or you may already have stored the tree instance upon creation:
  7190. * import {createTree, version} from 'jquery.fancytree'
  7191. * const tree = createTree('#tree', { ... });
  7192. * var node = tree.getActiveNode();
  7193. *
  7194. * @see {Fancytree_Static#getTree}
  7195. * @deprecated Use methods of the {Fancytree} instance instead
  7196. * @mixin Fancytree_Widget
  7197. */
  7198. $.widget(
  7199. "ui.fancytree",
  7200. /** @lends Fancytree_Widget# */
  7201. {
  7202. /**These options will be used as defaults
  7203. * @type {FancytreeOptions}
  7204. */
  7205. options: {
  7206. activeVisible: true,
  7207. ajax: {
  7208. type: "GET",
  7209. cache: false, // false: Append random '_' argument to the request url to prevent caching.
  7210. // timeout: 0, // >0: Make sure we get an ajax error if server is unreachable
  7211. dataType: "json", // Expect json format and pass json object to callbacks.
  7212. },
  7213. aria: true,
  7214. autoActivate: true,
  7215. autoCollapse: false,
  7216. autoScroll: false,
  7217. checkbox: false,
  7218. clickFolderMode: 4,
  7219. copyFunctionsToData: false,
  7220. debugLevel: null, // 0..4 (null: use global setting $.ui.fancytree.debugLevel)
  7221. disabled: false, // TODO: required anymore?
  7222. enableAspx: 42, // TODO: this is truethy, but distinguishable from true: default will change to false in the future
  7223. escapeTitles: false,
  7224. extensions: [],
  7225. focusOnSelect: false,
  7226. generateIds: false,
  7227. icon: true,
  7228. idPrefix: "ft_",
  7229. keyboard: true,
  7230. keyPathSeparator: "/",
  7231. minExpandLevel: 1,
  7232. nodata: true, // (bool, string, or callback) display message, when no data available
  7233. quicksearch: false,
  7234. rtl: false,
  7235. scrollOfs: { top: 0, bottom: 0 },
  7236. scrollParent: null,
  7237. selectMode: 2,
  7238. strings: {
  7239. loading: "Loading...", // &#8230; would be escaped when escapeTitles is true
  7240. loadError: "Load error!",
  7241. moreData: "More...",
  7242. noData: "No data.",
  7243. },
  7244. tabindex: "0",
  7245. titlesTabbable: false,
  7246. toggleEffect: { effect: "slideToggle", duration: 200 }, //< "toggle" or "slideToggle" to use jQuery instead of jQueryUI for toggleEffect animation
  7247. tooltip: false,
  7248. treeId: null,
  7249. _classNames: {
  7250. active: "fancytree-active",
  7251. animating: "fancytree-animating",
  7252. combinedExpanderPrefix: "fancytree-exp-",
  7253. combinedIconPrefix: "fancytree-ico-",
  7254. error: "fancytree-error",
  7255. expanded: "fancytree-expanded",
  7256. focused: "fancytree-focused",
  7257. folder: "fancytree-folder",
  7258. hasChildren: "fancytree-has-children",
  7259. lastsib: "fancytree-lastsib",
  7260. lazy: "fancytree-lazy",
  7261. loading: "fancytree-loading",
  7262. node: "fancytree-node",
  7263. partload: "fancytree-partload",
  7264. partsel: "fancytree-partsel",
  7265. radio: "fancytree-radio",
  7266. selected: "fancytree-selected",
  7267. statusNodePrefix: "fancytree-statusnode-",
  7268. unselectable: "fancytree-unselectable",
  7269. },
  7270. // events
  7271. lazyLoad: null,
  7272. postProcess: null,
  7273. },
  7274. _deprecationWarning: function(name) {
  7275. var tree = this.tree;
  7276. if (tree && tree.options.debugLevel >= 3) {
  7277. tree.warn(
  7278. "$().fancytree('" +
  7279. name +
  7280. "') is deprecated (see https://wwwendt.de/tech/fancytree/doc/jsdoc/Fancytree_Widget.html"
  7281. );
  7282. }
  7283. },
  7284. /* Set up the widget, Called on first $().fancytree() */
  7285. _create: function() {
  7286. this.tree = new Fancytree(this);
  7287. this.$source =
  7288. this.source || this.element.data("type") === "json"
  7289. ? this.element
  7290. : this.element.find(">ul").first();
  7291. // Subclass Fancytree instance with all enabled extensions
  7292. var extension,
  7293. extName,
  7294. i,
  7295. opts = this.options,
  7296. extensions = opts.extensions,
  7297. base = this.tree;
  7298. for (i = 0; i < extensions.length; i++) {
  7299. extName = extensions[i];
  7300. extension = $.ui.fancytree._extensions[extName];
  7301. if (!extension) {
  7302. $.error(
  7303. "Could not apply extension '" +
  7304. extName +
  7305. "' (it is not registered, did you forget to include it?)"
  7306. );
  7307. }
  7308. // Add extension options as tree.options.EXTENSION
  7309. // _assert(!this.tree.options[extName], "Extension name must not exist as option name: " + extName);
  7310. // console.info("extend " + extName, extension.options, this.tree.options[extName])
  7311. // issue #876: we want to replace custom array-options, not merge them
  7312. this.tree.options[extName] = _simpleDeepMerge(
  7313. {},
  7314. extension.options,
  7315. this.tree.options[extName]
  7316. );
  7317. // this.tree.options[extName] = $.extend(true, {}, extension.options, this.tree.options[extName]);
  7318. // console.info("extend " + extName + " =>", this.tree.options[extName])
  7319. // console.info("extend " + extName + " org default =>", extension.options)
  7320. // Add a namespace tree.ext.EXTENSION, to hold instance data
  7321. _assert(
  7322. this.tree.ext[extName] === undefined,
  7323. "Extension name must not exist as Fancytree.ext attribute: '" +
  7324. extName +
  7325. "'"
  7326. );
  7327. // this.tree[extName] = extension;
  7328. this.tree.ext[extName] = {};
  7329. // Subclass Fancytree methods using proxies.
  7330. _subclassObject(this.tree, base, extension, extName);
  7331. // current extension becomes base for the next extension
  7332. base = extension;
  7333. }
  7334. //
  7335. if (opts.icons !== undefined) {
  7336. // 2015-11-16
  7337. if (opts.icon === true) {
  7338. this.tree.warn(
  7339. "'icons' tree option is deprecated since v2.14.0: use 'icon' instead"
  7340. );
  7341. opts.icon = opts.icons;
  7342. } else {
  7343. $.error(
  7344. "'icons' tree option is deprecated since v2.14.0: use 'icon' only instead"
  7345. );
  7346. }
  7347. }
  7348. if (opts.iconClass !== undefined) {
  7349. // 2015-11-16
  7350. if (opts.icon) {
  7351. $.error(
  7352. "'iconClass' tree option is deprecated since v2.14.0: use 'icon' only instead"
  7353. );
  7354. } else {
  7355. this.tree.warn(
  7356. "'iconClass' tree option is deprecated since v2.14.0: use 'icon' instead"
  7357. );
  7358. opts.icon = opts.iconClass;
  7359. }
  7360. }
  7361. if (opts.tabbable !== undefined) {
  7362. // 2016-04-04
  7363. opts.tabindex = opts.tabbable ? "0" : "-1";
  7364. this.tree.warn(
  7365. "'tabbable' tree option is deprecated since v2.17.0: use 'tabindex='" +
  7366. opts.tabindex +
  7367. "' instead"
  7368. );
  7369. }
  7370. //
  7371. this.tree._callHook("treeCreate", this.tree);
  7372. // Note: 'fancytreecreate' event is fired by widget base class
  7373. // this.tree._triggerTreeEvent("create");
  7374. },
  7375. /* Called on every $().fancytree() */
  7376. _init: function() {
  7377. this.tree._callHook("treeInit", this.tree);
  7378. // TODO: currently we call bind after treeInit, because treeInit
  7379. // might change tree.$container.
  7380. // It would be better, to move event binding into hooks altogether
  7381. this._bind();
  7382. },
  7383. /* Use the _setOption method to respond to changes to options. */
  7384. _setOption: function(key, value) {
  7385. return this.tree._callHook(
  7386. "treeSetOption",
  7387. this.tree,
  7388. key,
  7389. value
  7390. );
  7391. },
  7392. /** Use the destroy method to clean up any modifications your widget has made to the DOM */
  7393. _destroy: function() {
  7394. this._unbind();
  7395. this.tree._callHook("treeDestroy", this.tree);
  7396. // In jQuery UI 1.8, you must invoke the destroy method from the base widget
  7397. // $.Widget.prototype.destroy.call(this);
  7398. // TODO: delete tree and nodes to make garbage collect easier?
  7399. // TODO: In jQuery UI 1.9 and above, you would define _destroy instead of destroy and not call the base method
  7400. },
  7401. // -------------------------------------------------------------------------
  7402. /* Remove all event handlers for our namespace */
  7403. _unbind: function() {
  7404. var ns = this.tree._ns;
  7405. this.element.off(ns);
  7406. this.tree.$container.off(ns);
  7407. $(document).off(ns);
  7408. },
  7409. /* Add mouse and kyboard handlers to the container */
  7410. _bind: function() {
  7411. var self = this,
  7412. opts = this.options,
  7413. tree = this.tree,
  7414. ns = tree._ns;
  7415. // selstartEvent = ( $.support.selectstart ? "selectstart" : "mousedown" )
  7416. // Remove all previuous handlers for this tree
  7417. this._unbind();
  7418. //alert("keydown" + ns + "foc=" + tree.hasFocus() + tree.$container);
  7419. // tree.debug("bind events; container: ", tree.$container);
  7420. tree.$container
  7421. .on("focusin" + ns + " focusout" + ns, function(event) {
  7422. var node = FT.getNode(event),
  7423. flag = event.type === "focusin";
  7424. if (!flag && node && $(event.target).is("a")) {
  7425. // #764
  7426. node.debug(
  7427. "Ignored focusout on embedded <a> element."
  7428. );
  7429. return;
  7430. }
  7431. // tree.treeOnFocusInOut.call(tree, event);
  7432. // tree.debug("Tree container got event " + event.type, node, event, FT.getEventTarget(event));
  7433. if (flag) {
  7434. if (tree._getExpiringValue("focusin")) {
  7435. // #789: IE 11 may send duplicate focusin events
  7436. tree.debug("Ignored double focusin.");
  7437. return;
  7438. }
  7439. tree._setExpiringValue("focusin", true, 50);
  7440. if (!node) {
  7441. // #789: IE 11 may send focusin before mousdown(?)
  7442. node = tree._getExpiringValue("mouseDownNode");
  7443. if (node) {
  7444. tree.debug(
  7445. "Reconstruct mouse target for focusin from recent event."
  7446. );
  7447. }
  7448. }
  7449. }
  7450. if (node) {
  7451. // For example clicking into an <input> that is part of a node
  7452. tree._callHook(
  7453. "nodeSetFocus",
  7454. tree._makeHookContext(node, event),
  7455. flag
  7456. );
  7457. } else {
  7458. if (
  7459. tree.tbody &&
  7460. $(event.target).parents(
  7461. "table.fancytree-container > thead"
  7462. ).length
  7463. ) {
  7464. // #767: ignore events in the table's header
  7465. tree.debug(
  7466. "Ignore focus event outside table body.",
  7467. event
  7468. );
  7469. } else {
  7470. tree._callHook("treeSetFocus", tree, flag);
  7471. }
  7472. }
  7473. })
  7474. .on("selectstart" + ns, "span.fancytree-title", function(
  7475. event
  7476. ) {
  7477. // prevent mouse-drags to select text ranges
  7478. // tree.debug("<span title> got event " + event.type);
  7479. event.preventDefault();
  7480. })
  7481. .on("keydown" + ns, function(event) {
  7482. // TODO: also bind keyup and keypress
  7483. // tree.debug("got event " + event.type + ", hasFocus:" + tree.hasFocus());
  7484. // if(opts.disabled || opts.keyboard === false || !tree.hasFocus() ){
  7485. if (opts.disabled || opts.keyboard === false) {
  7486. return true;
  7487. }
  7488. var res,
  7489. node = tree.focusNode, // node may be null
  7490. ctx = tree._makeHookContext(node || tree, event),
  7491. prevPhase = tree.phase;
  7492. try {
  7493. tree.phase = "userEvent";
  7494. // If a 'fancytreekeydown' handler returns false, skip the default
  7495. // handling (implemented by tree.nodeKeydown()).
  7496. if (node) {
  7497. res = tree._triggerNodeEvent(
  7498. "keydown",
  7499. node,
  7500. event
  7501. );
  7502. } else {
  7503. res = tree._triggerTreeEvent("keydown", event);
  7504. }
  7505. if (res === "preventNav") {
  7506. res = true; // prevent keyboard navigation, but don't prevent default handling of embedded input controls
  7507. } else if (res !== false) {
  7508. res = tree._callHook("nodeKeydown", ctx);
  7509. }
  7510. return res;
  7511. } finally {
  7512. tree.phase = prevPhase;
  7513. }
  7514. })
  7515. .on("mousedown" + ns, function(event) {
  7516. var et = FT.getEventTarget(event);
  7517. // self.tree.debug("event(" + event.type + "): node: ", et.node);
  7518. // #712: Store the clicked node, so we can use it when we get a focusin event
  7519. // ('click' event fires after focusin)
  7520. // tree.debug("event(" + event.type + "): node: ", et.node);
  7521. tree._lastMousedownNode = et ? et.node : null;
  7522. // #789: Store the node also for a short period, so we can use it
  7523. // in a *resulting* focusin event
  7524. tree._setExpiringValue(
  7525. "mouseDownNode",
  7526. tree._lastMousedownNode
  7527. );
  7528. })
  7529. .on("click" + ns + " dblclick" + ns, function(event) {
  7530. if (opts.disabled) {
  7531. return true;
  7532. }
  7533. var ctx,
  7534. et = FT.getEventTarget(event),
  7535. node = et.node,
  7536. tree = self.tree,
  7537. prevPhase = tree.phase;
  7538. // self.tree.debug("event(" + event.type + "): node: ", node);
  7539. if (!node) {
  7540. return true; // Allow bubbling of other events
  7541. }
  7542. ctx = tree._makeHookContext(node, event);
  7543. // self.tree.debug("event(" + event.type + "): node: ", node);
  7544. try {
  7545. tree.phase = "userEvent";
  7546. switch (event.type) {
  7547. case "click":
  7548. ctx.targetType = et.type;
  7549. if (node.isPagingNode()) {
  7550. return (
  7551. tree._triggerNodeEvent(
  7552. "clickPaging",
  7553. ctx,
  7554. event
  7555. ) === true
  7556. );
  7557. }
  7558. return tree._triggerNodeEvent(
  7559. "click",
  7560. ctx,
  7561. event
  7562. ) === false
  7563. ? false
  7564. : tree._callHook("nodeClick", ctx);
  7565. case "dblclick":
  7566. ctx.targetType = et.type;
  7567. return tree._triggerNodeEvent(
  7568. "dblclick",
  7569. ctx,
  7570. event
  7571. ) === false
  7572. ? false
  7573. : tree._callHook("nodeDblclick", ctx);
  7574. }
  7575. } finally {
  7576. tree.phase = prevPhase;
  7577. }
  7578. });
  7579. },
  7580. /** Return the active node or null.
  7581. * @returns {FancytreeNode}
  7582. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7583. */
  7584. getActiveNode: function() {
  7585. this._deprecationWarning("getActiveNode");
  7586. return this.tree.activeNode;
  7587. },
  7588. /** Return the matching node or null.
  7589. * @param {string} key
  7590. * @returns {FancytreeNode}
  7591. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7592. */
  7593. getNodeByKey: function(key) {
  7594. this._deprecationWarning("getNodeByKey");
  7595. return this.tree.getNodeByKey(key);
  7596. },
  7597. /** Return the invisible system root node.
  7598. * @returns {FancytreeNode}
  7599. * @deprecated Use methods of the Fancytree instance instead (<a href="Fancytree_Widget.html">example above</a>).
  7600. */
  7601. getRootNode: function() {
  7602. this._deprecationWarning("getRootNode");
  7603. return this.tree.rootNode;
  7604. },
  7605. /** Return the current tree instance.
  7606. * @returns {Fancytree}
  7607. * @deprecated Use `$.ui.fancytree.getTree()` instead (<a href="Fancytree_Widget.html">example above</a>).
  7608. */
  7609. getTree: function() {
  7610. this._deprecationWarning("getTree");
  7611. return this.tree;
  7612. },
  7613. }
  7614. );
  7615. // $.ui.fancytree was created by the widget factory. Create a local shortcut:
  7616. FT = $.ui.fancytree;
  7617. /**
  7618. * Static members in the `$.ui.fancytree` namespace.
  7619. * This properties and methods can be accessed without instantiating a concrete
  7620. * Fancytree instance.
  7621. *
  7622. * @example
  7623. * // Access static members:
  7624. * var node = $.ui.fancytree.getNode(element);
  7625. * alert($.ui.fancytree.version);
  7626. *
  7627. * @mixin Fancytree_Static
  7628. */
  7629. $.extend(
  7630. $.ui.fancytree,
  7631. /** @lends Fancytree_Static# */
  7632. {
  7633. /** Version number `"MAJOR.MINOR.PATCH"`
  7634. * @type {string} */
  7635. version: "2.37.0", // Set to semver by 'grunt release'
  7636. /** @type {string}
  7637. * @description `"production" for release builds` */
  7638. buildType: "production", // Set to 'production' by 'grunt build'
  7639. /** @type {int}
  7640. * @description 0: silent .. 5: verbose (default: 3 for release builds). */
  7641. debugLevel: 3, // Set to 3 by 'grunt build'
  7642. // Used by $.ui.fancytree.debug() and as default for tree.options.debugLevel
  7643. _nextId: 1,
  7644. _nextNodeKey: 1,
  7645. _extensions: {},
  7646. // focusTree: null,
  7647. /** Expose class object as `$.ui.fancytree._FancytreeClass`.
  7648. * Useful to extend `$.ui.fancytree._FancytreeClass.prototype`.
  7649. * @type {Fancytree}
  7650. */
  7651. _FancytreeClass: Fancytree,
  7652. /** Expose class object as $.ui.fancytree._FancytreeNodeClass
  7653. * Useful to extend `$.ui.fancytree._FancytreeNodeClass.prototype`.
  7654. * @type {FancytreeNode}
  7655. */
  7656. _FancytreeNodeClass: FancytreeNode,
  7657. /* Feature checks to provide backwards compatibility */
  7658. jquerySupports: {
  7659. // http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7660. positionMyOfs: isVersionAtLeast($.ui.version, 1, 9),
  7661. },
  7662. /** Throw an error if condition fails (debug method).
  7663. * @param {boolean} cond
  7664. * @param {string} msg
  7665. */
  7666. assert: function(cond, msg) {
  7667. return _assert(cond, msg);
  7668. },
  7669. /** Create a new Fancytree instance on a target element.
  7670. *
  7671. * @param {Element | jQueryObject | string} el Target DOM element or selector
  7672. * @param {FancytreeOptions} [opts] Fancytree options
  7673. * @returns {Fancytree} new tree instance
  7674. * @example
  7675. * var tree = $.ui.fancytree.createTree("#tree", {
  7676. * source: {url: "my/webservice"}
  7677. * }); // Create tree for this matching element
  7678. *
  7679. * @since 2.25
  7680. */
  7681. createTree: function(el, opts) {
  7682. var $tree = $(el).fancytree(opts);
  7683. return FT.getTree($tree);
  7684. },
  7685. /** Return a function that executes *fn* at most every *timeout* ms.
  7686. * @param {integer} timeout
  7687. * @param {function} fn
  7688. * @param {boolean} [invokeAsap=false]
  7689. * @param {any} [ctx]
  7690. */
  7691. debounce: function(timeout, fn, invokeAsap, ctx) {
  7692. var timer;
  7693. if (arguments.length === 3 && typeof invokeAsap !== "boolean") {
  7694. ctx = invokeAsap;
  7695. invokeAsap = false;
  7696. }
  7697. return function() {
  7698. var args = arguments;
  7699. ctx = ctx || this;
  7700. // eslint-disable-next-line no-unused-expressions
  7701. invokeAsap && !timer && fn.apply(ctx, args);
  7702. clearTimeout(timer);
  7703. timer = setTimeout(function() {
  7704. // eslint-disable-next-line no-unused-expressions
  7705. invokeAsap || fn.apply(ctx, args);
  7706. timer = null;
  7707. }, timeout);
  7708. };
  7709. },
  7710. /** Write message to console if debugLevel >= 4
  7711. * @param {string} msg
  7712. */
  7713. debug: function(msg) {
  7714. if ($.ui.fancytree.debugLevel >= 4) {
  7715. consoleApply("log", arguments);
  7716. }
  7717. },
  7718. /** Write error message to console if debugLevel >= 1.
  7719. * @param {string} msg
  7720. */
  7721. error: function(msg) {
  7722. if ($.ui.fancytree.debugLevel >= 1) {
  7723. consoleApply("error", arguments);
  7724. }
  7725. },
  7726. /** Convert `<`, `>`, `&`, `"`, `'`, and `/` to the equivalent entities.
  7727. *
  7728. * @param {string} s
  7729. * @returns {string}
  7730. */
  7731. escapeHtml: function(s) {
  7732. return ("" + s).replace(REX_HTML, function(s) {
  7733. return ENTITY_MAP[s];
  7734. });
  7735. },
  7736. /** Make jQuery.position() arguments backwards compatible, i.e. if
  7737. * jQuery UI version <= 1.8, convert
  7738. * { my: "left+3 center", at: "left bottom", of: $target }
  7739. * to
  7740. * { my: "left center", at: "left bottom", of: $target, offset: "3 0" }
  7741. *
  7742. * See http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at
  7743. * and http://jsfiddle.net/mar10/6xtu9a4e/
  7744. *
  7745. * @param {object} opts
  7746. * @returns {object} the (potentially modified) original opts hash object
  7747. */
  7748. fixPositionOptions: function(opts) {
  7749. if (opts.offset || ("" + opts.my + opts.at).indexOf("%") >= 0) {
  7750. $.error(
  7751. "expected new position syntax (but '%' is not supported)"
  7752. );
  7753. }
  7754. if (!$.ui.fancytree.jquerySupports.positionMyOfs) {
  7755. var // parse 'left+3 center' into ['left+3 center', 'left', '+3', 'center', undefined]
  7756. myParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(
  7757. opts.my
  7758. ),
  7759. atParts = /(\w+)([+-]?\d+)?\s+(\w+)([+-]?\d+)?/.exec(
  7760. opts.at
  7761. ),
  7762. // convert to numbers
  7763. dx =
  7764. (myParts[2] ? +myParts[2] : 0) +
  7765. (atParts[2] ? +atParts[2] : 0),
  7766. dy =
  7767. (myParts[4] ? +myParts[4] : 0) +
  7768. (atParts[4] ? +atParts[4] : 0);
  7769. opts = $.extend({}, opts, {
  7770. // make a copy and overwrite
  7771. my: myParts[1] + " " + myParts[3],
  7772. at: atParts[1] + " " + atParts[3],
  7773. });
  7774. if (dx || dy) {
  7775. opts.offset = "" + dx + " " + dy;
  7776. }
  7777. }
  7778. return opts;
  7779. },
  7780. /** Return a {node: FancytreeNode, type: TYPE} object for a mouse event.
  7781. *
  7782. * @param {Event} event Mouse event, e.g. click, ...
  7783. * @returns {object} Return a {node: FancytreeNode, type: TYPE} object
  7784. * TYPE: 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7785. */
  7786. getEventTarget: function(event) {
  7787. var $target,
  7788. tree,
  7789. tcn = event && event.target ? event.target.className : "",
  7790. res = { node: this.getNode(event.target), type: undefined };
  7791. // We use a fast version of $(res.node).hasClass()
  7792. // See http://jsperf.com/test-for-classname/2
  7793. if (/\bfancytree-title\b/.test(tcn)) {
  7794. res.type = "title";
  7795. } else if (/\bfancytree-expander\b/.test(tcn)) {
  7796. res.type =
  7797. res.node.hasChildren() === false
  7798. ? "prefix"
  7799. : "expander";
  7800. // }else if( /\bfancytree-checkbox\b/.test(tcn) || /\bfancytree-radio\b/.test(tcn) ){
  7801. } else if (/\bfancytree-checkbox\b/.test(tcn)) {
  7802. res.type = "checkbox";
  7803. } else if (/\bfancytree(-custom)?-icon\b/.test(tcn)) {
  7804. res.type = "icon";
  7805. } else if (/\bfancytree-node\b/.test(tcn)) {
  7806. // Somewhere near the title
  7807. res.type = "title";
  7808. } else if (event && event.target) {
  7809. $target = $(event.target);
  7810. if ($target.is("ul[role=group]")) {
  7811. // #nnn: Clicking right to a node may hit the surrounding UL
  7812. tree = res.node && res.node.tree;
  7813. (tree || FT).debug("Ignoring click on outer UL.");
  7814. res.node = null;
  7815. } else if ($target.closest(".fancytree-title").length) {
  7816. // #228: clicking an embedded element inside a title
  7817. res.type = "title";
  7818. } else if ($target.closest(".fancytree-checkbox").length) {
  7819. // E.g. <svg> inside checkbox span
  7820. res.type = "checkbox";
  7821. } else if ($target.closest(".fancytree-expander").length) {
  7822. res.type = "expander";
  7823. }
  7824. }
  7825. return res;
  7826. },
  7827. /** Return a string describing the affected node region for a mouse event.
  7828. *
  7829. * @param {Event} event Mouse event, e.g. click, mousemove, ...
  7830. * @returns {string} 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
  7831. */
  7832. getEventTargetType: function(event) {
  7833. return this.getEventTarget(event).type;
  7834. },
  7835. /** Return a FancytreeNode instance from element, event, or jQuery object.
  7836. *
  7837. * @param {Element | jQueryObject | Event} el
  7838. * @returns {FancytreeNode} matching node or null
  7839. */
  7840. getNode: function(el) {
  7841. if (el instanceof FancytreeNode) {
  7842. return el; // el already was a FancytreeNode
  7843. } else if (el instanceof $) {
  7844. el = el[0]; // el was a jQuery object: use the DOM element
  7845. } else if (el.originalEvent !== undefined) {
  7846. el = el.target; // el was an Event
  7847. }
  7848. while (el) {
  7849. if (el.ftnode) {
  7850. return el.ftnode;
  7851. }
  7852. el = el.parentNode;
  7853. }
  7854. return null;
  7855. },
  7856. /** Return a Fancytree instance, from element, index, event, or jQueryObject.
  7857. *
  7858. * @param {Element | jQueryObject | Event | integer | string} [el]
  7859. * @returns {Fancytree} matching tree or null
  7860. * @example
  7861. * $.ui.fancytree.getTree(); // Get first Fancytree instance on page
  7862. * $.ui.fancytree.getTree(1); // Get second Fancytree instance on page
  7863. * $.ui.fancytree.getTree(event); // Get tree for this mouse- or keyboard event
  7864. * $.ui.fancytree.getTree("foo"); // Get tree for this `opts.treeId`
  7865. * $.ui.fancytree.getTree("#tree"); // Get tree for this matching element
  7866. *
  7867. * @since 2.13
  7868. */
  7869. getTree: function(el) {
  7870. var widget,
  7871. orgEl = el;
  7872. if (el instanceof Fancytree) {
  7873. return el; // el already was a Fancytree
  7874. }
  7875. if (el === undefined) {
  7876. el = 0; // get first tree
  7877. }
  7878. if (typeof el === "number") {
  7879. el = $(".fancytree-container").eq(el); // el was an integer: return nth instance
  7880. } else if (typeof el === "string") {
  7881. // `el` may be a treeId or a selector:
  7882. el = $("#ft-id-" + orgEl).eq(0);
  7883. if (!el.length) {
  7884. el = $(orgEl).eq(0); // el was a selector: use first match
  7885. }
  7886. } else if (
  7887. el instanceof Element ||
  7888. el instanceof HTMLDocument
  7889. ) {
  7890. el = $(el);
  7891. } else if (el instanceof $) {
  7892. el = el.eq(0); // el was a jQuery object: use the first
  7893. } else if (el.originalEvent !== undefined) {
  7894. el = $(el.target); // el was an Event
  7895. }
  7896. // el is a jQuery object wit one element here
  7897. el = el.closest(":ui-fancytree");
  7898. widget = el.data("ui-fancytree") || el.data("fancytree"); // the latter is required by jQuery <= 1.8
  7899. return widget ? widget.tree : null;
  7900. },
  7901. /** Return an option value that has a default, but may be overridden by a
  7902. * callback or a node instance attribute.
  7903. *
  7904. * Evaluation sequence:
  7905. *
  7906. * If `tree.options.<optionName>` is a callback that returns something, use that.
  7907. * Else if `node.<optionName>` is defined, use that.
  7908. * Else if `tree.options.<optionName>` is a value, use that.
  7909. * Else use `defaultValue`.
  7910. *
  7911. * @param {string} optionName name of the option property (on node and tree)
  7912. * @param {FancytreeNode} node passed to the callback
  7913. * @param {object} nodeObject where to look for the local option property, e.g. `node` or `node.data`
  7914. * @param {object} treeOption where to look for the tree option, e.g. `tree.options` or `tree.options.dnd5`
  7915. * @param {any} [defaultValue]
  7916. * @returns {any}
  7917. *
  7918. * @example
  7919. * // Check for node.foo, tree,options.foo(), and tree.options.foo:
  7920. * $.ui.fancytree.evalOption("foo", node, node, tree.options);
  7921. * // Check for node.data.bar, tree,options.qux.bar(), and tree.options.qux.bar:
  7922. * $.ui.fancytree.evalOption("bar", node, node.data, tree.options.qux);
  7923. *
  7924. * @since 2.22
  7925. */
  7926. evalOption: function(
  7927. optionName,
  7928. node,
  7929. nodeObject,
  7930. treeOptions,
  7931. defaultValue
  7932. ) {
  7933. var ctx,
  7934. res,
  7935. tree = node.tree,
  7936. treeOpt = treeOptions[optionName],
  7937. nodeOpt = nodeObject[optionName];
  7938. if ($.isFunction(treeOpt)) {
  7939. ctx = {
  7940. node: node,
  7941. tree: tree,
  7942. widget: tree.widget,
  7943. options: tree.widget.options,
  7944. typeInfo: tree.types[node.type] || {},
  7945. };
  7946. res = treeOpt.call(tree, { type: optionName }, ctx);
  7947. if (res == null) {
  7948. res = nodeOpt;
  7949. }
  7950. } else {
  7951. res = nodeOpt == null ? treeOpt : nodeOpt;
  7952. }
  7953. if (res == null) {
  7954. res = defaultValue; // no option set at all: return default
  7955. }
  7956. return res;
  7957. },
  7958. /** Set expander, checkbox, or node icon, supporting string and object format.
  7959. *
  7960. * @param {Element | jQueryObject} span
  7961. * @param {string} baseClass
  7962. * @param {string | object} icon
  7963. * @since 2.27
  7964. */
  7965. setSpanIcon: function(span, baseClass, icon) {
  7966. var $span = $(span);
  7967. if (typeof icon === "string") {
  7968. $span.attr("class", baseClass + " " + icon);
  7969. } else {
  7970. // support object syntax: { text: ligature, addClasse: classname }
  7971. if (icon.text) {
  7972. $span.text("" + icon.text);
  7973. } else if (icon.html) {
  7974. span.innerHTML = icon.html;
  7975. }
  7976. $span.attr(
  7977. "class",
  7978. baseClass + " " + (icon.addClass || "")
  7979. );
  7980. }
  7981. },
  7982. /** Convert a keydown or mouse event to a canonical string like 'ctrl+a',
  7983. * 'ctrl+shift+f2', 'shift+leftdblclick'.
  7984. *
  7985. * This is especially handy for switch-statements in event handlers.
  7986. *
  7987. * @param {event}
  7988. * @returns {string}
  7989. *
  7990. * @example
  7991. switch( $.ui.fancytree.eventToString(event) ) {
  7992. case "-":
  7993. tree.nodeSetExpanded(ctx, false);
  7994. break;
  7995. case "shift+return":
  7996. tree.nodeSetActive(ctx, true);
  7997. break;
  7998. case "down":
  7999. res = node.navigate(event.which, activate);
  8000. break;
  8001. default:
  8002. handled = false;
  8003. }
  8004. if( handled ){
  8005. event.preventDefault();
  8006. }
  8007. */
  8008. eventToString: function(event) {
  8009. // Poor-man's hotkeys. See here for a complete implementation:
  8010. // https://github.com/jeresig/jquery.hotkeys
  8011. var which = event.which,
  8012. et = event.type,
  8013. s = [];
  8014. if (event.altKey) {
  8015. s.push("alt");
  8016. }
  8017. if (event.ctrlKey) {
  8018. s.push("ctrl");
  8019. }
  8020. if (event.metaKey) {
  8021. s.push("meta");
  8022. }
  8023. if (event.shiftKey) {
  8024. s.push("shift");
  8025. }
  8026. if (et === "click" || et === "dblclick") {
  8027. s.push(MOUSE_BUTTONS[event.button] + et);
  8028. } else if (et === "wheel") {
  8029. s.push(et);
  8030. } else if (!IGNORE_KEYCODES[which]) {
  8031. s.push(
  8032. SPECIAL_KEYCODES[which] ||
  8033. String.fromCharCode(which).toLowerCase()
  8034. );
  8035. }
  8036. return s.join("+");
  8037. },
  8038. /** Write message to console if debugLevel >= 3
  8039. * @param {string} msg
  8040. */
  8041. info: function(msg) {
  8042. if ($.ui.fancytree.debugLevel >= 3) {
  8043. consoleApply("info", arguments);
  8044. }
  8045. },
  8046. /* @deprecated: use eventToString(event) instead.
  8047. */
  8048. keyEventToString: function(event) {
  8049. this.warn(
  8050. "keyEventToString() is deprecated: use eventToString()"
  8051. );
  8052. return this.eventToString(event);
  8053. },
  8054. /** Return a wrapped handler method, that provides `this._super`.
  8055. *
  8056. * @example
  8057. // Implement `opts.createNode` event to add the 'draggable' attribute
  8058. $.ui.fancytree.overrideMethod(ctx.options, "createNode", function(event, data) {
  8059. // Default processing if any
  8060. this._super.apply(this, arguments);
  8061. // Add 'draggable' attribute
  8062. data.node.span.draggable = true;
  8063. });
  8064. *
  8065. * @param {object} instance
  8066. * @param {string} methodName
  8067. * @param {function} handler
  8068. * @param {object} [context] optional context
  8069. */
  8070. overrideMethod: function(instance, methodName, handler, context) {
  8071. var prevSuper,
  8072. _super = instance[methodName] || $.noop;
  8073. instance[methodName] = function() {
  8074. var self = context || this;
  8075. try {
  8076. prevSuper = self._super;
  8077. self._super = _super;
  8078. return handler.apply(self, arguments);
  8079. } finally {
  8080. self._super = prevSuper;
  8081. }
  8082. };
  8083. },
  8084. /**
  8085. * Parse tree data from HTML <ul> markup
  8086. *
  8087. * @param {jQueryObject} $ul
  8088. * @returns {NodeData[]}
  8089. */
  8090. parseHtml: function($ul) {
  8091. var classes,
  8092. className,
  8093. extraClasses,
  8094. i,
  8095. iPos,
  8096. l,
  8097. tmp,
  8098. tmp2,
  8099. $children = $ul.find(">li"),
  8100. children = [];
  8101. $children.each(function() {
  8102. var allData,
  8103. lowerCaseAttr,
  8104. $li = $(this),
  8105. $liSpan = $li.find(">span", this).first(),
  8106. $liA = $liSpan.length ? null : $li.find(">a").first(),
  8107. d = { tooltip: null, data: {} };
  8108. if ($liSpan.length) {
  8109. d.title = $liSpan.html();
  8110. } else if ($liA && $liA.length) {
  8111. // If a <li><a> tag is specified, use it literally and extract href/target.
  8112. d.title = $liA.html();
  8113. d.data.href = $liA.attr("href");
  8114. d.data.target = $liA.attr("target");
  8115. d.tooltip = $liA.attr("title");
  8116. } else {
  8117. // If only a <li> tag is specified, use the trimmed string up to
  8118. // the next child <ul> tag.
  8119. d.title = $li.html();
  8120. iPos = d.title.search(/<ul/i);
  8121. if (iPos >= 0) {
  8122. d.title = d.title.substring(0, iPos);
  8123. }
  8124. }
  8125. d.title = $.trim(d.title);
  8126. // Make sure all fields exist
  8127. for (i = 0, l = CLASS_ATTRS.length; i < l; i++) {
  8128. d[CLASS_ATTRS[i]] = undefined;
  8129. }
  8130. // Initialize to `true`, if class is set and collect extraClasses
  8131. classes = this.className.split(" ");
  8132. extraClasses = [];
  8133. for (i = 0, l = classes.length; i < l; i++) {
  8134. className = classes[i];
  8135. if (CLASS_ATTR_MAP[className]) {
  8136. d[className] = true;
  8137. } else {
  8138. extraClasses.push(className);
  8139. }
  8140. }
  8141. d.extraClasses = extraClasses.join(" ");
  8142. // Parse node options from ID, title and class attributes
  8143. tmp = $li.attr("title");
  8144. if (tmp) {
  8145. d.tooltip = tmp; // overrides <a title='...'>
  8146. }
  8147. tmp = $li.attr("id");
  8148. if (tmp) {
  8149. d.key = tmp;
  8150. }
  8151. // Translate hideCheckbox -> checkbox:false
  8152. if ($li.attr("hideCheckbox")) {
  8153. d.checkbox = false;
  8154. }
  8155. // Add <li data-NAME='...'> as node.data.NAME
  8156. allData = _getElementDataAsDict($li);
  8157. if (allData && !$.isEmptyObject(allData)) {
  8158. // #507: convert data-hidecheckbox (lower case) to hideCheckbox
  8159. for (lowerCaseAttr in NODE_ATTR_LOWERCASE_MAP) {
  8160. if (allData.hasOwnProperty(lowerCaseAttr)) {
  8161. allData[
  8162. NODE_ATTR_LOWERCASE_MAP[lowerCaseAttr]
  8163. ] = allData[lowerCaseAttr];
  8164. delete allData[lowerCaseAttr];
  8165. }
  8166. }
  8167. // #56: Allow to set special node.attributes from data-...
  8168. for (i = 0, l = NODE_ATTRS.length; i < l; i++) {
  8169. tmp = NODE_ATTRS[i];
  8170. tmp2 = allData[tmp];
  8171. if (tmp2 != null) {
  8172. delete allData[tmp];
  8173. d[tmp] = tmp2;
  8174. }
  8175. }
  8176. // All other data-... goes to node.data...
  8177. $.extend(d.data, allData);
  8178. }
  8179. // Recursive reading of child nodes, if LI tag contains an UL tag
  8180. $ul = $li.find(">ul").first();
  8181. if ($ul.length) {
  8182. d.children = $.ui.fancytree.parseHtml($ul);
  8183. } else {
  8184. d.children = d.lazy ? undefined : null;
  8185. }
  8186. children.push(d);
  8187. // FT.debug("parse ", d, children);
  8188. });
  8189. return children;
  8190. },
  8191. /** Add Fancytree extension definition to the list of globally available extensions.
  8192. *
  8193. * @param {object} definition
  8194. */
  8195. registerExtension: function(definition) {
  8196. _assert(
  8197. definition.name != null,
  8198. "extensions must have a `name` property."
  8199. );
  8200. _assert(
  8201. definition.version != null,
  8202. "extensions must have a `version` property."
  8203. );
  8204. $.ui.fancytree._extensions[definition.name] = definition;
  8205. },
  8206. /** Inverse of escapeHtml().
  8207. *
  8208. * @param {string} s
  8209. * @returns {string}
  8210. */
  8211. unescapeHtml: function(s) {
  8212. var e = document.createElement("div");
  8213. e.innerHTML = s;
  8214. return e.childNodes.length === 0
  8215. ? ""
  8216. : e.childNodes[0].nodeValue;
  8217. },
  8218. /** Write warning message to console if debugLevel >= 2.
  8219. * @param {string} msg
  8220. */
  8221. warn: function(msg) {
  8222. if ($.ui.fancytree.debugLevel >= 2) {
  8223. consoleApply("warn", arguments);
  8224. }
  8225. },
  8226. }
  8227. );
  8228. // Value returned by `require('jquery.fancytree')`
  8229. return $.ui.fancytree;
  8230. }); // End of closure
  8231. /*! Extension 'jquery.fancytree.childcounter.js' */// Extending Fancytree
  8232. // ===================
  8233. //
  8234. // See also the [live demo](https://wwWendt.de/tech/fancytree/demo/sample-ext-childcounter.html) of this code.
  8235. //
  8236. // Every extension should have a comment header containing some information
  8237. // about the author, copyright and licensing. Also a pointer to the latest
  8238. // source code.
  8239. // Prefix with `/*!` so the comment is not removed by the minifier.
  8240. /*!
  8241. * jquery.fancytree.childcounter.js
  8242. *
  8243. * Add a child counter bubble to tree nodes.
  8244. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8245. *
  8246. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  8247. *
  8248. * Released under the MIT license
  8249. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8250. *
  8251. * @version 2.37.0
  8252. * @date 2020-09-11T18:58:08Z
  8253. */
  8254. // To keep the global namespace clean, we wrap everything in a closure.
  8255. // The UMD wrapper pattern defines the dependencies on jQuery and the
  8256. // Fancytree core module, and makes sure that we can use the `require()`
  8257. // syntax with package loaders.
  8258. (function(factory) {
  8259. if (typeof define === "function" && define.amd) {
  8260. // AMD. Register as an anonymous module.
  8261. define(["jquery", "./jquery.fancytree"], factory);
  8262. } else if (typeof module === "object" && module.exports) {
  8263. // Node/CommonJS
  8264. require("./jquery.fancytree");
  8265. module.exports = factory(require("jquery"));
  8266. } else {
  8267. // Browser globals
  8268. factory(jQuery);
  8269. }
  8270. })(function($) {
  8271. // Consider to use [strict mode](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)
  8272. "use strict";
  8273. // The [coding guidelines](http://contribute.jquery.org/style-guide/js/)
  8274. // require jshint /eslint compliance.
  8275. // But for this sample, we want to allow unused variables for demonstration purpose.
  8276. /*eslint-disable no-unused-vars */
  8277. // Adding methods
  8278. // --------------
  8279. // New member functions can be added to the `Fancytree` class.
  8280. // This function will be available for every tree instance:
  8281. //
  8282. // var tree = $.ui.fancytree.getTree("#tree");
  8283. // tree.countSelected(false);
  8284. $.ui.fancytree._FancytreeClass.prototype.countSelected = function(topOnly) {
  8285. var tree = this,
  8286. treeOptions = tree.options;
  8287. return tree.getSelectedNodes(topOnly).length;
  8288. };
  8289. // The `FancytreeNode` class can also be easily extended. This would be called
  8290. // like
  8291. // node.updateCounters();
  8292. //
  8293. // It is also good practice to add a docstring comment.
  8294. /**
  8295. * [ext-childcounter] Update counter badges for `node` and its parents.
  8296. * May be called in the `loadChildren` event, to update parents of lazy loaded
  8297. * nodes.
  8298. * @alias FancytreeNode#updateCounters
  8299. * @requires jquery.fancytree.childcounters.js
  8300. */
  8301. $.ui.fancytree._FancytreeNodeClass.prototype.updateCounters = function() {
  8302. var node = this,
  8303. $badge = $("span.fancytree-childcounter", node.span),
  8304. extOpts = node.tree.options.childcounter,
  8305. count = node.countChildren(extOpts.deep);
  8306. node.data.childCounter = count;
  8307. if (
  8308. (count || !extOpts.hideZeros) &&
  8309. (!node.isExpanded() || !extOpts.hideExpanded)
  8310. ) {
  8311. if (!$badge.length) {
  8312. $badge = $("<span class='fancytree-childcounter'/>").appendTo(
  8313. $(
  8314. "span.fancytree-icon,span.fancytree-custom-icon",
  8315. node.span
  8316. )
  8317. );
  8318. }
  8319. $badge.text(count);
  8320. } else {
  8321. $badge.remove();
  8322. }
  8323. if (extOpts.deep && !node.isTopLevel() && !node.isRootNode()) {
  8324. node.parent.updateCounters();
  8325. }
  8326. };
  8327. // Finally, we can extend the widget API and create functions that are called
  8328. // like so:
  8329. //
  8330. // $("#tree").fancytree("widgetMethod1", "abc");
  8331. $.ui.fancytree.prototype.widgetMethod1 = function(arg1) {
  8332. var tree = this.tree;
  8333. return arg1;
  8334. };
  8335. // Register a Fancytree extension
  8336. // ------------------------------
  8337. // A full blown extension, extension is available for all trees and can be
  8338. // enabled like so (see also the [live demo](https://wwWendt.de/tech/fancytree/demo/sample-ext-childcounter.html)):
  8339. //
  8340. // <script src="../src/jquery.fancytree.js"></script>
  8341. // <script src="../src/jquery.fancytree.childcounter.js"></script>
  8342. // ...
  8343. //
  8344. // $("#tree").fancytree({
  8345. // extensions: ["childcounter"],
  8346. // childcounter: {
  8347. // hideExpanded: true
  8348. // },
  8349. // ...
  8350. // });
  8351. //
  8352. /* 'childcounter' extension */
  8353. $.ui.fancytree.registerExtension({
  8354. // Every extension must be registered by a unique name.
  8355. name: "childcounter",
  8356. // Version information should be compliant with [semver](http://semver.org)
  8357. version: "2.37.0",
  8358. // Extension specific options and their defaults.
  8359. // This options will be available as `tree.options.childcounter.hideExpanded`
  8360. options: {
  8361. deep: true,
  8362. hideZeros: true,
  8363. hideExpanded: false,
  8364. },
  8365. // Attributes other than `options` (or functions) can be defined here, and
  8366. // will be added to the tree.ext.EXTNAME namespace, in this case `tree.ext.childcounter.foo`.
  8367. // They can also be accessed as `this._local.foo` from within the extension
  8368. // methods.
  8369. foo: 42,
  8370. // Local functions are prefixed with an underscore '_'.
  8371. // Callable as `this._local._appendCounter()`.
  8372. _appendCounter: function(bar) {
  8373. var tree = this;
  8374. },
  8375. // **Override virtual methods for this extension.**
  8376. //
  8377. // Fancytree implements a number of 'hook methods', prefixed by 'node...' or 'tree...'.
  8378. // with a `ctx` argument (see [EventData](https://wwWendt.de/tech/fancytree/doc/jsdoc/global.html#EventData)
  8379. // for details) and an extended calling context:<br>
  8380. // `this` : the Fancytree instance<br>
  8381. // `this._local`: the namespace that contains extension attributes and private methods (same as this.ext.EXTNAME)<br>
  8382. // `this._super`: the virtual function that was overridden (member of previous extension or Fancytree)
  8383. //
  8384. // See also the [complete list of available hook functions](https://wwWendt.de/tech/fancytree/doc/jsdoc/Fancytree_Hooks.html).
  8385. /* Init */
  8386. // `treeInit` is triggered when a tree is initalized. We can set up classes or
  8387. // bind event handlers here...
  8388. treeInit: function(ctx) {
  8389. var tree = this, // same as ctx.tree,
  8390. opts = ctx.options,
  8391. extOpts = ctx.options.childcounter;
  8392. // Optionally check for dependencies with other extensions
  8393. /* this._requireExtension("glyph", false, false); */
  8394. // Call the base implementation
  8395. this._superApply(arguments);
  8396. // Add a class to the tree container
  8397. this.$container.addClass("fancytree-ext-childcounter");
  8398. },
  8399. // Destroy this tree instance (we only call the default implementation, so
  8400. // this method could as well be omitted).
  8401. treeDestroy: function(ctx) {
  8402. this._superApply(arguments);
  8403. },
  8404. // Overload the `renderTitle` hook, to append a counter badge
  8405. nodeRenderTitle: function(ctx, title) {
  8406. var node = ctx.node,
  8407. extOpts = ctx.options.childcounter,
  8408. count =
  8409. node.data.childCounter == null
  8410. ? node.countChildren(extOpts.deep)
  8411. : +node.data.childCounter;
  8412. // Let the base implementation render the title
  8413. // We use `_super()` instead of `_superApply()` here, since it is a little bit
  8414. // more performant when called often
  8415. this._super(ctx, title);
  8416. // Append a counter badge
  8417. if (
  8418. (count || !extOpts.hideZeros) &&
  8419. (!node.isExpanded() || !extOpts.hideExpanded)
  8420. ) {
  8421. $(
  8422. "span.fancytree-icon,span.fancytree-custom-icon",
  8423. node.span
  8424. ).append(
  8425. $("<span class='fancytree-childcounter'/>").text(count)
  8426. );
  8427. }
  8428. },
  8429. // Overload the `setExpanded` hook, so the counters are updated
  8430. nodeSetExpanded: function(ctx, flag, callOpts) {
  8431. var tree = ctx.tree,
  8432. node = ctx.node;
  8433. // Let the base implementation expand/collapse the node, then redraw the title
  8434. // after the animation has finished
  8435. return this._superApply(arguments).always(function() {
  8436. tree.nodeRenderTitle(ctx);
  8437. });
  8438. },
  8439. // End of extension definition
  8440. });
  8441. // Value returned by `require('jquery.fancytree..')`
  8442. return $.ui.fancytree;
  8443. }); // End of closure
  8444. /*! Extension 'jquery.fancytree.clones.js' *//*!
  8445. *
  8446. * jquery.fancytree.clones.js
  8447. * Support faster lookup of nodes by key and shared ref-ids.
  8448. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8449. *
  8450. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  8451. *
  8452. * Released under the MIT license
  8453. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8454. *
  8455. * @version 2.37.0
  8456. * @date 2020-09-11T18:58:08Z
  8457. */
  8458. (function(factory) {
  8459. if (typeof define === "function" && define.amd) {
  8460. // AMD. Register as an anonymous module.
  8461. define(["jquery", "./jquery.fancytree"], factory);
  8462. } else if (typeof module === "object" && module.exports) {
  8463. // Node/CommonJS
  8464. require("./jquery.fancytree");
  8465. module.exports = factory(require("jquery"));
  8466. } else {
  8467. // Browser globals
  8468. factory(jQuery);
  8469. }
  8470. })(function($) {
  8471. "use strict";
  8472. /*******************************************************************************
  8473. * Private functions and variables
  8474. */
  8475. function _assert(cond, msg) {
  8476. // TODO: see qunit.js extractStacktrace()
  8477. if (!cond) {
  8478. msg = msg ? ": " + msg : "";
  8479. $.error("Assertion failed" + msg);
  8480. }
  8481. }
  8482. /* Return first occurrence of member from array. */
  8483. function _removeArrayMember(arr, elem) {
  8484. // TODO: use Array.indexOf for IE >= 9
  8485. var i;
  8486. for (i = arr.length - 1; i >= 0; i--) {
  8487. if (arr[i] === elem) {
  8488. arr.splice(i, 1);
  8489. return true;
  8490. }
  8491. }
  8492. return false;
  8493. }
  8494. /**
  8495. * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)
  8496. *
  8497. * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
  8498. * @see http://github.com/garycourt/murmurhash-js
  8499. * @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a>
  8500. * @see http://sites.google.com/site/murmurhash/
  8501. *
  8502. * @param {string} key ASCII only
  8503. * @param {boolean} [asString=false]
  8504. * @param {number} seed Positive integer only
  8505. * @return {number} 32-bit positive integer hash
  8506. */
  8507. function hashMurmur3(key, asString, seed) {
  8508. /*eslint-disable no-bitwise */
  8509. var h1b,
  8510. k1,
  8511. remainder = key.length & 3,
  8512. bytes = key.length - remainder,
  8513. h1 = seed,
  8514. c1 = 0xcc9e2d51,
  8515. c2 = 0x1b873593,
  8516. i = 0;
  8517. while (i < bytes) {
  8518. k1 =
  8519. (key.charCodeAt(i) & 0xff) |
  8520. ((key.charCodeAt(++i) & 0xff) << 8) |
  8521. ((key.charCodeAt(++i) & 0xff) << 16) |
  8522. ((key.charCodeAt(++i) & 0xff) << 24);
  8523. ++i;
  8524. k1 =
  8525. ((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
  8526. 0xffffffff;
  8527. k1 = (k1 << 15) | (k1 >>> 17);
  8528. k1 =
  8529. ((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
  8530. 0xffffffff;
  8531. h1 ^= k1;
  8532. h1 = (h1 << 13) | (h1 >>> 19);
  8533. h1b =
  8534. ((h1 & 0xffff) * 5 + ((((h1 >>> 16) * 5) & 0xffff) << 16)) &
  8535. 0xffffffff;
  8536. h1 =
  8537. (h1b & 0xffff) +
  8538. 0x6b64 +
  8539. ((((h1b >>> 16) + 0xe654) & 0xffff) << 16);
  8540. }
  8541. k1 = 0;
  8542. switch (remainder) {
  8543. case 3:
  8544. k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
  8545. // fall through
  8546. case 2:
  8547. k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
  8548. // fall through
  8549. case 1:
  8550. k1 ^= key.charCodeAt(i) & 0xff;
  8551. k1 =
  8552. ((k1 & 0xffff) * c1 +
  8553. ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
  8554. 0xffffffff;
  8555. k1 = (k1 << 15) | (k1 >>> 17);
  8556. k1 =
  8557. ((k1 & 0xffff) * c2 +
  8558. ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
  8559. 0xffffffff;
  8560. h1 ^= k1;
  8561. }
  8562. h1 ^= key.length;
  8563. h1 ^= h1 >>> 16;
  8564. h1 =
  8565. ((h1 & 0xffff) * 0x85ebca6b +
  8566. ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) &
  8567. 0xffffffff;
  8568. h1 ^= h1 >>> 13;
  8569. h1 =
  8570. ((h1 & 0xffff) * 0xc2b2ae35 +
  8571. ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16)) &
  8572. 0xffffffff;
  8573. h1 ^= h1 >>> 16;
  8574. if (asString) {
  8575. // Convert to 8 digit hex string
  8576. return ("0000000" + (h1 >>> 0).toString(16)).substr(-8);
  8577. }
  8578. return h1 >>> 0;
  8579. /*eslint-enable no-bitwise */
  8580. }
  8581. /*
  8582. * Return a unique key for node by calculating the hash of the parents refKey-list.
  8583. */
  8584. function calcUniqueKey(node) {
  8585. var key,
  8586. h1,
  8587. path = $.map(node.getParentList(false, true), function(e) {
  8588. return e.refKey || e.key;
  8589. });
  8590. path = path.join("/");
  8591. // 32-bit has a high probability of collisions, so we pump up to 64-bit
  8592. // https://security.stackexchange.com/q/209882/207588
  8593. h1 = hashMurmur3(path, true);
  8594. key = "id_" + h1 + hashMurmur3(h1 + path, true);
  8595. return key;
  8596. }
  8597. /**
  8598. * [ext-clones] Return a list of clone-nodes (i.e. same refKey) or null.
  8599. * @param {boolean} [includeSelf=false]
  8600. * @returns {FancytreeNode[] | null}
  8601. *
  8602. * @alias FancytreeNode#getCloneList
  8603. * @requires jquery.fancytree.clones.js
  8604. */
  8605. $.ui.fancytree._FancytreeNodeClass.prototype.getCloneList = function(
  8606. includeSelf
  8607. ) {
  8608. var key,
  8609. tree = this.tree,
  8610. refList = tree.refMap[this.refKey] || null,
  8611. keyMap = tree.keyMap;
  8612. if (refList) {
  8613. key = this.key;
  8614. // Convert key list to node list
  8615. if (includeSelf) {
  8616. refList = $.map(refList, function(val) {
  8617. return keyMap[val];
  8618. });
  8619. } else {
  8620. refList = $.map(refList, function(val) {
  8621. return val === key ? null : keyMap[val];
  8622. });
  8623. if (refList.length < 1) {
  8624. refList = null;
  8625. }
  8626. }
  8627. }
  8628. return refList;
  8629. };
  8630. /**
  8631. * [ext-clones] Return true if this node has at least another clone with same refKey.
  8632. * @returns {boolean}
  8633. *
  8634. * @alias FancytreeNode#isClone
  8635. * @requires jquery.fancytree.clones.js
  8636. */
  8637. $.ui.fancytree._FancytreeNodeClass.prototype.isClone = function() {
  8638. var refKey = this.refKey || null,
  8639. refList = (refKey && this.tree.refMap[refKey]) || null;
  8640. return !!(refList && refList.length > 1);
  8641. };
  8642. /**
  8643. * [ext-clones] Update key and/or refKey for an existing node.
  8644. * @param {string} key
  8645. * @param {string} refKey
  8646. * @returns {boolean}
  8647. *
  8648. * @alias FancytreeNode#reRegister
  8649. * @requires jquery.fancytree.clones.js
  8650. */
  8651. $.ui.fancytree._FancytreeNodeClass.prototype.reRegister = function(
  8652. key,
  8653. refKey
  8654. ) {
  8655. key = key == null ? null : "" + key;
  8656. refKey = refKey == null ? null : "" + refKey;
  8657. // this.debug("reRegister", key, refKey);
  8658. var tree = this.tree,
  8659. prevKey = this.key,
  8660. prevRefKey = this.refKey,
  8661. keyMap = tree.keyMap,
  8662. refMap = tree.refMap,
  8663. refList = refMap[prevRefKey] || null,
  8664. // curCloneKeys = refList ? node.getCloneList(true),
  8665. modified = false;
  8666. // Key has changed: update all references
  8667. if (key != null && key !== this.key) {
  8668. if (keyMap[key]) {
  8669. $.error(
  8670. "[ext-clones] reRegister(" +
  8671. key +
  8672. "): already exists: " +
  8673. this
  8674. );
  8675. }
  8676. // Update keyMap
  8677. delete keyMap[prevKey];
  8678. keyMap[key] = this;
  8679. // Update refMap
  8680. if (refList) {
  8681. refMap[prevRefKey] = $.map(refList, function(e) {
  8682. return e === prevKey ? key : e;
  8683. });
  8684. }
  8685. this.key = key;
  8686. modified = true;
  8687. }
  8688. // refKey has changed
  8689. if (refKey != null && refKey !== this.refKey) {
  8690. // Remove previous refKeys
  8691. if (refList) {
  8692. if (refList.length === 1) {
  8693. delete refMap[prevRefKey];
  8694. } else {
  8695. refMap[prevRefKey] = $.map(refList, function(e) {
  8696. return e === prevKey ? null : e;
  8697. });
  8698. }
  8699. }
  8700. // Add refKey
  8701. if (refMap[refKey]) {
  8702. refMap[refKey].append(key);
  8703. } else {
  8704. refMap[refKey] = [this.key];
  8705. }
  8706. this.refKey = refKey;
  8707. modified = true;
  8708. }
  8709. return modified;
  8710. };
  8711. /**
  8712. * [ext-clones] Define a refKey for an existing node.
  8713. * @param {string} refKey
  8714. * @returns {boolean}
  8715. *
  8716. * @alias FancytreeNode#setRefKey
  8717. * @requires jquery.fancytree.clones.js
  8718. * @since 2.16
  8719. */
  8720. $.ui.fancytree._FancytreeNodeClass.prototype.setRefKey = function(refKey) {
  8721. return this.reRegister(null, refKey);
  8722. };
  8723. /**
  8724. * [ext-clones] Return all nodes with a given refKey (null if not found).
  8725. * @param {string} refKey
  8726. * @param {FancytreeNode} [rootNode] optionally restrict results to descendants of this node
  8727. * @returns {FancytreeNode[] | null}
  8728. * @alias Fancytree#getNodesByRef
  8729. * @requires jquery.fancytree.clones.js
  8730. */
  8731. $.ui.fancytree._FancytreeClass.prototype.getNodesByRef = function(
  8732. refKey,
  8733. rootNode
  8734. ) {
  8735. var keyMap = this.keyMap,
  8736. refList = this.refMap[refKey] || null;
  8737. if (refList) {
  8738. // Convert key list to node list
  8739. if (rootNode) {
  8740. refList = $.map(refList, function(val) {
  8741. var node = keyMap[val];
  8742. return node.isDescendantOf(rootNode) ? node : null;
  8743. });
  8744. } else {
  8745. refList = $.map(refList, function(val) {
  8746. return keyMap[val];
  8747. });
  8748. }
  8749. if (refList.length < 1) {
  8750. refList = null;
  8751. }
  8752. }
  8753. return refList;
  8754. };
  8755. /**
  8756. * [ext-clones] Replace a refKey with a new one.
  8757. * @param {string} oldRefKey
  8758. * @param {string} newRefKey
  8759. * @alias Fancytree#changeRefKey
  8760. * @requires jquery.fancytree.clones.js
  8761. */
  8762. $.ui.fancytree._FancytreeClass.prototype.changeRefKey = function(
  8763. oldRefKey,
  8764. newRefKey
  8765. ) {
  8766. var i,
  8767. node,
  8768. keyMap = this.keyMap,
  8769. refList = this.refMap[oldRefKey] || null;
  8770. if (refList) {
  8771. for (i = 0; i < refList.length; i++) {
  8772. node = keyMap[refList[i]];
  8773. node.refKey = newRefKey;
  8774. }
  8775. delete this.refMap[oldRefKey];
  8776. this.refMap[newRefKey] = refList;
  8777. }
  8778. };
  8779. /*******************************************************************************
  8780. * Extension code
  8781. */
  8782. $.ui.fancytree.registerExtension({
  8783. name: "clones",
  8784. version: "2.37.0",
  8785. // Default options for this extension.
  8786. options: {
  8787. highlightActiveClones: true, // set 'fancytree-active-clone' on active clones and all peers
  8788. highlightClones: false, // set 'fancytree-clone' class on any node that has at least one clone
  8789. },
  8790. treeCreate: function(ctx) {
  8791. this._superApply(arguments);
  8792. ctx.tree.refMap = {};
  8793. ctx.tree.keyMap = {};
  8794. },
  8795. treeInit: function(ctx) {
  8796. this.$container.addClass("fancytree-ext-clones");
  8797. _assert(ctx.options.defaultKey == null);
  8798. // Generate unique / reproducible default keys
  8799. ctx.options.defaultKey = function(node) {
  8800. return calcUniqueKey(node);
  8801. };
  8802. // The default implementation loads initial data
  8803. this._superApply(arguments);
  8804. },
  8805. treeClear: function(ctx) {
  8806. ctx.tree.refMap = {};
  8807. ctx.tree.keyMap = {};
  8808. return this._superApply(arguments);
  8809. },
  8810. treeRegisterNode: function(ctx, add, node) {
  8811. var refList,
  8812. len,
  8813. tree = ctx.tree,
  8814. keyMap = tree.keyMap,
  8815. refMap = tree.refMap,
  8816. key = node.key,
  8817. refKey = node && node.refKey != null ? "" + node.refKey : null;
  8818. // ctx.tree.debug("clones.treeRegisterNode", add, node);
  8819. if (node.isStatusNode()) {
  8820. return this._super(ctx, add, node);
  8821. }
  8822. if (add) {
  8823. if (keyMap[node.key] != null) {
  8824. var other = keyMap[node.key],
  8825. msg =
  8826. "clones.treeRegisterNode: duplicate key '" +
  8827. node.key +
  8828. "': /" +
  8829. node.getPath(true) +
  8830. " => " +
  8831. other.getPath(true);
  8832. // Sometimes this exception is not visible in the console,
  8833. // so we also write it:
  8834. tree.error(msg);
  8835. $.error(msg);
  8836. }
  8837. keyMap[key] = node;
  8838. if (refKey) {
  8839. refList = refMap[refKey];
  8840. if (refList) {
  8841. refList.push(key);
  8842. if (
  8843. refList.length === 2 &&
  8844. ctx.options.clones.highlightClones
  8845. ) {
  8846. // Mark peer node, if it just became a clone (no need to
  8847. // mark current node, since it will be rendered later anyway)
  8848. keyMap[refList[0]].renderStatus();
  8849. }
  8850. } else {
  8851. refMap[refKey] = [key];
  8852. }
  8853. // node.debug("clones.treeRegisterNode: add clone =>", refMap[refKey]);
  8854. }
  8855. } else {
  8856. if (keyMap[key] == null) {
  8857. $.error(
  8858. "clones.treeRegisterNode: node.key not registered: " +
  8859. node.key
  8860. );
  8861. }
  8862. delete keyMap[key];
  8863. if (refKey) {
  8864. refList = refMap[refKey];
  8865. // node.debug("clones.treeRegisterNode: remove clone BEFORE =>", refMap[refKey]);
  8866. if (refList) {
  8867. len = refList.length;
  8868. if (len <= 1) {
  8869. _assert(len === 1);
  8870. _assert(refList[0] === key);
  8871. delete refMap[refKey];
  8872. } else {
  8873. _removeArrayMember(refList, key);
  8874. // Unmark peer node, if this was the only clone
  8875. if (
  8876. len === 2 &&
  8877. ctx.options.clones.highlightClones
  8878. ) {
  8879. // node.debug("clones.treeRegisterNode: last =>", node.getCloneList());
  8880. keyMap[refList[0]].renderStatus();
  8881. }
  8882. }
  8883. // node.debug("clones.treeRegisterNode: remove clone =>", refMap[refKey]);
  8884. }
  8885. }
  8886. }
  8887. return this._super(ctx, add, node);
  8888. },
  8889. nodeRenderStatus: function(ctx) {
  8890. var $span,
  8891. res,
  8892. node = ctx.node;
  8893. res = this._super(ctx);
  8894. if (ctx.options.clones.highlightClones) {
  8895. $span = $(node[ctx.tree.statusClassPropName]);
  8896. // Only if span already exists
  8897. if ($span.length && node.isClone()) {
  8898. // node.debug("clones.nodeRenderStatus: ", ctx.options.clones.highlightClones);
  8899. $span.addClass("fancytree-clone");
  8900. }
  8901. }
  8902. return res;
  8903. },
  8904. nodeSetActive: function(ctx, flag, callOpts) {
  8905. var res,
  8906. scpn = ctx.tree.statusClassPropName,
  8907. node = ctx.node;
  8908. res = this._superApply(arguments);
  8909. if (ctx.options.clones.highlightActiveClones && node.isClone()) {
  8910. $.each(node.getCloneList(true), function(idx, n) {
  8911. // n.debug("clones.nodeSetActive: ", flag !== false);
  8912. $(n[scpn]).toggleClass(
  8913. "fancytree-active-clone",
  8914. flag !== false
  8915. );
  8916. });
  8917. }
  8918. return res;
  8919. },
  8920. });
  8921. // Value returned by `require('jquery.fancytree..')`
  8922. return $.ui.fancytree;
  8923. }); // End of closure
  8924. /*! Extension 'jquery.fancytree.dnd5.js' *//*!
  8925. * jquery.fancytree.dnd5.js
  8926. *
  8927. * Drag-and-drop support (native HTML5).
  8928. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  8929. *
  8930. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  8931. *
  8932. * Released under the MIT license
  8933. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  8934. *
  8935. * @version 2.37.0
  8936. * @date 2020-09-11T18:58:08Z
  8937. */
  8938. /*
  8939. #TODO
  8940. Compatiblity when dragging between *separate* windows:
  8941. Drag from Chrome Edge FF IE11 Safari
  8942. To Chrome ok ok ok NO ?
  8943. Edge ok ok ok NO ?
  8944. FF ok ok ok NO ?
  8945. IE 11 ok ok ok ok ?
  8946. Safari ? ? ? ? ok
  8947. */
  8948. (function(factory) {
  8949. if (typeof define === "function" && define.amd) {
  8950. // AMD. Register as an anonymous module.
  8951. define(["jquery", "./jquery.fancytree"], factory);
  8952. } else if (typeof module === "object" && module.exports) {
  8953. // Node/CommonJS
  8954. require("./jquery.fancytree");
  8955. module.exports = factory(require("jquery"));
  8956. } else {
  8957. // Browser globals
  8958. factory(jQuery);
  8959. }
  8960. })(function($) {
  8961. "use strict";
  8962. /******************************************************************************
  8963. * Private functions and variables
  8964. */
  8965. var FT = $.ui.fancytree,
  8966. isMac = /Mac/.test(navigator.platform),
  8967. classDragSource = "fancytree-drag-source",
  8968. classDragRemove = "fancytree-drag-remove",
  8969. classDropAccept = "fancytree-drop-accept",
  8970. classDropAfter = "fancytree-drop-after",
  8971. classDropBefore = "fancytree-drop-before",
  8972. classDropOver = "fancytree-drop-over",
  8973. classDropReject = "fancytree-drop-reject",
  8974. classDropTarget = "fancytree-drop-target",
  8975. nodeMimeType = "application/x-fancytree-node",
  8976. $dropMarker = null,
  8977. $dragImage,
  8978. $extraHelper,
  8979. SOURCE_NODE = null,
  8980. SOURCE_NODE_LIST = null,
  8981. $sourceList = null,
  8982. DRAG_ENTER_RESPONSE = null,
  8983. // SESSION_DATA = null, // plain object passed to events as `data`
  8984. SUGGESTED_DROP_EFFECT = null,
  8985. REQUESTED_DROP_EFFECT = null,
  8986. REQUESTED_EFFECT_ALLOWED = null,
  8987. LAST_HIT_MODE = null,
  8988. DRAG_OVER_STAMP = null; // Time when a node entered the 'over' hitmode
  8989. /* */
  8990. function _clearGlobals() {
  8991. DRAG_ENTER_RESPONSE = null;
  8992. DRAG_OVER_STAMP = null;
  8993. REQUESTED_DROP_EFFECT = null;
  8994. REQUESTED_EFFECT_ALLOWED = null;
  8995. SUGGESTED_DROP_EFFECT = null;
  8996. SOURCE_NODE = null;
  8997. SOURCE_NODE_LIST = null;
  8998. if ($sourceList) {
  8999. $sourceList.removeClass(classDragSource + " " + classDragRemove);
  9000. }
  9001. $sourceList = null;
  9002. if ($dropMarker) {
  9003. $dropMarker.hide();
  9004. }
  9005. // Take this badge off of me - I can't use it anymore:
  9006. if ($extraHelper) {
  9007. $extraHelper.remove();
  9008. $extraHelper = null;
  9009. }
  9010. }
  9011. /* Convert number to string and prepend +/-; return empty string for 0.*/
  9012. function offsetString(n) {
  9013. // eslint-disable-next-line no-nested-ternary
  9014. return n === 0 ? "" : n > 0 ? "+" + n : "" + n;
  9015. }
  9016. /* Convert a dragEnter() or dragOver() response to a canonical form.
  9017. * Return false or plain object
  9018. * @param {string|object|boolean} r
  9019. * @return {object|false}
  9020. */
  9021. function normalizeDragEnterResponse(r) {
  9022. var res;
  9023. if (!r) {
  9024. return false;
  9025. }
  9026. if ($.isPlainObject(r)) {
  9027. res = {
  9028. over: !!r.over,
  9029. before: !!r.before,
  9030. after: !!r.after,
  9031. };
  9032. } else if ($.isArray(r)) {
  9033. res = {
  9034. over: $.inArray("over", r) >= 0,
  9035. before: $.inArray("before", r) >= 0,
  9036. after: $.inArray("after", r) >= 0,
  9037. };
  9038. } else {
  9039. res = {
  9040. over: r === true || r === "over",
  9041. before: r === true || r === "before",
  9042. after: r === true || r === "after",
  9043. };
  9044. }
  9045. if (Object.keys(res).length === 0) {
  9046. return false;
  9047. }
  9048. // if( Object.keys(res).length === 1 ) {
  9049. // res.unique = res[0];
  9050. // }
  9051. return res;
  9052. }
  9053. /* Convert a dataTransfer.effectAllowed to a canonical form.
  9054. * Return false or plain object
  9055. * @param {string|boolean} r
  9056. * @return {object|false}
  9057. */
  9058. // function normalizeEffectAllowed(r) {
  9059. // if (!r || r === "none") {
  9060. // return false;
  9061. // }
  9062. // var all = r === "all",
  9063. // res = {
  9064. // copy: all || /copy/i.test(r),
  9065. // link: all || /link/i.test(r),
  9066. // move: all || /move/i.test(r),
  9067. // };
  9068. // return res;
  9069. // }
  9070. /* Implement auto scrolling when drag cursor is in top/bottom area of scroll parent. */
  9071. function autoScroll(tree, event) {
  9072. var spOfs,
  9073. scrollTop,
  9074. delta,
  9075. dndOpts = tree.options.dnd5,
  9076. sp = tree.$scrollParent[0],
  9077. sensitivity = dndOpts.scrollSensitivity,
  9078. speed = dndOpts.scrollSpeed,
  9079. scrolled = 0;
  9080. if (sp !== document && sp.tagName !== "HTML") {
  9081. spOfs = tree.$scrollParent.offset();
  9082. scrollTop = sp.scrollTop;
  9083. if (spOfs.top + sp.offsetHeight - event.pageY < sensitivity) {
  9084. delta =
  9085. sp.scrollHeight -
  9086. tree.$scrollParent.innerHeight() -
  9087. scrollTop;
  9088. // console.log ("sp.offsetHeight: " + sp.offsetHeight
  9089. // + ", spOfs.top: " + spOfs.top
  9090. // + ", scrollTop: " + scrollTop
  9091. // + ", innerHeight: " + tree.$scrollParent.innerHeight()
  9092. // + ", scrollHeight: " + sp.scrollHeight
  9093. // + ", delta: " + delta
  9094. // );
  9095. if (delta > 0) {
  9096. sp.scrollTop = scrolled = scrollTop + speed;
  9097. }
  9098. } else if (scrollTop > 0 && event.pageY - spOfs.top < sensitivity) {
  9099. sp.scrollTop = scrolled = scrollTop - speed;
  9100. }
  9101. } else {
  9102. scrollTop = $(document).scrollTop();
  9103. if (scrollTop > 0 && event.pageY - scrollTop < sensitivity) {
  9104. scrolled = scrollTop - speed;
  9105. $(document).scrollTop(scrolled);
  9106. } else if (
  9107. $(window).height() - (event.pageY - scrollTop) <
  9108. sensitivity
  9109. ) {
  9110. scrolled = scrollTop + speed;
  9111. $(document).scrollTop(scrolled);
  9112. }
  9113. }
  9114. if (scrolled) {
  9115. tree.debug("autoScroll: " + scrolled + "px");
  9116. }
  9117. return scrolled;
  9118. }
  9119. /* Guess dropEffect from modifier keys.
  9120. * Using rules suggested here:
  9121. * https://ux.stackexchange.com/a/83769
  9122. * @returns
  9123. * 'copy', 'link', 'move', or 'none'
  9124. */
  9125. function evalEffectModifiers(tree, event, effectDefault) {
  9126. var res = effectDefault;
  9127. if (isMac) {
  9128. if (event.metaKey && event.altKey) {
  9129. // Mac: [Control] + [Option]
  9130. res = "link";
  9131. } else if (event.ctrlKey) {
  9132. // Chrome on Mac: [Control]
  9133. res = "link";
  9134. } else if (event.metaKey) {
  9135. // Mac: [Command]
  9136. res = "move";
  9137. } else if (event.altKey) {
  9138. // Mac: [Option]
  9139. res = "copy";
  9140. }
  9141. } else {
  9142. if (event.ctrlKey) {
  9143. // Windows: [Ctrl]
  9144. res = "copy";
  9145. } else if (event.shiftKey) {
  9146. // Windows: [Shift]
  9147. res = "move";
  9148. } else if (event.altKey) {
  9149. // Windows: [Alt]
  9150. res = "link";
  9151. }
  9152. }
  9153. if (res !== SUGGESTED_DROP_EFFECT) {
  9154. tree.info(
  9155. "evalEffectModifiers: " +
  9156. event.type +
  9157. " - evalEffectModifiers(): " +
  9158. SUGGESTED_DROP_EFFECT +
  9159. " -> " +
  9160. res
  9161. );
  9162. }
  9163. SUGGESTED_DROP_EFFECT = res;
  9164. // tree.debug("evalEffectModifiers: " + res);
  9165. return res;
  9166. }
  9167. /*
  9168. * Check if the previous callback (dragEnter, dragOver, ...) has changed
  9169. * the `data` object and apply those settings.
  9170. *
  9171. * Safari:
  9172. * It seems that `dataTransfer.dropEffect` can only be set on dragStart, and will remain
  9173. * even if the cursor changes when [Alt] or [Ctrl] are pressed (?)
  9174. * Using rules suggested here:
  9175. * https://ux.stackexchange.com/a/83769
  9176. * @returns
  9177. * 'copy', 'link', 'move', or 'none'
  9178. */
  9179. function prepareDropEffectCallback(event, data) {
  9180. var tree = data.tree,
  9181. dataTransfer = data.dataTransfer;
  9182. if (event.type === "dragstart") {
  9183. data.effectAllowed = tree.options.dnd5.effectAllowed;
  9184. data.dropEffect = tree.options.dnd5.dropEffectDefault;
  9185. } else {
  9186. data.effectAllowed = REQUESTED_EFFECT_ALLOWED;
  9187. data.dropEffect = REQUESTED_DROP_EFFECT;
  9188. }
  9189. data.dropEffectSuggested = evalEffectModifiers(
  9190. tree,
  9191. event,
  9192. tree.options.dnd5.dropEffectDefault
  9193. );
  9194. data.isMove = data.dropEffect === "move";
  9195. data.files = dataTransfer.files || [];
  9196. // if (REQUESTED_EFFECT_ALLOWED !== dataTransfer.effectAllowed) {
  9197. // tree.warn(
  9198. // "prepareDropEffectCallback(" +
  9199. // event.type +
  9200. // "): dataTransfer.effectAllowed changed from " +
  9201. // REQUESTED_EFFECT_ALLOWED +
  9202. // " -> " +
  9203. // dataTransfer.effectAllowed
  9204. // );
  9205. // }
  9206. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9207. // tree.warn(
  9208. // "prepareDropEffectCallback(" +
  9209. // event.type +
  9210. // "): dataTransfer.dropEffect changed from requested " +
  9211. // REQUESTED_DROP_EFFECT +
  9212. // " to " +
  9213. // dataTransfer.dropEffect
  9214. // );
  9215. // }
  9216. }
  9217. function applyDropEffectCallback(event, data, allowDrop) {
  9218. var tree = data.tree,
  9219. dataTransfer = data.dataTransfer;
  9220. if (
  9221. event.type !== "dragstart" &&
  9222. REQUESTED_EFFECT_ALLOWED !== data.effectAllowed
  9223. ) {
  9224. tree.warn(
  9225. "effectAllowed should only be changed in dragstart event: " +
  9226. event.type +
  9227. ": data.effectAllowed changed from " +
  9228. REQUESTED_EFFECT_ALLOWED +
  9229. " -> " +
  9230. data.effectAllowed
  9231. );
  9232. }
  9233. if (allowDrop === false) {
  9234. tree.info("applyDropEffectCallback: allowDrop === false");
  9235. data.effectAllowed = "none";
  9236. data.dropEffect = "none";
  9237. }
  9238. // if (REQUESTED_DROP_EFFECT !== data.dropEffect) {
  9239. // tree.debug(
  9240. // "applyDropEffectCallback(" +
  9241. // event.type +
  9242. // "): data.dropEffect changed from previous " +
  9243. // REQUESTED_DROP_EFFECT +
  9244. // " to " +
  9245. // data.dropEffect
  9246. // );
  9247. // }
  9248. data.isMove = data.dropEffect === "move";
  9249. // data.isMove = data.dropEffectSuggested === "move";
  9250. // `effectAllowed` must only be defined in dragstart event, so we
  9251. // store it in a global variable for reference
  9252. if (event.type === "dragstart") {
  9253. REQUESTED_EFFECT_ALLOWED = data.effectAllowed;
  9254. REQUESTED_DROP_EFFECT = data.dropEffect;
  9255. }
  9256. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9257. // data.tree.info(
  9258. // "applyDropEffectCallback(" +
  9259. // event.type +
  9260. // "): dataTransfer.dropEffect changed from " +
  9261. // REQUESTED_DROP_EFFECT +
  9262. // " -> " +
  9263. // dataTransfer.dropEffect
  9264. // );
  9265. // }
  9266. dataTransfer.effectAllowed = REQUESTED_EFFECT_ALLOWED;
  9267. dataTransfer.dropEffect = REQUESTED_DROP_EFFECT;
  9268. // tree.debug(
  9269. // "applyDropEffectCallback(" +
  9270. // event.type +
  9271. // "): set " +
  9272. // dataTransfer.dropEffect +
  9273. // "/" +
  9274. // dataTransfer.effectAllowed
  9275. // );
  9276. // if (REQUESTED_DROP_EFFECT !== dataTransfer.dropEffect) {
  9277. // data.tree.warn(
  9278. // "applyDropEffectCallback(" +
  9279. // event.type +
  9280. // "): could not set dataTransfer.dropEffect to " +
  9281. // REQUESTED_DROP_EFFECT +
  9282. // ": got " +
  9283. // dataTransfer.dropEffect
  9284. // );
  9285. // }
  9286. return REQUESTED_DROP_EFFECT;
  9287. }
  9288. /* Handle dragover event (fired every x ms) on valid drop targets.
  9289. *
  9290. * - Auto-scroll when cursor is in border regions
  9291. * - Apply restrictioan like 'preventVoidMoves'
  9292. * - Calculate hit mode
  9293. * - Calculate drop effect
  9294. * - Trigger dragOver() callback to let user modify hit mode and drop effect
  9295. * - Adjust the drop marker accordingly
  9296. *
  9297. * @returns hitMode
  9298. */
  9299. function handleDragOver(event, data) {
  9300. // Implement auto-scrolling
  9301. if (data.options.dnd5.scroll) {
  9302. autoScroll(data.tree, event);
  9303. }
  9304. // Bail out with previous response if we get an invalid dragover
  9305. if (!data.node) {
  9306. data.tree.warn("Ignored dragover for non-node"); //, event, data);
  9307. return LAST_HIT_MODE;
  9308. }
  9309. var markerOffsetX,
  9310. nodeOfs,
  9311. pos,
  9312. relPosY,
  9313. hitMode = null,
  9314. tree = data.tree,
  9315. options = tree.options,
  9316. dndOpts = options.dnd5,
  9317. targetNode = data.node,
  9318. sourceNode = data.otherNode,
  9319. markerAt = "center",
  9320. $target = $(targetNode.span),
  9321. $targetTitle = $target.find("span.fancytree-title");
  9322. if (DRAG_ENTER_RESPONSE === false) {
  9323. tree.debug("Ignored dragover, since dragenter returned false.");
  9324. return false;
  9325. } else if (typeof DRAG_ENTER_RESPONSE === "string") {
  9326. $.error("assert failed: dragenter returned string");
  9327. }
  9328. // Calculate hitMode from relative cursor position.
  9329. nodeOfs = $target.offset();
  9330. relPosY = (event.pageY - nodeOfs.top) / $target.height();
  9331. if (event.pageY === undefined) {
  9332. tree.warn("event.pageY is undefined: see issue #1013.");
  9333. }
  9334. if (DRAG_ENTER_RESPONSE.after && relPosY > 0.75) {
  9335. hitMode = "after";
  9336. } else if (
  9337. !DRAG_ENTER_RESPONSE.over &&
  9338. DRAG_ENTER_RESPONSE.after &&
  9339. relPosY > 0.5
  9340. ) {
  9341. hitMode = "after";
  9342. } else if (DRAG_ENTER_RESPONSE.before && relPosY <= 0.25) {
  9343. hitMode = "before";
  9344. } else if (
  9345. !DRAG_ENTER_RESPONSE.over &&
  9346. DRAG_ENTER_RESPONSE.before &&
  9347. relPosY <= 0.5
  9348. ) {
  9349. hitMode = "before";
  9350. } else if (DRAG_ENTER_RESPONSE.over) {
  9351. hitMode = "over";
  9352. }
  9353. // Prevent no-ops like 'before source node'
  9354. // TODO: these are no-ops when moving nodes, but not in copy mode
  9355. if (dndOpts.preventVoidMoves && data.dropEffect === "move") {
  9356. if (targetNode === sourceNode) {
  9357. targetNode.debug("Drop over source node prevented.");
  9358. hitMode = null;
  9359. } else if (
  9360. hitMode === "before" &&
  9361. sourceNode &&
  9362. targetNode === sourceNode.getNextSibling()
  9363. ) {
  9364. targetNode.debug("Drop after source node prevented.");
  9365. hitMode = null;
  9366. } else if (
  9367. hitMode === "after" &&
  9368. sourceNode &&
  9369. targetNode === sourceNode.getPrevSibling()
  9370. ) {
  9371. targetNode.debug("Drop before source node prevented.");
  9372. hitMode = null;
  9373. } else if (
  9374. hitMode === "over" &&
  9375. sourceNode &&
  9376. sourceNode.parent === targetNode &&
  9377. sourceNode.isLastSibling()
  9378. ) {
  9379. targetNode.debug("Drop last child over own parent prevented.");
  9380. hitMode = null;
  9381. }
  9382. }
  9383. // Let callback modify the calculated hitMode
  9384. data.hitMode = hitMode;
  9385. if (hitMode && dndOpts.dragOver) {
  9386. prepareDropEffectCallback(event, data);
  9387. dndOpts.dragOver(targetNode, data);
  9388. var allowDrop = !!hitMode;
  9389. applyDropEffectCallback(event, data, allowDrop);
  9390. hitMode = data.hitMode;
  9391. }
  9392. LAST_HIT_MODE = hitMode;
  9393. //
  9394. if (hitMode === "after" || hitMode === "before" || hitMode === "over") {
  9395. markerOffsetX = dndOpts.dropMarkerOffsetX || 0;
  9396. switch (hitMode) {
  9397. case "before":
  9398. markerAt = "top";
  9399. markerOffsetX += dndOpts.dropMarkerInsertOffsetX || 0;
  9400. break;
  9401. case "after":
  9402. markerAt = "bottom";
  9403. markerOffsetX += dndOpts.dropMarkerInsertOffsetX || 0;
  9404. break;
  9405. }
  9406. pos = {
  9407. my: "left" + offsetString(markerOffsetX) + " center",
  9408. at: "left " + markerAt,
  9409. of: $targetTitle,
  9410. };
  9411. if (options.rtl) {
  9412. pos.my = "right" + offsetString(-markerOffsetX) + " center";
  9413. pos.at = "right " + markerAt;
  9414. // console.log("rtl", pos);
  9415. }
  9416. $dropMarker
  9417. .toggleClass(classDropAfter, hitMode === "after")
  9418. .toggleClass(classDropOver, hitMode === "over")
  9419. .toggleClass(classDropBefore, hitMode === "before")
  9420. .show()
  9421. .position(FT.fixPositionOptions(pos));
  9422. } else {
  9423. $dropMarker.hide();
  9424. // console.log("hide dropmarker")
  9425. }
  9426. $(targetNode.span)
  9427. .toggleClass(
  9428. classDropTarget,
  9429. hitMode === "after" ||
  9430. hitMode === "before" ||
  9431. hitMode === "over"
  9432. )
  9433. .toggleClass(classDropAfter, hitMode === "after")
  9434. .toggleClass(classDropBefore, hitMode === "before")
  9435. .toggleClass(classDropAccept, hitMode === "over")
  9436. .toggleClass(classDropReject, hitMode === false);
  9437. return hitMode;
  9438. }
  9439. /*
  9440. * Handle dragstart drag dragend events on the container
  9441. */
  9442. function onDragEvent(event) {
  9443. var json,
  9444. tree = this,
  9445. dndOpts = tree.options.dnd5,
  9446. node = FT.getNode(event),
  9447. dataTransfer =
  9448. event.dataTransfer || event.originalEvent.dataTransfer,
  9449. data = {
  9450. tree: tree,
  9451. node: node,
  9452. options: tree.options,
  9453. originalEvent: event.originalEvent,
  9454. widget: tree.widget,
  9455. dataTransfer: dataTransfer,
  9456. useDefaultImage: true,
  9457. dropEffect: undefined,
  9458. dropEffectSuggested: undefined,
  9459. effectAllowed: undefined, // set by dragstart
  9460. files: undefined, // only for drop events
  9461. isCancelled: undefined, // set by dragend
  9462. isMove: undefined,
  9463. };
  9464. switch (event.type) {
  9465. case "dragstart":
  9466. if (!node) {
  9467. tree.info("Ignored dragstart on a non-node.");
  9468. return false;
  9469. }
  9470. // Store current source node in different formats
  9471. SOURCE_NODE = node;
  9472. // Also optionally store selected nodes
  9473. if (dndOpts.multiSource === false) {
  9474. SOURCE_NODE_LIST = [node];
  9475. } else if (dndOpts.multiSource === true) {
  9476. if (node.isSelected()) {
  9477. SOURCE_NODE_LIST = tree.getSelectedNodes();
  9478. } else {
  9479. SOURCE_NODE_LIST = [node];
  9480. }
  9481. } else {
  9482. SOURCE_NODE_LIST = dndOpts.multiSource(node, data);
  9483. }
  9484. // Cache as array of jQuery objects for faster access:
  9485. $sourceList = $(
  9486. $.map(SOURCE_NODE_LIST, function(n) {
  9487. return n.span;
  9488. })
  9489. );
  9490. // Set visual feedback
  9491. $sourceList.addClass(classDragSource);
  9492. // Set payload
  9493. // Note:
  9494. // Transfer data is only accessible on dragstart and drop!
  9495. // For all other events the formats and kinds in the drag
  9496. // data store list of items representing dragged data can be
  9497. // enumerated, but the data itself is unavailable and no new
  9498. // data can be added.
  9499. var nodeData = node.toDict();
  9500. nodeData.treeId = node.tree._id;
  9501. json = JSON.stringify(nodeData);
  9502. try {
  9503. dataTransfer.setData(nodeMimeType, json);
  9504. dataTransfer.setData("text/html", $(node.span).html());
  9505. dataTransfer.setData("text/plain", node.title);
  9506. } catch (ex) {
  9507. // IE only accepts 'text' type
  9508. tree.warn(
  9509. "Could not set data (IE only accepts 'text') - " + ex
  9510. );
  9511. }
  9512. // We always need to set the 'text' type if we want to drag
  9513. // Because IE 11 only accepts this single type.
  9514. // If we pass JSON here, IE can can access all node properties,
  9515. // even when the source lives in another window. (D'n'd inside
  9516. // the same window will always work.)
  9517. // The drawback is, that in this case ALL browsers will see
  9518. // the JSON representation as 'text', so dragging
  9519. // to a text field will insert the JSON string instead of
  9520. // the node title.
  9521. if (dndOpts.setTextTypeJson) {
  9522. dataTransfer.setData("text", json);
  9523. } else {
  9524. dataTransfer.setData("text", node.title);
  9525. }
  9526. // Set the allowed drag modes (combinations of move, copy, and link)
  9527. // (effectAllowed can only be set in the dragstart event.)
  9528. // This can be overridden in the dragStart() callback
  9529. prepareDropEffectCallback(event, data);
  9530. // Let user cancel or modify above settings
  9531. // Realize potential changes by previous callback
  9532. if (dndOpts.dragStart(node, data) === false) {
  9533. // Cancel dragging
  9534. // dataTransfer.dropEffect = "none";
  9535. _clearGlobals();
  9536. return false;
  9537. }
  9538. applyDropEffectCallback(event, data);
  9539. // Unless user set `data.useDefaultImage` to false in dragStart,
  9540. // generata a default drag image now:
  9541. $extraHelper = null;
  9542. if (data.useDefaultImage) {
  9543. // Set the title as drag image (otherwise it would contain the expander)
  9544. $dragImage = $(node.span).find(".fancytree-title");
  9545. if (SOURCE_NODE_LIST && SOURCE_NODE_LIST.length > 1) {
  9546. // Add a counter badge to node title if dragging more than one node.
  9547. // We want this, because the element that is used as drag image
  9548. // must be *visible* in the DOM, so we cannot create some hidden
  9549. // custom markup.
  9550. // See https://kryogenix.org/code/browser/custom-drag-image.html
  9551. // Also, since IE 11 and Edge don't support setDragImage() alltogether,
  9552. // it gives som feedback to the user.
  9553. // The badge will be removed later on drag end.
  9554. $extraHelper = $(
  9555. "<span class='fancytree-childcounter'/>"
  9556. )
  9557. .text("+" + (SOURCE_NODE_LIST.length - 1))
  9558. .appendTo($dragImage);
  9559. }
  9560. if (dataTransfer.setDragImage) {
  9561. // IE 11 and Edge do not support this
  9562. dataTransfer.setDragImage($dragImage[0], -10, -10);
  9563. }
  9564. }
  9565. return true;
  9566. case "drag":
  9567. // Called every few milliseconds (no matter if the
  9568. // cursor is over a valid drop target)
  9569. // data.tree.info("drag", SOURCE_NODE)
  9570. prepareDropEffectCallback(event, data);
  9571. dndOpts.dragDrag(node, data);
  9572. applyDropEffectCallback(event, data);
  9573. $sourceList.toggleClass(classDragRemove, data.isMove);
  9574. break;
  9575. case "dragend":
  9576. // Called at the end of a d'n'd process (after drop)
  9577. // Note caveat: If drop removed the dragged source element,
  9578. // we may not get this event, since the target does not exist
  9579. // anymore
  9580. prepareDropEffectCallback(event, data);
  9581. _clearGlobals();
  9582. data.isCancelled = !LAST_HIT_MODE;
  9583. dndOpts.dragEnd(node, data, !LAST_HIT_MODE);
  9584. // applyDropEffectCallback(event, data);
  9585. break;
  9586. }
  9587. }
  9588. /*
  9589. * Handle dragenter dragover dragleave drop events on the container
  9590. */
  9591. function onDropEvent(event) {
  9592. var json,
  9593. allowAutoExpand,
  9594. nodeData,
  9595. isSourceFtNode,
  9596. r,
  9597. res,
  9598. tree = this,
  9599. dndOpts = tree.options.dnd5,
  9600. allowDrop = null,
  9601. node = FT.getNode(event),
  9602. dataTransfer =
  9603. event.dataTransfer || event.originalEvent.dataTransfer,
  9604. data = {
  9605. tree: tree,
  9606. node: node,
  9607. options: tree.options,
  9608. originalEvent: event.originalEvent,
  9609. widget: tree.widget,
  9610. hitMode: DRAG_ENTER_RESPONSE,
  9611. dataTransfer: dataTransfer,
  9612. otherNode: SOURCE_NODE || null,
  9613. otherNodeList: SOURCE_NODE_LIST || null,
  9614. otherNodeData: null, // set by drop event
  9615. useDefaultImage: true,
  9616. dropEffect: undefined,
  9617. dropEffectSuggested: undefined,
  9618. effectAllowed: undefined, // set by dragstart
  9619. files: null, // list of File objects (may be [])
  9620. isCancelled: undefined, // set by drop event
  9621. isMove: undefined,
  9622. };
  9623. // data.isMove = dropEffect === "move";
  9624. switch (event.type) {
  9625. case "dragenter":
  9626. // The dragenter event is fired when a dragged element or
  9627. // text selection enters a valid drop target.
  9628. DRAG_OVER_STAMP = null;
  9629. if (!node) {
  9630. // Sometimes we get dragenter for the container element
  9631. tree.debug(
  9632. "Ignore non-node " +
  9633. event.type +
  9634. ": " +
  9635. event.target.tagName +
  9636. "." +
  9637. event.target.className
  9638. );
  9639. DRAG_ENTER_RESPONSE = false;
  9640. break;
  9641. }
  9642. $(node.span)
  9643. .addClass(classDropOver)
  9644. .removeClass(classDropAccept + " " + classDropReject);
  9645. // Data is only readable in the dragstart and drop event,
  9646. // but we can check for the type:
  9647. isSourceFtNode =
  9648. $.inArray(nodeMimeType, dataTransfer.types) >= 0;
  9649. if (dndOpts.preventNonNodes && !isSourceFtNode) {
  9650. node.debug("Reject dropping a non-node.");
  9651. DRAG_ENTER_RESPONSE = false;
  9652. break;
  9653. } else if (
  9654. dndOpts.preventForeignNodes &&
  9655. (!SOURCE_NODE || SOURCE_NODE.tree !== node.tree)
  9656. ) {
  9657. node.debug("Reject dropping a foreign node.");
  9658. DRAG_ENTER_RESPONSE = false;
  9659. break;
  9660. } else if (
  9661. dndOpts.preventSameParent &&
  9662. data.otherNode &&
  9663. data.otherNode.tree === node.tree &&
  9664. node.parent === data.otherNode.parent
  9665. ) {
  9666. node.debug("Reject dropping as sibling (same parent).");
  9667. DRAG_ENTER_RESPONSE = false;
  9668. break;
  9669. } else if (
  9670. dndOpts.preventRecursion &&
  9671. data.otherNode &&
  9672. data.otherNode.tree === node.tree &&
  9673. node.isDescendantOf(data.otherNode)
  9674. ) {
  9675. node.debug("Reject dropping below own ancestor.");
  9676. DRAG_ENTER_RESPONSE = false;
  9677. break;
  9678. } else if (dndOpts.preventLazyParents && !node.isLoaded()) {
  9679. node.warn("Drop over unloaded target node prevented.");
  9680. DRAG_ENTER_RESPONSE = false;
  9681. break;
  9682. }
  9683. $dropMarker.show();
  9684. // Call dragEnter() to figure out if (and where) dropping is allowed
  9685. prepareDropEffectCallback(event, data);
  9686. r = dndOpts.dragEnter(node, data);
  9687. res = normalizeDragEnterResponse(r);
  9688. // alert("res:" + JSON.stringify(res))
  9689. DRAG_ENTER_RESPONSE = res;
  9690. allowDrop = res && (res.over || res.before || res.after);
  9691. applyDropEffectCallback(event, data, allowDrop);
  9692. break;
  9693. case "dragover":
  9694. if (!node) {
  9695. tree.debug(
  9696. "Ignore non-node " +
  9697. event.type +
  9698. ": " +
  9699. event.target.tagName +
  9700. "." +
  9701. event.target.className
  9702. );
  9703. break;
  9704. }
  9705. // The dragover event is fired when an element or text
  9706. // selection is being dragged over a valid drop target
  9707. // (every few hundred milliseconds).
  9708. // tree.debug(
  9709. // event.type +
  9710. // ": dropEffect: " +
  9711. // dataTransfer.dropEffect
  9712. // );
  9713. prepareDropEffectCallback(event, data);
  9714. LAST_HIT_MODE = handleDragOver(event, data);
  9715. // The flag controls the preventDefault() below:
  9716. allowDrop = !!LAST_HIT_MODE;
  9717. allowAutoExpand =
  9718. LAST_HIT_MODE === "over" || LAST_HIT_MODE === false;
  9719. if (
  9720. allowAutoExpand &&
  9721. !node.expanded &&
  9722. node.hasChildren() !== false
  9723. ) {
  9724. if (!DRAG_OVER_STAMP) {
  9725. DRAG_OVER_STAMP = Date.now();
  9726. } else if (
  9727. dndOpts.autoExpandMS &&
  9728. Date.now() - DRAG_OVER_STAMP > dndOpts.autoExpandMS &&
  9729. !node.isLoading() &&
  9730. (!dndOpts.dragExpand ||
  9731. dndOpts.dragExpand(node, data) !== false)
  9732. ) {
  9733. node.setExpanded();
  9734. }
  9735. } else {
  9736. DRAG_OVER_STAMP = null;
  9737. }
  9738. break;
  9739. case "dragleave":
  9740. // NOTE: dragleave is fired AFTER the dragenter event of the
  9741. // FOLLOWING element.
  9742. if (!node) {
  9743. tree.debug(
  9744. "Ignore non-node " +
  9745. event.type +
  9746. ": " +
  9747. event.target.tagName +
  9748. "." +
  9749. event.target.className
  9750. );
  9751. break;
  9752. }
  9753. if (!$(node.span).hasClass(classDropOver)) {
  9754. node.debug("Ignore dragleave (multi).");
  9755. break;
  9756. }
  9757. $(node.span).removeClass(
  9758. classDropOver +
  9759. " " +
  9760. classDropAccept +
  9761. " " +
  9762. classDropReject
  9763. );
  9764. node.scheduleAction("cancel");
  9765. dndOpts.dragLeave(node, data);
  9766. $dropMarker.hide();
  9767. break;
  9768. case "drop":
  9769. // Data is only readable in the (dragstart and) drop event:
  9770. if ($.inArray(nodeMimeType, dataTransfer.types) >= 0) {
  9771. nodeData = dataTransfer.getData(nodeMimeType);
  9772. tree.info(
  9773. event.type +
  9774. ": getData('application/x-fancytree-node'): '" +
  9775. nodeData +
  9776. "'"
  9777. );
  9778. }
  9779. if (!nodeData) {
  9780. // 1. Source is not a Fancytree node, or
  9781. // 2. If the FT mime type was set, but returns '', this
  9782. // is probably IE 11 (which only supports 'text')
  9783. nodeData = dataTransfer.getData("text");
  9784. tree.info(
  9785. event.type + ": getData('text'): '" + nodeData + "'"
  9786. );
  9787. }
  9788. if (nodeData) {
  9789. try {
  9790. // 'text' type may contain JSON if IE is involved
  9791. // and setTextTypeJson option was set
  9792. json = JSON.parse(nodeData);
  9793. if (json.title !== undefined) {
  9794. data.otherNodeData = json;
  9795. }
  9796. } catch (ex) {
  9797. // assume 'text' type contains plain text, so `otherNodeData`
  9798. // should not be set
  9799. }
  9800. }
  9801. tree.debug(
  9802. event.type +
  9803. ": nodeData: '" +
  9804. nodeData +
  9805. "', otherNodeData: ",
  9806. data.otherNodeData
  9807. );
  9808. $(node.span).removeClass(
  9809. classDropOver +
  9810. " " +
  9811. classDropAccept +
  9812. " " +
  9813. classDropReject
  9814. );
  9815. // Let user implement the actual drop operation
  9816. data.hitMode = LAST_HIT_MODE;
  9817. prepareDropEffectCallback(event, data, !LAST_HIT_MODE);
  9818. data.isCancelled = !LAST_HIT_MODE;
  9819. var orgSourceElem = SOURCE_NODE && SOURCE_NODE.span,
  9820. orgSourceTree = SOURCE_NODE && SOURCE_NODE.tree;
  9821. dndOpts.dragDrop(node, data);
  9822. // applyDropEffectCallback(event, data);
  9823. // Prevent browser's default drop handling, i.e. open as link, ...
  9824. event.preventDefault();
  9825. if (orgSourceElem && !document.body.contains(orgSourceElem)) {
  9826. // The drop handler removed the original drag source from
  9827. // the DOM, so the dragend event will probaly not fire.
  9828. if (orgSourceTree === tree) {
  9829. tree.debug(
  9830. "Drop handler removed source element: generating dragEnd."
  9831. );
  9832. dndOpts.dragEnd(SOURCE_NODE, data);
  9833. } else {
  9834. tree.warn(
  9835. "Drop handler removed source element: dragend event may be lost."
  9836. );
  9837. }
  9838. }
  9839. _clearGlobals();
  9840. break;
  9841. }
  9842. // Dnd API madness: we must PREVENT default handling to enable dropping
  9843. if (allowDrop) {
  9844. event.preventDefault();
  9845. return false;
  9846. }
  9847. }
  9848. /** [ext-dnd5] Return a Fancytree instance, from element, index, event, or jQueryObject.
  9849. *
  9850. * @returns {FancytreeNode[]} List of nodes (empty if no drag operation)
  9851. * @example
  9852. * $.ui.fancytree.getDragNodeList();
  9853. *
  9854. * @alias Fancytree_Static#getDragNodeList
  9855. * @requires jquery.fancytree.dnd5.js
  9856. * @since 2.31
  9857. */
  9858. $.ui.fancytree.getDragNodeList = function() {
  9859. return SOURCE_NODE_LIST || [];
  9860. };
  9861. /** [ext-dnd5] Return the FancytreeNode that is currently being dragged.
  9862. *
  9863. * If multiple nodes are dragged, only the first is returned.
  9864. *
  9865. * @returns {FancytreeNode | null} dragged nodes or null if no drag operation
  9866. * @example
  9867. * $.ui.fancytree.getDragNode();
  9868. *
  9869. * @alias Fancytree_Static#getDragNode
  9870. * @requires jquery.fancytree.dnd5.js
  9871. * @since 2.31
  9872. */
  9873. $.ui.fancytree.getDragNode = function() {
  9874. return SOURCE_NODE;
  9875. };
  9876. /******************************************************************************
  9877. *
  9878. */
  9879. $.ui.fancytree.registerExtension({
  9880. name: "dnd5",
  9881. version: "2.37.0",
  9882. // Default options for this extension.
  9883. options: {
  9884. autoExpandMS: 1500, // Expand nodes after n milliseconds of hovering
  9885. dropMarkerInsertOffsetX: -16, // Additional offset for drop-marker with hitMode = "before"/"after"
  9886. dropMarkerOffsetX: -24, // Absolute position offset for .fancytree-drop-marker relatively to ..fancytree-title (icon/img near a node accepting drop)
  9887. // #1021 `document.body` is not available yet
  9888. dropMarkerParent: "body", // Root Container used for drop marker (could be a shadow root)
  9889. multiSource: false, // true: Drag multiple (i.e. selected) nodes. Also a callback() is allowed
  9890. effectAllowed: "all", // Restrict the possible cursor shapes and modifier operations (can also be set in the dragStart event)
  9891. // dropEffect: "auto", // 'copy'|'link'|'move'|'auto'(calculate from `effectAllowed`+modifier keys) or callback(node, data) that returns such string.
  9892. dropEffectDefault: "move", // Default dropEffect ('copy', 'link', or 'move') when no modifier is pressed (overide in dragDrag, dragOver).
  9893. preventForeignNodes: false, // Prevent dropping nodes from different Fancytrees
  9894. preventLazyParents: true, // Prevent dropping items on unloaded lazy Fancytree nodes
  9895. preventNonNodes: false, // Prevent dropping items other than Fancytree nodes
  9896. preventRecursion: true, // Prevent dropping nodes on own descendants
  9897. preventSameParent: false, // Prevent dropping nodes under same direct parent
  9898. preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
  9899. scroll: true, // Enable auto-scrolling while dragging
  9900. scrollSensitivity: 20, // Active top/bottom margin in pixel
  9901. scrollSpeed: 5, // Pixel per event
  9902. setTextTypeJson: false, // Allow dragging of nodes to different IE windows
  9903. // Events (drag support)
  9904. dragStart: null, // Callback(sourceNode, data), return true, to enable dnd drag
  9905. dragDrag: $.noop, // Callback(sourceNode, data)
  9906. dragEnd: $.noop, // Callback(sourceNode, data)
  9907. // Events (drop support)
  9908. dragEnter: null, // Callback(targetNode, data), return true, to enable dnd drop
  9909. dragOver: $.noop, // Callback(targetNode, data)
  9910. dragExpand: $.noop, // Callback(targetNode, data), return false to prevent autoExpand
  9911. dragDrop: $.noop, // Callback(targetNode, data)
  9912. dragLeave: $.noop, // Callback(targetNode, data)
  9913. },
  9914. treeInit: function(ctx) {
  9915. var $temp,
  9916. tree = ctx.tree,
  9917. opts = ctx.options,
  9918. glyph = opts.glyph || null,
  9919. dndOpts = opts.dnd5;
  9920. if ($.inArray("dnd", opts.extensions) >= 0) {
  9921. $.error("Extensions 'dnd' and 'dnd5' are mutually exclusive.");
  9922. }
  9923. if (dndOpts.dragStop) {
  9924. $.error(
  9925. "dragStop is not used by ext-dnd5. Use dragEnd instead."
  9926. );
  9927. }
  9928. if (dndOpts.preventRecursiveMoves != null) {
  9929. $.error(
  9930. "preventRecursiveMoves was renamed to preventRecursion."
  9931. );
  9932. }
  9933. // Implement `opts.createNode` event to add the 'draggable' attribute
  9934. // #680: this must happen before calling super.treeInit()
  9935. if (dndOpts.dragStart) {
  9936. FT.overrideMethod(ctx.options, "createNode", function(
  9937. event,
  9938. data
  9939. ) {
  9940. // Default processing if any
  9941. this._super.apply(this, arguments);
  9942. if (data.node.span) {
  9943. data.node.span.draggable = true;
  9944. } else {
  9945. data.node.warn("Cannot add `draggable`: no span tag");
  9946. }
  9947. });
  9948. }
  9949. this._superApply(arguments);
  9950. this.$container.addClass("fancytree-ext-dnd5");
  9951. // Store the current scroll parent, which may be the tree
  9952. // container, any enclosing div, or the document.
  9953. // #761: scrollParent() always needs a container child
  9954. $temp = $("<span>").appendTo(this.$container);
  9955. this.$scrollParent = $temp.scrollParent();
  9956. $temp.remove();
  9957. $dropMarker = $("#fancytree-drop-marker");
  9958. if (!$dropMarker.length) {
  9959. $dropMarker = $("<div id='fancytree-drop-marker'></div>")
  9960. .hide()
  9961. .css({
  9962. "z-index": 1000,
  9963. // Drop marker should not steal dragenter/dragover events:
  9964. "pointer-events": "none",
  9965. })
  9966. .prependTo(dndOpts.dropMarkerParent);
  9967. if (glyph) {
  9968. FT.setSpanIcon(
  9969. $dropMarker[0],
  9970. glyph.map._addClass,
  9971. glyph.map.dropMarker
  9972. );
  9973. }
  9974. }
  9975. $dropMarker.toggleClass("fancytree-rtl", !!opts.rtl);
  9976. // Enable drag support if dragStart() is specified:
  9977. if (dndOpts.dragStart) {
  9978. // Bind drag event handlers
  9979. tree.$container.on(
  9980. "dragstart drag dragend",
  9981. onDragEvent.bind(tree)
  9982. );
  9983. }
  9984. // Enable drop support if dragEnter() is specified:
  9985. if (dndOpts.dragEnter) {
  9986. // Bind drop event handlers
  9987. tree.$container.on(
  9988. "dragenter dragover dragleave drop",
  9989. onDropEvent.bind(tree)
  9990. );
  9991. }
  9992. },
  9993. });
  9994. // Value returned by `require('jquery.fancytree..')`
  9995. return $.ui.fancytree;
  9996. }); // End of closure
  9997. /*! Extension 'jquery.fancytree.edit.js' *//*!
  9998. * jquery.fancytree.edit.js
  9999. *
  10000. * Make node titles editable.
  10001. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10002. *
  10003. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  10004. *
  10005. * Released under the MIT license
  10006. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10007. *
  10008. * @version 2.37.0
  10009. * @date 2020-09-11T18:58:08Z
  10010. */
  10011. (function(factory) {
  10012. if (typeof define === "function" && define.amd) {
  10013. // AMD. Register as an anonymous module.
  10014. define(["jquery", "./jquery.fancytree"], factory);
  10015. } else if (typeof module === "object" && module.exports) {
  10016. // Node/CommonJS
  10017. require("./jquery.fancytree");
  10018. module.exports = factory(require("jquery"));
  10019. } else {
  10020. // Browser globals
  10021. factory(jQuery);
  10022. }
  10023. })(function($) {
  10024. "use strict";
  10025. /*******************************************************************************
  10026. * Private functions and variables
  10027. */
  10028. var isMac = /Mac/.test(navigator.platform),
  10029. escapeHtml = $.ui.fancytree.escapeHtml,
  10030. unescapeHtml = $.ui.fancytree.unescapeHtml;
  10031. /**
  10032. * [ext-edit] Start inline editing of current node title.
  10033. *
  10034. * @alias FancytreeNode#editStart
  10035. * @requires Fancytree
  10036. */
  10037. $.ui.fancytree._FancytreeNodeClass.prototype.editStart = function() {
  10038. var $input,
  10039. node = this,
  10040. tree = this.tree,
  10041. local = tree.ext.edit,
  10042. instOpts = tree.options.edit,
  10043. $title = $(".fancytree-title", node.span),
  10044. eventData = {
  10045. node: node,
  10046. tree: tree,
  10047. options: tree.options,
  10048. isNew: $(node[tree.statusClassPropName]).hasClass(
  10049. "fancytree-edit-new"
  10050. ),
  10051. orgTitle: node.title,
  10052. input: null,
  10053. dirty: false,
  10054. };
  10055. // beforeEdit may want to modify the title before editing
  10056. if (
  10057. instOpts.beforeEdit.call(
  10058. node,
  10059. { type: "beforeEdit" },
  10060. eventData
  10061. ) === false
  10062. ) {
  10063. return false;
  10064. }
  10065. $.ui.fancytree.assert(!local.currentNode, "recursive edit");
  10066. local.currentNode = this;
  10067. local.eventData = eventData;
  10068. // Disable standard Fancytree mouse- and key handling
  10069. tree.widget._unbind();
  10070. local.lastDraggableAttrValue = node.span.draggable;
  10071. if (local.lastDraggableAttrValue) {
  10072. node.span.draggable = false;
  10073. }
  10074. // #116: ext-dnd prevents the blur event, so we have to catch outer clicks
  10075. $(document).on("mousedown.fancytree-edit", function(event) {
  10076. if (!$(event.target).hasClass("fancytree-edit-input")) {
  10077. node.editEnd(true, event);
  10078. }
  10079. });
  10080. // Replace node with <input>
  10081. $input = $("<input />", {
  10082. class: "fancytree-edit-input",
  10083. type: "text",
  10084. value: tree.options.escapeTitles
  10085. ? eventData.orgTitle
  10086. : unescapeHtml(eventData.orgTitle),
  10087. });
  10088. local.eventData.input = $input;
  10089. if (instOpts.adjustWidthOfs != null) {
  10090. $input.width($title.width() + instOpts.adjustWidthOfs);
  10091. }
  10092. if (instOpts.inputCss != null) {
  10093. $input.css(instOpts.inputCss);
  10094. }
  10095. $title.html($input);
  10096. // Focus <input> and bind keyboard handler
  10097. $input
  10098. .focus()
  10099. .change(function(event) {
  10100. $input.addClass("fancytree-edit-dirty");
  10101. })
  10102. .on("keydown", function(event) {
  10103. switch (event.which) {
  10104. case $.ui.keyCode.ESCAPE:
  10105. node.editEnd(false, event);
  10106. break;
  10107. case $.ui.keyCode.ENTER:
  10108. node.editEnd(true, event);
  10109. return false; // so we don't start editmode on Mac
  10110. }
  10111. event.stopPropagation();
  10112. })
  10113. .blur(function(event) {
  10114. return node.editEnd(true, event);
  10115. });
  10116. instOpts.edit.call(node, { type: "edit" }, eventData);
  10117. };
  10118. /**
  10119. * [ext-edit] Stop inline editing.
  10120. * @param {Boolean} [applyChanges=false] false: cancel edit, true: save (if modified)
  10121. * @alias FancytreeNode#editEnd
  10122. * @requires jquery.fancytree.edit.js
  10123. */
  10124. $.ui.fancytree._FancytreeNodeClass.prototype.editEnd = function(
  10125. applyChanges,
  10126. _event
  10127. ) {
  10128. var newVal,
  10129. node = this,
  10130. tree = this.tree,
  10131. local = tree.ext.edit,
  10132. eventData = local.eventData,
  10133. instOpts = tree.options.edit,
  10134. $title = $(".fancytree-title", node.span),
  10135. $input = $title.find("input.fancytree-edit-input");
  10136. if (instOpts.trim) {
  10137. $input.val($.trim($input.val()));
  10138. }
  10139. newVal = $input.val();
  10140. eventData.dirty = newVal !== node.title;
  10141. eventData.originalEvent = _event;
  10142. // Find out, if saving is required
  10143. if (applyChanges === false) {
  10144. // If true/false was passed, honor this (except in rename mode, if unchanged)
  10145. eventData.save = false;
  10146. } else if (eventData.isNew) {
  10147. // In create mode, we save everything, except for empty text
  10148. eventData.save = newVal !== "";
  10149. } else {
  10150. // In rename mode, we save everyting, except for empty or unchanged text
  10151. eventData.save = eventData.dirty && newVal !== "";
  10152. }
  10153. // Allow to break (keep editor open), modify input, or re-define data.save
  10154. if (
  10155. instOpts.beforeClose.call(
  10156. node,
  10157. { type: "beforeClose" },
  10158. eventData
  10159. ) === false
  10160. ) {
  10161. return false;
  10162. }
  10163. if (
  10164. eventData.save &&
  10165. instOpts.save.call(node, { type: "save" }, eventData) === false
  10166. ) {
  10167. return false;
  10168. }
  10169. $input.removeClass("fancytree-edit-dirty").off();
  10170. // Unbind outer-click handler
  10171. $(document).off(".fancytree-edit");
  10172. if (eventData.save) {
  10173. // # 171: escape user input (not required if global escaping is on)
  10174. node.setTitle(
  10175. tree.options.escapeTitles ? newVal : escapeHtml(newVal)
  10176. );
  10177. node.setFocus();
  10178. } else {
  10179. if (eventData.isNew) {
  10180. node.remove();
  10181. node = eventData.node = null;
  10182. local.relatedNode.setFocus();
  10183. } else {
  10184. node.renderTitle();
  10185. node.setFocus();
  10186. }
  10187. }
  10188. local.eventData = null;
  10189. local.currentNode = null;
  10190. local.relatedNode = null;
  10191. // Re-enable mouse and keyboard handling
  10192. tree.widget._bind();
  10193. if (node && local.lastDraggableAttrValue) {
  10194. node.span.draggable = true;
  10195. }
  10196. // Set keyboard focus, even if setFocus() claims 'nothing to do'
  10197. tree.$container.get(0).focus({ preventScroll: true });
  10198. eventData.input = null;
  10199. instOpts.close.call(node, { type: "close" }, eventData);
  10200. return true;
  10201. };
  10202. /**
  10203. * [ext-edit] Create a new child or sibling node and start edit mode.
  10204. *
  10205. * @param {String} [mode='child'] 'before', 'after', or 'child'
  10206. * @param {Object} [init] NodeData (or simple title string)
  10207. * @alias FancytreeNode#editCreateNode
  10208. * @requires jquery.fancytree.edit.js
  10209. * @since 2.4
  10210. */
  10211. $.ui.fancytree._FancytreeNodeClass.prototype.editCreateNode = function(
  10212. mode,
  10213. init
  10214. ) {
  10215. var newNode,
  10216. tree = this.tree,
  10217. self = this;
  10218. mode = mode || "child";
  10219. if (init == null) {
  10220. init = { title: "" };
  10221. } else if (typeof init === "string") {
  10222. init = { title: init };
  10223. } else {
  10224. $.ui.fancytree.assert($.isPlainObject(init));
  10225. }
  10226. // Make sure node is expanded (and loaded) in 'child' mode
  10227. if (
  10228. mode === "child" &&
  10229. !this.isExpanded() &&
  10230. this.hasChildren() !== false
  10231. ) {
  10232. this.setExpanded().done(function() {
  10233. self.editCreateNode(mode, init);
  10234. });
  10235. return;
  10236. }
  10237. newNode = this.addNode(init, mode);
  10238. // #644: Don't filter new nodes.
  10239. newNode.match = true;
  10240. $(newNode[tree.statusClassPropName])
  10241. .removeClass("fancytree-hide")
  10242. .addClass("fancytree-match");
  10243. newNode.makeVisible(/*{noAnimation: true}*/).done(function() {
  10244. $(newNode[tree.statusClassPropName]).addClass("fancytree-edit-new");
  10245. self.tree.ext.edit.relatedNode = self;
  10246. newNode.editStart();
  10247. });
  10248. };
  10249. /**
  10250. * [ext-edit] Check if any node in this tree in edit mode.
  10251. *
  10252. * @returns {FancytreeNode | null}
  10253. * @alias Fancytree#isEditing
  10254. * @requires jquery.fancytree.edit.js
  10255. */
  10256. $.ui.fancytree._FancytreeClass.prototype.isEditing = function() {
  10257. return this.ext.edit ? this.ext.edit.currentNode : null;
  10258. };
  10259. /**
  10260. * [ext-edit] Check if this node is in edit mode.
  10261. * @returns {Boolean} true if node is currently beeing edited
  10262. * @alias FancytreeNode#isEditing
  10263. * @requires jquery.fancytree.edit.js
  10264. */
  10265. $.ui.fancytree._FancytreeNodeClass.prototype.isEditing = function() {
  10266. return this.tree.ext.edit
  10267. ? this.tree.ext.edit.currentNode === this
  10268. : false;
  10269. };
  10270. /*******************************************************************************
  10271. * Extension code
  10272. */
  10273. $.ui.fancytree.registerExtension({
  10274. name: "edit",
  10275. version: "2.37.0",
  10276. // Default options for this extension.
  10277. options: {
  10278. adjustWidthOfs: 4, // null: don't adjust input size to content
  10279. allowEmpty: false, // Prevent empty input
  10280. inputCss: { minWidth: "3em" },
  10281. // triggerCancel: ["esc", "tab", "click"],
  10282. triggerStart: ["f2", "mac+enter", "shift+click"],
  10283. trim: true, // Trim whitespace before save
  10284. // Events:
  10285. beforeClose: $.noop, // Return false to prevent cancel/save (data.input is available)
  10286. beforeEdit: $.noop, // Return false to prevent edit mode
  10287. close: $.noop, // Editor was removed
  10288. edit: $.noop, // Editor was opened (available as data.input)
  10289. // keypress: $.noop, // Not yet implemented
  10290. save: $.noop, // Save data.input.val() or return false to keep editor open
  10291. },
  10292. // Local attributes
  10293. currentNode: null,
  10294. treeInit: function(ctx) {
  10295. var tree = ctx.tree;
  10296. this._superApply(arguments);
  10297. this.$container
  10298. .addClass("fancytree-ext-edit")
  10299. .on("fancytreebeforeupdateviewport", function(event, data) {
  10300. var editNode = tree.isEditing();
  10301. // When scrolling, the TR may be re-used by another node, so the
  10302. // active cell marker an
  10303. if (editNode) {
  10304. editNode.info("Cancel edit due to scroll event.");
  10305. editNode.editEnd(false, event);
  10306. }
  10307. });
  10308. },
  10309. nodeClick: function(ctx) {
  10310. var eventStr = $.ui.fancytree.eventToString(ctx.originalEvent),
  10311. triggerStart = ctx.options.edit.triggerStart;
  10312. if (
  10313. eventStr === "shift+click" &&
  10314. $.inArray("shift+click", triggerStart) >= 0
  10315. ) {
  10316. if (ctx.originalEvent.shiftKey) {
  10317. ctx.node.editStart();
  10318. return false;
  10319. }
  10320. }
  10321. if (
  10322. eventStr === "click" &&
  10323. $.inArray("clickActive", triggerStart) >= 0
  10324. ) {
  10325. // Only when click was inside title text (not aynwhere else in the row)
  10326. if (
  10327. ctx.node.isActive() &&
  10328. !ctx.node.isEditing() &&
  10329. $(ctx.originalEvent.target).hasClass("fancytree-title")
  10330. ) {
  10331. ctx.node.editStart();
  10332. return false;
  10333. }
  10334. }
  10335. return this._superApply(arguments);
  10336. },
  10337. nodeDblclick: function(ctx) {
  10338. if ($.inArray("dblclick", ctx.options.edit.triggerStart) >= 0) {
  10339. ctx.node.editStart();
  10340. return false;
  10341. }
  10342. return this._superApply(arguments);
  10343. },
  10344. nodeKeydown: function(ctx) {
  10345. switch (ctx.originalEvent.which) {
  10346. case 113: // [F2]
  10347. if ($.inArray("f2", ctx.options.edit.triggerStart) >= 0) {
  10348. ctx.node.editStart();
  10349. return false;
  10350. }
  10351. break;
  10352. case $.ui.keyCode.ENTER:
  10353. if (
  10354. $.inArray("mac+enter", ctx.options.edit.triggerStart) >=
  10355. 0 &&
  10356. isMac
  10357. ) {
  10358. ctx.node.editStart();
  10359. return false;
  10360. }
  10361. break;
  10362. }
  10363. return this._superApply(arguments);
  10364. },
  10365. });
  10366. // Value returned by `require('jquery.fancytree..')`
  10367. return $.ui.fancytree;
  10368. }); // End of closure
  10369. /*! Extension 'jquery.fancytree.filter.js' *//*!
  10370. * jquery.fancytree.filter.js
  10371. *
  10372. * Remove or highlight tree nodes, based on a filter.
  10373. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10374. *
  10375. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  10376. *
  10377. * Released under the MIT license
  10378. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10379. *
  10380. * @version 2.37.0
  10381. * @date 2020-09-11T18:58:08Z
  10382. */
  10383. (function(factory) {
  10384. if (typeof define === "function" && define.amd) {
  10385. // AMD. Register as an anonymous module.
  10386. define(["jquery", "./jquery.fancytree"], factory);
  10387. } else if (typeof module === "object" && module.exports) {
  10388. // Node/CommonJS
  10389. require("./jquery.fancytree");
  10390. module.exports = factory(require("jquery"));
  10391. } else {
  10392. // Browser globals
  10393. factory(jQuery);
  10394. }
  10395. })(function($) {
  10396. "use strict";
  10397. /*******************************************************************************
  10398. * Private functions and variables
  10399. */
  10400. var KeyNoData = "__not_found__",
  10401. escapeHtml = $.ui.fancytree.escapeHtml;
  10402. function _escapeRegex(str) {
  10403. return (str + "").replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
  10404. }
  10405. function extractHtmlText(s) {
  10406. if (s.indexOf(">") >= 0) {
  10407. return $("<div/>")
  10408. .html(s)
  10409. .text();
  10410. }
  10411. return s;
  10412. }
  10413. $.ui.fancytree._FancytreeClass.prototype._applyFilterImpl = function(
  10414. filter,
  10415. branchMode,
  10416. _opts
  10417. ) {
  10418. var match,
  10419. statusNode,
  10420. re,
  10421. reHighlight,
  10422. temp,
  10423. prevEnableUpdate,
  10424. count = 0,
  10425. treeOpts = this.options,
  10426. escapeTitles = treeOpts.escapeTitles,
  10427. prevAutoCollapse = treeOpts.autoCollapse,
  10428. opts = $.extend({}, treeOpts.filter, _opts),
  10429. hideMode = opts.mode === "hide",
  10430. leavesOnly = !!opts.leavesOnly && !branchMode;
  10431. // Default to 'match title substring (not case sensitive)'
  10432. if (typeof filter === "string") {
  10433. if (filter === "") {
  10434. this.warn(
  10435. "Fancytree passing an empty string as a filter is handled as clearFilter()."
  10436. );
  10437. this.clearFilter();
  10438. return;
  10439. }
  10440. if (opts.fuzzy) {
  10441. // See https://codereview.stackexchange.com/questions/23899/faster-javascript-fuzzy-string-matching-function/23905#23905
  10442. // and http://www.quora.com/How-is-the-fuzzy-search-algorithm-in-Sublime-Text-designed
  10443. // and http://www.dustindiaz.com/autocomplete-fuzzy-matching
  10444. match = filter.split("").reduce(function(a, b) {
  10445. return a + "[^" + b + "]*" + b;
  10446. });
  10447. } else {
  10448. match = _escapeRegex(filter); // make sure a '.' is treated literally
  10449. }
  10450. re = new RegExp(".*" + match + ".*", "i");
  10451. reHighlight = new RegExp(_escapeRegex(filter), "gi");
  10452. filter = function(node) {
  10453. if (!node.title) {
  10454. return false;
  10455. }
  10456. var text = escapeTitles
  10457. ? node.title
  10458. : extractHtmlText(node.title),
  10459. res = !!re.test(text);
  10460. if (res && opts.highlight) {
  10461. if (escapeTitles) {
  10462. // #740: we must not apply the marks to escaped entity names, e.g. `&quot;`
  10463. // Use some exotic characters to mark matches:
  10464. temp = text.replace(reHighlight, function(s) {
  10465. return "\uFFF7" + s + "\uFFF8";
  10466. });
  10467. // now we can escape the title...
  10468. node.titleWithHighlight = escapeHtml(temp)
  10469. // ... and finally insert the desired `<mark>` tags
  10470. .replace(/\uFFF7/g, "<mark>")
  10471. .replace(/\uFFF8/g, "</mark>");
  10472. } else {
  10473. node.titleWithHighlight = text.replace(
  10474. reHighlight,
  10475. function(s) {
  10476. return "<mark>" + s + "</mark>";
  10477. }
  10478. );
  10479. }
  10480. // node.debug("filter", escapeTitles, text, node.titleWithHighlight);
  10481. }
  10482. return res;
  10483. };
  10484. }
  10485. this.enableFilter = true;
  10486. this.lastFilterArgs = arguments;
  10487. prevEnableUpdate = this.enableUpdate(false);
  10488. this.$div.addClass("fancytree-ext-filter");
  10489. if (hideMode) {
  10490. this.$div.addClass("fancytree-ext-filter-hide");
  10491. } else {
  10492. this.$div.addClass("fancytree-ext-filter-dimm");
  10493. }
  10494. this.$div.toggleClass(
  10495. "fancytree-ext-filter-hide-expanders",
  10496. !!opts.hideExpanders
  10497. );
  10498. // Reset current filter
  10499. this.rootNode.subMatchCount = 0;
  10500. this.visit(function(node) {
  10501. delete node.match;
  10502. delete node.titleWithHighlight;
  10503. node.subMatchCount = 0;
  10504. });
  10505. statusNode = this.getRootNode()._findDirectChild(KeyNoData);
  10506. if (statusNode) {
  10507. statusNode.remove();
  10508. }
  10509. // Adjust node.hide, .match, and .subMatchCount properties
  10510. treeOpts.autoCollapse = false; // #528
  10511. this.visit(function(node) {
  10512. if (leavesOnly && node.children != null) {
  10513. return;
  10514. }
  10515. var res = filter(node),
  10516. matchedByBranch = false;
  10517. if (res === "skip") {
  10518. node.visit(function(c) {
  10519. c.match = false;
  10520. }, true);
  10521. return "skip";
  10522. }
  10523. if (!res && (branchMode || res === "branch") && node.parent.match) {
  10524. res = true;
  10525. matchedByBranch = true;
  10526. }
  10527. if (res) {
  10528. count++;
  10529. node.match = true;
  10530. node.visitParents(function(p) {
  10531. if (p !== node) {
  10532. p.subMatchCount += 1;
  10533. }
  10534. // Expand match (unless this is no real match, but only a node in a matched branch)
  10535. if (opts.autoExpand && !matchedByBranch && !p.expanded) {
  10536. p.setExpanded(true, {
  10537. noAnimation: true,
  10538. noEvents: true,
  10539. scrollIntoView: false,
  10540. });
  10541. p._filterAutoExpanded = true;
  10542. }
  10543. }, true);
  10544. }
  10545. });
  10546. treeOpts.autoCollapse = prevAutoCollapse;
  10547. if (count === 0 && opts.nodata && hideMode) {
  10548. statusNode = opts.nodata;
  10549. if ($.isFunction(statusNode)) {
  10550. statusNode = statusNode();
  10551. }
  10552. if (statusNode === true) {
  10553. statusNode = {};
  10554. } else if (typeof statusNode === "string") {
  10555. statusNode = { title: statusNode };
  10556. }
  10557. statusNode = $.extend(
  10558. {
  10559. statusNodeType: "nodata",
  10560. key: KeyNoData,
  10561. title: this.options.strings.noData,
  10562. },
  10563. statusNode
  10564. );
  10565. this.getRootNode().addNode(statusNode).match = true;
  10566. }
  10567. // Redraw whole tree
  10568. this._callHook("treeStructureChanged", this, "applyFilter");
  10569. // this.render();
  10570. this.enableUpdate(prevEnableUpdate);
  10571. return count;
  10572. };
  10573. /**
  10574. * [ext-filter] Dimm or hide nodes.
  10575. *
  10576. * @param {function | string} filter
  10577. * @param {boolean} [opts={autoExpand: false, leavesOnly: false}]
  10578. * @returns {integer} count
  10579. * @alias Fancytree#filterNodes
  10580. * @requires jquery.fancytree.filter.js
  10581. */
  10582. $.ui.fancytree._FancytreeClass.prototype.filterNodes = function(
  10583. filter,
  10584. opts
  10585. ) {
  10586. if (typeof opts === "boolean") {
  10587. opts = { leavesOnly: opts };
  10588. this.warn(
  10589. "Fancytree.filterNodes() leavesOnly option is deprecated since 2.9.0 / 2015-04-19. Use opts.leavesOnly instead."
  10590. );
  10591. }
  10592. return this._applyFilterImpl(filter, false, opts);
  10593. };
  10594. /**
  10595. * [ext-filter] Dimm or hide whole branches.
  10596. *
  10597. * @param {function | string} filter
  10598. * @param {boolean} [opts={autoExpand: false}]
  10599. * @returns {integer} count
  10600. * @alias Fancytree#filterBranches
  10601. * @requires jquery.fancytree.filter.js
  10602. */
  10603. $.ui.fancytree._FancytreeClass.prototype.filterBranches = function(
  10604. filter,
  10605. opts
  10606. ) {
  10607. return this._applyFilterImpl(filter, true, opts);
  10608. };
  10609. /**
  10610. * [ext-filter] Reset the filter.
  10611. *
  10612. * @alias Fancytree#clearFilter
  10613. * @requires jquery.fancytree.filter.js
  10614. */
  10615. $.ui.fancytree._FancytreeClass.prototype.clearFilter = function() {
  10616. var $title,
  10617. statusNode = this.getRootNode()._findDirectChild(KeyNoData),
  10618. escapeTitles = this.options.escapeTitles,
  10619. enhanceTitle = this.options.enhanceTitle,
  10620. prevEnableUpdate = this.enableUpdate(false);
  10621. if (statusNode) {
  10622. statusNode.remove();
  10623. }
  10624. // we also counted root node's subMatchCount
  10625. delete this.rootNode.match;
  10626. delete this.rootNode.subMatchCount;
  10627. this.visit(function(node) {
  10628. if (node.match && node.span) {
  10629. // #491, #601
  10630. $title = $(node.span).find(">span.fancytree-title");
  10631. if (escapeTitles) {
  10632. $title.text(node.title);
  10633. } else {
  10634. $title.html(node.title);
  10635. }
  10636. if (enhanceTitle) {
  10637. enhanceTitle(
  10638. { type: "enhanceTitle" },
  10639. { node: node, $title: $title }
  10640. );
  10641. }
  10642. }
  10643. delete node.match;
  10644. delete node.subMatchCount;
  10645. delete node.titleWithHighlight;
  10646. if (node.$subMatchBadge) {
  10647. node.$subMatchBadge.remove();
  10648. delete node.$subMatchBadge;
  10649. }
  10650. if (node._filterAutoExpanded && node.expanded) {
  10651. node.setExpanded(false, {
  10652. noAnimation: true,
  10653. noEvents: true,
  10654. scrollIntoView: false,
  10655. });
  10656. }
  10657. delete node._filterAutoExpanded;
  10658. });
  10659. this.enableFilter = false;
  10660. this.lastFilterArgs = null;
  10661. this.$div.removeClass(
  10662. "fancytree-ext-filter fancytree-ext-filter-dimm fancytree-ext-filter-hide"
  10663. );
  10664. this._callHook("treeStructureChanged", this, "clearFilter");
  10665. // this.render();
  10666. this.enableUpdate(prevEnableUpdate);
  10667. };
  10668. /**
  10669. * [ext-filter] Return true if a filter is currently applied.
  10670. *
  10671. * @returns {Boolean}
  10672. * @alias Fancytree#isFilterActive
  10673. * @requires jquery.fancytree.filter.js
  10674. * @since 2.13
  10675. */
  10676. $.ui.fancytree._FancytreeClass.prototype.isFilterActive = function() {
  10677. return !!this.enableFilter;
  10678. };
  10679. /**
  10680. * [ext-filter] Return true if this node is matched by current filter (or no filter is active).
  10681. *
  10682. * @returns {Boolean}
  10683. * @alias FancytreeNode#isMatched
  10684. * @requires jquery.fancytree.filter.js
  10685. * @since 2.13
  10686. */
  10687. $.ui.fancytree._FancytreeNodeClass.prototype.isMatched = function() {
  10688. return !(this.tree.enableFilter && !this.match);
  10689. };
  10690. /*******************************************************************************
  10691. * Extension code
  10692. */
  10693. $.ui.fancytree.registerExtension({
  10694. name: "filter",
  10695. version: "2.37.0",
  10696. // Default options for this extension.
  10697. options: {
  10698. autoApply: true, // Re-apply last filter if lazy data is loaded
  10699. autoExpand: false, // Expand all branches that contain matches while filtered
  10700. counter: true, // Show a badge with number of matching child nodes near parent icons
  10701. fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar'
  10702. hideExpandedCounter: true, // Hide counter badge if parent is expanded
  10703. hideExpanders: false, // Hide expanders if all child nodes are hidden by filter
  10704. highlight: true, // Highlight matches by wrapping inside <mark> tags
  10705. leavesOnly: false, // Match end nodes only
  10706. nodata: true, // Display a 'no data' status node if result is empty
  10707. mode: "dimm", // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
  10708. },
  10709. nodeLoadChildren: function(ctx, source) {
  10710. var tree = ctx.tree;
  10711. return this._superApply(arguments).done(function() {
  10712. if (
  10713. tree.enableFilter &&
  10714. tree.lastFilterArgs &&
  10715. ctx.options.filter.autoApply
  10716. ) {
  10717. tree._applyFilterImpl.apply(tree, tree.lastFilterArgs);
  10718. }
  10719. });
  10720. },
  10721. nodeSetExpanded: function(ctx, flag, callOpts) {
  10722. var node = ctx.node;
  10723. delete node._filterAutoExpanded;
  10724. // Make sure counter badge is displayed again, when node is beeing collapsed
  10725. if (
  10726. !flag &&
  10727. ctx.options.filter.hideExpandedCounter &&
  10728. node.$subMatchBadge
  10729. ) {
  10730. node.$subMatchBadge.show();
  10731. }
  10732. return this._superApply(arguments);
  10733. },
  10734. nodeRenderStatus: function(ctx) {
  10735. // Set classes for current status
  10736. var res,
  10737. node = ctx.node,
  10738. tree = ctx.tree,
  10739. opts = ctx.options.filter,
  10740. $title = $(node.span).find("span.fancytree-title"),
  10741. $span = $(node[tree.statusClassPropName]),
  10742. enhanceTitle = ctx.options.enhanceTitle,
  10743. escapeTitles = ctx.options.escapeTitles;
  10744. res = this._super(ctx);
  10745. // nothing to do, if node was not yet rendered
  10746. if (!$span.length || !tree.enableFilter) {
  10747. return res;
  10748. }
  10749. $span
  10750. .toggleClass("fancytree-match", !!node.match)
  10751. .toggleClass("fancytree-submatch", !!node.subMatchCount)
  10752. .toggleClass(
  10753. "fancytree-hide",
  10754. !(node.match || node.subMatchCount)
  10755. );
  10756. // Add/update counter badge
  10757. if (
  10758. opts.counter &&
  10759. node.subMatchCount &&
  10760. (!node.isExpanded() || !opts.hideExpandedCounter)
  10761. ) {
  10762. if (!node.$subMatchBadge) {
  10763. node.$subMatchBadge = $(
  10764. "<span class='fancytree-childcounter'/>"
  10765. );
  10766. $(
  10767. "span.fancytree-icon, span.fancytree-custom-icon",
  10768. node.span
  10769. ).append(node.$subMatchBadge);
  10770. }
  10771. node.$subMatchBadge.show().text(node.subMatchCount);
  10772. } else if (node.$subMatchBadge) {
  10773. node.$subMatchBadge.hide();
  10774. }
  10775. // node.debug("nodeRenderStatus", node.titleWithHighlight, node.title)
  10776. // #601: also check for $title.length, because we don't need to render
  10777. // if node.span is null (i.e. not rendered)
  10778. if (node.span && (!node.isEditing || !node.isEditing.call(node))) {
  10779. if (node.titleWithHighlight) {
  10780. $title.html(node.titleWithHighlight);
  10781. } else if (escapeTitles) {
  10782. $title.text(node.title);
  10783. } else {
  10784. $title.html(node.title);
  10785. }
  10786. if (enhanceTitle) {
  10787. enhanceTitle(
  10788. { type: "enhanceTitle" },
  10789. { node: node, $title: $title }
  10790. );
  10791. }
  10792. }
  10793. return res;
  10794. },
  10795. });
  10796. // Value returned by `require('jquery.fancytree..')`
  10797. return $.ui.fancytree;
  10798. }); // End of closure
  10799. /*! Extension 'jquery.fancytree.glyph.js' *//*!
  10800. * jquery.fancytree.glyph.js
  10801. *
  10802. * Use glyph-fonts, ligature-fonts, or SVG icons instead of icon sprites.
  10803. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  10804. *
  10805. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  10806. *
  10807. * Released under the MIT license
  10808. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  10809. *
  10810. * @version 2.37.0
  10811. * @date 2020-09-11T18:58:08Z
  10812. */
  10813. (function(factory) {
  10814. if (typeof define === "function" && define.amd) {
  10815. // AMD. Register as an anonymous module.
  10816. define(["jquery", "./jquery.fancytree"], factory);
  10817. } else if (typeof module === "object" && module.exports) {
  10818. // Node/CommonJS
  10819. require("./jquery.fancytree");
  10820. module.exports = factory(require("jquery"));
  10821. } else {
  10822. // Browser globals
  10823. factory(jQuery);
  10824. }
  10825. })(function($) {
  10826. "use strict";
  10827. /******************************************************************************
  10828. * Private functions and variables
  10829. */
  10830. var FT = $.ui.fancytree,
  10831. PRESETS = {
  10832. awesome3: {
  10833. // Outdated!
  10834. _addClass: "",
  10835. checkbox: "icon-check-empty",
  10836. checkboxSelected: "icon-check",
  10837. checkboxUnknown: "icon-check icon-muted",
  10838. dragHelper: "icon-caret-right",
  10839. dropMarker: "icon-caret-right",
  10840. error: "icon-exclamation-sign",
  10841. expanderClosed: "icon-caret-right",
  10842. expanderLazy: "icon-angle-right",
  10843. expanderOpen: "icon-caret-down",
  10844. loading: "icon-refresh icon-spin",
  10845. nodata: "icon-meh",
  10846. noExpander: "",
  10847. radio: "icon-circle-blank",
  10848. radioSelected: "icon-circle",
  10849. // radioUnknown: "icon-circle icon-muted",
  10850. // Default node icons.
  10851. // (Use tree.options.icon callback to define custom icons based on node data)
  10852. doc: "icon-file-alt",
  10853. docOpen: "icon-file-alt",
  10854. folder: "icon-folder-close-alt",
  10855. folderOpen: "icon-folder-open-alt",
  10856. },
  10857. awesome4: {
  10858. _addClass: "fa",
  10859. checkbox: "fa-square-o",
  10860. checkboxSelected: "fa-check-square-o",
  10861. checkboxUnknown: "fa-square fancytree-helper-indeterminate-cb",
  10862. dragHelper: "fa-arrow-right",
  10863. dropMarker: "fa-long-arrow-right",
  10864. error: "fa-warning",
  10865. expanderClosed: "fa-caret-right",
  10866. expanderLazy: "fa-angle-right",
  10867. expanderOpen: "fa-caret-down",
  10868. // We may prevent wobbling rotations on FF by creating a separate sub element:
  10869. loading: { html: "<span class='fa fa-spinner fa-pulse' />" },
  10870. nodata: "fa-meh-o",
  10871. noExpander: "",
  10872. radio: "fa-circle-thin", // "fa-circle-o"
  10873. radioSelected: "fa-circle",
  10874. // radioUnknown: "fa-dot-circle-o",
  10875. // Default node icons.
  10876. // (Use tree.options.icon callback to define custom icons based on node data)
  10877. doc: "fa-file-o",
  10878. docOpen: "fa-file-o",
  10879. folder: "fa-folder-o",
  10880. folderOpen: "fa-folder-open-o",
  10881. },
  10882. awesome5: {
  10883. // fontawesome 5 have several different base classes
  10884. // "far, fas, fal and fab" The rendered svg puts that prefix
  10885. // in a different location so we have to keep them separate here
  10886. _addClass: "",
  10887. checkbox: "far fa-square",
  10888. checkboxSelected: "far fa-check-square",
  10889. // checkboxUnknown: "far fa-window-close",
  10890. checkboxUnknown:
  10891. "fas fa-square fancytree-helper-indeterminate-cb",
  10892. radio: "far fa-circle",
  10893. radioSelected: "fas fa-circle",
  10894. radioUnknown: "far fa-dot-circle",
  10895. dragHelper: "fas fa-arrow-right",
  10896. dropMarker: "fas fa-long-arrow-alt-right",
  10897. error: "fas fa-exclamation-triangle",
  10898. expanderClosed: "fas fa-caret-right",
  10899. expanderLazy: "fas fa-angle-right",
  10900. expanderOpen: "fas fa-caret-down",
  10901. loading: "fas fa-spinner fa-pulse",
  10902. nodata: "far fa-meh",
  10903. noExpander: "",
  10904. // Default node icons.
  10905. // (Use tree.options.icon callback to define custom icons based on node data)
  10906. doc: "far fa-file",
  10907. docOpen: "far fa-file",
  10908. folder: "far fa-folder",
  10909. folderOpen: "far fa-folder-open",
  10910. },
  10911. bootstrap3: {
  10912. _addClass: "glyphicon",
  10913. checkbox: "glyphicon-unchecked",
  10914. checkboxSelected: "glyphicon-check",
  10915. checkboxUnknown:
  10916. "glyphicon-expand fancytree-helper-indeterminate-cb", // "glyphicon-share",
  10917. dragHelper: "glyphicon-play",
  10918. dropMarker: "glyphicon-arrow-right",
  10919. error: "glyphicon-warning-sign",
  10920. expanderClosed: "glyphicon-menu-right", // glyphicon-plus-sign
  10921. expanderLazy: "glyphicon-menu-right", // glyphicon-plus-sign
  10922. expanderOpen: "glyphicon-menu-down", // glyphicon-minus-sign
  10923. loading: "glyphicon-refresh fancytree-helper-spin",
  10924. nodata: "glyphicon-info-sign",
  10925. noExpander: "",
  10926. radio: "glyphicon-remove-circle", // "glyphicon-unchecked",
  10927. radioSelected: "glyphicon-ok-circle", // "glyphicon-check",
  10928. // radioUnknown: "glyphicon-ban-circle",
  10929. // Default node icons.
  10930. // (Use tree.options.icon callback to define custom icons based on node data)
  10931. doc: "glyphicon-file",
  10932. docOpen: "glyphicon-file",
  10933. folder: "glyphicon-folder-close",
  10934. folderOpen: "glyphicon-folder-open",
  10935. },
  10936. material: {
  10937. _addClass: "material-icons",
  10938. checkbox: { text: "check_box_outline_blank" },
  10939. checkboxSelected: { text: "check_box" },
  10940. checkboxUnknown: { text: "indeterminate_check_box" },
  10941. dragHelper: { text: "play_arrow" },
  10942. dropMarker: { text: "arrow-forward" },
  10943. error: { text: "warning" },
  10944. expanderClosed: { text: "chevron_right" },
  10945. expanderLazy: { text: "last_page" },
  10946. expanderOpen: { text: "expand_more" },
  10947. loading: {
  10948. text: "autorenew",
  10949. addClass: "fancytree-helper-spin",
  10950. },
  10951. nodata: { text: "info" },
  10952. noExpander: { text: "" },
  10953. radio: { text: "radio_button_unchecked" },
  10954. radioSelected: { text: "radio_button_checked" },
  10955. // Default node icons.
  10956. // (Use tree.options.icon callback to define custom icons based on node data)
  10957. doc: { text: "insert_drive_file" },
  10958. docOpen: { text: "insert_drive_file" },
  10959. folder: { text: "folder" },
  10960. folderOpen: { text: "folder_open" },
  10961. },
  10962. };
  10963. function setIcon(node, span, baseClass, opts, type) {
  10964. var map = opts.map,
  10965. icon = map[type],
  10966. $span = $(span),
  10967. $counter = $span.find(".fancytree-childcounter"),
  10968. setClass = baseClass + " " + (map._addClass || "");
  10969. // #871 Allow a callback
  10970. if ($.isFunction(icon)) {
  10971. icon = icon.call(this, node, span, type);
  10972. }
  10973. // node.debug( "setIcon(" + baseClass + ", " + type + "): " + "oldIcon" + " -> " + icon );
  10974. // #871: propsed this, but I am not sure how robust this is, e.g.
  10975. // the prefix (fas, far) class changes are not considered?
  10976. // if (span.tagName === "svg" && opts.preset === "awesome5") {
  10977. // // fa5 script converts <i> to <svg> so call a specific handler.
  10978. // var oldIcon = "fa-" + $span.data("icon");
  10979. // // node.debug( "setIcon(" + baseClass + ", " + type + "): " + oldIcon + " -> " + icon );
  10980. // if (typeof oldIcon === "string") {
  10981. // $span.removeClass(oldIcon);
  10982. // }
  10983. // if (typeof icon === "string") {
  10984. // $span.addClass(icon);
  10985. // }
  10986. // return;
  10987. // }
  10988. if (typeof icon === "string") {
  10989. // #883: remove inner html that may be added by prev. mode
  10990. span.innerHTML = "";
  10991. $span.attr("class", setClass + " " + icon).append($counter);
  10992. } else if (icon) {
  10993. if (icon.text) {
  10994. span.textContent = "" + icon.text;
  10995. } else if (icon.html) {
  10996. span.innerHTML = icon.html;
  10997. } else {
  10998. span.innerHTML = "";
  10999. }
  11000. $span
  11001. .attr("class", setClass + " " + (icon.addClass || ""))
  11002. .append($counter);
  11003. }
  11004. }
  11005. $.ui.fancytree.registerExtension({
  11006. name: "glyph",
  11007. version: "2.37.0",
  11008. // Default options for this extension.
  11009. options: {
  11010. preset: null, // 'awesome3', 'awesome4', 'bootstrap3', 'material'
  11011. map: {},
  11012. },
  11013. treeInit: function(ctx) {
  11014. var tree = ctx.tree,
  11015. opts = ctx.options.glyph;
  11016. if (opts.preset) {
  11017. FT.assert(
  11018. !!PRESETS[opts.preset],
  11019. "Invalid value for `options.glyph.preset`: " + opts.preset
  11020. );
  11021. opts.map = $.extend({}, PRESETS[opts.preset], opts.map);
  11022. } else {
  11023. tree.warn("ext-glyph: missing `preset` option.");
  11024. }
  11025. this._superApply(arguments);
  11026. tree.$container.addClass("fancytree-ext-glyph");
  11027. },
  11028. nodeRenderStatus: function(ctx) {
  11029. var checkbox,
  11030. icon,
  11031. res,
  11032. span,
  11033. node = ctx.node,
  11034. $span = $(node.span),
  11035. opts = ctx.options.glyph;
  11036. res = this._super(ctx);
  11037. if (node.isRootNode()) {
  11038. return res;
  11039. }
  11040. span = $span.children(".fancytree-expander").get(0);
  11041. if (span) {
  11042. // if( node.isLoading() ){
  11043. // icon = "loading";
  11044. if (node.expanded && node.hasChildren()) {
  11045. icon = "expanderOpen";
  11046. } else if (node.isUndefined()) {
  11047. icon = "expanderLazy";
  11048. } else if (node.hasChildren()) {
  11049. icon = "expanderClosed";
  11050. } else {
  11051. icon = "noExpander";
  11052. }
  11053. // span.className = "fancytree-expander " + map[icon];
  11054. setIcon(node, span, "fancytree-expander", opts, icon);
  11055. }
  11056. if (node.tr) {
  11057. span = $("td", node.tr)
  11058. .find(".fancytree-checkbox")
  11059. .get(0);
  11060. } else {
  11061. span = $span.children(".fancytree-checkbox").get(0);
  11062. }
  11063. if (span) {
  11064. checkbox = FT.evalOption("checkbox", node, node, opts, false);
  11065. if (
  11066. (node.parent && node.parent.radiogroup) ||
  11067. checkbox === "radio"
  11068. ) {
  11069. icon = node.selected ? "radioSelected" : "radio";
  11070. setIcon(
  11071. node,
  11072. span,
  11073. "fancytree-checkbox fancytree-radio",
  11074. opts,
  11075. icon
  11076. );
  11077. } else {
  11078. // eslint-disable-next-line no-nested-ternary
  11079. icon = node.selected
  11080. ? "checkboxSelected"
  11081. : node.partsel
  11082. ? "checkboxUnknown"
  11083. : "checkbox";
  11084. // span.className = "fancytree-checkbox " + map[icon];
  11085. setIcon(node, span, "fancytree-checkbox", opts, icon);
  11086. }
  11087. }
  11088. // Standard icon (note that this does not match .fancytree-custom-icon,
  11089. // that might be set by opts.icon callbacks)
  11090. span = $span.children(".fancytree-icon").get(0);
  11091. if (span) {
  11092. if (node.statusNodeType) {
  11093. icon = node.statusNodeType; // loading, error
  11094. } else if (node.folder) {
  11095. icon =
  11096. node.expanded && node.hasChildren()
  11097. ? "folderOpen"
  11098. : "folder";
  11099. } else {
  11100. icon = node.expanded ? "docOpen" : "doc";
  11101. }
  11102. setIcon(node, span, "fancytree-icon", opts, icon);
  11103. }
  11104. return res;
  11105. },
  11106. nodeSetStatus: function(ctx, status, message, details) {
  11107. var res,
  11108. span,
  11109. opts = ctx.options.glyph,
  11110. node = ctx.node;
  11111. res = this._superApply(arguments);
  11112. if (
  11113. status === "error" ||
  11114. status === "loading" ||
  11115. status === "nodata"
  11116. ) {
  11117. if (node.parent) {
  11118. span = $(".fancytree-expander", node.span).get(0);
  11119. if (span) {
  11120. setIcon(node, span, "fancytree-expander", opts, status);
  11121. }
  11122. } else {
  11123. //
  11124. span = $(
  11125. ".fancytree-statusnode-" + status,
  11126. node[this.nodeContainerAttrName]
  11127. )
  11128. .find(".fancytree-icon")
  11129. .get(0);
  11130. if (span) {
  11131. setIcon(node, span, "fancytree-icon", opts, status);
  11132. }
  11133. }
  11134. }
  11135. return res;
  11136. },
  11137. });
  11138. // Value returned by `require('jquery.fancytree..')`
  11139. return $.ui.fancytree;
  11140. }); // End of closure
  11141. /*! Extension 'jquery.fancytree.gridnav.js' *//*!
  11142. * jquery.fancytree.gridnav.js
  11143. *
  11144. * Support keyboard navigation for trees with embedded input controls.
  11145. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11146. *
  11147. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  11148. *
  11149. * Released under the MIT license
  11150. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11151. *
  11152. * @version 2.37.0
  11153. * @date 2020-09-11T18:58:08Z
  11154. */
  11155. (function(factory) {
  11156. if (typeof define === "function" && define.amd) {
  11157. // AMD. Register as an anonymous module.
  11158. define([
  11159. "jquery",
  11160. "./jquery.fancytree",
  11161. "./jquery.fancytree.table",
  11162. ], factory);
  11163. } else if (typeof module === "object" && module.exports) {
  11164. // Node/CommonJS
  11165. require("./jquery.fancytree.table"); // core + table
  11166. module.exports = factory(require("jquery"));
  11167. } else {
  11168. // Browser globals
  11169. factory(jQuery);
  11170. }
  11171. })(function($) {
  11172. "use strict";
  11173. /*******************************************************************************
  11174. * Private functions and variables
  11175. */
  11176. // Allow these navigation keys even when input controls are focused
  11177. var KC = $.ui.keyCode,
  11178. // which keys are *not* handled by embedded control, but passed to tree
  11179. // navigation handler:
  11180. NAV_KEYS = {
  11181. text: [KC.UP, KC.DOWN],
  11182. checkbox: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11183. link: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11184. radiobutton: [KC.UP, KC.DOWN, KC.LEFT, KC.RIGHT],
  11185. "select-one": [KC.LEFT, KC.RIGHT],
  11186. "select-multiple": [KC.LEFT, KC.RIGHT],
  11187. };
  11188. /* Calculate TD column index (considering colspans).*/
  11189. function getColIdx($tr, $td) {
  11190. var colspan,
  11191. td = $td.get(0),
  11192. idx = 0;
  11193. $tr.children().each(function() {
  11194. if (this === td) {
  11195. return false;
  11196. }
  11197. colspan = $(this).prop("colspan");
  11198. idx += colspan ? colspan : 1;
  11199. });
  11200. return idx;
  11201. }
  11202. /* Find TD at given column index (considering colspans).*/
  11203. function findTdAtColIdx($tr, colIdx) {
  11204. var colspan,
  11205. res = null,
  11206. idx = 0;
  11207. $tr.children().each(function() {
  11208. if (idx >= colIdx) {
  11209. res = $(this);
  11210. return false;
  11211. }
  11212. colspan = $(this).prop("colspan");
  11213. idx += colspan ? colspan : 1;
  11214. });
  11215. return res;
  11216. }
  11217. /* Find adjacent cell for a given direction. Skip empty cells and consider merged cells */
  11218. function findNeighbourTd($target, keyCode) {
  11219. var $tr,
  11220. colIdx,
  11221. $td = $target.closest("td"),
  11222. $tdNext = null;
  11223. switch (keyCode) {
  11224. case KC.LEFT:
  11225. $tdNext = $td.prev();
  11226. break;
  11227. case KC.RIGHT:
  11228. $tdNext = $td.next();
  11229. break;
  11230. case KC.UP:
  11231. case KC.DOWN:
  11232. $tr = $td.parent();
  11233. colIdx = getColIdx($tr, $td);
  11234. while (true) {
  11235. $tr = keyCode === KC.UP ? $tr.prev() : $tr.next();
  11236. if (!$tr.length) {
  11237. break;
  11238. }
  11239. // Skip hidden rows
  11240. if ($tr.is(":hidden")) {
  11241. continue;
  11242. }
  11243. // Find adjacent cell in the same column
  11244. $tdNext = findTdAtColIdx($tr, colIdx);
  11245. // Skip cells that don't conatain a focusable element
  11246. if ($tdNext && $tdNext.find(":input,a").length) {
  11247. break;
  11248. }
  11249. }
  11250. break;
  11251. }
  11252. return $tdNext;
  11253. }
  11254. /*******************************************************************************
  11255. * Extension code
  11256. */
  11257. $.ui.fancytree.registerExtension({
  11258. name: "gridnav",
  11259. version: "2.37.0",
  11260. // Default options for this extension.
  11261. options: {
  11262. autofocusInput: false, // Focus first embedded input if node gets activated
  11263. handleCursorKeys: true, // Allow UP/DOWN in inputs to move to prev/next node
  11264. },
  11265. treeInit: function(ctx) {
  11266. // gridnav requires the table extension to be loaded before itself
  11267. this._requireExtension("table", true, true);
  11268. this._superApply(arguments);
  11269. this.$container.addClass("fancytree-ext-gridnav");
  11270. // Activate node if embedded input gets focus (due to a click)
  11271. this.$container.on("focusin", function(event) {
  11272. var ctx2,
  11273. node = $.ui.fancytree.getNode(event.target);
  11274. if (node && !node.isActive()) {
  11275. // Call node.setActive(), but also pass the event
  11276. ctx2 = ctx.tree._makeHookContext(node, event);
  11277. ctx.tree._callHook("nodeSetActive", ctx2, true);
  11278. }
  11279. });
  11280. },
  11281. nodeSetActive: function(ctx, flag, callOpts) {
  11282. var $outer,
  11283. opts = ctx.options.gridnav,
  11284. node = ctx.node,
  11285. event = ctx.originalEvent || {},
  11286. triggeredByInput = $(event.target).is(":input");
  11287. flag = flag !== false;
  11288. this._superApply(arguments);
  11289. if (flag) {
  11290. if (ctx.options.titlesTabbable) {
  11291. if (!triggeredByInput) {
  11292. $(node.span)
  11293. .find("span.fancytree-title")
  11294. .focus();
  11295. node.setFocus();
  11296. }
  11297. // If one node is tabbable, the container no longer needs to be
  11298. ctx.tree.$container.attr("tabindex", "-1");
  11299. // ctx.tree.$container.removeAttr("tabindex");
  11300. } else if (opts.autofocusInput && !triggeredByInput) {
  11301. // Set focus to input sub input (if node was clicked, but not
  11302. // when TAB was pressed )
  11303. $outer = $(node.tr || node.span);
  11304. $outer
  11305. .find(":input:enabled")
  11306. .first()
  11307. .focus();
  11308. }
  11309. }
  11310. },
  11311. nodeKeydown: function(ctx) {
  11312. var inputType,
  11313. handleKeys,
  11314. $td,
  11315. opts = ctx.options.gridnav,
  11316. event = ctx.originalEvent,
  11317. $target = $(event.target);
  11318. if ($target.is(":input:enabled")) {
  11319. inputType = $target.prop("type");
  11320. } else if ($target.is("a")) {
  11321. inputType = "link";
  11322. }
  11323. // ctx.tree.debug("ext-gridnav nodeKeydown", event, inputType);
  11324. if (inputType && opts.handleCursorKeys) {
  11325. handleKeys = NAV_KEYS[inputType];
  11326. if (handleKeys && $.inArray(event.which, handleKeys) >= 0) {
  11327. $td = findNeighbourTd($target, event.which);
  11328. if ($td && $td.length) {
  11329. // ctx.node.debug("ignore keydown in input", event.which, handleKeys);
  11330. $td.find(":input:enabled,a").focus();
  11331. // Prevent Fancytree default navigation
  11332. return false;
  11333. }
  11334. }
  11335. return true;
  11336. }
  11337. // ctx.tree.debug("ext-gridnav NOT HANDLED", event, inputType);
  11338. return this._superApply(arguments);
  11339. },
  11340. });
  11341. // Value returned by `require('jquery.fancytree..')`
  11342. return $.ui.fancytree;
  11343. }); // End of closure
  11344. /*! Extension 'jquery.fancytree.multi.js' *//*!
  11345. * jquery.fancytree.multi.js
  11346. *
  11347. * Allow multiple selection of nodes by mouse or keyboard.
  11348. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11349. *
  11350. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  11351. *
  11352. * Released under the MIT license
  11353. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11354. *
  11355. * @version 2.37.0
  11356. * @date 2020-09-11T18:58:08Z
  11357. */
  11358. (function(factory) {
  11359. if (typeof define === "function" && define.amd) {
  11360. // AMD. Register as an anonymous module.
  11361. define(["jquery", "./jquery.fancytree"], factory);
  11362. } else if (typeof module === "object" && module.exports) {
  11363. // Node/CommonJS
  11364. require("./jquery.fancytree");
  11365. module.exports = factory(require("jquery"));
  11366. } else {
  11367. // Browser globals
  11368. factory(jQuery);
  11369. }
  11370. })(function($) {
  11371. "use strict";
  11372. /*******************************************************************************
  11373. * Private functions and variables
  11374. */
  11375. // var isMac = /Mac/.test(navigator.platform);
  11376. /*******************************************************************************
  11377. * Extension code
  11378. */
  11379. $.ui.fancytree.registerExtension({
  11380. name: "multi",
  11381. version: "2.37.0",
  11382. // Default options for this extension.
  11383. options: {
  11384. allowNoSelect: false, //
  11385. mode: "sameParent", //
  11386. // Events:
  11387. // beforeSelect: $.noop // Return false to prevent cancel/save (data.input is available)
  11388. },
  11389. treeInit: function(ctx) {
  11390. this._superApply(arguments);
  11391. this.$container.addClass("fancytree-ext-multi");
  11392. if (ctx.options.selectMode === 1) {
  11393. $.error(
  11394. "Fancytree ext-multi: selectMode: 1 (single) is not compatible."
  11395. );
  11396. }
  11397. },
  11398. nodeClick: function(ctx) {
  11399. var //pluginOpts = ctx.options.multi,
  11400. tree = ctx.tree,
  11401. node = ctx.node,
  11402. activeNode = tree.getActiveNode() || tree.getFirstChild(),
  11403. isCbClick = ctx.targetType === "checkbox",
  11404. isExpanderClick = ctx.targetType === "expander",
  11405. eventStr = $.ui.fancytree.eventToString(ctx.originalEvent);
  11406. switch (eventStr) {
  11407. case "click":
  11408. if (isExpanderClick) {
  11409. break;
  11410. } // Default handler will expand/collapse
  11411. if (!isCbClick) {
  11412. tree.selectAll(false);
  11413. // Select clicked node (radio-button mode)
  11414. node.setSelected();
  11415. }
  11416. // Default handler will toggle checkbox clicks and activate
  11417. break;
  11418. case "shift+click":
  11419. // node.debug("click")
  11420. tree.visitRows(
  11421. function(n) {
  11422. // n.debug("click2", n===node, node)
  11423. n.setSelected();
  11424. if (n === node) {
  11425. return false;
  11426. }
  11427. },
  11428. {
  11429. start: activeNode,
  11430. reverse: activeNode.isBelowOf(node),
  11431. }
  11432. );
  11433. break;
  11434. case "ctrl+click":
  11435. case "meta+click": // Mac: [Command]
  11436. node.toggleSelected();
  11437. return;
  11438. }
  11439. return this._superApply(arguments);
  11440. },
  11441. nodeKeydown: function(ctx) {
  11442. var tree = ctx.tree,
  11443. node = ctx.node,
  11444. event = ctx.originalEvent,
  11445. eventStr = $.ui.fancytree.eventToString(event);
  11446. switch (eventStr) {
  11447. case "up":
  11448. case "down":
  11449. tree.selectAll(false);
  11450. node.navigate(event.which, true);
  11451. tree.getActiveNode().setSelected();
  11452. break;
  11453. case "shift+up":
  11454. case "shift+down":
  11455. node.navigate(event.which, true);
  11456. tree.getActiveNode().setSelected();
  11457. break;
  11458. }
  11459. return this._superApply(arguments);
  11460. },
  11461. });
  11462. // Value returned by `require('jquery.fancytree..')`
  11463. return $.ui.fancytree;
  11464. }); // End of closure
  11465. /*! Extension 'jquery.fancytree.persist.js' *//*!
  11466. * jquery.fancytree.persist.js
  11467. *
  11468. * Persist tree status in cookiesRemove or highlight tree nodes, based on a filter.
  11469. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11470. *
  11471. * @depends: js-cookie or jquery-cookie
  11472. *
  11473. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  11474. *
  11475. * Released under the MIT license
  11476. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11477. *
  11478. * @version 2.37.0
  11479. * @date 2020-09-11T18:58:08Z
  11480. */
  11481. (function(factory) {
  11482. if (typeof define === "function" && define.amd) {
  11483. // AMD. Register as an anonymous module.
  11484. define(["jquery", "./jquery.fancytree"], factory);
  11485. } else if (typeof module === "object" && module.exports) {
  11486. // Node/CommonJS
  11487. require("./jquery.fancytree");
  11488. module.exports = factory(require("jquery"));
  11489. } else {
  11490. // Browser globals
  11491. factory(jQuery);
  11492. }
  11493. })(function($) {
  11494. "use strict";
  11495. /* global Cookies:false */
  11496. /*******************************************************************************
  11497. * Private functions and variables
  11498. */
  11499. var cookieStore = null,
  11500. localStorageStore = null,
  11501. sessionStorageStore = null,
  11502. _assert = $.ui.fancytree.assert,
  11503. ACTIVE = "active",
  11504. EXPANDED = "expanded",
  11505. FOCUS = "focus",
  11506. SELECTED = "selected";
  11507. // Accessing window.xxxStorage may raise security exceptions (see #1022)
  11508. try {
  11509. _assert(window.localStorage && window.localStorage.getItem);
  11510. localStorageStore = {
  11511. get: function(key) {
  11512. return window.localStorage.getItem(key);
  11513. },
  11514. set: function(key, value) {
  11515. window.localStorage.setItem(key, value);
  11516. },
  11517. remove: function(key) {
  11518. window.localStorage.removeItem(key);
  11519. },
  11520. };
  11521. } catch (e) {
  11522. $.ui.fancytree.warn("Could not access window.localStorage", e);
  11523. }
  11524. try {
  11525. _assert(window.sessionStorage && window.sessionStorage.getItem);
  11526. sessionStorageStore = {
  11527. get: function(key) {
  11528. return window.sessionStorage.getItem(key);
  11529. },
  11530. set: function(key, value) {
  11531. window.sessionStorage.setItem(key, value);
  11532. },
  11533. remove: function(key) {
  11534. window.sessionStorage.removeItem(key);
  11535. },
  11536. };
  11537. } catch (e) {
  11538. $.ui.fancytree.warn("Could not access window.sessionStorage", e);
  11539. }
  11540. if (typeof Cookies === "function") {
  11541. // Assume https://github.com/js-cookie/js-cookie
  11542. cookieStore = {
  11543. get: Cookies.get,
  11544. set: function(key, value) {
  11545. Cookies.set(key, value, this.options.persist.cookie);
  11546. },
  11547. remove: Cookies.remove,
  11548. };
  11549. } else if ($ && typeof $.cookie === "function") {
  11550. // Fall back to https://github.com/carhartl/jquery-cookie
  11551. cookieStore = {
  11552. get: $.cookie,
  11553. set: function(key, value) {
  11554. $.cookie.set(key, value, this.options.persist.cookie);
  11555. },
  11556. remove: $.removeCookie,
  11557. };
  11558. }
  11559. /* Recursively load lazy nodes
  11560. * @param {string} mode 'load', 'expand', false
  11561. */
  11562. function _loadLazyNodes(tree, local, keyList, mode, dfd) {
  11563. var i,
  11564. key,
  11565. l,
  11566. node,
  11567. foundOne = false,
  11568. expandOpts = tree.options.persist.expandOpts,
  11569. deferredList = [],
  11570. missingKeyList = [];
  11571. keyList = keyList || [];
  11572. dfd = dfd || $.Deferred();
  11573. for (i = 0, l = keyList.length; i < l; i++) {
  11574. key = keyList[i];
  11575. node = tree.getNodeByKey(key);
  11576. if (node) {
  11577. if (mode && node.isUndefined()) {
  11578. foundOne = true;
  11579. tree.debug(
  11580. "_loadLazyNodes: " + node + " is lazy: loading..."
  11581. );
  11582. if (mode === "expand") {
  11583. deferredList.push(node.setExpanded(true, expandOpts));
  11584. } else {
  11585. deferredList.push(node.load());
  11586. }
  11587. } else {
  11588. tree.debug("_loadLazyNodes: " + node + " already loaded.");
  11589. node.setExpanded(true, expandOpts);
  11590. }
  11591. } else {
  11592. missingKeyList.push(key);
  11593. tree.debug("_loadLazyNodes: " + node + " was not yet found.");
  11594. }
  11595. }
  11596. $.when.apply($, deferredList).always(function() {
  11597. // All lazy-expands have finished
  11598. if (foundOne && missingKeyList.length > 0) {
  11599. // If we read new nodes from server, try to resolve yet-missing keys
  11600. _loadLazyNodes(tree, local, missingKeyList, mode, dfd);
  11601. } else {
  11602. if (missingKeyList.length) {
  11603. tree.warn(
  11604. "_loadLazyNodes: could not load those keys: ",
  11605. missingKeyList
  11606. );
  11607. for (i = 0, l = missingKeyList.length; i < l; i++) {
  11608. key = keyList[i];
  11609. local._appendKey(EXPANDED, keyList[i], false);
  11610. }
  11611. }
  11612. dfd.resolve();
  11613. }
  11614. });
  11615. return dfd;
  11616. }
  11617. /**
  11618. * [ext-persist] Remove persistence data of the given type(s).
  11619. * Called like
  11620. * $.ui.fancytree.getTree("#tree").clearCookies("active expanded focus selected");
  11621. *
  11622. * @alias Fancytree#clearPersistData
  11623. * @requires jquery.fancytree.persist.js
  11624. */
  11625. $.ui.fancytree._FancytreeClass.prototype.clearPersistData = function(
  11626. types
  11627. ) {
  11628. var local = this.ext.persist,
  11629. prefix = local.cookiePrefix;
  11630. types = types || "active expanded focus selected";
  11631. if (types.indexOf(ACTIVE) >= 0) {
  11632. local._data(prefix + ACTIVE, null);
  11633. }
  11634. if (types.indexOf(EXPANDED) >= 0) {
  11635. local._data(prefix + EXPANDED, null);
  11636. }
  11637. if (types.indexOf(FOCUS) >= 0) {
  11638. local._data(prefix + FOCUS, null);
  11639. }
  11640. if (types.indexOf(SELECTED) >= 0) {
  11641. local._data(prefix + SELECTED, null);
  11642. }
  11643. };
  11644. $.ui.fancytree._FancytreeClass.prototype.clearCookies = function(types) {
  11645. this.warn(
  11646. "'tree.clearCookies()' is deprecated since v2.27.0: use 'clearPersistData()' instead."
  11647. );
  11648. return this.clearPersistData(types);
  11649. };
  11650. /**
  11651. * [ext-persist] Return persistence information from cookies
  11652. *
  11653. * Called like
  11654. * $.ui.fancytree.getTree("#tree").getPersistData();
  11655. *
  11656. * @alias Fancytree#getPersistData
  11657. * @requires jquery.fancytree.persist.js
  11658. */
  11659. $.ui.fancytree._FancytreeClass.prototype.getPersistData = function() {
  11660. var local = this.ext.persist,
  11661. prefix = local.cookiePrefix,
  11662. delim = local.cookieDelimiter,
  11663. res = {};
  11664. res[ACTIVE] = local._data(prefix + ACTIVE);
  11665. res[EXPANDED] = (local._data(prefix + EXPANDED) || "").split(delim);
  11666. res[SELECTED] = (local._data(prefix + SELECTED) || "").split(delim);
  11667. res[FOCUS] = local._data(prefix + FOCUS);
  11668. return res;
  11669. };
  11670. /******************************************************************************
  11671. * Extension code
  11672. */
  11673. $.ui.fancytree.registerExtension({
  11674. name: "persist",
  11675. version: "2.37.0",
  11676. // Default options for this extension.
  11677. options: {
  11678. cookieDelimiter: "~",
  11679. cookiePrefix: undefined, // 'fancytree-<treeId>-' by default
  11680. cookie: {
  11681. raw: false,
  11682. expires: "",
  11683. path: "",
  11684. domain: "",
  11685. secure: false,
  11686. },
  11687. expandLazy: false, // true: recursively expand and load lazy nodes
  11688. expandOpts: undefined, // optional `opts` argument passed to setExpanded()
  11689. fireActivate: true, // false: suppress `activate` event after active node was restored
  11690. overrideSource: true, // true: cookie takes precedence over `source` data attributes.
  11691. store: "auto", // 'cookie': force cookie, 'local': force localStore, 'session': force sessionStore
  11692. types: "active expanded focus selected",
  11693. },
  11694. /* Generic read/write string data to cookie, sessionStorage or localStorage. */
  11695. _data: function(key, value) {
  11696. var store = this._local.store;
  11697. if (value === undefined) {
  11698. return store.get.call(this, key);
  11699. } else if (value === null) {
  11700. store.remove.call(this, key);
  11701. } else {
  11702. store.set.call(this, key, value);
  11703. }
  11704. },
  11705. /* Append `key` to a cookie. */
  11706. _appendKey: function(type, key, flag) {
  11707. key = "" + key; // #90
  11708. var local = this._local,
  11709. instOpts = this.options.persist,
  11710. delim = instOpts.cookieDelimiter,
  11711. cookieName = local.cookiePrefix + type,
  11712. data = local._data(cookieName),
  11713. keyList = data ? data.split(delim) : [],
  11714. idx = $.inArray(key, keyList);
  11715. // Remove, even if we add a key, so the key is always the last entry
  11716. if (idx >= 0) {
  11717. keyList.splice(idx, 1);
  11718. }
  11719. // Append key to cookie
  11720. if (flag) {
  11721. keyList.push(key);
  11722. }
  11723. local._data(cookieName, keyList.join(delim));
  11724. },
  11725. treeInit: function(ctx) {
  11726. var tree = ctx.tree,
  11727. opts = ctx.options,
  11728. local = this._local,
  11729. instOpts = this.options.persist;
  11730. // // For 'auto' or 'cookie' mode, the cookie plugin must be available
  11731. // _assert((instOpts.store !== "auto" && instOpts.store !== "cookie") || cookieStore,
  11732. // "Missing required plugin for 'persist' extension: js.cookie.js or jquery.cookie.js");
  11733. local.cookiePrefix =
  11734. instOpts.cookiePrefix || "fancytree-" + tree._id + "-";
  11735. local.storeActive = instOpts.types.indexOf(ACTIVE) >= 0;
  11736. local.storeExpanded = instOpts.types.indexOf(EXPANDED) >= 0;
  11737. local.storeSelected = instOpts.types.indexOf(SELECTED) >= 0;
  11738. local.storeFocus = instOpts.types.indexOf(FOCUS) >= 0;
  11739. local.store = null;
  11740. if (instOpts.store === "auto") {
  11741. instOpts.store = localStorageStore ? "local" : "cookie";
  11742. }
  11743. if ($.isPlainObject(instOpts.store)) {
  11744. local.store = instOpts.store;
  11745. } else if (instOpts.store === "cookie") {
  11746. local.store = cookieStore;
  11747. } else if (instOpts.store === "local") {
  11748. local.store =
  11749. instOpts.store === "local"
  11750. ? localStorageStore
  11751. : sessionStorageStore;
  11752. } else if (instOpts.store === "session") {
  11753. local.store =
  11754. instOpts.store === "local"
  11755. ? localStorageStore
  11756. : sessionStorageStore;
  11757. }
  11758. _assert(local.store, "Need a valid store.");
  11759. // Bind init-handler to apply cookie state
  11760. tree.$div.on("fancytreeinit", function(event) {
  11761. if (
  11762. tree._triggerTreeEvent("beforeRestore", null, {}) === false
  11763. ) {
  11764. return;
  11765. }
  11766. var cookie,
  11767. dfd,
  11768. i,
  11769. keyList,
  11770. node,
  11771. prevFocus = local._data(local.cookiePrefix + FOCUS), // record this before node.setActive() overrides it;
  11772. noEvents = instOpts.fireActivate === false;
  11773. // tree.debug("document.cookie:", document.cookie);
  11774. cookie = local._data(local.cookiePrefix + EXPANDED);
  11775. keyList = cookie && cookie.split(instOpts.cookieDelimiter);
  11776. if (local.storeExpanded) {
  11777. // Recursively load nested lazy nodes if expandLazy is 'expand' or 'load'
  11778. // Also remove expand-cookies for unmatched nodes
  11779. dfd = _loadLazyNodes(
  11780. tree,
  11781. local,
  11782. keyList,
  11783. instOpts.expandLazy ? "expand" : false,
  11784. null
  11785. );
  11786. } else {
  11787. // nothing to do
  11788. dfd = new $.Deferred().resolve();
  11789. }
  11790. dfd.done(function() {
  11791. if (local.storeSelected) {
  11792. cookie = local._data(local.cookiePrefix + SELECTED);
  11793. if (cookie) {
  11794. keyList = cookie.split(instOpts.cookieDelimiter);
  11795. for (i = 0; i < keyList.length; i++) {
  11796. node = tree.getNodeByKey(keyList[i]);
  11797. if (node) {
  11798. if (
  11799. node.selected === undefined ||
  11800. (instOpts.overrideSource &&
  11801. node.selected === false)
  11802. ) {
  11803. // node.setSelected();
  11804. node.selected = true;
  11805. node.renderStatus();
  11806. }
  11807. } else {
  11808. // node is no longer member of the tree: remove from cookie also
  11809. local._appendKey(
  11810. SELECTED,
  11811. keyList[i],
  11812. false
  11813. );
  11814. }
  11815. }
  11816. }
  11817. // In selectMode 3 we have to fix the child nodes, since we
  11818. // only stored the selected *top* nodes
  11819. if (tree.options.selectMode === 3) {
  11820. tree.visit(function(n) {
  11821. if (n.selected) {
  11822. n.fixSelection3AfterClick();
  11823. return "skip";
  11824. }
  11825. });
  11826. }
  11827. }
  11828. if (local.storeActive) {
  11829. cookie = local._data(local.cookiePrefix + ACTIVE);
  11830. if (
  11831. cookie &&
  11832. (opts.persist.overrideSource || !tree.activeNode)
  11833. ) {
  11834. node = tree.getNodeByKey(cookie);
  11835. if (node) {
  11836. node.debug("persist: set active", cookie);
  11837. // We only want to set the focus if the container
  11838. // had the keyboard focus before
  11839. node.setActive(true, {
  11840. noFocus: true,
  11841. noEvents: noEvents,
  11842. });
  11843. }
  11844. }
  11845. }
  11846. if (local.storeFocus && prevFocus) {
  11847. node = tree.getNodeByKey(prevFocus);
  11848. if (node) {
  11849. // node.debug("persist: set focus", cookie);
  11850. if (tree.options.titlesTabbable) {
  11851. $(node.span)
  11852. .find(".fancytree-title")
  11853. .focus();
  11854. } else {
  11855. $(tree.$container).focus();
  11856. }
  11857. // node.setFocus();
  11858. }
  11859. }
  11860. tree._triggerTreeEvent("restore", null, {});
  11861. });
  11862. });
  11863. // Init the tree
  11864. return this._superApply(arguments);
  11865. },
  11866. nodeSetActive: function(ctx, flag, callOpts) {
  11867. var res,
  11868. local = this._local;
  11869. flag = flag !== false;
  11870. res = this._superApply(arguments);
  11871. if (local.storeActive) {
  11872. local._data(
  11873. local.cookiePrefix + ACTIVE,
  11874. this.activeNode ? this.activeNode.key : null
  11875. );
  11876. }
  11877. return res;
  11878. },
  11879. nodeSetExpanded: function(ctx, flag, callOpts) {
  11880. var res,
  11881. node = ctx.node,
  11882. local = this._local;
  11883. flag = flag !== false;
  11884. res = this._superApply(arguments);
  11885. if (local.storeExpanded) {
  11886. local._appendKey(EXPANDED, node.key, flag);
  11887. }
  11888. return res;
  11889. },
  11890. nodeSetFocus: function(ctx, flag) {
  11891. var res,
  11892. local = this._local;
  11893. flag = flag !== false;
  11894. res = this._superApply(arguments);
  11895. if (local.storeFocus) {
  11896. local._data(
  11897. local.cookiePrefix + FOCUS,
  11898. this.focusNode ? this.focusNode.key : null
  11899. );
  11900. }
  11901. return res;
  11902. },
  11903. nodeSetSelected: function(ctx, flag, callOpts) {
  11904. var res,
  11905. selNodes,
  11906. tree = ctx.tree,
  11907. node = ctx.node,
  11908. local = this._local;
  11909. flag = flag !== false;
  11910. res = this._superApply(arguments);
  11911. if (local.storeSelected) {
  11912. if (tree.options.selectMode === 3) {
  11913. // In selectMode 3 we only store the the selected *top* nodes.
  11914. // De-selecting a node may also de-select some parents, so we
  11915. // calculate the current status again
  11916. selNodes = $.map(tree.getSelectedNodes(true), function(n) {
  11917. return n.key;
  11918. });
  11919. selNodes = selNodes.join(
  11920. ctx.options.persist.cookieDelimiter
  11921. );
  11922. local._data(local.cookiePrefix + SELECTED, selNodes);
  11923. } else {
  11924. // beforeSelect can prevent the change - flag doesn't reflect the node.selected state
  11925. local._appendKey(SELECTED, node.key, node.selected);
  11926. }
  11927. }
  11928. return res;
  11929. },
  11930. });
  11931. // Value returned by `require('jquery.fancytree..')`
  11932. return $.ui.fancytree;
  11933. }); // End of closure
  11934. /*! Extension 'jquery.fancytree.table.js' *//*!
  11935. * jquery.fancytree.table.js
  11936. *
  11937. * Render tree as table (aka 'tree grid', 'table tree').
  11938. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  11939. *
  11940. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  11941. *
  11942. * Released under the MIT license
  11943. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  11944. *
  11945. * @version 2.37.0
  11946. * @date 2020-09-11T18:58:08Z
  11947. */
  11948. (function(factory) {
  11949. if (typeof define === "function" && define.amd) {
  11950. // AMD. Register as an anonymous module.
  11951. define(["jquery", "./jquery.fancytree"], factory);
  11952. } else if (typeof module === "object" && module.exports) {
  11953. // Node/CommonJS
  11954. require("./jquery.fancytree");
  11955. module.exports = factory(require("jquery"));
  11956. } else {
  11957. // Browser globals
  11958. factory(jQuery);
  11959. }
  11960. })(function($) {
  11961. "use strict";
  11962. /******************************************************************************
  11963. * Private functions and variables
  11964. */
  11965. function _assert(cond, msg) {
  11966. msg = msg || "";
  11967. if (!cond) {
  11968. $.error("Assertion failed " + msg);
  11969. }
  11970. }
  11971. function insertFirstChild(referenceNode, newNode) {
  11972. referenceNode.insertBefore(newNode, referenceNode.firstChild);
  11973. }
  11974. function insertSiblingAfter(referenceNode, newNode) {
  11975. referenceNode.parentNode.insertBefore(
  11976. newNode,
  11977. referenceNode.nextSibling
  11978. );
  11979. }
  11980. /* Show/hide all rows that are structural descendants of `parent`. */
  11981. function setChildRowVisibility(parent, flag) {
  11982. parent.visit(function(node) {
  11983. var tr = node.tr;
  11984. // currentFlag = node.hide ? false : flag; // fix for ext-filter
  11985. if (tr) {
  11986. tr.style.display = node.hide || !flag ? "none" : "";
  11987. }
  11988. if (!node.expanded) {
  11989. return "skip";
  11990. }
  11991. });
  11992. }
  11993. /* Find node that is rendered in previous row. */
  11994. function findPrevRowNode(node) {
  11995. var i,
  11996. last,
  11997. prev,
  11998. parent = node.parent,
  11999. siblings = parent ? parent.children : null;
  12000. if (siblings && siblings.length > 1 && siblings[0] !== node) {
  12001. // use the lowest descendant of the preceeding sibling
  12002. i = $.inArray(node, siblings);
  12003. prev = siblings[i - 1];
  12004. _assert(prev.tr);
  12005. // descend to lowest child (with a <tr> tag)
  12006. while (prev.children && prev.children.length) {
  12007. last = prev.children[prev.children.length - 1];
  12008. if (!last.tr) {
  12009. break;
  12010. }
  12011. prev = last;
  12012. }
  12013. } else {
  12014. // if there is no preceding sibling, use the direct parent
  12015. prev = parent;
  12016. }
  12017. return prev;
  12018. }
  12019. $.ui.fancytree.registerExtension({
  12020. name: "table",
  12021. version: "2.37.0",
  12022. // Default options for this extension.
  12023. options: {
  12024. checkboxColumnIdx: null, // render the checkboxes into the this column index (default: nodeColumnIdx)
  12025. indentation: 16, // indent every node level by 16px
  12026. mergeStatusColumns: true, // display 'nodata', 'loading', 'error' centered in a single, merged TR
  12027. nodeColumnIdx: 0, // render node expander, icon, and title to this column (default: #0)
  12028. },
  12029. // Overide virtual methods for this extension.
  12030. // `this` : is this extension object
  12031. // `this._super`: the virtual function that was overriden (member of prev. extension or Fancytree)
  12032. treeInit: function(ctx) {
  12033. var i,
  12034. n,
  12035. $row,
  12036. $tbody,
  12037. tree = ctx.tree,
  12038. opts = ctx.options,
  12039. tableOpts = opts.table,
  12040. $table = tree.widget.element;
  12041. if (tableOpts.customStatus != null) {
  12042. if (opts.renderStatusColumns == null) {
  12043. tree.warn(
  12044. "The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' instead."
  12045. );
  12046. opts.renderStatusColumns = tableOpts.customStatus;
  12047. } else {
  12048. $.error(
  12049. "The 'customStatus' option is deprecated since v2.15.0. Use 'renderStatusColumns' only instead."
  12050. );
  12051. }
  12052. }
  12053. if (opts.renderStatusColumns) {
  12054. if (opts.renderStatusColumns === true) {
  12055. opts.renderStatusColumns = opts.renderColumns;
  12056. // } else if( opts.renderStatusColumns === "wide" ) {
  12057. // opts.renderStatusColumns = _renderStatusNodeWide;
  12058. }
  12059. }
  12060. $table.addClass("fancytree-container fancytree-ext-table");
  12061. $tbody = $table.find(">tbody");
  12062. if (!$tbody.length) {
  12063. // TODO: not sure if we can rely on browsers to insert missing <tbody> before <tr>s:
  12064. if ($table.find(">tr").length) {
  12065. $.error(
  12066. "Expected table > tbody > tr. If you see this please open an issue."
  12067. );
  12068. }
  12069. $tbody = $("<tbody>").appendTo($table);
  12070. }
  12071. tree.tbody = $tbody[0];
  12072. // Prepare row templates:
  12073. // Determine column count from table header if any
  12074. tree.columnCount = $("thead >tr", $table)
  12075. .last()
  12076. .find(">th", $table).length;
  12077. // Read TR templates from tbody if any
  12078. $row = $tbody.children("tr").first();
  12079. if ($row.length) {
  12080. n = $row.children("td").length;
  12081. if (tree.columnCount && n !== tree.columnCount) {
  12082. tree.warn(
  12083. "Column count mismatch between thead (" +
  12084. tree.columnCount +
  12085. ") and tbody (" +
  12086. n +
  12087. "): using tbody."
  12088. );
  12089. tree.columnCount = n;
  12090. }
  12091. $row = $row.clone();
  12092. } else {
  12093. // Only thead is defined: create default row markup
  12094. _assert(
  12095. tree.columnCount >= 1,
  12096. "Need either <thead> or <tbody> with <td> elements to determine column count."
  12097. );
  12098. $row = $("<tr />");
  12099. for (i = 0; i < tree.columnCount; i++) {
  12100. $row.append("<td />");
  12101. }
  12102. }
  12103. $row.find(">td")
  12104. .eq(tableOpts.nodeColumnIdx)
  12105. .html("<span class='fancytree-node' />");
  12106. if (opts.aria) {
  12107. $row.attr("role", "row");
  12108. $row.find("td").attr("role", "gridcell");
  12109. }
  12110. tree.rowFragment = document.createDocumentFragment();
  12111. tree.rowFragment.appendChild($row.get(0));
  12112. // // If tbody contains a second row, use this as status node template
  12113. // $row = $tbody.children("tr").eq(1);
  12114. // if( $row.length === 0 ) {
  12115. // tree.statusRowFragment = tree.rowFragment;
  12116. // } else {
  12117. // $row = $row.clone();
  12118. // tree.statusRowFragment = document.createDocumentFragment();
  12119. // tree.statusRowFragment.appendChild($row.get(0));
  12120. // }
  12121. //
  12122. $tbody.empty();
  12123. // Make sure that status classes are set on the node's <tr> elements
  12124. tree.statusClassPropName = "tr";
  12125. tree.ariaPropName = "tr";
  12126. this.nodeContainerAttrName = "tr";
  12127. // #489: make sure $container is set to <table>, even if ext-dnd is listed before ext-table
  12128. tree.$container = $table;
  12129. this._superApply(arguments);
  12130. // standard Fancytree created a root UL
  12131. $(tree.rootNode.ul).remove();
  12132. tree.rootNode.ul = null;
  12133. // Add container to the TAB chain
  12134. // #577: Allow to set tabindex to "0", "-1" and ""
  12135. this.$container.attr("tabindex", opts.tabindex);
  12136. // this.$container.attr("tabindex", opts.tabbable ? "0" : "-1");
  12137. if (opts.aria) {
  12138. tree.$container
  12139. .attr("role", "treegrid")
  12140. .attr("aria-readonly", true);
  12141. }
  12142. },
  12143. nodeRemoveChildMarkup: function(ctx) {
  12144. var node = ctx.node;
  12145. // node.debug("nodeRemoveChildMarkup()");
  12146. node.visit(function(n) {
  12147. if (n.tr) {
  12148. $(n.tr).remove();
  12149. n.tr = null;
  12150. }
  12151. });
  12152. },
  12153. nodeRemoveMarkup: function(ctx) {
  12154. var node = ctx.node;
  12155. // node.debug("nodeRemoveMarkup()");
  12156. if (node.tr) {
  12157. $(node.tr).remove();
  12158. node.tr = null;
  12159. }
  12160. this.nodeRemoveChildMarkup(ctx);
  12161. },
  12162. /* Override standard render. */
  12163. nodeRender: function(ctx, force, deep, collapsed, _recursive) {
  12164. var children,
  12165. firstTr,
  12166. i,
  12167. l,
  12168. newRow,
  12169. prevNode,
  12170. prevTr,
  12171. subCtx,
  12172. tree = ctx.tree,
  12173. node = ctx.node,
  12174. opts = ctx.options,
  12175. isRootNode = !node.parent;
  12176. if (tree._enableUpdate === false) {
  12177. // $.ui.fancytree.debug("*** nodeRender _enableUpdate: false");
  12178. return;
  12179. }
  12180. if (!_recursive) {
  12181. ctx.hasCollapsedParents = node.parent && !node.parent.expanded;
  12182. }
  12183. // $.ui.fancytree.debug("*** nodeRender " + node + ", isRoot=" + isRootNode, "tr=" + node.tr, "hcp=" + ctx.hasCollapsedParents, "parent.tr=" + (node.parent && node.parent.tr));
  12184. if (!isRootNode) {
  12185. if (node.tr && force) {
  12186. this.nodeRemoveMarkup(ctx);
  12187. }
  12188. if (node.tr) {
  12189. if (force) {
  12190. // Set icon, link, and title (normally this is only required on initial render)
  12191. this.nodeRenderTitle(ctx); // triggers renderColumns()
  12192. } else {
  12193. // Update element classes according to node state
  12194. this.nodeRenderStatus(ctx);
  12195. }
  12196. } else {
  12197. if (ctx.hasCollapsedParents && !deep) {
  12198. // #166: we assume that the parent will be (recursively) rendered
  12199. // later anyway.
  12200. // node.debug("nodeRender ignored due to unrendered parent");
  12201. return;
  12202. }
  12203. // Create new <tr> after previous row
  12204. // if( node.isStatusNode() ) {
  12205. // newRow = tree.statusRowFragment.firstChild.cloneNode(true);
  12206. // } else {
  12207. newRow = tree.rowFragment.firstChild.cloneNode(true);
  12208. // }
  12209. prevNode = findPrevRowNode(node);
  12210. // $.ui.fancytree.debug("*** nodeRender " + node + ": prev: " + prevNode.key);
  12211. _assert(prevNode);
  12212. if (collapsed === true && _recursive) {
  12213. // hide all child rows, so we can use an animation to show it later
  12214. newRow.style.display = "none";
  12215. } else if (deep && ctx.hasCollapsedParents) {
  12216. // also hide this row if deep === true but any parent is collapsed
  12217. newRow.style.display = "none";
  12218. // newRow.style.color = "red";
  12219. }
  12220. if (prevNode.tr) {
  12221. insertSiblingAfter(prevNode.tr, newRow);
  12222. } else {
  12223. _assert(
  12224. !prevNode.parent,
  12225. "prev. row must have a tr, or be system root"
  12226. );
  12227. // tree.tbody.appendChild(newRow);
  12228. insertFirstChild(tree.tbody, newRow); // #675
  12229. }
  12230. node.tr = newRow;
  12231. if (node.key && opts.generateIds) {
  12232. node.tr.id = opts.idPrefix + node.key;
  12233. }
  12234. node.tr.ftnode = node;
  12235. // if(opts.aria){
  12236. // $(node.tr).attr("aria-labelledby", "ftal_" + opts.idPrefix + node.key);
  12237. // }
  12238. node.span = $("span.fancytree-node", node.tr).get(0);
  12239. // Set icon, link, and title (normally this is only required on initial render)
  12240. this.nodeRenderTitle(ctx);
  12241. // Allow tweaking, binding, after node was created for the first time
  12242. // tree._triggerNodeEvent("createNode", ctx);
  12243. if (opts.createNode) {
  12244. opts.createNode.call(tree, { type: "createNode" }, ctx);
  12245. }
  12246. }
  12247. }
  12248. // Allow tweaking after node state was rendered
  12249. // tree._triggerNodeEvent("renderNode", ctx);
  12250. if (opts.renderNode) {
  12251. opts.renderNode.call(tree, { type: "renderNode" }, ctx);
  12252. }
  12253. // Visit child nodes
  12254. // Add child markup
  12255. children = node.children;
  12256. if (children && (isRootNode || deep || node.expanded)) {
  12257. for (i = 0, l = children.length; i < l; i++) {
  12258. subCtx = $.extend({}, ctx, { node: children[i] });
  12259. subCtx.hasCollapsedParents =
  12260. subCtx.hasCollapsedParents || !node.expanded;
  12261. this.nodeRender(subCtx, force, deep, collapsed, true);
  12262. }
  12263. }
  12264. // Make sure, that <tr> order matches node.children order.
  12265. if (children && !_recursive) {
  12266. // we only have to do it once, for the root branch
  12267. prevTr = node.tr || null;
  12268. firstTr = tree.tbody.firstChild;
  12269. // Iterate over all descendants
  12270. node.visit(function(n) {
  12271. if (n.tr) {
  12272. if (
  12273. !n.parent.expanded &&
  12274. n.tr.style.display !== "none"
  12275. ) {
  12276. // fix after a node was dropped over a collapsed
  12277. n.tr.style.display = "none";
  12278. setChildRowVisibility(n, false);
  12279. }
  12280. if (n.tr.previousSibling !== prevTr) {
  12281. node.debug("_fixOrder: mismatch at node: " + n);
  12282. var nextTr = prevTr ? prevTr.nextSibling : firstTr;
  12283. tree.tbody.insertBefore(n.tr, nextTr);
  12284. }
  12285. prevTr = n.tr;
  12286. }
  12287. });
  12288. }
  12289. // Update element classes according to node state
  12290. // if(!isRootNode){
  12291. // this.nodeRenderStatus(ctx);
  12292. // }
  12293. },
  12294. nodeRenderTitle: function(ctx, title) {
  12295. var $cb,
  12296. res,
  12297. tree = ctx.tree,
  12298. node = ctx.node,
  12299. opts = ctx.options,
  12300. isStatusNode = node.isStatusNode();
  12301. res = this._super(ctx, title);
  12302. if (node.isRootNode()) {
  12303. return res;
  12304. }
  12305. // Move checkbox to custom column
  12306. if (
  12307. opts.checkbox &&
  12308. !isStatusNode &&
  12309. opts.table.checkboxColumnIdx != null
  12310. ) {
  12311. $cb = $("span.fancytree-checkbox", node.span); //.detach();
  12312. $(node.tr)
  12313. .find("td")
  12314. .eq(+opts.table.checkboxColumnIdx)
  12315. .html($cb);
  12316. }
  12317. // Update element classes according to node state
  12318. this.nodeRenderStatus(ctx);
  12319. if (isStatusNode) {
  12320. if (opts.renderStatusColumns) {
  12321. // Let user code write column content
  12322. opts.renderStatusColumns.call(
  12323. tree,
  12324. { type: "renderStatusColumns" },
  12325. ctx
  12326. );
  12327. } else if (opts.table.mergeStatusColumns && node.isTopLevel()) {
  12328. $(node.tr)
  12329. .find(">td")
  12330. .eq(0)
  12331. .prop("colspan", tree.columnCount)
  12332. .text(node.title)
  12333. .addClass("fancytree-status-merged")
  12334. .nextAll()
  12335. .remove();
  12336. } // else: default rendering for status node: leave other cells empty
  12337. } else if (opts.renderColumns) {
  12338. opts.renderColumns.call(tree, { type: "renderColumns" }, ctx);
  12339. }
  12340. return res;
  12341. },
  12342. nodeRenderStatus: function(ctx) {
  12343. var indent,
  12344. node = ctx.node,
  12345. opts = ctx.options;
  12346. this._super(ctx);
  12347. $(node.tr).removeClass("fancytree-node");
  12348. // indent
  12349. indent = (node.getLevel() - 1) * opts.table.indentation;
  12350. if (opts.rtl) {
  12351. $(node.span).css({ paddingRight: indent + "px" });
  12352. } else {
  12353. $(node.span).css({ paddingLeft: indent + "px" });
  12354. }
  12355. },
  12356. /* Expand node, return Deferred.promise. */
  12357. nodeSetExpanded: function(ctx, flag, callOpts) {
  12358. // flag defaults to true
  12359. flag = flag !== false;
  12360. if ((ctx.node.expanded && flag) || (!ctx.node.expanded && !flag)) {
  12361. // Expanded state isn't changed - just call base implementation
  12362. return this._superApply(arguments);
  12363. }
  12364. var dfd = new $.Deferred(),
  12365. subOpts = $.extend({}, callOpts, {
  12366. noEvents: true,
  12367. noAnimation: true,
  12368. });
  12369. callOpts = callOpts || {};
  12370. function _afterExpand(ok) {
  12371. setChildRowVisibility(ctx.node, flag);
  12372. if (ok) {
  12373. if (
  12374. flag &&
  12375. ctx.options.autoScroll &&
  12376. !callOpts.noAnimation &&
  12377. ctx.node.hasChildren()
  12378. ) {
  12379. // Scroll down to last child, but keep current node visible
  12380. ctx.node
  12381. .getLastChild()
  12382. .scrollIntoView(true, { topNode: ctx.node })
  12383. .always(function() {
  12384. if (!callOpts.noEvents) {
  12385. ctx.tree._triggerNodeEvent(
  12386. flag ? "expand" : "collapse",
  12387. ctx
  12388. );
  12389. }
  12390. dfd.resolveWith(ctx.node);
  12391. });
  12392. } else {
  12393. if (!callOpts.noEvents) {
  12394. ctx.tree._triggerNodeEvent(
  12395. flag ? "expand" : "collapse",
  12396. ctx
  12397. );
  12398. }
  12399. dfd.resolveWith(ctx.node);
  12400. }
  12401. } else {
  12402. if (!callOpts.noEvents) {
  12403. ctx.tree._triggerNodeEvent(
  12404. flag ? "expand" : "collapse",
  12405. ctx
  12406. );
  12407. }
  12408. dfd.rejectWith(ctx.node);
  12409. }
  12410. }
  12411. // Call base-expand with disabled events and animation
  12412. this._super(ctx, flag, subOpts)
  12413. .done(function() {
  12414. _afterExpand(true);
  12415. })
  12416. .fail(function() {
  12417. _afterExpand(false);
  12418. });
  12419. return dfd.promise();
  12420. },
  12421. nodeSetStatus: function(ctx, status, message, details) {
  12422. if (status === "ok") {
  12423. var node = ctx.node,
  12424. firstChild = node.children ? node.children[0] : null;
  12425. if (firstChild && firstChild.isStatusNode()) {
  12426. $(firstChild.tr).remove();
  12427. }
  12428. }
  12429. return this._superApply(arguments);
  12430. },
  12431. treeClear: function(ctx) {
  12432. this.nodeRemoveChildMarkup(this._makeHookContext(this.rootNode));
  12433. return this._superApply(arguments);
  12434. },
  12435. treeDestroy: function(ctx) {
  12436. this.$container.find("tbody").empty();
  12437. if (this.$source) {
  12438. this.$source.removeClass("fancytree-helper-hidden");
  12439. }
  12440. return this._superApply(arguments);
  12441. },
  12442. /*,
  12443. treeSetFocus: function(ctx, flag) {
  12444. // alert("treeSetFocus" + ctx.tree.$container);
  12445. ctx.tree.$container.focus();
  12446. $.ui.fancytree.focusTree = ctx.tree;
  12447. }*/
  12448. });
  12449. // Value returned by `require('jquery.fancytree..')`
  12450. return $.ui.fancytree;
  12451. }); // End of closure
  12452. /*! Extension 'jquery.fancytree.themeroller.js' *//*!
  12453. * jquery.fancytree.themeroller.js
  12454. *
  12455. * Enable jQuery UI ThemeRoller styles.
  12456. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12457. *
  12458. * @see http://jqueryui.com/themeroller/
  12459. *
  12460. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  12461. *
  12462. * Released under the MIT license
  12463. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12464. *
  12465. * @version 2.37.0
  12466. * @date 2020-09-11T18:58:08Z
  12467. */
  12468. (function(factory) {
  12469. if (typeof define === "function" && define.amd) {
  12470. // AMD. Register as an anonymous module.
  12471. define(["jquery", "./jquery.fancytree"], factory);
  12472. } else if (typeof module === "object" && module.exports) {
  12473. // Node/CommonJS
  12474. require("./jquery.fancytree");
  12475. module.exports = factory(require("jquery"));
  12476. } else {
  12477. // Browser globals
  12478. factory(jQuery);
  12479. }
  12480. })(function($) {
  12481. "use strict";
  12482. /*******************************************************************************
  12483. * Extension code
  12484. */
  12485. $.ui.fancytree.registerExtension({
  12486. name: "themeroller",
  12487. version: "2.37.0",
  12488. // Default options for this extension.
  12489. options: {
  12490. activeClass: "ui-state-active", // Class added to active node
  12491. // activeClass: "ui-state-highlight",
  12492. addClass: "ui-corner-all", // Class added to all nodes
  12493. focusClass: "ui-state-focus", // Class added to focused node
  12494. hoverClass: "ui-state-hover", // Class added to hovered node
  12495. selectedClass: "ui-state-highlight", // Class added to selected nodes
  12496. // selectedClass: "ui-state-active"
  12497. },
  12498. treeInit: function(ctx) {
  12499. var $el = ctx.widget.element,
  12500. opts = ctx.options.themeroller;
  12501. this._superApply(arguments);
  12502. if ($el[0].nodeName === "TABLE") {
  12503. $el.addClass("ui-widget ui-corner-all");
  12504. $el.find(">thead tr").addClass("ui-widget-header");
  12505. $el.find(">tbody").addClass("ui-widget-conent");
  12506. } else {
  12507. $el.addClass("ui-widget ui-widget-content ui-corner-all");
  12508. }
  12509. $el.on("mouseenter mouseleave", ".fancytree-node", function(event) {
  12510. var node = $.ui.fancytree.getNode(event.target),
  12511. flag = event.type === "mouseenter";
  12512. $(node.tr ? node.tr : node.span).toggleClass(
  12513. opts.hoverClass + " " + opts.addClass,
  12514. flag
  12515. );
  12516. });
  12517. },
  12518. treeDestroy: function(ctx) {
  12519. this._superApply(arguments);
  12520. ctx.widget.element.removeClass(
  12521. "ui-widget ui-widget-content ui-corner-all"
  12522. );
  12523. },
  12524. nodeRenderStatus: function(ctx) {
  12525. var classes = {},
  12526. node = ctx.node,
  12527. $el = $(node.tr ? node.tr : node.span),
  12528. opts = ctx.options.themeroller;
  12529. this._super(ctx);
  12530. /*
  12531. .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.
  12532. .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.
  12533. .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.
  12534. .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.
  12535. .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.
  12536. .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.
  12537. .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.
  12538. */
  12539. // Set ui-state-* class (handle the case that the same class is assigned
  12540. // to different states)
  12541. classes[opts.activeClass] = false;
  12542. classes[opts.focusClass] = false;
  12543. classes[opts.selectedClass] = false;
  12544. if (node.isActive()) {
  12545. classes[opts.activeClass] = true;
  12546. }
  12547. if (node.hasFocus()) {
  12548. classes[opts.focusClass] = true;
  12549. }
  12550. // activeClass takes precedence before selectedClass:
  12551. if (node.isSelected() && !node.isActive()) {
  12552. classes[opts.selectedClass] = true;
  12553. }
  12554. $el.toggleClass(opts.activeClass, classes[opts.activeClass]);
  12555. $el.toggleClass(opts.focusClass, classes[opts.focusClass]);
  12556. $el.toggleClass(opts.selectedClass, classes[opts.selectedClass]);
  12557. // Additional classes (e.g. 'ui-corner-all')
  12558. $el.addClass(opts.addClass);
  12559. },
  12560. });
  12561. // Value returned by `require('jquery.fancytree..')`
  12562. return $.ui.fancytree;
  12563. }); // End of closure
  12564. /*! Extension 'jquery.fancytree.wide.js' *//*!
  12565. * jquery.fancytree.wide.js
  12566. * Support for 100% wide selection bars.
  12567. * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
  12568. *
  12569. * Copyright (c) 2008-2020, Martin Wendt (https://wwWendt.de)
  12570. *
  12571. * Released under the MIT license
  12572. * https://github.com/mar10/fancytree/wiki/LicenseInfo
  12573. *
  12574. * @version 2.37.0
  12575. * @date 2020-09-11T18:58:08Z
  12576. */
  12577. (function(factory) {
  12578. if (typeof define === "function" && define.amd) {
  12579. // AMD. Register as an anonymous module.
  12580. define(["jquery", "./jquery.fancytree"], factory);
  12581. } else if (typeof module === "object" && module.exports) {
  12582. // Node/CommonJS
  12583. require("./jquery.fancytree");
  12584. module.exports = factory(require("jquery"));
  12585. } else {
  12586. // Browser globals
  12587. factory(jQuery);
  12588. }
  12589. })(function($) {
  12590. "use strict";
  12591. var reNumUnit = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/; // split "1.5em" to ["1.5", "em"]
  12592. /*******************************************************************************
  12593. * Private functions and variables
  12594. */
  12595. // var _assert = $.ui.fancytree.assert;
  12596. /* Calculate inner width without scrollbar */
  12597. // function realInnerWidth($el) {
  12598. // // http://blog.jquery.com/2012/08/16/jquery-1-8-box-sizing-width-csswidth-and-outerwidth/
  12599. // // inst.contWidth = parseFloat(this.$container.css("width"), 10);
  12600. // // 'Client width without scrollbar' - 'padding'
  12601. // return $el[0].clientWidth - ($el.innerWidth() - parseFloat($el.css("width"), 10));
  12602. // }
  12603. /* Create a global embedded CSS style for the tree. */
  12604. function defineHeadStyleElement(id, cssText) {
  12605. id = "fancytree-style-" + id;
  12606. var $headStyle = $("#" + id);
  12607. if (!cssText) {
  12608. $headStyle.remove();
  12609. return null;
  12610. }
  12611. if (!$headStyle.length) {
  12612. $headStyle = $("<style />")
  12613. .attr("id", id)
  12614. .addClass("fancytree-style")
  12615. .prop("type", "text/css")
  12616. .appendTo("head");
  12617. }
  12618. try {
  12619. $headStyle.html(cssText);
  12620. } catch (e) {
  12621. // fix for IE 6-8
  12622. $headStyle[0].styleSheet.cssText = cssText;
  12623. }
  12624. return $headStyle;
  12625. }
  12626. /* Calculate the CSS rules that indent title spans. */
  12627. function renderLevelCss(
  12628. containerId,
  12629. depth,
  12630. levelOfs,
  12631. lineOfs,
  12632. labelOfs,
  12633. measureUnit
  12634. ) {
  12635. var i,
  12636. prefix = "#" + containerId + " span.fancytree-level-",
  12637. rules = [];
  12638. for (i = 0; i < depth; i++) {
  12639. rules.push(
  12640. prefix +
  12641. (i + 1) +
  12642. " span.fancytree-title { padding-left: " +
  12643. (i * levelOfs + lineOfs) +
  12644. measureUnit +
  12645. "; }"
  12646. );
  12647. }
  12648. // Some UI animations wrap the UL inside a DIV and set position:relative on both.
  12649. // This breaks the left:0 and padding-left:nn settings of the title
  12650. rules.push(
  12651. "#" +
  12652. containerId +
  12653. " div.ui-effects-wrapper ul li span.fancytree-title, " +
  12654. "#" +
  12655. containerId +
  12656. " li.fancytree-animating span.fancytree-title " + // #716
  12657. "{ padding-left: " +
  12658. labelOfs +
  12659. measureUnit +
  12660. "; position: static; width: auto; }"
  12661. );
  12662. return rules.join("\n");
  12663. }
  12664. // /**
  12665. // * [ext-wide] Recalculate the width of the selection bar after the tree container
  12666. // * was resized.<br>
  12667. // * May be called explicitly on container resize, since there is no resize event
  12668. // * for DIV tags.
  12669. // *
  12670. // * @alias Fancytree#wideUpdate
  12671. // * @requires jquery.fancytree.wide.js
  12672. // */
  12673. // $.ui.fancytree._FancytreeClass.prototype.wideUpdate = function(){
  12674. // var inst = this.ext.wide,
  12675. // prevCw = inst.contWidth,
  12676. // prevLo = inst.lineOfs;
  12677. // inst.contWidth = realInnerWidth(this.$container);
  12678. // // Each title is precceeded by 2 or 3 icons (16px + 3 margin)
  12679. // // + 1px title border and 3px title padding
  12680. // // TODO: use code from treeInit() below
  12681. // inst.lineOfs = (this.options.checkbox ? 3 : 2) * 19;
  12682. // if( prevCw !== inst.contWidth || prevLo !== inst.lineOfs ) {
  12683. // this.debug("wideUpdate: " + inst.contWidth);
  12684. // this.visit(function(node){
  12685. // node.tree._callHook("nodeRenderTitle", node);
  12686. // });
  12687. // }
  12688. // };
  12689. /*******************************************************************************
  12690. * Extension code
  12691. */
  12692. $.ui.fancytree.registerExtension({
  12693. name: "wide",
  12694. version: "2.37.0",
  12695. // Default options for this extension.
  12696. options: {
  12697. iconWidth: null, // Adjust this if @fancy-icon-width != "16px"
  12698. iconSpacing: null, // Adjust this if @fancy-icon-spacing != "3px"
  12699. labelSpacing: null, // Adjust this if padding between icon and label != "3px"
  12700. levelOfs: null, // Adjust this if ul padding != "16px"
  12701. },
  12702. treeCreate: function(ctx) {
  12703. this._superApply(arguments);
  12704. this.$container.addClass("fancytree-ext-wide");
  12705. var containerId,
  12706. cssText,
  12707. iconSpacingUnit,
  12708. labelSpacingUnit,
  12709. iconWidthUnit,
  12710. levelOfsUnit,
  12711. instOpts = ctx.options.wide,
  12712. // css sniffing
  12713. $dummyLI = $(
  12714. "<li id='fancytreeTemp'><span class='fancytree-node'><span class='fancytree-icon' /><span class='fancytree-title' /></span><ul />"
  12715. ).appendTo(ctx.tree.$container),
  12716. $dummyIcon = $dummyLI.find(".fancytree-icon"),
  12717. $dummyUL = $dummyLI.find("ul"),
  12718. // $dummyTitle = $dummyLI.find(".fancytree-title"),
  12719. iconSpacing =
  12720. instOpts.iconSpacing || $dummyIcon.css("margin-left"),
  12721. iconWidth = instOpts.iconWidth || $dummyIcon.css("width"),
  12722. labelSpacing = instOpts.labelSpacing || "3px",
  12723. levelOfs = instOpts.levelOfs || $dummyUL.css("padding-left");
  12724. $dummyLI.remove();
  12725. iconSpacingUnit = iconSpacing.match(reNumUnit)[2];
  12726. iconSpacing = parseFloat(iconSpacing, 10);
  12727. labelSpacingUnit = labelSpacing.match(reNumUnit)[2];
  12728. labelSpacing = parseFloat(labelSpacing, 10);
  12729. iconWidthUnit = iconWidth.match(reNumUnit)[2];
  12730. iconWidth = parseFloat(iconWidth, 10);
  12731. levelOfsUnit = levelOfs.match(reNumUnit)[2];
  12732. if (
  12733. iconSpacingUnit !== iconWidthUnit ||
  12734. levelOfsUnit !== iconWidthUnit ||
  12735. labelSpacingUnit !== iconWidthUnit
  12736. ) {
  12737. $.error(
  12738. "iconWidth, iconSpacing, and levelOfs must have the same css measure unit"
  12739. );
  12740. }
  12741. this._local.measureUnit = iconWidthUnit;
  12742. this._local.levelOfs = parseFloat(levelOfs);
  12743. this._local.lineOfs =
  12744. (1 +
  12745. (ctx.options.checkbox ? 1 : 0) +
  12746. (ctx.options.icon === false ? 0 : 1)) *
  12747. (iconWidth + iconSpacing) +
  12748. iconSpacing;
  12749. this._local.labelOfs = labelSpacing;
  12750. this._local.maxDepth = 10;
  12751. // Get/Set a unique Id on the container (if not already exists)
  12752. containerId = this.$container.uniqueId().attr("id");
  12753. // Generated css rules for some levels (extended on demand)
  12754. cssText = renderLevelCss(
  12755. containerId,
  12756. this._local.maxDepth,
  12757. this._local.levelOfs,
  12758. this._local.lineOfs,
  12759. this._local.labelOfs,
  12760. this._local.measureUnit
  12761. );
  12762. defineHeadStyleElement(containerId, cssText);
  12763. },
  12764. treeDestroy: function(ctx) {
  12765. // Remove generated css rules
  12766. defineHeadStyleElement(this.$container.attr("id"), null);
  12767. return this._superApply(arguments);
  12768. },
  12769. nodeRenderStatus: function(ctx) {
  12770. var containerId,
  12771. cssText,
  12772. res,
  12773. node = ctx.node,
  12774. level = node.getLevel();
  12775. res = this._super(ctx);
  12776. // Generate some more level-n rules if required
  12777. if (level > this._local.maxDepth) {
  12778. containerId = this.$container.attr("id");
  12779. this._local.maxDepth *= 2;
  12780. node.debug(
  12781. "Define global ext-wide css up to level " +
  12782. this._local.maxDepth
  12783. );
  12784. cssText = renderLevelCss(
  12785. containerId,
  12786. this._local.maxDepth,
  12787. this._local.levelOfs,
  12788. this._local.lineOfs,
  12789. this._local.labelSpacing,
  12790. this._local.measureUnit
  12791. );
  12792. defineHeadStyleElement(containerId, cssText);
  12793. }
  12794. // Add level-n class to apply indentation padding.
  12795. // (Setting element style would not work, since it cannot easily be
  12796. // overriden while animations run)
  12797. $(node.span).addClass("fancytree-level-" + level);
  12798. return res;
  12799. },
  12800. });
  12801. // Value returned by `require('jquery.fancytree..')`
  12802. return $.ui.fancytree;
  12803. }); // End of closure
  12804. // Value returned by `require('jquery.fancytree')`
  12805. return $.ui.fancytree;
  12806. })); // End of closure