jstree.js 296 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589
  1. /*globals jQuery, define, module, exports, require, window, document, postMessage */
  2. (function (factory) {
  3. "use strict";
  4. if (typeof define === 'function' && define.amd) {
  5. define(['jquery'], factory);
  6. }
  7. else if(typeof module !== 'undefined' && module.exports) {
  8. module.exports = factory(require('jquery'));
  9. }
  10. else {
  11. factory(jQuery);
  12. }
  13. }(function ($, undefined) {
  14. "use strict";
  15. /*!
  16. * jsTree 3.3.5
  17. * http://jstree.com/
  18. *
  19. * Copyright (c) 2014 Ivan Bozhanov (http://vakata.com)
  20. *
  21. * Licensed same as jquery - under the terms of the MIT License
  22. * http://www.opensource.org/licenses/mit-license.php
  23. */
  24. /*!
  25. * if using jslint please allow for the jQuery global and use following options:
  26. * jslint: loopfunc: true, browser: true, ass: true, bitwise: true, continue: true, nomen: true, plusplus: true, regexp: true, unparam: true, todo: true, white: true
  27. */
  28. /*jshint -W083 */
  29. // prevent another load? maybe there is a better way?
  30. if($.jstree) {
  31. return;
  32. }
  33. /**
  34. * ### jsTree core functionality
  35. */
  36. // internal variables
  37. var instance_counter = 0,
  38. ccp_node = false,
  39. ccp_mode = false,
  40. ccp_inst = false,
  41. themes_loaded = [],
  42. src = $('script:last').attr('src'),
  43. document = window.document; // local variable is always faster to access then a global
  44. /**
  45. * holds all jstree related functions and variables, including the actual class and methods to create, access and manipulate instances.
  46. * @name $.jstree
  47. */
  48. $.jstree = {
  49. /**
  50. * specifies the jstree version in use
  51. * @name $.jstree.version
  52. */
  53. version : '3.3.5',
  54. /**
  55. * holds all the default options used when creating new instances
  56. * @name $.jstree.defaults
  57. */
  58. defaults : {
  59. /**
  60. * configure which plugins will be active on an instance. Should be an array of strings, where each element is a plugin name. The default is `[]`
  61. * @name $.jstree.defaults.plugins
  62. */
  63. plugins : []
  64. },
  65. /**
  66. * stores all loaded jstree plugins (used internally)
  67. * @name $.jstree.plugins
  68. */
  69. plugins : {},
  70. path : src && src.indexOf('/') !== -1 ? src.replace(/\/[^\/]+$/,'') : '',
  71. idregex : /[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g,
  72. root : '#'
  73. };
  74. /**
  75. * creates a jstree instance
  76. * @name $.jstree.create(el [, options])
  77. * @param {DOMElement|jQuery|String} el the element to create the instance on, can be jQuery extended or a selector
  78. * @param {Object} options options for this instance (extends `$.jstree.defaults`)
  79. * @return {jsTree} the new instance
  80. */
  81. $.jstree.create = function (el, options) {
  82. var tmp = new $.jstree.core(++instance_counter),
  83. opt = options;
  84. options = $.extend(true, {}, $.jstree.defaults, options);
  85. if(opt && opt.plugins) {
  86. options.plugins = opt.plugins;
  87. }
  88. $.each(options.plugins, function (i, k) {
  89. if(i !== 'core') {
  90. tmp = tmp.plugin(k, options[k]);
  91. }
  92. });
  93. $(el).data('jstree', tmp);
  94. tmp.init(el, options);
  95. return tmp;
  96. };
  97. /**
  98. * remove all traces of jstree from the DOM and destroy all instances
  99. * @name $.jstree.destroy()
  100. */
  101. $.jstree.destroy = function () {
  102. $('.jstree:jstree').jstree('destroy');
  103. $(document).off('.jstree');
  104. };
  105. /**
  106. * the jstree class constructor, used only internally
  107. * @private
  108. * @name $.jstree.core(id)
  109. * @param {Number} id this instance's index
  110. */
  111. $.jstree.core = function (id) {
  112. this._id = id;
  113. this._cnt = 0;
  114. this._wrk = null;
  115. this._data = {
  116. core : {
  117. themes : {
  118. name : false,
  119. dots : false,
  120. icons : false,
  121. ellipsis : false
  122. },
  123. selected : [],
  124. last_error : {},
  125. working : false,
  126. worker_queue : [],
  127. focused : null
  128. }
  129. };
  130. };
  131. /**
  132. * get a reference to an existing instance
  133. *
  134. * __Examples__
  135. *
  136. * // provided a container with an ID of "tree", and a nested node with an ID of "branch"
  137. * // all of there will return the same instance
  138. * $.jstree.reference('tree');
  139. * $.jstree.reference('#tree');
  140. * $.jstree.reference($('#tree'));
  141. * $.jstree.reference(document.getElementByID('tree'));
  142. * $.jstree.reference('branch');
  143. * $.jstree.reference('#branch');
  144. * $.jstree.reference($('#branch'));
  145. * $.jstree.reference(document.getElementByID('branch'));
  146. *
  147. * @name $.jstree.reference(needle)
  148. * @param {DOMElement|jQuery|String} needle
  149. * @return {jsTree|null} the instance or `null` if not found
  150. */
  151. $.jstree.reference = function (needle) {
  152. var tmp = null,
  153. obj = null;
  154. if(needle && needle.id && (!needle.tagName || !needle.nodeType)) { needle = needle.id; }
  155. if(!obj || !obj.length) {
  156. try { obj = $(needle); } catch (ignore) { }
  157. }
  158. if(!obj || !obj.length) {
  159. try { obj = $('#' + needle.replace($.jstree.idregex,'\\$&')); } catch (ignore) { }
  160. }
  161. if(obj && obj.length && (obj = obj.closest('.jstree')).length && (obj = obj.data('jstree'))) {
  162. tmp = obj;
  163. }
  164. else {
  165. $('.jstree').each(function () {
  166. var inst = $(this).data('jstree');
  167. if(inst && inst._model.data[needle]) {
  168. tmp = inst;
  169. return false;
  170. }
  171. });
  172. }
  173. return tmp;
  174. };
  175. /**
  176. * Create an instance, get an instance or invoke a command on a instance.
  177. *
  178. * If there is no instance associated with the current node a new one is created and `arg` is used to extend `$.jstree.defaults` for this new instance. There would be no return value (chaining is not broken).
  179. *
  180. * If there is an existing instance and `arg` is a string the command specified by `arg` is executed on the instance, with any additional arguments passed to the function. If the function returns a value it will be returned (chaining could break depending on function).
  181. *
  182. * If there is an existing instance and `arg` is not a string the instance itself is returned (similar to `$.jstree.reference`).
  183. *
  184. * In any other case - nothing is returned and chaining is not broken.
  185. *
  186. * __Examples__
  187. *
  188. * $('#tree1').jstree(); // creates an instance
  189. * $('#tree2').jstree({ plugins : [] }); // create an instance with some options
  190. * $('#tree1').jstree('open_node', '#branch_1'); // call a method on an existing instance, passing additional arguments
  191. * $('#tree2').jstree(); // get an existing instance (or create an instance)
  192. * $('#tree2').jstree(true); // get an existing instance (will not create new instance)
  193. * $('#branch_1').jstree().select_node('#branch_1'); // get an instance (using a nested element and call a method)
  194. *
  195. * @name $().jstree([arg])
  196. * @param {String|Object} arg
  197. * @return {Mixed}
  198. */
  199. $.fn.jstree = function (arg) {
  200. // check for string argument
  201. var is_method = (typeof arg === 'string'),
  202. args = Array.prototype.slice.call(arguments, 1),
  203. result = null;
  204. if(arg === true && !this.length) { return false; }
  205. this.each(function () {
  206. // get the instance (if there is one) and method (if it exists)
  207. var instance = $.jstree.reference(this),
  208. method = is_method && instance ? instance[arg] : null;
  209. // if calling a method, and method is available - execute on the instance
  210. result = is_method && method ?
  211. method.apply(instance, args) :
  212. null;
  213. // if there is no instance and no method is being called - create one
  214. if(!instance && !is_method && (arg === undefined || $.isPlainObject(arg))) {
  215. $.jstree.create(this, arg);
  216. }
  217. // if there is an instance and no method is called - return the instance
  218. if( (instance && !is_method) || arg === true ) {
  219. result = instance || false;
  220. }
  221. // if there was a method call which returned a result - break and return the value
  222. if(result !== null && result !== undefined) {
  223. return false;
  224. }
  225. });
  226. // if there was a method call with a valid return value - return that, otherwise continue the chain
  227. return result !== null && result !== undefined ?
  228. result : this;
  229. };
  230. /**
  231. * used to find elements containing an instance
  232. *
  233. * __Examples__
  234. *
  235. * $('div:jstree').each(function () {
  236. * $(this).jstree('destroy');
  237. * });
  238. *
  239. * @name $(':jstree')
  240. * @return {jQuery}
  241. */
  242. $.expr.pseudos.jstree = $.expr.createPseudo(function(search) {
  243. return function(a) {
  244. return $(a).hasClass('jstree') &&
  245. $(a).data('jstree') !== undefined;
  246. };
  247. });
  248. /**
  249. * stores all defaults for the core
  250. * @name $.jstree.defaults.core
  251. */
  252. $.jstree.defaults.core = {
  253. /**
  254. * data configuration
  255. *
  256. * If left as `false` the HTML inside the jstree container element is used to populate the tree (that should be an unordered list with list items).
  257. *
  258. * You can also pass in a HTML string or a JSON array here.
  259. *
  260. * It is possible to pass in a standard jQuery-like AJAX config and jstree will automatically determine if the response is JSON or HTML and use that to populate the tree.
  261. * In addition to the standard jQuery ajax options here you can suppy functions for `data` and `url`, the functions will be run in the current instance's scope and a param will be passed indicating which node is being loaded, the return value of those functions will be used.
  262. *
  263. * The last option is to specify a function, that function will receive the node being loaded as argument and a second param which is a function which should be called with the result.
  264. *
  265. * __Examples__
  266. *
  267. * // AJAX
  268. * $('#tree').jstree({
  269. * 'core' : {
  270. * 'data' : {
  271. * 'url' : '/get/children/',
  272. * 'data' : function (node) {
  273. * return { 'id' : node.id };
  274. * }
  275. * }
  276. * });
  277. *
  278. * // direct data
  279. * $('#tree').jstree({
  280. * 'core' : {
  281. * 'data' : [
  282. * 'Simple root node',
  283. * {
  284. * 'id' : 'node_2',
  285. * 'text' : 'Root node with options',
  286. * 'state' : { 'opened' : true, 'selected' : true },
  287. * 'children' : [ { 'text' : 'Child 1' }, 'Child 2']
  288. * }
  289. * ]
  290. * }
  291. * });
  292. *
  293. * // function
  294. * $('#tree').jstree({
  295. * 'core' : {
  296. * 'data' : function (obj, callback) {
  297. * callback.call(this, ['Root 1', 'Root 2']);
  298. * }
  299. * });
  300. *
  301. * @name $.jstree.defaults.core.data
  302. */
  303. data : false,
  304. /**
  305. * configure the various strings used throughout the tree
  306. *
  307. * You can use an object where the key is the string you need to replace and the value is your replacement.
  308. * Another option is to specify a function which will be called with an argument of the needed string and should return the replacement.
  309. * If left as `false` no replacement is made.
  310. *
  311. * __Examples__
  312. *
  313. * $('#tree').jstree({
  314. * 'core' : {
  315. * 'strings' : {
  316. * 'Loading ...' : 'Please wait ...'
  317. * }
  318. * }
  319. * });
  320. *
  321. * @name $.jstree.defaults.core.strings
  322. */
  323. strings : false,
  324. /**
  325. * determines what happens when a user tries to modify the structure of the tree
  326. * If left as `false` all operations like create, rename, delete, move or copy are prevented.
  327. * You can set this to `true` to allow all interactions or use a function to have better control.
  328. *
  329. * __Examples__
  330. *
  331. * $('#tree').jstree({
  332. * 'core' : {
  333. * 'check_callback' : function (operation, node, node_parent, node_position, more) {
  334. * // operation can be 'create_node', 'rename_node', 'delete_node', 'move_node', 'copy_node' or 'edit'
  335. * // in case of 'rename_node' node_position is filled with the new node name
  336. * return operation === 'rename_node' ? true : false;
  337. * }
  338. * }
  339. * });
  340. *
  341. * @name $.jstree.defaults.core.check_callback
  342. */
  343. check_callback : false,
  344. /**
  345. * a callback called with a single object parameter in the instance's scope when something goes wrong (operation prevented, ajax failed, etc)
  346. * @name $.jstree.defaults.core.error
  347. */
  348. error : $.noop,
  349. /**
  350. * the open / close animation duration in milliseconds - set this to `false` to disable the animation (default is `200`)
  351. * @name $.jstree.defaults.core.animation
  352. */
  353. animation : 200,
  354. /**
  355. * a boolean indicating if multiple nodes can be selected
  356. * @name $.jstree.defaults.core.multiple
  357. */
  358. multiple : true,
  359. /**
  360. * theme configuration object
  361. * @name $.jstree.defaults.core.themes
  362. */
  363. themes : {
  364. /**
  365. * the name of the theme to use (if left as `false` the default theme is used)
  366. * @name $.jstree.defaults.core.themes.name
  367. */
  368. name : false,
  369. /**
  370. * the URL of the theme's CSS file, leave this as `false` if you have manually included the theme CSS (recommended). You can set this to `true` too which will try to autoload the theme.
  371. * @name $.jstree.defaults.core.themes.url
  372. */
  373. url : false,
  374. /**
  375. * the location of all jstree themes - only used if `url` is set to `true`
  376. * @name $.jstree.defaults.core.themes.dir
  377. */
  378. dir : false,
  379. /**
  380. * a boolean indicating if connecting dots are shown
  381. * @name $.jstree.defaults.core.themes.dots
  382. */
  383. dots : true,
  384. /**
  385. * a boolean indicating if node icons are shown
  386. * @name $.jstree.defaults.core.themes.icons
  387. */
  388. icons : true,
  389. /**
  390. * a boolean indicating if node ellipsis should be shown - this only works with a fixed with on the container
  391. * @name $.jstree.defaults.core.themes.ellipsis
  392. */
  393. ellipsis : false,
  394. /**
  395. * a boolean indicating if the tree background is striped
  396. * @name $.jstree.defaults.core.themes.stripes
  397. */
  398. stripes : false,
  399. /**
  400. * a string (or boolean `false`) specifying the theme variant to use (if the theme supports variants)
  401. * @name $.jstree.defaults.core.themes.variant
  402. */
  403. variant : false,
  404. /**
  405. * a boolean specifying if a reponsive version of the theme should kick in on smaller screens (if the theme supports it). Defaults to `false`.
  406. * @name $.jstree.defaults.core.themes.responsive
  407. */
  408. responsive : false
  409. },
  410. /**
  411. * if left as `true` all parents of all selected nodes will be opened once the tree loads (so that all selected nodes are visible to the user)
  412. * @name $.jstree.defaults.core.expand_selected_onload
  413. */
  414. expand_selected_onload : true,
  415. /**
  416. * if left as `true` web workers will be used to parse incoming JSON data where possible, so that the UI will not be blocked by large requests. Workers are however about 30% slower. Defaults to `true`
  417. * @name $.jstree.defaults.core.worker
  418. */
  419. worker : true,
  420. /**
  421. * Force node text to plain text (and escape HTML). Defaults to `false`
  422. * @name $.jstree.defaults.core.force_text
  423. */
  424. force_text : false,
  425. /**
  426. * Should the node should be toggled if the text is double clicked . Defaults to `true`
  427. * @name $.jstree.defaults.core.dblclick_toggle
  428. */
  429. dblclick_toggle : true,
  430. /**
  431. * Should the loaded nodes be part of the state. Defaults to `false`
  432. * @name $.jstree.defaults.core.loaded_state
  433. */
  434. loaded_state : false,
  435. /**
  436. * Should the last active node be focused when the tree container is blurred and the focused again. This helps working with screen readers. Defaults to `true`
  437. * @name $.jstree.defaults.core.restore_focus
  438. */
  439. restore_focus : true,
  440. /**
  441. * Default keyboard shortcuts (an object where each key is the button name or combo - like 'enter', 'ctrl-space', 'p', etc and the value is the function to execute in the instance's scope)
  442. * @name $.jstree.defaults.core.keyboard
  443. */
  444. keyboard : {
  445. 'ctrl-space': function (e) {
  446. // aria defines space only with Ctrl
  447. e.type = "click";
  448. $(e.currentTarget).trigger(e);
  449. },
  450. 'enter': function (e) {
  451. // enter
  452. e.type = "click";
  453. $(e.currentTarget).trigger(e);
  454. },
  455. 'left': function (e) {
  456. // left
  457. e.preventDefault();
  458. if(this.is_open(e.currentTarget)) {
  459. this.close_node(e.currentTarget);
  460. }
  461. else {
  462. var o = this.get_parent(e.currentTarget);
  463. if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').focus(); }
  464. }
  465. },
  466. 'up': function (e) {
  467. // up
  468. e.preventDefault();
  469. var o = this.get_prev_dom(e.currentTarget);
  470. if(o && o.length) { o.children('.jstree-anchor').focus(); }
  471. },
  472. 'right': function (e) {
  473. // right
  474. e.preventDefault();
  475. if(this.is_closed(e.currentTarget)) {
  476. this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').focus(); });
  477. }
  478. else if (this.is_open(e.currentTarget)) {
  479. var o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
  480. if(o) { $(this._firstChild(o)).children('.jstree-anchor').focus(); }
  481. }
  482. },
  483. 'down': function (e) {
  484. // down
  485. e.preventDefault();
  486. var o = this.get_next_dom(e.currentTarget);
  487. if(o && o.length) { o.children('.jstree-anchor').focus(); }
  488. },
  489. '*': function (e) {
  490. // aria defines * on numpad as open_all - not very common
  491. this.open_all();
  492. },
  493. 'home': function (e) {
  494. // home
  495. e.preventDefault();
  496. var o = this._firstChild(this.get_container_ul()[0]);
  497. if(o) { $(o).children('.jstree-anchor').filter(':visible').focus(); }
  498. },
  499. 'end': function (e) {
  500. // end
  501. e.preventDefault();
  502. this.element.find('.jstree-anchor').filter(':visible').last().focus();
  503. },
  504. 'f2': function (e) {
  505. // f2 - safe to include - if check_callback is false it will fail
  506. e.preventDefault();
  507. this.edit(e.currentTarget);
  508. }
  509. }
  510. };
  511. $.jstree.core.prototype = {
  512. /**
  513. * used to decorate an instance with a plugin. Used internally.
  514. * @private
  515. * @name plugin(deco [, opts])
  516. * @param {String} deco the plugin to decorate with
  517. * @param {Object} opts options for the plugin
  518. * @return {jsTree}
  519. */
  520. plugin : function (deco, opts) {
  521. var Child = $.jstree.plugins[deco];
  522. if(Child) {
  523. this._data[deco] = {};
  524. Child.prototype = this;
  525. return new Child(opts, this);
  526. }
  527. return this;
  528. },
  529. /**
  530. * initialize the instance. Used internally.
  531. * @private
  532. * @name init(el, optons)
  533. * @param {DOMElement|jQuery|String} el the element we are transforming
  534. * @param {Object} options options for this instance
  535. * @trigger init.jstree, loading.jstree, loaded.jstree, ready.jstree, changed.jstree
  536. */
  537. init : function (el, options) {
  538. this._model = {
  539. data : {},
  540. changed : [],
  541. force_full_redraw : false,
  542. redraw_timeout : false,
  543. default_state : {
  544. loaded : true,
  545. opened : false,
  546. selected : false,
  547. disabled : false
  548. }
  549. };
  550. this._model.data[$.jstree.root] = {
  551. id : $.jstree.root,
  552. parent : null,
  553. parents : [],
  554. children : [],
  555. children_d : [],
  556. state : { loaded : false }
  557. };
  558. this.element = $(el).addClass('jstree jstree-' + this._id);
  559. this.settings = options;
  560. this._data.core.ready = false;
  561. this._data.core.loaded = false;
  562. this._data.core.rtl = (this.element.css("direction") === "rtl");
  563. this.element[this._data.core.rtl ? 'addClass' : 'removeClass']("jstree-rtl");
  564. this.element.attr('role','tree');
  565. if(this.settings.core.multiple) {
  566. this.element.attr('aria-multiselectable', true);
  567. }
  568. if(!this.element.attr('tabindex')) {
  569. this.element.attr('tabindex','0');
  570. }
  571. this.bind();
  572. /**
  573. * triggered after all events are bound
  574. * @event
  575. * @name init.jstree
  576. */
  577. this.trigger("init");
  578. this._data.core.original_container_html = this.element.find(" > ul > li").clone(true);
  579. this._data.core.original_container_html
  580. .find("li").addBack()
  581. .contents().filter(function() {
  582. return this.nodeType === 3 && (!this.nodeValue || /^\s+$/.test(this.nodeValue));
  583. })
  584. .remove();
  585. this.element.html("<"+"ul class='jstree-container-ul jstree-children' role='group'><"+"li id='j"+this._id+"_loading' class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='tree-item'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
  586. this.element.attr('aria-activedescendant','j' + this._id + '_loading');
  587. this._data.core.li_height = this.get_container_ul().children("li").first().outerHeight() || 24;
  588. this._data.core.node = this._create_prototype_node();
  589. /**
  590. * triggered after the loading text is shown and before loading starts
  591. * @event
  592. * @name loading.jstree
  593. */
  594. this.trigger("loading");
  595. this.load_node($.jstree.root);
  596. },
  597. /**
  598. * destroy an instance
  599. * @name destroy()
  600. * @param {Boolean} keep_html if not set to `true` the container will be emptied, otherwise the current DOM elements will be kept intact
  601. */
  602. destroy : function (keep_html) {
  603. /**
  604. * triggered before the tree is destroyed
  605. * @event
  606. * @name destroy.jstree
  607. */
  608. this.trigger("destroy");
  609. if(this._wrk) {
  610. try {
  611. window.URL.revokeObjectURL(this._wrk);
  612. this._wrk = null;
  613. }
  614. catch (ignore) { }
  615. }
  616. if(!keep_html) { this.element.empty(); }
  617. this.teardown();
  618. },
  619. /**
  620. * Create a prototype node
  621. * @name _create_prototype_node()
  622. * @return {DOMElement}
  623. */
  624. _create_prototype_node : function () {
  625. var _node = document.createElement('LI'), _temp1, _temp2;
  626. _node.setAttribute('role', 'treeitem');
  627. _temp1 = document.createElement('I');
  628. _temp1.className = 'jstree-icon jstree-ocl';
  629. _temp1.setAttribute('role', 'presentation');
  630. _node.appendChild(_temp1);
  631. _temp1 = document.createElement('A');
  632. _temp1.className = 'jstree-anchor';
  633. _temp1.setAttribute('href','#');
  634. _temp1.setAttribute('tabindex','-1');
  635. _temp2 = document.createElement('I');
  636. _temp2.className = 'jstree-icon jstree-themeicon';
  637. _temp2.setAttribute('role', 'presentation');
  638. _temp1.appendChild(_temp2);
  639. _node.appendChild(_temp1);
  640. _temp1 = _temp2 = null;
  641. return _node;
  642. },
  643. _kbevent_to_func : function (e) {
  644. var keys = {
  645. 8: "Backspace", 9: "Tab", 13: "Return", 19: "Pause", 27: "Esc",
  646. 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home",
  647. 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "Print", 45: "Insert",
  648. 46: "Delete", 96: "Numpad0", 97: "Numpad1", 98: "Numpad2", 99 : "Numpad3",
  649. 100: "Numpad4", 101: "Numpad5", 102: "Numpad6", 103: "Numpad7",
  650. 104: "Numpad8", 105: "Numpad9", '-13': "NumpadEnter", 112: "F1",
  651. 113: "F2", 114: "F3", 115: "F4", 116: "F5", 117: "F6", 118: "F7",
  652. 119: "F8", 120: "F9", 121: "F10", 122: "F11", 123: "F12", 144: "Numlock",
  653. 145: "Scrolllock", 16: 'Shift', 17: 'Ctrl', 18: 'Alt',
  654. 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  655. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  656. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  657. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  658. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  659. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  660. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  661. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*', 173: '-'
  662. };
  663. var parts = [];
  664. if (e.ctrlKey) { parts.push('ctrl'); }
  665. if (e.altKey) { parts.push('alt'); }
  666. if (e.shiftKey) { parts.push('shift'); }
  667. parts.push(keys[e.which] || e.which);
  668. parts = parts.sort().join('-').toLowerCase();
  669. var kb = this.settings.core.keyboard, i, tmp;
  670. for (i in kb) {
  671. if (kb.hasOwnProperty(i)) {
  672. tmp = i;
  673. if (tmp !== '-' && tmp !== '+') {
  674. tmp = tmp.replace('--', '-MINUS').replace('+-', '-MINUS').replace('++', '-PLUS').replace('-+', '-PLUS');
  675. tmp = tmp.split(/-|\+/).sort().join('-').replace('MINUS', '-').replace('PLUS', '+').toLowerCase();
  676. }
  677. if (tmp === parts) {
  678. return kb[i];
  679. }
  680. }
  681. }
  682. return null;
  683. },
  684. /**
  685. * part of the destroying of an instance. Used internally.
  686. * @private
  687. * @name teardown()
  688. */
  689. teardown : function () {
  690. this.unbind();
  691. this.element
  692. .removeClass('jstree')
  693. .removeData('jstree')
  694. .find("[class^='jstree']")
  695. .addBack()
  696. .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });
  697. this.element = null;
  698. },
  699. /**
  700. * bind all events. Used internally.
  701. * @private
  702. * @name bind()
  703. */
  704. bind : function () {
  705. var word = '',
  706. tout = null,
  707. was_click = 0;
  708. this.element
  709. .on("dblclick.jstree", function (e) {
  710. if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
  711. if(document.selection && document.selection.empty) {
  712. document.selection.empty();
  713. }
  714. else {
  715. if(window.getSelection) {
  716. var sel = window.getSelection();
  717. try {
  718. sel.removeAllRanges();
  719. sel.collapse();
  720. } catch (ignore) { }
  721. }
  722. }
  723. })
  724. .on("mousedown.jstree", $.proxy(function (e) {
  725. if(e.target === this.element[0]) {
  726. e.preventDefault(); // prevent losing focus when clicking scroll arrows (FF, Chrome)
  727. was_click = +(new Date()); // ie does not allow to prevent losing focus
  728. }
  729. }, this))
  730. .on("mousedown.jstree", ".jstree-ocl", function (e) {
  731. e.preventDefault(); // prevent any node inside from losing focus when clicking the open/close icon
  732. })
  733. .on("click.jstree", ".jstree-ocl", $.proxy(function (e) {
  734. this.toggle_node(e.target);
  735. }, this))
  736. .on("dblclick.jstree", ".jstree-anchor", $.proxy(function (e) {
  737. if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
  738. if(this.settings.core.dblclick_toggle) {
  739. this.toggle_node(e.target);
  740. }
  741. }, this))
  742. .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
  743. e.preventDefault();
  744. if(e.currentTarget !== document.activeElement) { $(e.currentTarget).focus(); }
  745. this.activate_node(e.currentTarget, e);
  746. }, this))
  747. .on('keydown.jstree', '.jstree-anchor', $.proxy(function (e) {
  748. if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
  749. if(this._data.core.rtl) {
  750. if(e.which === 37) { e.which = 39; }
  751. else if(e.which === 39) { e.which = 37; }
  752. }
  753. var f = this._kbevent_to_func(e);
  754. if (f) {
  755. var r = f.call(this, e);
  756. if (r === false || r === true) {
  757. return r;
  758. }
  759. }
  760. }, this))
  761. .on("load_node.jstree", $.proxy(function (e, data) {
  762. if(data.status) {
  763. if(data.node.id === $.jstree.root && !this._data.core.loaded) {
  764. this._data.core.loaded = true;
  765. if(this._firstChild(this.get_container_ul()[0])) {
  766. this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
  767. }
  768. /**
  769. * triggered after the root node is loaded for the first time
  770. * @event
  771. * @name loaded.jstree
  772. */
  773. this.trigger("loaded");
  774. }
  775. if(!this._data.core.ready) {
  776. setTimeout($.proxy(function() {
  777. if(this.element && !this.get_container_ul().find('.jstree-loading').length) {
  778. this._data.core.ready = true;
  779. if(this._data.core.selected.length) {
  780. if(this.settings.core.expand_selected_onload) {
  781. var tmp = [], i, j;
  782. for(i = 0, j = this._data.core.selected.length; i < j; i++) {
  783. tmp = tmp.concat(this._model.data[this._data.core.selected[i]].parents);
  784. }
  785. tmp = $.vakata.array_unique(tmp);
  786. for(i = 0, j = tmp.length; i < j; i++) {
  787. this.open_node(tmp[i], false, 0);
  788. }
  789. }
  790. this.trigger('changed', { 'action' : 'ready', 'selected' : this._data.core.selected });
  791. }
  792. /**
  793. * triggered after all nodes are finished loading
  794. * @event
  795. * @name ready.jstree
  796. */
  797. this.trigger("ready");
  798. }
  799. }, this), 0);
  800. }
  801. }
  802. }, this))
  803. // quick searching when the tree is focused
  804. .on('keypress.jstree', $.proxy(function (e) {
  805. if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
  806. if(tout) { clearTimeout(tout); }
  807. tout = setTimeout(function () {
  808. word = '';
  809. }, 500);
  810. var chr = String.fromCharCode(e.which).toLowerCase(),
  811. col = this.element.find('.jstree-anchor').filter(':visible'),
  812. ind = col.index(document.activeElement) || 0,
  813. end = false;
  814. word += chr;
  815. // match for whole word from current node down (including the current node)
  816. if(word.length > 1) {
  817. col.slice(ind).each($.proxy(function (i, v) {
  818. if($(v).text().toLowerCase().indexOf(word) === 0) {
  819. $(v).focus();
  820. end = true;
  821. return false;
  822. }
  823. }, this));
  824. if(end) { return; }
  825. // match for whole word from the beginning of the tree
  826. col.slice(0, ind).each($.proxy(function (i, v) {
  827. if($(v).text().toLowerCase().indexOf(word) === 0) {
  828. $(v).focus();
  829. end = true;
  830. return false;
  831. }
  832. }, this));
  833. if(end) { return; }
  834. }
  835. // list nodes that start with that letter (only if word consists of a single char)
  836. if(new RegExp('^' + chr.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '+$').test(word)) {
  837. // search for the next node starting with that letter
  838. col.slice(ind + 1).each($.proxy(function (i, v) {
  839. if($(v).text().toLowerCase().charAt(0) === chr) {
  840. $(v).focus();
  841. end = true;
  842. return false;
  843. }
  844. }, this));
  845. if(end) { return; }
  846. // search from the beginning
  847. col.slice(0, ind + 1).each($.proxy(function (i, v) {
  848. if($(v).text().toLowerCase().charAt(0) === chr) {
  849. $(v).focus();
  850. end = true;
  851. return false;
  852. }
  853. }, this));
  854. if(end) { return; }
  855. }
  856. }, this))
  857. // THEME RELATED
  858. .on("init.jstree", $.proxy(function () {
  859. var s = this.settings.core.themes;
  860. this._data.core.themes.dots = s.dots;
  861. this._data.core.themes.stripes = s.stripes;
  862. this._data.core.themes.icons = s.icons;
  863. this._data.core.themes.ellipsis = s.ellipsis;
  864. this.set_theme(s.name || "default", s.url);
  865. this.set_theme_variant(s.variant);
  866. }, this))
  867. .on("loading.jstree", $.proxy(function () {
  868. this[ this._data.core.themes.dots ? "show_dots" : "hide_dots" ]();
  869. this[ this._data.core.themes.icons ? "show_icons" : "hide_icons" ]();
  870. this[ this._data.core.themes.stripes ? "show_stripes" : "hide_stripes" ]();
  871. this[ this._data.core.themes.ellipsis ? "show_ellipsis" : "hide_ellipsis" ]();
  872. }, this))
  873. .on('blur.jstree', '.jstree-anchor', $.proxy(function (e) {
  874. this._data.core.focused = null;
  875. $(e.currentTarget).filter('.jstree-hovered').mouseleave();
  876. this.element.attr('tabindex', '0');
  877. }, this))
  878. .on('focus.jstree', '.jstree-anchor', $.proxy(function (e) {
  879. var tmp = this.get_node(e.currentTarget);
  880. if(tmp && tmp.id) {
  881. this._data.core.focused = tmp.id;
  882. }
  883. this.element.find('.jstree-hovered').not(e.currentTarget).mouseleave();
  884. $(e.currentTarget).mouseenter();
  885. this.element.attr('tabindex', '-1');
  886. }, this))
  887. .on('focus.jstree', $.proxy(function () {
  888. if(+(new Date()) - was_click > 500 && !this._data.core.focused && this.settings.core.restore_focus) {
  889. was_click = 0;
  890. var act = this.get_node(this.element.attr('aria-activedescendant'), true);
  891. if(act) {
  892. act.find('> .jstree-anchor').focus();
  893. }
  894. }
  895. }, this))
  896. .on('mouseenter.jstree', '.jstree-anchor', $.proxy(function (e) {
  897. this.hover_node(e.currentTarget);
  898. }, this))
  899. .on('mouseleave.jstree', '.jstree-anchor', $.proxy(function (e) {
  900. this.dehover_node(e.currentTarget);
  901. }, this));
  902. },
  903. /**
  904. * part of the destroying of an instance. Used internally.
  905. * @private
  906. * @name unbind()
  907. */
  908. unbind : function () {
  909. this.element.off('.jstree');
  910. $(document).off('.jstree-' + this._id);
  911. },
  912. /**
  913. * trigger an event. Used internally.
  914. * @private
  915. * @name trigger(ev [, data])
  916. * @param {String} ev the name of the event to trigger
  917. * @param {Object} data additional data to pass with the event
  918. */
  919. trigger : function (ev, data) {
  920. if(!data) {
  921. data = {};
  922. }
  923. data.instance = this;
  924. this.element.triggerHandler(ev.replace('.jstree','') + '.jstree', data);
  925. },
  926. /**
  927. * returns the jQuery extended instance container
  928. * @name get_container()
  929. * @return {jQuery}
  930. */
  931. get_container : function () {
  932. return this.element;
  933. },
  934. /**
  935. * returns the jQuery extended main UL node inside the instance container. Used internally.
  936. * @private
  937. * @name get_container_ul()
  938. * @return {jQuery}
  939. */
  940. get_container_ul : function () {
  941. return this.element.children(".jstree-children").first();
  942. },
  943. /**
  944. * gets string replacements (localization). Used internally.
  945. * @private
  946. * @name get_string(key)
  947. * @param {String} key
  948. * @return {String}
  949. */
  950. get_string : function (key) {
  951. var a = this.settings.core.strings;
  952. if($.isFunction(a)) { return a.call(this, key); }
  953. if(a && a[key]) { return a[key]; }
  954. return key;
  955. },
  956. /**
  957. * gets the first child of a DOM node. Used internally.
  958. * @private
  959. * @name _firstChild(dom)
  960. * @param {DOMElement} dom
  961. * @return {DOMElement}
  962. */
  963. _firstChild : function (dom) {
  964. dom = dom ? dom.firstChild : null;
  965. while(dom !== null && dom.nodeType !== 1) {
  966. dom = dom.nextSibling;
  967. }
  968. return dom;
  969. },
  970. /**
  971. * gets the next sibling of a DOM node. Used internally.
  972. * @private
  973. * @name _nextSibling(dom)
  974. * @param {DOMElement} dom
  975. * @return {DOMElement}
  976. */
  977. _nextSibling : function (dom) {
  978. dom = dom ? dom.nextSibling : null;
  979. while(dom !== null && dom.nodeType !== 1) {
  980. dom = dom.nextSibling;
  981. }
  982. return dom;
  983. },
  984. /**
  985. * gets the previous sibling of a DOM node. Used internally.
  986. * @private
  987. * @name _previousSibling(dom)
  988. * @param {DOMElement} dom
  989. * @return {DOMElement}
  990. */
  991. _previousSibling : function (dom) {
  992. dom = dom ? dom.previousSibling : null;
  993. while(dom !== null && dom.nodeType !== 1) {
  994. dom = dom.previousSibling;
  995. }
  996. return dom;
  997. },
  998. /**
  999. * get the JSON representation of a node (or the actual jQuery extended DOM node) by using any input (child DOM element, ID string, selector, etc)
  1000. * @name get_node(obj [, as_dom])
  1001. * @param {mixed} obj
  1002. * @param {Boolean} as_dom
  1003. * @return {Object|jQuery}
  1004. */
  1005. get_node : function (obj, as_dom) {
  1006. if(obj && obj.id) {
  1007. obj = obj.id;
  1008. }
  1009. var dom;
  1010. try {
  1011. if(this._model.data[obj]) {
  1012. obj = this._model.data[obj];
  1013. }
  1014. else if(typeof obj === "string" && this._model.data[obj.replace(/^#/, '')]) {
  1015. obj = this._model.data[obj.replace(/^#/, '')];
  1016. }
  1017. else if(typeof obj === "string" && (dom = $('#' + obj.replace($.jstree.idregex,'\\$&'), this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
  1018. obj = this._model.data[dom.closest('.jstree-node').attr('id')];
  1019. }
  1020. else if((dom = $(obj, this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
  1021. obj = this._model.data[dom.closest('.jstree-node').attr('id')];
  1022. }
  1023. else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
  1024. obj = this._model.data[$.jstree.root];
  1025. }
  1026. else {
  1027. return false;
  1028. }
  1029. if(as_dom) {
  1030. obj = obj.id === $.jstree.root ? this.element : $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
  1031. }
  1032. return obj;
  1033. } catch (ex) { return false; }
  1034. },
  1035. /**
  1036. * get the path to a node, either consisting of node texts, or of node IDs, optionally glued together (otherwise an array)
  1037. * @name get_path(obj [, glue, ids])
  1038. * @param {mixed} obj the node
  1039. * @param {String} glue if you want the path as a string - pass the glue here (for example '/'), if a falsy value is supplied here, an array is returned
  1040. * @param {Boolean} ids if set to true build the path using ID, otherwise node text is used
  1041. * @return {mixed}
  1042. */
  1043. get_path : function (obj, glue, ids) {
  1044. obj = obj.parents ? obj : this.get_node(obj);
  1045. if(!obj || obj.id === $.jstree.root || !obj.parents) {
  1046. return false;
  1047. }
  1048. var i, j, p = [];
  1049. p.push(ids ? obj.id : obj.text);
  1050. for(i = 0, j = obj.parents.length; i < j; i++) {
  1051. p.push(ids ? obj.parents[i] : this.get_text(obj.parents[i]));
  1052. }
  1053. p = p.reverse().slice(1);
  1054. return glue ? p.join(glue) : p;
  1055. },
  1056. /**
  1057. * get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
  1058. * @name get_next_dom(obj [, strict])
  1059. * @param {mixed} obj
  1060. * @param {Boolean} strict
  1061. * @return {jQuery}
  1062. */
  1063. get_next_dom : function (obj, strict) {
  1064. var tmp;
  1065. obj = this.get_node(obj, true);
  1066. if(obj[0] === this.element[0]) {
  1067. tmp = this._firstChild(this.get_container_ul()[0]);
  1068. while (tmp && tmp.offsetHeight === 0) {
  1069. tmp = this._nextSibling(tmp);
  1070. }
  1071. return tmp ? $(tmp) : false;
  1072. }
  1073. if(!obj || !obj.length) {
  1074. return false;
  1075. }
  1076. if(strict) {
  1077. tmp = obj[0];
  1078. do {
  1079. tmp = this._nextSibling(tmp);
  1080. } while (tmp && tmp.offsetHeight === 0);
  1081. return tmp ? $(tmp) : false;
  1082. }
  1083. if(obj.hasClass("jstree-open")) {
  1084. tmp = this._firstChild(obj.children('.jstree-children')[0]);
  1085. while (tmp && tmp.offsetHeight === 0) {
  1086. tmp = this._nextSibling(tmp);
  1087. }
  1088. if(tmp !== null) {
  1089. return $(tmp);
  1090. }
  1091. }
  1092. tmp = obj[0];
  1093. do {
  1094. tmp = this._nextSibling(tmp);
  1095. } while (tmp && tmp.offsetHeight === 0);
  1096. if(tmp !== null) {
  1097. return $(tmp);
  1098. }
  1099. return obj.parentsUntil(".jstree",".jstree-node").nextAll(".jstree-node:visible").first();
  1100. },
  1101. /**
  1102. * get the previous visible node that is above the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
  1103. * @name get_prev_dom(obj [, strict])
  1104. * @param {mixed} obj
  1105. * @param {Boolean} strict
  1106. * @return {jQuery}
  1107. */
  1108. get_prev_dom : function (obj, strict) {
  1109. var tmp;
  1110. obj = this.get_node(obj, true);
  1111. if(obj[0] === this.element[0]) {
  1112. tmp = this.get_container_ul()[0].lastChild;
  1113. while (tmp && tmp.offsetHeight === 0) {
  1114. tmp = this._previousSibling(tmp);
  1115. }
  1116. return tmp ? $(tmp) : false;
  1117. }
  1118. if(!obj || !obj.length) {
  1119. return false;
  1120. }
  1121. if(strict) {
  1122. tmp = obj[0];
  1123. do {
  1124. tmp = this._previousSibling(tmp);
  1125. } while (tmp && tmp.offsetHeight === 0);
  1126. return tmp ? $(tmp) : false;
  1127. }
  1128. tmp = obj[0];
  1129. do {
  1130. tmp = this._previousSibling(tmp);
  1131. } while (tmp && tmp.offsetHeight === 0);
  1132. if(tmp !== null) {
  1133. obj = $(tmp);
  1134. while(obj.hasClass("jstree-open")) {
  1135. obj = obj.children(".jstree-children").first().children(".jstree-node:visible:last");
  1136. }
  1137. return obj;
  1138. }
  1139. tmp = obj[0].parentNode.parentNode;
  1140. return tmp && tmp.className && tmp.className.indexOf('jstree-node') !== -1 ? $(tmp) : false;
  1141. },
  1142. /**
  1143. * get the parent ID of a node
  1144. * @name get_parent(obj)
  1145. * @param {mixed} obj
  1146. * @return {String}
  1147. */
  1148. get_parent : function (obj) {
  1149. obj = this.get_node(obj);
  1150. if(!obj || obj.id === $.jstree.root) {
  1151. return false;
  1152. }
  1153. return obj.parent;
  1154. },
  1155. /**
  1156. * get a jQuery collection of all the children of a node (node must be rendered), returns false on error
  1157. * @name get_children_dom(obj)
  1158. * @param {mixed} obj
  1159. * @return {jQuery}
  1160. */
  1161. get_children_dom : function (obj) {
  1162. obj = this.get_node(obj, true);
  1163. if(obj[0] === this.element[0]) {
  1164. return this.get_container_ul().children(".jstree-node");
  1165. }
  1166. if(!obj || !obj.length) {
  1167. return false;
  1168. }
  1169. return obj.children(".jstree-children").children(".jstree-node");
  1170. },
  1171. /**
  1172. * checks if a node has children
  1173. * @name is_parent(obj)
  1174. * @param {mixed} obj
  1175. * @return {Boolean}
  1176. */
  1177. is_parent : function (obj) {
  1178. obj = this.get_node(obj);
  1179. return obj && (obj.state.loaded === false || obj.children.length > 0);
  1180. },
  1181. /**
  1182. * checks if a node is loaded (its children are available)
  1183. * @name is_loaded(obj)
  1184. * @param {mixed} obj
  1185. * @return {Boolean}
  1186. */
  1187. is_loaded : function (obj) {
  1188. obj = this.get_node(obj);
  1189. return obj && obj.state.loaded;
  1190. },
  1191. /**
  1192. * check if a node is currently loading (fetching children)
  1193. * @name is_loading(obj)
  1194. * @param {mixed} obj
  1195. * @return {Boolean}
  1196. */
  1197. is_loading : function (obj) {
  1198. obj = this.get_node(obj);
  1199. return obj && obj.state && obj.state.loading;
  1200. },
  1201. /**
  1202. * check if a node is opened
  1203. * @name is_open(obj)
  1204. * @param {mixed} obj
  1205. * @return {Boolean}
  1206. */
  1207. is_open : function (obj) {
  1208. obj = this.get_node(obj);
  1209. return obj && obj.state.opened;
  1210. },
  1211. /**
  1212. * check if a node is in a closed state
  1213. * @name is_closed(obj)
  1214. * @param {mixed} obj
  1215. * @return {Boolean}
  1216. */
  1217. is_closed : function (obj) {
  1218. obj = this.get_node(obj);
  1219. return obj && this.is_parent(obj) && !obj.state.opened;
  1220. },
  1221. /**
  1222. * check if a node has no children
  1223. * @name is_leaf(obj)
  1224. * @param {mixed} obj
  1225. * @return {Boolean}
  1226. */
  1227. is_leaf : function (obj) {
  1228. return !this.is_parent(obj);
  1229. },
  1230. /**
  1231. * loads a node (fetches its children using the `core.data` setting). Multiple nodes can be passed to by using an array.
  1232. * @name load_node(obj [, callback])
  1233. * @param {mixed} obj
  1234. * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives two arguments - the node and a boolean status
  1235. * @return {Boolean}
  1236. * @trigger load_node.jstree
  1237. */
  1238. load_node : function (obj, callback) {
  1239. var k, l, i, j, c;
  1240. if($.isArray(obj)) {
  1241. this._load_nodes(obj.slice(), callback);
  1242. return true;
  1243. }
  1244. obj = this.get_node(obj);
  1245. if(!obj) {
  1246. if(callback) { callback.call(this, obj, false); }
  1247. return false;
  1248. }
  1249. // if(obj.state.loading) { } // the node is already loading - just wait for it to load and invoke callback? but if called implicitly it should be loaded again?
  1250. if(obj.state.loaded) {
  1251. obj.state.loaded = false;
  1252. for(i = 0, j = obj.parents.length; i < j; i++) {
  1253. this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
  1254. return $.inArray(v, obj.children_d) === -1;
  1255. });
  1256. }
  1257. for(k = 0, l = obj.children_d.length; k < l; k++) {
  1258. if(this._model.data[obj.children_d[k]].state.selected) {
  1259. c = true;
  1260. }
  1261. delete this._model.data[obj.children_d[k]];
  1262. }
  1263. if (c) {
  1264. this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
  1265. return $.inArray(v, obj.children_d) === -1;
  1266. });
  1267. }
  1268. obj.children = [];
  1269. obj.children_d = [];
  1270. if(c) {
  1271. this.trigger('changed', { 'action' : 'load_node', 'node' : obj, 'selected' : this._data.core.selected });
  1272. }
  1273. }
  1274. obj.state.failed = false;
  1275. obj.state.loading = true;
  1276. this.get_node(obj, true).addClass("jstree-loading").attr('aria-busy',true);
  1277. this._load_node(obj, $.proxy(function (status) {
  1278. obj = this._model.data[obj.id];
  1279. obj.state.loading = false;
  1280. obj.state.loaded = status;
  1281. obj.state.failed = !obj.state.loaded;
  1282. var dom = this.get_node(obj, true), i = 0, j = 0, m = this._model.data, has_children = false;
  1283. for(i = 0, j = obj.children.length; i < j; i++) {
  1284. if(m[obj.children[i]] && !m[obj.children[i]].state.hidden) {
  1285. has_children = true;
  1286. break;
  1287. }
  1288. }
  1289. if(obj.state.loaded && dom && dom.length) {
  1290. dom.removeClass('jstree-closed jstree-open jstree-leaf');
  1291. if (!has_children) {
  1292. dom.addClass('jstree-leaf');
  1293. }
  1294. else {
  1295. if (obj.id !== '#') {
  1296. dom.addClass(obj.state.opened ? 'jstree-open' : 'jstree-closed');
  1297. }
  1298. }
  1299. }
  1300. dom.removeClass("jstree-loading").attr('aria-busy',false);
  1301. /**
  1302. * triggered after a node is loaded
  1303. * @event
  1304. * @name load_node.jstree
  1305. * @param {Object} node the node that was loading
  1306. * @param {Boolean} status was the node loaded successfully
  1307. */
  1308. this.trigger('load_node', { "node" : obj, "status" : status });
  1309. if(callback) {
  1310. callback.call(this, obj, status);
  1311. }
  1312. }, this));
  1313. return true;
  1314. },
  1315. /**
  1316. * load an array of nodes (will also load unavailable nodes as soon as the appear in the structure). Used internally.
  1317. * @private
  1318. * @name _load_nodes(nodes [, callback])
  1319. * @param {array} nodes
  1320. * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives one argument - the array passed to _load_nodes
  1321. */
  1322. _load_nodes : function (nodes, callback, is_callback, force_reload) {
  1323. var r = true,
  1324. c = function () { this._load_nodes(nodes, callback, true); },
  1325. m = this._model.data, i, j, tmp = [];
  1326. for(i = 0, j = nodes.length; i < j; i++) {
  1327. if(m[nodes[i]] && ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || (!is_callback && force_reload) )) {
  1328. if(!this.is_loading(nodes[i])) {
  1329. this.load_node(nodes[i], c);
  1330. }
  1331. r = false;
  1332. }
  1333. }
  1334. if(r) {
  1335. for(i = 0, j = nodes.length; i < j; i++) {
  1336. if(m[nodes[i]] && m[nodes[i]].state.loaded) {
  1337. tmp.push(nodes[i]);
  1338. }
  1339. }
  1340. if(callback && !callback.done) {
  1341. callback.call(this, tmp);
  1342. callback.done = true;
  1343. }
  1344. }
  1345. },
  1346. /**
  1347. * loads all unloaded nodes
  1348. * @name load_all([obj, callback])
  1349. * @param {mixed} obj the node to load recursively, omit to load all nodes in the tree
  1350. * @param {function} callback a function to be executed once loading all the nodes is complete,
  1351. * @trigger load_all.jstree
  1352. */
  1353. load_all : function (obj, callback) {
  1354. if(!obj) { obj = $.jstree.root; }
  1355. obj = this.get_node(obj);
  1356. if(!obj) { return false; }
  1357. var to_load = [],
  1358. m = this._model.data,
  1359. c = m[obj.id].children_d,
  1360. i, j;
  1361. if(obj.state && !obj.state.loaded) {
  1362. to_load.push(obj.id);
  1363. }
  1364. for(i = 0, j = c.length; i < j; i++) {
  1365. if(m[c[i]] && m[c[i]].state && !m[c[i]].state.loaded) {
  1366. to_load.push(c[i]);
  1367. }
  1368. }
  1369. if(to_load.length) {
  1370. this._load_nodes(to_load, function () {
  1371. this.load_all(obj, callback);
  1372. });
  1373. }
  1374. else {
  1375. /**
  1376. * triggered after a load_all call completes
  1377. * @event
  1378. * @name load_all.jstree
  1379. * @param {Object} node the recursively loaded node
  1380. */
  1381. if(callback) { callback.call(this, obj); }
  1382. this.trigger('load_all', { "node" : obj });
  1383. }
  1384. },
  1385. /**
  1386. * handles the actual loading of a node. Used only internally.
  1387. * @private
  1388. * @name _load_node(obj [, callback])
  1389. * @param {mixed} obj
  1390. * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives one argument - a boolean status
  1391. * @return {Boolean}
  1392. */
  1393. _load_node : function (obj, callback) {
  1394. var s = this.settings.core.data, t;
  1395. var notTextOrCommentNode = function notTextOrCommentNode () {
  1396. return this.nodeType !== 3 && this.nodeType !== 8;
  1397. };
  1398. // use original HTML
  1399. if(!s) {
  1400. if(obj.id === $.jstree.root) {
  1401. return this._append_html_data(obj, this._data.core.original_container_html.clone(true), function (status) {
  1402. callback.call(this, status);
  1403. });
  1404. }
  1405. else {
  1406. return callback.call(this, false);
  1407. }
  1408. // return callback.call(this, obj.id === $.jstree.root ? this._append_html_data(obj, this._data.core.original_container_html.clone(true)) : false);
  1409. }
  1410. if($.isFunction(s)) {
  1411. return s.call(this, obj, $.proxy(function (d) {
  1412. if(d === false) {
  1413. callback.call(this, false);
  1414. }
  1415. else {
  1416. this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $($.parseHTML(d)).filter(notTextOrCommentNode) : d, function (status) {
  1417. callback.call(this, status);
  1418. });
  1419. }
  1420. // return d === false ? callback.call(this, false) : callback.call(this, this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $(d) : d));
  1421. }, this));
  1422. }
  1423. if(typeof s === 'object') {
  1424. if(s.url) {
  1425. s = $.extend(true, {}, s);
  1426. if($.isFunction(s.url)) {
  1427. s.url = s.url.call(this, obj);
  1428. }
  1429. if($.isFunction(s.data)) {
  1430. s.data = s.data.call(this, obj);
  1431. }
  1432. return $.ajax(s)
  1433. .done($.proxy(function (d,t,x) {
  1434. var type = x.getResponseHeader('Content-Type');
  1435. if((type && type.indexOf('json') !== -1) || typeof d === "object") {
  1436. return this._append_json_data(obj, d, function (status) { callback.call(this, status); });
  1437. //return callback.call(this, this._append_json_data(obj, d));
  1438. }
  1439. if((type && type.indexOf('html') !== -1) || typeof d === "string") {
  1440. return this._append_html_data(obj, $($.parseHTML(d)).filter(notTextOrCommentNode), function (status) { callback.call(this, status); });
  1441. // return callback.call(this, this._append_html_data(obj, $(d)));
  1442. }
  1443. this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'core', 'id' : 'core_04', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id, 'xhr' : x }) };
  1444. this.settings.core.error.call(this, this._data.core.last_error);
  1445. return callback.call(this, false);
  1446. }, this))
  1447. .fail($.proxy(function (f) {
  1448. this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'core', 'id' : 'core_04', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id, 'xhr' : f }) };
  1449. callback.call(this, false);
  1450. this.settings.core.error.call(this, this._data.core.last_error);
  1451. }, this));
  1452. }
  1453. if ($.isArray(s)) {
  1454. t = $.extend(true, [], s);
  1455. } else if ($.isPlainObject(s)) {
  1456. t = $.extend(true, {}, s);
  1457. } else {
  1458. t = s;
  1459. }
  1460. if(obj.id === $.jstree.root) {
  1461. return this._append_json_data(obj, t, function (status) {
  1462. callback.call(this, status);
  1463. });
  1464. }
  1465. else {
  1466. this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_05', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
  1467. this.settings.core.error.call(this, this._data.core.last_error);
  1468. return callback.call(this, false);
  1469. }
  1470. //return callback.call(this, (obj.id === $.jstree.root ? this._append_json_data(obj, t) : false) );
  1471. }
  1472. if(typeof s === 'string') {
  1473. if(obj.id === $.jstree.root) {
  1474. return this._append_html_data(obj, $($.parseHTML(s)).filter(notTextOrCommentNode), function (status) {
  1475. callback.call(this, status);
  1476. });
  1477. }
  1478. else {
  1479. this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_06', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
  1480. this.settings.core.error.call(this, this._data.core.last_error);
  1481. return callback.call(this, false);
  1482. }
  1483. //return callback.call(this, (obj.id === $.jstree.root ? this._append_html_data(obj, $(s)) : false) );
  1484. }
  1485. return callback.call(this, false);
  1486. },
  1487. /**
  1488. * adds a node to the list of nodes to redraw. Used only internally.
  1489. * @private
  1490. * @name _node_changed(obj [, callback])
  1491. * @param {mixed} obj
  1492. */
  1493. _node_changed : function (obj) {
  1494. obj = this.get_node(obj);
  1495. if (obj && $.inArray(obj.id, this._model.changed) === -1) {
  1496. this._model.changed.push(obj.id);
  1497. }
  1498. },
  1499. /**
  1500. * appends HTML content to the tree. Used internally.
  1501. * @private
  1502. * @name _append_html_data(obj, data)
  1503. * @param {mixed} obj the node to append to
  1504. * @param {String} data the HTML string to parse and append
  1505. * @trigger model.jstree, changed.jstree
  1506. */
  1507. _append_html_data : function (dom, data, cb) {
  1508. dom = this.get_node(dom);
  1509. dom.children = [];
  1510. dom.children_d = [];
  1511. var dat = data.is('ul') ? data.children() : data,
  1512. par = dom.id,
  1513. chd = [],
  1514. dpc = [],
  1515. m = this._model.data,
  1516. p = m[par],
  1517. s = this._data.core.selected.length,
  1518. tmp, i, j;
  1519. dat.each($.proxy(function (i, v) {
  1520. tmp = this._parse_model_from_html($(v), par, p.parents.concat());
  1521. if(tmp) {
  1522. chd.push(tmp);
  1523. dpc.push(tmp);
  1524. if(m[tmp].children_d.length) {
  1525. dpc = dpc.concat(m[tmp].children_d);
  1526. }
  1527. }
  1528. }, this));
  1529. p.children = chd;
  1530. p.children_d = dpc;
  1531. for(i = 0, j = p.parents.length; i < j; i++) {
  1532. m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
  1533. }
  1534. /**
  1535. * triggered when new data is inserted to the tree model
  1536. * @event
  1537. * @name model.jstree
  1538. * @param {Array} nodes an array of node IDs
  1539. * @param {String} parent the parent ID of the nodes
  1540. */
  1541. this.trigger('model', { "nodes" : dpc, 'parent' : par });
  1542. if(par !== $.jstree.root) {
  1543. this._node_changed(par);
  1544. this.redraw();
  1545. }
  1546. else {
  1547. this.get_container_ul().children('.jstree-initial-node').remove();
  1548. this.redraw(true);
  1549. }
  1550. if(this._data.core.selected.length !== s) {
  1551. this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
  1552. }
  1553. cb.call(this, true);
  1554. },
  1555. /**
  1556. * appends JSON content to the tree. Used internally.
  1557. * @private
  1558. * @name _append_json_data(obj, data)
  1559. * @param {mixed} obj the node to append to
  1560. * @param {String} data the JSON object to parse and append
  1561. * @param {Boolean} force_processing internal param - do not set
  1562. * @trigger model.jstree, changed.jstree
  1563. */
  1564. _append_json_data : function (dom, data, cb, force_processing) {
  1565. if(this.element === null) { return; }
  1566. dom = this.get_node(dom);
  1567. dom.children = [];
  1568. dom.children_d = [];
  1569. // *%$@!!!
  1570. if(data.d) {
  1571. data = data.d;
  1572. if(typeof data === "string") {
  1573. data = JSON.parse(data);
  1574. }
  1575. }
  1576. if(!$.isArray(data)) { data = [data]; }
  1577. var w = null,
  1578. args = {
  1579. 'df' : this._model.default_state,
  1580. 'dat' : data,
  1581. 'par' : dom.id,
  1582. 'm' : this._model.data,
  1583. 't_id' : this._id,
  1584. 't_cnt' : this._cnt,
  1585. 'sel' : this._data.core.selected
  1586. },
  1587. func = function (data, undefined) {
  1588. if(data.data) { data = data.data; }
  1589. var dat = data.dat,
  1590. par = data.par,
  1591. chd = [],
  1592. dpc = [],
  1593. add = [],
  1594. df = data.df,
  1595. t_id = data.t_id,
  1596. t_cnt = data.t_cnt,
  1597. m = data.m,
  1598. p = m[par],
  1599. sel = data.sel,
  1600. tmp, i, j, rslt,
  1601. parse_flat = function (d, p, ps) {
  1602. if(!ps) { ps = []; }
  1603. else { ps = ps.concat(); }
  1604. if(p) { ps.unshift(p); }
  1605. var tid = d.id.toString(),
  1606. i, j, c, e,
  1607. tmp = {
  1608. id : tid,
  1609. text : d.text || '',
  1610. icon : d.icon !== undefined ? d.icon : true,
  1611. parent : p,
  1612. parents : ps,
  1613. children : d.children || [],
  1614. children_d : d.children_d || [],
  1615. data : d.data,
  1616. state : { },
  1617. li_attr : { id : false },
  1618. a_attr : { href : '#' },
  1619. original : false
  1620. };
  1621. for(i in df) {
  1622. if(df.hasOwnProperty(i)) {
  1623. tmp.state[i] = df[i];
  1624. }
  1625. }
  1626. if(d && d.data && d.data.jstree && d.data.jstree.icon) {
  1627. tmp.icon = d.data.jstree.icon;
  1628. }
  1629. if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
  1630. tmp.icon = true;
  1631. }
  1632. if(d && d.data) {
  1633. tmp.data = d.data;
  1634. if(d.data.jstree) {
  1635. for(i in d.data.jstree) {
  1636. if(d.data.jstree.hasOwnProperty(i)) {
  1637. tmp.state[i] = d.data.jstree[i];
  1638. }
  1639. }
  1640. }
  1641. }
  1642. if(d && typeof d.state === 'object') {
  1643. for (i in d.state) {
  1644. if(d.state.hasOwnProperty(i)) {
  1645. tmp.state[i] = d.state[i];
  1646. }
  1647. }
  1648. }
  1649. if(d && typeof d.li_attr === 'object') {
  1650. for (i in d.li_attr) {
  1651. if(d.li_attr.hasOwnProperty(i)) {
  1652. tmp.li_attr[i] = d.li_attr[i];
  1653. }
  1654. }
  1655. }
  1656. if(!tmp.li_attr.id) {
  1657. tmp.li_attr.id = tid;
  1658. }
  1659. if(d && typeof d.a_attr === 'object') {
  1660. for (i in d.a_attr) {
  1661. if(d.a_attr.hasOwnProperty(i)) {
  1662. tmp.a_attr[i] = d.a_attr[i];
  1663. }
  1664. }
  1665. }
  1666. if(d && d.children && d.children === true) {
  1667. tmp.state.loaded = false;
  1668. tmp.children = [];
  1669. tmp.children_d = [];
  1670. }
  1671. m[tmp.id] = tmp;
  1672. for(i = 0, j = tmp.children.length; i < j; i++) {
  1673. c = parse_flat(m[tmp.children[i]], tmp.id, ps);
  1674. e = m[c];
  1675. tmp.children_d.push(c);
  1676. if(e.children_d.length) {
  1677. tmp.children_d = tmp.children_d.concat(e.children_d);
  1678. }
  1679. }
  1680. delete d.data;
  1681. delete d.children;
  1682. m[tmp.id].original = d;
  1683. if(tmp.state.selected) {
  1684. add.push(tmp.id);
  1685. }
  1686. return tmp.id;
  1687. },
  1688. parse_nest = function (d, p, ps) {
  1689. if(!ps) { ps = []; }
  1690. else { ps = ps.concat(); }
  1691. if(p) { ps.unshift(p); }
  1692. var tid = false, i, j, c, e, tmp;
  1693. do {
  1694. tid = 'j' + t_id + '_' + (++t_cnt);
  1695. } while(m[tid]);
  1696. tmp = {
  1697. id : false,
  1698. text : typeof d === 'string' ? d : '',
  1699. icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
  1700. parent : p,
  1701. parents : ps,
  1702. children : [],
  1703. children_d : [],
  1704. data : null,
  1705. state : { },
  1706. li_attr : { id : false },
  1707. a_attr : { href : '#' },
  1708. original : false
  1709. };
  1710. for(i in df) {
  1711. if(df.hasOwnProperty(i)) {
  1712. tmp.state[i] = df[i];
  1713. }
  1714. }
  1715. if(d && d.id) { tmp.id = d.id.toString(); }
  1716. if(d && d.text) { tmp.text = d.text; }
  1717. if(d && d.data && d.data.jstree && d.data.jstree.icon) {
  1718. tmp.icon = d.data.jstree.icon;
  1719. }
  1720. if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
  1721. tmp.icon = true;
  1722. }
  1723. if(d && d.data) {
  1724. tmp.data = d.data;
  1725. if(d.data.jstree) {
  1726. for(i in d.data.jstree) {
  1727. if(d.data.jstree.hasOwnProperty(i)) {
  1728. tmp.state[i] = d.data.jstree[i];
  1729. }
  1730. }
  1731. }
  1732. }
  1733. if(d && typeof d.state === 'object') {
  1734. for (i in d.state) {
  1735. if(d.state.hasOwnProperty(i)) {
  1736. tmp.state[i] = d.state[i];
  1737. }
  1738. }
  1739. }
  1740. if(d && typeof d.li_attr === 'object') {
  1741. for (i in d.li_attr) {
  1742. if(d.li_attr.hasOwnProperty(i)) {
  1743. tmp.li_attr[i] = d.li_attr[i];
  1744. }
  1745. }
  1746. }
  1747. if(tmp.li_attr.id && !tmp.id) {
  1748. tmp.id = tmp.li_attr.id.toString();
  1749. }
  1750. if(!tmp.id) {
  1751. tmp.id = tid;
  1752. }
  1753. if(!tmp.li_attr.id) {
  1754. tmp.li_attr.id = tmp.id;
  1755. }
  1756. if(d && typeof d.a_attr === 'object') {
  1757. for (i in d.a_attr) {
  1758. if(d.a_attr.hasOwnProperty(i)) {
  1759. tmp.a_attr[i] = d.a_attr[i];
  1760. }
  1761. }
  1762. }
  1763. if(d && d.children && d.children.length) {
  1764. for(i = 0, j = d.children.length; i < j; i++) {
  1765. c = parse_nest(d.children[i], tmp.id, ps);
  1766. e = m[c];
  1767. tmp.children.push(c);
  1768. if(e.children_d.length) {
  1769. tmp.children_d = tmp.children_d.concat(e.children_d);
  1770. }
  1771. }
  1772. tmp.children_d = tmp.children_d.concat(tmp.children);
  1773. }
  1774. if(d && d.children && d.children === true) {
  1775. tmp.state.loaded = false;
  1776. tmp.children = [];
  1777. tmp.children_d = [];
  1778. }
  1779. delete d.data;
  1780. delete d.children;
  1781. tmp.original = d;
  1782. m[tmp.id] = tmp;
  1783. if(tmp.state.selected) {
  1784. add.push(tmp.id);
  1785. }
  1786. return tmp.id;
  1787. };
  1788. if(dat.length && dat[0].id !== undefined && dat[0].parent !== undefined) {
  1789. // Flat JSON support (for easy import from DB):
  1790. // 1) convert to object (foreach)
  1791. for(i = 0, j = dat.length; i < j; i++) {
  1792. if(!dat[i].children) {
  1793. dat[i].children = [];
  1794. }
  1795. if(!dat[i].state) {
  1796. dat[i].state = {};
  1797. }
  1798. m[dat[i].id.toString()] = dat[i];
  1799. }
  1800. // 2) populate children (foreach)
  1801. for(i = 0, j = dat.length; i < j; i++) {
  1802. if (!m[dat[i].parent.toString()]) {
  1803. this._data.core.last_error = { 'error' : 'parse', 'plugin' : 'core', 'id' : 'core_07', 'reason' : 'Node with invalid parent', 'data' : JSON.stringify({ 'id' : dat[i].id.toString(), 'parent' : dat[i].parent.toString() }) };
  1804. this.settings.core.error.call(this, this._data.core.last_error);
  1805. continue;
  1806. }
  1807. m[dat[i].parent.toString()].children.push(dat[i].id.toString());
  1808. // populate parent.children_d
  1809. p.children_d.push(dat[i].id.toString());
  1810. }
  1811. // 3) normalize && populate parents and children_d with recursion
  1812. for(i = 0, j = p.children.length; i < j; i++) {
  1813. tmp = parse_flat(m[p.children[i]], par, p.parents.concat());
  1814. dpc.push(tmp);
  1815. if(m[tmp].children_d.length) {
  1816. dpc = dpc.concat(m[tmp].children_d);
  1817. }
  1818. }
  1819. for(i = 0, j = p.parents.length; i < j; i++) {
  1820. m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
  1821. }
  1822. // ?) three_state selection - p.state.selected && t - (if three_state foreach(dat => ch) -> foreach(parents) if(parent.selected) child.selected = true;
  1823. rslt = {
  1824. 'cnt' : t_cnt,
  1825. 'mod' : m,
  1826. 'sel' : sel,
  1827. 'par' : par,
  1828. 'dpc' : dpc,
  1829. 'add' : add
  1830. };
  1831. }
  1832. else {
  1833. for(i = 0, j = dat.length; i < j; i++) {
  1834. tmp = parse_nest(dat[i], par, p.parents.concat());
  1835. if(tmp) {
  1836. chd.push(tmp);
  1837. dpc.push(tmp);
  1838. if(m[tmp].children_d.length) {
  1839. dpc = dpc.concat(m[tmp].children_d);
  1840. }
  1841. }
  1842. }
  1843. p.children = chd;
  1844. p.children_d = dpc;
  1845. for(i = 0, j = p.parents.length; i < j; i++) {
  1846. m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
  1847. }
  1848. rslt = {
  1849. 'cnt' : t_cnt,
  1850. 'mod' : m,
  1851. 'sel' : sel,
  1852. 'par' : par,
  1853. 'dpc' : dpc,
  1854. 'add' : add
  1855. };
  1856. }
  1857. if(typeof window === 'undefined' || typeof window.document === 'undefined') {
  1858. postMessage(rslt);
  1859. }
  1860. else {
  1861. return rslt;
  1862. }
  1863. },
  1864. rslt = function (rslt, worker) {
  1865. if(this.element === null) { return; }
  1866. this._cnt = rslt.cnt;
  1867. var i, m = this._model.data;
  1868. for (i in m) {
  1869. if (m.hasOwnProperty(i) && m[i].state && m[i].state.loading && rslt.mod[i]) {
  1870. rslt.mod[i].state.loading = true;
  1871. }
  1872. }
  1873. this._model.data = rslt.mod; // breaks the reference in load_node - careful
  1874. if(worker) {
  1875. var j, a = rslt.add, r = rslt.sel, s = this._data.core.selected.slice();
  1876. m = this._model.data;
  1877. // if selection was changed while calculating in worker
  1878. if(r.length !== s.length || $.vakata.array_unique(r.concat(s)).length !== r.length) {
  1879. // deselect nodes that are no longer selected
  1880. for(i = 0, j = r.length; i < j; i++) {
  1881. if($.inArray(r[i], a) === -1 && $.inArray(r[i], s) === -1) {
  1882. m[r[i]].state.selected = false;
  1883. }
  1884. }
  1885. // select nodes that were selected in the mean time
  1886. for(i = 0, j = s.length; i < j; i++) {
  1887. if($.inArray(s[i], r) === -1) {
  1888. m[s[i]].state.selected = true;
  1889. }
  1890. }
  1891. }
  1892. }
  1893. if(rslt.add.length) {
  1894. this._data.core.selected = this._data.core.selected.concat(rslt.add);
  1895. }
  1896. this.trigger('model', { "nodes" : rslt.dpc, 'parent' : rslt.par });
  1897. if(rslt.par !== $.jstree.root) {
  1898. this._node_changed(rslt.par);
  1899. this.redraw();
  1900. }
  1901. else {
  1902. // this.get_container_ul().children('.jstree-initial-node').remove();
  1903. this.redraw(true);
  1904. }
  1905. if(rslt.add.length) {
  1906. this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
  1907. }
  1908. cb.call(this, true);
  1909. };
  1910. if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
  1911. try {
  1912. if(this._wrk === null) {
  1913. this._wrk = window.URL.createObjectURL(
  1914. new window.Blob(
  1915. ['self.onmessage = ' + func.toString()],
  1916. {type:"text/javascript"}
  1917. )
  1918. );
  1919. }
  1920. if(!this._data.core.working || force_processing) {
  1921. this._data.core.working = true;
  1922. w = new window.Worker(this._wrk);
  1923. w.onmessage = $.proxy(function (e) {
  1924. rslt.call(this, e.data, true);
  1925. try { w.terminate(); w = null; } catch(ignore) { }
  1926. if(this._data.core.worker_queue.length) {
  1927. this._append_json_data.apply(this, this._data.core.worker_queue.shift());
  1928. }
  1929. else {
  1930. this._data.core.working = false;
  1931. }
  1932. }, this);
  1933. if(!args.par) {
  1934. if(this._data.core.worker_queue.length) {
  1935. this._append_json_data.apply(this, this._data.core.worker_queue.shift());
  1936. }
  1937. else {
  1938. this._data.core.working = false;
  1939. }
  1940. }
  1941. else {
  1942. w.postMessage(args);
  1943. }
  1944. }
  1945. else {
  1946. this._data.core.worker_queue.push([dom, data, cb, true]);
  1947. }
  1948. }
  1949. catch(e) {
  1950. rslt.call(this, func(args), false);
  1951. if(this._data.core.worker_queue.length) {
  1952. this._append_json_data.apply(this, this._data.core.worker_queue.shift());
  1953. }
  1954. else {
  1955. this._data.core.working = false;
  1956. }
  1957. }
  1958. }
  1959. else {
  1960. rslt.call(this, func(args), false);
  1961. }
  1962. },
  1963. /**
  1964. * parses a node from a jQuery object and appends them to the in memory tree model. Used internally.
  1965. * @private
  1966. * @name _parse_model_from_html(d [, p, ps])
  1967. * @param {jQuery} d the jQuery object to parse
  1968. * @param {String} p the parent ID
  1969. * @param {Array} ps list of all parents
  1970. * @return {String} the ID of the object added to the model
  1971. */
  1972. _parse_model_from_html : function (d, p, ps) {
  1973. if(!ps) { ps = []; }
  1974. else { ps = [].concat(ps); }
  1975. if(p) { ps.unshift(p); }
  1976. var c, e, m = this._model.data,
  1977. data = {
  1978. id : false,
  1979. text : false,
  1980. icon : true,
  1981. parent : p,
  1982. parents : ps,
  1983. children : [],
  1984. children_d : [],
  1985. data : null,
  1986. state : { },
  1987. li_attr : { id : false },
  1988. a_attr : { href : '#' },
  1989. original : false
  1990. }, i, tmp, tid;
  1991. for(i in this._model.default_state) {
  1992. if(this._model.default_state.hasOwnProperty(i)) {
  1993. data.state[i] = this._model.default_state[i];
  1994. }
  1995. }
  1996. tmp = $.vakata.attributes(d, true);
  1997. $.each(tmp, function (i, v) {
  1998. v = $.trim(v);
  1999. if(!v.length) { return true; }
  2000. data.li_attr[i] = v;
  2001. if(i === 'id') {
  2002. data.id = v.toString();
  2003. }
  2004. });
  2005. tmp = d.children('a').first();
  2006. if(tmp.length) {
  2007. tmp = $.vakata.attributes(tmp, true);
  2008. $.each(tmp, function (i, v) {
  2009. v = $.trim(v);
  2010. if(v.length) {
  2011. data.a_attr[i] = v;
  2012. }
  2013. });
  2014. }
  2015. tmp = d.children("a").first().length ? d.children("a").first().clone() : d.clone();
  2016. tmp.children("ins, i, ul").remove();
  2017. tmp = tmp.html();
  2018. tmp = $('<div />').html(tmp);
  2019. data.text = this.settings.core.force_text ? tmp.text() : tmp.html();
  2020. tmp = d.data();
  2021. data.data = tmp ? $.extend(true, {}, tmp) : null;
  2022. data.state.opened = d.hasClass('jstree-open');
  2023. data.state.selected = d.children('a').hasClass('jstree-clicked');
  2024. data.state.disabled = d.children('a').hasClass('jstree-disabled');
  2025. if(data.data && data.data.jstree) {
  2026. for(i in data.data.jstree) {
  2027. if(data.data.jstree.hasOwnProperty(i)) {
  2028. data.state[i] = data.data.jstree[i];
  2029. }
  2030. }
  2031. }
  2032. tmp = d.children("a").children(".jstree-themeicon");
  2033. if(tmp.length) {
  2034. data.icon = tmp.hasClass('jstree-themeicon-hidden') ? false : tmp.attr('rel');
  2035. }
  2036. if(data.state.icon !== undefined) {
  2037. data.icon = data.state.icon;
  2038. }
  2039. if(data.icon === undefined || data.icon === null || data.icon === "") {
  2040. data.icon = true;
  2041. }
  2042. tmp = d.children("ul").children("li");
  2043. do {
  2044. tid = 'j' + this._id + '_' + (++this._cnt);
  2045. } while(m[tid]);
  2046. data.id = data.li_attr.id ? data.li_attr.id.toString() : tid;
  2047. if(tmp.length) {
  2048. tmp.each($.proxy(function (i, v) {
  2049. c = this._parse_model_from_html($(v), data.id, ps);
  2050. e = this._model.data[c];
  2051. data.children.push(c);
  2052. if(e.children_d.length) {
  2053. data.children_d = data.children_d.concat(e.children_d);
  2054. }
  2055. }, this));
  2056. data.children_d = data.children_d.concat(data.children);
  2057. }
  2058. else {
  2059. if(d.hasClass('jstree-closed')) {
  2060. data.state.loaded = false;
  2061. }
  2062. }
  2063. if(data.li_attr['class']) {
  2064. data.li_attr['class'] = data.li_attr['class'].replace('jstree-closed','').replace('jstree-open','');
  2065. }
  2066. if(data.a_attr['class']) {
  2067. data.a_attr['class'] = data.a_attr['class'].replace('jstree-clicked','').replace('jstree-disabled','');
  2068. }
  2069. m[data.id] = data;
  2070. if(data.state.selected) {
  2071. this._data.core.selected.push(data.id);
  2072. }
  2073. return data.id;
  2074. },
  2075. /**
  2076. * parses a node from a JSON object (used when dealing with flat data, which has no nesting of children, but has id and parent properties) and appends it to the in memory tree model. Used internally.
  2077. * @private
  2078. * @name _parse_model_from_flat_json(d [, p, ps])
  2079. * @param {Object} d the JSON object to parse
  2080. * @param {String} p the parent ID
  2081. * @param {Array} ps list of all parents
  2082. * @return {String} the ID of the object added to the model
  2083. */
  2084. _parse_model_from_flat_json : function (d, p, ps) {
  2085. if(!ps) { ps = []; }
  2086. else { ps = ps.concat(); }
  2087. if(p) { ps.unshift(p); }
  2088. var tid = d.id.toString(),
  2089. m = this._model.data,
  2090. df = this._model.default_state,
  2091. i, j, c, e,
  2092. tmp = {
  2093. id : tid,
  2094. text : d.text || '',
  2095. icon : d.icon !== undefined ? d.icon : true,
  2096. parent : p,
  2097. parents : ps,
  2098. children : d.children || [],
  2099. children_d : d.children_d || [],
  2100. data : d.data,
  2101. state : { },
  2102. li_attr : { id : false },
  2103. a_attr : { href : '#' },
  2104. original : false
  2105. };
  2106. for(i in df) {
  2107. if(df.hasOwnProperty(i)) {
  2108. tmp.state[i] = df[i];
  2109. }
  2110. }
  2111. if(d && d.data && d.data.jstree && d.data.jstree.icon) {
  2112. tmp.icon = d.data.jstree.icon;
  2113. }
  2114. if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
  2115. tmp.icon = true;
  2116. }
  2117. if(d && d.data) {
  2118. tmp.data = d.data;
  2119. if(d.data.jstree) {
  2120. for(i in d.data.jstree) {
  2121. if(d.data.jstree.hasOwnProperty(i)) {
  2122. tmp.state[i] = d.data.jstree[i];
  2123. }
  2124. }
  2125. }
  2126. }
  2127. if(d && typeof d.state === 'object') {
  2128. for (i in d.state) {
  2129. if(d.state.hasOwnProperty(i)) {
  2130. tmp.state[i] = d.state[i];
  2131. }
  2132. }
  2133. }
  2134. if(d && typeof d.li_attr === 'object') {
  2135. for (i in d.li_attr) {
  2136. if(d.li_attr.hasOwnProperty(i)) {
  2137. tmp.li_attr[i] = d.li_attr[i];
  2138. }
  2139. }
  2140. }
  2141. if(!tmp.li_attr.id) {
  2142. tmp.li_attr.id = tid;
  2143. }
  2144. if(d && typeof d.a_attr === 'object') {
  2145. for (i in d.a_attr) {
  2146. if(d.a_attr.hasOwnProperty(i)) {
  2147. tmp.a_attr[i] = d.a_attr[i];
  2148. }
  2149. }
  2150. }
  2151. if(d && d.children && d.children === true) {
  2152. tmp.state.loaded = false;
  2153. tmp.children = [];
  2154. tmp.children_d = [];
  2155. }
  2156. m[tmp.id] = tmp;
  2157. for(i = 0, j = tmp.children.length; i < j; i++) {
  2158. c = this._parse_model_from_flat_json(m[tmp.children[i]], tmp.id, ps);
  2159. e = m[c];
  2160. tmp.children_d.push(c);
  2161. if(e.children_d.length) {
  2162. tmp.children_d = tmp.children_d.concat(e.children_d);
  2163. }
  2164. }
  2165. delete d.data;
  2166. delete d.children;
  2167. m[tmp.id].original = d;
  2168. if(tmp.state.selected) {
  2169. this._data.core.selected.push(tmp.id);
  2170. }
  2171. return tmp.id;
  2172. },
  2173. /**
  2174. * parses a node from a JSON object and appends it to the in memory tree model. Used internally.
  2175. * @private
  2176. * @name _parse_model_from_json(d [, p, ps])
  2177. * @param {Object} d the JSON object to parse
  2178. * @param {String} p the parent ID
  2179. * @param {Array} ps list of all parents
  2180. * @return {String} the ID of the object added to the model
  2181. */
  2182. _parse_model_from_json : function (d, p, ps) {
  2183. if(!ps) { ps = []; }
  2184. else { ps = ps.concat(); }
  2185. if(p) { ps.unshift(p); }
  2186. var tid = false, i, j, c, e, m = this._model.data, df = this._model.default_state, tmp;
  2187. do {
  2188. tid = 'j' + this._id + '_' + (++this._cnt);
  2189. } while(m[tid]);
  2190. tmp = {
  2191. id : false,
  2192. text : typeof d === 'string' ? d : '',
  2193. icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
  2194. parent : p,
  2195. parents : ps,
  2196. children : [],
  2197. children_d : [],
  2198. data : null,
  2199. state : { },
  2200. li_attr : { id : false },
  2201. a_attr : { href : '#' },
  2202. original : false
  2203. };
  2204. for(i in df) {
  2205. if(df.hasOwnProperty(i)) {
  2206. tmp.state[i] = df[i];
  2207. }
  2208. }
  2209. if(d && d.id) { tmp.id = d.id.toString(); }
  2210. if(d && d.text) { tmp.text = d.text; }
  2211. if(d && d.data && d.data.jstree && d.data.jstree.icon) {
  2212. tmp.icon = d.data.jstree.icon;
  2213. }
  2214. if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
  2215. tmp.icon = true;
  2216. }
  2217. if(d && d.data) {
  2218. tmp.data = d.data;
  2219. if(d.data.jstree) {
  2220. for(i in d.data.jstree) {
  2221. if(d.data.jstree.hasOwnProperty(i)) {
  2222. tmp.state[i] = d.data.jstree[i];
  2223. }
  2224. }
  2225. }
  2226. }
  2227. if(d && typeof d.state === 'object') {
  2228. for (i in d.state) {
  2229. if(d.state.hasOwnProperty(i)) {
  2230. tmp.state[i] = d.state[i];
  2231. }
  2232. }
  2233. }
  2234. if(d && typeof d.li_attr === 'object') {
  2235. for (i in d.li_attr) {
  2236. if(d.li_attr.hasOwnProperty(i)) {
  2237. tmp.li_attr[i] = d.li_attr[i];
  2238. }
  2239. }
  2240. }
  2241. if(tmp.li_attr.id && !tmp.id) {
  2242. tmp.id = tmp.li_attr.id.toString();
  2243. }
  2244. if(!tmp.id) {
  2245. tmp.id = tid;
  2246. }
  2247. if(!tmp.li_attr.id) {
  2248. tmp.li_attr.id = tmp.id;
  2249. }
  2250. if(d && typeof d.a_attr === 'object') {
  2251. for (i in d.a_attr) {
  2252. if(d.a_attr.hasOwnProperty(i)) {
  2253. tmp.a_attr[i] = d.a_attr[i];
  2254. }
  2255. }
  2256. }
  2257. if(d && d.children && d.children.length) {
  2258. for(i = 0, j = d.children.length; i < j; i++) {
  2259. c = this._parse_model_from_json(d.children[i], tmp.id, ps);
  2260. e = m[c];
  2261. tmp.children.push(c);
  2262. if(e.children_d.length) {
  2263. tmp.children_d = tmp.children_d.concat(e.children_d);
  2264. }
  2265. }
  2266. tmp.children_d = tmp.children_d.concat(tmp.children);
  2267. }
  2268. if(d && d.children && d.children === true) {
  2269. tmp.state.loaded = false;
  2270. tmp.children = [];
  2271. tmp.children_d = [];
  2272. }
  2273. delete d.data;
  2274. delete d.children;
  2275. tmp.original = d;
  2276. m[tmp.id] = tmp;
  2277. if(tmp.state.selected) {
  2278. this._data.core.selected.push(tmp.id);
  2279. }
  2280. return tmp.id;
  2281. },
  2282. /**
  2283. * redraws all nodes that need to be redrawn. Used internally.
  2284. * @private
  2285. * @name _redraw()
  2286. * @trigger redraw.jstree
  2287. */
  2288. _redraw : function () {
  2289. var nodes = this._model.force_full_redraw ? this._model.data[$.jstree.root].children.concat([]) : this._model.changed.concat([]),
  2290. f = document.createElement('UL'), tmp, i, j, fe = this._data.core.focused;
  2291. for(i = 0, j = nodes.length; i < j; i++) {
  2292. tmp = this.redraw_node(nodes[i], true, this._model.force_full_redraw);
  2293. if(tmp && this._model.force_full_redraw) {
  2294. f.appendChild(tmp);
  2295. }
  2296. }
  2297. if(this._model.force_full_redraw) {
  2298. f.className = this.get_container_ul()[0].className;
  2299. f.setAttribute('role','group');
  2300. this.element.empty().append(f);
  2301. //this.get_container_ul()[0].appendChild(f);
  2302. }
  2303. if(fe !== null) {
  2304. tmp = this.get_node(fe, true);
  2305. if(tmp && tmp.length && tmp.children('.jstree-anchor')[0] !== document.activeElement) {
  2306. tmp.children('.jstree-anchor').focus();
  2307. }
  2308. else {
  2309. this._data.core.focused = null;
  2310. }
  2311. }
  2312. this._model.force_full_redraw = false;
  2313. this._model.changed = [];
  2314. /**
  2315. * triggered after nodes are redrawn
  2316. * @event
  2317. * @name redraw.jstree
  2318. * @param {array} nodes the redrawn nodes
  2319. */
  2320. this.trigger('redraw', { "nodes" : nodes });
  2321. },
  2322. /**
  2323. * redraws all nodes that need to be redrawn or optionally - the whole tree
  2324. * @name redraw([full])
  2325. * @param {Boolean} full if set to `true` all nodes are redrawn.
  2326. */
  2327. redraw : function (full) {
  2328. if(full) {
  2329. this._model.force_full_redraw = true;
  2330. }
  2331. //if(this._model.redraw_timeout) {
  2332. // clearTimeout(this._model.redraw_timeout);
  2333. //}
  2334. //this._model.redraw_timeout = setTimeout($.proxy(this._redraw, this),0);
  2335. this._redraw();
  2336. },
  2337. /**
  2338. * redraws a single node's children. Used internally.
  2339. * @private
  2340. * @name draw_children(node)
  2341. * @param {mixed} node the node whose children will be redrawn
  2342. */
  2343. draw_children : function (node) {
  2344. var obj = this.get_node(node),
  2345. i = false,
  2346. j = false,
  2347. k = false,
  2348. d = document;
  2349. if(!obj) { return false; }
  2350. if(obj.id === $.jstree.root) { return this.redraw(true); }
  2351. node = this.get_node(node, true);
  2352. if(!node || !node.length) { return false; } // TODO: quick toggle
  2353. node.children('.jstree-children').remove();
  2354. node = node[0];
  2355. if(obj.children.length && obj.state.loaded) {
  2356. k = d.createElement('UL');
  2357. k.setAttribute('role', 'group');
  2358. k.className = 'jstree-children';
  2359. for(i = 0, j = obj.children.length; i < j; i++) {
  2360. k.appendChild(this.redraw_node(obj.children[i], true, true));
  2361. }
  2362. node.appendChild(k);
  2363. }
  2364. },
  2365. /**
  2366. * redraws a single node. Used internally.
  2367. * @private
  2368. * @name redraw_node(node, deep, is_callback, force_render)
  2369. * @param {mixed} node the node to redraw
  2370. * @param {Boolean} deep should child nodes be redrawn too
  2371. * @param {Boolean} is_callback is this a recursion call
  2372. * @param {Boolean} force_render should children of closed parents be drawn anyway
  2373. */
  2374. redraw_node : function (node, deep, is_callback, force_render) {
  2375. var obj = this.get_node(node),
  2376. par = false,
  2377. ind = false,
  2378. old = false,
  2379. i = false,
  2380. j = false,
  2381. k = false,
  2382. c = '',
  2383. d = document,
  2384. m = this._model.data,
  2385. f = false,
  2386. s = false,
  2387. tmp = null,
  2388. t = 0,
  2389. l = 0,
  2390. has_children = false,
  2391. last_sibling = false;
  2392. if(!obj) { return false; }
  2393. if(obj.id === $.jstree.root) { return this.redraw(true); }
  2394. deep = deep || obj.children.length === 0;
  2395. node = !document.querySelector ? document.getElementById(obj.id) : this.element[0].querySelector('#' + ("0123456789".indexOf(obj.id[0]) !== -1 ? '\\3' + obj.id[0] + ' ' + obj.id.substr(1).replace($.jstree.idregex,'\\$&') : obj.id.replace($.jstree.idregex,'\\$&')) ); //, this.element);
  2396. if(!node) {
  2397. deep = true;
  2398. //node = d.createElement('LI');
  2399. if(!is_callback) {
  2400. par = obj.parent !== $.jstree.root ? $('#' + obj.parent.replace($.jstree.idregex,'\\$&'), this.element)[0] : null;
  2401. if(par !== null && (!par || !m[obj.parent].state.opened)) {
  2402. return false;
  2403. }
  2404. ind = $.inArray(obj.id, par === null ? m[$.jstree.root].children : m[obj.parent].children);
  2405. }
  2406. }
  2407. else {
  2408. node = $(node);
  2409. if(!is_callback) {
  2410. par = node.parent().parent()[0];
  2411. if(par === this.element[0]) {
  2412. par = null;
  2413. }
  2414. ind = node.index();
  2415. }
  2416. // m[obj.id].data = node.data(); // use only node's data, no need to touch jquery storage
  2417. if(!deep && obj.children.length && !node.children('.jstree-children').length) {
  2418. deep = true;
  2419. }
  2420. if(!deep) {
  2421. old = node.children('.jstree-children')[0];
  2422. }
  2423. f = node.children('.jstree-anchor')[0] === document.activeElement;
  2424. node.remove();
  2425. //node = d.createElement('LI');
  2426. //node = node[0];
  2427. }
  2428. node = this._data.core.node.cloneNode(true);
  2429. // node is DOM, deep is boolean
  2430. c = 'jstree-node ';
  2431. for(i in obj.li_attr) {
  2432. if(obj.li_attr.hasOwnProperty(i)) {
  2433. if(i === 'id') { continue; }
  2434. if(i !== 'class') {
  2435. node.setAttribute(i, obj.li_attr[i]);
  2436. }
  2437. else {
  2438. c += obj.li_attr[i];
  2439. }
  2440. }
  2441. }
  2442. if(!obj.a_attr.id) {
  2443. obj.a_attr.id = obj.id + '_anchor';
  2444. }
  2445. node.setAttribute('aria-selected', !!obj.state.selected);
  2446. node.setAttribute('aria-level', obj.parents.length);
  2447. node.setAttribute('aria-labelledby', obj.a_attr.id);
  2448. if(obj.state.disabled) {
  2449. node.setAttribute('aria-disabled', true);
  2450. }
  2451. for(i = 0, j = obj.children.length; i < j; i++) {
  2452. if(!m[obj.children[i]].state.hidden) {
  2453. has_children = true;
  2454. break;
  2455. }
  2456. }
  2457. if(obj.parent !== null && m[obj.parent] && !obj.state.hidden) {
  2458. i = $.inArray(obj.id, m[obj.parent].children);
  2459. last_sibling = obj.id;
  2460. if(i !== -1) {
  2461. i++;
  2462. for(j = m[obj.parent].children.length; i < j; i++) {
  2463. if(!m[m[obj.parent].children[i]].state.hidden) {
  2464. last_sibling = m[obj.parent].children[i];
  2465. }
  2466. if(last_sibling !== obj.id) {
  2467. break;
  2468. }
  2469. }
  2470. }
  2471. }
  2472. if(obj.state.hidden) {
  2473. c += ' jstree-hidden';
  2474. }
  2475. if (obj.state.loading) {
  2476. c += ' jstree-loading';
  2477. }
  2478. if(obj.state.loaded && !has_children) {
  2479. c += ' jstree-leaf';
  2480. }
  2481. else {
  2482. c += obj.state.opened && obj.state.loaded ? ' jstree-open' : ' jstree-closed';
  2483. node.setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
  2484. }
  2485. if(last_sibling === obj.id) {
  2486. c += ' jstree-last';
  2487. }
  2488. node.id = obj.id;
  2489. node.className = c;
  2490. c = ( obj.state.selected ? ' jstree-clicked' : '') + ( obj.state.disabled ? ' jstree-disabled' : '');
  2491. for(j in obj.a_attr) {
  2492. if(obj.a_attr.hasOwnProperty(j)) {
  2493. if(j === 'href' && obj.a_attr[j] === '#') { continue; }
  2494. if(j !== 'class') {
  2495. node.childNodes[1].setAttribute(j, obj.a_attr[j]);
  2496. }
  2497. else {
  2498. c += ' ' + obj.a_attr[j];
  2499. }
  2500. }
  2501. }
  2502. if(c.length) {
  2503. node.childNodes[1].className = 'jstree-anchor ' + c;
  2504. }
  2505. if((obj.icon && obj.icon !== true) || obj.icon === false) {
  2506. if(obj.icon === false) {
  2507. node.childNodes[1].childNodes[0].className += ' jstree-themeicon-hidden';
  2508. }
  2509. else if(obj.icon.indexOf('/') === -1 && obj.icon.indexOf('.') === -1) {
  2510. node.childNodes[1].childNodes[0].className += ' ' + obj.icon + ' jstree-themeicon-custom';
  2511. }
  2512. else {
  2513. node.childNodes[1].childNodes[0].style.backgroundImage = 'url("'+obj.icon+'")';
  2514. node.childNodes[1].childNodes[0].style.backgroundPosition = 'center center';
  2515. node.childNodes[1].childNodes[0].style.backgroundSize = 'auto';
  2516. node.childNodes[1].childNodes[0].className += ' jstree-themeicon-custom';
  2517. }
  2518. }
  2519. if(this.settings.core.force_text) {
  2520. node.childNodes[1].appendChild(d.createTextNode(obj.text));
  2521. }
  2522. else {
  2523. node.childNodes[1].innerHTML += obj.text;
  2524. }
  2525. if(deep && obj.children.length && (obj.state.opened || force_render) && obj.state.loaded) {
  2526. k = d.createElement('UL');
  2527. k.setAttribute('role', 'group');
  2528. k.className = 'jstree-children';
  2529. for(i = 0, j = obj.children.length; i < j; i++) {
  2530. k.appendChild(this.redraw_node(obj.children[i], deep, true));
  2531. }
  2532. node.appendChild(k);
  2533. }
  2534. if(old) {
  2535. node.appendChild(old);
  2536. }
  2537. if(!is_callback) {
  2538. // append back using par / ind
  2539. if(!par) {
  2540. par = this.element[0];
  2541. }
  2542. for(i = 0, j = par.childNodes.length; i < j; i++) {
  2543. if(par.childNodes[i] && par.childNodes[i].className && par.childNodes[i].className.indexOf('jstree-children') !== -1) {
  2544. tmp = par.childNodes[i];
  2545. break;
  2546. }
  2547. }
  2548. if(!tmp) {
  2549. tmp = d.createElement('UL');
  2550. tmp.setAttribute('role', 'group');
  2551. tmp.className = 'jstree-children';
  2552. par.appendChild(tmp);
  2553. }
  2554. par = tmp;
  2555. if(ind < par.childNodes.length) {
  2556. par.insertBefore(node, par.childNodes[ind]);
  2557. }
  2558. else {
  2559. par.appendChild(node);
  2560. }
  2561. if(f) {
  2562. t = this.element[0].scrollTop;
  2563. l = this.element[0].scrollLeft;
  2564. node.childNodes[1].focus();
  2565. this.element[0].scrollTop = t;
  2566. this.element[0].scrollLeft = l;
  2567. }
  2568. }
  2569. if(obj.state.opened && !obj.state.loaded) {
  2570. obj.state.opened = false;
  2571. setTimeout($.proxy(function () {
  2572. this.open_node(obj.id, false, 0);
  2573. }, this), 0);
  2574. }
  2575. return node;
  2576. },
  2577. /**
  2578. * opens a node, revaling its children. If the node is not loaded it will be loaded and opened once ready.
  2579. * @name open_node(obj [, callback, animation])
  2580. * @param {mixed} obj the node to open
  2581. * @param {Function} callback a function to execute once the node is opened
  2582. * @param {Number} animation the animation duration in milliseconds when opening the node (overrides the `core.animation` setting). Use `false` for no animation.
  2583. * @trigger open_node.jstree, after_open.jstree, before_open.jstree
  2584. */
  2585. open_node : function (obj, callback, animation) {
  2586. var t1, t2, d, t;
  2587. if($.isArray(obj)) {
  2588. obj = obj.slice();
  2589. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2590. this.open_node(obj[t1], callback, animation);
  2591. }
  2592. return true;
  2593. }
  2594. obj = this.get_node(obj);
  2595. if(!obj || obj.id === $.jstree.root) {
  2596. return false;
  2597. }
  2598. animation = animation === undefined ? this.settings.core.animation : animation;
  2599. if(!this.is_closed(obj)) {
  2600. if(callback) {
  2601. callback.call(this, obj, false);
  2602. }
  2603. return false;
  2604. }
  2605. if(!this.is_loaded(obj)) {
  2606. if(this.is_loading(obj)) {
  2607. return setTimeout($.proxy(function () {
  2608. this.open_node(obj, callback, animation);
  2609. }, this), 500);
  2610. }
  2611. this.load_node(obj, function (o, ok) {
  2612. return ok ? this.open_node(o, callback, animation) : (callback ? callback.call(this, o, false) : false);
  2613. });
  2614. }
  2615. else {
  2616. d = this.get_node(obj, true);
  2617. t = this;
  2618. if(d.length) {
  2619. if(animation && d.children(".jstree-children").length) {
  2620. d.children(".jstree-children").stop(true, true);
  2621. }
  2622. if(obj.children.length && !this._firstChild(d.children('.jstree-children')[0])) {
  2623. this.draw_children(obj);
  2624. //d = this.get_node(obj, true);
  2625. }
  2626. if(!animation) {
  2627. this.trigger('before_open', { "node" : obj });
  2628. d[0].className = d[0].className.replace('jstree-closed', 'jstree-open');
  2629. d[0].setAttribute("aria-expanded", true);
  2630. }
  2631. else {
  2632. this.trigger('before_open', { "node" : obj });
  2633. d
  2634. .children(".jstree-children").css("display","none").end()
  2635. .removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded", true)
  2636. .children(".jstree-children").stop(true, true)
  2637. .slideDown(animation, function () {
  2638. this.style.display = "";
  2639. if (t.element) {
  2640. t.trigger("after_open", { "node" : obj });
  2641. }
  2642. });
  2643. }
  2644. }
  2645. obj.state.opened = true;
  2646. if(callback) {
  2647. callback.call(this, obj, true);
  2648. }
  2649. if(!d.length) {
  2650. /**
  2651. * triggered when a node is about to be opened (if the node is supposed to be in the DOM, it will be, but it won't be visible yet)
  2652. * @event
  2653. * @name before_open.jstree
  2654. * @param {Object} node the opened node
  2655. */
  2656. this.trigger('before_open', { "node" : obj });
  2657. }
  2658. /**
  2659. * triggered when a node is opened (if there is an animation it will not be completed yet)
  2660. * @event
  2661. * @name open_node.jstree
  2662. * @param {Object} node the opened node
  2663. */
  2664. this.trigger('open_node', { "node" : obj });
  2665. if(!animation || !d.length) {
  2666. /**
  2667. * triggered when a node is opened and the animation is complete
  2668. * @event
  2669. * @name after_open.jstree
  2670. * @param {Object} node the opened node
  2671. */
  2672. this.trigger("after_open", { "node" : obj });
  2673. }
  2674. return true;
  2675. }
  2676. },
  2677. /**
  2678. * opens every parent of a node (node should be loaded)
  2679. * @name _open_to(obj)
  2680. * @param {mixed} obj the node to reveal
  2681. * @private
  2682. */
  2683. _open_to : function (obj) {
  2684. obj = this.get_node(obj);
  2685. if(!obj || obj.id === $.jstree.root) {
  2686. return false;
  2687. }
  2688. var i, j, p = obj.parents;
  2689. for(i = 0, j = p.length; i < j; i+=1) {
  2690. if(i !== $.jstree.root) {
  2691. this.open_node(p[i], false, 0);
  2692. }
  2693. }
  2694. return $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
  2695. },
  2696. /**
  2697. * closes a node, hiding its children
  2698. * @name close_node(obj [, animation])
  2699. * @param {mixed} obj the node to close
  2700. * @param {Number} animation the animation duration in milliseconds when closing the node (overrides the `core.animation` setting). Use `false` for no animation.
  2701. * @trigger close_node.jstree, after_close.jstree
  2702. */
  2703. close_node : function (obj, animation) {
  2704. var t1, t2, t, d;
  2705. if($.isArray(obj)) {
  2706. obj = obj.slice();
  2707. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2708. this.close_node(obj[t1], animation);
  2709. }
  2710. return true;
  2711. }
  2712. obj = this.get_node(obj);
  2713. if(!obj || obj.id === $.jstree.root) {
  2714. return false;
  2715. }
  2716. if(this.is_closed(obj)) {
  2717. return false;
  2718. }
  2719. animation = animation === undefined ? this.settings.core.animation : animation;
  2720. t = this;
  2721. d = this.get_node(obj, true);
  2722. obj.state.opened = false;
  2723. /**
  2724. * triggered when a node is closed (if there is an animation it will not be complete yet)
  2725. * @event
  2726. * @name close_node.jstree
  2727. * @param {Object} node the closed node
  2728. */
  2729. this.trigger('close_node',{ "node" : obj });
  2730. if(!d.length) {
  2731. /**
  2732. * triggered when a node is closed and the animation is complete
  2733. * @event
  2734. * @name after_close.jstree
  2735. * @param {Object} node the closed node
  2736. */
  2737. this.trigger("after_close", { "node" : obj });
  2738. }
  2739. else {
  2740. if(!animation) {
  2741. d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
  2742. d.attr("aria-expanded", false).children('.jstree-children').remove();
  2743. this.trigger("after_close", { "node" : obj });
  2744. }
  2745. else {
  2746. d
  2747. .children(".jstree-children").attr("style","display:block !important").end()
  2748. .removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded", false)
  2749. .children(".jstree-children").stop(true, true).slideUp(animation, function () {
  2750. this.style.display = "";
  2751. d.children('.jstree-children').remove();
  2752. if (t.element) {
  2753. t.trigger("after_close", { "node" : obj });
  2754. }
  2755. });
  2756. }
  2757. }
  2758. },
  2759. /**
  2760. * toggles a node - closing it if it is open, opening it if it is closed
  2761. * @name toggle_node(obj)
  2762. * @param {mixed} obj the node to toggle
  2763. */
  2764. toggle_node : function (obj) {
  2765. var t1, t2;
  2766. if($.isArray(obj)) {
  2767. obj = obj.slice();
  2768. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2769. this.toggle_node(obj[t1]);
  2770. }
  2771. return true;
  2772. }
  2773. if(this.is_closed(obj)) {
  2774. return this.open_node(obj);
  2775. }
  2776. if(this.is_open(obj)) {
  2777. return this.close_node(obj);
  2778. }
  2779. },
  2780. /**
  2781. * opens all nodes within a node (or the tree), revaling their children. If the node is not loaded it will be loaded and opened once ready.
  2782. * @name open_all([obj, animation, original_obj])
  2783. * @param {mixed} obj the node to open recursively, omit to open all nodes in the tree
  2784. * @param {Number} animation the animation duration in milliseconds when opening the nodes, the default is no animation
  2785. * @param {jQuery} reference to the node that started the process (internal use)
  2786. * @trigger open_all.jstree
  2787. */
  2788. open_all : function (obj, animation, original_obj) {
  2789. if(!obj) { obj = $.jstree.root; }
  2790. obj = this.get_node(obj);
  2791. if(!obj) { return false; }
  2792. var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true), i, j, _this;
  2793. if(!dom.length) {
  2794. for(i = 0, j = obj.children_d.length; i < j; i++) {
  2795. if(this.is_closed(this._model.data[obj.children_d[i]])) {
  2796. this._model.data[obj.children_d[i]].state.opened = true;
  2797. }
  2798. }
  2799. return this.trigger('open_all', { "node" : obj });
  2800. }
  2801. original_obj = original_obj || dom;
  2802. _this = this;
  2803. dom = this.is_closed(obj) ? dom.find('.jstree-closed').addBack() : dom.find('.jstree-closed');
  2804. dom.each(function () {
  2805. _this.open_node(
  2806. this,
  2807. function(node, status) { if(status && this.is_parent(node)) { this.open_all(node, animation, original_obj); } },
  2808. animation || 0
  2809. );
  2810. });
  2811. if(original_obj.find('.jstree-closed').length === 0) {
  2812. /**
  2813. * triggered when an `open_all` call completes
  2814. * @event
  2815. * @name open_all.jstree
  2816. * @param {Object} node the opened node
  2817. */
  2818. this.trigger('open_all', { "node" : this.get_node(original_obj) });
  2819. }
  2820. },
  2821. /**
  2822. * closes all nodes within a node (or the tree), revaling their children
  2823. * @name close_all([obj, animation])
  2824. * @param {mixed} obj the node to close recursively, omit to close all nodes in the tree
  2825. * @param {Number} animation the animation duration in milliseconds when closing the nodes, the default is no animation
  2826. * @trigger close_all.jstree
  2827. */
  2828. close_all : function (obj, animation) {
  2829. if(!obj) { obj = $.jstree.root; }
  2830. obj = this.get_node(obj);
  2831. if(!obj) { return false; }
  2832. var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true),
  2833. _this = this, i, j;
  2834. if(dom.length) {
  2835. dom = this.is_open(obj) ? dom.find('.jstree-open').addBack() : dom.find('.jstree-open');
  2836. $(dom.get().reverse()).each(function () { _this.close_node(this, animation || 0); });
  2837. }
  2838. for(i = 0, j = obj.children_d.length; i < j; i++) {
  2839. this._model.data[obj.children_d[i]].state.opened = false;
  2840. }
  2841. /**
  2842. * triggered when an `close_all` call completes
  2843. * @event
  2844. * @name close_all.jstree
  2845. * @param {Object} node the closed node
  2846. */
  2847. this.trigger('close_all', { "node" : obj });
  2848. },
  2849. /**
  2850. * checks if a node is disabled (not selectable)
  2851. * @name is_disabled(obj)
  2852. * @param {mixed} obj
  2853. * @return {Boolean}
  2854. */
  2855. is_disabled : function (obj) {
  2856. obj = this.get_node(obj);
  2857. return obj && obj.state && obj.state.disabled;
  2858. },
  2859. /**
  2860. * enables a node - so that it can be selected
  2861. * @name enable_node(obj)
  2862. * @param {mixed} obj the node to enable
  2863. * @trigger enable_node.jstree
  2864. */
  2865. enable_node : function (obj) {
  2866. var t1, t2;
  2867. if($.isArray(obj)) {
  2868. obj = obj.slice();
  2869. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2870. this.enable_node(obj[t1]);
  2871. }
  2872. return true;
  2873. }
  2874. obj = this.get_node(obj);
  2875. if(!obj || obj.id === $.jstree.root) {
  2876. return false;
  2877. }
  2878. obj.state.disabled = false;
  2879. this.get_node(obj,true).children('.jstree-anchor').removeClass('jstree-disabled').attr('aria-disabled', false);
  2880. /**
  2881. * triggered when an node is enabled
  2882. * @event
  2883. * @name enable_node.jstree
  2884. * @param {Object} node the enabled node
  2885. */
  2886. this.trigger('enable_node', { 'node' : obj });
  2887. },
  2888. /**
  2889. * disables a node - so that it can not be selected
  2890. * @name disable_node(obj)
  2891. * @param {mixed} obj the node to disable
  2892. * @trigger disable_node.jstree
  2893. */
  2894. disable_node : function (obj) {
  2895. var t1, t2;
  2896. if($.isArray(obj)) {
  2897. obj = obj.slice();
  2898. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2899. this.disable_node(obj[t1]);
  2900. }
  2901. return true;
  2902. }
  2903. obj = this.get_node(obj);
  2904. if(!obj || obj.id === $.jstree.root) {
  2905. return false;
  2906. }
  2907. obj.state.disabled = true;
  2908. this.get_node(obj,true).children('.jstree-anchor').addClass('jstree-disabled').attr('aria-disabled', true);
  2909. /**
  2910. * triggered when an node is disabled
  2911. * @event
  2912. * @name disable_node.jstree
  2913. * @param {Object} node the disabled node
  2914. */
  2915. this.trigger('disable_node', { 'node' : obj });
  2916. },
  2917. /**
  2918. * determines if a node is hidden
  2919. * @name is_hidden(obj)
  2920. * @param {mixed} obj the node
  2921. */
  2922. is_hidden : function (obj) {
  2923. obj = this.get_node(obj);
  2924. return obj.state.hidden === true;
  2925. },
  2926. /**
  2927. * hides a node - it is still in the structure but will not be visible
  2928. * @name hide_node(obj)
  2929. * @param {mixed} obj the node to hide
  2930. * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
  2931. * @trigger hide_node.jstree
  2932. */
  2933. hide_node : function (obj, skip_redraw) {
  2934. var t1, t2;
  2935. if($.isArray(obj)) {
  2936. obj = obj.slice();
  2937. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2938. this.hide_node(obj[t1], true);
  2939. }
  2940. if (!skip_redraw) {
  2941. this.redraw();
  2942. }
  2943. return true;
  2944. }
  2945. obj = this.get_node(obj);
  2946. if(!obj || obj.id === $.jstree.root) {
  2947. return false;
  2948. }
  2949. if(!obj.state.hidden) {
  2950. obj.state.hidden = true;
  2951. this._node_changed(obj.parent);
  2952. if(!skip_redraw) {
  2953. this.redraw();
  2954. }
  2955. /**
  2956. * triggered when an node is hidden
  2957. * @event
  2958. * @name hide_node.jstree
  2959. * @param {Object} node the hidden node
  2960. */
  2961. this.trigger('hide_node', { 'node' : obj });
  2962. }
  2963. },
  2964. /**
  2965. * shows a node
  2966. * @name show_node(obj)
  2967. * @param {mixed} obj the node to show
  2968. * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
  2969. * @trigger show_node.jstree
  2970. */
  2971. show_node : function (obj, skip_redraw) {
  2972. var t1, t2;
  2973. if($.isArray(obj)) {
  2974. obj = obj.slice();
  2975. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2976. this.show_node(obj[t1], true);
  2977. }
  2978. if (!skip_redraw) {
  2979. this.redraw();
  2980. }
  2981. return true;
  2982. }
  2983. obj = this.get_node(obj);
  2984. if(!obj || obj.id === $.jstree.root) {
  2985. return false;
  2986. }
  2987. if(obj.state.hidden) {
  2988. obj.state.hidden = false;
  2989. this._node_changed(obj.parent);
  2990. if(!skip_redraw) {
  2991. this.redraw();
  2992. }
  2993. /**
  2994. * triggered when an node is shown
  2995. * @event
  2996. * @name show_node.jstree
  2997. * @param {Object} node the shown node
  2998. */
  2999. this.trigger('show_node', { 'node' : obj });
  3000. }
  3001. },
  3002. /**
  3003. * hides all nodes
  3004. * @name hide_all()
  3005. * @trigger hide_all.jstree
  3006. */
  3007. hide_all : function (skip_redraw) {
  3008. var i, m = this._model.data, ids = [];
  3009. for(i in m) {
  3010. if(m.hasOwnProperty(i) && i !== $.jstree.root && !m[i].state.hidden) {
  3011. m[i].state.hidden = true;
  3012. ids.push(i);
  3013. }
  3014. }
  3015. this._model.force_full_redraw = true;
  3016. if(!skip_redraw) {
  3017. this.redraw();
  3018. }
  3019. /**
  3020. * triggered when all nodes are hidden
  3021. * @event
  3022. * @name hide_all.jstree
  3023. * @param {Array} nodes the IDs of all hidden nodes
  3024. */
  3025. this.trigger('hide_all', { 'nodes' : ids });
  3026. return ids;
  3027. },
  3028. /**
  3029. * shows all nodes
  3030. * @name show_all()
  3031. * @trigger show_all.jstree
  3032. */
  3033. show_all : function (skip_redraw) {
  3034. var i, m = this._model.data, ids = [];
  3035. for(i in m) {
  3036. if(m.hasOwnProperty(i) && i !== $.jstree.root && m[i].state.hidden) {
  3037. m[i].state.hidden = false;
  3038. ids.push(i);
  3039. }
  3040. }
  3041. this._model.force_full_redraw = true;
  3042. if(!skip_redraw) {
  3043. this.redraw();
  3044. }
  3045. /**
  3046. * triggered when all nodes are shown
  3047. * @event
  3048. * @name show_all.jstree
  3049. * @param {Array} nodes the IDs of all shown nodes
  3050. */
  3051. this.trigger('show_all', { 'nodes' : ids });
  3052. return ids;
  3053. },
  3054. /**
  3055. * called when a node is selected by the user. Used internally.
  3056. * @private
  3057. * @name activate_node(obj, e)
  3058. * @param {mixed} obj the node
  3059. * @param {Object} e the related event
  3060. * @trigger activate_node.jstree, changed.jstree
  3061. */
  3062. activate_node : function (obj, e) {
  3063. if(this.is_disabled(obj)) {
  3064. return false;
  3065. }
  3066. if(!e || typeof e !== 'object') {
  3067. e = {};
  3068. }
  3069. // ensure last_clicked is still in the DOM, make it fresh (maybe it was moved?) and make sure it is still selected, if not - make last_clicked the last selected node
  3070. this._data.core.last_clicked = this._data.core.last_clicked && this._data.core.last_clicked.id !== undefined ? this.get_node(this._data.core.last_clicked.id) : null;
  3071. if(this._data.core.last_clicked && !this._data.core.last_clicked.state.selected) { this._data.core.last_clicked = null; }
  3072. if(!this._data.core.last_clicked && this._data.core.selected.length) { this._data.core.last_clicked = this.get_node(this._data.core.selected[this._data.core.selected.length - 1]); }
  3073. if(!this.settings.core.multiple || (!e.metaKey && !e.ctrlKey && !e.shiftKey) || (e.shiftKey && (!this._data.core.last_clicked || !this.get_parent(obj) || this.get_parent(obj) !== this._data.core.last_clicked.parent ) )) {
  3074. if(!this.settings.core.multiple && (e.metaKey || e.ctrlKey || e.shiftKey) && this.is_selected(obj)) {
  3075. this.deselect_node(obj, false, e);
  3076. }
  3077. else {
  3078. this.deselect_all(true);
  3079. this.select_node(obj, false, false, e);
  3080. this._data.core.last_clicked = this.get_node(obj);
  3081. }
  3082. }
  3083. else {
  3084. if(e.shiftKey) {
  3085. var o = this.get_node(obj).id,
  3086. l = this._data.core.last_clicked.id,
  3087. p = this.get_node(this._data.core.last_clicked.parent).children,
  3088. c = false,
  3089. i, j;
  3090. for(i = 0, j = p.length; i < j; i += 1) {
  3091. // separate IFs work whem o and l are the same
  3092. if(p[i] === o) {
  3093. c = !c;
  3094. }
  3095. if(p[i] === l) {
  3096. c = !c;
  3097. }
  3098. if(!this.is_disabled(p[i]) && (c || p[i] === o || p[i] === l)) {
  3099. if (!this.is_hidden(p[i])) {
  3100. this.select_node(p[i], true, false, e);
  3101. }
  3102. }
  3103. else {
  3104. this.deselect_node(p[i], true, e);
  3105. }
  3106. }
  3107. this.trigger('changed', { 'action' : 'select_node', 'node' : this.get_node(obj), 'selected' : this._data.core.selected, 'event' : e });
  3108. }
  3109. else {
  3110. if(!this.is_selected(obj)) {
  3111. this.select_node(obj, false, false, e);
  3112. }
  3113. else {
  3114. this.deselect_node(obj, false, e);
  3115. }
  3116. }
  3117. }
  3118. /**
  3119. * triggered when an node is clicked or intercated with by the user
  3120. * @event
  3121. * @name activate_node.jstree
  3122. * @param {Object} node
  3123. * @param {Object} event the ooriginal event (if any) which triggered the call (may be an empty object)
  3124. */
  3125. this.trigger('activate_node', { 'node' : this.get_node(obj), 'event' : e });
  3126. },
  3127. /**
  3128. * applies the hover state on a node, called when a node is hovered by the user. Used internally.
  3129. * @private
  3130. * @name hover_node(obj)
  3131. * @param {mixed} obj
  3132. * @trigger hover_node.jstree
  3133. */
  3134. hover_node : function (obj) {
  3135. obj = this.get_node(obj, true);
  3136. if(!obj || !obj.length || obj.children('.jstree-hovered').length) {
  3137. return false;
  3138. }
  3139. var o = this.element.find('.jstree-hovered'), t = this.element;
  3140. if(o && o.length) { this.dehover_node(o); }
  3141. obj.children('.jstree-anchor').addClass('jstree-hovered');
  3142. /**
  3143. * triggered when an node is hovered
  3144. * @event
  3145. * @name hover_node.jstree
  3146. * @param {Object} node
  3147. */
  3148. this.trigger('hover_node', { 'node' : this.get_node(obj) });
  3149. setTimeout(function () { t.attr('aria-activedescendant', obj[0].id); }, 0);
  3150. },
  3151. /**
  3152. * removes the hover state from a nodecalled when a node is no longer hovered by the user. Used internally.
  3153. * @private
  3154. * @name dehover_node(obj)
  3155. * @param {mixed} obj
  3156. * @trigger dehover_node.jstree
  3157. */
  3158. dehover_node : function (obj) {
  3159. obj = this.get_node(obj, true);
  3160. if(!obj || !obj.length || !obj.children('.jstree-hovered').length) {
  3161. return false;
  3162. }
  3163. obj.children('.jstree-anchor').removeClass('jstree-hovered');
  3164. /**
  3165. * triggered when an node is no longer hovered
  3166. * @event
  3167. * @name dehover_node.jstree
  3168. * @param {Object} node
  3169. */
  3170. this.trigger('dehover_node', { 'node' : this.get_node(obj) });
  3171. },
  3172. /**
  3173. * select a node
  3174. * @name select_node(obj [, supress_event, prevent_open])
  3175. * @param {mixed} obj an array can be used to select multiple nodes
  3176. * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
  3177. * @param {Boolean} prevent_open if set to `true` parents of the selected node won't be opened
  3178. * @trigger select_node.jstree, changed.jstree
  3179. */
  3180. select_node : function (obj, supress_event, prevent_open, e) {
  3181. var dom, t1, t2, th;
  3182. if($.isArray(obj)) {
  3183. obj = obj.slice();
  3184. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3185. this.select_node(obj[t1], supress_event, prevent_open, e);
  3186. }
  3187. return true;
  3188. }
  3189. obj = this.get_node(obj);
  3190. if(!obj || obj.id === $.jstree.root) {
  3191. return false;
  3192. }
  3193. dom = this.get_node(obj, true);
  3194. if(!obj.state.selected) {
  3195. obj.state.selected = true;
  3196. this._data.core.selected.push(obj.id);
  3197. if(!prevent_open) {
  3198. dom = this._open_to(obj);
  3199. }
  3200. if(dom && dom.length) {
  3201. dom.attr('aria-selected', true).children('.jstree-anchor').addClass('jstree-clicked');
  3202. }
  3203. /**
  3204. * triggered when an node is selected
  3205. * @event
  3206. * @name select_node.jstree
  3207. * @param {Object} node
  3208. * @param {Array} selected the current selection
  3209. * @param {Object} event the event (if any) that triggered this select_node
  3210. */
  3211. this.trigger('select_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
  3212. if(!supress_event) {
  3213. /**
  3214. * triggered when selection changes
  3215. * @event
  3216. * @name changed.jstree
  3217. * @param {Object} node
  3218. * @param {Object} action the action that caused the selection to change
  3219. * @param {Array} selected the current selection
  3220. * @param {Object} event the event (if any) that triggered this changed event
  3221. */
  3222. this.trigger('changed', { 'action' : 'select_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
  3223. }
  3224. }
  3225. },
  3226. /**
  3227. * deselect a node
  3228. * @name deselect_node(obj [, supress_event])
  3229. * @param {mixed} obj an array can be used to deselect multiple nodes
  3230. * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
  3231. * @trigger deselect_node.jstree, changed.jstree
  3232. */
  3233. deselect_node : function (obj, supress_event, e) {
  3234. var t1, t2, dom;
  3235. if($.isArray(obj)) {
  3236. obj = obj.slice();
  3237. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3238. this.deselect_node(obj[t1], supress_event, e);
  3239. }
  3240. return true;
  3241. }
  3242. obj = this.get_node(obj);
  3243. if(!obj || obj.id === $.jstree.root) {
  3244. return false;
  3245. }
  3246. dom = this.get_node(obj, true);
  3247. if(obj.state.selected) {
  3248. obj.state.selected = false;
  3249. this._data.core.selected = $.vakata.array_remove_item(this._data.core.selected, obj.id);
  3250. if(dom.length) {
  3251. dom.attr('aria-selected', false).children('.jstree-anchor').removeClass('jstree-clicked');
  3252. }
  3253. /**
  3254. * triggered when an node is deselected
  3255. * @event
  3256. * @name deselect_node.jstree
  3257. * @param {Object} node
  3258. * @param {Array} selected the current selection
  3259. * @param {Object} event the event (if any) that triggered this deselect_node
  3260. */
  3261. this.trigger('deselect_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
  3262. if(!supress_event) {
  3263. this.trigger('changed', { 'action' : 'deselect_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
  3264. }
  3265. }
  3266. },
  3267. /**
  3268. * select all nodes in the tree
  3269. * @name select_all([supress_event])
  3270. * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
  3271. * @trigger select_all.jstree, changed.jstree
  3272. */
  3273. select_all : function (supress_event) {
  3274. var tmp = this._data.core.selected.concat([]), i, j;
  3275. this._data.core.selected = this._model.data[$.jstree.root].children_d.concat();
  3276. for(i = 0, j = this._data.core.selected.length; i < j; i++) {
  3277. if(this._model.data[this._data.core.selected[i]]) {
  3278. this._model.data[this._data.core.selected[i]].state.selected = true;
  3279. }
  3280. }
  3281. this.redraw(true);
  3282. /**
  3283. * triggered when all nodes are selected
  3284. * @event
  3285. * @name select_all.jstree
  3286. * @param {Array} selected the current selection
  3287. */
  3288. this.trigger('select_all', { 'selected' : this._data.core.selected });
  3289. if(!supress_event) {
  3290. this.trigger('changed', { 'action' : 'select_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
  3291. }
  3292. },
  3293. /**
  3294. * deselect all selected nodes
  3295. * @name deselect_all([supress_event])
  3296. * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
  3297. * @trigger deselect_all.jstree, changed.jstree
  3298. */
  3299. deselect_all : function (supress_event) {
  3300. var tmp = this._data.core.selected.concat([]), i, j;
  3301. for(i = 0, j = this._data.core.selected.length; i < j; i++) {
  3302. if(this._model.data[this._data.core.selected[i]]) {
  3303. this._model.data[this._data.core.selected[i]].state.selected = false;
  3304. }
  3305. }
  3306. this._data.core.selected = [];
  3307. this.element.find('.jstree-clicked').removeClass('jstree-clicked').parent().attr('aria-selected', false);
  3308. /**
  3309. * triggered when all nodes are deselected
  3310. * @event
  3311. * @name deselect_all.jstree
  3312. * @param {Object} node the previous selection
  3313. * @param {Array} selected the current selection
  3314. */
  3315. this.trigger('deselect_all', { 'selected' : this._data.core.selected, 'node' : tmp });
  3316. if(!supress_event) {
  3317. this.trigger('changed', { 'action' : 'deselect_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
  3318. }
  3319. },
  3320. /**
  3321. * checks if a node is selected
  3322. * @name is_selected(obj)
  3323. * @param {mixed} obj
  3324. * @return {Boolean}
  3325. */
  3326. is_selected : function (obj) {
  3327. obj = this.get_node(obj);
  3328. if(!obj || obj.id === $.jstree.root) {
  3329. return false;
  3330. }
  3331. return obj.state.selected;
  3332. },
  3333. /**
  3334. * get an array of all selected nodes
  3335. * @name get_selected([full])
  3336. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  3337. * @return {Array}
  3338. */
  3339. get_selected : function (full) {
  3340. return full ? $.map(this._data.core.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.core.selected.slice();
  3341. },
  3342. /**
  3343. * get an array of all top level selected nodes (ignoring children of selected nodes)
  3344. * @name get_top_selected([full])
  3345. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  3346. * @return {Array}
  3347. */
  3348. get_top_selected : function (full) {
  3349. var tmp = this.get_selected(true),
  3350. obj = {}, i, j, k, l;
  3351. for(i = 0, j = tmp.length; i < j; i++) {
  3352. obj[tmp[i].id] = tmp[i];
  3353. }
  3354. for(i = 0, j = tmp.length; i < j; i++) {
  3355. for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
  3356. if(obj[tmp[i].children_d[k]]) {
  3357. delete obj[tmp[i].children_d[k]];
  3358. }
  3359. }
  3360. }
  3361. tmp = [];
  3362. for(i in obj) {
  3363. if(obj.hasOwnProperty(i)) {
  3364. tmp.push(i);
  3365. }
  3366. }
  3367. return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
  3368. },
  3369. /**
  3370. * get an array of all bottom level selected nodes (ignoring selected parents)
  3371. * @name get_bottom_selected([full])
  3372. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  3373. * @return {Array}
  3374. */
  3375. get_bottom_selected : function (full) {
  3376. var tmp = this.get_selected(true),
  3377. obj = [], i, j;
  3378. for(i = 0, j = tmp.length; i < j; i++) {
  3379. if(!tmp[i].children.length) {
  3380. obj.push(tmp[i].id);
  3381. }
  3382. }
  3383. return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
  3384. },
  3385. /**
  3386. * gets the current state of the tree so that it can be restored later with `set_state(state)`. Used internally.
  3387. * @name get_state()
  3388. * @private
  3389. * @return {Object}
  3390. */
  3391. get_state : function () {
  3392. var state = {
  3393. 'core' : {
  3394. 'open' : [],
  3395. 'loaded' : [],
  3396. 'scroll' : {
  3397. 'left' : this.element.scrollLeft(),
  3398. 'top' : this.element.scrollTop()
  3399. },
  3400. /*!
  3401. 'themes' : {
  3402. 'name' : this.get_theme(),
  3403. 'icons' : this._data.core.themes.icons,
  3404. 'dots' : this._data.core.themes.dots
  3405. },
  3406. */
  3407. 'selected' : []
  3408. }
  3409. }, i;
  3410. for(i in this._model.data) {
  3411. if(this._model.data.hasOwnProperty(i)) {
  3412. if(i !== $.jstree.root) {
  3413. if(this._model.data[i].state.loaded && this.settings.core.loaded_state) {
  3414. state.core.loaded.push(i);
  3415. }
  3416. if(this._model.data[i].state.opened) {
  3417. state.core.open.push(i);
  3418. }
  3419. if(this._model.data[i].state.selected) {
  3420. state.core.selected.push(i);
  3421. }
  3422. }
  3423. }
  3424. }
  3425. return state;
  3426. },
  3427. /**
  3428. * sets the state of the tree. Used internally.
  3429. * @name set_state(state [, callback])
  3430. * @private
  3431. * @param {Object} state the state to restore. Keep in mind this object is passed by reference and jstree will modify it.
  3432. * @param {Function} callback an optional function to execute once the state is restored.
  3433. * @trigger set_state.jstree
  3434. */
  3435. set_state : function (state, callback) {
  3436. if(state) {
  3437. if(state.core && state.core.selected && state.core.initial_selection === undefined) {
  3438. state.core.initial_selection = this._data.core.selected.concat([]).sort().join(',');
  3439. }
  3440. if(state.core) {
  3441. var res, n, t, _this, i;
  3442. if(state.core.loaded) {
  3443. if(!this.settings.core.loaded_state || !$.isArray(state.core.loaded) || !state.core.loaded.length) {
  3444. delete state.core.loaded;
  3445. this.set_state(state, callback);
  3446. }
  3447. else {
  3448. this._load_nodes(state.core.loaded, function (nodes) {
  3449. delete state.core.loaded;
  3450. this.set_state(state, callback);
  3451. });
  3452. }
  3453. return false;
  3454. }
  3455. if(state.core.open) {
  3456. if(!$.isArray(state.core.open) || !state.core.open.length) {
  3457. delete state.core.open;
  3458. this.set_state(state, callback);
  3459. }
  3460. else {
  3461. this._load_nodes(state.core.open, function (nodes) {
  3462. this.open_node(nodes, false, 0);
  3463. delete state.core.open;
  3464. this.set_state(state, callback);
  3465. });
  3466. }
  3467. return false;
  3468. }
  3469. if(state.core.scroll) {
  3470. if(state.core.scroll && state.core.scroll.left !== undefined) {
  3471. this.element.scrollLeft(state.core.scroll.left);
  3472. }
  3473. if(state.core.scroll && state.core.scroll.top !== undefined) {
  3474. this.element.scrollTop(state.core.scroll.top);
  3475. }
  3476. delete state.core.scroll;
  3477. this.set_state(state, callback);
  3478. return false;
  3479. }
  3480. if(state.core.selected) {
  3481. _this = this;
  3482. if (state.core.initial_selection === undefined ||
  3483. state.core.initial_selection === this._data.core.selected.concat([]).sort().join(',')
  3484. ) {
  3485. this.deselect_all();
  3486. $.each(state.core.selected, function (i, v) {
  3487. _this.select_node(v, false, true);
  3488. });
  3489. }
  3490. delete state.core.initial_selection;
  3491. delete state.core.selected;
  3492. this.set_state(state, callback);
  3493. return false;
  3494. }
  3495. for(i in state) {
  3496. if(state.hasOwnProperty(i) && i !== "core" && $.inArray(i, this.settings.plugins) === -1) {
  3497. delete state[i];
  3498. }
  3499. }
  3500. if($.isEmptyObject(state.core)) {
  3501. delete state.core;
  3502. this.set_state(state, callback);
  3503. return false;
  3504. }
  3505. }
  3506. if($.isEmptyObject(state)) {
  3507. state = null;
  3508. if(callback) { callback.call(this); }
  3509. /**
  3510. * triggered when a `set_state` call completes
  3511. * @event
  3512. * @name set_state.jstree
  3513. */
  3514. this.trigger('set_state');
  3515. return false;
  3516. }
  3517. return true;
  3518. }
  3519. return false;
  3520. },
  3521. /**
  3522. * refreshes the tree - all nodes are reloaded with calls to `load_node`.
  3523. * @name refresh()
  3524. * @param {Boolean} skip_loading an option to skip showing the loading indicator
  3525. * @param {Mixed} forget_state if set to `true` state will not be reapplied, if set to a function (receiving the current state as argument) the result of that function will be used as state
  3526. * @trigger refresh.jstree
  3527. */
  3528. refresh : function (skip_loading, forget_state) {
  3529. this._data.core.state = forget_state === true ? {} : this.get_state();
  3530. if(forget_state && $.isFunction(forget_state)) { this._data.core.state = forget_state.call(this, this._data.core.state); }
  3531. this._cnt = 0;
  3532. this._model.data = {};
  3533. this._model.data[$.jstree.root] = {
  3534. id : $.jstree.root,
  3535. parent : null,
  3536. parents : [],
  3537. children : [],
  3538. children_d : [],
  3539. state : { loaded : false }
  3540. };
  3541. this._data.core.selected = [];
  3542. this._data.core.last_clicked = null;
  3543. this._data.core.focused = null;
  3544. var c = this.get_container_ul()[0].className;
  3545. if(!skip_loading) {
  3546. this.element.html("<"+"ul class='"+c+"' role='group'><"+"li class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='treeitem' id='j"+this._id+"_loading'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
  3547. this.element.attr('aria-activedescendant','j'+this._id+'_loading');
  3548. }
  3549. this.load_node($.jstree.root, function (o, s) {
  3550. if(s) {
  3551. this.get_container_ul()[0].className = c;
  3552. if(this._firstChild(this.get_container_ul()[0])) {
  3553. this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
  3554. }
  3555. this.set_state($.extend(true, {}, this._data.core.state), function () {
  3556. /**
  3557. * triggered when a `refresh` call completes
  3558. * @event
  3559. * @name refresh.jstree
  3560. */
  3561. this.trigger('refresh');
  3562. });
  3563. }
  3564. this._data.core.state = null;
  3565. });
  3566. },
  3567. /**
  3568. * refreshes a node in the tree (reload its children) all opened nodes inside that node are reloaded with calls to `load_node`.
  3569. * @name refresh_node(obj)
  3570. * @param {mixed} obj the node
  3571. * @trigger refresh_node.jstree
  3572. */
  3573. refresh_node : function (obj) {
  3574. obj = this.get_node(obj);
  3575. if(!obj || obj.id === $.jstree.root) { return false; }
  3576. var opened = [], to_load = [], s = this._data.core.selected.concat([]);
  3577. to_load.push(obj.id);
  3578. if(obj.state.opened === true) { opened.push(obj.id); }
  3579. this.get_node(obj, true).find('.jstree-open').each(function() { to_load.push(this.id); opened.push(this.id); });
  3580. this._load_nodes(to_load, $.proxy(function (nodes) {
  3581. this.open_node(opened, false, 0);
  3582. this.select_node(s);
  3583. /**
  3584. * triggered when a node is refreshed
  3585. * @event
  3586. * @name refresh_node.jstree
  3587. * @param {Object} node - the refreshed node
  3588. * @param {Array} nodes - an array of the IDs of the nodes that were reloaded
  3589. */
  3590. this.trigger('refresh_node', { 'node' : obj, 'nodes' : nodes });
  3591. }, this), false, true);
  3592. },
  3593. /**
  3594. * set (change) the ID of a node
  3595. * @name set_id(obj, id)
  3596. * @param {mixed} obj the node
  3597. * @param {String} id the new ID
  3598. * @return {Boolean}
  3599. * @trigger set_id.jstree
  3600. */
  3601. set_id : function (obj, id) {
  3602. obj = this.get_node(obj);
  3603. if(!obj || obj.id === $.jstree.root) { return false; }
  3604. var i, j, m = this._model.data, old = obj.id;
  3605. id = id.toString();
  3606. // update parents (replace current ID with new one in children and children_d)
  3607. m[obj.parent].children[$.inArray(obj.id, m[obj.parent].children)] = id;
  3608. for(i = 0, j = obj.parents.length; i < j; i++) {
  3609. m[obj.parents[i]].children_d[$.inArray(obj.id, m[obj.parents[i]].children_d)] = id;
  3610. }
  3611. // update children (replace current ID with new one in parent and parents)
  3612. for(i = 0, j = obj.children.length; i < j; i++) {
  3613. m[obj.children[i]].parent = id;
  3614. }
  3615. for(i = 0, j = obj.children_d.length; i < j; i++) {
  3616. m[obj.children_d[i]].parents[$.inArray(obj.id, m[obj.children_d[i]].parents)] = id;
  3617. }
  3618. i = $.inArray(obj.id, this._data.core.selected);
  3619. if(i !== -1) { this._data.core.selected[i] = id; }
  3620. // update model and obj itself (obj.id, this._model.data[KEY])
  3621. i = this.get_node(obj.id, true);
  3622. if(i) {
  3623. i.attr('id', id); //.children('.jstree-anchor').attr('id', id + '_anchor').end().attr('aria-labelledby', id + '_anchor');
  3624. if(this.element.attr('aria-activedescendant') === obj.id) {
  3625. this.element.attr('aria-activedescendant', id);
  3626. }
  3627. }
  3628. delete m[obj.id];
  3629. obj.id = id;
  3630. obj.li_attr.id = id;
  3631. m[id] = obj;
  3632. /**
  3633. * triggered when a node id value is changed
  3634. * @event
  3635. * @name set_id.jstree
  3636. * @param {Object} node
  3637. * @param {String} old the old id
  3638. */
  3639. this.trigger('set_id',{ "node" : obj, "new" : obj.id, "old" : old });
  3640. return true;
  3641. },
  3642. /**
  3643. * get the text value of a node
  3644. * @name get_text(obj)
  3645. * @param {mixed} obj the node
  3646. * @return {String}
  3647. */
  3648. get_text : function (obj) {
  3649. obj = this.get_node(obj);
  3650. return (!obj || obj.id === $.jstree.root) ? false : obj.text;
  3651. },
  3652. /**
  3653. * set the text value of a node. Used internally, please use `rename_node(obj, val)`.
  3654. * @private
  3655. * @name set_text(obj, val)
  3656. * @param {mixed} obj the node, you can pass an array to set the text on multiple nodes
  3657. * @param {String} val the new text value
  3658. * @return {Boolean}
  3659. * @trigger set_text.jstree
  3660. */
  3661. set_text : function (obj, val) {
  3662. var t1, t2;
  3663. if($.isArray(obj)) {
  3664. obj = obj.slice();
  3665. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3666. this.set_text(obj[t1], val);
  3667. }
  3668. return true;
  3669. }
  3670. obj = this.get_node(obj);
  3671. if(!obj || obj.id === $.jstree.root) { return false; }
  3672. obj.text = val;
  3673. if(this.get_node(obj, true).length) {
  3674. this.redraw_node(obj.id);
  3675. }
  3676. /**
  3677. * triggered when a node text value is changed
  3678. * @event
  3679. * @name set_text.jstree
  3680. * @param {Object} obj
  3681. * @param {String} text the new value
  3682. */
  3683. this.trigger('set_text',{ "obj" : obj, "text" : val });
  3684. return true;
  3685. },
  3686. /**
  3687. * gets a JSON representation of a node (or the whole tree)
  3688. * @name get_json([obj, options])
  3689. * @param {mixed} obj
  3690. * @param {Object} options
  3691. * @param {Boolean} options.no_state do not return state information
  3692. * @param {Boolean} options.no_id do not return ID
  3693. * @param {Boolean} options.no_children do not include children
  3694. * @param {Boolean} options.no_data do not include node data
  3695. * @param {Boolean} options.no_li_attr do not include LI attributes
  3696. * @param {Boolean} options.no_a_attr do not include A attributes
  3697. * @param {Boolean} options.flat return flat JSON instead of nested
  3698. * @return {Object}
  3699. */
  3700. get_json : function (obj, options, flat) {
  3701. obj = this.get_node(obj || $.jstree.root);
  3702. if(!obj) { return false; }
  3703. if(options && options.flat && !flat) { flat = []; }
  3704. var tmp = {
  3705. 'id' : obj.id,
  3706. 'text' : obj.text,
  3707. 'icon' : this.get_icon(obj),
  3708. 'li_attr' : $.extend(true, {}, obj.li_attr),
  3709. 'a_attr' : $.extend(true, {}, obj.a_attr),
  3710. 'state' : {},
  3711. 'data' : options && options.no_data ? false : $.extend(true, $.isArray(obj.data)?[]:{}, obj.data)
  3712. //( this.get_node(obj, true).length ? this.get_node(obj, true).data() : obj.data ),
  3713. }, i, j;
  3714. if(options && options.flat) {
  3715. tmp.parent = obj.parent;
  3716. }
  3717. else {
  3718. tmp.children = [];
  3719. }
  3720. if(!options || !options.no_state) {
  3721. for(i in obj.state) {
  3722. if(obj.state.hasOwnProperty(i)) {
  3723. tmp.state[i] = obj.state[i];
  3724. }
  3725. }
  3726. } else {
  3727. delete tmp.state;
  3728. }
  3729. if(options && options.no_li_attr) {
  3730. delete tmp.li_attr;
  3731. }
  3732. if(options && options.no_a_attr) {
  3733. delete tmp.a_attr;
  3734. }
  3735. if(options && options.no_id) {
  3736. delete tmp.id;
  3737. if(tmp.li_attr && tmp.li_attr.id) {
  3738. delete tmp.li_attr.id;
  3739. }
  3740. if(tmp.a_attr && tmp.a_attr.id) {
  3741. delete tmp.a_attr.id;
  3742. }
  3743. }
  3744. if(options && options.flat && obj.id !== $.jstree.root) {
  3745. flat.push(tmp);
  3746. }
  3747. if(!options || !options.no_children) {
  3748. for(i = 0, j = obj.children.length; i < j; i++) {
  3749. if(options && options.flat) {
  3750. this.get_json(obj.children[i], options, flat);
  3751. }
  3752. else {
  3753. tmp.children.push(this.get_json(obj.children[i], options));
  3754. }
  3755. }
  3756. }
  3757. return options && options.flat ? flat : (obj.id === $.jstree.root ? tmp.children : tmp);
  3758. },
  3759. /**
  3760. * create a new node (do not confuse with load_node)
  3761. * @name create_node([par, node, pos, callback, is_loaded])
  3762. * @param {mixed} par the parent node (to create a root node use either "#" (string) or `null`)
  3763. * @param {mixed} node the data for the new node (a valid JSON object, or a simple string with the name)
  3764. * @param {mixed} pos the index at which to insert the node, "first" and "last" are also supported, default is "last"
  3765. * @param {Function} callback a function to be called once the node is created
  3766. * @param {Boolean} is_loaded internal argument indicating if the parent node was succesfully loaded
  3767. * @return {String} the ID of the newly create node
  3768. * @trigger model.jstree, create_node.jstree
  3769. */
  3770. create_node : function (par, node, pos, callback, is_loaded) {
  3771. if(par === null) { par = $.jstree.root; }
  3772. par = this.get_node(par);
  3773. if(!par) { return false; }
  3774. pos = pos === undefined ? "last" : pos;
  3775. if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
  3776. return this.load_node(par, function () { this.create_node(par, node, pos, callback, true); });
  3777. }
  3778. if(!node) { node = { "text" : this.get_string('New node') }; }
  3779. if(typeof node === "string") {
  3780. node = { "text" : node };
  3781. } else {
  3782. node = $.extend(true, {}, node);
  3783. }
  3784. if(node.text === undefined) { node.text = this.get_string('New node'); }
  3785. var tmp, dpc, i, j;
  3786. if(par.id === $.jstree.root) {
  3787. if(pos === "before") { pos = "first"; }
  3788. if(pos === "after") { pos = "last"; }
  3789. }
  3790. switch(pos) {
  3791. case "before":
  3792. tmp = this.get_node(par.parent);
  3793. pos = $.inArray(par.id, tmp.children);
  3794. par = tmp;
  3795. break;
  3796. case "after" :
  3797. tmp = this.get_node(par.parent);
  3798. pos = $.inArray(par.id, tmp.children) + 1;
  3799. par = tmp;
  3800. break;
  3801. case "inside":
  3802. case "first":
  3803. pos = 0;
  3804. break;
  3805. case "last":
  3806. pos = par.children.length;
  3807. break;
  3808. default:
  3809. if(!pos) { pos = 0; }
  3810. break;
  3811. }
  3812. if(pos > par.children.length) { pos = par.children.length; }
  3813. if(!node.id) { node.id = true; }
  3814. if(!this.check("create_node", node, par, pos)) {
  3815. this.settings.core.error.call(this, this._data.core.last_error);
  3816. return false;
  3817. }
  3818. if(node.id === true) { delete node.id; }
  3819. node = this._parse_model_from_json(node, par.id, par.parents.concat());
  3820. if(!node) { return false; }
  3821. tmp = this.get_node(node);
  3822. dpc = [];
  3823. dpc.push(node);
  3824. dpc = dpc.concat(tmp.children_d);
  3825. this.trigger('model', { "nodes" : dpc, "parent" : par.id });
  3826. par.children_d = par.children_d.concat(dpc);
  3827. for(i = 0, j = par.parents.length; i < j; i++) {
  3828. this._model.data[par.parents[i]].children_d = this._model.data[par.parents[i]].children_d.concat(dpc);
  3829. }
  3830. node = tmp;
  3831. tmp = [];
  3832. for(i = 0, j = par.children.length; i < j; i++) {
  3833. tmp[i >= pos ? i+1 : i] = par.children[i];
  3834. }
  3835. tmp[pos] = node.id;
  3836. par.children = tmp;
  3837. this.redraw_node(par, true);
  3838. /**
  3839. * triggered when a node is created
  3840. * @event
  3841. * @name create_node.jstree
  3842. * @param {Object} node
  3843. * @param {String} parent the parent's ID
  3844. * @param {Number} position the position of the new node among the parent's children
  3845. */
  3846. this.trigger('create_node', { "node" : this.get_node(node), "parent" : par.id, "position" : pos });
  3847. if(callback) { callback.call(this, this.get_node(node)); }
  3848. return node.id;
  3849. },
  3850. /**
  3851. * set the text value of a node
  3852. * @name rename_node(obj, val)
  3853. * @param {mixed} obj the node, you can pass an array to rename multiple nodes to the same name
  3854. * @param {String} val the new text value
  3855. * @return {Boolean}
  3856. * @trigger rename_node.jstree
  3857. */
  3858. rename_node : function (obj, val) {
  3859. var t1, t2, old;
  3860. if($.isArray(obj)) {
  3861. obj = obj.slice();
  3862. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3863. this.rename_node(obj[t1], val);
  3864. }
  3865. return true;
  3866. }
  3867. obj = this.get_node(obj);
  3868. if(!obj || obj.id === $.jstree.root) { return false; }
  3869. old = obj.text;
  3870. if(!this.check("rename_node", obj, this.get_parent(obj), val)) {
  3871. this.settings.core.error.call(this, this._data.core.last_error);
  3872. return false;
  3873. }
  3874. this.set_text(obj, val); // .apply(this, Array.prototype.slice.call(arguments))
  3875. /**
  3876. * triggered when a node is renamed
  3877. * @event
  3878. * @name rename_node.jstree
  3879. * @param {Object} node
  3880. * @param {String} text the new value
  3881. * @param {String} old the old value
  3882. */
  3883. this.trigger('rename_node', { "node" : obj, "text" : val, "old" : old });
  3884. return true;
  3885. },
  3886. /**
  3887. * remove a node
  3888. * @name delete_node(obj)
  3889. * @param {mixed} obj the node, you can pass an array to delete multiple nodes
  3890. * @return {Boolean}
  3891. * @trigger delete_node.jstree, changed.jstree
  3892. */
  3893. delete_node : function (obj) {
  3894. var t1, t2, par, pos, tmp, i, j, k, l, c, top, lft;
  3895. if($.isArray(obj)) {
  3896. obj = obj.slice();
  3897. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3898. this.delete_node(obj[t1]);
  3899. }
  3900. return true;
  3901. }
  3902. obj = this.get_node(obj);
  3903. if(!obj || obj.id === $.jstree.root) { return false; }
  3904. par = this.get_node(obj.parent);
  3905. pos = $.inArray(obj.id, par.children);
  3906. c = false;
  3907. if(!this.check("delete_node", obj, par, pos)) {
  3908. this.settings.core.error.call(this, this._data.core.last_error);
  3909. return false;
  3910. }
  3911. if(pos !== -1) {
  3912. par.children = $.vakata.array_remove(par.children, pos);
  3913. }
  3914. tmp = obj.children_d.concat([]);
  3915. tmp.push(obj.id);
  3916. for(i = 0, j = obj.parents.length; i < j; i++) {
  3917. this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
  3918. return $.inArray(v, tmp) === -1;
  3919. });
  3920. }
  3921. for(k = 0, l = tmp.length; k < l; k++) {
  3922. if(this._model.data[tmp[k]].state.selected) {
  3923. c = true;
  3924. break;
  3925. }
  3926. }
  3927. if (c) {
  3928. this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
  3929. return $.inArray(v, tmp) === -1;
  3930. });
  3931. }
  3932. /**
  3933. * triggered when a node is deleted
  3934. * @event
  3935. * @name delete_node.jstree
  3936. * @param {Object} node
  3937. * @param {String} parent the parent's ID
  3938. */
  3939. this.trigger('delete_node', { "node" : obj, "parent" : par.id });
  3940. if(c) {
  3941. this.trigger('changed', { 'action' : 'delete_node', 'node' : obj, 'selected' : this._data.core.selected, 'parent' : par.id });
  3942. }
  3943. for(k = 0, l = tmp.length; k < l; k++) {
  3944. delete this._model.data[tmp[k]];
  3945. }
  3946. if($.inArray(this._data.core.focused, tmp) !== -1) {
  3947. this._data.core.focused = null;
  3948. top = this.element[0].scrollTop;
  3949. lft = this.element[0].scrollLeft;
  3950. if(par.id === $.jstree.root) {
  3951. if (this._model.data[$.jstree.root].children[0]) {
  3952. this.get_node(this._model.data[$.jstree.root].children[0], true).children('.jstree-anchor').focus();
  3953. }
  3954. }
  3955. else {
  3956. this.get_node(par, true).children('.jstree-anchor').focus();
  3957. }
  3958. this.element[0].scrollTop = top;
  3959. this.element[0].scrollLeft = lft;
  3960. }
  3961. this.redraw_node(par, true);
  3962. return true;
  3963. },
  3964. /**
  3965. * check if an operation is premitted on the tree. Used internally.
  3966. * @private
  3967. * @name check(chk, obj, par, pos)
  3968. * @param {String} chk the operation to check, can be "create_node", "rename_node", "delete_node", "copy_node" or "move_node"
  3969. * @param {mixed} obj the node
  3970. * @param {mixed} par the parent
  3971. * @param {mixed} pos the position to insert at, or if "rename_node" - the new name
  3972. * @param {mixed} more some various additional information, for example if a "move_node" operations is triggered by DND this will be the hovered node
  3973. * @return {Boolean}
  3974. */
  3975. check : function (chk, obj, par, pos, more) {
  3976. obj = obj && obj.id ? obj : this.get_node(obj);
  3977. par = par && par.id ? par : this.get_node(par);
  3978. var tmp = chk.match(/^move_node|copy_node|create_node$/i) ? par : obj,
  3979. chc = this.settings.core.check_callback;
  3980. if(chk === "move_node" || chk === "copy_node") {
  3981. if((!more || !more.is_multi) && (obj.id === par.id || (chk === "move_node" && $.inArray(obj.id, par.children) === pos) || $.inArray(par.id, obj.children_d) !== -1)) {
  3982. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_01', 'reason' : 'Moving parent inside child', 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  3983. return false;
  3984. }
  3985. }
  3986. if(tmp && tmp.data) { tmp = tmp.data; }
  3987. if(tmp && tmp.functions && (tmp.functions[chk] === false || tmp.functions[chk] === true)) {
  3988. if(tmp.functions[chk] === false) {
  3989. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_02', 'reason' : 'Node data prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  3990. }
  3991. return tmp.functions[chk];
  3992. }
  3993. if(chc === false || ($.isFunction(chc) && chc.call(this, chk, obj, par, pos, more) === false) || (chc && chc[chk] === false)) {
  3994. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_03', 'reason' : 'User config for core.check_callback prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  3995. return false;
  3996. }
  3997. return true;
  3998. },
  3999. /**
  4000. * get the last error
  4001. * @name last_error()
  4002. * @return {Object}
  4003. */
  4004. last_error : function () {
  4005. return this._data.core.last_error;
  4006. },
  4007. /**
  4008. * move a node to a new parent
  4009. * @name move_node(obj, par [, pos, callback, is_loaded])
  4010. * @param {mixed} obj the node to move, pass an array to move multiple nodes
  4011. * @param {mixed} par the new parent
  4012. * @param {mixed} pos the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer `0`
  4013. * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
  4014. * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
  4015. * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
  4016. * @param {Boolean} instance internal parameter indicating if the node comes from another instance
  4017. * @trigger move_node.jstree
  4018. */
  4019. move_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
  4020. var t1, t2, old_par, old_pos, new_par, old_ins, is_multi, dpc, tmp, i, j, k, l, p;
  4021. par = this.get_node(par);
  4022. pos = pos === undefined ? 0 : pos;
  4023. if(!par) { return false; }
  4024. if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
  4025. return this.load_node(par, function () { this.move_node(obj, par, pos, callback, true, false, origin); });
  4026. }
  4027. if($.isArray(obj)) {
  4028. if(obj.length === 1) {
  4029. obj = obj[0];
  4030. }
  4031. else {
  4032. //obj = obj.slice();
  4033. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4034. if((tmp = this.move_node(obj[t1], par, pos, callback, is_loaded, false, origin))) {
  4035. par = tmp;
  4036. pos = "after";
  4037. }
  4038. }
  4039. this.redraw();
  4040. return true;
  4041. }
  4042. }
  4043. obj = obj && obj.id ? obj : this.get_node(obj);
  4044. if(!obj || obj.id === $.jstree.root) { return false; }
  4045. old_par = (obj.parent || $.jstree.root).toString();
  4046. new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
  4047. old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
  4048. is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
  4049. old_pos = old_ins && old_ins._id && old_par && old_ins._model.data[old_par] && old_ins._model.data[old_par].children ? $.inArray(obj.id, old_ins._model.data[old_par].children) : -1;
  4050. if(old_ins && old_ins._id) {
  4051. obj = old_ins._model.data[obj.id];
  4052. }
  4053. if(is_multi) {
  4054. if((tmp = this.copy_node(obj, par, pos, callback, is_loaded, false, origin))) {
  4055. if(old_ins) { old_ins.delete_node(obj); }
  4056. return tmp;
  4057. }
  4058. return false;
  4059. }
  4060. //var m = this._model.data;
  4061. if(par.id === $.jstree.root) {
  4062. if(pos === "before") { pos = "first"; }
  4063. if(pos === "after") { pos = "last"; }
  4064. }
  4065. switch(pos) {
  4066. case "before":
  4067. pos = $.inArray(par.id, new_par.children);
  4068. break;
  4069. case "after" :
  4070. pos = $.inArray(par.id, new_par.children) + 1;
  4071. break;
  4072. case "inside":
  4073. case "first":
  4074. pos = 0;
  4075. break;
  4076. case "last":
  4077. pos = new_par.children.length;
  4078. break;
  4079. default:
  4080. if(!pos) { pos = 0; }
  4081. break;
  4082. }
  4083. if(pos > new_par.children.length) { pos = new_par.children.length; }
  4084. if(!this.check("move_node", obj, new_par, pos, { 'core' : true, 'origin' : origin, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id) })) {
  4085. this.settings.core.error.call(this, this._data.core.last_error);
  4086. return false;
  4087. }
  4088. if(obj.parent === new_par.id) {
  4089. dpc = new_par.children.concat();
  4090. tmp = $.inArray(obj.id, dpc);
  4091. if(tmp !== -1) {
  4092. dpc = $.vakata.array_remove(dpc, tmp);
  4093. if(pos > tmp) { pos--; }
  4094. }
  4095. tmp = [];
  4096. for(i = 0, j = dpc.length; i < j; i++) {
  4097. tmp[i >= pos ? i+1 : i] = dpc[i];
  4098. }
  4099. tmp[pos] = obj.id;
  4100. new_par.children = tmp;
  4101. this._node_changed(new_par.id);
  4102. this.redraw(new_par.id === $.jstree.root);
  4103. }
  4104. else {
  4105. // clean old parent and up
  4106. tmp = obj.children_d.concat();
  4107. tmp.push(obj.id);
  4108. for(i = 0, j = obj.parents.length; i < j; i++) {
  4109. dpc = [];
  4110. p = old_ins._model.data[obj.parents[i]].children_d;
  4111. for(k = 0, l = p.length; k < l; k++) {
  4112. if($.inArray(p[k], tmp) === -1) {
  4113. dpc.push(p[k]);
  4114. }
  4115. }
  4116. old_ins._model.data[obj.parents[i]].children_d = dpc;
  4117. }
  4118. old_ins._model.data[old_par].children = $.vakata.array_remove_item(old_ins._model.data[old_par].children, obj.id);
  4119. // insert into new parent and up
  4120. for(i = 0, j = new_par.parents.length; i < j; i++) {
  4121. this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(tmp);
  4122. }
  4123. dpc = [];
  4124. for(i = 0, j = new_par.children.length; i < j; i++) {
  4125. dpc[i >= pos ? i+1 : i] = new_par.children[i];
  4126. }
  4127. dpc[pos] = obj.id;
  4128. new_par.children = dpc;
  4129. new_par.children_d.push(obj.id);
  4130. new_par.children_d = new_par.children_d.concat(obj.children_d);
  4131. // update object
  4132. obj.parent = new_par.id;
  4133. tmp = new_par.parents.concat();
  4134. tmp.unshift(new_par.id);
  4135. p = obj.parents.length;
  4136. obj.parents = tmp;
  4137. // update object children
  4138. tmp = tmp.concat();
  4139. for(i = 0, j = obj.children_d.length; i < j; i++) {
  4140. this._model.data[obj.children_d[i]].parents = this._model.data[obj.children_d[i]].parents.slice(0,p*-1);
  4141. Array.prototype.push.apply(this._model.data[obj.children_d[i]].parents, tmp);
  4142. }
  4143. if(old_par === $.jstree.root || new_par.id === $.jstree.root) {
  4144. this._model.force_full_redraw = true;
  4145. }
  4146. if(!this._model.force_full_redraw) {
  4147. this._node_changed(old_par);
  4148. this._node_changed(new_par.id);
  4149. }
  4150. if(!skip_redraw) {
  4151. this.redraw();
  4152. }
  4153. }
  4154. if(callback) { callback.call(this, obj, new_par, pos); }
  4155. /**
  4156. * triggered when a node is moved
  4157. * @event
  4158. * @name move_node.jstree
  4159. * @param {Object} node
  4160. * @param {String} parent the parent's ID
  4161. * @param {Number} position the position of the node among the parent's children
  4162. * @param {String} old_parent the old parent of the node
  4163. * @param {Number} old_position the old position of the node
  4164. * @param {Boolean} is_multi do the node and new parent belong to different instances
  4165. * @param {jsTree} old_instance the instance the node came from
  4166. * @param {jsTree} new_instance the instance of the new parent
  4167. */
  4168. this.trigger('move_node', { "node" : obj, "parent" : new_par.id, "position" : pos, "old_parent" : old_par, "old_position" : old_pos, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id), 'old_instance' : old_ins, 'new_instance' : this });
  4169. return obj.id;
  4170. },
  4171. /**
  4172. * copy a node to a new parent
  4173. * @name copy_node(obj, par [, pos, callback, is_loaded])
  4174. * @param {mixed} obj the node to copy, pass an array to copy multiple nodes
  4175. * @param {mixed} par the new parent
  4176. * @param {mixed} pos the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer `0`
  4177. * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
  4178. * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
  4179. * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
  4180. * @param {Boolean} instance internal parameter indicating if the node comes from another instance
  4181. * @trigger model.jstree copy_node.jstree
  4182. */
  4183. copy_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
  4184. var t1, t2, dpc, tmp, i, j, node, old_par, new_par, old_ins, is_multi;
  4185. par = this.get_node(par);
  4186. pos = pos === undefined ? 0 : pos;
  4187. if(!par) { return false; }
  4188. if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
  4189. return this.load_node(par, function () { this.copy_node(obj, par, pos, callback, true, false, origin); });
  4190. }
  4191. if($.isArray(obj)) {
  4192. if(obj.length === 1) {
  4193. obj = obj[0];
  4194. }
  4195. else {
  4196. //obj = obj.slice();
  4197. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4198. if((tmp = this.copy_node(obj[t1], par, pos, callback, is_loaded, true, origin))) {
  4199. par = tmp;
  4200. pos = "after";
  4201. }
  4202. }
  4203. this.redraw();
  4204. return true;
  4205. }
  4206. }
  4207. obj = obj && obj.id ? obj : this.get_node(obj);
  4208. if(!obj || obj.id === $.jstree.root) { return false; }
  4209. old_par = (obj.parent || $.jstree.root).toString();
  4210. new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
  4211. old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
  4212. is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
  4213. if(old_ins && old_ins._id) {
  4214. obj = old_ins._model.data[obj.id];
  4215. }
  4216. if(par.id === $.jstree.root) {
  4217. if(pos === "before") { pos = "first"; }
  4218. if(pos === "after") { pos = "last"; }
  4219. }
  4220. switch(pos) {
  4221. case "before":
  4222. pos = $.inArray(par.id, new_par.children);
  4223. break;
  4224. case "after" :
  4225. pos = $.inArray(par.id, new_par.children) + 1;
  4226. break;
  4227. case "inside":
  4228. case "first":
  4229. pos = 0;
  4230. break;
  4231. case "last":
  4232. pos = new_par.children.length;
  4233. break;
  4234. default:
  4235. if(!pos) { pos = 0; }
  4236. break;
  4237. }
  4238. if(pos > new_par.children.length) { pos = new_par.children.length; }
  4239. if(!this.check("copy_node", obj, new_par, pos, { 'core' : true, 'origin' : origin, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id) })) {
  4240. this.settings.core.error.call(this, this._data.core.last_error);
  4241. return false;
  4242. }
  4243. node = old_ins ? old_ins.get_json(obj, { no_id : true, no_data : true, no_state : true }) : obj;
  4244. if(!node) { return false; }
  4245. if(node.id === true) { delete node.id; }
  4246. node = this._parse_model_from_json(node, new_par.id, new_par.parents.concat());
  4247. if(!node) { return false; }
  4248. tmp = this.get_node(node);
  4249. if(obj && obj.state && obj.state.loaded === false) { tmp.state.loaded = false; }
  4250. dpc = [];
  4251. dpc.push(node);
  4252. dpc = dpc.concat(tmp.children_d);
  4253. this.trigger('model', { "nodes" : dpc, "parent" : new_par.id });
  4254. // insert into new parent and up
  4255. for(i = 0, j = new_par.parents.length; i < j; i++) {
  4256. this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(dpc);
  4257. }
  4258. dpc = [];
  4259. for(i = 0, j = new_par.children.length; i < j; i++) {
  4260. dpc[i >= pos ? i+1 : i] = new_par.children[i];
  4261. }
  4262. dpc[pos] = tmp.id;
  4263. new_par.children = dpc;
  4264. new_par.children_d.push(tmp.id);
  4265. new_par.children_d = new_par.children_d.concat(tmp.children_d);
  4266. if(new_par.id === $.jstree.root) {
  4267. this._model.force_full_redraw = true;
  4268. }
  4269. if(!this._model.force_full_redraw) {
  4270. this._node_changed(new_par.id);
  4271. }
  4272. if(!skip_redraw) {
  4273. this.redraw(new_par.id === $.jstree.root);
  4274. }
  4275. if(callback) { callback.call(this, tmp, new_par, pos); }
  4276. /**
  4277. * triggered when a node is copied
  4278. * @event
  4279. * @name copy_node.jstree
  4280. * @param {Object} node the copied node
  4281. * @param {Object} original the original node
  4282. * @param {String} parent the parent's ID
  4283. * @param {Number} position the position of the node among the parent's children
  4284. * @param {String} old_parent the old parent of the node
  4285. * @param {Number} old_position the position of the original node
  4286. * @param {Boolean} is_multi do the node and new parent belong to different instances
  4287. * @param {jsTree} old_instance the instance the node came from
  4288. * @param {jsTree} new_instance the instance of the new parent
  4289. */
  4290. this.trigger('copy_node', { "node" : tmp, "original" : obj, "parent" : new_par.id, "position" : pos, "old_parent" : old_par, "old_position" : old_ins && old_ins._id && old_par && old_ins._model.data[old_par] && old_ins._model.data[old_par].children ? $.inArray(obj.id, old_ins._model.data[old_par].children) : -1,'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id), 'old_instance' : old_ins, 'new_instance' : this });
  4291. return tmp.id;
  4292. },
  4293. /**
  4294. * cut a node (a later call to `paste(obj)` would move the node)
  4295. * @name cut(obj)
  4296. * @param {mixed} obj multiple objects can be passed using an array
  4297. * @trigger cut.jstree
  4298. */
  4299. cut : function (obj) {
  4300. if(!obj) { obj = this._data.core.selected.concat(); }
  4301. if(!$.isArray(obj)) { obj = [obj]; }
  4302. if(!obj.length) { return false; }
  4303. var tmp = [], o, t1, t2;
  4304. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4305. o = this.get_node(obj[t1]);
  4306. if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
  4307. }
  4308. if(!tmp.length) { return false; }
  4309. ccp_node = tmp;
  4310. ccp_inst = this;
  4311. ccp_mode = 'move_node';
  4312. /**
  4313. * triggered when nodes are added to the buffer for moving
  4314. * @event
  4315. * @name cut.jstree
  4316. * @param {Array} node
  4317. */
  4318. this.trigger('cut', { "node" : obj });
  4319. },
  4320. /**
  4321. * copy a node (a later call to `paste(obj)` would copy the node)
  4322. * @name copy(obj)
  4323. * @param {mixed} obj multiple objects can be passed using an array
  4324. * @trigger copy.jstree
  4325. */
  4326. copy : function (obj) {
  4327. if(!obj) { obj = this._data.core.selected.concat(); }
  4328. if(!$.isArray(obj)) { obj = [obj]; }
  4329. if(!obj.length) { return false; }
  4330. var tmp = [], o, t1, t2;
  4331. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4332. o = this.get_node(obj[t1]);
  4333. if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
  4334. }
  4335. if(!tmp.length) { return false; }
  4336. ccp_node = tmp;
  4337. ccp_inst = this;
  4338. ccp_mode = 'copy_node';
  4339. /**
  4340. * triggered when nodes are added to the buffer for copying
  4341. * @event
  4342. * @name copy.jstree
  4343. * @param {Array} node
  4344. */
  4345. this.trigger('copy', { "node" : obj });
  4346. },
  4347. /**
  4348. * get the current buffer (any nodes that are waiting for a paste operation)
  4349. * @name get_buffer()
  4350. * @return {Object} an object consisting of `mode` ("copy_node" or "move_node"), `node` (an array of objects) and `inst` (the instance)
  4351. */
  4352. get_buffer : function () {
  4353. return { 'mode' : ccp_mode, 'node' : ccp_node, 'inst' : ccp_inst };
  4354. },
  4355. /**
  4356. * check if there is something in the buffer to paste
  4357. * @name can_paste()
  4358. * @return {Boolean}
  4359. */
  4360. can_paste : function () {
  4361. return ccp_mode !== false && ccp_node !== false; // && ccp_inst._model.data[ccp_node];
  4362. },
  4363. /**
  4364. * copy or move the previously cut or copied nodes to a new parent
  4365. * @name paste(obj [, pos])
  4366. * @param {mixed} obj the new parent
  4367. * @param {mixed} pos the position to insert at (besides integer, "first" and "last" are supported), defaults to integer `0`
  4368. * @trigger paste.jstree
  4369. */
  4370. paste : function (obj, pos) {
  4371. obj = this.get_node(obj);
  4372. if(!obj || !ccp_mode || !ccp_mode.match(/^(copy_node|move_node)$/) || !ccp_node) { return false; }
  4373. if(this[ccp_mode](ccp_node, obj, pos, false, false, false, ccp_inst)) {
  4374. /**
  4375. * triggered when paste is invoked
  4376. * @event
  4377. * @name paste.jstree
  4378. * @param {String} parent the ID of the receiving node
  4379. * @param {Array} node the nodes in the buffer
  4380. * @param {String} mode the performed operation - "copy_node" or "move_node"
  4381. */
  4382. this.trigger('paste', { "parent" : obj.id, "node" : ccp_node, "mode" : ccp_mode });
  4383. }
  4384. ccp_node = false;
  4385. ccp_mode = false;
  4386. ccp_inst = false;
  4387. },
  4388. /**
  4389. * clear the buffer of previously copied or cut nodes
  4390. * @name clear_buffer()
  4391. * @trigger clear_buffer.jstree
  4392. */
  4393. clear_buffer : function () {
  4394. ccp_node = false;
  4395. ccp_mode = false;
  4396. ccp_inst = false;
  4397. /**
  4398. * triggered when the copy / cut buffer is cleared
  4399. * @event
  4400. * @name clear_buffer.jstree
  4401. */
  4402. this.trigger('clear_buffer');
  4403. },
  4404. /**
  4405. * put a node in edit mode (input field to rename the node)
  4406. * @name edit(obj [, default_text, callback])
  4407. * @param {mixed} obj
  4408. * @param {String} default_text the text to populate the input with (if omitted or set to a non-string value the node's text value is used)
  4409. * @param {Function} callback a function to be called once the text box is blurred, it is called in the instance's scope and receives the node, a status parameter (true if the rename is successful, false otherwise) and a boolean indicating if the user cancelled the edit. You can access the node's title using .text
  4410. */
  4411. edit : function (obj, default_text, callback) {
  4412. var rtl, w, a, s, t, h1, h2, fn, tmp, cancel = false;
  4413. obj = this.get_node(obj);
  4414. if(!obj) { return false; }
  4415. if(!this.check("edit", obj, this.get_parent(obj))) {
  4416. this.settings.core.error.call(this, this._data.core.last_error);
  4417. return false;
  4418. }
  4419. tmp = obj;
  4420. default_text = typeof default_text === 'string' ? default_text : obj.text;
  4421. this.set_text(obj, "");
  4422. obj = this._open_to(obj);
  4423. tmp.text = default_text;
  4424. rtl = this._data.core.rtl;
  4425. w = this.element.width();
  4426. this._data.core.focused = tmp.id;
  4427. a = obj.children('.jstree-anchor').focus();
  4428. s = $('<span>');
  4429. /*!
  4430. oi = obj.children("i:visible"),
  4431. ai = a.children("i:visible"),
  4432. w1 = oi.width() * oi.length,
  4433. w2 = ai.width() * ai.length,
  4434. */
  4435. t = default_text;
  4436. h1 = $("<"+"div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo("body");
  4437. h2 = $("<"+"input />", {
  4438. "value" : t,
  4439. "class" : "jstree-rename-input",
  4440. // "size" : t.length,
  4441. "css" : {
  4442. "padding" : "0",
  4443. "border" : "1px solid silver",
  4444. "box-sizing" : "border-box",
  4445. "display" : "inline-block",
  4446. "height" : (this._data.core.li_height) + "px",
  4447. "lineHeight" : (this._data.core.li_height) + "px",
  4448. "width" : "150px" // will be set a bit further down
  4449. },
  4450. "blur" : $.proxy(function (e) {
  4451. e.stopImmediatePropagation();
  4452. e.preventDefault();
  4453. var i = s.children(".jstree-rename-input"),
  4454. v = i.val(),
  4455. f = this.settings.core.force_text,
  4456. nv;
  4457. if(v === "") { v = t; }
  4458. h1.remove();
  4459. s.replaceWith(a);
  4460. s.remove();
  4461. t = f ? t : $('<div></div>').append($.parseHTML(t)).html();
  4462. this.set_text(obj, t);
  4463. nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html());
  4464. if(!nv) {
  4465. this.set_text(obj, t); // move this up? and fix #483
  4466. }
  4467. this._data.core.focused = tmp.id;
  4468. setTimeout($.proxy(function () {
  4469. var node = this.get_node(tmp.id, true);
  4470. if(node.length) {
  4471. this._data.core.focused = tmp.id;
  4472. node.children('.jstree-anchor').focus();
  4473. }
  4474. }, this), 0);
  4475. if(callback) {
  4476. callback.call(this, tmp, nv, cancel);
  4477. }
  4478. h2 = null;
  4479. }, this),
  4480. "keydown" : function (e) {
  4481. var key = e.which;
  4482. if(key === 27) {
  4483. cancel = true;
  4484. this.value = t;
  4485. }
  4486. if(key === 27 || key === 13 || key === 37 || key === 38 || key === 39 || key === 40 || key === 32) {
  4487. e.stopImmediatePropagation();
  4488. }
  4489. if(key === 27 || key === 13) {
  4490. e.preventDefault();
  4491. this.blur();
  4492. }
  4493. },
  4494. "click" : function (e) { e.stopImmediatePropagation(); },
  4495. "mousedown" : function (e) { e.stopImmediatePropagation(); },
  4496. "keyup" : function (e) {
  4497. h2.width(Math.min(h1.text("pW" + this.value).width(),w));
  4498. },
  4499. "keypress" : function(e) {
  4500. if(e.which === 13) { return false; }
  4501. }
  4502. });
  4503. fn = {
  4504. fontFamily : a.css('fontFamily') || '',
  4505. fontSize : a.css('fontSize') || '',
  4506. fontWeight : a.css('fontWeight') || '',
  4507. fontStyle : a.css('fontStyle') || '',
  4508. fontStretch : a.css('fontStretch') || '',
  4509. fontVariant : a.css('fontVariant') || '',
  4510. letterSpacing : a.css('letterSpacing') || '',
  4511. wordSpacing : a.css('wordSpacing') || ''
  4512. };
  4513. s.attr('class', a.attr('class')).append(a.contents().clone()).append(h2);
  4514. a.replaceWith(s);
  4515. h1.css(fn);
  4516. h2.css(fn).width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
  4517. $(document).one('mousedown.jstree touchstart.jstree dnd_start.vakata', function (e) {
  4518. if (h2 && e.target !== h2) {
  4519. $(h2).blur();
  4520. }
  4521. });
  4522. },
  4523. /**
  4524. * changes the theme
  4525. * @name set_theme(theme_name [, theme_url])
  4526. * @param {String} theme_name the name of the new theme to apply
  4527. * @param {mixed} theme_url the location of the CSS file for this theme. Omit or set to `false` if you manually included the file. Set to `true` to autoload from the `core.themes.dir` directory.
  4528. * @trigger set_theme.jstree
  4529. */
  4530. set_theme : function (theme_name, theme_url) {
  4531. if(!theme_name) { return false; }
  4532. if(theme_url === true) {
  4533. var dir = this.settings.core.themes.dir;
  4534. if(!dir) { dir = $.jstree.path + '/themes'; }
  4535. theme_url = dir + '/' + theme_name + '/style.css';
  4536. }
  4537. if(theme_url && $.inArray(theme_url, themes_loaded) === -1) {
  4538. $('head').append('<'+'link rel="stylesheet" href="' + theme_url + '" type="text/css" />');
  4539. themes_loaded.push(theme_url);
  4540. }
  4541. if(this._data.core.themes.name) {
  4542. this.element.removeClass('jstree-' + this._data.core.themes.name);
  4543. }
  4544. this._data.core.themes.name = theme_name;
  4545. this.element.addClass('jstree-' + theme_name);
  4546. this.element[this.settings.core.themes.responsive ? 'addClass' : 'removeClass' ]('jstree-' + theme_name + '-responsive');
  4547. /**
  4548. * triggered when a theme is set
  4549. * @event
  4550. * @name set_theme.jstree
  4551. * @param {String} theme the new theme
  4552. */
  4553. this.trigger('set_theme', { 'theme' : theme_name });
  4554. },
  4555. /**
  4556. * gets the name of the currently applied theme name
  4557. * @name get_theme()
  4558. * @return {String}
  4559. */
  4560. get_theme : function () { return this._data.core.themes.name; },
  4561. /**
  4562. * changes the theme variant (if the theme has variants)
  4563. * @name set_theme_variant(variant_name)
  4564. * @param {String|Boolean} variant_name the variant to apply (if `false` is used the current variant is removed)
  4565. */
  4566. set_theme_variant : function (variant_name) {
  4567. if(this._data.core.themes.variant) {
  4568. this.element.removeClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
  4569. }
  4570. this._data.core.themes.variant = variant_name;
  4571. if(variant_name) {
  4572. this.element.addClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
  4573. }
  4574. },
  4575. /**
  4576. * gets the name of the currently applied theme variant
  4577. * @name get_theme()
  4578. * @return {String}
  4579. */
  4580. get_theme_variant : function () { return this._data.core.themes.variant; },
  4581. /**
  4582. * shows a striped background on the container (if the theme supports it)
  4583. * @name show_stripes()
  4584. */
  4585. show_stripes : function () {
  4586. this._data.core.themes.stripes = true;
  4587. this.get_container_ul().addClass("jstree-striped");
  4588. /**
  4589. * triggered when stripes are shown
  4590. * @event
  4591. * @name show_stripes.jstree
  4592. */
  4593. this.trigger('show_stripes');
  4594. },
  4595. /**
  4596. * hides the striped background on the container
  4597. * @name hide_stripes()
  4598. */
  4599. hide_stripes : function () {
  4600. this._data.core.themes.stripes = false;
  4601. this.get_container_ul().removeClass("jstree-striped");
  4602. /**
  4603. * triggered when stripes are hidden
  4604. * @event
  4605. * @name hide_stripes.jstree
  4606. */
  4607. this.trigger('hide_stripes');
  4608. },
  4609. /**
  4610. * toggles the striped background on the container
  4611. * @name toggle_stripes()
  4612. */
  4613. toggle_stripes : function () { if(this._data.core.themes.stripes) { this.hide_stripes(); } else { this.show_stripes(); } },
  4614. /**
  4615. * shows the connecting dots (if the theme supports it)
  4616. * @name show_dots()
  4617. */
  4618. show_dots : function () {
  4619. this._data.core.themes.dots = true;
  4620. this.get_container_ul().removeClass("jstree-no-dots");
  4621. /**
  4622. * triggered when dots are shown
  4623. * @event
  4624. * @name show_dots.jstree
  4625. */
  4626. this.trigger('show_dots');
  4627. },
  4628. /**
  4629. * hides the connecting dots
  4630. * @name hide_dots()
  4631. */
  4632. hide_dots : function () {
  4633. this._data.core.themes.dots = false;
  4634. this.get_container_ul().addClass("jstree-no-dots");
  4635. /**
  4636. * triggered when dots are hidden
  4637. * @event
  4638. * @name hide_dots.jstree
  4639. */
  4640. this.trigger('hide_dots');
  4641. },
  4642. /**
  4643. * toggles the connecting dots
  4644. * @name toggle_dots()
  4645. */
  4646. toggle_dots : function () { if(this._data.core.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
  4647. /**
  4648. * show the node icons
  4649. * @name show_icons()
  4650. */
  4651. show_icons : function () {
  4652. this._data.core.themes.icons = true;
  4653. this.get_container_ul().removeClass("jstree-no-icons");
  4654. /**
  4655. * triggered when icons are shown
  4656. * @event
  4657. * @name show_icons.jstree
  4658. */
  4659. this.trigger('show_icons');
  4660. },
  4661. /**
  4662. * hide the node icons
  4663. * @name hide_icons()
  4664. */
  4665. hide_icons : function () {
  4666. this._data.core.themes.icons = false;
  4667. this.get_container_ul().addClass("jstree-no-icons");
  4668. /**
  4669. * triggered when icons are hidden
  4670. * @event
  4671. * @name hide_icons.jstree
  4672. */
  4673. this.trigger('hide_icons');
  4674. },
  4675. /**
  4676. * toggle the node icons
  4677. * @name toggle_icons()
  4678. */
  4679. toggle_icons : function () { if(this._data.core.themes.icons) { this.hide_icons(); } else { this.show_icons(); } },
  4680. /**
  4681. * show the node ellipsis
  4682. * @name show_icons()
  4683. */
  4684. show_ellipsis : function () {
  4685. this._data.core.themes.ellipsis = true;
  4686. this.get_container_ul().addClass("jstree-ellipsis");
  4687. /**
  4688. * triggered when ellisis is shown
  4689. * @event
  4690. * @name show_ellipsis.jstree
  4691. */
  4692. this.trigger('show_ellipsis');
  4693. },
  4694. /**
  4695. * hide the node ellipsis
  4696. * @name hide_ellipsis()
  4697. */
  4698. hide_ellipsis : function () {
  4699. this._data.core.themes.ellipsis = false;
  4700. this.get_container_ul().removeClass("jstree-ellipsis");
  4701. /**
  4702. * triggered when ellisis is hidden
  4703. * @event
  4704. * @name hide_ellipsis.jstree
  4705. */
  4706. this.trigger('hide_ellipsis');
  4707. },
  4708. /**
  4709. * toggle the node ellipsis
  4710. * @name toggle_icons()
  4711. */
  4712. toggle_ellipsis : function () { if(this._data.core.themes.ellipsis) { this.hide_ellipsis(); } else { this.show_ellipsis(); } },
  4713. /**
  4714. * set the node icon for a node
  4715. * @name set_icon(obj, icon)
  4716. * @param {mixed} obj
  4717. * @param {String} icon the new icon - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
  4718. */
  4719. set_icon : function (obj, icon) {
  4720. var t1, t2, dom, old;
  4721. if($.isArray(obj)) {
  4722. obj = obj.slice();
  4723. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4724. this.set_icon(obj[t1], icon);
  4725. }
  4726. return true;
  4727. }
  4728. obj = this.get_node(obj);
  4729. if(!obj || obj.id === $.jstree.root) { return false; }
  4730. old = obj.icon;
  4731. obj.icon = icon === true || icon === null || icon === undefined || icon === '' ? true : icon;
  4732. dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
  4733. if(icon === false) {
  4734. dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
  4735. this.hide_icon(obj);
  4736. }
  4737. else if(icon === true || icon === null || icon === undefined || icon === '') {
  4738. dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
  4739. if(old === false) { this.show_icon(obj); }
  4740. }
  4741. else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
  4742. dom.removeClass(old).css("background","");
  4743. dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
  4744. if(old === false) { this.show_icon(obj); }
  4745. }
  4746. else {
  4747. dom.removeClass(old).css("background","");
  4748. dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
  4749. if(old === false) { this.show_icon(obj); }
  4750. }
  4751. return true;
  4752. },
  4753. /**
  4754. * get the node icon for a node
  4755. * @name get_icon(obj)
  4756. * @param {mixed} obj
  4757. * @return {String}
  4758. */
  4759. get_icon : function (obj) {
  4760. obj = this.get_node(obj);
  4761. return (!obj || obj.id === $.jstree.root) ? false : obj.icon;
  4762. },
  4763. /**
  4764. * hide the icon on an individual node
  4765. * @name hide_icon(obj)
  4766. * @param {mixed} obj
  4767. */
  4768. hide_icon : function (obj) {
  4769. var t1, t2;
  4770. if($.isArray(obj)) {
  4771. obj = obj.slice();
  4772. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4773. this.hide_icon(obj[t1]);
  4774. }
  4775. return true;
  4776. }
  4777. obj = this.get_node(obj);
  4778. if(!obj || obj === $.jstree.root) { return false; }
  4779. obj.icon = false;
  4780. this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon").addClass('jstree-themeicon-hidden');
  4781. return true;
  4782. },
  4783. /**
  4784. * show the icon on an individual node
  4785. * @name show_icon(obj)
  4786. * @param {mixed} obj
  4787. */
  4788. show_icon : function (obj) {
  4789. var t1, t2, dom;
  4790. if($.isArray(obj)) {
  4791. obj = obj.slice();
  4792. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4793. this.show_icon(obj[t1]);
  4794. }
  4795. return true;
  4796. }
  4797. obj = this.get_node(obj);
  4798. if(!obj || obj === $.jstree.root) { return false; }
  4799. dom = this.get_node(obj, true);
  4800. obj.icon = dom.length ? dom.children(".jstree-anchor").children(".jstree-themeicon").attr('rel') : true;
  4801. if(!obj.icon) { obj.icon = true; }
  4802. dom.children(".jstree-anchor").children(".jstree-themeicon").removeClass('jstree-themeicon-hidden');
  4803. return true;
  4804. }
  4805. };
  4806. // helpers
  4807. $.vakata = {};
  4808. // collect attributes
  4809. $.vakata.attributes = function(node, with_values) {
  4810. node = $(node)[0];
  4811. var attr = with_values ? {} : [];
  4812. if(node && node.attributes) {
  4813. $.each(node.attributes, function (i, v) {
  4814. if($.inArray(v.name.toLowerCase(),['style','contenteditable','hasfocus','tabindex']) !== -1) { return; }
  4815. if(v.value !== null && $.trim(v.value) !== '') {
  4816. if(with_values) { attr[v.name] = v.value; }
  4817. else { attr.push(v.name); }
  4818. }
  4819. });
  4820. }
  4821. return attr;
  4822. };
  4823. $.vakata.array_unique = function(array) {
  4824. var a = [], i, j, l, o = {};
  4825. for(i = 0, l = array.length; i < l; i++) {
  4826. if(o[array[i]] === undefined) {
  4827. a.push(array[i]);
  4828. o[array[i]] = true;
  4829. }
  4830. }
  4831. return a;
  4832. };
  4833. // remove item from array
  4834. $.vakata.array_remove = function(array, from) {
  4835. array.splice(from, 1);
  4836. return array;
  4837. //var rest = array.slice((to || from) + 1 || array.length);
  4838. //array.length = from < 0 ? array.length + from : from;
  4839. //array.push.apply(array, rest);
  4840. //return array;
  4841. };
  4842. // remove item from array
  4843. $.vakata.array_remove_item = function(array, item) {
  4844. var tmp = $.inArray(item, array);
  4845. return tmp !== -1 ? $.vakata.array_remove(array, tmp) : array;
  4846. };
  4847. $.vakata.array_filter = function(c,a,b,d,e) {
  4848. if (c.filter) {
  4849. return c.filter(a, b);
  4850. }
  4851. d=[];
  4852. for (e in c) {
  4853. if (~~e+''===e+'' && e>=0 && a.call(b,c[e],+e,c)) {
  4854. d.push(c[e]);
  4855. }
  4856. }
  4857. return d;
  4858. };
  4859. /**
  4860. * ### Changed plugin
  4861. *
  4862. * This plugin adds more information to the `changed.jstree` event. The new data is contained in the `changed` event data property, and contains a lists of `selected` and `deselected` nodes.
  4863. */
  4864. $.jstree.plugins.changed = function (options, parent) {
  4865. var last = [];
  4866. this.trigger = function (ev, data) {
  4867. var i, j;
  4868. if(!data) {
  4869. data = {};
  4870. }
  4871. if(ev.replace('.jstree','') === 'changed') {
  4872. data.changed = { selected : [], deselected : [] };
  4873. var tmp = {};
  4874. for(i = 0, j = last.length; i < j; i++) {
  4875. tmp[last[i]] = 1;
  4876. }
  4877. for(i = 0, j = data.selected.length; i < j; i++) {
  4878. if(!tmp[data.selected[i]]) {
  4879. data.changed.selected.push(data.selected[i]);
  4880. }
  4881. else {
  4882. tmp[data.selected[i]] = 2;
  4883. }
  4884. }
  4885. for(i = 0, j = last.length; i < j; i++) {
  4886. if(tmp[last[i]] === 1) {
  4887. data.changed.deselected.push(last[i]);
  4888. }
  4889. }
  4890. last = data.selected.slice();
  4891. }
  4892. /**
  4893. * triggered when selection changes (the "changed" plugin enhances the original event with more data)
  4894. * @event
  4895. * @name changed.jstree
  4896. * @param {Object} node
  4897. * @param {Object} action the action that caused the selection to change
  4898. * @param {Array} selected the current selection
  4899. * @param {Object} changed an object containing two properties `selected` and `deselected` - both arrays of node IDs, which were selected or deselected since the last changed event
  4900. * @param {Object} event the event (if any) that triggered this changed event
  4901. * @plugin changed
  4902. */
  4903. parent.trigger.call(this, ev, data);
  4904. };
  4905. this.refresh = function (skip_loading, forget_state) {
  4906. last = [];
  4907. return parent.refresh.apply(this, arguments);
  4908. };
  4909. };
  4910. /**
  4911. * ### Checkbox plugin
  4912. *
  4913. * This plugin renders checkbox icons in front of each node, making multiple selection much easier.
  4914. * It also supports tri-state behavior, meaning that if a node has a few of its children checked it will be rendered as undetermined, and state will be propagated up.
  4915. */
  4916. var _i = document.createElement('I');
  4917. _i.className = 'jstree-icon jstree-checkbox';
  4918. _i.setAttribute('role', 'presentation');
  4919. /**
  4920. * stores all defaults for the checkbox plugin
  4921. * @name $.jstree.defaults.checkbox
  4922. * @plugin checkbox
  4923. */
  4924. $.jstree.defaults.checkbox = {
  4925. /**
  4926. * a boolean indicating if checkboxes should be visible (can be changed at a later time using `show_checkboxes()` and `hide_checkboxes`). Defaults to `true`.
  4927. * @name $.jstree.defaults.checkbox.visible
  4928. * @plugin checkbox
  4929. */
  4930. visible : true,
  4931. /**
  4932. * a boolean indicating if checkboxes should cascade down and have an undetermined state. Defaults to `true`.
  4933. * @name $.jstree.defaults.checkbox.three_state
  4934. * @plugin checkbox
  4935. */
  4936. three_state : true,
  4937. /**
  4938. * a boolean indicating if clicking anywhere on the node should act as clicking on the checkbox. Defaults to `true`.
  4939. * @name $.jstree.defaults.checkbox.whole_node
  4940. * @plugin checkbox
  4941. */
  4942. whole_node : true,
  4943. /**
  4944. * a boolean indicating if the selected style of a node should be kept, or removed. Defaults to `true`.
  4945. * @name $.jstree.defaults.checkbox.keep_selected_style
  4946. * @plugin checkbox
  4947. */
  4948. keep_selected_style : true,
  4949. /**
  4950. * This setting controls how cascading and undetermined nodes are applied.
  4951. * If 'up' is in the string - cascading up is enabled, if 'down' is in the string - cascading down is enabled, if 'undetermined' is in the string - undetermined nodes will be used.
  4952. * If `three_state` is set to `true` this setting is automatically set to 'up+down+undetermined'. Defaults to ''.
  4953. * @name $.jstree.defaults.checkbox.cascade
  4954. * @plugin checkbox
  4955. */
  4956. cascade : '',
  4957. /**
  4958. * This setting controls if checkbox are bound to the general tree selection or to an internal array maintained by the checkbox plugin. Defaults to `true`, only set to `false` if you know exactly what you are doing.
  4959. * @name $.jstree.defaults.checkbox.tie_selection
  4960. * @plugin checkbox
  4961. */
  4962. tie_selection : true,
  4963. /**
  4964. * This setting controls if cascading down affects disabled checkboxes
  4965. * @name $.jstree.defaults.checkbox.cascade_to_disabled
  4966. * @plugin checkbox
  4967. */
  4968. cascade_to_disabled : true,
  4969. /**
  4970. * This setting controls if cascading down affects hidden checkboxes
  4971. * @name $.jstree.defaults.checkbox.cascade_to_hidden
  4972. * @plugin checkbox
  4973. */
  4974. cascade_to_hidden : true
  4975. };
  4976. $.jstree.plugins.checkbox = function (options, parent) {
  4977. this.bind = function () {
  4978. parent.bind.call(this);
  4979. this._data.checkbox.uto = false;
  4980. this._data.checkbox.selected = [];
  4981. if(this.settings.checkbox.three_state) {
  4982. this.settings.checkbox.cascade = 'up+down+undetermined';
  4983. }
  4984. this.element
  4985. .on("init.jstree", $.proxy(function () {
  4986. this._data.checkbox.visible = this.settings.checkbox.visible;
  4987. if(!this.settings.checkbox.keep_selected_style) {
  4988. this.element.addClass('jstree-checkbox-no-clicked');
  4989. }
  4990. if(this.settings.checkbox.tie_selection) {
  4991. this.element.addClass('jstree-checkbox-selection');
  4992. }
  4993. }, this))
  4994. .on("loading.jstree", $.proxy(function () {
  4995. this[ this._data.checkbox.visible ? 'show_checkboxes' : 'hide_checkboxes' ]();
  4996. }, this));
  4997. if(this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
  4998. this.element
  4999. .on('changed.jstree uncheck_node.jstree check_node.jstree uncheck_all.jstree check_all.jstree move_node.jstree copy_node.jstree redraw.jstree open_node.jstree', $.proxy(function () {
  5000. // only if undetermined is in setting
  5001. if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
  5002. this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
  5003. }, this));
  5004. }
  5005. if(!this.settings.checkbox.tie_selection) {
  5006. this.element
  5007. .on('model.jstree', $.proxy(function (e, data) {
  5008. var m = this._model.data,
  5009. p = m[data.parent],
  5010. dpc = data.nodes,
  5011. i, j;
  5012. for(i = 0, j = dpc.length; i < j; i++) {
  5013. m[dpc[i]].state.checked = m[dpc[i]].state.checked || (m[dpc[i]].original && m[dpc[i]].original.state && m[dpc[i]].original.state.checked);
  5014. if(m[dpc[i]].state.checked) {
  5015. this._data.checkbox.selected.push(dpc[i]);
  5016. }
  5017. }
  5018. }, this));
  5019. }
  5020. if(this.settings.checkbox.cascade.indexOf('up') !== -1 || this.settings.checkbox.cascade.indexOf('down') !== -1) {
  5021. this.element
  5022. .on('model.jstree', $.proxy(function (e, data) {
  5023. var m = this._model.data,
  5024. p = m[data.parent],
  5025. dpc = data.nodes,
  5026. chd = [],
  5027. c, i, j, k, l, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection;
  5028. if(s.indexOf('down') !== -1) {
  5029. // apply down
  5030. if(p.state[ t ? 'selected' : 'checked' ]) {
  5031. for(i = 0, j = dpc.length; i < j; i++) {
  5032. m[dpc[i]].state[ t ? 'selected' : 'checked' ] = true;
  5033. }
  5034. this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(dpc);
  5035. }
  5036. else {
  5037. for(i = 0, j = dpc.length; i < j; i++) {
  5038. if(m[dpc[i]].state[ t ? 'selected' : 'checked' ]) {
  5039. for(k = 0, l = m[dpc[i]].children_d.length; k < l; k++) {
  5040. m[m[dpc[i]].children_d[k]].state[ t ? 'selected' : 'checked' ] = true;
  5041. }
  5042. this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(m[dpc[i]].children_d);
  5043. }
  5044. }
  5045. }
  5046. }
  5047. if(s.indexOf('up') !== -1) {
  5048. // apply up
  5049. for(i = 0, j = p.children_d.length; i < j; i++) {
  5050. if(!m[p.children_d[i]].children.length) {
  5051. chd.push(m[p.children_d[i]].parent);
  5052. }
  5053. }
  5054. chd = $.vakata.array_unique(chd);
  5055. for(k = 0, l = chd.length; k < l; k++) {
  5056. p = m[chd[k]];
  5057. while(p && p.id !== $.jstree.root) {
  5058. c = 0;
  5059. for(i = 0, j = p.children.length; i < j; i++) {
  5060. c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
  5061. }
  5062. if(c === j) {
  5063. p.state[ t ? 'selected' : 'checked' ] = true;
  5064. this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
  5065. tmp = this.get_node(p, true);
  5066. if(tmp && tmp.length) {
  5067. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass( t ? 'jstree-clicked' : 'jstree-checked');
  5068. }
  5069. }
  5070. else {
  5071. break;
  5072. }
  5073. p = this.get_node(p.parent);
  5074. }
  5075. }
  5076. }
  5077. this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected);
  5078. }, this))
  5079. .on(this.settings.checkbox.tie_selection ? 'select_node.jstree' : 'check_node.jstree', $.proxy(function (e, data) {
  5080. var self = this,
  5081. obj = data.node,
  5082. m = this._model.data,
  5083. par = this.get_node(obj.parent),
  5084. i, j, c, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
  5085. sel = {}, cur = this._data[ t ? 'core' : 'checkbox' ].selected;
  5086. for (i = 0, j = cur.length; i < j; i++) {
  5087. sel[cur[i]] = true;
  5088. }
  5089. // apply down
  5090. if(s.indexOf('down') !== -1) {
  5091. //this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected.concat(obj.children_d));
  5092. var selectedIds = this._cascade_new_checked_state(obj.id, true);
  5093. var temp = obj.children_d.concat(obj.id);
  5094. for (i = 0, j = temp.length; i < j; i++) {
  5095. if (selectedIds.indexOf(temp[i]) > -1) {
  5096. sel[temp[i]] = true;
  5097. }
  5098. else {
  5099. delete sel[temp[i]];
  5100. }
  5101. }
  5102. }
  5103. // apply up
  5104. if(s.indexOf('up') !== -1) {
  5105. while(par && par.id !== $.jstree.root) {
  5106. c = 0;
  5107. for(i = 0, j = par.children.length; i < j; i++) {
  5108. c += m[par.children[i]].state[ t ? 'selected' : 'checked' ];
  5109. }
  5110. if(c === j) {
  5111. par.state[ t ? 'selected' : 'checked' ] = true;
  5112. sel[par.id] = true;
  5113. //this._data[ t ? 'core' : 'checkbox' ].selected.push(par.id);
  5114. tmp = this.get_node(par, true);
  5115. if(tmp && tmp.length) {
  5116. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5117. }
  5118. }
  5119. else {
  5120. break;
  5121. }
  5122. par = this.get_node(par.parent);
  5123. }
  5124. }
  5125. cur = [];
  5126. for (i in sel) {
  5127. if (sel.hasOwnProperty(i)) {
  5128. cur.push(i);
  5129. }
  5130. }
  5131. this._data[ t ? 'core' : 'checkbox' ].selected = cur;
  5132. }, this))
  5133. .on(this.settings.checkbox.tie_selection ? 'deselect_all.jstree' : 'uncheck_all.jstree', $.proxy(function (e, data) {
  5134. var obj = this.get_node($.jstree.root),
  5135. m = this._model.data,
  5136. i, j, tmp;
  5137. for(i = 0, j = obj.children_d.length; i < j; i++) {
  5138. tmp = m[obj.children_d[i]];
  5139. if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
  5140. tmp.original.state.undetermined = false;
  5141. }
  5142. }
  5143. }, this))
  5144. .on(this.settings.checkbox.tie_selection ? 'deselect_node.jstree' : 'uncheck_node.jstree', $.proxy(function (e, data) {
  5145. var self = this,
  5146. obj = data.node,
  5147. dom = this.get_node(obj, true),
  5148. i, j, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
  5149. cur = this._data[ t ? 'core' : 'checkbox' ].selected, sel = {},
  5150. stillSelectedIds = [],
  5151. allIds = obj.children_d.concat(obj.id);
  5152. // apply down
  5153. if(s.indexOf('down') !== -1) {
  5154. var selectedIds = this._cascade_new_checked_state(obj.id, false);
  5155. cur = cur.filter(function(id) {
  5156. return allIds.indexOf(id) === -1 || selectedIds.indexOf(id) > -1;
  5157. });
  5158. }
  5159. // only apply up if cascade up is enabled and if this node is not selected
  5160. // (if all child nodes are disabled and cascade_to_disabled === false then this node will till be selected).
  5161. if(s.indexOf('up') !== -1 && cur.indexOf(obj.id) === -1) {
  5162. for(i = 0, j = obj.parents.length; i < j; i++) {
  5163. tmp = this._model.data[obj.parents[i]];
  5164. tmp.state[ t ? 'selected' : 'checked' ] = false;
  5165. if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
  5166. tmp.original.state.undetermined = false;
  5167. }
  5168. tmp = this.get_node(obj.parents[i], true);
  5169. if(tmp && tmp.length) {
  5170. tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
  5171. }
  5172. }
  5173. cur = cur.filter(function(id) {
  5174. return obj.parents.indexOf(id) === -1;
  5175. });
  5176. }
  5177. this._data[ t ? 'core' : 'checkbox' ].selected = cur;
  5178. }, this));
  5179. }
  5180. if(this.settings.checkbox.cascade.indexOf('up') !== -1) {
  5181. this.element
  5182. .on('delete_node.jstree', $.proxy(function (e, data) {
  5183. // apply up (whole handler)
  5184. var p = this.get_node(data.parent),
  5185. m = this._model.data,
  5186. i, j, c, tmp, t = this.settings.checkbox.tie_selection;
  5187. while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
  5188. c = 0;
  5189. for(i = 0, j = p.children.length; i < j; i++) {
  5190. c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
  5191. }
  5192. if(j > 0 && c === j) {
  5193. p.state[ t ? 'selected' : 'checked' ] = true;
  5194. this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
  5195. tmp = this.get_node(p, true);
  5196. if(tmp && tmp.length) {
  5197. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5198. }
  5199. }
  5200. else {
  5201. break;
  5202. }
  5203. p = this.get_node(p.parent);
  5204. }
  5205. }, this))
  5206. .on('move_node.jstree', $.proxy(function (e, data) {
  5207. // apply up (whole handler)
  5208. var is_multi = data.is_multi,
  5209. old_par = data.old_parent,
  5210. new_par = this.get_node(data.parent),
  5211. m = this._model.data,
  5212. p, c, i, j, tmp, t = this.settings.checkbox.tie_selection;
  5213. if(!is_multi) {
  5214. p = this.get_node(old_par);
  5215. while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
  5216. c = 0;
  5217. for(i = 0, j = p.children.length; i < j; i++) {
  5218. c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
  5219. }
  5220. if(j > 0 && c === j) {
  5221. p.state[ t ? 'selected' : 'checked' ] = true;
  5222. this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
  5223. tmp = this.get_node(p, true);
  5224. if(tmp && tmp.length) {
  5225. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5226. }
  5227. }
  5228. else {
  5229. break;
  5230. }
  5231. p = this.get_node(p.parent);
  5232. }
  5233. }
  5234. p = new_par;
  5235. while(p && p.id !== $.jstree.root) {
  5236. c = 0;
  5237. for(i = 0, j = p.children.length; i < j; i++) {
  5238. c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
  5239. }
  5240. if(c === j) {
  5241. if(!p.state[ t ? 'selected' : 'checked' ]) {
  5242. p.state[ t ? 'selected' : 'checked' ] = true;
  5243. this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
  5244. tmp = this.get_node(p, true);
  5245. if(tmp && tmp.length) {
  5246. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5247. }
  5248. }
  5249. }
  5250. else {
  5251. if(p.state[ t ? 'selected' : 'checked' ]) {
  5252. p.state[ t ? 'selected' : 'checked' ] = false;
  5253. this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_remove_item(this._data[ t ? 'core' : 'checkbox' ].selected, p.id);
  5254. tmp = this.get_node(p, true);
  5255. if(tmp && tmp.length) {
  5256. tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
  5257. }
  5258. }
  5259. else {
  5260. break;
  5261. }
  5262. }
  5263. p = this.get_node(p.parent);
  5264. }
  5265. }, this));
  5266. }
  5267. };
  5268. /**
  5269. * get an array of all nodes whose state is "undetermined"
  5270. * @name get_undetermined([full])
  5271. * @param {boolean} full: if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  5272. * @return {Array}
  5273. * @plugin checkbox
  5274. */
  5275. this.get_undetermined = function (full) {
  5276. if (this.settings.checkbox.cascade.indexOf('undetermined') === -1) {
  5277. return [];
  5278. }
  5279. var i, j, k, l, o = {}, m = this._model.data, t = this.settings.checkbox.tie_selection, s = this._data[ t ? 'core' : 'checkbox' ].selected, p = [], tt = this, r = [];
  5280. for(i = 0, j = s.length; i < j; i++) {
  5281. if(m[s[i]] && m[s[i]].parents) {
  5282. for(k = 0, l = m[s[i]].parents.length; k < l; k++) {
  5283. if(o[m[s[i]].parents[k]] !== undefined) {
  5284. break;
  5285. }
  5286. if(m[s[i]].parents[k] !== $.jstree.root) {
  5287. o[m[s[i]].parents[k]] = true;
  5288. p.push(m[s[i]].parents[k]);
  5289. }
  5290. }
  5291. }
  5292. }
  5293. // attempt for server side undetermined state
  5294. this.element.find('.jstree-closed').not(':has(.jstree-children)')
  5295. .each(function () {
  5296. var tmp = tt.get_node(this), tmp2;
  5297. if(!tmp) { return; }
  5298. if(!tmp.state.loaded) {
  5299. if(tmp.original && tmp.original.state && tmp.original.state.undetermined && tmp.original.state.undetermined === true) {
  5300. if(o[tmp.id] === undefined && tmp.id !== $.jstree.root) {
  5301. o[tmp.id] = true;
  5302. p.push(tmp.id);
  5303. }
  5304. for(k = 0, l = tmp.parents.length; k < l; k++) {
  5305. if(o[tmp.parents[k]] === undefined && tmp.parents[k] !== $.jstree.root) {
  5306. o[tmp.parents[k]] = true;
  5307. p.push(tmp.parents[k]);
  5308. }
  5309. }
  5310. }
  5311. }
  5312. else {
  5313. for(i = 0, j = tmp.children_d.length; i < j; i++) {
  5314. tmp2 = m[tmp.children_d[i]];
  5315. if(!tmp2.state.loaded && tmp2.original && tmp2.original.state && tmp2.original.state.undetermined && tmp2.original.state.undetermined === true) {
  5316. if(o[tmp2.id] === undefined && tmp2.id !== $.jstree.root) {
  5317. o[tmp2.id] = true;
  5318. p.push(tmp2.id);
  5319. }
  5320. for(k = 0, l = tmp2.parents.length; k < l; k++) {
  5321. if(o[tmp2.parents[k]] === undefined && tmp2.parents[k] !== $.jstree.root) {
  5322. o[tmp2.parents[k]] = true;
  5323. p.push(tmp2.parents[k]);
  5324. }
  5325. }
  5326. }
  5327. }
  5328. }
  5329. });
  5330. for (i = 0, j = p.length; i < j; i++) {
  5331. if(!m[p[i]].state[ t ? 'selected' : 'checked' ]) {
  5332. r.push(full ? m[p[i]] : p[i]);
  5333. }
  5334. }
  5335. return r;
  5336. };
  5337. /**
  5338. * set the undetermined state where and if necessary. Used internally.
  5339. * @private
  5340. * @name _undetermined()
  5341. * @plugin checkbox
  5342. */
  5343. this._undetermined = function () {
  5344. if(this.element === null) { return; }
  5345. var p = this.get_undetermined(false), i, j, s;
  5346. this.element.find('.jstree-undetermined').removeClass('jstree-undetermined');
  5347. for (i = 0, j = p.length; i < j; i++) {
  5348. s = this.get_node(p[i], true);
  5349. if(s && s.length) {
  5350. s.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-undetermined');
  5351. }
  5352. }
  5353. };
  5354. this.redraw_node = function(obj, deep, is_callback, force_render) {
  5355. obj = parent.redraw_node.apply(this, arguments);
  5356. if(obj) {
  5357. var i, j, tmp = null, icon = null;
  5358. for(i = 0, j = obj.childNodes.length; i < j; i++) {
  5359. if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
  5360. tmp = obj.childNodes[i];
  5361. break;
  5362. }
  5363. }
  5364. if(tmp) {
  5365. if(!this.settings.checkbox.tie_selection && this._model.data[obj.id].state.checked) { tmp.className += ' jstree-checked'; }
  5366. icon = _i.cloneNode(false);
  5367. if(this._model.data[obj.id].state.checkbox_disabled) { icon.className += ' jstree-checkbox-disabled'; }
  5368. tmp.insertBefore(icon, tmp.childNodes[0]);
  5369. }
  5370. }
  5371. if(!is_callback && this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
  5372. if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
  5373. this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
  5374. }
  5375. return obj;
  5376. };
  5377. /**
  5378. * show the node checkbox icons
  5379. * @name show_checkboxes()
  5380. * @plugin checkbox
  5381. */
  5382. this.show_checkboxes = function () { this._data.core.themes.checkboxes = true; this.get_container_ul().removeClass("jstree-no-checkboxes"); };
  5383. /**
  5384. * hide the node checkbox icons
  5385. * @name hide_checkboxes()
  5386. * @plugin checkbox
  5387. */
  5388. this.hide_checkboxes = function () { this._data.core.themes.checkboxes = false; this.get_container_ul().addClass("jstree-no-checkboxes"); };
  5389. /**
  5390. * toggle the node icons
  5391. * @name toggle_checkboxes()
  5392. * @plugin checkbox
  5393. */
  5394. this.toggle_checkboxes = function () { if(this._data.core.themes.checkboxes) { this.hide_checkboxes(); } else { this.show_checkboxes(); } };
  5395. /**
  5396. * checks if a node is in an undetermined state
  5397. * @name is_undetermined(obj)
  5398. * @param {mixed} obj
  5399. * @return {Boolean}
  5400. */
  5401. this.is_undetermined = function (obj) {
  5402. obj = this.get_node(obj);
  5403. var s = this.settings.checkbox.cascade, i, j, t = this.settings.checkbox.tie_selection, d = this._data[ t ? 'core' : 'checkbox' ].selected, m = this._model.data;
  5404. if(!obj || obj.state[ t ? 'selected' : 'checked' ] === true || s.indexOf('undetermined') === -1 || (s.indexOf('down') === -1 && s.indexOf('up') === -1)) {
  5405. return false;
  5406. }
  5407. if(!obj.state.loaded && obj.original.state.undetermined === true) {
  5408. return true;
  5409. }
  5410. for(i = 0, j = obj.children_d.length; i < j; i++) {
  5411. if($.inArray(obj.children_d[i], d) !== -1 || (!m[obj.children_d[i]].state.loaded && m[obj.children_d[i]].original.state.undetermined)) {
  5412. return true;
  5413. }
  5414. }
  5415. return false;
  5416. };
  5417. /**
  5418. * disable a node's checkbox
  5419. * @name disable_checkbox(obj)
  5420. * @param {mixed} obj an array can be used too
  5421. * @trigger disable_checkbox.jstree
  5422. * @plugin checkbox
  5423. */
  5424. this.disable_checkbox = function (obj) {
  5425. var t1, t2, dom;
  5426. if($.isArray(obj)) {
  5427. obj = obj.slice();
  5428. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  5429. this.disable_checkbox(obj[t1]);
  5430. }
  5431. return true;
  5432. }
  5433. obj = this.get_node(obj);
  5434. if(!obj || obj.id === $.jstree.root) {
  5435. return false;
  5436. }
  5437. dom = this.get_node(obj, true);
  5438. if(!obj.state.checkbox_disabled) {
  5439. obj.state.checkbox_disabled = true;
  5440. if(dom && dom.length) {
  5441. dom.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-checkbox-disabled');
  5442. }
  5443. /**
  5444. * triggered when an node's checkbox is disabled
  5445. * @event
  5446. * @name disable_checkbox.jstree
  5447. * @param {Object} node
  5448. * @plugin checkbox
  5449. */
  5450. this.trigger('disable_checkbox', { 'node' : obj });
  5451. }
  5452. };
  5453. /**
  5454. * enable a node's checkbox
  5455. * @name disable_checkbox(obj)
  5456. * @param {mixed} obj an array can be used too
  5457. * @trigger enable_checkbox.jstree
  5458. * @plugin checkbox
  5459. */
  5460. this.enable_checkbox = function (obj) {
  5461. var t1, t2, dom;
  5462. if($.isArray(obj)) {
  5463. obj = obj.slice();
  5464. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  5465. this.enable_checkbox(obj[t1]);
  5466. }
  5467. return true;
  5468. }
  5469. obj = this.get_node(obj);
  5470. if(!obj || obj.id === $.jstree.root) {
  5471. return false;
  5472. }
  5473. dom = this.get_node(obj, true);
  5474. if(obj.state.checkbox_disabled) {
  5475. obj.state.checkbox_disabled = false;
  5476. if(dom && dom.length) {
  5477. dom.children('.jstree-anchor').children('.jstree-checkbox').removeClass('jstree-checkbox-disabled');
  5478. }
  5479. /**
  5480. * triggered when an node's checkbox is enabled
  5481. * @event
  5482. * @name enable_checkbox.jstree
  5483. * @param {Object} node
  5484. * @plugin checkbox
  5485. */
  5486. this.trigger('enable_checkbox', { 'node' : obj });
  5487. }
  5488. };
  5489. this.activate_node = function (obj, e) {
  5490. if($(e.target).hasClass('jstree-checkbox-disabled')) {
  5491. return false;
  5492. }
  5493. if(this.settings.checkbox.tie_selection && (this.settings.checkbox.whole_node || $(e.target).hasClass('jstree-checkbox'))) {
  5494. e.ctrlKey = true;
  5495. }
  5496. if(this.settings.checkbox.tie_selection || (!this.settings.checkbox.whole_node && !$(e.target).hasClass('jstree-checkbox'))) {
  5497. return parent.activate_node.call(this, obj, e);
  5498. }
  5499. if(this.is_disabled(obj)) {
  5500. return false;
  5501. }
  5502. if(this.is_checked(obj)) {
  5503. this.uncheck_node(obj, e);
  5504. }
  5505. else {
  5506. this.check_node(obj, e);
  5507. }
  5508. this.trigger('activate_node', { 'node' : this.get_node(obj) });
  5509. };
  5510. /**
  5511. * Cascades checked state to a node and all its descendants. This function does NOT affect hidden and disabled nodes (or their descendants).
  5512. * However if these unaffected nodes are already selected their ids will be included in the returned array.
  5513. * @private
  5514. * @param {string} id the node ID
  5515. * @param {bool} checkedState should the nodes be checked or not
  5516. * @returns {Array} Array of all node id's (in this tree branch) that are checked.
  5517. */
  5518. this._cascade_new_checked_state = function (id, checkedState) {
  5519. var self = this;
  5520. var t = this.settings.checkbox.tie_selection;
  5521. var node = this._model.data[id];
  5522. var selectedNodeIds = [];
  5523. var selectedChildrenIds = [], i, j, selectedChildIds;
  5524. if (
  5525. (this.settings.checkbox.cascade_to_disabled || !node.state.disabled) &&
  5526. (this.settings.checkbox.cascade_to_hidden || !node.state.hidden)
  5527. ) {
  5528. //First try and check/uncheck the children
  5529. if (node.children) {
  5530. for (i = 0, j = node.children.length; i < j; i++) {
  5531. var childId = node.children[i];
  5532. selectedChildIds = self._cascade_new_checked_state(childId, checkedState);
  5533. selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
  5534. if (selectedChildIds.indexOf(childId) > -1) {
  5535. selectedChildrenIds.push(childId);
  5536. }
  5537. }
  5538. }
  5539. var dom = self.get_node(node, true);
  5540. //A node's state is undetermined if some but not all of it's children are checked/selected .
  5541. var undetermined = selectedChildrenIds.length > 0 && selectedChildrenIds.length < node.children.length;
  5542. if(node.original && node.original.state && node.original.state.undetermined) {
  5543. node.original.state.undetermined = undetermined;
  5544. }
  5545. //If a node is undetermined then remove selected class
  5546. if (undetermined) {
  5547. node.state[ t ? 'selected' : 'checked' ] = false;
  5548. dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
  5549. }
  5550. //Otherwise, if the checkedState === true (i.e. the node is being checked now) and all of the node's children are checked (if it has any children),
  5551. //check the node and style it correctly.
  5552. else if (checkedState && selectedChildrenIds.length === node.children.length) {
  5553. node.state[ t ? 'selected' : 'checked' ] = checkedState;
  5554. selectedNodeIds.push(node.id);
  5555. dom.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5556. }
  5557. else {
  5558. node.state[ t ? 'selected' : 'checked' ] = false;
  5559. dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
  5560. }
  5561. }
  5562. else {
  5563. selectedChildIds = this.get_checked_descendants(id);
  5564. if (node.state[ t ? 'selected' : 'checked' ]) {
  5565. selectedChildIds.push(node.id);
  5566. }
  5567. selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
  5568. }
  5569. return selectedNodeIds;
  5570. };
  5571. /**
  5572. * Gets ids of nodes selected in branch (of tree) specified by id (does not include the node specified by id)
  5573. * @name get_checked_descendants(obj)
  5574. * @param {string} id the node ID
  5575. * @return {Array} array of IDs
  5576. * @plugin checkbox
  5577. */
  5578. this.get_checked_descendants = function (id) {
  5579. var self = this;
  5580. var t = self.settings.checkbox.tie_selection;
  5581. var node = self._model.data[id];
  5582. return node.children_d.filter(function(_id) {
  5583. return self._model.data[_id].state[ t ? 'selected' : 'checked' ];
  5584. });
  5585. };
  5586. /**
  5587. * check a node (only if tie_selection in checkbox settings is false, otherwise select_node will be called internally)
  5588. * @name check_node(obj)
  5589. * @param {mixed} obj an array can be used to check multiple nodes
  5590. * @trigger check_node.jstree
  5591. * @plugin checkbox
  5592. */
  5593. this.check_node = function (obj, e) {
  5594. if(this.settings.checkbox.tie_selection) { return this.select_node(obj, false, true, e); }
  5595. var dom, t1, t2, th;
  5596. if($.isArray(obj)) {
  5597. obj = obj.slice();
  5598. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  5599. this.check_node(obj[t1], e);
  5600. }
  5601. return true;
  5602. }
  5603. obj = this.get_node(obj);
  5604. if(!obj || obj.id === $.jstree.root) {
  5605. return false;
  5606. }
  5607. dom = this.get_node(obj, true);
  5608. if(!obj.state.checked) {
  5609. obj.state.checked = true;
  5610. this._data.checkbox.selected.push(obj.id);
  5611. if(dom && dom.length) {
  5612. dom.children('.jstree-anchor').addClass('jstree-checked');
  5613. }
  5614. /**
  5615. * triggered when an node is checked (only if tie_selection in checkbox settings is false)
  5616. * @event
  5617. * @name check_node.jstree
  5618. * @param {Object} node
  5619. * @param {Array} selected the current selection
  5620. * @param {Object} event the event (if any) that triggered this check_node
  5621. * @plugin checkbox
  5622. */
  5623. this.trigger('check_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
  5624. }
  5625. };
  5626. /**
  5627. * uncheck a node (only if tie_selection in checkbox settings is false, otherwise deselect_node will be called internally)
  5628. * @name uncheck_node(obj)
  5629. * @param {mixed} obj an array can be used to uncheck multiple nodes
  5630. * @trigger uncheck_node.jstree
  5631. * @plugin checkbox
  5632. */
  5633. this.uncheck_node = function (obj, e) {
  5634. if(this.settings.checkbox.tie_selection) { return this.deselect_node(obj, false, e); }
  5635. var t1, t2, dom;
  5636. if($.isArray(obj)) {
  5637. obj = obj.slice();
  5638. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  5639. this.uncheck_node(obj[t1], e);
  5640. }
  5641. return true;
  5642. }
  5643. obj = this.get_node(obj);
  5644. if(!obj || obj.id === $.jstree.root) {
  5645. return false;
  5646. }
  5647. dom = this.get_node(obj, true);
  5648. if(obj.state.checked) {
  5649. obj.state.checked = false;
  5650. this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, obj.id);
  5651. if(dom.length) {
  5652. dom.children('.jstree-anchor').removeClass('jstree-checked');
  5653. }
  5654. /**
  5655. * triggered when an node is unchecked (only if tie_selection in checkbox settings is false)
  5656. * @event
  5657. * @name uncheck_node.jstree
  5658. * @param {Object} node
  5659. * @param {Array} selected the current selection
  5660. * @param {Object} event the event (if any) that triggered this uncheck_node
  5661. * @plugin checkbox
  5662. */
  5663. this.trigger('uncheck_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
  5664. }
  5665. };
  5666. /**
  5667. * checks all nodes in the tree (only if tie_selection in checkbox settings is false, otherwise select_all will be called internally)
  5668. * @name check_all()
  5669. * @trigger check_all.jstree, changed.jstree
  5670. * @plugin checkbox
  5671. */
  5672. this.check_all = function () {
  5673. if(this.settings.checkbox.tie_selection) { return this.select_all(); }
  5674. var tmp = this._data.checkbox.selected.concat([]), i, j;
  5675. this._data.checkbox.selected = this._model.data[$.jstree.root].children_d.concat();
  5676. for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
  5677. if(this._model.data[this._data.checkbox.selected[i]]) {
  5678. this._model.data[this._data.checkbox.selected[i]].state.checked = true;
  5679. }
  5680. }
  5681. this.redraw(true);
  5682. /**
  5683. * triggered when all nodes are checked (only if tie_selection in checkbox settings is false)
  5684. * @event
  5685. * @name check_all.jstree
  5686. * @param {Array} selected the current selection
  5687. * @plugin checkbox
  5688. */
  5689. this.trigger('check_all', { 'selected' : this._data.checkbox.selected });
  5690. };
  5691. /**
  5692. * uncheck all checked nodes (only if tie_selection in checkbox settings is false, otherwise deselect_all will be called internally)
  5693. * @name uncheck_all()
  5694. * @trigger uncheck_all.jstree
  5695. * @plugin checkbox
  5696. */
  5697. this.uncheck_all = function () {
  5698. if(this.settings.checkbox.tie_selection) { return this.deselect_all(); }
  5699. var tmp = this._data.checkbox.selected.concat([]), i, j;
  5700. for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
  5701. if(this._model.data[this._data.checkbox.selected[i]]) {
  5702. this._model.data[this._data.checkbox.selected[i]].state.checked = false;
  5703. }
  5704. }
  5705. this._data.checkbox.selected = [];
  5706. this.element.find('.jstree-checked').removeClass('jstree-checked');
  5707. /**
  5708. * triggered when all nodes are unchecked (only if tie_selection in checkbox settings is false)
  5709. * @event
  5710. * @name uncheck_all.jstree
  5711. * @param {Object} node the previous selection
  5712. * @param {Array} selected the current selection
  5713. * @plugin checkbox
  5714. */
  5715. this.trigger('uncheck_all', { 'selected' : this._data.checkbox.selected, 'node' : tmp });
  5716. };
  5717. /**
  5718. * checks if a node is checked (if tie_selection is on in the settings this function will return the same as is_selected)
  5719. * @name is_checked(obj)
  5720. * @param {mixed} obj
  5721. * @return {Boolean}
  5722. * @plugin checkbox
  5723. */
  5724. this.is_checked = function (obj) {
  5725. if(this.settings.checkbox.tie_selection) { return this.is_selected(obj); }
  5726. obj = this.get_node(obj);
  5727. if(!obj || obj.id === $.jstree.root) { return false; }
  5728. return obj.state.checked;
  5729. };
  5730. /**
  5731. * get an array of all checked nodes (if tie_selection is on in the settings this function will return the same as get_selected)
  5732. * @name get_checked([full])
  5733. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  5734. * @return {Array}
  5735. * @plugin checkbox
  5736. */
  5737. this.get_checked = function (full) {
  5738. if(this.settings.checkbox.tie_selection) { return this.get_selected(full); }
  5739. return full ? $.map(this._data.checkbox.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.checkbox.selected;
  5740. };
  5741. /**
  5742. * get an array of all top level checked nodes (ignoring children of checked nodes) (if tie_selection is on in the settings this function will return the same as get_top_selected)
  5743. * @name get_top_checked([full])
  5744. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  5745. * @return {Array}
  5746. * @plugin checkbox
  5747. */
  5748. this.get_top_checked = function (full) {
  5749. if(this.settings.checkbox.tie_selection) { return this.get_top_selected(full); }
  5750. var tmp = this.get_checked(true),
  5751. obj = {}, i, j, k, l;
  5752. for(i = 0, j = tmp.length; i < j; i++) {
  5753. obj[tmp[i].id] = tmp[i];
  5754. }
  5755. for(i = 0, j = tmp.length; i < j; i++) {
  5756. for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
  5757. if(obj[tmp[i].children_d[k]]) {
  5758. delete obj[tmp[i].children_d[k]];
  5759. }
  5760. }
  5761. }
  5762. tmp = [];
  5763. for(i in obj) {
  5764. if(obj.hasOwnProperty(i)) {
  5765. tmp.push(i);
  5766. }
  5767. }
  5768. return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
  5769. };
  5770. /**
  5771. * get an array of all bottom level checked nodes (ignoring selected parents) (if tie_selection is on in the settings this function will return the same as get_bottom_selected)
  5772. * @name get_bottom_checked([full])
  5773. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  5774. * @return {Array}
  5775. * @plugin checkbox
  5776. */
  5777. this.get_bottom_checked = function (full) {
  5778. if(this.settings.checkbox.tie_selection) { return this.get_bottom_selected(full); }
  5779. var tmp = this.get_checked(true),
  5780. obj = [], i, j;
  5781. for(i = 0, j = tmp.length; i < j; i++) {
  5782. if(!tmp[i].children.length) {
  5783. obj.push(tmp[i].id);
  5784. }
  5785. }
  5786. return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
  5787. };
  5788. this.load_node = function (obj, callback) {
  5789. var k, l, i, j, c, tmp;
  5790. if(!$.isArray(obj) && !this.settings.checkbox.tie_selection) {
  5791. tmp = this.get_node(obj);
  5792. if(tmp && tmp.state.loaded) {
  5793. for(k = 0, l = tmp.children_d.length; k < l; k++) {
  5794. if(this._model.data[tmp.children_d[k]].state.checked) {
  5795. c = true;
  5796. this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, tmp.children_d[k]);
  5797. }
  5798. }
  5799. }
  5800. }
  5801. return parent.load_node.apply(this, arguments);
  5802. };
  5803. this.get_state = function () {
  5804. var state = parent.get_state.apply(this, arguments);
  5805. if(this.settings.checkbox.tie_selection) { return state; }
  5806. state.checkbox = this._data.checkbox.selected.slice();
  5807. return state;
  5808. };
  5809. this.set_state = function (state, callback) {
  5810. var res = parent.set_state.apply(this, arguments);
  5811. if(res && state.checkbox) {
  5812. if(!this.settings.checkbox.tie_selection) {
  5813. this.uncheck_all();
  5814. var _this = this;
  5815. $.each(state.checkbox, function (i, v) {
  5816. _this.check_node(v);
  5817. });
  5818. }
  5819. delete state.checkbox;
  5820. this.set_state(state, callback);
  5821. return false;
  5822. }
  5823. return res;
  5824. };
  5825. this.refresh = function (skip_loading, forget_state) {
  5826. if(!this.settings.checkbox.tie_selection) {
  5827. this._data.checkbox.selected = [];
  5828. }
  5829. return parent.refresh.apply(this, arguments);
  5830. };
  5831. };
  5832. // include the checkbox plugin by default
  5833. // $.jstree.defaults.plugins.push("checkbox");
  5834. /**
  5835. * ### Conditionalselect plugin
  5836. *
  5837. * This plugin allows defining a callback to allow or deny node selection by user input (activate node method).
  5838. */
  5839. /**
  5840. * a callback (function) which is invoked in the instance's scope and receives two arguments - the node and the event that triggered the `activate_node` call. Returning false prevents working with the node, returning true allows invoking activate_node. Defaults to returning `true`.
  5841. * @name $.jstree.defaults.checkbox.visible
  5842. * @plugin checkbox
  5843. */
  5844. $.jstree.defaults.conditionalselect = function () { return true; };
  5845. $.jstree.plugins.conditionalselect = function (options, parent) {
  5846. // own function
  5847. this.activate_node = function (obj, e) {
  5848. if(this.settings.conditionalselect.call(this, this.get_node(obj), e)) {
  5849. return parent.activate_node.call(this, obj, e);
  5850. }
  5851. };
  5852. };
  5853. /**
  5854. * ### Contextmenu plugin
  5855. *
  5856. * Shows a context menu when a node is right-clicked.
  5857. */
  5858. /**
  5859. * stores all defaults for the contextmenu plugin
  5860. * @name $.jstree.defaults.contextmenu
  5861. * @plugin contextmenu
  5862. */
  5863. $.jstree.defaults.contextmenu = {
  5864. /**
  5865. * a boolean indicating if the node should be selected when the context menu is invoked on it. Defaults to `true`.
  5866. * @name $.jstree.defaults.contextmenu.select_node
  5867. * @plugin contextmenu
  5868. */
  5869. select_node : true,
  5870. /**
  5871. * a boolean indicating if the menu should be shown aligned with the node. Defaults to `true`, otherwise the mouse coordinates are used.
  5872. * @name $.jstree.defaults.contextmenu.show_at_node
  5873. * @plugin contextmenu
  5874. */
  5875. show_at_node : true,
  5876. /**
  5877. * an object of actions, or a function that accepts a node and a callback function and calls the callback function with an object of actions available for that node (you can also return the items too).
  5878. *
  5879. * Each action consists of a key (a unique name) and a value which is an object with the following properties (only label and action are required). Once a menu item is activated the `action` function will be invoked with an object containing the following keys: item - the contextmenu item definition as seen below, reference - the DOM node that was used (the tree node), element - the contextmenu DOM element, position - an object with x/y properties indicating the position of the menu.
  5880. *
  5881. * * `separator_before` - a boolean indicating if there should be a separator before this item
  5882. * * `separator_after` - a boolean indicating if there should be a separator after this item
  5883. * * `_disabled` - a boolean indicating if this action should be disabled
  5884. * * `label` - a string - the name of the action (could be a function returning a string)
  5885. * * `title` - a string - an optional tooltip for the item
  5886. * * `action` - a function to be executed if this item is chosen, the function will receive
  5887. * * `icon` - a string, can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
  5888. * * `shortcut` - keyCode which will trigger the action if the menu is open (for example `113` for rename, which equals F2)
  5889. * * `shortcut_label` - shortcut label (like for example `F2` for rename)
  5890. * * `submenu` - an object with the same structure as $.jstree.defaults.contextmenu.items which can be used to create a submenu - each key will be rendered as a separate option in a submenu that will appear once the current item is hovered
  5891. *
  5892. * @name $.jstree.defaults.contextmenu.items
  5893. * @plugin contextmenu
  5894. */
  5895. items : function (o, cb) { // Could be an object directly
  5896. return {
  5897. "create" : {
  5898. "separator_before" : false,
  5899. "separator_after" : true,
  5900. "_disabled" : false, //(this.check("create_node", data.reference, {}, "last")),
  5901. "label" : "Create",
  5902. "action" : function (data) {
  5903. var inst = $.jstree.reference(data.reference),
  5904. obj = inst.get_node(data.reference);
  5905. inst.create_node(obj, {}, "last", function (new_node) {
  5906. try {
  5907. inst.edit(new_node);
  5908. } catch (ex) {
  5909. setTimeout(function () { inst.edit(new_node); },0);
  5910. }
  5911. });
  5912. }
  5913. },
  5914. "rename" : {
  5915. "separator_before" : false,
  5916. "separator_after" : false,
  5917. "_disabled" : false, //(this.check("rename_node", data.reference, this.get_parent(data.reference), "")),
  5918. "label" : "Rename",
  5919. /*!
  5920. "shortcut" : 113,
  5921. "shortcut_label" : 'F2',
  5922. "icon" : "glyphicon glyphicon-leaf",
  5923. */
  5924. "action" : function (data) {
  5925. var inst = $.jstree.reference(data.reference),
  5926. obj = inst.get_node(data.reference);
  5927. inst.edit(obj);
  5928. }
  5929. },
  5930. "remove" : {
  5931. "separator_before" : false,
  5932. "icon" : false,
  5933. "separator_after" : false,
  5934. "_disabled" : false, //(this.check("delete_node", data.reference, this.get_parent(data.reference), "")),
  5935. "label" : "Delete",
  5936. "action" : function (data) {
  5937. var inst = $.jstree.reference(data.reference),
  5938. obj = inst.get_node(data.reference);
  5939. if(inst.is_selected(obj)) {
  5940. inst.delete_node(inst.get_selected());
  5941. }
  5942. else {
  5943. inst.delete_node(obj);
  5944. }
  5945. }
  5946. },
  5947. "ccp" : {
  5948. "separator_before" : true,
  5949. "icon" : false,
  5950. "separator_after" : false,
  5951. "label" : "Edit",
  5952. "action" : false,
  5953. "submenu" : {
  5954. "cut" : {
  5955. "separator_before" : false,
  5956. "separator_after" : false,
  5957. "label" : "Cut",
  5958. "action" : function (data) {
  5959. var inst = $.jstree.reference(data.reference),
  5960. obj = inst.get_node(data.reference);
  5961. if(inst.is_selected(obj)) {
  5962. inst.cut(inst.get_top_selected());
  5963. }
  5964. else {
  5965. inst.cut(obj);
  5966. }
  5967. }
  5968. },
  5969. "copy" : {
  5970. "separator_before" : false,
  5971. "icon" : false,
  5972. "separator_after" : false,
  5973. "label" : "Copy",
  5974. "action" : function (data) {
  5975. var inst = $.jstree.reference(data.reference),
  5976. obj = inst.get_node(data.reference);
  5977. if(inst.is_selected(obj)) {
  5978. inst.copy(inst.get_top_selected());
  5979. }
  5980. else {
  5981. inst.copy(obj);
  5982. }
  5983. }
  5984. },
  5985. "paste" : {
  5986. "separator_before" : false,
  5987. "icon" : false,
  5988. "_disabled" : function (data) {
  5989. return !$.jstree.reference(data.reference).can_paste();
  5990. },
  5991. "separator_after" : false,
  5992. "label" : "Paste",
  5993. "action" : function (data) {
  5994. var inst = $.jstree.reference(data.reference),
  5995. obj = inst.get_node(data.reference);
  5996. inst.paste(obj);
  5997. }
  5998. }
  5999. }
  6000. }
  6001. };
  6002. }
  6003. };
  6004. $.jstree.plugins.contextmenu = function (options, parent) {
  6005. this.bind = function () {
  6006. parent.bind.call(this);
  6007. var last_ts = 0, cto = null, ex, ey;
  6008. this.element
  6009. .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
  6010. this.get_container_ul().addClass('jstree-contextmenu');
  6011. }, this))
  6012. .on("contextmenu.jstree", ".jstree-anchor", $.proxy(function (e, data) {
  6013. if (e.target.tagName.toLowerCase() === 'input') {
  6014. return;
  6015. }
  6016. e.preventDefault();
  6017. last_ts = e.ctrlKey ? +new Date() : 0;
  6018. if(data || cto) {
  6019. last_ts = (+new Date()) + 10000;
  6020. }
  6021. if(cto) {
  6022. clearTimeout(cto);
  6023. }
  6024. if(!this.is_loading(e.currentTarget)) {
  6025. this.show_contextmenu(e.currentTarget, e.pageX, e.pageY, e);
  6026. }
  6027. }, this))
  6028. .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
  6029. if(this._data.contextmenu.visible && (!last_ts || (+new Date()) - last_ts > 250)) { // work around safari & macOS ctrl+click
  6030. $.vakata.context.hide();
  6031. }
  6032. last_ts = 0;
  6033. }, this))
  6034. .on("touchstart.jstree", ".jstree-anchor", function (e) {
  6035. if(!e.originalEvent || !e.originalEvent.changedTouches || !e.originalEvent.changedTouches[0]) {
  6036. return;
  6037. }
  6038. ex = e.originalEvent.changedTouches[0].clientX;
  6039. ey = e.originalEvent.changedTouches[0].clientY;
  6040. cto = setTimeout(function () {
  6041. $(e.currentTarget).trigger('contextmenu', true);
  6042. }, 750);
  6043. })
  6044. .on('touchmove.vakata.jstree', function (e) {
  6045. if(cto && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0] && (Math.abs(ex - e.originalEvent.changedTouches[0].clientX) > 10 || Math.abs(ey - e.originalEvent.changedTouches[0].clientY) > 10)) {
  6046. clearTimeout(cto);
  6047. $.vakata.context.hide();
  6048. }
  6049. })
  6050. .on('touchend.vakata.jstree', function (e) {
  6051. if(cto) {
  6052. clearTimeout(cto);
  6053. }
  6054. });
  6055. /*!
  6056. if(!('oncontextmenu' in document.body) && ('ontouchstart' in document.body)) {
  6057. var el = null, tm = null;
  6058. this.element
  6059. .on("touchstart", ".jstree-anchor", function (e) {
  6060. el = e.currentTarget;
  6061. tm = +new Date();
  6062. $(document).one("touchend", function (e) {
  6063. e.target = document.elementFromPoint(e.originalEvent.targetTouches[0].pageX - window.pageXOffset, e.originalEvent.targetTouches[0].pageY - window.pageYOffset);
  6064. e.currentTarget = e.target;
  6065. tm = ((+(new Date())) - tm);
  6066. if(e.target === el && tm > 600 && tm < 1000) {
  6067. e.preventDefault();
  6068. $(el).trigger('contextmenu', e);
  6069. }
  6070. el = null;
  6071. tm = null;
  6072. });
  6073. });
  6074. }
  6075. */
  6076. $(document).on("context_hide.vakata.jstree", $.proxy(function (e, data) {
  6077. this._data.contextmenu.visible = false;
  6078. $(data.reference).removeClass('jstree-context');
  6079. }, this));
  6080. };
  6081. this.teardown = function () {
  6082. if(this._data.contextmenu.visible) {
  6083. $.vakata.context.hide();
  6084. }
  6085. parent.teardown.call(this);
  6086. };
  6087. /**
  6088. * prepare and show the context menu for a node
  6089. * @name show_contextmenu(obj [, x, y])
  6090. * @param {mixed} obj the node
  6091. * @param {Number} x the x-coordinate relative to the document to show the menu at
  6092. * @param {Number} y the y-coordinate relative to the document to show the menu at
  6093. * @param {Object} e the event if available that triggered the contextmenu
  6094. * @plugin contextmenu
  6095. * @trigger show_contextmenu.jstree
  6096. */
  6097. this.show_contextmenu = function (obj, x, y, e) {
  6098. obj = this.get_node(obj);
  6099. if(!obj || obj.id === $.jstree.root) { return false; }
  6100. var s = this.settings.contextmenu,
  6101. d = this.get_node(obj, true),
  6102. a = d.children(".jstree-anchor"),
  6103. o = false,
  6104. i = false;
  6105. if(s.show_at_node || x === undefined || y === undefined) {
  6106. o = a.offset();
  6107. x = o.left;
  6108. y = o.top + this._data.core.li_height;
  6109. }
  6110. if(this.settings.contextmenu.select_node && !this.is_selected(obj)) {
  6111. this.activate_node(obj, e);
  6112. }
  6113. i = s.items;
  6114. if($.isFunction(i)) {
  6115. i = i.call(this, obj, $.proxy(function (i) {
  6116. this._show_contextmenu(obj, x, y, i);
  6117. }, this));
  6118. }
  6119. if($.isPlainObject(i)) {
  6120. this._show_contextmenu(obj, x, y, i);
  6121. }
  6122. };
  6123. /**
  6124. * show the prepared context menu for a node
  6125. * @name _show_contextmenu(obj, x, y, i)
  6126. * @param {mixed} obj the node
  6127. * @param {Number} x the x-coordinate relative to the document to show the menu at
  6128. * @param {Number} y the y-coordinate relative to the document to show the menu at
  6129. * @param {Number} i the object of items to show
  6130. * @plugin contextmenu
  6131. * @trigger show_contextmenu.jstree
  6132. * @private
  6133. */
  6134. this._show_contextmenu = function (obj, x, y, i) {
  6135. var d = this.get_node(obj, true),
  6136. a = d.children(".jstree-anchor");
  6137. $(document).one("context_show.vakata.jstree", $.proxy(function (e, data) {
  6138. var cls = 'jstree-contextmenu jstree-' + this.get_theme() + '-contextmenu';
  6139. $(data.element).addClass(cls);
  6140. a.addClass('jstree-context');
  6141. }, this));
  6142. this._data.contextmenu.visible = true;
  6143. $.vakata.context.show(a, { 'x' : x, 'y' : y }, i);
  6144. /**
  6145. * triggered when the contextmenu is shown for a node
  6146. * @event
  6147. * @name show_contextmenu.jstree
  6148. * @param {Object} node the node
  6149. * @param {Number} x the x-coordinate of the menu relative to the document
  6150. * @param {Number} y the y-coordinate of the menu relative to the document
  6151. * @plugin contextmenu
  6152. */
  6153. this.trigger('show_contextmenu', { "node" : obj, "x" : x, "y" : y });
  6154. };
  6155. };
  6156. // contextmenu helper
  6157. (function ($) {
  6158. var right_to_left = false,
  6159. vakata_context = {
  6160. element : false,
  6161. reference : false,
  6162. position_x : 0,
  6163. position_y : 0,
  6164. items : [],
  6165. html : "",
  6166. is_visible : false
  6167. };
  6168. $.vakata.context = {
  6169. settings : {
  6170. hide_onmouseleave : 0,
  6171. icons : true
  6172. },
  6173. _trigger : function (event_name) {
  6174. $(document).triggerHandler("context_" + event_name + ".vakata", {
  6175. "reference" : vakata_context.reference,
  6176. "element" : vakata_context.element,
  6177. "position" : {
  6178. "x" : vakata_context.position_x,
  6179. "y" : vakata_context.position_y
  6180. }
  6181. });
  6182. },
  6183. _execute : function (i) {
  6184. i = vakata_context.items[i];
  6185. return i && (!i._disabled || ($.isFunction(i._disabled) && !i._disabled({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }))) && i.action ? i.action.call(null, {
  6186. "item" : i,
  6187. "reference" : vakata_context.reference,
  6188. "element" : vakata_context.element,
  6189. "position" : {
  6190. "x" : vakata_context.position_x,
  6191. "y" : vakata_context.position_y
  6192. }
  6193. }) : false;
  6194. },
  6195. _parse : function (o, is_callback) {
  6196. if(!o) { return false; }
  6197. if(!is_callback) {
  6198. vakata_context.html = "";
  6199. vakata_context.items = [];
  6200. }
  6201. var str = "",
  6202. sep = false,
  6203. tmp;
  6204. if(is_callback) { str += "<"+"ul>"; }
  6205. $.each(o, function (i, val) {
  6206. if(!val) { return true; }
  6207. vakata_context.items.push(val);
  6208. if(!sep && val.separator_before) {
  6209. str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
  6210. }
  6211. sep = false;
  6212. str += "<"+"li class='" + (val._class || "") + (val._disabled === true || ($.isFunction(val._disabled) && val._disabled({ "item" : val, "reference" : vakata_context.reference, "element" : vakata_context.element })) ? " vakata-contextmenu-disabled " : "") + "' "+(val.shortcut?" data-shortcut='"+val.shortcut+"' ":'')+">";
  6213. str += "<"+"a href='#' rel='" + (vakata_context.items.length - 1) + "' " + (val.title ? "title='" + val.title + "'" : "") + ">";
  6214. if($.vakata.context.settings.icons) {
  6215. str += "<"+"i ";
  6216. if(val.icon) {
  6217. if(val.icon.indexOf("/") !== -1 || val.icon.indexOf(".") !== -1) { str += " style='background:url(\"" + val.icon + "\") center center no-repeat' "; }
  6218. else { str += " class='" + val.icon + "' "; }
  6219. }
  6220. str += "><"+"/i><"+"span class='vakata-contextmenu-sep'>&#160;<"+"/span>";
  6221. }
  6222. str += ($.isFunction(val.label) ? val.label({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }) : val.label) + (val.shortcut?' <span class="vakata-contextmenu-shortcut vakata-contextmenu-shortcut-'+val.shortcut+'">'+ (val.shortcut_label || '') +'</span>':'') + "<"+"/a>";
  6223. if(val.submenu) {
  6224. tmp = $.vakata.context._parse(val.submenu, true);
  6225. if(tmp) { str += tmp; }
  6226. }
  6227. str += "<"+"/li>";
  6228. if(val.separator_after) {
  6229. str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
  6230. sep = true;
  6231. }
  6232. });
  6233. str = str.replace(/<li class\='vakata-context-separator'\><\/li\>$/,"");
  6234. if(is_callback) { str += "</ul>"; }
  6235. /**
  6236. * triggered on the document when the contextmenu is parsed (HTML is built)
  6237. * @event
  6238. * @plugin contextmenu
  6239. * @name context_parse.vakata
  6240. * @param {jQuery} reference the element that was right clicked
  6241. * @param {jQuery} element the DOM element of the menu itself
  6242. * @param {Object} position the x & y coordinates of the menu
  6243. */
  6244. if(!is_callback) { vakata_context.html = str; $.vakata.context._trigger("parse"); }
  6245. return str.length > 10 ? str : false;
  6246. },
  6247. _show_submenu : function (o) {
  6248. o = $(o);
  6249. if(!o.length || !o.children("ul").length) { return; }
  6250. var e = o.children("ul"),
  6251. xl = o.offset().left,
  6252. x = xl + o.outerWidth(),
  6253. y = o.offset().top,
  6254. w = e.width(),
  6255. h = e.height(),
  6256. dw = $(window).width() + $(window).scrollLeft(),
  6257. dh = $(window).height() + $(window).scrollTop();
  6258. // може да се спести е една проверка - дали няма някой от класовете вече нагоре
  6259. if(right_to_left) {
  6260. o[x - (w + 10 + o.outerWidth()) < 0 ? "addClass" : "removeClass"]("vakata-context-left");
  6261. }
  6262. else {
  6263. o[x + w > dw && xl > dw - x ? "addClass" : "removeClass"]("vakata-context-right");
  6264. }
  6265. if(y + h + 10 > dh) {
  6266. e.css("bottom","-1px");
  6267. }
  6268. //if does not fit - stick it to the side
  6269. if (o.hasClass('vakata-context-right')) {
  6270. if (xl < w) {
  6271. e.css("margin-right", xl - w);
  6272. }
  6273. } else {
  6274. if (dw - x < w) {
  6275. e.css("margin-left", dw - x - w);
  6276. }
  6277. }
  6278. e.show();
  6279. },
  6280. show : function (reference, position, data) {
  6281. var o, e, x, y, w, h, dw, dh, cond = true;
  6282. if(vakata_context.element && vakata_context.element.length) {
  6283. vakata_context.element.width('');
  6284. }
  6285. switch(cond) {
  6286. case (!position && !reference):
  6287. return false;
  6288. case (!!position && !!reference):
  6289. vakata_context.reference = reference;
  6290. vakata_context.position_x = position.x;
  6291. vakata_context.position_y = position.y;
  6292. break;
  6293. case (!position && !!reference):
  6294. vakata_context.reference = reference;
  6295. o = reference.offset();
  6296. vakata_context.position_x = o.left + reference.outerHeight();
  6297. vakata_context.position_y = o.top;
  6298. break;
  6299. case (!!position && !reference):
  6300. vakata_context.position_x = position.x;
  6301. vakata_context.position_y = position.y;
  6302. break;
  6303. }
  6304. if(!!reference && !data && $(reference).data('vakata_contextmenu')) {
  6305. data = $(reference).data('vakata_contextmenu');
  6306. }
  6307. if($.vakata.context._parse(data)) {
  6308. vakata_context.element.html(vakata_context.html);
  6309. }
  6310. if(vakata_context.items.length) {
  6311. vakata_context.element.appendTo("body");
  6312. e = vakata_context.element;
  6313. x = vakata_context.position_x;
  6314. y = vakata_context.position_y;
  6315. w = e.width();
  6316. h = e.height();
  6317. dw = $(window).width() + $(window).scrollLeft();
  6318. dh = $(window).height() + $(window).scrollTop();
  6319. if(right_to_left) {
  6320. x -= (e.outerWidth() - $(reference).outerWidth());
  6321. if(x < $(window).scrollLeft() + 20) {
  6322. x = $(window).scrollLeft() + 20;
  6323. }
  6324. }
  6325. if(x + w + 20 > dw) {
  6326. x = dw - (w + 20);
  6327. }
  6328. if(y + h + 20 > dh) {
  6329. y = dh - (h + 20);
  6330. }
  6331. vakata_context.element
  6332. .css({ "left" : x, "top" : y })
  6333. .show()
  6334. .find('a').first().focus().parent().addClass("vakata-context-hover");
  6335. vakata_context.is_visible = true;
  6336. /**
  6337. * triggered on the document when the contextmenu is shown
  6338. * @event
  6339. * @plugin contextmenu
  6340. * @name context_show.vakata
  6341. * @param {jQuery} reference the element that was right clicked
  6342. * @param {jQuery} element the DOM element of the menu itself
  6343. * @param {Object} position the x & y coordinates of the menu
  6344. */
  6345. $.vakata.context._trigger("show");
  6346. }
  6347. },
  6348. hide : function () {
  6349. if(vakata_context.is_visible) {
  6350. vakata_context.element.hide().find("ul").hide().end().find(':focus').blur().end().detach();
  6351. vakata_context.is_visible = false;
  6352. /**
  6353. * triggered on the document when the contextmenu is hidden
  6354. * @event
  6355. * @plugin contextmenu
  6356. * @name context_hide.vakata
  6357. * @param {jQuery} reference the element that was right clicked
  6358. * @param {jQuery} element the DOM element of the menu itself
  6359. * @param {Object} position the x & y coordinates of the menu
  6360. */
  6361. $.vakata.context._trigger("hide");
  6362. }
  6363. }
  6364. };
  6365. $(function () {
  6366. right_to_left = $("body").css("direction") === "rtl";
  6367. var to = false;
  6368. vakata_context.element = $("<ul class='vakata-context'></ul>");
  6369. vakata_context.element
  6370. .on("mouseenter", "li", function (e) {
  6371. e.stopImmediatePropagation();
  6372. if($.contains(this, e.relatedTarget)) {
  6373. // премахнато заради delegate mouseleave по-долу
  6374. // $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
  6375. return;
  6376. }
  6377. if(to) { clearTimeout(to); }
  6378. vakata_context.element.find(".vakata-context-hover").removeClass("vakata-context-hover").end();
  6379. $(this)
  6380. .siblings().find("ul").hide().end().end()
  6381. .parentsUntil(".vakata-context", "li").addBack().addClass("vakata-context-hover");
  6382. $.vakata.context._show_submenu(this);
  6383. })
  6384. // тестово - дали не натоварва?
  6385. .on("mouseleave", "li", function (e) {
  6386. if($.contains(this, e.relatedTarget)) { return; }
  6387. $(this).find(".vakata-context-hover").addBack().removeClass("vakata-context-hover");
  6388. })
  6389. .on("mouseleave", function (e) {
  6390. $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
  6391. if($.vakata.context.settings.hide_onmouseleave) {
  6392. to = setTimeout(
  6393. (function (t) {
  6394. return function () { $.vakata.context.hide(); };
  6395. }(this)), $.vakata.context.settings.hide_onmouseleave);
  6396. }
  6397. })
  6398. .on("click", "a", function (e) {
  6399. e.preventDefault();
  6400. //})
  6401. //.on("mouseup", "a", function (e) {
  6402. if(!$(this).blur().parent().hasClass("vakata-context-disabled") && $.vakata.context._execute($(this).attr("rel")) !== false) {
  6403. $.vakata.context.hide();
  6404. }
  6405. })
  6406. .on('keydown', 'a', function (e) {
  6407. var o = null;
  6408. switch(e.which) {
  6409. case 13:
  6410. case 32:
  6411. e.type = "click";
  6412. e.preventDefault();
  6413. $(e.currentTarget).trigger(e);
  6414. break;
  6415. case 37:
  6416. if(vakata_context.is_visible) {
  6417. vakata_context.element.find(".vakata-context-hover").last().closest("li").first().find("ul").hide().find(".vakata-context-hover").removeClass("vakata-context-hover").end().end().children('a').focus();
  6418. e.stopImmediatePropagation();
  6419. e.preventDefault();
  6420. }
  6421. break;
  6422. case 38:
  6423. if(vakata_context.is_visible) {
  6424. o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").prevAll("li:not(.vakata-context-separator)").first();
  6425. if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").last(); }
  6426. o.addClass("vakata-context-hover").children('a').focus();
  6427. e.stopImmediatePropagation();
  6428. e.preventDefault();
  6429. }
  6430. break;
  6431. case 39:
  6432. if(vakata_context.is_visible) {
  6433. vakata_context.element.find(".vakata-context-hover").last().children("ul").show().children("li:not(.vakata-context-separator)").removeClass("vakata-context-hover").first().addClass("vakata-context-hover").children('a').focus();
  6434. e.stopImmediatePropagation();
  6435. e.preventDefault();
  6436. }
  6437. break;
  6438. case 40:
  6439. if(vakata_context.is_visible) {
  6440. o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").nextAll("li:not(.vakata-context-separator)").first();
  6441. if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").first(); }
  6442. o.addClass("vakata-context-hover").children('a').focus();
  6443. e.stopImmediatePropagation();
  6444. e.preventDefault();
  6445. }
  6446. break;
  6447. case 27:
  6448. $.vakata.context.hide();
  6449. e.preventDefault();
  6450. break;
  6451. default:
  6452. //console.log(e.which);
  6453. break;
  6454. }
  6455. })
  6456. .on('keydown', function (e) {
  6457. e.preventDefault();
  6458. var a = vakata_context.element.find('.vakata-contextmenu-shortcut-' + e.which).parent();
  6459. if(a.parent().not('.vakata-context-disabled')) {
  6460. a.click();
  6461. }
  6462. });
  6463. $(document)
  6464. .on("mousedown.vakata.jstree", function (e) {
  6465. if(vakata_context.is_visible && vakata_context.element[0] !== e.target && !$.contains(vakata_context.element[0], e.target)) {
  6466. $.vakata.context.hide();
  6467. }
  6468. })
  6469. .on("context_show.vakata.jstree", function (e, data) {
  6470. vakata_context.element.find("li:has(ul)").children("a").addClass("vakata-context-parent");
  6471. if(right_to_left) {
  6472. vakata_context.element.addClass("vakata-context-rtl").css("direction", "rtl");
  6473. }
  6474. // also apply a RTL class?
  6475. vakata_context.element.find("ul").hide().end();
  6476. });
  6477. });
  6478. }($));
  6479. // $.jstree.defaults.plugins.push("contextmenu");
  6480. /**
  6481. * ### Drag'n'drop plugin
  6482. *
  6483. * Enables dragging and dropping of nodes in the tree, resulting in a move or copy operations.
  6484. */
  6485. /**
  6486. * stores all defaults for the drag'n'drop plugin
  6487. * @name $.jstree.defaults.dnd
  6488. * @plugin dnd
  6489. */
  6490. $.jstree.defaults.dnd = {
  6491. /**
  6492. * a boolean indicating if a copy should be possible while dragging (by pressint the meta key or Ctrl). Defaults to `true`.
  6493. * @name $.jstree.defaults.dnd.copy
  6494. * @plugin dnd
  6495. */
  6496. copy : true,
  6497. /**
  6498. * a number indicating how long a node should remain hovered while dragging to be opened. Defaults to `500`.
  6499. * @name $.jstree.defaults.dnd.open_timeout
  6500. * @plugin dnd
  6501. */
  6502. open_timeout : 500,
  6503. /**
  6504. * a function invoked each time a node is about to be dragged, invoked in the tree's scope and receives the nodes about to be dragged as an argument (array) and the event that started the drag - return `false` to prevent dragging
  6505. * @name $.jstree.defaults.dnd.is_draggable
  6506. * @plugin dnd
  6507. */
  6508. is_draggable : true,
  6509. /**
  6510. * a boolean indicating if checks should constantly be made while the user is dragging the node (as opposed to checking only on drop), default is `true`
  6511. * @name $.jstree.defaults.dnd.check_while_dragging
  6512. * @plugin dnd
  6513. */
  6514. check_while_dragging : true,
  6515. /**
  6516. * a boolean indicating if nodes from this tree should only be copied with dnd (as opposed to moved), default is `false`
  6517. * @name $.jstree.defaults.dnd.always_copy
  6518. * @plugin dnd
  6519. */
  6520. always_copy : false,
  6521. /**
  6522. * when dropping a node "inside", this setting indicates the position the node should go to - it can be an integer or a string: "first" (same as 0) or "last", default is `0`
  6523. * @name $.jstree.defaults.dnd.inside_pos
  6524. * @plugin dnd
  6525. */
  6526. inside_pos : 0,
  6527. /**
  6528. * when starting the drag on a node that is selected this setting controls if all selected nodes are dragged or only the single node, default is `true`, which means all selected nodes are dragged when the drag is started on a selected node
  6529. * @name $.jstree.defaults.dnd.drag_selection
  6530. * @plugin dnd
  6531. */
  6532. drag_selection : true,
  6533. /**
  6534. * controls whether dnd works on touch devices. If left as boolean true dnd will work the same as in desktop browsers, which in some cases may impair scrolling. If set to boolean false dnd will not work on touch devices. There is a special third option - string "selected" which means only selected nodes can be dragged on touch devices.
  6535. * @name $.jstree.defaults.dnd.touch
  6536. * @plugin dnd
  6537. */
  6538. touch : true,
  6539. /**
  6540. * controls whether items can be dropped anywhere on the node, not just on the anchor, by default only the node anchor is a valid drop target. Works best with the wholerow plugin. If enabled on mobile depending on the interface it might be hard for the user to cancel the drop, since the whole tree container will be a valid drop target.
  6541. * @name $.jstree.defaults.dnd.large_drop_target
  6542. * @plugin dnd
  6543. */
  6544. large_drop_target : false,
  6545. /**
  6546. * controls whether a drag can be initiated from any part of the node and not just the text/icon part, works best with the wholerow plugin. Keep in mind it can cause problems with tree scrolling on mobile depending on the interface - in that case set the touch option to "selected".
  6547. * @name $.jstree.defaults.dnd.large_drag_target
  6548. * @plugin dnd
  6549. */
  6550. large_drag_target : false,
  6551. /**
  6552. * controls whether use HTML5 dnd api instead of classical. That will allow better integration of dnd events with other HTML5 controls.
  6553. * @reference http://caniuse.com/#feat=dragndrop
  6554. * @name $.jstree.defaults.dnd.use_html5
  6555. * @plugin dnd
  6556. */
  6557. use_html5: false
  6558. };
  6559. var drg, elm;
  6560. // TODO: now check works by checking for each node individually, how about max_children, unique, etc?
  6561. $.jstree.plugins.dnd = function (options, parent) {
  6562. this.init = function (el, options) {
  6563. parent.init.call(this, el, options);
  6564. this.settings.dnd.use_html5 = this.settings.dnd.use_html5 && ('draggable' in document.createElement('span'));
  6565. };
  6566. this.bind = function () {
  6567. parent.bind.call(this);
  6568. this.element
  6569. .on(this.settings.dnd.use_html5 ? 'dragstart.jstree' : 'mousedown.jstree touchstart.jstree', this.settings.dnd.large_drag_target ? '.jstree-node' : '.jstree-anchor', $.proxy(function (e) {
  6570. if(this.settings.dnd.large_drag_target && $(e.target).closest('.jstree-node')[0] !== e.currentTarget) {
  6571. return true;
  6572. }
  6573. if(e.type === "touchstart" && (!this.settings.dnd.touch || (this.settings.dnd.touch === 'selected' && !$(e.currentTarget).closest('.jstree-node').children('.jstree-anchor').hasClass('jstree-clicked')))) {
  6574. return true;
  6575. }
  6576. var obj = this.get_node(e.target),
  6577. mlt = this.is_selected(obj) && this.settings.dnd.drag_selection ? this.get_top_selected().length : 1,
  6578. txt = (mlt > 1 ? mlt + ' ' + this.get_string('nodes') : this.get_text(e.currentTarget));
  6579. if(this.settings.core.force_text) {
  6580. txt = $.vakata.html.escape(txt);
  6581. }
  6582. if(obj && obj.id && obj.id !== $.jstree.root && (e.which === 1 || e.type === "touchstart" || e.type === "dragstart") &&
  6583. (this.settings.dnd.is_draggable === true || ($.isFunction(this.settings.dnd.is_draggable) && this.settings.dnd.is_draggable.call(this, (mlt > 1 ? this.get_top_selected(true) : [obj]), e)))
  6584. ) {
  6585. drg = { 'jstree' : true, 'origin' : this, 'obj' : this.get_node(obj,true), 'nodes' : mlt > 1 ? this.get_top_selected() : [obj.id] };
  6586. elm = e.currentTarget;
  6587. if (this.settings.dnd.use_html5) {
  6588. $.vakata.dnd._trigger('start', e, { 'helper': $(), 'element': elm, 'data': drg });
  6589. } else {
  6590. this.element.trigger('mousedown.jstree');
  6591. return $.vakata.dnd.start(e, drg, '<div id="jstree-dnd" class="jstree-' + this.get_theme() + ' jstree-' + this.get_theme() + '-' + this.get_theme_variant() + ' ' + ( this.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ) + '"><i class="jstree-icon jstree-er"></i>' + txt + '<ins class="jstree-copy" style="display:none;">+</ins></div>');
  6592. }
  6593. }
  6594. }, this));
  6595. if (this.settings.dnd.use_html5) {
  6596. this.element
  6597. .on('dragover.jstree', function (e) {
  6598. e.preventDefault();
  6599. $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
  6600. return false;
  6601. })
  6602. //.on('dragenter.jstree', this.settings.dnd.large_drop_target ? '.jstree-node' : '.jstree-anchor', $.proxy(function (e) {
  6603. // e.preventDefault();
  6604. // $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
  6605. // return false;
  6606. // }, this))
  6607. .on('drop.jstree', $.proxy(function (e) {
  6608. e.preventDefault();
  6609. $.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
  6610. return false;
  6611. }, this));
  6612. }
  6613. };
  6614. this.redraw_node = function(obj, deep, callback, force_render) {
  6615. obj = parent.redraw_node.apply(this, arguments);
  6616. if (obj && this.settings.dnd.use_html5) {
  6617. if (this.settings.dnd.large_drag_target) {
  6618. obj.setAttribute('draggable', true);
  6619. } else {
  6620. var i, j, tmp = null;
  6621. for(i = 0, j = obj.childNodes.length; i < j; i++) {
  6622. if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
  6623. tmp = obj.childNodes[i];
  6624. break;
  6625. }
  6626. }
  6627. if(tmp) {
  6628. tmp.setAttribute('draggable', true);
  6629. }
  6630. }
  6631. }
  6632. return obj;
  6633. };
  6634. };
  6635. $(function() {
  6636. // bind only once for all instances
  6637. var lastmv = false,
  6638. laster = false,
  6639. lastev = false,
  6640. opento = false,
  6641. marker = $('<div id="jstree-marker">&#160;</div>').hide(); //.appendTo('body');
  6642. $(document)
  6643. .on('dnd_start.vakata.jstree', function (e, data) {
  6644. lastmv = false;
  6645. lastev = false;
  6646. if(!data || !data.data || !data.data.jstree) { return; }
  6647. marker.appendTo('body'); //.show();
  6648. })
  6649. .on('dnd_move.vakata.jstree', function (e, data) {
  6650. var isDifferentNode = data.event.target !== lastev.target;
  6651. if(opento) {
  6652. if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
  6653. clearTimeout(opento);
  6654. }
  6655. }
  6656. if(!data || !data.data || !data.data.jstree) { return; }
  6657. // if we are hovering the marker image do nothing (can happen on "inside" drags)
  6658. if(data.event.target.id && data.event.target.id === 'jstree-marker') {
  6659. return;
  6660. }
  6661. lastev = data.event;
  6662. var ins = $.jstree.reference(data.event.target),
  6663. ref = false,
  6664. off = false,
  6665. rel = false,
  6666. tmp, l, t, h, p, i, o, ok, t1, t2, op, ps, pr, ip, tm, is_copy, pn;
  6667. // if we are over an instance
  6668. if(ins && ins._data && ins._data.dnd) {
  6669. marker.attr('class', 'jstree-' + ins.get_theme() + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ));
  6670. is_copy = data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey)));
  6671. data.helper
  6672. .children().attr('class', 'jstree-' + ins.get_theme() + ' jstree-' + ins.get_theme() + '-' + ins.get_theme_variant() + ' ' + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ))
  6673. .find('.jstree-copy').first()[ is_copy ? 'show' : 'hide' ]();
  6674. // if are hovering the container itself add a new root node
  6675. //console.log(data.event);
  6676. if( (data.event.target === ins.element[0] || data.event.target === ins.get_container_ul()[0]) && ins.get_container_ul().children().length === 0) {
  6677. ok = true;
  6678. for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
  6679. ok = ok && ins.check( (data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey)) ) ? "copy_node" : "move_node"), (data.data.origin && data.data.origin !== ins ? data.data.origin.get_node(data.data.nodes[t1]) : data.data.nodes[t1]), $.jstree.root, 'last', { 'dnd' : true, 'ref' : ins.get_node($.jstree.root), 'pos' : 'i', 'origin' : data.data.origin, 'is_multi' : (data.data.origin && data.data.origin !== ins), 'is_foreign' : (!data.data.origin) });
  6680. if(!ok) { break; }
  6681. }
  6682. if(ok) {
  6683. lastmv = { 'ins' : ins, 'par' : $.jstree.root, 'pos' : 'last' };
  6684. marker.hide();
  6685. data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
  6686. if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
  6687. data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
  6688. }
  6689. return;
  6690. }
  6691. }
  6692. else {
  6693. // if we are hovering a tree node
  6694. ref = ins.settings.dnd.large_drop_target ? $(data.event.target).closest('.jstree-node').children('.jstree-anchor') : $(data.event.target).closest('.jstree-anchor');
  6695. if(ref && ref.length && ref.parent().is('.jstree-closed, .jstree-open, .jstree-leaf')) {
  6696. off = ref.offset();
  6697. rel = (data.event.pageY !== undefined ? data.event.pageY : data.event.originalEvent.pageY) - off.top;
  6698. h = ref.outerHeight();
  6699. if(rel < h / 3) {
  6700. o = ['b', 'i', 'a'];
  6701. }
  6702. else if(rel > h - h / 3) {
  6703. o = ['a', 'i', 'b'];
  6704. }
  6705. else {
  6706. o = rel > h / 2 ? ['i', 'a', 'b'] : ['i', 'b', 'a'];
  6707. }
  6708. $.each(o, function (j, v) {
  6709. switch(v) {
  6710. case 'b':
  6711. l = off.left - 6;
  6712. t = off.top;
  6713. p = ins.get_parent(ref);
  6714. i = ref.parent().index();
  6715. break;
  6716. case 'i':
  6717. ip = ins.settings.dnd.inside_pos;
  6718. tm = ins.get_node(ref.parent());
  6719. l = off.left - 2;
  6720. t = off.top + h / 2 + 1;
  6721. p = tm.id;
  6722. i = ip === 'first' ? 0 : (ip === 'last' ? tm.children.length : Math.min(ip, tm.children.length));
  6723. break;
  6724. case 'a':
  6725. l = off.left - 6;
  6726. t = off.top + h;
  6727. p = ins.get_parent(ref);
  6728. i = ref.parent().index() + 1;
  6729. break;
  6730. }
  6731. ok = true;
  6732. for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
  6733. op = data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey))) ? "copy_node" : "move_node";
  6734. ps = i;
  6735. if(op === "move_node" && v === 'a' && (data.data.origin && data.data.origin === ins) && p === ins.get_parent(data.data.nodes[t1])) {
  6736. pr = ins.get_node(p);
  6737. if(ps > $.inArray(data.data.nodes[t1], pr.children)) {
  6738. ps -= 1;
  6739. }
  6740. }
  6741. ok = ok && ( (ins && ins.settings && ins.settings.dnd && ins.settings.dnd.check_while_dragging === false) || ins.check(op, (data.data.origin && data.data.origin !== ins ? data.data.origin.get_node(data.data.nodes[t1]) : data.data.nodes[t1]), p, ps, { 'dnd' : true, 'ref' : ins.get_node(ref.parent()), 'pos' : v, 'origin' : data.data.origin, 'is_multi' : (data.data.origin && data.data.origin !== ins), 'is_foreign' : (!data.data.origin) }) );
  6742. if(!ok) {
  6743. if(ins && ins.last_error) { laster = ins.last_error(); }
  6744. break;
  6745. }
  6746. }
  6747. if(v === 'i' && ref.parent().is('.jstree-closed') && ins.settings.dnd.open_timeout) {
  6748. if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
  6749. if (opento) { clearTimeout(opento); }
  6750. opento = setTimeout((function (x, z) { return function () { x.open_node(z); }; }(ins, ref)), ins.settings.dnd.open_timeout);
  6751. }
  6752. }
  6753. if(ok) {
  6754. pn = ins.get_node(p, true);
  6755. if (!pn.hasClass('.jstree-dnd-parent')) {
  6756. $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
  6757. pn.addClass('jstree-dnd-parent');
  6758. }
  6759. lastmv = { 'ins' : ins, 'par' : p, 'pos' : v === 'i' && ip === 'last' && i === 0 && !ins.is_loaded(tm) ? 'last' : i };
  6760. marker.css({ 'left' : l + 'px', 'top' : t + 'px' }).show();
  6761. data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
  6762. if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
  6763. data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
  6764. }
  6765. laster = {};
  6766. o = true;
  6767. return false;
  6768. }
  6769. });
  6770. if(o === true) { return; }
  6771. }
  6772. }
  6773. }
  6774. $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
  6775. lastmv = false;
  6776. data.helper.find('.jstree-icon').removeClass('jstree-ok').addClass('jstree-er');
  6777. if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
  6778. data.event.originalEvent.dataTransfer.dropEffect = 'none';
  6779. }
  6780. marker.hide();
  6781. })
  6782. .on('dnd_scroll.vakata.jstree', function (e, data) {
  6783. if(!data || !data.data || !data.data.jstree) { return; }
  6784. marker.hide();
  6785. lastmv = false;
  6786. lastev = false;
  6787. data.helper.find('.jstree-icon').first().removeClass('jstree-ok').addClass('jstree-er');
  6788. })
  6789. .on('dnd_stop.vakata.jstree', function (e, data) {
  6790. $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
  6791. if(opento) { clearTimeout(opento); }
  6792. if(!data || !data.data || !data.data.jstree) { return; }
  6793. marker.hide().detach();
  6794. var i, j, nodes = [];
  6795. if(lastmv) {
  6796. for(i = 0, j = data.data.nodes.length; i < j; i++) {
  6797. nodes[i] = data.data.origin ? data.data.origin.get_node(data.data.nodes[i]) : data.data.nodes[i];
  6798. }
  6799. lastmv.ins[ data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey))) ? 'copy_node' : 'move_node' ](nodes, lastmv.par, lastmv.pos, false, false, false, data.data.origin);
  6800. }
  6801. else {
  6802. i = $(data.event.target).closest('.jstree');
  6803. if(i.length && laster && laster.error && laster.error === 'check') {
  6804. i = i.jstree(true);
  6805. if(i) {
  6806. i.settings.core.error.call(this, laster);
  6807. }
  6808. }
  6809. }
  6810. lastev = false;
  6811. lastmv = false;
  6812. })
  6813. .on('keyup.jstree keydown.jstree', function (e, data) {
  6814. data = $.vakata.dnd._get();
  6815. if(data && data.data && data.data.jstree) {
  6816. if (e.type === "keyup" && e.which === 27) {
  6817. if (opento) { clearTimeout(opento); }
  6818. lastmv = false;
  6819. laster = false;
  6820. lastev = false;
  6821. opento = false;
  6822. marker.hide().detach();
  6823. $.vakata.dnd._clean();
  6824. } else {
  6825. data.helper.find('.jstree-copy').first()[ data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (e.metaKey || e.ctrlKey))) ? 'show' : 'hide' ]();
  6826. if(lastev) {
  6827. lastev.metaKey = e.metaKey;
  6828. lastev.ctrlKey = e.ctrlKey;
  6829. $.vakata.dnd._trigger('move', lastev);
  6830. }
  6831. }
  6832. }
  6833. });
  6834. });
  6835. // helpers
  6836. (function ($) {
  6837. $.vakata.html = {
  6838. div : $('<div />'),
  6839. escape : function (str) {
  6840. return $.vakata.html.div.text(str).html();
  6841. },
  6842. strip : function (str) {
  6843. return $.vakata.html.div.empty().append($.parseHTML(str)).text();
  6844. }
  6845. };
  6846. // private variable
  6847. var vakata_dnd = {
  6848. element : false,
  6849. target : false,
  6850. is_down : false,
  6851. is_drag : false,
  6852. helper : false,
  6853. helper_w: 0,
  6854. data : false,
  6855. init_x : 0,
  6856. init_y : 0,
  6857. scroll_l: 0,
  6858. scroll_t: 0,
  6859. scroll_e: false,
  6860. scroll_i: false,
  6861. is_touch: false
  6862. };
  6863. $.vakata.dnd = {
  6864. settings : {
  6865. scroll_speed : 10,
  6866. scroll_proximity : 20,
  6867. helper_left : 5,
  6868. helper_top : 10,
  6869. threshold : 5,
  6870. threshold_touch : 10
  6871. },
  6872. _trigger : function (event_name, e, data) {
  6873. if (data === undefined) {
  6874. data = $.vakata.dnd._get();
  6875. }
  6876. data.event = e;
  6877. $(document).triggerHandler("dnd_" + event_name + ".vakata", data);
  6878. },
  6879. _get : function () {
  6880. return {
  6881. "data" : vakata_dnd.data,
  6882. "element" : vakata_dnd.element,
  6883. "helper" : vakata_dnd.helper
  6884. };
  6885. },
  6886. _clean : function () {
  6887. if(vakata_dnd.helper) { vakata_dnd.helper.remove(); }
  6888. if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
  6889. vakata_dnd = {
  6890. element : false,
  6891. target : false,
  6892. is_down : false,
  6893. is_drag : false,
  6894. helper : false,
  6895. helper_w: 0,
  6896. data : false,
  6897. init_x : 0,
  6898. init_y : 0,
  6899. scroll_l: 0,
  6900. scroll_t: 0,
  6901. scroll_e: false,
  6902. scroll_i: false,
  6903. is_touch: false
  6904. };
  6905. $(document).off("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
  6906. $(document).off("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
  6907. },
  6908. _scroll : function (init_only) {
  6909. if(!vakata_dnd.scroll_e || (!vakata_dnd.scroll_l && !vakata_dnd.scroll_t)) {
  6910. if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
  6911. return false;
  6912. }
  6913. if(!vakata_dnd.scroll_i) {
  6914. vakata_dnd.scroll_i = setInterval($.vakata.dnd._scroll, 100);
  6915. return false;
  6916. }
  6917. if(init_only === true) { return false; }
  6918. var i = vakata_dnd.scroll_e.scrollTop(),
  6919. j = vakata_dnd.scroll_e.scrollLeft();
  6920. vakata_dnd.scroll_e.scrollTop(i + vakata_dnd.scroll_t * $.vakata.dnd.settings.scroll_speed);
  6921. vakata_dnd.scroll_e.scrollLeft(j + vakata_dnd.scroll_l * $.vakata.dnd.settings.scroll_speed);
  6922. if(i !== vakata_dnd.scroll_e.scrollTop() || j !== vakata_dnd.scroll_e.scrollLeft()) {
  6923. /**
  6924. * triggered on the document when a drag causes an element to scroll
  6925. * @event
  6926. * @plugin dnd
  6927. * @name dnd_scroll.vakata
  6928. * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
  6929. * @param {DOM} element the DOM element being dragged
  6930. * @param {jQuery} helper the helper shown next to the mouse
  6931. * @param {jQuery} event the element that is scrolling
  6932. */
  6933. $.vakata.dnd._trigger("scroll", vakata_dnd.scroll_e);
  6934. }
  6935. },
  6936. start : function (e, data, html) {
  6937. if(e.type === "touchstart" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
  6938. e.pageX = e.originalEvent.changedTouches[0].pageX;
  6939. e.pageY = e.originalEvent.changedTouches[0].pageY;
  6940. e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
  6941. }
  6942. if(vakata_dnd.is_drag) { $.vakata.dnd.stop({}); }
  6943. try {
  6944. e.currentTarget.unselectable = "on";
  6945. e.currentTarget.onselectstart = function() { return false; };
  6946. if(e.currentTarget.style) {
  6947. e.currentTarget.style.touchAction = "none";
  6948. e.currentTarget.style.msTouchAction = "none";
  6949. e.currentTarget.style.MozUserSelect = "none";
  6950. }
  6951. } catch(ignore) { }
  6952. vakata_dnd.init_x = e.pageX;
  6953. vakata_dnd.init_y = e.pageY;
  6954. vakata_dnd.data = data;
  6955. vakata_dnd.is_down = true;
  6956. vakata_dnd.element = e.currentTarget;
  6957. vakata_dnd.target = e.target;
  6958. vakata_dnd.is_touch = e.type === "touchstart";
  6959. if(html !== false) {
  6960. vakata_dnd.helper = $("<div id='vakata-dnd'></div>").html(html).css({
  6961. "display" : "block",
  6962. "margin" : "0",
  6963. "padding" : "0",
  6964. "position" : "absolute",
  6965. "top" : "-2000px",
  6966. "lineHeight" : "16px",
  6967. "zIndex" : "10000"
  6968. });
  6969. }
  6970. $(document).on("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
  6971. $(document).on("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
  6972. return false;
  6973. },
  6974. drag : function (e) {
  6975. if(e.type === "touchmove" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
  6976. e.pageX = e.originalEvent.changedTouches[0].pageX;
  6977. e.pageY = e.originalEvent.changedTouches[0].pageY;
  6978. e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
  6979. }
  6980. if(!vakata_dnd.is_down) { return; }
  6981. if(!vakata_dnd.is_drag) {
  6982. if(
  6983. Math.abs(e.pageX - vakata_dnd.init_x) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold) ||
  6984. Math.abs(e.pageY - vakata_dnd.init_y) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold)
  6985. ) {
  6986. if(vakata_dnd.helper) {
  6987. vakata_dnd.helper.appendTo("body");
  6988. vakata_dnd.helper_w = vakata_dnd.helper.outerWidth();
  6989. }
  6990. vakata_dnd.is_drag = true;
  6991. $(vakata_dnd.target).one('click.vakata', false);
  6992. /**
  6993. * triggered on the document when a drag starts
  6994. * @event
  6995. * @plugin dnd
  6996. * @name dnd_start.vakata
  6997. * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
  6998. * @param {DOM} element the DOM element being dragged
  6999. * @param {jQuery} helper the helper shown next to the mouse
  7000. * @param {Object} event the event that caused the start (probably mousemove)
  7001. */
  7002. $.vakata.dnd._trigger("start", e);
  7003. }
  7004. else { return; }
  7005. }
  7006. var d = false, w = false,
  7007. dh = false, wh = false,
  7008. dw = false, ww = false,
  7009. dt = false, dl = false,
  7010. ht = false, hl = false;
  7011. vakata_dnd.scroll_t = 0;
  7012. vakata_dnd.scroll_l = 0;
  7013. vakata_dnd.scroll_e = false;
  7014. $($(e.target).parentsUntil("body").addBack().get().reverse())
  7015. .filter(function () {
  7016. return (/^auto|scroll$/).test($(this).css("overflow")) &&
  7017. (this.scrollHeight > this.offsetHeight || this.scrollWidth > this.offsetWidth);
  7018. })
  7019. .each(function () {
  7020. var t = $(this), o = t.offset();
  7021. if(this.scrollHeight > this.offsetHeight) {
  7022. if(o.top + t.height() - e.pageY < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
  7023. if(e.pageY - o.top < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
  7024. }
  7025. if(this.scrollWidth > this.offsetWidth) {
  7026. if(o.left + t.width() - e.pageX < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
  7027. if(e.pageX - o.left < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
  7028. }
  7029. if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
  7030. vakata_dnd.scroll_e = $(this);
  7031. return false;
  7032. }
  7033. });
  7034. if(!vakata_dnd.scroll_e) {
  7035. d = $(document); w = $(window);
  7036. dh = d.height(); wh = w.height();
  7037. dw = d.width(); ww = w.width();
  7038. dt = d.scrollTop(); dl = d.scrollLeft();
  7039. if(dh > wh && e.pageY - dt < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
  7040. if(dh > wh && wh - (e.pageY - dt) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
  7041. if(dw > ww && e.pageX - dl < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
  7042. if(dw > ww && ww - (e.pageX - dl) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
  7043. if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
  7044. vakata_dnd.scroll_e = d;
  7045. }
  7046. }
  7047. if(vakata_dnd.scroll_e) { $.vakata.dnd._scroll(true); }
  7048. if(vakata_dnd.helper) {
  7049. ht = parseInt(e.pageY + $.vakata.dnd.settings.helper_top, 10);
  7050. hl = parseInt(e.pageX + $.vakata.dnd.settings.helper_left, 10);
  7051. if(dh && ht + 25 > dh) { ht = dh - 50; }
  7052. if(dw && hl + vakata_dnd.helper_w > dw) { hl = dw - (vakata_dnd.helper_w + 2); }
  7053. vakata_dnd.helper.css({
  7054. left : hl + "px",
  7055. top : ht + "px"
  7056. });
  7057. }
  7058. /**
  7059. * triggered on the document when a drag is in progress
  7060. * @event
  7061. * @plugin dnd
  7062. * @name dnd_move.vakata
  7063. * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
  7064. * @param {DOM} element the DOM element being dragged
  7065. * @param {jQuery} helper the helper shown next to the mouse
  7066. * @param {Object} event the event that caused this to trigger (most likely mousemove)
  7067. */
  7068. $.vakata.dnd._trigger("move", e);
  7069. return false;
  7070. },
  7071. stop : function (e) {
  7072. if(e.type === "touchend" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
  7073. e.pageX = e.originalEvent.changedTouches[0].pageX;
  7074. e.pageY = e.originalEvent.changedTouches[0].pageY;
  7075. e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
  7076. }
  7077. if(vakata_dnd.is_drag) {
  7078. /**
  7079. * triggered on the document when a drag stops (the dragged element is dropped)
  7080. * @event
  7081. * @plugin dnd
  7082. * @name dnd_stop.vakata
  7083. * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
  7084. * @param {DOM} element the DOM element being dragged
  7085. * @param {jQuery} helper the helper shown next to the mouse
  7086. * @param {Object} event the event that caused the stop
  7087. */
  7088. if (e.target !== vakata_dnd.target) {
  7089. $(vakata_dnd.target).off('click.vakata');
  7090. }
  7091. $.vakata.dnd._trigger("stop", e);
  7092. }
  7093. else {
  7094. if(e.type === "touchend" && e.target === vakata_dnd.target) {
  7095. var to = setTimeout(function () { $(e.target).click(); }, 100);
  7096. $(e.target).one('click', function() { if(to) { clearTimeout(to); } });
  7097. }
  7098. }
  7099. $.vakata.dnd._clean();
  7100. return false;
  7101. }
  7102. };
  7103. }($));
  7104. // include the dnd plugin by default
  7105. // $.jstree.defaults.plugins.push("dnd");
  7106. /**
  7107. * ### Massload plugin
  7108. *
  7109. * Adds massload functionality to jsTree, so that multiple nodes can be loaded in a single request (only useful with lazy loading).
  7110. */
  7111. /**
  7112. * massload configuration
  7113. *
  7114. * It is possible to set this to a standard jQuery-like AJAX config.
  7115. * In addition to the standard jQuery ajax options here you can supply functions for `data` and `url`, the functions will be run in the current instance's scope and a param will be passed indicating which node IDs need to be loaded, the return value of those functions will be used.
  7116. *
  7117. * You can also set this to a function, that function will receive the node IDs being loaded as argument and a second param which is a function (callback) which should be called with the result.
  7118. *
  7119. * Both the AJAX and the function approach rely on the same return value - an object where the keys are the node IDs, and the value is the children of that node as an array.
  7120. *
  7121. * {
  7122. * "id1" : [{ "text" : "Child of ID1", "id" : "c1" }, { "text" : "Another child of ID1", "id" : "c2" }],
  7123. * "id2" : [{ "text" : "Child of ID2", "id" : "c3" }]
  7124. * }
  7125. *
  7126. * @name $.jstree.defaults.massload
  7127. * @plugin massload
  7128. */
  7129. $.jstree.defaults.massload = null;
  7130. $.jstree.plugins.massload = function (options, parent) {
  7131. this.init = function (el, options) {
  7132. this._data.massload = {};
  7133. parent.init.call(this, el, options);
  7134. };
  7135. this._load_nodes = function (nodes, callback, is_callback, force_reload) {
  7136. var s = this.settings.massload,
  7137. nodesString = JSON.stringify(nodes),
  7138. toLoad = [],
  7139. m = this._model.data,
  7140. i, j, dom;
  7141. if (!is_callback) {
  7142. for(i = 0, j = nodes.length; i < j; i++) {
  7143. if(!m[nodes[i]] || ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || force_reload) ) {
  7144. toLoad.push(nodes[i]);
  7145. dom = this.get_node(nodes[i], true);
  7146. if (dom && dom.length) {
  7147. dom.addClass("jstree-loading").attr('aria-busy',true);
  7148. }
  7149. }
  7150. }
  7151. this._data.massload = {};
  7152. if (toLoad.length) {
  7153. if($.isFunction(s)) {
  7154. return s.call(this, toLoad, $.proxy(function (data) {
  7155. var i, j;
  7156. if(data) {
  7157. for(i in data) {
  7158. if(data.hasOwnProperty(i)) {
  7159. this._data.massload[i] = data[i];
  7160. }
  7161. }
  7162. }
  7163. for(i = 0, j = nodes.length; i < j; i++) {
  7164. dom = this.get_node(nodes[i], true);
  7165. if (dom && dom.length) {
  7166. dom.removeClass("jstree-loading").attr('aria-busy',false);
  7167. }
  7168. }
  7169. parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
  7170. }, this));
  7171. }
  7172. if(typeof s === 'object' && s && s.url) {
  7173. s = $.extend(true, {}, s);
  7174. if($.isFunction(s.url)) {
  7175. s.url = s.url.call(this, toLoad);
  7176. }
  7177. if($.isFunction(s.data)) {
  7178. s.data = s.data.call(this, toLoad);
  7179. }
  7180. return $.ajax(s)
  7181. .done($.proxy(function (data,t,x) {
  7182. var i, j;
  7183. if(data) {
  7184. for(i in data) {
  7185. if(data.hasOwnProperty(i)) {
  7186. this._data.massload[i] = data[i];
  7187. }
  7188. }
  7189. }
  7190. for(i = 0, j = nodes.length; i < j; i++) {
  7191. dom = this.get_node(nodes[i], true);
  7192. if (dom && dom.length) {
  7193. dom.removeClass("jstree-loading").attr('aria-busy',false);
  7194. }
  7195. }
  7196. parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
  7197. }, this))
  7198. .fail($.proxy(function (f) {
  7199. parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
  7200. }, this));
  7201. }
  7202. }
  7203. }
  7204. return parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
  7205. };
  7206. this._load_node = function (obj, callback) {
  7207. var data = this._data.massload[obj.id],
  7208. rslt = null, dom;
  7209. if(data) {
  7210. rslt = this[typeof data === 'string' ? '_append_html_data' : '_append_json_data'](
  7211. obj,
  7212. typeof data === 'string' ? $($.parseHTML(data)).filter(function () { return this.nodeType !== 3; }) : data,
  7213. function (status) { callback.call(this, status); }
  7214. );
  7215. dom = this.get_node(obj.id, true);
  7216. if (dom && dom.length) {
  7217. dom.removeClass("jstree-loading").attr('aria-busy',false);
  7218. }
  7219. delete this._data.massload[obj.id];
  7220. return rslt;
  7221. }
  7222. return parent._load_node.call(this, obj, callback);
  7223. };
  7224. };
  7225. /**
  7226. * ### Search plugin
  7227. *
  7228. * Adds search functionality to jsTree.
  7229. */
  7230. /**
  7231. * stores all defaults for the search plugin
  7232. * @name $.jstree.defaults.search
  7233. * @plugin search
  7234. */
  7235. $.jstree.defaults.search = {
  7236. /**
  7237. * a jQuery-like AJAX config, which jstree uses if a server should be queried for results.
  7238. *
  7239. * A `str` (which is the search string) parameter will be added with the request, an optional `inside` parameter will be added if the search is limited to a node id. The expected result is a JSON array with nodes that need to be opened so that matching nodes will be revealed.
  7240. * Leave this setting as `false` to not query the server. You can also set this to a function, which will be invoked in the instance's scope and receive 3 parameters - the search string, the callback to call with the array of nodes to load, and the optional node ID to limit the search to
  7241. * @name $.jstree.defaults.search.ajax
  7242. * @plugin search
  7243. */
  7244. ajax : false,
  7245. /**
  7246. * Indicates if the search should be fuzzy or not (should `chnd3` match `child node 3`). Default is `false`.
  7247. * @name $.jstree.defaults.search.fuzzy
  7248. * @plugin search
  7249. */
  7250. fuzzy : false,
  7251. /**
  7252. * Indicates if the search should be case sensitive. Default is `false`.
  7253. * @name $.jstree.defaults.search.case_sensitive
  7254. * @plugin search
  7255. */
  7256. case_sensitive : false,
  7257. /**
  7258. * Indicates if the tree should be filtered (by default) to show only matching nodes (keep in mind this can be a heavy on large trees in old browsers).
  7259. * This setting can be changed at runtime when calling the search method. Default is `false`.
  7260. * @name $.jstree.defaults.search.show_only_matches
  7261. * @plugin search
  7262. */
  7263. show_only_matches : false,
  7264. /**
  7265. * Indicates if the children of matched element are shown (when show_only_matches is true)
  7266. * This setting can be changed at runtime when calling the search method. Default is `false`.
  7267. * @name $.jstree.defaults.search.show_only_matches_children
  7268. * @plugin search
  7269. */
  7270. show_only_matches_children : false,
  7271. /**
  7272. * Indicates if all nodes opened to reveal the search result, should be closed when the search is cleared or a new search is performed. Default is `true`.
  7273. * @name $.jstree.defaults.search.close_opened_onclear
  7274. * @plugin search
  7275. */
  7276. close_opened_onclear : true,
  7277. /**
  7278. * Indicates if only leaf nodes should be included in search results. Default is `false`.
  7279. * @name $.jstree.defaults.search.search_leaves_only
  7280. * @plugin search
  7281. */
  7282. search_leaves_only : false,
  7283. /**
  7284. * If set to a function it wil be called in the instance's scope with two arguments - search string and node (where node will be every node in the structure, so use with caution).
  7285. * If the function returns a truthy value the node will be considered a match (it might not be displayed if search_only_leaves is set to true and the node is not a leaf). Default is `false`.
  7286. * @name $.jstree.defaults.search.search_callback
  7287. * @plugin search
  7288. */
  7289. search_callback : false
  7290. };
  7291. $.jstree.plugins.search = function (options, parent) {
  7292. this.bind = function () {
  7293. parent.bind.call(this);
  7294. this._data.search.str = "";
  7295. this._data.search.dom = $();
  7296. this._data.search.res = [];
  7297. this._data.search.opn = [];
  7298. this._data.search.som = false;
  7299. this._data.search.smc = false;
  7300. this._data.search.hdn = [];
  7301. this.element
  7302. .on("search.jstree", $.proxy(function (e, data) {
  7303. if(this._data.search.som && data.res.length) {
  7304. var m = this._model.data, i, j, p = [], k, l;
  7305. for(i = 0, j = data.res.length; i < j; i++) {
  7306. if(m[data.res[i]] && !m[data.res[i]].state.hidden) {
  7307. p.push(data.res[i]);
  7308. p = p.concat(m[data.res[i]].parents);
  7309. if(this._data.search.smc) {
  7310. for (k = 0, l = m[data.res[i]].children_d.length; k < l; k++) {
  7311. if (m[m[data.res[i]].children_d[k]] && !m[m[data.res[i]].children_d[k]].state.hidden) {
  7312. p.push(m[data.res[i]].children_d[k]);
  7313. }
  7314. }
  7315. }
  7316. }
  7317. }
  7318. p = $.vakata.array_remove_item($.vakata.array_unique(p), $.jstree.root);
  7319. this._data.search.hdn = this.hide_all(true);
  7320. this.show_node(p, true);
  7321. this.redraw(true);
  7322. }
  7323. }, this))
  7324. .on("clear_search.jstree", $.proxy(function (e, data) {
  7325. if(this._data.search.som && data.res.length) {
  7326. this.show_node(this._data.search.hdn, true);
  7327. this.redraw(true);
  7328. }
  7329. }, this));
  7330. };
  7331. /**
  7332. * used to search the tree nodes for a given string
  7333. * @name search(str [, skip_async])
  7334. * @param {String} str the search string
  7335. * @param {Boolean} skip_async if set to true server will not be queried even if configured
  7336. * @param {Boolean} show_only_matches if set to true only matching nodes will be shown (keep in mind this can be very slow on large trees or old browsers)
  7337. * @param {mixed} inside an optional node to whose children to limit the search
  7338. * @param {Boolean} append if set to true the results of this search are appended to the previous search
  7339. * @plugin search
  7340. * @trigger search.jstree
  7341. */
  7342. this.search = function (str, skip_async, show_only_matches, inside, append, show_only_matches_children) {
  7343. if(str === false || $.trim(str.toString()) === "") {
  7344. return this.clear_search();
  7345. }
  7346. inside = this.get_node(inside);
  7347. inside = inside && inside.id ? inside.id : null;
  7348. str = str.toString();
  7349. var s = this.settings.search,
  7350. a = s.ajax ? s.ajax : false,
  7351. m = this._model.data,
  7352. f = null,
  7353. r = [],
  7354. p = [], i, j;
  7355. if(this._data.search.res.length && !append) {
  7356. this.clear_search();
  7357. }
  7358. if(show_only_matches === undefined) {
  7359. show_only_matches = s.show_only_matches;
  7360. }
  7361. if(show_only_matches_children === undefined) {
  7362. show_only_matches_children = s.show_only_matches_children;
  7363. }
  7364. if(!skip_async && a !== false) {
  7365. if($.isFunction(a)) {
  7366. return a.call(this, str, $.proxy(function (d) {
  7367. if(d && d.d) { d = d.d; }
  7368. this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
  7369. this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
  7370. });
  7371. }, this), inside);
  7372. }
  7373. else {
  7374. a = $.extend({}, a);
  7375. if(!a.data) { a.data = {}; }
  7376. a.data.str = str;
  7377. if(inside) {
  7378. a.data.inside = inside;
  7379. }
  7380. if (this._data.search.lastRequest) {
  7381. this._data.search.lastRequest.abort();
  7382. }
  7383. this._data.search.lastRequest = $.ajax(a)
  7384. .fail($.proxy(function () {
  7385. this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'search', 'id' : 'search_01', 'reason' : 'Could not load search parents', 'data' : JSON.stringify(a) };
  7386. this.settings.core.error.call(this, this._data.core.last_error);
  7387. }, this))
  7388. .done($.proxy(function (d) {
  7389. if(d && d.d) { d = d.d; }
  7390. this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
  7391. this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
  7392. });
  7393. }, this));
  7394. return this._data.search.lastRequest;
  7395. }
  7396. }
  7397. if(!append) {
  7398. this._data.search.str = str;
  7399. this._data.search.dom = $();
  7400. this._data.search.res = [];
  7401. this._data.search.opn = [];
  7402. this._data.search.som = show_only_matches;
  7403. this._data.search.smc = show_only_matches_children;
  7404. }
  7405. f = new $.vakata.search(str, true, { caseSensitive : s.case_sensitive, fuzzy : s.fuzzy });
  7406. $.each(m[inside ? inside : $.jstree.root].children_d, function (ii, i) {
  7407. var v = m[i];
  7408. if(v.text && !v.state.hidden && (!s.search_leaves_only || (v.state.loaded && v.children.length === 0)) && ( (s.search_callback && s.search_callback.call(this, str, v)) || (!s.search_callback && f.search(v.text).isMatch) ) ) {
  7409. r.push(i);
  7410. p = p.concat(v.parents);
  7411. }
  7412. });
  7413. if(r.length) {
  7414. p = $.vakata.array_unique(p);
  7415. for(i = 0, j = p.length; i < j; i++) {
  7416. if(p[i] !== $.jstree.root && m[p[i]] && this.open_node(p[i], null, 0) === true) {
  7417. this._data.search.opn.push(p[i]);
  7418. }
  7419. }
  7420. if(!append) {
  7421. this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(r, function (v) { return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&'); }).join(', #')));
  7422. this._data.search.res = r;
  7423. }
  7424. else {
  7425. this._data.search.dom = this._data.search.dom.add($(this.element[0].querySelectorAll('#' + $.map(r, function (v) { return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&'); }).join(', #'))));
  7426. this._data.search.res = $.vakata.array_unique(this._data.search.res.concat(r));
  7427. }
  7428. this._data.search.dom.children(".jstree-anchor").addClass('jstree-search');
  7429. }
  7430. /**
  7431. * triggered after search is complete
  7432. * @event
  7433. * @name search.jstree
  7434. * @param {jQuery} nodes a jQuery collection of matching nodes
  7435. * @param {String} str the search string
  7436. * @param {Array} res a collection of objects represeing the matching nodes
  7437. * @plugin search
  7438. */
  7439. this.trigger('search', { nodes : this._data.search.dom, str : str, res : this._data.search.res, show_only_matches : show_only_matches });
  7440. };
  7441. /**
  7442. * used to clear the last search (removes classes and shows all nodes if filtering is on)
  7443. * @name clear_search()
  7444. * @plugin search
  7445. * @trigger clear_search.jstree
  7446. */
  7447. this.clear_search = function () {
  7448. if(this.settings.search.close_opened_onclear) {
  7449. this.close_node(this._data.search.opn, 0);
  7450. }
  7451. /**
  7452. * triggered after search is complete
  7453. * @event
  7454. * @name clear_search.jstree
  7455. * @param {jQuery} nodes a jQuery collection of matching nodes (the result from the last search)
  7456. * @param {String} str the search string (the last search string)
  7457. * @param {Array} res a collection of objects represeing the matching nodes (the result from the last search)
  7458. * @plugin search
  7459. */
  7460. this.trigger('clear_search', { 'nodes' : this._data.search.dom, str : this._data.search.str, res : this._data.search.res });
  7461. if(this._data.search.res.length) {
  7462. this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(this._data.search.res, function (v) {
  7463. return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&');
  7464. }).join(', #')));
  7465. this._data.search.dom.children(".jstree-anchor").removeClass("jstree-search");
  7466. }
  7467. this._data.search.str = "";
  7468. this._data.search.res = [];
  7469. this._data.search.opn = [];
  7470. this._data.search.dom = $();
  7471. };
  7472. this.redraw_node = function(obj, deep, callback, force_render) {
  7473. obj = parent.redraw_node.apply(this, arguments);
  7474. if(obj) {
  7475. if($.inArray(obj.id, this._data.search.res) !== -1) {
  7476. var i, j, tmp = null;
  7477. for(i = 0, j = obj.childNodes.length; i < j; i++) {
  7478. if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
  7479. tmp = obj.childNodes[i];
  7480. break;
  7481. }
  7482. }
  7483. if(tmp) {
  7484. tmp.className += ' jstree-search';
  7485. }
  7486. }
  7487. }
  7488. return obj;
  7489. };
  7490. };
  7491. // helpers
  7492. (function ($) {
  7493. // from http://kiro.me/projects/fuse.html
  7494. $.vakata.search = function(pattern, txt, options) {
  7495. options = options || {};
  7496. options = $.extend({}, $.vakata.search.defaults, options);
  7497. if(options.fuzzy !== false) {
  7498. options.fuzzy = true;
  7499. }
  7500. pattern = options.caseSensitive ? pattern : pattern.toLowerCase();
  7501. var MATCH_LOCATION = options.location,
  7502. MATCH_DISTANCE = options.distance,
  7503. MATCH_THRESHOLD = options.threshold,
  7504. patternLen = pattern.length,
  7505. matchmask, pattern_alphabet, match_bitapScore, search;
  7506. if(patternLen > 32) {
  7507. options.fuzzy = false;
  7508. }
  7509. if(options.fuzzy) {
  7510. matchmask = 1 << (patternLen - 1);
  7511. pattern_alphabet = (function () {
  7512. var mask = {},
  7513. i = 0;
  7514. for (i = 0; i < patternLen; i++) {
  7515. mask[pattern.charAt(i)] = 0;
  7516. }
  7517. for (i = 0; i < patternLen; i++) {
  7518. mask[pattern.charAt(i)] |= 1 << (patternLen - i - 1);
  7519. }
  7520. return mask;
  7521. }());
  7522. match_bitapScore = function (e, x) {
  7523. var accuracy = e / patternLen,
  7524. proximity = Math.abs(MATCH_LOCATION - x);
  7525. if(!MATCH_DISTANCE) {
  7526. return proximity ? 1.0 : accuracy;
  7527. }
  7528. return accuracy + (proximity / MATCH_DISTANCE);
  7529. };
  7530. }
  7531. search = function (text) {
  7532. text = options.caseSensitive ? text : text.toLowerCase();
  7533. if(pattern === text || text.indexOf(pattern) !== -1) {
  7534. return {
  7535. isMatch: true,
  7536. score: 0
  7537. };
  7538. }
  7539. if(!options.fuzzy) {
  7540. return {
  7541. isMatch: false,
  7542. score: 1
  7543. };
  7544. }
  7545. var i, j,
  7546. textLen = text.length,
  7547. scoreThreshold = MATCH_THRESHOLD,
  7548. bestLoc = text.indexOf(pattern, MATCH_LOCATION),
  7549. binMin, binMid,
  7550. binMax = patternLen + textLen,
  7551. lastRd, start, finish, rd, charMatch,
  7552. score = 1,
  7553. locations = [];
  7554. if (bestLoc !== -1) {
  7555. scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
  7556. bestLoc = text.lastIndexOf(pattern, MATCH_LOCATION + patternLen);
  7557. if (bestLoc !== -1) {
  7558. scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
  7559. }
  7560. }
  7561. bestLoc = -1;
  7562. for (i = 0; i < patternLen; i++) {
  7563. binMin = 0;
  7564. binMid = binMax;
  7565. while (binMin < binMid) {
  7566. if (match_bitapScore(i, MATCH_LOCATION + binMid) <= scoreThreshold) {
  7567. binMin = binMid;
  7568. } else {
  7569. binMax = binMid;
  7570. }
  7571. binMid = Math.floor((binMax - binMin) / 2 + binMin);
  7572. }
  7573. binMax = binMid;
  7574. start = Math.max(1, MATCH_LOCATION - binMid + 1);
  7575. finish = Math.min(MATCH_LOCATION + binMid, textLen) + patternLen;
  7576. rd = new Array(finish + 2);
  7577. rd[finish + 1] = (1 << i) - 1;
  7578. for (j = finish; j >= start; j--) {
  7579. charMatch = pattern_alphabet[text.charAt(j - 1)];
  7580. if (i === 0) {
  7581. rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
  7582. } else {
  7583. rd[j] = ((rd[j + 1] << 1) | 1) & charMatch | (((lastRd[j + 1] | lastRd[j]) << 1) | 1) | lastRd[j + 1];
  7584. }
  7585. if (rd[j] & matchmask) {
  7586. score = match_bitapScore(i, j - 1);
  7587. if (score <= scoreThreshold) {
  7588. scoreThreshold = score;
  7589. bestLoc = j - 1;
  7590. locations.push(bestLoc);
  7591. if (bestLoc > MATCH_LOCATION) {
  7592. start = Math.max(1, 2 * MATCH_LOCATION - bestLoc);
  7593. } else {
  7594. break;
  7595. }
  7596. }
  7597. }
  7598. }
  7599. if (match_bitapScore(i + 1, MATCH_LOCATION) > scoreThreshold) {
  7600. break;
  7601. }
  7602. lastRd = rd;
  7603. }
  7604. return {
  7605. isMatch: bestLoc >= 0,
  7606. score: score
  7607. };
  7608. };
  7609. return txt === true ? { 'search' : search } : search(txt);
  7610. };
  7611. $.vakata.search.defaults = {
  7612. location : 0,
  7613. distance : 100,
  7614. threshold : 0.6,
  7615. fuzzy : false,
  7616. caseSensitive : false
  7617. };
  7618. }($));
  7619. // include the search plugin by default
  7620. // $.jstree.defaults.plugins.push("search");
  7621. /**
  7622. * ### Sort plugin
  7623. *
  7624. * Automatically sorts all siblings in the tree according to a sorting function.
  7625. */
  7626. /**
  7627. * the settings function used to sort the nodes.
  7628. * It is executed in the tree's context, accepts two nodes as arguments and should return `1` or `-1`.
  7629. * @name $.jstree.defaults.sort
  7630. * @plugin sort
  7631. */
  7632. $.jstree.defaults.sort = function (a, b) {
  7633. //return this.get_type(a) === this.get_type(b) ? (this.get_text(a) > this.get_text(b) ? 1 : -1) : this.get_type(a) >= this.get_type(b);
  7634. return this.get_text(a) > this.get_text(b) ? 1 : -1;
  7635. };
  7636. $.jstree.plugins.sort = function (options, parent) {
  7637. this.bind = function () {
  7638. parent.bind.call(this);
  7639. this.element
  7640. .on("model.jstree", $.proxy(function (e, data) {
  7641. this.sort(data.parent, true);
  7642. }, this))
  7643. .on("rename_node.jstree create_node.jstree", $.proxy(function (e, data) {
  7644. this.sort(data.parent || data.node.parent, false);
  7645. this.redraw_node(data.parent || data.node.parent, true);
  7646. }, this))
  7647. .on("move_node.jstree copy_node.jstree", $.proxy(function (e, data) {
  7648. this.sort(data.parent, false);
  7649. this.redraw_node(data.parent, true);
  7650. }, this));
  7651. };
  7652. /**
  7653. * used to sort a node's children
  7654. * @private
  7655. * @name sort(obj [, deep])
  7656. * @param {mixed} obj the node
  7657. * @param {Boolean} deep if set to `true` nodes are sorted recursively.
  7658. * @plugin sort
  7659. * @trigger search.jstree
  7660. */
  7661. this.sort = function (obj, deep) {
  7662. var i, j;
  7663. obj = this.get_node(obj);
  7664. if(obj && obj.children && obj.children.length) {
  7665. obj.children.sort($.proxy(this.settings.sort, this));
  7666. if(deep) {
  7667. for(i = 0, j = obj.children_d.length; i < j; i++) {
  7668. this.sort(obj.children_d[i], false);
  7669. }
  7670. }
  7671. }
  7672. };
  7673. };
  7674. // include the sort plugin by default
  7675. // $.jstree.defaults.plugins.push("sort");
  7676. /**
  7677. * ### State plugin
  7678. *
  7679. * Saves the state of the tree (selected nodes, opened nodes) on the user's computer using available options (localStorage, cookies, etc)
  7680. */
  7681. var to = false;
  7682. /**
  7683. * stores all defaults for the state plugin
  7684. * @name $.jstree.defaults.state
  7685. * @plugin state
  7686. */
  7687. $.jstree.defaults.state = {
  7688. /**
  7689. * A string for the key to use when saving the current tree (change if using multiple trees in your project). Defaults to `jstree`.
  7690. * @name $.jstree.defaults.state.key
  7691. * @plugin state
  7692. */
  7693. key : 'jstree',
  7694. /**
  7695. * A space separated list of events that trigger a state save. Defaults to `changed.jstree open_node.jstree close_node.jstree`.
  7696. * @name $.jstree.defaults.state.events
  7697. * @plugin state
  7698. */
  7699. events : 'changed.jstree open_node.jstree close_node.jstree check_node.jstree uncheck_node.jstree',
  7700. /**
  7701. * Time in milliseconds after which the state will expire. Defaults to 'false' meaning - no expire.
  7702. * @name $.jstree.defaults.state.ttl
  7703. * @plugin state
  7704. */
  7705. ttl : false,
  7706. /**
  7707. * A function that will be executed prior to restoring state with one argument - the state object. Can be used to clear unwanted parts of the state.
  7708. * @name $.jstree.defaults.state.filter
  7709. * @plugin state
  7710. */
  7711. filter : false,
  7712. /**
  7713. * Should loaded nodes be restored (setting this to true means that it is possible that the whole tree will be loaded for some users - use with caution). Defaults to `false`
  7714. * @name $.jstree.defaults.state.preserve_loaded
  7715. * @plugin state
  7716. */
  7717. preserve_loaded : false
  7718. };
  7719. $.jstree.plugins.state = function (options, parent) {
  7720. this.bind = function () {
  7721. parent.bind.call(this);
  7722. var bind = $.proxy(function () {
  7723. this.element.on(this.settings.state.events, $.proxy(function () {
  7724. if(to) { clearTimeout(to); }
  7725. to = setTimeout($.proxy(function () { this.save_state(); }, this), 100);
  7726. }, this));
  7727. /**
  7728. * triggered when the state plugin is finished restoring the state (and immediately after ready if there is no state to restore).
  7729. * @event
  7730. * @name state_ready.jstree
  7731. * @plugin state
  7732. */
  7733. this.trigger('state_ready');
  7734. }, this);
  7735. this.element
  7736. .on("ready.jstree", $.proxy(function (e, data) {
  7737. this.element.one("restore_state.jstree", bind);
  7738. if(!this.restore_state()) { bind(); }
  7739. }, this));
  7740. };
  7741. /**
  7742. * save the state
  7743. * @name save_state()
  7744. * @plugin state
  7745. */
  7746. this.save_state = function () {
  7747. var tm = this.get_state();
  7748. if (!this.settings.state.preserve_loaded) {
  7749. delete tm.core.loaded;
  7750. }
  7751. var st = { 'state' : tm, 'ttl' : this.settings.state.ttl, 'sec' : +(new Date()) };
  7752. $.vakata.storage.set(this.settings.state.key, JSON.stringify(st));
  7753. };
  7754. /**
  7755. * restore the state from the user's computer
  7756. * @name restore_state()
  7757. * @plugin state
  7758. */
  7759. this.restore_state = function () {
  7760. var k = $.vakata.storage.get(this.settings.state.key);
  7761. if(!!k) { try { k = JSON.parse(k); } catch(ex) { return false; } }
  7762. if(!!k && k.ttl && k.sec && +(new Date()) - k.sec > k.ttl) { return false; }
  7763. if(!!k && k.state) { k = k.state; }
  7764. if(!!k && $.isFunction(this.settings.state.filter)) { k = this.settings.state.filter.call(this, k); }
  7765. if(!!k) {
  7766. if (!this.settings.state.preserve_loaded) {
  7767. delete k.core.loaded;
  7768. }
  7769. this.element.one("set_state.jstree", function (e, data) { data.instance.trigger('restore_state', { 'state' : $.extend(true, {}, k) }); });
  7770. this.set_state(k);
  7771. return true;
  7772. }
  7773. return false;
  7774. };
  7775. /**
  7776. * clear the state on the user's computer
  7777. * @name clear_state()
  7778. * @plugin state
  7779. */
  7780. this.clear_state = function () {
  7781. return $.vakata.storage.del(this.settings.state.key);
  7782. };
  7783. };
  7784. (function ($, undefined) {
  7785. $.vakata.storage = {
  7786. // simply specifying the functions in FF throws an error
  7787. set : function (key, val) { return window.localStorage.setItem(key, val); },
  7788. get : function (key) { return window.localStorage.getItem(key); },
  7789. del : function (key) { return window.localStorage.removeItem(key); }
  7790. };
  7791. }($));
  7792. // include the state plugin by default
  7793. // $.jstree.defaults.plugins.push("state");
  7794. /**
  7795. * ### Types plugin
  7796. *
  7797. * Makes it possible to add predefined types for groups of nodes, which make it possible to easily control nesting rules and icon for each group.
  7798. */
  7799. /**
  7800. * An object storing all types as key value pairs, where the key is the type name and the value is an object that could contain following keys (all optional).
  7801. *
  7802. * * `max_children` the maximum number of immediate children this node type can have. Do not specify or set to `-1` for unlimited.
  7803. * * `max_depth` the maximum number of nesting this node type can have. A value of `1` would mean that the node can have children, but no grandchildren. Do not specify or set to `-1` for unlimited.
  7804. * * `valid_children` an array of node type strings, that nodes of this type can have as children. Do not specify or set to `-1` for no limits.
  7805. * * `icon` a string - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class. Omit to use the default icon from your theme.
  7806. * * `li_attr` an object of values which will be used to add HTML attributes on the resulting LI DOM node (merged with the node's own data)
  7807. * * `a_attr` an object of values which will be used to add HTML attributes on the resulting A DOM node (merged with the node's own data)
  7808. *
  7809. * There are two predefined types:
  7810. *
  7811. * * `#` represents the root of the tree, for example `max_children` would control the maximum number of root nodes.
  7812. * * `default` represents the default node - any settings here will be applied to all nodes that do not have a type specified.
  7813. *
  7814. * @name $.jstree.defaults.types
  7815. * @plugin types
  7816. */
  7817. $.jstree.defaults.types = {
  7818. 'default' : {}
  7819. };
  7820. $.jstree.defaults.types[$.jstree.root] = {};
  7821. $.jstree.plugins.types = function (options, parent) {
  7822. this.init = function (el, options) {
  7823. var i, j;
  7824. if(options && options.types && options.types['default']) {
  7825. for(i in options.types) {
  7826. if(i !== "default" && i !== $.jstree.root && options.types.hasOwnProperty(i)) {
  7827. for(j in options.types['default']) {
  7828. if(options.types['default'].hasOwnProperty(j) && options.types[i][j] === undefined) {
  7829. options.types[i][j] = options.types['default'][j];
  7830. }
  7831. }
  7832. }
  7833. }
  7834. }
  7835. parent.init.call(this, el, options);
  7836. this._model.data[$.jstree.root].type = $.jstree.root;
  7837. };
  7838. this.refresh = function (skip_loading, forget_state) {
  7839. parent.refresh.call(this, skip_loading, forget_state);
  7840. this._model.data[$.jstree.root].type = $.jstree.root;
  7841. };
  7842. this.bind = function () {
  7843. this.element
  7844. .on('model.jstree', $.proxy(function (e, data) {
  7845. var m = this._model.data,
  7846. dpc = data.nodes,
  7847. t = this.settings.types,
  7848. i, j, c = 'default', k;
  7849. for(i = 0, j = dpc.length; i < j; i++) {
  7850. c = 'default';
  7851. if(m[dpc[i]].original && m[dpc[i]].original.type && t[m[dpc[i]].original.type]) {
  7852. c = m[dpc[i]].original.type;
  7853. }
  7854. if(m[dpc[i]].data && m[dpc[i]].data.jstree && m[dpc[i]].data.jstree.type && t[m[dpc[i]].data.jstree.type]) {
  7855. c = m[dpc[i]].data.jstree.type;
  7856. }
  7857. m[dpc[i]].type = c;
  7858. if(m[dpc[i]].icon === true && t[c].icon !== undefined) {
  7859. m[dpc[i]].icon = t[c].icon;
  7860. }
  7861. if(t[c].li_attr !== undefined && typeof t[c].li_attr === 'object') {
  7862. for (k in t[c].li_attr) {
  7863. if (t[c].li_attr.hasOwnProperty(k)) {
  7864. if (k === 'id') {
  7865. continue;
  7866. }
  7867. else if (m[dpc[i]].li_attr[k] === undefined) {
  7868. m[dpc[i]].li_attr[k] = t[c].li_attr[k];
  7869. }
  7870. else if (k === 'class') {
  7871. m[dpc[i]].li_attr['class'] = t[c].li_attr['class'] + ' ' + m[dpc[i]].li_attr['class'];
  7872. }
  7873. }
  7874. }
  7875. }
  7876. if(t[c].a_attr !== undefined && typeof t[c].a_attr === 'object') {
  7877. for (k in t[c].a_attr) {
  7878. if (t[c].a_attr.hasOwnProperty(k)) {
  7879. if (k === 'id') {
  7880. continue;
  7881. }
  7882. else if (m[dpc[i]].a_attr[k] === undefined) {
  7883. m[dpc[i]].a_attr[k] = t[c].a_attr[k];
  7884. }
  7885. else if (k === 'href' && m[dpc[i]].a_attr[k] === '#') {
  7886. m[dpc[i]].a_attr['href'] = t[c].a_attr['href'];
  7887. }
  7888. else if (k === 'class') {
  7889. m[dpc[i]].a_attr['class'] = t[c].a_attr['class'] + ' ' + m[dpc[i]].a_attr['class'];
  7890. }
  7891. }
  7892. }
  7893. }
  7894. }
  7895. m[$.jstree.root].type = $.jstree.root;
  7896. }, this));
  7897. parent.bind.call(this);
  7898. };
  7899. this.get_json = function (obj, options, flat) {
  7900. var i, j,
  7901. m = this._model.data,
  7902. opt = options ? $.extend(true, {}, options, {no_id:false}) : {},
  7903. tmp = parent.get_json.call(this, obj, opt, flat);
  7904. if(tmp === false) { return false; }
  7905. if($.isArray(tmp)) {
  7906. for(i = 0, j = tmp.length; i < j; i++) {
  7907. tmp[i].type = tmp[i].id && m[tmp[i].id] && m[tmp[i].id].type ? m[tmp[i].id].type : "default";
  7908. if(options && options.no_id) {
  7909. delete tmp[i].id;
  7910. if(tmp[i].li_attr && tmp[i].li_attr.id) {
  7911. delete tmp[i].li_attr.id;
  7912. }
  7913. if(tmp[i].a_attr && tmp[i].a_attr.id) {
  7914. delete tmp[i].a_attr.id;
  7915. }
  7916. }
  7917. }
  7918. }
  7919. else {
  7920. tmp.type = tmp.id && m[tmp.id] && m[tmp.id].type ? m[tmp.id].type : "default";
  7921. if(options && options.no_id) {
  7922. tmp = this._delete_ids(tmp);
  7923. }
  7924. }
  7925. return tmp;
  7926. };
  7927. this._delete_ids = function (tmp) {
  7928. if($.isArray(tmp)) {
  7929. for(var i = 0, j = tmp.length; i < j; i++) {
  7930. tmp[i] = this._delete_ids(tmp[i]);
  7931. }
  7932. return tmp;
  7933. }
  7934. delete tmp.id;
  7935. if(tmp.li_attr && tmp.li_attr.id) {
  7936. delete tmp.li_attr.id;
  7937. }
  7938. if(tmp.a_attr && tmp.a_attr.id) {
  7939. delete tmp.a_attr.id;
  7940. }
  7941. if(tmp.children && $.isArray(tmp.children)) {
  7942. tmp.children = this._delete_ids(tmp.children);
  7943. }
  7944. return tmp;
  7945. };
  7946. this.check = function (chk, obj, par, pos, more) {
  7947. if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
  7948. obj = obj && obj.id ? obj : this.get_node(obj);
  7949. par = par && par.id ? par : this.get_node(par);
  7950. var m = obj && obj.id ? (more && more.origin ? more.origin : $.jstree.reference(obj.id)) : null, tmp, d, i, j;
  7951. m = m && m._model && m._model.data ? m._model.data : null;
  7952. switch(chk) {
  7953. case "create_node":
  7954. case "move_node":
  7955. case "copy_node":
  7956. if(chk !== 'move_node' || $.inArray(obj.id, par.children) === -1) {
  7957. tmp = this.get_rules(par);
  7958. if(tmp.max_children !== undefined && tmp.max_children !== -1 && tmp.max_children === par.children.length) {
  7959. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_01', 'reason' : 'max_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  7960. return false;
  7961. }
  7962. if(tmp.valid_children !== undefined && tmp.valid_children !== -1 && $.inArray((obj.type || 'default'), tmp.valid_children) === -1) {
  7963. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_02', 'reason' : 'valid_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  7964. return false;
  7965. }
  7966. if(m && obj.children_d && obj.parents) {
  7967. d = 0;
  7968. for(i = 0, j = obj.children_d.length; i < j; i++) {
  7969. d = Math.max(d, m[obj.children_d[i]].parents.length);
  7970. }
  7971. d = d - obj.parents.length + 1;
  7972. }
  7973. if(d <= 0 || d === undefined) { d = 1; }
  7974. do {
  7975. if(tmp.max_depth !== undefined && tmp.max_depth !== -1 && tmp.max_depth < d) {
  7976. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_03', 'reason' : 'max_depth prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  7977. return false;
  7978. }
  7979. par = this.get_node(par.parent);
  7980. tmp = this.get_rules(par);
  7981. d++;
  7982. } while(par);
  7983. }
  7984. break;
  7985. }
  7986. return true;
  7987. };
  7988. /**
  7989. * used to retrieve the type settings object for a node
  7990. * @name get_rules(obj)
  7991. * @param {mixed} obj the node to find the rules for
  7992. * @return {Object}
  7993. * @plugin types
  7994. */
  7995. this.get_rules = function (obj) {
  7996. obj = this.get_node(obj);
  7997. if(!obj) { return false; }
  7998. var tmp = this.get_type(obj, true);
  7999. if(tmp.max_depth === undefined) { tmp.max_depth = -1; }
  8000. if(tmp.max_children === undefined) { tmp.max_children = -1; }
  8001. if(tmp.valid_children === undefined) { tmp.valid_children = -1; }
  8002. return tmp;
  8003. };
  8004. /**
  8005. * used to retrieve the type string or settings object for a node
  8006. * @name get_type(obj [, rules])
  8007. * @param {mixed} obj the node to find the rules for
  8008. * @param {Boolean} rules if set to `true` instead of a string the settings object will be returned
  8009. * @return {String|Object}
  8010. * @plugin types
  8011. */
  8012. this.get_type = function (obj, rules) {
  8013. obj = this.get_node(obj);
  8014. return (!obj) ? false : ( rules ? $.extend({ 'type' : obj.type }, this.settings.types[obj.type]) : obj.type);
  8015. };
  8016. /**
  8017. * used to change a node's type
  8018. * @name set_type(obj, type)
  8019. * @param {mixed} obj the node to change
  8020. * @param {String} type the new type
  8021. * @plugin types
  8022. */
  8023. this.set_type = function (obj, type) {
  8024. var m = this._model.data, t, t1, t2, old_type, old_icon, k, d, a;
  8025. if($.isArray(obj)) {
  8026. obj = obj.slice();
  8027. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  8028. this.set_type(obj[t1], type);
  8029. }
  8030. return true;
  8031. }
  8032. t = this.settings.types;
  8033. obj = this.get_node(obj);
  8034. if(!t[type] || !obj) { return false; }
  8035. d = this.get_node(obj, true);
  8036. if (d && d.length) {
  8037. a = d.children('.jstree-anchor');
  8038. }
  8039. old_type = obj.type;
  8040. old_icon = this.get_icon(obj);
  8041. obj.type = type;
  8042. if(old_icon === true || !t[old_type] || (t[old_type].icon !== undefined && old_icon === t[old_type].icon)) {
  8043. this.set_icon(obj, t[type].icon !== undefined ? t[type].icon : true);
  8044. }
  8045. // remove old type props
  8046. if(t[old_type] && t[old_type].li_attr !== undefined && typeof t[old_type].li_attr === 'object') {
  8047. for (k in t[old_type].li_attr) {
  8048. if (t[old_type].li_attr.hasOwnProperty(k)) {
  8049. if (k === 'id') {
  8050. continue;
  8051. }
  8052. else if (k === 'class') {
  8053. m[obj.id].li_attr['class'] = (m[obj.id].li_attr['class'] || '').replace(t[old_type].li_attr[k], '');
  8054. if (d) { d.removeClass(t[old_type].li_attr[k]); }
  8055. }
  8056. else if (m[obj.id].li_attr[k] === t[old_type].li_attr[k]) {
  8057. m[obj.id].li_attr[k] = null;
  8058. if (d) { d.removeAttr(k); }
  8059. }
  8060. }
  8061. }
  8062. }
  8063. if(t[old_type] && t[old_type].a_attr !== undefined && typeof t[old_type].a_attr === 'object') {
  8064. for (k in t[old_type].a_attr) {
  8065. if (t[old_type].a_attr.hasOwnProperty(k)) {
  8066. if (k === 'id') {
  8067. continue;
  8068. }
  8069. else if (k === 'class') {
  8070. m[obj.id].a_attr['class'] = (m[obj.id].a_attr['class'] || '').replace(t[old_type].a_attr[k], '');
  8071. if (a) { a.removeClass(t[old_type].a_attr[k]); }
  8072. }
  8073. else if (m[obj.id].a_attr[k] === t[old_type].a_attr[k]) {
  8074. if (k === 'href') {
  8075. m[obj.id].a_attr[k] = '#';
  8076. if (a) { a.attr('href', '#'); }
  8077. }
  8078. else {
  8079. delete m[obj.id].a_attr[k];
  8080. if (a) { a.removeAttr(k); }
  8081. }
  8082. }
  8083. }
  8084. }
  8085. }
  8086. // add new props
  8087. if(t[type].li_attr !== undefined && typeof t[type].li_attr === 'object') {
  8088. for (k in t[type].li_attr) {
  8089. if (t[type].li_attr.hasOwnProperty(k)) {
  8090. if (k === 'id') {
  8091. continue;
  8092. }
  8093. else if (m[obj.id].li_attr[k] === undefined) {
  8094. m[obj.id].li_attr[k] = t[type].li_attr[k];
  8095. if (d) {
  8096. if (k === 'class') {
  8097. d.addClass(t[type].li_attr[k]);
  8098. }
  8099. else {
  8100. d.attr(k, t[type].li_attr[k]);
  8101. }
  8102. }
  8103. }
  8104. else if (k === 'class') {
  8105. m[obj.id].li_attr['class'] = t[type].li_attr[k] + ' ' + m[obj.id].li_attr['class'];
  8106. if (d) { d.addClass(t[type].li_attr[k]); }
  8107. }
  8108. }
  8109. }
  8110. }
  8111. if(t[type].a_attr !== undefined && typeof t[type].a_attr === 'object') {
  8112. for (k in t[type].a_attr) {
  8113. if (t[type].a_attr.hasOwnProperty(k)) {
  8114. if (k === 'id') {
  8115. continue;
  8116. }
  8117. else if (m[obj.id].a_attr[k] === undefined) {
  8118. m[obj.id].a_attr[k] = t[type].a_attr[k];
  8119. if (a) {
  8120. if (k === 'class') {
  8121. a.addClass(t[type].a_attr[k]);
  8122. }
  8123. else {
  8124. a.attr(k, t[type].a_attr[k]);
  8125. }
  8126. }
  8127. }
  8128. else if (k === 'href' && m[obj.id].a_attr[k] === '#') {
  8129. m[obj.id].a_attr['href'] = t[type].a_attr['href'];
  8130. if (a) { a.attr('href', t[type].a_attr['href']); }
  8131. }
  8132. else if (k === 'class') {
  8133. m[obj.id].a_attr['class'] = t[type].a_attr['class'] + ' ' + m[obj.id].a_attr['class'];
  8134. if (a) { a.addClass(t[type].a_attr[k]); }
  8135. }
  8136. }
  8137. }
  8138. }
  8139. return true;
  8140. };
  8141. };
  8142. // include the types plugin by default
  8143. // $.jstree.defaults.plugins.push("types");
  8144. /**
  8145. * ### Unique plugin
  8146. *
  8147. * Enforces that no nodes with the same name can coexist as siblings.
  8148. */
  8149. /**
  8150. * stores all defaults for the unique plugin
  8151. * @name $.jstree.defaults.unique
  8152. * @plugin unique
  8153. */
  8154. $.jstree.defaults.unique = {
  8155. /**
  8156. * Indicates if the comparison should be case sensitive. Default is `false`.
  8157. * @name $.jstree.defaults.unique.case_sensitive
  8158. * @plugin unique
  8159. */
  8160. case_sensitive : false,
  8161. /**
  8162. * Indicates if white space should be trimmed before the comparison. Default is `false`.
  8163. * @name $.jstree.defaults.unique.trim_whitespace
  8164. * @plugin unique
  8165. */
  8166. trim_whitespace : false,
  8167. /**
  8168. * A callback executed in the instance's scope when a new node is created and the name is already taken, the two arguments are the conflicting name and the counter. The default will produce results like `New node (2)`.
  8169. * @name $.jstree.defaults.unique.duplicate
  8170. * @plugin unique
  8171. */
  8172. duplicate : function (name, counter) {
  8173. return name + ' (' + counter + ')';
  8174. }
  8175. };
  8176. $.jstree.plugins.unique = function (options, parent) {
  8177. this.check = function (chk, obj, par, pos, more) {
  8178. if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
  8179. obj = obj && obj.id ? obj : this.get_node(obj);
  8180. par = par && par.id ? par : this.get_node(par);
  8181. if(!par || !par.children) { return true; }
  8182. var n = chk === "rename_node" ? pos : obj.text,
  8183. c = [],
  8184. s = this.settings.unique.case_sensitive,
  8185. w = this.settings.unique.trim_whitespace,
  8186. m = this._model.data, i, j, t;
  8187. for(i = 0, j = par.children.length; i < j; i++) {
  8188. t = m[par.children[i]].text;
  8189. if (!s) {
  8190. t = t.toLowerCase();
  8191. }
  8192. if (w) {
  8193. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8194. }
  8195. c.push(t);
  8196. }
  8197. if(!s) { n = n.toLowerCase(); }
  8198. if (w) { n = n.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }
  8199. switch(chk) {
  8200. case "delete_node":
  8201. return true;
  8202. case "rename_node":
  8203. t = obj.text || '';
  8204. if (!s) {
  8205. t = t.toLowerCase();
  8206. }
  8207. if (w) {
  8208. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8209. }
  8210. i = ($.inArray(n, c) === -1 || (obj.text && t === n));
  8211. if(!i) {
  8212. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_01', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  8213. }
  8214. return i;
  8215. case "create_node":
  8216. i = ($.inArray(n, c) === -1);
  8217. if(!i) {
  8218. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_04', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  8219. }
  8220. return i;
  8221. case "copy_node":
  8222. i = ($.inArray(n, c) === -1);
  8223. if(!i) {
  8224. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_02', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  8225. }
  8226. return i;
  8227. case "move_node":
  8228. i = ( (obj.parent === par.id && (!more || !more.is_multi)) || $.inArray(n, c) === -1);
  8229. if(!i) {
  8230. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_03', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  8231. }
  8232. return i;
  8233. }
  8234. return true;
  8235. };
  8236. this.create_node = function (par, node, pos, callback, is_loaded) {
  8237. if(!node || node.text === undefined) {
  8238. if(par === null) {
  8239. par = $.jstree.root;
  8240. }
  8241. par = this.get_node(par);
  8242. if(!par) {
  8243. return parent.create_node.call(this, par, node, pos, callback, is_loaded);
  8244. }
  8245. pos = pos === undefined ? "last" : pos;
  8246. if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
  8247. return parent.create_node.call(this, par, node, pos, callback, is_loaded);
  8248. }
  8249. if(!node) { node = {}; }
  8250. var tmp, n, dpc, i, j, m = this._model.data, s = this.settings.unique.case_sensitive, w = this.settings.unique.trim_whitespace, cb = this.settings.unique.duplicate, t;
  8251. n = tmp = this.get_string('New node');
  8252. dpc = [];
  8253. for(i = 0, j = par.children.length; i < j; i++) {
  8254. t = m[par.children[i]].text;
  8255. if (!s) {
  8256. t = t.toLowerCase();
  8257. }
  8258. if (w) {
  8259. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8260. }
  8261. dpc.push(t);
  8262. }
  8263. i = 1;
  8264. t = n;
  8265. if (!s) {
  8266. t = t.toLowerCase();
  8267. }
  8268. if (w) {
  8269. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8270. }
  8271. while($.inArray(t, dpc) !== -1) {
  8272. n = cb.call(this, tmp, (++i)).toString();
  8273. t = n;
  8274. if (!s) {
  8275. t = t.toLowerCase();
  8276. }
  8277. if (w) {
  8278. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8279. }
  8280. }
  8281. node.text = n;
  8282. }
  8283. return parent.create_node.call(this, par, node, pos, callback, is_loaded);
  8284. };
  8285. };
  8286. // include the unique plugin by default
  8287. // $.jstree.defaults.plugins.push("unique");
  8288. /**
  8289. * ### Wholerow plugin
  8290. *
  8291. * Makes each node appear block level. Making selection easier. May cause slow down for large trees in old browsers.
  8292. */
  8293. var div = document.createElement('DIV');
  8294. div.setAttribute('unselectable','on');
  8295. div.setAttribute('role','presentation');
  8296. div.className = 'jstree-wholerow';
  8297. div.innerHTML = '&#160;';
  8298. $.jstree.plugins.wholerow = function (options, parent) {
  8299. this.bind = function () {
  8300. parent.bind.call(this);
  8301. this.element
  8302. .on('ready.jstree set_state.jstree', $.proxy(function () {
  8303. this.hide_dots();
  8304. }, this))
  8305. .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
  8306. //div.style.height = this._data.core.li_height + 'px';
  8307. this.get_container_ul().addClass('jstree-wholerow-ul');
  8308. }, this))
  8309. .on("deselect_all.jstree", $.proxy(function (e, data) {
  8310. this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
  8311. }, this))
  8312. .on("changed.jstree", $.proxy(function (e, data) {
  8313. this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
  8314. var tmp = false, i, j;
  8315. for(i = 0, j = data.selected.length; i < j; i++) {
  8316. tmp = this.get_node(data.selected[i], true);
  8317. if(tmp && tmp.length) {
  8318. tmp.children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
  8319. }
  8320. }
  8321. }, this))
  8322. .on("open_node.jstree", $.proxy(function (e, data) {
  8323. this.get_node(data.node, true).find('.jstree-clicked').parent().children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
  8324. }, this))
  8325. .on("hover_node.jstree dehover_node.jstree", $.proxy(function (e, data) {
  8326. if(e.type === "hover_node" && this.is_disabled(data.node)) { return; }
  8327. this.get_node(data.node, true).children('.jstree-wholerow')[e.type === "hover_node"?"addClass":"removeClass"]('jstree-wholerow-hovered');
  8328. }, this))
  8329. .on("contextmenu.jstree", ".jstree-wholerow", $.proxy(function (e) {
  8330. if (this._data.contextmenu) {
  8331. e.preventDefault();
  8332. var tmp = $.Event('contextmenu', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey, pageX : e.pageX, pageY : e.pageY });
  8333. $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp);
  8334. }
  8335. }, this))
  8336. /*!
  8337. .on("mousedown.jstree touchstart.jstree", ".jstree-wholerow", function (e) {
  8338. if(e.target === e.currentTarget) {
  8339. var a = $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor");
  8340. e.target = a[0];
  8341. a.trigger(e);
  8342. }
  8343. })
  8344. */
  8345. .on("click.jstree", ".jstree-wholerow", function (e) {
  8346. e.stopImmediatePropagation();
  8347. var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
  8348. $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
  8349. })
  8350. .on("dblclick.jstree", ".jstree-wholerow", function (e) {
  8351. e.stopImmediatePropagation();
  8352. var tmp = $.Event('dblclick', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
  8353. $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
  8354. })
  8355. .on("click.jstree", ".jstree-leaf > .jstree-ocl", $.proxy(function (e) {
  8356. e.stopImmediatePropagation();
  8357. var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
  8358. $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
  8359. }, this))
  8360. .on("mouseover.jstree", ".jstree-wholerow, .jstree-icon", $.proxy(function (e) {
  8361. e.stopImmediatePropagation();
  8362. if(!this.is_disabled(e.currentTarget)) {
  8363. this.hover_node(e.currentTarget);
  8364. }
  8365. return false;
  8366. }, this))
  8367. .on("mouseleave.jstree", ".jstree-node", $.proxy(function (e) {
  8368. this.dehover_node(e.currentTarget);
  8369. }, this));
  8370. };
  8371. this.teardown = function () {
  8372. if(this.settings.wholerow) {
  8373. this.element.find(".jstree-wholerow").remove();
  8374. }
  8375. parent.teardown.call(this);
  8376. };
  8377. this.redraw_node = function(obj, deep, callback, force_render) {
  8378. obj = parent.redraw_node.apply(this, arguments);
  8379. if(obj) {
  8380. var tmp = div.cloneNode(true);
  8381. //tmp.style.height = this._data.core.li_height + 'px';
  8382. if($.inArray(obj.id, this._data.core.selected) !== -1) { tmp.className += ' jstree-wholerow-clicked'; }
  8383. if(this._data.core.focused && this._data.core.focused === obj.id) { tmp.className += ' jstree-wholerow-hovered'; }
  8384. obj.insertBefore(tmp, obj.childNodes[0]);
  8385. }
  8386. return obj;
  8387. };
  8388. };
  8389. // include the wholerow plugin by default
  8390. // $.jstree.defaults.plugins.push("wholerow");
  8391. if(document.registerElement && Object && Object.create) {
  8392. var proto = Object.create(HTMLElement.prototype);
  8393. proto.createdCallback = function () {
  8394. var c = { core : {}, plugins : [] }, i;
  8395. for(i in $.jstree.plugins) {
  8396. if($.jstree.plugins.hasOwnProperty(i) && this.attributes[i]) {
  8397. c.plugins.push(i);
  8398. if(this.getAttribute(i) && JSON.parse(this.getAttribute(i))) {
  8399. c[i] = JSON.parse(this.getAttribute(i));
  8400. }
  8401. }
  8402. }
  8403. for(i in $.jstree.defaults.core) {
  8404. if($.jstree.defaults.core.hasOwnProperty(i) && this.attributes[i]) {
  8405. c.core[i] = JSON.parse(this.getAttribute(i)) || this.getAttribute(i);
  8406. }
  8407. }
  8408. $(this).jstree(c);
  8409. };
  8410. // proto.attributeChangedCallback = function (name, previous, value) { };
  8411. try {
  8412. document.registerElement("vakata-jstree", { prototype: proto });
  8413. } catch(ignore) { }
  8414. }
  8415. }));