jstree.js 299 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647
  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.10
  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. var setImmediate = window.setImmediate;
  45. var Promise = window.Promise;
  46. if (!setImmediate && Promise) {
  47. // Good enough approximation of setImmediate
  48. setImmediate = function (cb, arg) {
  49. Promise.resolve(arg).then(cb);
  50. };
  51. }
  52. /**
  53. * holds all jstree related functions and variables, including the actual class and methods to create, access and manipulate instances.
  54. * @name $.jstree
  55. */
  56. $.jstree = {
  57. /**
  58. * specifies the jstree version in use
  59. * @name $.jstree.version
  60. */
  61. version : '3.3.10',
  62. /**
  63. * holds all the default options used when creating new instances
  64. * @name $.jstree.defaults
  65. */
  66. defaults : {
  67. /**
  68. * 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 `[]`
  69. * @name $.jstree.defaults.plugins
  70. */
  71. plugins : []
  72. },
  73. /**
  74. * stores all loaded jstree plugins (used internally)
  75. * @name $.jstree.plugins
  76. */
  77. plugins : {},
  78. path : src && src.indexOf('/') !== -1 ? src.replace(/\/[^\/]+$/,'') : '',
  79. idregex : /[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g,
  80. root : '#'
  81. };
  82. /**
  83. * creates a jstree instance
  84. * @name $.jstree.create(el [, options])
  85. * @param {DOMElement|jQuery|String} el the element to create the instance on, can be jQuery extended or a selector
  86. * @param {Object} options options for this instance (extends `$.jstree.defaults`)
  87. * @return {jsTree} the new instance
  88. */
  89. $.jstree.create = function (el, options) {
  90. var tmp = new $.jstree.core(++instance_counter),
  91. opt = options;
  92. options = $.extend(true, {}, $.jstree.defaults, options);
  93. if(opt && opt.plugins) {
  94. options.plugins = opt.plugins;
  95. }
  96. $.each(options.plugins, function (i, k) {
  97. if(i !== 'core') {
  98. tmp = tmp.plugin(k, options[k]);
  99. }
  100. });
  101. $(el).data('jstree', tmp);
  102. tmp.init(el, options);
  103. return tmp;
  104. };
  105. /**
  106. * remove all traces of jstree from the DOM and destroy all instances
  107. * @name $.jstree.destroy()
  108. */
  109. $.jstree.destroy = function () {
  110. $('.jstree:jstree').jstree('destroy');
  111. $(document).off('.jstree');
  112. };
  113. /**
  114. * the jstree class constructor, used only internally
  115. * @private
  116. * @name $.jstree.core(id)
  117. * @param {Number} id this instance's index
  118. */
  119. $.jstree.core = function (id) {
  120. this._id = id;
  121. this._cnt = 0;
  122. this._wrk = null;
  123. this._data = {
  124. core : {
  125. themes : {
  126. name : false,
  127. dots : false,
  128. icons : false,
  129. ellipsis : false
  130. },
  131. selected : [],
  132. last_error : {},
  133. working : false,
  134. worker_queue : [],
  135. focused : null
  136. }
  137. };
  138. };
  139. /**
  140. * get a reference to an existing instance
  141. *
  142. * __Examples__
  143. *
  144. * // provided a container with an ID of "tree", and a nested node with an ID of "branch"
  145. * // all of there will return the same instance
  146. * $.jstree.reference('tree');
  147. * $.jstree.reference('#tree');
  148. * $.jstree.reference($('#tree'));
  149. * $.jstree.reference(document.getElementByID('tree'));
  150. * $.jstree.reference('branch');
  151. * $.jstree.reference('#branch');
  152. * $.jstree.reference($('#branch'));
  153. * $.jstree.reference(document.getElementByID('branch'));
  154. *
  155. * @name $.jstree.reference(needle)
  156. * @param {DOMElement|jQuery|String} needle
  157. * @return {jsTree|null} the instance or `null` if not found
  158. */
  159. $.jstree.reference = function (needle) {
  160. var tmp = null,
  161. obj = null;
  162. if(needle && needle.id && (!needle.tagName || !needle.nodeType)) { needle = needle.id; }
  163. if(!obj || !obj.length) {
  164. try { obj = $(needle); } catch (ignore) { }
  165. }
  166. if(!obj || !obj.length) {
  167. try { obj = $('#' + needle.replace($.jstree.idregex,'\\$&')); } catch (ignore) { }
  168. }
  169. if(obj && obj.length && (obj = obj.closest('.jstree')).length && (obj = obj.data('jstree'))) {
  170. tmp = obj;
  171. }
  172. else {
  173. $('.jstree').each(function () {
  174. var inst = $(this).data('jstree');
  175. if(inst && inst._model.data[needle]) {
  176. tmp = inst;
  177. return false;
  178. }
  179. });
  180. }
  181. return tmp;
  182. };
  183. /**
  184. * Create an instance, get an instance or invoke a command on a instance.
  185. *
  186. * 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).
  187. *
  188. * 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).
  189. *
  190. * If there is an existing instance and `arg` is not a string the instance itself is returned (similar to `$.jstree.reference`).
  191. *
  192. * In any other case - nothing is returned and chaining is not broken.
  193. *
  194. * __Examples__
  195. *
  196. * $('#tree1').jstree(); // creates an instance
  197. * $('#tree2').jstree({ plugins : [] }); // create an instance with some options
  198. * $('#tree1').jstree('open_node', '#branch_1'); // call a method on an existing instance, passing additional arguments
  199. * $('#tree2').jstree(); // get an existing instance (or create an instance)
  200. * $('#tree2').jstree(true); // get an existing instance (will not create new instance)
  201. * $('#branch_1').jstree().select_node('#branch_1'); // get an instance (using a nested element and call a method)
  202. *
  203. * @name $().jstree([arg])
  204. * @param {String|Object} arg
  205. * @return {Mixed}
  206. */
  207. $.fn.jstree = function (arg) {
  208. // check for string argument
  209. var is_method = (typeof arg === 'string'),
  210. args = Array.prototype.slice.call(arguments, 1),
  211. result = null;
  212. if(arg === true && !this.length) { return false; }
  213. this.each(function () {
  214. // get the instance (if there is one) and method (if it exists)
  215. var instance = $.jstree.reference(this),
  216. method = is_method && instance ? instance[arg] : null;
  217. // if calling a method, and method is available - execute on the instance
  218. result = is_method && method ?
  219. method.apply(instance, args) :
  220. null;
  221. // if there is no instance and no method is being called - create one
  222. if(!instance && !is_method && (arg === undefined || $.isPlainObject(arg))) {
  223. $.jstree.create(this, arg);
  224. }
  225. // if there is an instance and no method is called - return the instance
  226. if( (instance && !is_method) || arg === true ) {
  227. result = instance || false;
  228. }
  229. // if there was a method call which returned a result - break and return the value
  230. if(result !== null && result !== undefined) {
  231. return false;
  232. }
  233. });
  234. // if there was a method call with a valid return value - return that, otherwise continue the chain
  235. return result !== null && result !== undefined ?
  236. result : this;
  237. };
  238. /**
  239. * used to find elements containing an instance
  240. *
  241. * __Examples__
  242. *
  243. * $('div:jstree').each(function () {
  244. * $(this).jstree('destroy');
  245. * });
  246. *
  247. * @name $(':jstree')
  248. * @return {jQuery}
  249. */
  250. $.expr.pseudos.jstree = $.expr.createPseudo(function(search) {
  251. return function(a) {
  252. return $(a).hasClass('jstree') &&
  253. $(a).data('jstree') !== undefined;
  254. };
  255. });
  256. /**
  257. * stores all defaults for the core
  258. * @name $.jstree.defaults.core
  259. */
  260. $.jstree.defaults.core = {
  261. /**
  262. * data configuration
  263. *
  264. * 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).
  265. *
  266. * You can also pass in a HTML string or a JSON array here.
  267. *
  268. * 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.
  269. * 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.
  270. *
  271. * 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.
  272. *
  273. * __Examples__
  274. *
  275. * // AJAX
  276. * $('#tree').jstree({
  277. * 'core' : {
  278. * 'data' : {
  279. * 'url' : '/get/children/',
  280. * 'data' : function (node) {
  281. * return { 'id' : node.id };
  282. * }
  283. * }
  284. * });
  285. *
  286. * // direct data
  287. * $('#tree').jstree({
  288. * 'core' : {
  289. * 'data' : [
  290. * 'Simple root node',
  291. * {
  292. * 'id' : 'node_2',
  293. * 'text' : 'Root node with options',
  294. * 'state' : { 'opened' : true, 'selected' : true },
  295. * 'children' : [ { 'text' : 'Child 1' }, 'Child 2']
  296. * }
  297. * ]
  298. * }
  299. * });
  300. *
  301. * // function
  302. * $('#tree').jstree({
  303. * 'core' : {
  304. * 'data' : function (obj, callback) {
  305. * callback.call(this, ['Root 1', 'Root 2']);
  306. * }
  307. * });
  308. *
  309. * @name $.jstree.defaults.core.data
  310. */
  311. data : false,
  312. /**
  313. * configure the various strings used throughout the tree
  314. *
  315. * You can use an object where the key is the string you need to replace and the value is your replacement.
  316. * Another option is to specify a function which will be called with an argument of the needed string and should return the replacement.
  317. * If left as `false` no replacement is made.
  318. *
  319. * __Examples__
  320. *
  321. * $('#tree').jstree({
  322. * 'core' : {
  323. * 'strings' : {
  324. * 'Loading ...' : 'Please wait ...'
  325. * }
  326. * }
  327. * });
  328. *
  329. * @name $.jstree.defaults.core.strings
  330. */
  331. strings : false,
  332. /**
  333. * determines what happens when a user tries to modify the structure of the tree
  334. * If left as `false` all operations like create, rename, delete, move or copy are prevented.
  335. * You can set this to `true` to allow all interactions or use a function to have better control.
  336. *
  337. * __Examples__
  338. *
  339. * $('#tree').jstree({
  340. * 'core' : {
  341. * 'check_callback' : function (operation, node, node_parent, node_position, more) {
  342. * // operation can be 'create_node', 'rename_node', 'delete_node', 'move_node', 'copy_node' or 'edit'
  343. * // in case of 'rename_node' node_position is filled with the new node name
  344. * return operation === 'rename_node' ? true : false;
  345. * }
  346. * }
  347. * });
  348. *
  349. * @name $.jstree.defaults.core.check_callback
  350. */
  351. check_callback : false,
  352. /**
  353. * a callback called with a single object parameter in the instance's scope when something goes wrong (operation prevented, ajax failed, etc)
  354. * @name $.jstree.defaults.core.error
  355. */
  356. error : $.noop,
  357. /**
  358. * the open / close animation duration in milliseconds - set this to `false` to disable the animation (default is `200`)
  359. * @name $.jstree.defaults.core.animation
  360. */
  361. animation : 200,
  362. /**
  363. * a boolean indicating if multiple nodes can be selected
  364. * @name $.jstree.defaults.core.multiple
  365. */
  366. multiple : true,
  367. /**
  368. * theme configuration object
  369. * @name $.jstree.defaults.core.themes
  370. */
  371. themes : {
  372. /**
  373. * the name of the theme to use (if left as `false` the default theme is used)
  374. * @name $.jstree.defaults.core.themes.name
  375. */
  376. name : false,
  377. /**
  378. * 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.
  379. * @name $.jstree.defaults.core.themes.url
  380. */
  381. url : false,
  382. /**
  383. * the location of all jstree themes - only used if `url` is set to `true`
  384. * @name $.jstree.defaults.core.themes.dir
  385. */
  386. dir : false,
  387. /**
  388. * a boolean indicating if connecting dots are shown
  389. * @name $.jstree.defaults.core.themes.dots
  390. */
  391. dots : true,
  392. /**
  393. * a boolean indicating if node icons are shown
  394. * @name $.jstree.defaults.core.themes.icons
  395. */
  396. icons : true,
  397. /**
  398. * a boolean indicating if node ellipsis should be shown - this only works with a fixed with on the container
  399. * @name $.jstree.defaults.core.themes.ellipsis
  400. */
  401. ellipsis : false,
  402. /**
  403. * a boolean indicating if the tree background is striped
  404. * @name $.jstree.defaults.core.themes.stripes
  405. */
  406. stripes : false,
  407. /**
  408. * a string (or boolean `false`) specifying the theme variant to use (if the theme supports variants)
  409. * @name $.jstree.defaults.core.themes.variant
  410. */
  411. variant : false,
  412. /**
  413. * a boolean specifying if a reponsive version of the theme should kick in on smaller screens (if the theme supports it). Defaults to `false`.
  414. * @name $.jstree.defaults.core.themes.responsive
  415. */
  416. responsive : false
  417. },
  418. /**
  419. * 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)
  420. * @name $.jstree.defaults.core.expand_selected_onload
  421. */
  422. expand_selected_onload : true,
  423. /**
  424. * 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`
  425. * @name $.jstree.defaults.core.worker
  426. */
  427. worker : true,
  428. /**
  429. * Force node text to plain text (and escape HTML). Defaults to `false`
  430. * @name $.jstree.defaults.core.force_text
  431. */
  432. force_text : false,
  433. /**
  434. * Should the node be toggled if the text is double clicked. Defaults to `true`
  435. * @name $.jstree.defaults.core.dblclick_toggle
  436. */
  437. dblclick_toggle : true,
  438. /**
  439. * Should the loaded nodes be part of the state. Defaults to `false`
  440. * @name $.jstree.defaults.core.loaded_state
  441. */
  442. loaded_state : false,
  443. /**
  444. * 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`
  445. * @name $.jstree.defaults.core.restore_focus
  446. */
  447. restore_focus : true,
  448. /**
  449. * 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)
  450. * @name $.jstree.defaults.core.keyboard
  451. */
  452. keyboard : {
  453. 'ctrl-space': function (e) {
  454. // aria defines space only with Ctrl
  455. e.type = "click";
  456. $(e.currentTarget).trigger(e);
  457. },
  458. 'enter': function (e) {
  459. // enter
  460. e.type = "click";
  461. $(e.currentTarget).trigger(e);
  462. },
  463. 'left': function (e) {
  464. // left
  465. e.preventDefault();
  466. if(this.is_open(e.currentTarget)) {
  467. this.close_node(e.currentTarget);
  468. }
  469. else {
  470. var o = this.get_parent(e.currentTarget);
  471. if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').focus(); }
  472. }
  473. },
  474. 'up': function (e) {
  475. // up
  476. e.preventDefault();
  477. var o = this.get_prev_dom(e.currentTarget);
  478. if(o && o.length) { o.children('.jstree-anchor').focus(); }
  479. },
  480. 'right': function (e) {
  481. // right
  482. e.preventDefault();
  483. if(this.is_closed(e.currentTarget)) {
  484. this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').focus(); });
  485. }
  486. else if (this.is_open(e.currentTarget)) {
  487. var o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
  488. if(o) { $(this._firstChild(o)).children('.jstree-anchor').focus(); }
  489. }
  490. },
  491. 'down': function (e) {
  492. // down
  493. e.preventDefault();
  494. var o = this.get_next_dom(e.currentTarget);
  495. if(o && o.length) { o.children('.jstree-anchor').focus(); }
  496. },
  497. '*': function (e) {
  498. // aria defines * on numpad as open_all - not very common
  499. this.open_all();
  500. },
  501. 'home': function (e) {
  502. // home
  503. e.preventDefault();
  504. var o = this._firstChild(this.get_container_ul()[0]);
  505. if(o) { $(o).children('.jstree-anchor').filter(':visible').focus(); }
  506. },
  507. 'end': function (e) {
  508. // end
  509. e.preventDefault();
  510. this.element.find('.jstree-anchor').filter(':visible').last().focus();
  511. },
  512. 'f2': function (e) {
  513. // f2 - safe to include - if check_callback is false it will fail
  514. e.preventDefault();
  515. this.edit(e.currentTarget);
  516. }
  517. }
  518. };
  519. $.jstree.core.prototype = {
  520. /**
  521. * used to decorate an instance with a plugin. Used internally.
  522. * @private
  523. * @name plugin(deco [, opts])
  524. * @param {String} deco the plugin to decorate with
  525. * @param {Object} opts options for the plugin
  526. * @return {jsTree}
  527. */
  528. plugin : function (deco, opts) {
  529. var Child = $.jstree.plugins[deco];
  530. if(Child) {
  531. this._data[deco] = {};
  532. Child.prototype = this;
  533. return new Child(opts, this);
  534. }
  535. return this;
  536. },
  537. /**
  538. * initialize the instance. Used internally.
  539. * @private
  540. * @name init(el, optons)
  541. * @param {DOMElement|jQuery|String} el the element we are transforming
  542. * @param {Object} options options for this instance
  543. * @trigger init.jstree, loading.jstree, loaded.jstree, ready.jstree, changed.jstree
  544. */
  545. init : function (el, options) {
  546. this._model = {
  547. data : {},
  548. changed : [],
  549. force_full_redraw : false,
  550. redraw_timeout : false,
  551. default_state : {
  552. loaded : true,
  553. opened : false,
  554. selected : false,
  555. disabled : false
  556. }
  557. };
  558. this._model.data[$.jstree.root] = {
  559. id : $.jstree.root,
  560. parent : null,
  561. parents : [],
  562. children : [],
  563. children_d : [],
  564. state : { loaded : false }
  565. };
  566. this.element = $(el).addClass('jstree jstree-' + this._id);
  567. this.settings = options;
  568. this._data.core.ready = false;
  569. this._data.core.loaded = false;
  570. this._data.core.rtl = (this.element.css("direction") === "rtl");
  571. this.element[this._data.core.rtl ? 'addClass' : 'removeClass']("jstree-rtl");
  572. this.element.attr('role','tree');
  573. if(this.settings.core.multiple) {
  574. this.element.attr('aria-multiselectable', true);
  575. }
  576. if(!this.element.attr('tabindex')) {
  577. this.element.attr('tabindex','0');
  578. }
  579. this.bind();
  580. /**
  581. * triggered after all events are bound
  582. * @event
  583. * @name init.jstree
  584. */
  585. this.trigger("init");
  586. this._data.core.original_container_html = this.element.find(" > ul > li").clone(true);
  587. this._data.core.original_container_html
  588. .find("li").addBack()
  589. .contents().filter(function() {
  590. return this.nodeType === 3 && (!this.nodeValue || /^\s+$/.test(this.nodeValue));
  591. })
  592. .remove();
  593. 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='presentation'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' role='treeitem' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
  594. this.element.attr('aria-activedescendant','j' + this._id + '_loading');
  595. this._data.core.li_height = this.get_container_ul().children("li").first().outerHeight() || 24;
  596. this._data.core.node = this._create_prototype_node();
  597. /**
  598. * triggered after the loading text is shown and before loading starts
  599. * @event
  600. * @name loading.jstree
  601. */
  602. this.trigger("loading");
  603. this.load_node($.jstree.root);
  604. },
  605. /**
  606. * destroy an instance
  607. * @name destroy()
  608. * @param {Boolean} keep_html if not set to `true` the container will be emptied, otherwise the current DOM elements will be kept intact
  609. */
  610. destroy : function (keep_html) {
  611. /**
  612. * triggered before the tree is destroyed
  613. * @event
  614. * @name destroy.jstree
  615. */
  616. this.trigger("destroy");
  617. if(this._wrk) {
  618. try {
  619. window.URL.revokeObjectURL(this._wrk);
  620. this._wrk = null;
  621. }
  622. catch (ignore) { }
  623. }
  624. if(!keep_html) { this.element.empty(); }
  625. this.teardown();
  626. },
  627. /**
  628. * Create a prototype node
  629. * @name _create_prototype_node()
  630. * @return {DOMElement}
  631. */
  632. _create_prototype_node : function () {
  633. var _node = document.createElement('LI'), _temp1, _temp2;
  634. _node.setAttribute('role', 'presentation');
  635. _temp1 = document.createElement('I');
  636. _temp1.className = 'jstree-icon jstree-ocl';
  637. _temp1.setAttribute('role', 'presentation');
  638. _node.appendChild(_temp1);
  639. _temp1 = document.createElement('A');
  640. _temp1.className = 'jstree-anchor';
  641. _temp1.setAttribute('href','#');
  642. _temp1.setAttribute('tabindex','-1');
  643. _temp1.setAttribute('role', 'treeitem');
  644. _temp2 = document.createElement('I');
  645. _temp2.className = 'jstree-icon jstree-themeicon';
  646. _temp2.setAttribute('role', 'presentation');
  647. _temp1.appendChild(_temp2);
  648. _node.appendChild(_temp1);
  649. _temp1 = _temp2 = null;
  650. return _node;
  651. },
  652. _kbevent_to_func : function (e) {
  653. var keys = {
  654. 8: "Backspace", 9: "Tab", 13: "Enter", 19: "Pause", 27: "Esc",
  655. 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home",
  656. 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "Print", 45: "Insert",
  657. 46: "Delete", 96: "Numpad0", 97: "Numpad1", 98: "Numpad2", 99 : "Numpad3",
  658. 100: "Numpad4", 101: "Numpad5", 102: "Numpad6", 103: "Numpad7",
  659. 104: "Numpad8", 105: "Numpad9", '-13': "NumpadEnter", 112: "F1",
  660. 113: "F2", 114: "F3", 115: "F4", 116: "F5", 117: "F6", 118: "F7",
  661. 119: "F8", 120: "F9", 121: "F10", 122: "F11", 123: "F12", 144: "Numlock",
  662. 145: "Scrolllock", 16: 'Shift', 17: 'Ctrl', 18: 'Alt',
  663. 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  664. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  665. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  666. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  667. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  668. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  669. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  670. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*', 173: '-'
  671. };
  672. var parts = [];
  673. if (e.ctrlKey) { parts.push('ctrl'); }
  674. if (e.altKey) { parts.push('alt'); }
  675. if (e.shiftKey) { parts.push('shift'); }
  676. parts.push(keys[e.which] || e.which);
  677. parts = parts.sort().join('-').toLowerCase();
  678. if (parts === 'shift-shift' || parts === 'ctrl-ctrl' || parts === 'alt-alt') {
  679. return null;
  680. }
  681. var kb = this.settings.core.keyboard, i, tmp;
  682. for (i in kb) {
  683. if (kb.hasOwnProperty(i)) {
  684. tmp = i;
  685. if (tmp !== '-' && tmp !== '+') {
  686. tmp = tmp.replace('--', '-MINUS').replace('+-', '-MINUS').replace('++', '-PLUS').replace('-+', '-PLUS');
  687. tmp = tmp.split(/-|\+/).sort().join('-').replace('MINUS', '-').replace('PLUS', '+').toLowerCase();
  688. }
  689. if (tmp === parts) {
  690. return kb[i];
  691. }
  692. }
  693. }
  694. return null;
  695. },
  696. /**
  697. * part of the destroying of an instance. Used internally.
  698. * @private
  699. * @name teardown()
  700. */
  701. teardown : function () {
  702. this.unbind();
  703. this.element
  704. .removeClass('jstree')
  705. .removeData('jstree')
  706. .find("[class^='jstree']")
  707. .addBack()
  708. .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });
  709. this.element = null;
  710. },
  711. /**
  712. * bind all events. Used internally.
  713. * @private
  714. * @name bind()
  715. */
  716. bind : function () {
  717. var word = '',
  718. tout = null,
  719. was_click = 0;
  720. this.element
  721. .on("dblclick.jstree", function (e) {
  722. if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
  723. if(document.selection && document.selection.empty) {
  724. document.selection.empty();
  725. }
  726. else {
  727. if(window.getSelection) {
  728. var sel = window.getSelection();
  729. try {
  730. sel.removeAllRanges();
  731. sel.collapse();
  732. } catch (ignore) { }
  733. }
  734. }
  735. })
  736. .on("mousedown.jstree", $.proxy(function (e) {
  737. if(e.target === this.element[0]) {
  738. e.preventDefault(); // prevent losing focus when clicking scroll arrows (FF, Chrome)
  739. was_click = +(new Date()); // ie does not allow to prevent losing focus
  740. }
  741. }, this))
  742. .on("mousedown.jstree", ".jstree-ocl", function (e) {
  743. e.preventDefault(); // prevent any node inside from losing focus when clicking the open/close icon
  744. })
  745. .on("click.jstree", ".jstree-ocl", $.proxy(function (e) {
  746. this.toggle_node(e.target);
  747. }, this))
  748. .on("dblclick.jstree", ".jstree-anchor", $.proxy(function (e) {
  749. if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
  750. if(this.settings.core.dblclick_toggle) {
  751. this.toggle_node(e.target);
  752. }
  753. }, this))
  754. .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
  755. e.preventDefault();
  756. if(e.currentTarget !== document.activeElement) { $(e.currentTarget).focus(); }
  757. this.activate_node(e.currentTarget, e);
  758. }, this))
  759. .on('keydown.jstree', '.jstree-anchor', $.proxy(function (e) {
  760. if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
  761. if(this._data.core.rtl) {
  762. if(e.which === 37) { e.which = 39; }
  763. else if(e.which === 39) { e.which = 37; }
  764. }
  765. var f = this._kbevent_to_func(e);
  766. if (f) {
  767. var r = f.call(this, e);
  768. if (r === false || r === true) {
  769. return r;
  770. }
  771. }
  772. }, this))
  773. .on("load_node.jstree", $.proxy(function (e, data) {
  774. if(data.status) {
  775. if(data.node.id === $.jstree.root && !this._data.core.loaded) {
  776. this._data.core.loaded = true;
  777. if(this._firstChild(this.get_container_ul()[0])) {
  778. this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
  779. }
  780. /**
  781. * triggered after the root node is loaded for the first time
  782. * @event
  783. * @name loaded.jstree
  784. */
  785. this.trigger("loaded");
  786. }
  787. if(!this._data.core.ready) {
  788. setTimeout($.proxy(function() {
  789. if(this.element && !this.get_container_ul().find('.jstree-loading').length) {
  790. this._data.core.ready = true;
  791. if(this._data.core.selected.length) {
  792. if(this.settings.core.expand_selected_onload) {
  793. var tmp = [], i, j;
  794. for(i = 0, j = this._data.core.selected.length; i < j; i++) {
  795. tmp = tmp.concat(this._model.data[this._data.core.selected[i]].parents);
  796. }
  797. tmp = $.vakata.array_unique(tmp);
  798. for(i = 0, j = tmp.length; i < j; i++) {
  799. this.open_node(tmp[i], false, 0);
  800. }
  801. }
  802. this.trigger('changed', { 'action' : 'ready', 'selected' : this._data.core.selected });
  803. }
  804. /**
  805. * triggered after all nodes are finished loading
  806. * @event
  807. * @name ready.jstree
  808. */
  809. this.trigger("ready");
  810. }
  811. }, this), 0);
  812. }
  813. }
  814. }, this))
  815. // quick searching when the tree is focused
  816. .on('keypress.jstree', $.proxy(function (e) {
  817. if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
  818. if(tout) { clearTimeout(tout); }
  819. tout = setTimeout(function () {
  820. word = '';
  821. }, 500);
  822. var chr = String.fromCharCode(e.which).toLowerCase(),
  823. col = this.element.find('.jstree-anchor').filter(':visible'),
  824. ind = col.index(document.activeElement) || 0,
  825. end = false;
  826. word += chr;
  827. // match for whole word from current node down (including the current node)
  828. if(word.length > 1) {
  829. col.slice(ind).each($.proxy(function (i, v) {
  830. if($(v).text().toLowerCase().indexOf(word) === 0) {
  831. $(v).focus();
  832. end = true;
  833. return false;
  834. }
  835. }, this));
  836. if(end) { return; }
  837. // match for whole word from the beginning of the tree
  838. col.slice(0, ind).each($.proxy(function (i, v) {
  839. if($(v).text().toLowerCase().indexOf(word) === 0) {
  840. $(v).focus();
  841. end = true;
  842. return false;
  843. }
  844. }, this));
  845. if(end) { return; }
  846. }
  847. // list nodes that start with that letter (only if word consists of a single char)
  848. if(new RegExp('^' + chr.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '+$').test(word)) {
  849. // search for the next node starting with that letter
  850. col.slice(ind + 1).each($.proxy(function (i, v) {
  851. if($(v).text().toLowerCase().charAt(0) === chr) {
  852. $(v).focus();
  853. end = true;
  854. return false;
  855. }
  856. }, this));
  857. if(end) { return; }
  858. // search from the beginning
  859. col.slice(0, ind + 1).each($.proxy(function (i, v) {
  860. if($(v).text().toLowerCase().charAt(0) === chr) {
  861. $(v).focus();
  862. end = true;
  863. return false;
  864. }
  865. }, this));
  866. if(end) { return; }
  867. }
  868. }, this))
  869. // THEME RELATED
  870. .on("init.jstree", $.proxy(function () {
  871. var s = this.settings.core.themes;
  872. this._data.core.themes.dots = s.dots;
  873. this._data.core.themes.stripes = s.stripes;
  874. this._data.core.themes.icons = s.icons;
  875. this._data.core.themes.ellipsis = s.ellipsis;
  876. this.set_theme(s.name || "default", s.url);
  877. this.set_theme_variant(s.variant);
  878. }, this))
  879. .on("loading.jstree", $.proxy(function () {
  880. this[ this._data.core.themes.dots ? "show_dots" : "hide_dots" ]();
  881. this[ this._data.core.themes.icons ? "show_icons" : "hide_icons" ]();
  882. this[ this._data.core.themes.stripes ? "show_stripes" : "hide_stripes" ]();
  883. this[ this._data.core.themes.ellipsis ? "show_ellipsis" : "hide_ellipsis" ]();
  884. }, this))
  885. .on('blur.jstree', '.jstree-anchor', $.proxy(function (e) {
  886. this._data.core.focused = null;
  887. $(e.currentTarget).filter('.jstree-hovered').trigger('mouseleave');
  888. this.element.attr('tabindex', '0');
  889. }, this))
  890. .on('focus.jstree', '.jstree-anchor', $.proxy(function (e) {
  891. var tmp = this.get_node(e.currentTarget);
  892. if(tmp && tmp.id) {
  893. this._data.core.focused = tmp.id;
  894. }
  895. this.element.find('.jstree-hovered').not(e.currentTarget).trigger('mouseleave');
  896. $(e.currentTarget).trigger('mouseenter');
  897. this.element.attr('tabindex', '-1');
  898. }, this))
  899. .on('focus.jstree', $.proxy(function () {
  900. if(+(new Date()) - was_click > 500 && !this._data.core.focused && this.settings.core.restore_focus) {
  901. was_click = 0;
  902. var act = this.get_node(this.element.attr('aria-activedescendant'), true);
  903. if(act) {
  904. act.find('> .jstree-anchor').focus();
  905. }
  906. }
  907. }, this))
  908. .on('mouseenter.jstree', '.jstree-anchor', $.proxy(function (e) {
  909. this.hover_node(e.currentTarget);
  910. }, this))
  911. .on('mouseleave.jstree', '.jstree-anchor', $.proxy(function (e) {
  912. this.dehover_node(e.currentTarget);
  913. }, this));
  914. },
  915. /**
  916. * part of the destroying of an instance. Used internally.
  917. * @private
  918. * @name unbind()
  919. */
  920. unbind : function () {
  921. this.element.off('.jstree');
  922. $(document).off('.jstree-' + this._id);
  923. },
  924. /**
  925. * trigger an event. Used internally.
  926. * @private
  927. * @name trigger(ev [, data])
  928. * @param {String} ev the name of the event to trigger
  929. * @param {Object} data additional data to pass with the event
  930. */
  931. trigger : function (ev, data) {
  932. if(!data) {
  933. data = {};
  934. }
  935. data.instance = this;
  936. this.element.triggerHandler(ev.replace('.jstree','') + '.jstree', data);
  937. },
  938. /**
  939. * returns the jQuery extended instance container
  940. * @name get_container()
  941. * @return {jQuery}
  942. */
  943. get_container : function () {
  944. return this.element;
  945. },
  946. /**
  947. * returns the jQuery extended main UL node inside the instance container. Used internally.
  948. * @private
  949. * @name get_container_ul()
  950. * @return {jQuery}
  951. */
  952. get_container_ul : function () {
  953. return this.element.children(".jstree-children").first();
  954. },
  955. /**
  956. * gets string replacements (localization). Used internally.
  957. * @private
  958. * @name get_string(key)
  959. * @param {String} key
  960. * @return {String}
  961. */
  962. get_string : function (key) {
  963. var a = this.settings.core.strings;
  964. if($.isFunction(a)) { return a.call(this, key); }
  965. if(a && a[key]) { return a[key]; }
  966. return key;
  967. },
  968. /**
  969. * gets the first child of a DOM node. Used internally.
  970. * @private
  971. * @name _firstChild(dom)
  972. * @param {DOMElement} dom
  973. * @return {DOMElement}
  974. */
  975. _firstChild : function (dom) {
  976. dom = dom ? dom.firstChild : null;
  977. while(dom !== null && dom.nodeType !== 1) {
  978. dom = dom.nextSibling;
  979. }
  980. return dom;
  981. },
  982. /**
  983. * gets the next sibling of a DOM node. Used internally.
  984. * @private
  985. * @name _nextSibling(dom)
  986. * @param {DOMElement} dom
  987. * @return {DOMElement}
  988. */
  989. _nextSibling : function (dom) {
  990. dom = dom ? dom.nextSibling : null;
  991. while(dom !== null && dom.nodeType !== 1) {
  992. dom = dom.nextSibling;
  993. }
  994. return dom;
  995. },
  996. /**
  997. * gets the previous sibling of a DOM node. Used internally.
  998. * @private
  999. * @name _previousSibling(dom)
  1000. * @param {DOMElement} dom
  1001. * @return {DOMElement}
  1002. */
  1003. _previousSibling : function (dom) {
  1004. dom = dom ? dom.previousSibling : null;
  1005. while(dom !== null && dom.nodeType !== 1) {
  1006. dom = dom.previousSibling;
  1007. }
  1008. return dom;
  1009. },
  1010. /**
  1011. * 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)
  1012. * @name get_node(obj [, as_dom])
  1013. * @param {mixed} obj
  1014. * @param {Boolean} as_dom
  1015. * @return {Object|jQuery}
  1016. */
  1017. get_node : function (obj, as_dom) {
  1018. if(obj && obj.id) {
  1019. obj = obj.id;
  1020. }
  1021. if (obj instanceof $ && obj.length && obj[0].id) {
  1022. obj = obj[0].id;
  1023. }
  1024. var dom;
  1025. try {
  1026. if(this._model.data[obj]) {
  1027. obj = this._model.data[obj];
  1028. }
  1029. else if(typeof obj === "string" && this._model.data[obj.replace(/^#/, '')]) {
  1030. obj = this._model.data[obj.replace(/^#/, '')];
  1031. }
  1032. else if(typeof obj === "string" && (dom = $('#' + obj.replace($.jstree.idregex,'\\$&'), this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
  1033. obj = this._model.data[dom.closest('.jstree-node').attr('id')];
  1034. }
  1035. else if((dom = this.element.find(obj)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
  1036. obj = this._model.data[dom.closest('.jstree-node').attr('id')];
  1037. }
  1038. else if((dom = this.element.find(obj)).length && dom.hasClass('jstree')) {
  1039. obj = this._model.data[$.jstree.root];
  1040. }
  1041. else {
  1042. return false;
  1043. }
  1044. if(as_dom) {
  1045. obj = obj.id === $.jstree.root ? this.element : $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
  1046. }
  1047. return obj;
  1048. } catch (ex) { return false; }
  1049. },
  1050. /**
  1051. * get the path to a node, either consisting of node texts, or of node IDs, optionally glued together (otherwise an array)
  1052. * @name get_path(obj [, glue, ids])
  1053. * @param {mixed} obj the node
  1054. * @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
  1055. * @param {Boolean} ids if set to true build the path using ID, otherwise node text is used
  1056. * @return {mixed}
  1057. */
  1058. get_path : function (obj, glue, ids) {
  1059. obj = obj.parents ? obj : this.get_node(obj);
  1060. if(!obj || obj.id === $.jstree.root || !obj.parents) {
  1061. return false;
  1062. }
  1063. var i, j, p = [];
  1064. p.push(ids ? obj.id : obj.text);
  1065. for(i = 0, j = obj.parents.length; i < j; i++) {
  1066. p.push(ids ? obj.parents[i] : this.get_text(obj.parents[i]));
  1067. }
  1068. p = p.reverse().slice(1);
  1069. return glue ? p.join(glue) : p;
  1070. },
  1071. /**
  1072. * get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
  1073. * @name get_next_dom(obj [, strict])
  1074. * @param {mixed} obj
  1075. * @param {Boolean} strict
  1076. * @return {jQuery}
  1077. */
  1078. get_next_dom : function (obj, strict) {
  1079. var tmp;
  1080. obj = this.get_node(obj, true);
  1081. if(obj[0] === this.element[0]) {
  1082. tmp = this._firstChild(this.get_container_ul()[0]);
  1083. while (tmp && tmp.offsetHeight === 0) {
  1084. tmp = this._nextSibling(tmp);
  1085. }
  1086. return tmp ? $(tmp) : false;
  1087. }
  1088. if(!obj || !obj.length) {
  1089. return false;
  1090. }
  1091. if(strict) {
  1092. tmp = obj[0];
  1093. do {
  1094. tmp = this._nextSibling(tmp);
  1095. } while (tmp && tmp.offsetHeight === 0);
  1096. return tmp ? $(tmp) : false;
  1097. }
  1098. if(obj.hasClass("jstree-open")) {
  1099. tmp = this._firstChild(obj.children('.jstree-children')[0]);
  1100. while (tmp && tmp.offsetHeight === 0) {
  1101. tmp = this._nextSibling(tmp);
  1102. }
  1103. if(tmp !== null) {
  1104. return $(tmp);
  1105. }
  1106. }
  1107. tmp = obj[0];
  1108. do {
  1109. tmp = this._nextSibling(tmp);
  1110. } while (tmp && tmp.offsetHeight === 0);
  1111. if(tmp !== null) {
  1112. return $(tmp);
  1113. }
  1114. return obj.parentsUntil(".jstree",".jstree-node").nextAll(".jstree-node:visible").first();
  1115. },
  1116. /**
  1117. * get the previous visible node that is above the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
  1118. * @name get_prev_dom(obj [, strict])
  1119. * @param {mixed} obj
  1120. * @param {Boolean} strict
  1121. * @return {jQuery}
  1122. */
  1123. get_prev_dom : function (obj, strict) {
  1124. var tmp;
  1125. obj = this.get_node(obj, true);
  1126. if(obj[0] === this.element[0]) {
  1127. tmp = this.get_container_ul()[0].lastChild;
  1128. while (tmp && tmp.offsetHeight === 0) {
  1129. tmp = this._previousSibling(tmp);
  1130. }
  1131. return tmp ? $(tmp) : false;
  1132. }
  1133. if(!obj || !obj.length) {
  1134. return false;
  1135. }
  1136. if(strict) {
  1137. tmp = obj[0];
  1138. do {
  1139. tmp = this._previousSibling(tmp);
  1140. } while (tmp && tmp.offsetHeight === 0);
  1141. return tmp ? $(tmp) : false;
  1142. }
  1143. tmp = obj[0];
  1144. do {
  1145. tmp = this._previousSibling(tmp);
  1146. } while (tmp && tmp.offsetHeight === 0);
  1147. if(tmp !== null) {
  1148. obj = $(tmp);
  1149. while(obj.hasClass("jstree-open")) {
  1150. obj = obj.children(".jstree-children").first().children(".jstree-node:visible:last");
  1151. }
  1152. return obj;
  1153. }
  1154. tmp = obj[0].parentNode.parentNode;
  1155. return tmp && tmp.className && tmp.className.indexOf('jstree-node') !== -1 ? $(tmp) : false;
  1156. },
  1157. /**
  1158. * get the parent ID of a node
  1159. * @name get_parent(obj)
  1160. * @param {mixed} obj
  1161. * @return {String}
  1162. */
  1163. get_parent : function (obj) {
  1164. obj = this.get_node(obj);
  1165. if(!obj || obj.id === $.jstree.root) {
  1166. return false;
  1167. }
  1168. return obj.parent;
  1169. },
  1170. /**
  1171. * get a jQuery collection of all the children of a node (node must be rendered), returns false on error
  1172. * @name get_children_dom(obj)
  1173. * @param {mixed} obj
  1174. * @return {jQuery}
  1175. */
  1176. get_children_dom : function (obj) {
  1177. obj = this.get_node(obj, true);
  1178. if(obj[0] === this.element[0]) {
  1179. return this.get_container_ul().children(".jstree-node");
  1180. }
  1181. if(!obj || !obj.length) {
  1182. return false;
  1183. }
  1184. return obj.children(".jstree-children").children(".jstree-node");
  1185. },
  1186. /**
  1187. * checks if a node has children
  1188. * @name is_parent(obj)
  1189. * @param {mixed} obj
  1190. * @return {Boolean}
  1191. */
  1192. is_parent : function (obj) {
  1193. obj = this.get_node(obj);
  1194. return obj && (obj.state.loaded === false || obj.children.length > 0);
  1195. },
  1196. /**
  1197. * checks if a node is loaded (its children are available)
  1198. * @name is_loaded(obj)
  1199. * @param {mixed} obj
  1200. * @return {Boolean}
  1201. */
  1202. is_loaded : function (obj) {
  1203. obj = this.get_node(obj);
  1204. return obj && obj.state.loaded;
  1205. },
  1206. /**
  1207. * check if a node is currently loading (fetching children)
  1208. * @name is_loading(obj)
  1209. * @param {mixed} obj
  1210. * @return {Boolean}
  1211. */
  1212. is_loading : function (obj) {
  1213. obj = this.get_node(obj);
  1214. return obj && obj.state && obj.state.loading;
  1215. },
  1216. /**
  1217. * check if a node is opened
  1218. * @name is_open(obj)
  1219. * @param {mixed} obj
  1220. * @return {Boolean}
  1221. */
  1222. is_open : function (obj) {
  1223. obj = this.get_node(obj);
  1224. return obj && obj.state.opened;
  1225. },
  1226. /**
  1227. * check if a node is in a closed state
  1228. * @name is_closed(obj)
  1229. * @param {mixed} obj
  1230. * @return {Boolean}
  1231. */
  1232. is_closed : function (obj) {
  1233. obj = this.get_node(obj);
  1234. return obj && this.is_parent(obj) && !obj.state.opened;
  1235. },
  1236. /**
  1237. * check if a node has no children
  1238. * @name is_leaf(obj)
  1239. * @param {mixed} obj
  1240. * @return {Boolean}
  1241. */
  1242. is_leaf : function (obj) {
  1243. return !this.is_parent(obj);
  1244. },
  1245. /**
  1246. * loads a node (fetches its children using the `core.data` setting). Multiple nodes can be passed to by using an array.
  1247. * @name load_node(obj [, callback])
  1248. * @param {mixed} obj
  1249. * @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
  1250. * @return {Boolean}
  1251. * @trigger load_node.jstree
  1252. */
  1253. load_node : function (obj, callback) {
  1254. var k, l, i, j, c;
  1255. if($.isArray(obj)) {
  1256. this._load_nodes(obj.slice(), callback);
  1257. return true;
  1258. }
  1259. obj = this.get_node(obj);
  1260. if(!obj) {
  1261. if(callback) { callback.call(this, obj, false); }
  1262. return false;
  1263. }
  1264. // 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?
  1265. if(obj.state.loaded) {
  1266. obj.state.loaded = false;
  1267. for(i = 0, j = obj.parents.length; i < j; i++) {
  1268. this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
  1269. return $.inArray(v, obj.children_d) === -1;
  1270. });
  1271. }
  1272. for(k = 0, l = obj.children_d.length; k < l; k++) {
  1273. if(this._model.data[obj.children_d[k]].state.selected) {
  1274. c = true;
  1275. }
  1276. delete this._model.data[obj.children_d[k]];
  1277. }
  1278. if (c) {
  1279. this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
  1280. return $.inArray(v, obj.children_d) === -1;
  1281. });
  1282. }
  1283. obj.children = [];
  1284. obj.children_d = [];
  1285. if(c) {
  1286. this.trigger('changed', { 'action' : 'load_node', 'node' : obj, 'selected' : this._data.core.selected });
  1287. }
  1288. }
  1289. obj.state.failed = false;
  1290. obj.state.loading = true;
  1291. this.get_node(obj, true).addClass("jstree-loading").attr('aria-busy',true);
  1292. this._load_node(obj, $.proxy(function (status) {
  1293. obj = this._model.data[obj.id];
  1294. obj.state.loading = false;
  1295. obj.state.loaded = status;
  1296. obj.state.failed = !obj.state.loaded;
  1297. var dom = this.get_node(obj, true), i = 0, j = 0, m = this._model.data, has_children = false;
  1298. for(i = 0, j = obj.children.length; i < j; i++) {
  1299. if(m[obj.children[i]] && !m[obj.children[i]].state.hidden) {
  1300. has_children = true;
  1301. break;
  1302. }
  1303. }
  1304. if(obj.state.loaded && dom && dom.length) {
  1305. dom.removeClass('jstree-closed jstree-open jstree-leaf');
  1306. if (!has_children) {
  1307. dom.addClass('jstree-leaf');
  1308. }
  1309. else {
  1310. if (obj.id !== '#') {
  1311. dom.addClass(obj.state.opened ? 'jstree-open' : 'jstree-closed');
  1312. }
  1313. }
  1314. }
  1315. dom.removeClass("jstree-loading").attr('aria-busy',false);
  1316. /**
  1317. * triggered after a node is loaded
  1318. * @event
  1319. * @name load_node.jstree
  1320. * @param {Object} node the node that was loading
  1321. * @param {Boolean} status was the node loaded successfully
  1322. */
  1323. this.trigger('load_node', { "node" : obj, "status" : status });
  1324. if(callback) {
  1325. callback.call(this, obj, status);
  1326. }
  1327. }, this));
  1328. return true;
  1329. },
  1330. /**
  1331. * load an array of nodes (will also load unavailable nodes as soon as they appear in the structure). Used internally.
  1332. * @private
  1333. * @name _load_nodes(nodes [, callback])
  1334. * @param {array} nodes
  1335. * @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
  1336. */
  1337. _load_nodes : function (nodes, callback, is_callback, force_reload) {
  1338. var r = true,
  1339. c = function () { this._load_nodes(nodes, callback, true); },
  1340. m = this._model.data, i, j, tmp = [];
  1341. for(i = 0, j = nodes.length; i < j; i++) {
  1342. if(m[nodes[i]] && ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || (!is_callback && force_reload) )) {
  1343. if(!this.is_loading(nodes[i])) {
  1344. this.load_node(nodes[i], c);
  1345. }
  1346. r = false;
  1347. }
  1348. }
  1349. if(r) {
  1350. for(i = 0, j = nodes.length; i < j; i++) {
  1351. if(m[nodes[i]] && m[nodes[i]].state.loaded) {
  1352. tmp.push(nodes[i]);
  1353. }
  1354. }
  1355. if(callback && !callback.done) {
  1356. callback.call(this, tmp);
  1357. callback.done = true;
  1358. }
  1359. }
  1360. },
  1361. /**
  1362. * loads all unloaded nodes
  1363. * @name load_all([obj, callback])
  1364. * @param {mixed} obj the node to load recursively, omit to load all nodes in the tree
  1365. * @param {function} callback a function to be executed once loading all the nodes is complete,
  1366. * @trigger load_all.jstree
  1367. */
  1368. load_all : function (obj, callback) {
  1369. if(!obj) { obj = $.jstree.root; }
  1370. obj = this.get_node(obj);
  1371. if(!obj) { return false; }
  1372. var to_load = [],
  1373. m = this._model.data,
  1374. c = m[obj.id].children_d,
  1375. i, j;
  1376. if(obj.state && !obj.state.loaded) {
  1377. to_load.push(obj.id);
  1378. }
  1379. for(i = 0, j = c.length; i < j; i++) {
  1380. if(m[c[i]] && m[c[i]].state && !m[c[i]].state.loaded) {
  1381. to_load.push(c[i]);
  1382. }
  1383. }
  1384. if(to_load.length) {
  1385. this._load_nodes(to_load, function () {
  1386. this.load_all(obj, callback);
  1387. });
  1388. }
  1389. else {
  1390. /**
  1391. * triggered after a load_all call completes
  1392. * @event
  1393. * @name load_all.jstree
  1394. * @param {Object} node the recursively loaded node
  1395. */
  1396. if(callback) { callback.call(this, obj); }
  1397. this.trigger('load_all', { "node" : obj });
  1398. }
  1399. },
  1400. /**
  1401. * handles the actual loading of a node. Used only internally.
  1402. * @private
  1403. * @name _load_node(obj [, callback])
  1404. * @param {mixed} obj
  1405. * @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
  1406. * @return {Boolean}
  1407. */
  1408. _load_node : function (obj, callback) {
  1409. var s = this.settings.core.data, t;
  1410. var notTextOrCommentNode = function notTextOrCommentNode () {
  1411. return this.nodeType !== 3 && this.nodeType !== 8;
  1412. };
  1413. // use original HTML
  1414. if(!s) {
  1415. if(obj.id === $.jstree.root) {
  1416. return this._append_html_data(obj, this._data.core.original_container_html.clone(true), function (status) {
  1417. callback.call(this, status);
  1418. });
  1419. }
  1420. else {
  1421. return callback.call(this, false);
  1422. }
  1423. // return callback.call(this, obj.id === $.jstree.root ? this._append_html_data(obj, this._data.core.original_container_html.clone(true)) : false);
  1424. }
  1425. if($.isFunction(s)) {
  1426. return s.call(this, obj, $.proxy(function (d) {
  1427. if(d === false) {
  1428. callback.call(this, false);
  1429. }
  1430. else {
  1431. this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $($.parseHTML(d)).filter(notTextOrCommentNode) : d, function (status) {
  1432. callback.call(this, status);
  1433. });
  1434. }
  1435. // 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));
  1436. }, this));
  1437. }
  1438. if(typeof s === 'object') {
  1439. if(s.url) {
  1440. s = $.extend(true, {}, s);
  1441. if($.isFunction(s.url)) {
  1442. s.url = s.url.call(this, obj);
  1443. }
  1444. if($.isFunction(s.data)) {
  1445. s.data = s.data.call(this, obj);
  1446. }
  1447. return $.ajax(s)
  1448. .done($.proxy(function (d,t,x) {
  1449. var type = x.getResponseHeader('Content-Type');
  1450. if((type && type.indexOf('json') !== -1) || typeof d === "object") {
  1451. return this._append_json_data(obj, d, function (status) { callback.call(this, status); });
  1452. //return callback.call(this, this._append_json_data(obj, d));
  1453. }
  1454. if((type && type.indexOf('html') !== -1) || typeof d === "string") {
  1455. return this._append_html_data(obj, $($.parseHTML(d)).filter(notTextOrCommentNode), function (status) { callback.call(this, status); });
  1456. // return callback.call(this, this._append_html_data(obj, $(d)));
  1457. }
  1458. 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 }) };
  1459. this.settings.core.error.call(this, this._data.core.last_error);
  1460. return callback.call(this, false);
  1461. }, this))
  1462. .fail($.proxy(function (f) {
  1463. 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 }) };
  1464. callback.call(this, false);
  1465. this.settings.core.error.call(this, this._data.core.last_error);
  1466. }, this));
  1467. }
  1468. if ($.isArray(s)) {
  1469. t = $.extend(true, [], s);
  1470. } else if ($.isPlainObject(s)) {
  1471. t = $.extend(true, {}, s);
  1472. } else {
  1473. t = s;
  1474. }
  1475. if(obj.id === $.jstree.root) {
  1476. return this._append_json_data(obj, t, function (status) {
  1477. callback.call(this, status);
  1478. });
  1479. }
  1480. else {
  1481. this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_05', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
  1482. this.settings.core.error.call(this, this._data.core.last_error);
  1483. return callback.call(this, false);
  1484. }
  1485. //return callback.call(this, (obj.id === $.jstree.root ? this._append_json_data(obj, t) : false) );
  1486. }
  1487. if(typeof s === 'string') {
  1488. if(obj.id === $.jstree.root) {
  1489. return this._append_html_data(obj, $($.parseHTML(s)).filter(notTextOrCommentNode), function (status) {
  1490. callback.call(this, status);
  1491. });
  1492. }
  1493. else {
  1494. this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_06', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
  1495. this.settings.core.error.call(this, this._data.core.last_error);
  1496. return callback.call(this, false);
  1497. }
  1498. //return callback.call(this, (obj.id === $.jstree.root ? this._append_html_data(obj, $(s)) : false) );
  1499. }
  1500. return callback.call(this, false);
  1501. },
  1502. /**
  1503. * adds a node to the list of nodes to redraw. Used only internally.
  1504. * @private
  1505. * @name _node_changed(obj [, callback])
  1506. * @param {mixed} obj
  1507. */
  1508. _node_changed : function (obj) {
  1509. obj = this.get_node(obj);
  1510. if (obj && $.inArray(obj.id, this._model.changed) === -1) {
  1511. this._model.changed.push(obj.id);
  1512. }
  1513. },
  1514. /**
  1515. * appends HTML content to the tree. Used internally.
  1516. * @private
  1517. * @name _append_html_data(obj, data)
  1518. * @param {mixed} obj the node to append to
  1519. * @param {String} data the HTML string to parse and append
  1520. * @trigger model.jstree, changed.jstree
  1521. */
  1522. _append_html_data : function (dom, data, cb) {
  1523. dom = this.get_node(dom);
  1524. dom.children = [];
  1525. dom.children_d = [];
  1526. var dat = data.is('ul') ? data.children() : data,
  1527. par = dom.id,
  1528. chd = [],
  1529. dpc = [],
  1530. m = this._model.data,
  1531. p = m[par],
  1532. s = this._data.core.selected.length,
  1533. tmp, i, j;
  1534. dat.each($.proxy(function (i, v) {
  1535. tmp = this._parse_model_from_html($(v), par, p.parents.concat());
  1536. if(tmp) {
  1537. chd.push(tmp);
  1538. dpc.push(tmp);
  1539. if(m[tmp].children_d.length) {
  1540. dpc = dpc.concat(m[tmp].children_d);
  1541. }
  1542. }
  1543. }, this));
  1544. p.children = chd;
  1545. p.children_d = dpc;
  1546. for(i = 0, j = p.parents.length; i < j; i++) {
  1547. m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
  1548. }
  1549. /**
  1550. * triggered when new data is inserted to the tree model
  1551. * @event
  1552. * @name model.jstree
  1553. * @param {Array} nodes an array of node IDs
  1554. * @param {String} parent the parent ID of the nodes
  1555. */
  1556. this.trigger('model', { "nodes" : dpc, 'parent' : par });
  1557. if(par !== $.jstree.root) {
  1558. this._node_changed(par);
  1559. this.redraw();
  1560. }
  1561. else {
  1562. this.get_container_ul().children('.jstree-initial-node').remove();
  1563. this.redraw(true);
  1564. }
  1565. if(this._data.core.selected.length !== s) {
  1566. this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
  1567. }
  1568. cb.call(this, true);
  1569. },
  1570. /**
  1571. * appends JSON content to the tree. Used internally.
  1572. * @private
  1573. * @name _append_json_data(obj, data)
  1574. * @param {mixed} obj the node to append to
  1575. * @param {String} data the JSON object to parse and append
  1576. * @param {Boolean} force_processing internal param - do not set
  1577. * @trigger model.jstree, changed.jstree
  1578. */
  1579. _append_json_data : function (dom, data, cb, force_processing) {
  1580. if(this.element === null) { return; }
  1581. dom = this.get_node(dom);
  1582. dom.children = [];
  1583. dom.children_d = [];
  1584. // *%$@!!!
  1585. if(data.d) {
  1586. data = data.d;
  1587. if(typeof data === "string") {
  1588. data = JSON.parse(data);
  1589. }
  1590. }
  1591. if(!$.isArray(data)) { data = [data]; }
  1592. var w = null,
  1593. args = {
  1594. 'df' : this._model.default_state,
  1595. 'dat' : data,
  1596. 'par' : dom.id,
  1597. 'm' : this._model.data,
  1598. 't_id' : this._id,
  1599. 't_cnt' : this._cnt,
  1600. 'sel' : this._data.core.selected
  1601. },
  1602. inst = this,
  1603. func = function (data, undefined) {
  1604. if(data.data) { data = data.data; }
  1605. var dat = data.dat,
  1606. par = data.par,
  1607. chd = [],
  1608. dpc = [],
  1609. add = [],
  1610. df = data.df,
  1611. t_id = data.t_id,
  1612. t_cnt = data.t_cnt,
  1613. m = data.m,
  1614. p = m[par],
  1615. sel = data.sel,
  1616. tmp, i, j, rslt,
  1617. parse_flat = function (d, p, ps) {
  1618. if(!ps) { ps = []; }
  1619. else { ps = ps.concat(); }
  1620. if(p) { ps.unshift(p); }
  1621. var tid = d.id.toString(),
  1622. i, j, c, e,
  1623. tmp = {
  1624. id : tid,
  1625. text : d.text || '',
  1626. icon : d.icon !== undefined ? d.icon : true,
  1627. parent : p,
  1628. parents : ps,
  1629. children : d.children || [],
  1630. children_d : d.children_d || [],
  1631. data : d.data,
  1632. state : { },
  1633. li_attr : { id : false },
  1634. a_attr : { href : '#' },
  1635. original : false
  1636. };
  1637. for(i in df) {
  1638. if(df.hasOwnProperty(i)) {
  1639. tmp.state[i] = df[i];
  1640. }
  1641. }
  1642. if(d && d.data && d.data.jstree && d.data.jstree.icon) {
  1643. tmp.icon = d.data.jstree.icon;
  1644. }
  1645. if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
  1646. tmp.icon = true;
  1647. }
  1648. if(d && d.data) {
  1649. tmp.data = d.data;
  1650. if(d.data.jstree) {
  1651. for(i in d.data.jstree) {
  1652. if(d.data.jstree.hasOwnProperty(i)) {
  1653. tmp.state[i] = d.data.jstree[i];
  1654. }
  1655. }
  1656. }
  1657. }
  1658. if(d && typeof d.state === 'object') {
  1659. for (i in d.state) {
  1660. if(d.state.hasOwnProperty(i)) {
  1661. tmp.state[i] = d.state[i];
  1662. }
  1663. }
  1664. }
  1665. if(d && typeof d.li_attr === 'object') {
  1666. for (i in d.li_attr) {
  1667. if(d.li_attr.hasOwnProperty(i)) {
  1668. tmp.li_attr[i] = d.li_attr[i];
  1669. }
  1670. }
  1671. }
  1672. if(!tmp.li_attr.id) {
  1673. tmp.li_attr.id = tid;
  1674. }
  1675. if(d && typeof d.a_attr === 'object') {
  1676. for (i in d.a_attr) {
  1677. if(d.a_attr.hasOwnProperty(i)) {
  1678. tmp.a_attr[i] = d.a_attr[i];
  1679. }
  1680. }
  1681. }
  1682. if(d && d.children && d.children === true) {
  1683. tmp.state.loaded = false;
  1684. tmp.children = [];
  1685. tmp.children_d = [];
  1686. }
  1687. m[tmp.id] = tmp;
  1688. for(i = 0, j = tmp.children.length; i < j; i++) {
  1689. c = parse_flat(m[tmp.children[i]], tmp.id, ps);
  1690. e = m[c];
  1691. tmp.children_d.push(c);
  1692. if(e.children_d.length) {
  1693. tmp.children_d = tmp.children_d.concat(e.children_d);
  1694. }
  1695. }
  1696. delete d.data;
  1697. delete d.children;
  1698. m[tmp.id].original = d;
  1699. if(tmp.state.selected) {
  1700. add.push(tmp.id);
  1701. }
  1702. return tmp.id;
  1703. },
  1704. parse_nest = function (d, p, ps) {
  1705. if(!ps) { ps = []; }
  1706. else { ps = ps.concat(); }
  1707. if(p) { ps.unshift(p); }
  1708. var tid = false, i, j, c, e, tmp;
  1709. do {
  1710. tid = 'j' + t_id + '_' + (++t_cnt);
  1711. } while(m[tid]);
  1712. tmp = {
  1713. id : false,
  1714. text : typeof d === 'string' ? d : '',
  1715. icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
  1716. parent : p,
  1717. parents : ps,
  1718. children : [],
  1719. children_d : [],
  1720. data : null,
  1721. state : { },
  1722. li_attr : { id : false },
  1723. a_attr : { href : '#' },
  1724. original : false
  1725. };
  1726. for(i in df) {
  1727. if(df.hasOwnProperty(i)) {
  1728. tmp.state[i] = df[i];
  1729. }
  1730. }
  1731. if(d && d.id) { tmp.id = d.id.toString(); }
  1732. if(d && d.text) { tmp.text = d.text; }
  1733. if(d && d.data && d.data.jstree && d.data.jstree.icon) {
  1734. tmp.icon = d.data.jstree.icon;
  1735. }
  1736. if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
  1737. tmp.icon = true;
  1738. }
  1739. if(d && d.data) {
  1740. tmp.data = d.data;
  1741. if(d.data.jstree) {
  1742. for(i in d.data.jstree) {
  1743. if(d.data.jstree.hasOwnProperty(i)) {
  1744. tmp.state[i] = d.data.jstree[i];
  1745. }
  1746. }
  1747. }
  1748. }
  1749. if(d && typeof d.state === 'object') {
  1750. for (i in d.state) {
  1751. if(d.state.hasOwnProperty(i)) {
  1752. tmp.state[i] = d.state[i];
  1753. }
  1754. }
  1755. }
  1756. if(d && typeof d.li_attr === 'object') {
  1757. for (i in d.li_attr) {
  1758. if(d.li_attr.hasOwnProperty(i)) {
  1759. tmp.li_attr[i] = d.li_attr[i];
  1760. }
  1761. }
  1762. }
  1763. if(tmp.li_attr.id && !tmp.id) {
  1764. tmp.id = tmp.li_attr.id.toString();
  1765. }
  1766. if(!tmp.id) {
  1767. tmp.id = tid;
  1768. }
  1769. if(!tmp.li_attr.id) {
  1770. tmp.li_attr.id = tmp.id;
  1771. }
  1772. if(d && typeof d.a_attr === 'object') {
  1773. for (i in d.a_attr) {
  1774. if(d.a_attr.hasOwnProperty(i)) {
  1775. tmp.a_attr[i] = d.a_attr[i];
  1776. }
  1777. }
  1778. }
  1779. if(d && d.children && d.children.length) {
  1780. for(i = 0, j = d.children.length; i < j; i++) {
  1781. c = parse_nest(d.children[i], tmp.id, ps);
  1782. e = m[c];
  1783. tmp.children.push(c);
  1784. if(e.children_d.length) {
  1785. tmp.children_d = tmp.children_d.concat(e.children_d);
  1786. }
  1787. }
  1788. tmp.children_d = tmp.children_d.concat(tmp.children);
  1789. }
  1790. if(d && d.children && d.children === true) {
  1791. tmp.state.loaded = false;
  1792. tmp.children = [];
  1793. tmp.children_d = [];
  1794. }
  1795. delete d.data;
  1796. delete d.children;
  1797. tmp.original = d;
  1798. m[tmp.id] = tmp;
  1799. if(tmp.state.selected) {
  1800. add.push(tmp.id);
  1801. }
  1802. return tmp.id;
  1803. };
  1804. if(dat.length && dat[0].id !== undefined && dat[0].parent !== undefined) {
  1805. // Flat JSON support (for easy import from DB):
  1806. // 1) convert to object (foreach)
  1807. for(i = 0, j = dat.length; i < j; i++) {
  1808. if(!dat[i].children) {
  1809. dat[i].children = [];
  1810. }
  1811. if(!dat[i].state) {
  1812. dat[i].state = {};
  1813. }
  1814. m[dat[i].id.toString()] = dat[i];
  1815. }
  1816. // 2) populate children (foreach)
  1817. for(i = 0, j = dat.length; i < j; i++) {
  1818. if (!m[dat[i].parent.toString()]) {
  1819. if (typeof inst !== "undefined") {
  1820. inst._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() }) };
  1821. inst.settings.core.error.call(inst, inst._data.core.last_error);
  1822. }
  1823. continue;
  1824. }
  1825. m[dat[i].parent.toString()].children.push(dat[i].id.toString());
  1826. // populate parent.children_d
  1827. p.children_d.push(dat[i].id.toString());
  1828. }
  1829. // 3) normalize && populate parents and children_d with recursion
  1830. for(i = 0, j = p.children.length; i < j; i++) {
  1831. tmp = parse_flat(m[p.children[i]], par, p.parents.concat());
  1832. dpc.push(tmp);
  1833. if(m[tmp].children_d.length) {
  1834. dpc = dpc.concat(m[tmp].children_d);
  1835. }
  1836. }
  1837. for(i = 0, j = p.parents.length; i < j; i++) {
  1838. m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
  1839. }
  1840. // ?) three_state selection - p.state.selected && t - (if three_state foreach(dat => ch) -> foreach(parents) if(parent.selected) child.selected = true;
  1841. rslt = {
  1842. 'cnt' : t_cnt,
  1843. 'mod' : m,
  1844. 'sel' : sel,
  1845. 'par' : par,
  1846. 'dpc' : dpc,
  1847. 'add' : add
  1848. };
  1849. }
  1850. else {
  1851. for(i = 0, j = dat.length; i < j; i++) {
  1852. tmp = parse_nest(dat[i], par, p.parents.concat());
  1853. if(tmp) {
  1854. chd.push(tmp);
  1855. dpc.push(tmp);
  1856. if(m[tmp].children_d.length) {
  1857. dpc = dpc.concat(m[tmp].children_d);
  1858. }
  1859. }
  1860. }
  1861. p.children = chd;
  1862. p.children_d = dpc;
  1863. for(i = 0, j = p.parents.length; i < j; i++) {
  1864. m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
  1865. }
  1866. rslt = {
  1867. 'cnt' : t_cnt,
  1868. 'mod' : m,
  1869. 'sel' : sel,
  1870. 'par' : par,
  1871. 'dpc' : dpc,
  1872. 'add' : add
  1873. };
  1874. }
  1875. if(typeof window === 'undefined' || typeof window.document === 'undefined') {
  1876. postMessage(rslt);
  1877. }
  1878. else {
  1879. return rslt;
  1880. }
  1881. },
  1882. rslt = function (rslt, worker) {
  1883. if(this.element === null) { return; }
  1884. this._cnt = rslt.cnt;
  1885. var i, m = this._model.data;
  1886. for (i in m) {
  1887. if (m.hasOwnProperty(i) && m[i].state && m[i].state.loading && rslt.mod[i]) {
  1888. rslt.mod[i].state.loading = true;
  1889. }
  1890. }
  1891. this._model.data = rslt.mod; // breaks the reference in load_node - careful
  1892. if(worker) {
  1893. var j, a = rslt.add, r = rslt.sel, s = this._data.core.selected.slice();
  1894. m = this._model.data;
  1895. // if selection was changed while calculating in worker
  1896. if(r.length !== s.length || $.vakata.array_unique(r.concat(s)).length !== r.length) {
  1897. // deselect nodes that are no longer selected
  1898. for(i = 0, j = r.length; i < j; i++) {
  1899. if($.inArray(r[i], a) === -1 && $.inArray(r[i], s) === -1) {
  1900. m[r[i]].state.selected = false;
  1901. }
  1902. }
  1903. // select nodes that were selected in the mean time
  1904. for(i = 0, j = s.length; i < j; i++) {
  1905. if($.inArray(s[i], r) === -1) {
  1906. m[s[i]].state.selected = true;
  1907. }
  1908. }
  1909. }
  1910. }
  1911. if(rslt.add.length) {
  1912. this._data.core.selected = this._data.core.selected.concat(rslt.add);
  1913. }
  1914. this.trigger('model', { "nodes" : rslt.dpc, 'parent' : rslt.par });
  1915. if(rslt.par !== $.jstree.root) {
  1916. this._node_changed(rslt.par);
  1917. this.redraw();
  1918. }
  1919. else {
  1920. // this.get_container_ul().children('.jstree-initial-node').remove();
  1921. this.redraw(true);
  1922. }
  1923. if(rslt.add.length) {
  1924. this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
  1925. }
  1926. // If no worker, try to mimic worker behavioour, by invoking cb asynchronously
  1927. if (!worker && setImmediate) {
  1928. setImmediate(function(){
  1929. cb.call(inst, true);
  1930. });
  1931. }
  1932. else {
  1933. cb.call(inst, true);
  1934. }
  1935. };
  1936. if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
  1937. try {
  1938. if(this._wrk === null) {
  1939. this._wrk = window.URL.createObjectURL(
  1940. new window.Blob(
  1941. ['self.onmessage = ' + func.toString()],
  1942. {type:"text/javascript"}
  1943. )
  1944. );
  1945. }
  1946. if(!this._data.core.working || force_processing) {
  1947. this._data.core.working = true;
  1948. w = new window.Worker(this._wrk);
  1949. w.onmessage = $.proxy(function (e) {
  1950. rslt.call(this, e.data, true);
  1951. try { w.terminate(); w = null; } catch(ignore) { }
  1952. if(this._data.core.worker_queue.length) {
  1953. this._append_json_data.apply(this, this._data.core.worker_queue.shift());
  1954. }
  1955. else {
  1956. this._data.core.working = false;
  1957. }
  1958. }, this);
  1959. if(!args.par) {
  1960. if(this._data.core.worker_queue.length) {
  1961. this._append_json_data.apply(this, this._data.core.worker_queue.shift());
  1962. }
  1963. else {
  1964. this._data.core.working = false;
  1965. }
  1966. }
  1967. else {
  1968. w.postMessage(args);
  1969. }
  1970. }
  1971. else {
  1972. this._data.core.worker_queue.push([dom, data, cb, true]);
  1973. }
  1974. }
  1975. catch(e) {
  1976. rslt.call(this, func(args), false);
  1977. if(this._data.core.worker_queue.length) {
  1978. this._append_json_data.apply(this, this._data.core.worker_queue.shift());
  1979. }
  1980. else {
  1981. this._data.core.working = false;
  1982. }
  1983. }
  1984. }
  1985. else {
  1986. rslt.call(this, func(args), false);
  1987. }
  1988. },
  1989. /**
  1990. * parses a node from a jQuery object and appends them to the in memory tree model. Used internally.
  1991. * @private
  1992. * @name _parse_model_from_html(d [, p, ps])
  1993. * @param {jQuery} d the jQuery object to parse
  1994. * @param {String} p the parent ID
  1995. * @param {Array} ps list of all parents
  1996. * @return {String} the ID of the object added to the model
  1997. */
  1998. _parse_model_from_html : function (d, p, ps) {
  1999. if(!ps) { ps = []; }
  2000. else { ps = [].concat(ps); }
  2001. if(p) { ps.unshift(p); }
  2002. var c, e, m = this._model.data,
  2003. data = {
  2004. id : false,
  2005. text : false,
  2006. icon : true,
  2007. parent : p,
  2008. parents : ps,
  2009. children : [],
  2010. children_d : [],
  2011. data : null,
  2012. state : { },
  2013. li_attr : { id : false },
  2014. a_attr : { href : '#' },
  2015. original : false
  2016. }, i, tmp, tid;
  2017. for(i in this._model.default_state) {
  2018. if(this._model.default_state.hasOwnProperty(i)) {
  2019. data.state[i] = this._model.default_state[i];
  2020. }
  2021. }
  2022. tmp = $.vakata.attributes(d, true);
  2023. $.each(tmp, function (i, v) {
  2024. v = $.trim(v);
  2025. if(!v.length) { return true; }
  2026. data.li_attr[i] = v;
  2027. if(i === 'id') {
  2028. data.id = v.toString();
  2029. }
  2030. });
  2031. tmp = d.children('a').first();
  2032. if(tmp.length) {
  2033. tmp = $.vakata.attributes(tmp, true);
  2034. $.each(tmp, function (i, v) {
  2035. v = $.trim(v);
  2036. if(v.length) {
  2037. data.a_attr[i] = v;
  2038. }
  2039. });
  2040. }
  2041. tmp = d.children("a").first().length ? d.children("a").first().clone() : d.clone();
  2042. tmp.children("ins, i, ul").remove();
  2043. tmp = tmp.html();
  2044. tmp = $('<div></div>').html(tmp);
  2045. data.text = this.settings.core.force_text ? tmp.text() : tmp.html();
  2046. tmp = d.data();
  2047. data.data = tmp ? $.extend(true, {}, tmp) : null;
  2048. data.state.opened = d.hasClass('jstree-open');
  2049. data.state.selected = d.children('a').hasClass('jstree-clicked');
  2050. data.state.disabled = d.children('a').hasClass('jstree-disabled');
  2051. if(data.data && data.data.jstree) {
  2052. for(i in data.data.jstree) {
  2053. if(data.data.jstree.hasOwnProperty(i)) {
  2054. data.state[i] = data.data.jstree[i];
  2055. }
  2056. }
  2057. }
  2058. tmp = d.children("a").children(".jstree-themeicon");
  2059. if(tmp.length) {
  2060. data.icon = tmp.hasClass('jstree-themeicon-hidden') ? false : tmp.attr('rel');
  2061. }
  2062. if(data.state.icon !== undefined) {
  2063. data.icon = data.state.icon;
  2064. }
  2065. if(data.icon === undefined || data.icon === null || data.icon === "") {
  2066. data.icon = true;
  2067. }
  2068. tmp = d.children("ul").children("li");
  2069. do {
  2070. tid = 'j' + this._id + '_' + (++this._cnt);
  2071. } while(m[tid]);
  2072. data.id = data.li_attr.id ? data.li_attr.id.toString() : tid;
  2073. if(tmp.length) {
  2074. tmp.each($.proxy(function (i, v) {
  2075. c = this._parse_model_from_html($(v), data.id, ps);
  2076. e = this._model.data[c];
  2077. data.children.push(c);
  2078. if(e.children_d.length) {
  2079. data.children_d = data.children_d.concat(e.children_d);
  2080. }
  2081. }, this));
  2082. data.children_d = data.children_d.concat(data.children);
  2083. }
  2084. else {
  2085. if(d.hasClass('jstree-closed')) {
  2086. data.state.loaded = false;
  2087. }
  2088. }
  2089. if(data.li_attr['class']) {
  2090. data.li_attr['class'] = data.li_attr['class'].replace('jstree-closed','').replace('jstree-open','');
  2091. }
  2092. if(data.a_attr['class']) {
  2093. data.a_attr['class'] = data.a_attr['class'].replace('jstree-clicked','').replace('jstree-disabled','');
  2094. }
  2095. m[data.id] = data;
  2096. if(data.state.selected) {
  2097. this._data.core.selected.push(data.id);
  2098. }
  2099. return data.id;
  2100. },
  2101. /**
  2102. * 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.
  2103. * @private
  2104. * @name _parse_model_from_flat_json(d [, p, ps])
  2105. * @param {Object} d the JSON object to parse
  2106. * @param {String} p the parent ID
  2107. * @param {Array} ps list of all parents
  2108. * @return {String} the ID of the object added to the model
  2109. */
  2110. _parse_model_from_flat_json : function (d, p, ps) {
  2111. if(!ps) { ps = []; }
  2112. else { ps = ps.concat(); }
  2113. if(p) { ps.unshift(p); }
  2114. var tid = d.id.toString(),
  2115. m = this._model.data,
  2116. df = this._model.default_state,
  2117. i, j, c, e,
  2118. tmp = {
  2119. id : tid,
  2120. text : d.text || '',
  2121. icon : d.icon !== undefined ? d.icon : true,
  2122. parent : p,
  2123. parents : ps,
  2124. children : d.children || [],
  2125. children_d : d.children_d || [],
  2126. data : d.data,
  2127. state : { },
  2128. li_attr : { id : false },
  2129. a_attr : { href : '#' },
  2130. original : false
  2131. };
  2132. for(i in df) {
  2133. if(df.hasOwnProperty(i)) {
  2134. tmp.state[i] = df[i];
  2135. }
  2136. }
  2137. if(d && d.data && d.data.jstree && d.data.jstree.icon) {
  2138. tmp.icon = d.data.jstree.icon;
  2139. }
  2140. if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
  2141. tmp.icon = true;
  2142. }
  2143. if(d && d.data) {
  2144. tmp.data = d.data;
  2145. if(d.data.jstree) {
  2146. for(i in d.data.jstree) {
  2147. if(d.data.jstree.hasOwnProperty(i)) {
  2148. tmp.state[i] = d.data.jstree[i];
  2149. }
  2150. }
  2151. }
  2152. }
  2153. if(d && typeof d.state === 'object') {
  2154. for (i in d.state) {
  2155. if(d.state.hasOwnProperty(i)) {
  2156. tmp.state[i] = d.state[i];
  2157. }
  2158. }
  2159. }
  2160. if(d && typeof d.li_attr === 'object') {
  2161. for (i in d.li_attr) {
  2162. if(d.li_attr.hasOwnProperty(i)) {
  2163. tmp.li_attr[i] = d.li_attr[i];
  2164. }
  2165. }
  2166. }
  2167. if(!tmp.li_attr.id) {
  2168. tmp.li_attr.id = tid;
  2169. }
  2170. if(d && typeof d.a_attr === 'object') {
  2171. for (i in d.a_attr) {
  2172. if(d.a_attr.hasOwnProperty(i)) {
  2173. tmp.a_attr[i] = d.a_attr[i];
  2174. }
  2175. }
  2176. }
  2177. if(d && d.children && d.children === true) {
  2178. tmp.state.loaded = false;
  2179. tmp.children = [];
  2180. tmp.children_d = [];
  2181. }
  2182. m[tmp.id] = tmp;
  2183. for(i = 0, j = tmp.children.length; i < j; i++) {
  2184. c = this._parse_model_from_flat_json(m[tmp.children[i]], tmp.id, ps);
  2185. e = m[c];
  2186. tmp.children_d.push(c);
  2187. if(e.children_d.length) {
  2188. tmp.children_d = tmp.children_d.concat(e.children_d);
  2189. }
  2190. }
  2191. delete d.data;
  2192. delete d.children;
  2193. m[tmp.id].original = d;
  2194. if(tmp.state.selected) {
  2195. this._data.core.selected.push(tmp.id);
  2196. }
  2197. return tmp.id;
  2198. },
  2199. /**
  2200. * parses a node from a JSON object and appends it to the in memory tree model. Used internally.
  2201. * @private
  2202. * @name _parse_model_from_json(d [, p, ps])
  2203. * @param {Object} d the JSON object to parse
  2204. * @param {String} p the parent ID
  2205. * @param {Array} ps list of all parents
  2206. * @return {String} the ID of the object added to the model
  2207. */
  2208. _parse_model_from_json : function (d, p, ps) {
  2209. if(!ps) { ps = []; }
  2210. else { ps = ps.concat(); }
  2211. if(p) { ps.unshift(p); }
  2212. var tid = false, i, j, c, e, m = this._model.data, df = this._model.default_state, tmp;
  2213. do {
  2214. tid = 'j' + this._id + '_' + (++this._cnt);
  2215. } while(m[tid]);
  2216. tmp = {
  2217. id : false,
  2218. text : typeof d === 'string' ? d : '',
  2219. icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
  2220. parent : p,
  2221. parents : ps,
  2222. children : [],
  2223. children_d : [],
  2224. data : null,
  2225. state : { },
  2226. li_attr : { id : false },
  2227. a_attr : { href : '#' },
  2228. original : false
  2229. };
  2230. for(i in df) {
  2231. if(df.hasOwnProperty(i)) {
  2232. tmp.state[i] = df[i];
  2233. }
  2234. }
  2235. if(d && d.id) { tmp.id = d.id.toString(); }
  2236. if(d && d.text) { tmp.text = d.text; }
  2237. if(d && d.data && d.data.jstree && d.data.jstree.icon) {
  2238. tmp.icon = d.data.jstree.icon;
  2239. }
  2240. if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
  2241. tmp.icon = true;
  2242. }
  2243. if(d && d.data) {
  2244. tmp.data = d.data;
  2245. if(d.data.jstree) {
  2246. for(i in d.data.jstree) {
  2247. if(d.data.jstree.hasOwnProperty(i)) {
  2248. tmp.state[i] = d.data.jstree[i];
  2249. }
  2250. }
  2251. }
  2252. }
  2253. if(d && typeof d.state === 'object') {
  2254. for (i in d.state) {
  2255. if(d.state.hasOwnProperty(i)) {
  2256. tmp.state[i] = d.state[i];
  2257. }
  2258. }
  2259. }
  2260. if(d && typeof d.li_attr === 'object') {
  2261. for (i in d.li_attr) {
  2262. if(d.li_attr.hasOwnProperty(i)) {
  2263. tmp.li_attr[i] = d.li_attr[i];
  2264. }
  2265. }
  2266. }
  2267. if(tmp.li_attr.id && !tmp.id) {
  2268. tmp.id = tmp.li_attr.id.toString();
  2269. }
  2270. if(!tmp.id) {
  2271. tmp.id = tid;
  2272. }
  2273. if(!tmp.li_attr.id) {
  2274. tmp.li_attr.id = tmp.id;
  2275. }
  2276. if(d && typeof d.a_attr === 'object') {
  2277. for (i in d.a_attr) {
  2278. if(d.a_attr.hasOwnProperty(i)) {
  2279. tmp.a_attr[i] = d.a_attr[i];
  2280. }
  2281. }
  2282. }
  2283. if(d && d.children && d.children.length) {
  2284. for(i = 0, j = d.children.length; i < j; i++) {
  2285. c = this._parse_model_from_json(d.children[i], tmp.id, ps);
  2286. e = m[c];
  2287. tmp.children.push(c);
  2288. if(e.children_d.length) {
  2289. tmp.children_d = tmp.children_d.concat(e.children_d);
  2290. }
  2291. }
  2292. tmp.children_d = tmp.children.concat(tmp.children_d);
  2293. }
  2294. if(d && d.children && d.children === true) {
  2295. tmp.state.loaded = false;
  2296. tmp.children = [];
  2297. tmp.children_d = [];
  2298. }
  2299. delete d.data;
  2300. delete d.children;
  2301. tmp.original = d;
  2302. m[tmp.id] = tmp;
  2303. if(tmp.state.selected) {
  2304. this._data.core.selected.push(tmp.id);
  2305. }
  2306. return tmp.id;
  2307. },
  2308. /**
  2309. * redraws all nodes that need to be redrawn. Used internally.
  2310. * @private
  2311. * @name _redraw()
  2312. * @trigger redraw.jstree
  2313. */
  2314. _redraw : function () {
  2315. var nodes = this._model.force_full_redraw ? this._model.data[$.jstree.root].children.concat([]) : this._model.changed.concat([]),
  2316. f = document.createElement('UL'), tmp, i, j, fe = this._data.core.focused;
  2317. for(i = 0, j = nodes.length; i < j; i++) {
  2318. tmp = this.redraw_node(nodes[i], true, this._model.force_full_redraw);
  2319. if(tmp && this._model.force_full_redraw) {
  2320. f.appendChild(tmp);
  2321. }
  2322. }
  2323. if(this._model.force_full_redraw) {
  2324. f.className = this.get_container_ul()[0].className;
  2325. f.setAttribute('role','group');
  2326. this.element.empty().append(f);
  2327. //this.get_container_ul()[0].appendChild(f);
  2328. }
  2329. if(fe !== null && this.settings.core.restore_focus) {
  2330. tmp = this.get_node(fe, true);
  2331. if(tmp && tmp.length && tmp.children('.jstree-anchor')[0] !== document.activeElement) {
  2332. tmp.children('.jstree-anchor').focus();
  2333. }
  2334. else {
  2335. this._data.core.focused = null;
  2336. }
  2337. }
  2338. this._model.force_full_redraw = false;
  2339. this._model.changed = [];
  2340. /**
  2341. * triggered after nodes are redrawn
  2342. * @event
  2343. * @name redraw.jstree
  2344. * @param {array} nodes the redrawn nodes
  2345. */
  2346. this.trigger('redraw', { "nodes" : nodes });
  2347. },
  2348. /**
  2349. * redraws all nodes that need to be redrawn or optionally - the whole tree
  2350. * @name redraw([full])
  2351. * @param {Boolean} full if set to `true` all nodes are redrawn.
  2352. */
  2353. redraw : function (full) {
  2354. if(full) {
  2355. this._model.force_full_redraw = true;
  2356. }
  2357. //if(this._model.redraw_timeout) {
  2358. // clearTimeout(this._model.redraw_timeout);
  2359. //}
  2360. //this._model.redraw_timeout = setTimeout($.proxy(this._redraw, this),0);
  2361. this._redraw();
  2362. },
  2363. /**
  2364. * redraws a single node's children. Used internally.
  2365. * @private
  2366. * @name draw_children(node)
  2367. * @param {mixed} node the node whose children will be redrawn
  2368. */
  2369. draw_children : function (node) {
  2370. var obj = this.get_node(node),
  2371. i = false,
  2372. j = false,
  2373. k = false,
  2374. d = document;
  2375. if(!obj) { return false; }
  2376. if(obj.id === $.jstree.root) { return this.redraw(true); }
  2377. node = this.get_node(node, true);
  2378. if(!node || !node.length) { return false; } // TODO: quick toggle
  2379. node.children('.jstree-children').remove();
  2380. node = node[0];
  2381. if(obj.children.length && obj.state.loaded) {
  2382. k = d.createElement('UL');
  2383. k.setAttribute('role', 'group');
  2384. k.className = 'jstree-children';
  2385. for(i = 0, j = obj.children.length; i < j; i++) {
  2386. k.appendChild(this.redraw_node(obj.children[i], true, true));
  2387. }
  2388. node.appendChild(k);
  2389. }
  2390. },
  2391. /**
  2392. * redraws a single node. Used internally.
  2393. * @private
  2394. * @name redraw_node(node, deep, is_callback, force_render)
  2395. * @param {mixed} node the node to redraw
  2396. * @param {Boolean} deep should child nodes be redrawn too
  2397. * @param {Boolean} is_callback is this a recursion call
  2398. * @param {Boolean} force_render should children of closed parents be drawn anyway
  2399. */
  2400. redraw_node : function (node, deep, is_callback, force_render) {
  2401. var obj = this.get_node(node),
  2402. par = false,
  2403. ind = false,
  2404. old = false,
  2405. i = false,
  2406. j = false,
  2407. k = false,
  2408. c = '',
  2409. d = document,
  2410. m = this._model.data,
  2411. f = false,
  2412. s = false,
  2413. tmp = null,
  2414. t = 0,
  2415. l = 0,
  2416. has_children = false,
  2417. last_sibling = false;
  2418. if(!obj) { return false; }
  2419. if(obj.id === $.jstree.root) { return this.redraw(true); }
  2420. deep = deep || obj.children.length === 0;
  2421. 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);
  2422. if(!node) {
  2423. deep = true;
  2424. //node = d.createElement('LI');
  2425. if(!is_callback) {
  2426. par = obj.parent !== $.jstree.root ? $('#' + obj.parent.replace($.jstree.idregex,'\\$&'), this.element)[0] : null;
  2427. if(par !== null && (!par || !m[obj.parent].state.opened)) {
  2428. return false;
  2429. }
  2430. ind = $.inArray(obj.id, par === null ? m[$.jstree.root].children : m[obj.parent].children);
  2431. }
  2432. }
  2433. else {
  2434. node = $(node);
  2435. if(!is_callback) {
  2436. par = node.parent().parent()[0];
  2437. if(par === this.element[0]) {
  2438. par = null;
  2439. }
  2440. ind = node.index();
  2441. }
  2442. // m[obj.id].data = node.data(); // use only node's data, no need to touch jquery storage
  2443. if(!deep && obj.children.length && !node.children('.jstree-children').length) {
  2444. deep = true;
  2445. }
  2446. if(!deep) {
  2447. old = node.children('.jstree-children')[0];
  2448. }
  2449. f = node.children('.jstree-anchor')[0] === document.activeElement;
  2450. node.remove();
  2451. //node = d.createElement('LI');
  2452. //node = node[0];
  2453. }
  2454. node = this._data.core.node.cloneNode(true);
  2455. // node is DOM, deep is boolean
  2456. c = 'jstree-node ';
  2457. for(i in obj.li_attr) {
  2458. if(obj.li_attr.hasOwnProperty(i)) {
  2459. if(i === 'id') { continue; }
  2460. if(i !== 'class') {
  2461. node.setAttribute(i, obj.li_attr[i]);
  2462. }
  2463. else {
  2464. c += obj.li_attr[i];
  2465. }
  2466. }
  2467. }
  2468. if(!obj.a_attr.id) {
  2469. obj.a_attr.id = obj.id + '_anchor';
  2470. }
  2471. node.setAttribute('aria-selected', !!obj.state.selected);
  2472. node.childNodes[1].setAttribute('aria-selected', !!obj.state.selected);
  2473. node.setAttribute('aria-level', obj.parents.length);
  2474. node.childNodes[1].setAttribute('aria-level', obj.parents.length);
  2475. node.setAttribute('aria-labelledby', obj.a_attr.id);
  2476. if(obj.state.disabled) {
  2477. node.setAttribute('aria-disabled', true);
  2478. node.childNodes[1].setAttribute('aria-disabled', true);
  2479. }
  2480. for(i = 0, j = obj.children.length; i < j; i++) {
  2481. if(!m[obj.children[i]].state.hidden) {
  2482. has_children = true;
  2483. break;
  2484. }
  2485. }
  2486. if(obj.parent !== null && m[obj.parent] && !obj.state.hidden) {
  2487. i = $.inArray(obj.id, m[obj.parent].children);
  2488. last_sibling = obj.id;
  2489. if(i !== -1) {
  2490. i++;
  2491. for(j = m[obj.parent].children.length; i < j; i++) {
  2492. if(!m[m[obj.parent].children[i]].state.hidden) {
  2493. last_sibling = m[obj.parent].children[i];
  2494. }
  2495. if(last_sibling !== obj.id) {
  2496. break;
  2497. }
  2498. }
  2499. }
  2500. }
  2501. if(obj.state.hidden) {
  2502. c += ' jstree-hidden';
  2503. }
  2504. if (obj.state.loading) {
  2505. c += ' jstree-loading';
  2506. }
  2507. if(obj.state.loaded && !has_children) {
  2508. c += ' jstree-leaf';
  2509. }
  2510. else {
  2511. c += obj.state.opened && obj.state.loaded ? ' jstree-open' : ' jstree-closed';
  2512. node.setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
  2513. node.childNodes[1].setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
  2514. }
  2515. if(last_sibling === obj.id) {
  2516. c += ' jstree-last';
  2517. }
  2518. node.id = obj.id;
  2519. node.className = c;
  2520. c = ( obj.state.selected ? ' jstree-clicked' : '') + ( obj.state.disabled ? ' jstree-disabled' : '');
  2521. for(j in obj.a_attr) {
  2522. if(obj.a_attr.hasOwnProperty(j)) {
  2523. if(j === 'href' && obj.a_attr[j] === '#') { continue; }
  2524. if(j !== 'class') {
  2525. node.childNodes[1].setAttribute(j, obj.a_attr[j]);
  2526. }
  2527. else {
  2528. c += ' ' + obj.a_attr[j];
  2529. }
  2530. }
  2531. }
  2532. if(c.length) {
  2533. node.childNodes[1].className = 'jstree-anchor ' + c;
  2534. }
  2535. if((obj.icon && obj.icon !== true) || obj.icon === false) {
  2536. if(obj.icon === false) {
  2537. node.childNodes[1].childNodes[0].className += ' jstree-themeicon-hidden';
  2538. }
  2539. else if(obj.icon.indexOf('/') === -1 && obj.icon.indexOf('.') === -1) {
  2540. node.childNodes[1].childNodes[0].className += ' ' + obj.icon + ' jstree-themeicon-custom';
  2541. }
  2542. else {
  2543. node.childNodes[1].childNodes[0].style.backgroundImage = 'url("'+obj.icon+'")';
  2544. node.childNodes[1].childNodes[0].style.backgroundPosition = 'center center';
  2545. node.childNodes[1].childNodes[0].style.backgroundSize = 'auto';
  2546. node.childNodes[1].childNodes[0].className += ' jstree-themeicon-custom';
  2547. }
  2548. }
  2549. if(this.settings.core.force_text) {
  2550. node.childNodes[1].appendChild(d.createTextNode(obj.text));
  2551. }
  2552. else {
  2553. node.childNodes[1].innerHTML += obj.text;
  2554. }
  2555. if(deep && obj.children.length && (obj.state.opened || force_render) && obj.state.loaded) {
  2556. k = d.createElement('UL');
  2557. k.setAttribute('role', 'group');
  2558. k.className = 'jstree-children';
  2559. for(i = 0, j = obj.children.length; i < j; i++) {
  2560. k.appendChild(this.redraw_node(obj.children[i], deep, true));
  2561. }
  2562. node.appendChild(k);
  2563. }
  2564. if(old) {
  2565. node.appendChild(old);
  2566. }
  2567. if(!is_callback) {
  2568. // append back using par / ind
  2569. if(!par) {
  2570. par = this.element[0];
  2571. }
  2572. for(i = 0, j = par.childNodes.length; i < j; i++) {
  2573. if(par.childNodes[i] && par.childNodes[i].className && par.childNodes[i].className.indexOf('jstree-children') !== -1) {
  2574. tmp = par.childNodes[i];
  2575. break;
  2576. }
  2577. }
  2578. if(!tmp) {
  2579. tmp = d.createElement('UL');
  2580. tmp.setAttribute('role', 'group');
  2581. tmp.className = 'jstree-children';
  2582. par.appendChild(tmp);
  2583. }
  2584. par = tmp;
  2585. if(ind < par.childNodes.length) {
  2586. par.insertBefore(node, par.childNodes[ind]);
  2587. }
  2588. else {
  2589. par.appendChild(node);
  2590. }
  2591. if(f) {
  2592. t = this.element[0].scrollTop;
  2593. l = this.element[0].scrollLeft;
  2594. node.childNodes[1].focus();
  2595. this.element[0].scrollTop = t;
  2596. this.element[0].scrollLeft = l;
  2597. }
  2598. }
  2599. if(obj.state.opened && !obj.state.loaded) {
  2600. obj.state.opened = false;
  2601. setTimeout($.proxy(function () {
  2602. this.open_node(obj.id, false, 0);
  2603. }, this), 0);
  2604. }
  2605. return node;
  2606. },
  2607. /**
  2608. * opens a node, revealing its children. If the node is not loaded it will be loaded and opened once ready.
  2609. * @name open_node(obj [, callback, animation])
  2610. * @param {mixed} obj the node to open
  2611. * @param {Function} callback a function to execute once the node is opened
  2612. * @param {Number} animation the animation duration in milliseconds when opening the node (overrides the `core.animation` setting). Use `false` for no animation.
  2613. * @trigger open_node.jstree, after_open.jstree, before_open.jstree
  2614. */
  2615. open_node : function (obj, callback, animation) {
  2616. var t1, t2, d, t;
  2617. if($.isArray(obj)) {
  2618. obj = obj.slice();
  2619. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2620. this.open_node(obj[t1], callback, animation);
  2621. }
  2622. return true;
  2623. }
  2624. obj = this.get_node(obj);
  2625. if(!obj || obj.id === $.jstree.root) {
  2626. return false;
  2627. }
  2628. animation = animation === undefined ? this.settings.core.animation : animation;
  2629. if(!this.is_closed(obj)) {
  2630. if(callback) {
  2631. callback.call(this, obj, false);
  2632. }
  2633. return false;
  2634. }
  2635. if(!this.is_loaded(obj)) {
  2636. if(this.is_loading(obj)) {
  2637. return setTimeout($.proxy(function () {
  2638. this.open_node(obj, callback, animation);
  2639. }, this), 500);
  2640. }
  2641. this.load_node(obj, function (o, ok) {
  2642. return ok ? this.open_node(o, callback, animation) : (callback ? callback.call(this, o, false) : false);
  2643. });
  2644. }
  2645. else {
  2646. d = this.get_node(obj, true);
  2647. t = this;
  2648. if(d.length) {
  2649. if(animation && d.children(".jstree-children").length) {
  2650. d.children(".jstree-children").stop(true, true);
  2651. }
  2652. if(obj.children.length && !this._firstChild(d.children('.jstree-children')[0])) {
  2653. this.draw_children(obj);
  2654. //d = this.get_node(obj, true);
  2655. }
  2656. if(!animation) {
  2657. this.trigger('before_open', { "node" : obj });
  2658. d[0].className = d[0].className.replace('jstree-closed', 'jstree-open');
  2659. d[0].setAttribute("aria-expanded", true);
  2660. d[0].childNodes[1].setAttribute("aria-expanded", true);
  2661. }
  2662. else {
  2663. this.trigger('before_open', { "node" : obj });
  2664. d
  2665. .children(".jstree-children").css("display","none").end()
  2666. .removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded", true)
  2667. .children('.jstree-anchor').attr("aria-expanded", true).end()
  2668. .children(".jstree-children").stop(true, true)
  2669. .slideDown(animation, function () {
  2670. this.style.display = "";
  2671. if (t.element) {
  2672. t.trigger("after_open", { "node" : obj });
  2673. }
  2674. });
  2675. }
  2676. }
  2677. obj.state.opened = true;
  2678. if(callback) {
  2679. callback.call(this, obj, true);
  2680. }
  2681. if(!d.length) {
  2682. /**
  2683. * 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)
  2684. * @event
  2685. * @name before_open.jstree
  2686. * @param {Object} node the opened node
  2687. */
  2688. this.trigger('before_open', { "node" : obj });
  2689. }
  2690. /**
  2691. * triggered when a node is opened (if there is an animation it will not be completed yet)
  2692. * @event
  2693. * @name open_node.jstree
  2694. * @param {Object} node the opened node
  2695. */
  2696. this.trigger('open_node', { "node" : obj });
  2697. if(!animation || !d.length) {
  2698. /**
  2699. * triggered when a node is opened and the animation is complete
  2700. * @event
  2701. * @name after_open.jstree
  2702. * @param {Object} node the opened node
  2703. */
  2704. this.trigger("after_open", { "node" : obj });
  2705. }
  2706. return true;
  2707. }
  2708. },
  2709. /**
  2710. * opens every parent of a node (node should be loaded)
  2711. * @name _open_to(obj)
  2712. * @param {mixed} obj the node to reveal
  2713. * @private
  2714. */
  2715. _open_to : function (obj) {
  2716. obj = this.get_node(obj);
  2717. if(!obj || obj.id === $.jstree.root) {
  2718. return false;
  2719. }
  2720. var i, j, p = obj.parents;
  2721. for(i = 0, j = p.length; i < j; i+=1) {
  2722. if(i !== $.jstree.root) {
  2723. this.open_node(p[i], false, 0);
  2724. }
  2725. }
  2726. return $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
  2727. },
  2728. /**
  2729. * closes a node, hiding its children
  2730. * @name close_node(obj [, animation])
  2731. * @param {mixed} obj the node to close
  2732. * @param {Number} animation the animation duration in milliseconds when closing the node (overrides the `core.animation` setting). Use `false` for no animation.
  2733. * @trigger close_node.jstree, after_close.jstree
  2734. */
  2735. close_node : function (obj, animation) {
  2736. var t1, t2, t, d;
  2737. if($.isArray(obj)) {
  2738. obj = obj.slice();
  2739. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2740. this.close_node(obj[t1], animation);
  2741. }
  2742. return true;
  2743. }
  2744. obj = this.get_node(obj);
  2745. if(!obj || obj.id === $.jstree.root) {
  2746. return false;
  2747. }
  2748. if(this.is_closed(obj)) {
  2749. return false;
  2750. }
  2751. animation = animation === undefined ? this.settings.core.animation : animation;
  2752. t = this;
  2753. d = this.get_node(obj, true);
  2754. obj.state.opened = false;
  2755. /**
  2756. * triggered when a node is closed (if there is an animation it will not be complete yet)
  2757. * @event
  2758. * @name close_node.jstree
  2759. * @param {Object} node the closed node
  2760. */
  2761. this.trigger('close_node',{ "node" : obj });
  2762. if(!d.length) {
  2763. /**
  2764. * triggered when a node is closed and the animation is complete
  2765. * @event
  2766. * @name after_close.jstree
  2767. * @param {Object} node the closed node
  2768. */
  2769. this.trigger("after_close", { "node" : obj });
  2770. }
  2771. else {
  2772. if(!animation) {
  2773. d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
  2774. d.children('.jstree-anchor').attr("aria-expanded", false);
  2775. d.attr("aria-expanded", false).children('.jstree-children').remove();
  2776. this.trigger("after_close", { "node" : obj });
  2777. }
  2778. else {
  2779. d
  2780. .children(".jstree-children").attr("style","display:block !important").end()
  2781. .removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded", false)
  2782. .children('.jstree-anchor').attr("aria-expanded", false).end()
  2783. .children(".jstree-children").stop(true, true).slideUp(animation, function () {
  2784. this.style.display = "";
  2785. d.children('.jstree-children').remove();
  2786. if (t.element) {
  2787. t.trigger("after_close", { "node" : obj });
  2788. }
  2789. });
  2790. }
  2791. }
  2792. },
  2793. /**
  2794. * toggles a node - closing it if it is open, opening it if it is closed
  2795. * @name toggle_node(obj)
  2796. * @param {mixed} obj the node to toggle
  2797. */
  2798. toggle_node : function (obj) {
  2799. var t1, t2;
  2800. if($.isArray(obj)) {
  2801. obj = obj.slice();
  2802. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2803. this.toggle_node(obj[t1]);
  2804. }
  2805. return true;
  2806. }
  2807. if(this.is_closed(obj)) {
  2808. return this.open_node(obj);
  2809. }
  2810. if(this.is_open(obj)) {
  2811. return this.close_node(obj);
  2812. }
  2813. },
  2814. /**
  2815. * opens all nodes within a node (or the tree), revealing their children. If the node is not loaded it will be loaded and opened once ready.
  2816. * @name open_all([obj, animation, original_obj])
  2817. * @param {mixed} obj the node to open recursively, omit to open all nodes in the tree
  2818. * @param {Number} animation the animation duration in milliseconds when opening the nodes, the default is no animation
  2819. * @param {jQuery} reference to the node that started the process (internal use)
  2820. * @trigger open_all.jstree
  2821. */
  2822. open_all : function (obj, animation, original_obj) {
  2823. if(!obj) { obj = $.jstree.root; }
  2824. obj = this.get_node(obj);
  2825. if(!obj) { return false; }
  2826. var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true), i, j, _this;
  2827. if(!dom.length) {
  2828. for(i = 0, j = obj.children_d.length; i < j; i++) {
  2829. if(this.is_closed(this._model.data[obj.children_d[i]])) {
  2830. this._model.data[obj.children_d[i]].state.opened = true;
  2831. }
  2832. }
  2833. return this.trigger('open_all', { "node" : obj });
  2834. }
  2835. original_obj = original_obj || dom;
  2836. _this = this;
  2837. dom = this.is_closed(obj) ? dom.find('.jstree-closed').addBack() : dom.find('.jstree-closed');
  2838. dom.each(function () {
  2839. _this.open_node(
  2840. this,
  2841. function(node, status) { if(status && this.is_parent(node)) { this.open_all(node, animation, original_obj); } },
  2842. animation || 0
  2843. );
  2844. });
  2845. if(original_obj.find('.jstree-closed').length === 0) {
  2846. /**
  2847. * triggered when an `open_all` call completes
  2848. * @event
  2849. * @name open_all.jstree
  2850. * @param {Object} node the opened node
  2851. */
  2852. this.trigger('open_all', { "node" : this.get_node(original_obj) });
  2853. }
  2854. },
  2855. /**
  2856. * closes all nodes within a node (or the tree), revealing their children
  2857. * @name close_all([obj, animation])
  2858. * @param {mixed} obj the node to close recursively, omit to close all nodes in the tree
  2859. * @param {Number} animation the animation duration in milliseconds when closing the nodes, the default is no animation
  2860. * @trigger close_all.jstree
  2861. */
  2862. close_all : function (obj, animation) {
  2863. if(!obj) { obj = $.jstree.root; }
  2864. obj = this.get_node(obj);
  2865. if(!obj) { return false; }
  2866. var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true),
  2867. _this = this, i, j;
  2868. if(dom.length) {
  2869. dom = this.is_open(obj) ? dom.find('.jstree-open').addBack() : dom.find('.jstree-open');
  2870. $(dom.get().reverse()).each(function () { _this.close_node(this, animation || 0); });
  2871. }
  2872. for(i = 0, j = obj.children_d.length; i < j; i++) {
  2873. this._model.data[obj.children_d[i]].state.opened = false;
  2874. }
  2875. /**
  2876. * triggered when an `close_all` call completes
  2877. * @event
  2878. * @name close_all.jstree
  2879. * @param {Object} node the closed node
  2880. */
  2881. this.trigger('close_all', { "node" : obj });
  2882. },
  2883. /**
  2884. * checks if a node is disabled (not selectable)
  2885. * @name is_disabled(obj)
  2886. * @param {mixed} obj
  2887. * @return {Boolean}
  2888. */
  2889. is_disabled : function (obj) {
  2890. obj = this.get_node(obj);
  2891. return obj && obj.state && obj.state.disabled;
  2892. },
  2893. /**
  2894. * enables a node - so that it can be selected
  2895. * @name enable_node(obj)
  2896. * @param {mixed} obj the node to enable
  2897. * @trigger enable_node.jstree
  2898. */
  2899. enable_node : function (obj) {
  2900. var t1, t2;
  2901. if($.isArray(obj)) {
  2902. obj = obj.slice();
  2903. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2904. this.enable_node(obj[t1]);
  2905. }
  2906. return true;
  2907. }
  2908. obj = this.get_node(obj);
  2909. if(!obj || obj.id === $.jstree.root) {
  2910. return false;
  2911. }
  2912. obj.state.disabled = false;
  2913. this.get_node(obj,true).children('.jstree-anchor').removeClass('jstree-disabled').attr('aria-disabled', false);
  2914. /**
  2915. * triggered when an node is enabled
  2916. * @event
  2917. * @name enable_node.jstree
  2918. * @param {Object} node the enabled node
  2919. */
  2920. this.trigger('enable_node', { 'node' : obj });
  2921. },
  2922. /**
  2923. * disables a node - so that it can not be selected
  2924. * @name disable_node(obj)
  2925. * @param {mixed} obj the node to disable
  2926. * @trigger disable_node.jstree
  2927. */
  2928. disable_node : function (obj) {
  2929. var t1, t2;
  2930. if($.isArray(obj)) {
  2931. obj = obj.slice();
  2932. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2933. this.disable_node(obj[t1]);
  2934. }
  2935. return true;
  2936. }
  2937. obj = this.get_node(obj);
  2938. if(!obj || obj.id === $.jstree.root) {
  2939. return false;
  2940. }
  2941. obj.state.disabled = true;
  2942. this.get_node(obj,true).children('.jstree-anchor').addClass('jstree-disabled').attr('aria-disabled', true);
  2943. /**
  2944. * triggered when an node is disabled
  2945. * @event
  2946. * @name disable_node.jstree
  2947. * @param {Object} node the disabled node
  2948. */
  2949. this.trigger('disable_node', { 'node' : obj });
  2950. },
  2951. /**
  2952. * determines if a node is hidden
  2953. * @name is_hidden(obj)
  2954. * @param {mixed} obj the node
  2955. */
  2956. is_hidden : function (obj) {
  2957. obj = this.get_node(obj);
  2958. return obj.state.hidden === true;
  2959. },
  2960. /**
  2961. * hides a node - it is still in the structure but will not be visible
  2962. * @name hide_node(obj)
  2963. * @param {mixed} obj the node to hide
  2964. * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
  2965. * @trigger hide_node.jstree
  2966. */
  2967. hide_node : function (obj, skip_redraw) {
  2968. var t1, t2;
  2969. if($.isArray(obj)) {
  2970. obj = obj.slice();
  2971. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  2972. this.hide_node(obj[t1], true);
  2973. }
  2974. if (!skip_redraw) {
  2975. this.redraw();
  2976. }
  2977. return true;
  2978. }
  2979. obj = this.get_node(obj);
  2980. if(!obj || obj.id === $.jstree.root) {
  2981. return false;
  2982. }
  2983. if(!obj.state.hidden) {
  2984. obj.state.hidden = true;
  2985. this._node_changed(obj.parent);
  2986. if(!skip_redraw) {
  2987. this.redraw();
  2988. }
  2989. /**
  2990. * triggered when an node is hidden
  2991. * @event
  2992. * @name hide_node.jstree
  2993. * @param {Object} node the hidden node
  2994. */
  2995. this.trigger('hide_node', { 'node' : obj });
  2996. }
  2997. },
  2998. /**
  2999. * shows a node
  3000. * @name show_node(obj)
  3001. * @param {mixed} obj the node to show
  3002. * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
  3003. * @trigger show_node.jstree
  3004. */
  3005. show_node : function (obj, skip_redraw) {
  3006. var t1, t2;
  3007. if($.isArray(obj)) {
  3008. obj = obj.slice();
  3009. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3010. this.show_node(obj[t1], true);
  3011. }
  3012. if (!skip_redraw) {
  3013. this.redraw();
  3014. }
  3015. return true;
  3016. }
  3017. obj = this.get_node(obj);
  3018. if(!obj || obj.id === $.jstree.root) {
  3019. return false;
  3020. }
  3021. if(obj.state.hidden) {
  3022. obj.state.hidden = false;
  3023. this._node_changed(obj.parent);
  3024. if(!skip_redraw) {
  3025. this.redraw();
  3026. }
  3027. /**
  3028. * triggered when an node is shown
  3029. * @event
  3030. * @name show_node.jstree
  3031. * @param {Object} node the shown node
  3032. */
  3033. this.trigger('show_node', { 'node' : obj });
  3034. }
  3035. },
  3036. /**
  3037. * hides all nodes
  3038. * @name hide_all()
  3039. * @trigger hide_all.jstree
  3040. */
  3041. hide_all : function (skip_redraw) {
  3042. var i, m = this._model.data, ids = [];
  3043. for(i in m) {
  3044. if(m.hasOwnProperty(i) && i !== $.jstree.root && !m[i].state.hidden) {
  3045. m[i].state.hidden = true;
  3046. ids.push(i);
  3047. }
  3048. }
  3049. this._model.force_full_redraw = true;
  3050. if(!skip_redraw) {
  3051. this.redraw();
  3052. }
  3053. /**
  3054. * triggered when all nodes are hidden
  3055. * @event
  3056. * @name hide_all.jstree
  3057. * @param {Array} nodes the IDs of all hidden nodes
  3058. */
  3059. this.trigger('hide_all', { 'nodes' : ids });
  3060. return ids;
  3061. },
  3062. /**
  3063. * shows all nodes
  3064. * @name show_all()
  3065. * @trigger show_all.jstree
  3066. */
  3067. show_all : function (skip_redraw) {
  3068. var i, m = this._model.data, ids = [];
  3069. for(i in m) {
  3070. if(m.hasOwnProperty(i) && i !== $.jstree.root && m[i].state.hidden) {
  3071. m[i].state.hidden = false;
  3072. ids.push(i);
  3073. }
  3074. }
  3075. this._model.force_full_redraw = true;
  3076. if(!skip_redraw) {
  3077. this.redraw();
  3078. }
  3079. /**
  3080. * triggered when all nodes are shown
  3081. * @event
  3082. * @name show_all.jstree
  3083. * @param {Array} nodes the IDs of all shown nodes
  3084. */
  3085. this.trigger('show_all', { 'nodes' : ids });
  3086. return ids;
  3087. },
  3088. /**
  3089. * called when a node is selected by the user. Used internally.
  3090. * @private
  3091. * @name activate_node(obj, e)
  3092. * @param {mixed} obj the node
  3093. * @param {Object} e the related event
  3094. * @trigger activate_node.jstree, changed.jstree
  3095. */
  3096. activate_node : function (obj, e) {
  3097. if(this.is_disabled(obj)) {
  3098. return false;
  3099. }
  3100. if(!e || typeof e !== 'object') {
  3101. e = {};
  3102. }
  3103. // 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
  3104. 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;
  3105. if(this._data.core.last_clicked && !this._data.core.last_clicked.state.selected) { this._data.core.last_clicked = null; }
  3106. 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]); }
  3107. 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 ) )) {
  3108. if(!this.settings.core.multiple && (e.metaKey || e.ctrlKey || e.shiftKey) && this.is_selected(obj)) {
  3109. this.deselect_node(obj, false, e);
  3110. }
  3111. else {
  3112. this.deselect_all(true);
  3113. this.select_node(obj, false, false, e);
  3114. this._data.core.last_clicked = this.get_node(obj);
  3115. }
  3116. }
  3117. else {
  3118. if(e.shiftKey) {
  3119. var o = this.get_node(obj).id,
  3120. l = this._data.core.last_clicked.id,
  3121. p = this.get_node(this._data.core.last_clicked.parent).children,
  3122. c = false,
  3123. i, j;
  3124. for(i = 0, j = p.length; i < j; i += 1) {
  3125. // separate IFs work whem o and l are the same
  3126. if(p[i] === o) {
  3127. c = !c;
  3128. }
  3129. if(p[i] === l) {
  3130. c = !c;
  3131. }
  3132. if(!this.is_disabled(p[i]) && (c || p[i] === o || p[i] === l)) {
  3133. if (!this.is_hidden(p[i])) {
  3134. this.select_node(p[i], true, false, e);
  3135. }
  3136. }
  3137. else {
  3138. this.deselect_node(p[i], true, e);
  3139. }
  3140. }
  3141. this.trigger('changed', { 'action' : 'select_node', 'node' : this.get_node(obj), 'selected' : this._data.core.selected, 'event' : e });
  3142. }
  3143. else {
  3144. if(!this.is_selected(obj)) {
  3145. this.select_node(obj, false, false, e);
  3146. }
  3147. else {
  3148. this.deselect_node(obj, false, e);
  3149. }
  3150. }
  3151. }
  3152. /**
  3153. * triggered when an node is clicked or intercated with by the user
  3154. * @event
  3155. * @name activate_node.jstree
  3156. * @param {Object} node
  3157. * @param {Object} event the ooriginal event (if any) which triggered the call (may be an empty object)
  3158. */
  3159. this.trigger('activate_node', { 'node' : this.get_node(obj), 'event' : e });
  3160. },
  3161. /**
  3162. * applies the hover state on a node, called when a node is hovered by the user. Used internally.
  3163. * @private
  3164. * @name hover_node(obj)
  3165. * @param {mixed} obj
  3166. * @trigger hover_node.jstree
  3167. */
  3168. hover_node : function (obj) {
  3169. obj = this.get_node(obj, true);
  3170. if(!obj || !obj.length || obj.children('.jstree-hovered').length) {
  3171. return false;
  3172. }
  3173. var o = this.element.find('.jstree-hovered'), t = this.element;
  3174. if(o && o.length) { this.dehover_node(o); }
  3175. obj.children('.jstree-anchor').addClass('jstree-hovered');
  3176. /**
  3177. * triggered when an node is hovered
  3178. * @event
  3179. * @name hover_node.jstree
  3180. * @param {Object} node
  3181. */
  3182. this.trigger('hover_node', { 'node' : this.get_node(obj) });
  3183. setTimeout(function () { t.attr('aria-activedescendant', obj[0].id); }, 0);
  3184. },
  3185. /**
  3186. * removes the hover state from a nodecalled when a node is no longer hovered by the user. Used internally.
  3187. * @private
  3188. * @name dehover_node(obj)
  3189. * @param {mixed} obj
  3190. * @trigger dehover_node.jstree
  3191. */
  3192. dehover_node : function (obj) {
  3193. obj = this.get_node(obj, true);
  3194. if(!obj || !obj.length || !obj.children('.jstree-hovered').length) {
  3195. return false;
  3196. }
  3197. obj.children('.jstree-anchor').removeClass('jstree-hovered');
  3198. /**
  3199. * triggered when an node is no longer hovered
  3200. * @event
  3201. * @name dehover_node.jstree
  3202. * @param {Object} node
  3203. */
  3204. this.trigger('dehover_node', { 'node' : this.get_node(obj) });
  3205. },
  3206. /**
  3207. * select a node
  3208. * @name select_node(obj [, supress_event, prevent_open])
  3209. * @param {mixed} obj an array can be used to select multiple nodes
  3210. * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
  3211. * @param {Boolean} prevent_open if set to `true` parents of the selected node won't be opened
  3212. * @trigger select_node.jstree, changed.jstree
  3213. */
  3214. select_node : function (obj, supress_event, prevent_open, e) {
  3215. var dom, t1, t2, th;
  3216. if($.isArray(obj)) {
  3217. obj = obj.slice();
  3218. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3219. this.select_node(obj[t1], supress_event, prevent_open, e);
  3220. }
  3221. return true;
  3222. }
  3223. obj = this.get_node(obj);
  3224. if(!obj || obj.id === $.jstree.root) {
  3225. return false;
  3226. }
  3227. dom = this.get_node(obj, true);
  3228. if(!obj.state.selected) {
  3229. obj.state.selected = true;
  3230. this._data.core.selected.push(obj.id);
  3231. if(!prevent_open) {
  3232. dom = this._open_to(obj);
  3233. }
  3234. if(dom && dom.length) {
  3235. dom.attr('aria-selected', true).children('.jstree-anchor').addClass('jstree-clicked').attr('aria-selected', true);
  3236. }
  3237. /**
  3238. * triggered when an node is selected
  3239. * @event
  3240. * @name select_node.jstree
  3241. * @param {Object} node
  3242. * @param {Array} selected the current selection
  3243. * @param {Object} event the event (if any) that triggered this select_node
  3244. */
  3245. this.trigger('select_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
  3246. if(!supress_event) {
  3247. /**
  3248. * triggered when selection changes
  3249. * @event
  3250. * @name changed.jstree
  3251. * @param {Object} node
  3252. * @param {Object} action the action that caused the selection to change
  3253. * @param {Array} selected the current selection
  3254. * @param {Object} event the event (if any) that triggered this changed event
  3255. */
  3256. this.trigger('changed', { 'action' : 'select_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
  3257. }
  3258. }
  3259. },
  3260. /**
  3261. * deselect a node
  3262. * @name deselect_node(obj [, supress_event])
  3263. * @param {mixed} obj an array can be used to deselect multiple nodes
  3264. * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
  3265. * @trigger deselect_node.jstree, changed.jstree
  3266. */
  3267. deselect_node : function (obj, supress_event, e) {
  3268. var t1, t2, dom;
  3269. if($.isArray(obj)) {
  3270. obj = obj.slice();
  3271. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3272. this.deselect_node(obj[t1], supress_event, e);
  3273. }
  3274. return true;
  3275. }
  3276. obj = this.get_node(obj);
  3277. if(!obj || obj.id === $.jstree.root) {
  3278. return false;
  3279. }
  3280. dom = this.get_node(obj, true);
  3281. if(obj.state.selected) {
  3282. obj.state.selected = false;
  3283. this._data.core.selected = $.vakata.array_remove_item(this._data.core.selected, obj.id);
  3284. if(dom.length) {
  3285. dom.attr('aria-selected', false).children('.jstree-anchor').removeClass('jstree-clicked').attr('aria-selected', false);
  3286. }
  3287. /**
  3288. * triggered when an node is deselected
  3289. * @event
  3290. * @name deselect_node.jstree
  3291. * @param {Object} node
  3292. * @param {Array} selected the current selection
  3293. * @param {Object} event the event (if any) that triggered this deselect_node
  3294. */
  3295. this.trigger('deselect_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
  3296. if(!supress_event) {
  3297. this.trigger('changed', { 'action' : 'deselect_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
  3298. }
  3299. }
  3300. },
  3301. /**
  3302. * select all nodes in the tree
  3303. * @name select_all([supress_event])
  3304. * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
  3305. * @trigger select_all.jstree, changed.jstree
  3306. */
  3307. select_all : function (supress_event) {
  3308. var tmp = this._data.core.selected.concat([]), i, j;
  3309. this._data.core.selected = this._model.data[$.jstree.root].children_d.concat();
  3310. for(i = 0, j = this._data.core.selected.length; i < j; i++) {
  3311. if(this._model.data[this._data.core.selected[i]]) {
  3312. this._model.data[this._data.core.selected[i]].state.selected = true;
  3313. }
  3314. }
  3315. this.redraw(true);
  3316. /**
  3317. * triggered when all nodes are selected
  3318. * @event
  3319. * @name select_all.jstree
  3320. * @param {Array} selected the current selection
  3321. */
  3322. this.trigger('select_all', { 'selected' : this._data.core.selected });
  3323. if(!supress_event) {
  3324. this.trigger('changed', { 'action' : 'select_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
  3325. }
  3326. },
  3327. /**
  3328. * deselect all selected nodes
  3329. * @name deselect_all([supress_event])
  3330. * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
  3331. * @trigger deselect_all.jstree, changed.jstree
  3332. */
  3333. deselect_all : function (supress_event) {
  3334. var tmp = this._data.core.selected.concat([]), i, j;
  3335. for(i = 0, j = this._data.core.selected.length; i < j; i++) {
  3336. if(this._model.data[this._data.core.selected[i]]) {
  3337. this._model.data[this._data.core.selected[i]].state.selected = false;
  3338. }
  3339. }
  3340. this._data.core.selected = [];
  3341. this.element.find('.jstree-clicked').removeClass('jstree-clicked').attr('aria-selected', false).parent().attr('aria-selected', false);
  3342. /**
  3343. * triggered when all nodes are deselected
  3344. * @event
  3345. * @name deselect_all.jstree
  3346. * @param {Object} node the previous selection
  3347. * @param {Array} selected the current selection
  3348. */
  3349. this.trigger('deselect_all', { 'selected' : this._data.core.selected, 'node' : tmp });
  3350. if(!supress_event) {
  3351. this.trigger('changed', { 'action' : 'deselect_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
  3352. }
  3353. },
  3354. /**
  3355. * checks if a node is selected
  3356. * @name is_selected(obj)
  3357. * @param {mixed} obj
  3358. * @return {Boolean}
  3359. */
  3360. is_selected : function (obj) {
  3361. obj = this.get_node(obj);
  3362. if(!obj || obj.id === $.jstree.root) {
  3363. return false;
  3364. }
  3365. return obj.state.selected;
  3366. },
  3367. /**
  3368. * get an array of all selected nodes
  3369. * @name get_selected([full])
  3370. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  3371. * @return {Array}
  3372. */
  3373. get_selected : function (full) {
  3374. return full ? $.map(this._data.core.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.core.selected.slice();
  3375. },
  3376. /**
  3377. * get an array of all top level selected nodes (ignoring children of selected nodes)
  3378. * @name get_top_selected([full])
  3379. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  3380. * @return {Array}
  3381. */
  3382. get_top_selected : function (full) {
  3383. var tmp = this.get_selected(true),
  3384. obj = {}, i, j, k, l;
  3385. for(i = 0, j = tmp.length; i < j; i++) {
  3386. obj[tmp[i].id] = tmp[i];
  3387. }
  3388. for(i = 0, j = tmp.length; i < j; i++) {
  3389. for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
  3390. if(obj[tmp[i].children_d[k]]) {
  3391. delete obj[tmp[i].children_d[k]];
  3392. }
  3393. }
  3394. }
  3395. tmp = [];
  3396. for(i in obj) {
  3397. if(obj.hasOwnProperty(i)) {
  3398. tmp.push(i);
  3399. }
  3400. }
  3401. return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
  3402. },
  3403. /**
  3404. * get an array of all bottom level selected nodes (ignoring selected parents)
  3405. * @name get_bottom_selected([full])
  3406. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  3407. * @return {Array}
  3408. */
  3409. get_bottom_selected : function (full) {
  3410. var tmp = this.get_selected(true),
  3411. obj = [], i, j;
  3412. for(i = 0, j = tmp.length; i < j; i++) {
  3413. if(!tmp[i].children.length) {
  3414. obj.push(tmp[i].id);
  3415. }
  3416. }
  3417. return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
  3418. },
  3419. /**
  3420. * gets the current state of the tree so that it can be restored later with `set_state(state)`. Used internally.
  3421. * @name get_state()
  3422. * @private
  3423. * @return {Object}
  3424. */
  3425. get_state : function () {
  3426. var state = {
  3427. 'core' : {
  3428. 'open' : [],
  3429. 'loaded' : [],
  3430. 'scroll' : {
  3431. 'left' : this.element.scrollLeft(),
  3432. 'top' : this.element.scrollTop()
  3433. },
  3434. /*!
  3435. 'themes' : {
  3436. 'name' : this.get_theme(),
  3437. 'icons' : this._data.core.themes.icons,
  3438. 'dots' : this._data.core.themes.dots
  3439. },
  3440. */
  3441. 'selected' : []
  3442. }
  3443. }, i;
  3444. for(i in this._model.data) {
  3445. if(this._model.data.hasOwnProperty(i)) {
  3446. if(i !== $.jstree.root) {
  3447. if(this._model.data[i].state.loaded && this.settings.core.loaded_state) {
  3448. state.core.loaded.push(i);
  3449. }
  3450. if(this._model.data[i].state.opened) {
  3451. state.core.open.push(i);
  3452. }
  3453. if(this._model.data[i].state.selected) {
  3454. state.core.selected.push(i);
  3455. }
  3456. }
  3457. }
  3458. }
  3459. return state;
  3460. },
  3461. /**
  3462. * sets the state of the tree. Used internally.
  3463. * @name set_state(state [, callback])
  3464. * @private
  3465. * @param {Object} state the state to restore. Keep in mind this object is passed by reference and jstree will modify it.
  3466. * @param {Function} callback an optional function to execute once the state is restored.
  3467. * @trigger set_state.jstree
  3468. */
  3469. set_state : function (state, callback) {
  3470. if(state) {
  3471. if(state.core && state.core.selected && state.core.initial_selection === undefined) {
  3472. state.core.initial_selection = this._data.core.selected.concat([]).sort().join(',');
  3473. }
  3474. if(state.core) {
  3475. var res, n, t, _this, i;
  3476. if(state.core.loaded) {
  3477. if(!this.settings.core.loaded_state || !$.isArray(state.core.loaded) || !state.core.loaded.length) {
  3478. delete state.core.loaded;
  3479. this.set_state(state, callback);
  3480. }
  3481. else {
  3482. this._load_nodes(state.core.loaded, function (nodes) {
  3483. delete state.core.loaded;
  3484. this.set_state(state, callback);
  3485. });
  3486. }
  3487. return false;
  3488. }
  3489. if(state.core.open) {
  3490. if(!$.isArray(state.core.open) || !state.core.open.length) {
  3491. delete state.core.open;
  3492. this.set_state(state, callback);
  3493. }
  3494. else {
  3495. this._load_nodes(state.core.open, function (nodes) {
  3496. this.open_node(nodes, false, 0);
  3497. delete state.core.open;
  3498. this.set_state(state, callback);
  3499. });
  3500. }
  3501. return false;
  3502. }
  3503. if(state.core.scroll) {
  3504. if(state.core.scroll && state.core.scroll.left !== undefined) {
  3505. this.element.scrollLeft(state.core.scroll.left);
  3506. }
  3507. if(state.core.scroll && state.core.scroll.top !== undefined) {
  3508. this.element.scrollTop(state.core.scroll.top);
  3509. }
  3510. delete state.core.scroll;
  3511. this.set_state(state, callback);
  3512. return false;
  3513. }
  3514. if(state.core.selected) {
  3515. _this = this;
  3516. if (state.core.initial_selection === undefined ||
  3517. state.core.initial_selection === this._data.core.selected.concat([]).sort().join(',')
  3518. ) {
  3519. this.deselect_all();
  3520. $.each(state.core.selected, function (i, v) {
  3521. _this.select_node(v, false, true);
  3522. });
  3523. }
  3524. delete state.core.initial_selection;
  3525. delete state.core.selected;
  3526. this.set_state(state, callback);
  3527. return false;
  3528. }
  3529. for(i in state) {
  3530. if(state.hasOwnProperty(i) && i !== "core" && $.inArray(i, this.settings.plugins) === -1) {
  3531. delete state[i];
  3532. }
  3533. }
  3534. if($.isEmptyObject(state.core)) {
  3535. delete state.core;
  3536. this.set_state(state, callback);
  3537. return false;
  3538. }
  3539. }
  3540. if($.isEmptyObject(state)) {
  3541. state = null;
  3542. if(callback) { callback.call(this); }
  3543. /**
  3544. * triggered when a `set_state` call completes
  3545. * @event
  3546. * @name set_state.jstree
  3547. */
  3548. this.trigger('set_state');
  3549. return false;
  3550. }
  3551. return true;
  3552. }
  3553. return false;
  3554. },
  3555. /**
  3556. * refreshes the tree - all nodes are reloaded with calls to `load_node`.
  3557. * @name refresh()
  3558. * @param {Boolean} skip_loading an option to skip showing the loading indicator
  3559. * @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
  3560. * @trigger refresh.jstree
  3561. */
  3562. refresh : function (skip_loading, forget_state) {
  3563. this._data.core.state = forget_state === true ? {} : this.get_state();
  3564. if(forget_state && $.isFunction(forget_state)) { this._data.core.state = forget_state.call(this, this._data.core.state); }
  3565. this._cnt = 0;
  3566. this._model.data = {};
  3567. this._model.data[$.jstree.root] = {
  3568. id : $.jstree.root,
  3569. parent : null,
  3570. parents : [],
  3571. children : [],
  3572. children_d : [],
  3573. state : { loaded : false }
  3574. };
  3575. this._data.core.selected = [];
  3576. this._data.core.last_clicked = null;
  3577. this._data.core.focused = null;
  3578. var c = this.get_container_ul()[0].className;
  3579. if(!skip_loading) {
  3580. this.element.html("<"+"ul class='"+c+"' role='group'><"+"li class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='presentation' id='j"+this._id+"_loading'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' role='treeitem' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
  3581. this.element.attr('aria-activedescendant','j'+this._id+'_loading');
  3582. }
  3583. this.load_node($.jstree.root, function (o, s) {
  3584. if(s) {
  3585. this.get_container_ul()[0].className = c;
  3586. if(this._firstChild(this.get_container_ul()[0])) {
  3587. this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
  3588. }
  3589. this.set_state($.extend(true, {}, this._data.core.state), function () {
  3590. /**
  3591. * triggered when a `refresh` call completes
  3592. * @event
  3593. * @name refresh.jstree
  3594. */
  3595. this.trigger('refresh');
  3596. });
  3597. }
  3598. this._data.core.state = null;
  3599. });
  3600. },
  3601. /**
  3602. * refreshes a node in the tree (reload its children) all opened nodes inside that node are reloaded with calls to `load_node`.
  3603. * @name refresh_node(obj)
  3604. * @param {mixed} obj the node
  3605. * @trigger refresh_node.jstree
  3606. */
  3607. refresh_node : function (obj) {
  3608. obj = this.get_node(obj);
  3609. if(!obj || obj.id === $.jstree.root) { return false; }
  3610. var opened = [], to_load = [], s = this._data.core.selected.concat([]);
  3611. to_load.push(obj.id);
  3612. if(obj.state.opened === true) { opened.push(obj.id); }
  3613. this.get_node(obj, true).find('.jstree-open').each(function() { to_load.push(this.id); opened.push(this.id); });
  3614. this._load_nodes(to_load, $.proxy(function (nodes) {
  3615. this.open_node(opened, false, 0);
  3616. this.select_node(s);
  3617. /**
  3618. * triggered when a node is refreshed
  3619. * @event
  3620. * @name refresh_node.jstree
  3621. * @param {Object} node - the refreshed node
  3622. * @param {Array} nodes - an array of the IDs of the nodes that were reloaded
  3623. */
  3624. this.trigger('refresh_node', { 'node' : obj, 'nodes' : nodes });
  3625. }, this), false, true);
  3626. },
  3627. /**
  3628. * set (change) the ID of a node
  3629. * @name set_id(obj, id)
  3630. * @param {mixed} obj the node
  3631. * @param {String} id the new ID
  3632. * @return {Boolean}
  3633. * @trigger set_id.jstree
  3634. */
  3635. set_id : function (obj, id) {
  3636. obj = this.get_node(obj);
  3637. if(!obj || obj.id === $.jstree.root) { return false; }
  3638. var i, j, m = this._model.data, old = obj.id;
  3639. id = id.toString();
  3640. // update parents (replace current ID with new one in children and children_d)
  3641. m[obj.parent].children[$.inArray(obj.id, m[obj.parent].children)] = id;
  3642. for(i = 0, j = obj.parents.length; i < j; i++) {
  3643. m[obj.parents[i]].children_d[$.inArray(obj.id, m[obj.parents[i]].children_d)] = id;
  3644. }
  3645. // update children (replace current ID with new one in parent and parents)
  3646. for(i = 0, j = obj.children.length; i < j; i++) {
  3647. m[obj.children[i]].parent = id;
  3648. }
  3649. for(i = 0, j = obj.children_d.length; i < j; i++) {
  3650. m[obj.children_d[i]].parents[$.inArray(obj.id, m[obj.children_d[i]].parents)] = id;
  3651. }
  3652. i = $.inArray(obj.id, this._data.core.selected);
  3653. if(i !== -1) { this._data.core.selected[i] = id; }
  3654. // update model and obj itself (obj.id, this._model.data[KEY])
  3655. i = this.get_node(obj.id, true);
  3656. if(i) {
  3657. i.attr('id', id); //.children('.jstree-anchor').attr('id', id + '_anchor').end().attr('aria-labelledby', id + '_anchor');
  3658. if(this.element.attr('aria-activedescendant') === obj.id) {
  3659. this.element.attr('aria-activedescendant', id);
  3660. }
  3661. }
  3662. delete m[obj.id];
  3663. obj.id = id;
  3664. obj.li_attr.id = id;
  3665. m[id] = obj;
  3666. /**
  3667. * triggered when a node id value is changed
  3668. * @event
  3669. * @name set_id.jstree
  3670. * @param {Object} node
  3671. * @param {String} old the old id
  3672. */
  3673. this.trigger('set_id',{ "node" : obj, "new" : obj.id, "old" : old });
  3674. return true;
  3675. },
  3676. /**
  3677. * get the text value of a node
  3678. * @name get_text(obj)
  3679. * @param {mixed} obj the node
  3680. * @return {String}
  3681. */
  3682. get_text : function (obj) {
  3683. obj = this.get_node(obj);
  3684. return (!obj || obj.id === $.jstree.root) ? false : obj.text;
  3685. },
  3686. /**
  3687. * set the text value of a node. Used internally, please use `rename_node(obj, val)`.
  3688. * @private
  3689. * @name set_text(obj, val)
  3690. * @param {mixed} obj the node, you can pass an array to set the text on multiple nodes
  3691. * @param {String} val the new text value
  3692. * @return {Boolean}
  3693. * @trigger set_text.jstree
  3694. */
  3695. set_text : function (obj, val) {
  3696. var t1, t2;
  3697. if($.isArray(obj)) {
  3698. obj = obj.slice();
  3699. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3700. this.set_text(obj[t1], val);
  3701. }
  3702. return true;
  3703. }
  3704. obj = this.get_node(obj);
  3705. if(!obj || obj.id === $.jstree.root) { return false; }
  3706. obj.text = val;
  3707. if(this.get_node(obj, true).length) {
  3708. this.redraw_node(obj.id);
  3709. }
  3710. /**
  3711. * triggered when a node text value is changed
  3712. * @event
  3713. * @name set_text.jstree
  3714. * @param {Object} obj
  3715. * @param {String} text the new value
  3716. */
  3717. this.trigger('set_text',{ "obj" : obj, "text" : val });
  3718. return true;
  3719. },
  3720. /**
  3721. * gets a JSON representation of a node (or the whole tree)
  3722. * @name get_json([obj, options])
  3723. * @param {mixed} obj
  3724. * @param {Object} options
  3725. * @param {Boolean} options.no_state do not return state information
  3726. * @param {Boolean} options.no_id do not return ID
  3727. * @param {Boolean} options.no_children do not include children
  3728. * @param {Boolean} options.no_data do not include node data
  3729. * @param {Boolean} options.no_li_attr do not include LI attributes
  3730. * @param {Boolean} options.no_a_attr do not include A attributes
  3731. * @param {Boolean} options.flat return flat JSON instead of nested
  3732. * @return {Object}
  3733. */
  3734. get_json : function (obj, options, flat) {
  3735. obj = this.get_node(obj || $.jstree.root);
  3736. if(!obj) { return false; }
  3737. if(options && options.flat && !flat) { flat = []; }
  3738. var tmp = {
  3739. 'id' : obj.id,
  3740. 'text' : obj.text,
  3741. 'icon' : this.get_icon(obj),
  3742. 'li_attr' : $.extend(true, {}, obj.li_attr),
  3743. 'a_attr' : $.extend(true, {}, obj.a_attr),
  3744. 'state' : {},
  3745. 'data' : options && options.no_data ? false : $.extend(true, $.isArray(obj.data)?[]:{}, obj.data)
  3746. //( this.get_node(obj, true).length ? this.get_node(obj, true).data() : obj.data ),
  3747. }, i, j;
  3748. if(options && options.flat) {
  3749. tmp.parent = obj.parent;
  3750. }
  3751. else {
  3752. tmp.children = [];
  3753. }
  3754. if(!options || !options.no_state) {
  3755. for(i in obj.state) {
  3756. if(obj.state.hasOwnProperty(i)) {
  3757. tmp.state[i] = obj.state[i];
  3758. }
  3759. }
  3760. } else {
  3761. delete tmp.state;
  3762. }
  3763. if(options && options.no_li_attr) {
  3764. delete tmp.li_attr;
  3765. }
  3766. if(options && options.no_a_attr) {
  3767. delete tmp.a_attr;
  3768. }
  3769. if(options && options.no_id) {
  3770. delete tmp.id;
  3771. if(tmp.li_attr && tmp.li_attr.id) {
  3772. delete tmp.li_attr.id;
  3773. }
  3774. if(tmp.a_attr && tmp.a_attr.id) {
  3775. delete tmp.a_attr.id;
  3776. }
  3777. }
  3778. if(options && options.flat && obj.id !== $.jstree.root) {
  3779. flat.push(tmp);
  3780. }
  3781. if(!options || !options.no_children) {
  3782. for(i = 0, j = obj.children.length; i < j; i++) {
  3783. if(options && options.flat) {
  3784. this.get_json(obj.children[i], options, flat);
  3785. }
  3786. else {
  3787. tmp.children.push(this.get_json(obj.children[i], options));
  3788. }
  3789. }
  3790. }
  3791. return options && options.flat ? flat : (obj.id === $.jstree.root ? tmp.children : tmp);
  3792. },
  3793. /**
  3794. * create a new node (do not confuse with load_node)
  3795. * @name create_node([par, node, pos, callback, is_loaded])
  3796. * @param {mixed} par the parent node (to create a root node use either "#" (string) or `null`)
  3797. * @param {mixed} node the data for the new node (a valid JSON object, or a simple string with the name)
  3798. * @param {mixed} pos the index at which to insert the node, "first" and "last" are also supported, default is "last"
  3799. * @param {Function} callback a function to be called once the node is created
  3800. * @param {Boolean} is_loaded internal argument indicating if the parent node was succesfully loaded
  3801. * @return {String} the ID of the newly create node
  3802. * @trigger model.jstree, create_node.jstree
  3803. */
  3804. create_node : function (par, node, pos, callback, is_loaded) {
  3805. if(par === null) { par = $.jstree.root; }
  3806. par = this.get_node(par);
  3807. if(!par) { return false; }
  3808. pos = pos === undefined ? "last" : pos;
  3809. if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
  3810. return this.load_node(par, function () { this.create_node(par, node, pos, callback, true); });
  3811. }
  3812. if(!node) { node = { "text" : this.get_string('New node') }; }
  3813. if(typeof node === "string") {
  3814. node = { "text" : node };
  3815. } else {
  3816. node = $.extend(true, {}, node);
  3817. }
  3818. if(node.text === undefined) { node.text = this.get_string('New node'); }
  3819. var tmp, dpc, i, j;
  3820. if(par.id === $.jstree.root) {
  3821. if(pos === "before") { pos = "first"; }
  3822. if(pos === "after") { pos = "last"; }
  3823. }
  3824. switch(pos) {
  3825. case "before":
  3826. tmp = this.get_node(par.parent);
  3827. pos = $.inArray(par.id, tmp.children);
  3828. par = tmp;
  3829. break;
  3830. case "after" :
  3831. tmp = this.get_node(par.parent);
  3832. pos = $.inArray(par.id, tmp.children) + 1;
  3833. par = tmp;
  3834. break;
  3835. case "inside":
  3836. case "first":
  3837. pos = 0;
  3838. break;
  3839. case "last":
  3840. pos = par.children.length;
  3841. break;
  3842. default:
  3843. if(!pos) { pos = 0; }
  3844. break;
  3845. }
  3846. if(pos > par.children.length) { pos = par.children.length; }
  3847. if(!node.id) { node.id = true; }
  3848. if(!this.check("create_node", node, par, pos)) {
  3849. this.settings.core.error.call(this, this._data.core.last_error);
  3850. return false;
  3851. }
  3852. if(node.id === true) { delete node.id; }
  3853. node = this._parse_model_from_json(node, par.id, par.parents.concat());
  3854. if(!node) { return false; }
  3855. tmp = this.get_node(node);
  3856. dpc = [];
  3857. dpc.push(node);
  3858. dpc = dpc.concat(tmp.children_d);
  3859. this.trigger('model', { "nodes" : dpc, "parent" : par.id });
  3860. par.children_d = par.children_d.concat(dpc);
  3861. for(i = 0, j = par.parents.length; i < j; i++) {
  3862. this._model.data[par.parents[i]].children_d = this._model.data[par.parents[i]].children_d.concat(dpc);
  3863. }
  3864. node = tmp;
  3865. tmp = [];
  3866. for(i = 0, j = par.children.length; i < j; i++) {
  3867. tmp[i >= pos ? i+1 : i] = par.children[i];
  3868. }
  3869. tmp[pos] = node.id;
  3870. par.children = tmp;
  3871. this.redraw_node(par, true);
  3872. /**
  3873. * triggered when a node is created
  3874. * @event
  3875. * @name create_node.jstree
  3876. * @param {Object} node
  3877. * @param {String} parent the parent's ID
  3878. * @param {Number} position the position of the new node among the parent's children
  3879. */
  3880. this.trigger('create_node', { "node" : this.get_node(node), "parent" : par.id, "position" : pos });
  3881. if(callback) { callback.call(this, this.get_node(node)); }
  3882. return node.id;
  3883. },
  3884. /**
  3885. * set the text value of a node
  3886. * @name rename_node(obj, val)
  3887. * @param {mixed} obj the node, you can pass an array to rename multiple nodes to the same name
  3888. * @param {String} val the new text value
  3889. * @return {Boolean}
  3890. * @trigger rename_node.jstree
  3891. */
  3892. rename_node : function (obj, val) {
  3893. var t1, t2, old;
  3894. if($.isArray(obj)) {
  3895. obj = obj.slice();
  3896. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3897. this.rename_node(obj[t1], val);
  3898. }
  3899. return true;
  3900. }
  3901. obj = this.get_node(obj);
  3902. if(!obj || obj.id === $.jstree.root) { return false; }
  3903. old = obj.text;
  3904. if(!this.check("rename_node", obj, this.get_parent(obj), val)) {
  3905. this.settings.core.error.call(this, this._data.core.last_error);
  3906. return false;
  3907. }
  3908. this.set_text(obj, val); // .apply(this, Array.prototype.slice.call(arguments))
  3909. /**
  3910. * triggered when a node is renamed
  3911. * @event
  3912. * @name rename_node.jstree
  3913. * @param {Object} node
  3914. * @param {String} text the new value
  3915. * @param {String} old the old value
  3916. */
  3917. this.trigger('rename_node', { "node" : obj, "text" : val, "old" : old });
  3918. return true;
  3919. },
  3920. /**
  3921. * remove a node
  3922. * @name delete_node(obj)
  3923. * @param {mixed} obj the node, you can pass an array to delete multiple nodes
  3924. * @return {Boolean}
  3925. * @trigger delete_node.jstree, changed.jstree
  3926. */
  3927. delete_node : function (obj) {
  3928. var t1, t2, par, pos, tmp, i, j, k, l, c, top, lft;
  3929. if($.isArray(obj)) {
  3930. obj = obj.slice();
  3931. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  3932. this.delete_node(obj[t1]);
  3933. }
  3934. return true;
  3935. }
  3936. obj = this.get_node(obj);
  3937. if(!obj || obj.id === $.jstree.root) { return false; }
  3938. par = this.get_node(obj.parent);
  3939. pos = $.inArray(obj.id, par.children);
  3940. c = false;
  3941. if(!this.check("delete_node", obj, par, pos)) {
  3942. this.settings.core.error.call(this, this._data.core.last_error);
  3943. return false;
  3944. }
  3945. if(pos !== -1) {
  3946. par.children = $.vakata.array_remove(par.children, pos);
  3947. }
  3948. tmp = obj.children_d.concat([]);
  3949. tmp.push(obj.id);
  3950. for(i = 0, j = obj.parents.length; i < j; i++) {
  3951. this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
  3952. return $.inArray(v, tmp) === -1;
  3953. });
  3954. }
  3955. for(k = 0, l = tmp.length; k < l; k++) {
  3956. if(this._model.data[tmp[k]].state.selected) {
  3957. c = true;
  3958. break;
  3959. }
  3960. }
  3961. if (c) {
  3962. this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
  3963. return $.inArray(v, tmp) === -1;
  3964. });
  3965. }
  3966. /**
  3967. * triggered when a node is deleted
  3968. * @event
  3969. * @name delete_node.jstree
  3970. * @param {Object} node
  3971. * @param {String} parent the parent's ID
  3972. */
  3973. this.trigger('delete_node', { "node" : obj, "parent" : par.id });
  3974. if(c) {
  3975. this.trigger('changed', { 'action' : 'delete_node', 'node' : obj, 'selected' : this._data.core.selected, 'parent' : par.id });
  3976. }
  3977. for(k = 0, l = tmp.length; k < l; k++) {
  3978. delete this._model.data[tmp[k]];
  3979. }
  3980. if($.inArray(this._data.core.focused, tmp) !== -1) {
  3981. this._data.core.focused = null;
  3982. top = this.element[0].scrollTop;
  3983. lft = this.element[0].scrollLeft;
  3984. if(par.id === $.jstree.root) {
  3985. if (this._model.data[$.jstree.root].children[0]) {
  3986. this.get_node(this._model.data[$.jstree.root].children[0], true).children('.jstree-anchor').focus();
  3987. }
  3988. }
  3989. else {
  3990. this.get_node(par, true).children('.jstree-anchor').focus();
  3991. }
  3992. this.element[0].scrollTop = top;
  3993. this.element[0].scrollLeft = lft;
  3994. }
  3995. this.redraw_node(par, true);
  3996. return true;
  3997. },
  3998. /**
  3999. * check if an operation is premitted on the tree. Used internally.
  4000. * @private
  4001. * @name check(chk, obj, par, pos)
  4002. * @param {String} chk the operation to check, can be "create_node", "rename_node", "delete_node", "copy_node" or "move_node"
  4003. * @param {mixed} obj the node
  4004. * @param {mixed} par the parent
  4005. * @param {mixed} pos the position to insert at, or if "rename_node" - the new name
  4006. * @param {mixed} more some various additional information, for example if a "move_node" operations is triggered by DND this will be the hovered node
  4007. * @return {Boolean}
  4008. */
  4009. check : function (chk, obj, par, pos, more) {
  4010. obj = obj && obj.id ? obj : this.get_node(obj);
  4011. par = par && par.id ? par : this.get_node(par);
  4012. var tmp = chk.match(/^move_node|copy_node|create_node$/i) ? par : obj,
  4013. chc = this.settings.core.check_callback;
  4014. if(chk === "move_node" || chk === "copy_node") {
  4015. if((!more || !more.is_multi) && (chk === "move_node" && $.inArray(obj.id, par.children) === pos)) {
  4016. this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_08', 'reason' : 'Moving node to its current position', 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
  4017. return false;
  4018. }
  4019. 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)) {
  4020. 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 }) };
  4021. return false;
  4022. }
  4023. }
  4024. if(tmp && tmp.data) { tmp = tmp.data; }
  4025. if(tmp && tmp.functions && (tmp.functions[chk] === false || tmp.functions[chk] === true)) {
  4026. if(tmp.functions[chk] === false) {
  4027. 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 }) };
  4028. }
  4029. return tmp.functions[chk];
  4030. }
  4031. if(chc === false || ($.isFunction(chc) && chc.call(this, chk, obj, par, pos, more) === false) || (chc && chc[chk] === false)) {
  4032. 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 }) };
  4033. return false;
  4034. }
  4035. return true;
  4036. },
  4037. /**
  4038. * get the last error
  4039. * @name last_error()
  4040. * @return {Object}
  4041. */
  4042. last_error : function () {
  4043. return this._data.core.last_error;
  4044. },
  4045. /**
  4046. * move a node to a new parent
  4047. * @name move_node(obj, par [, pos, callback, is_loaded])
  4048. * @param {mixed} obj the node to move, pass an array to move multiple nodes
  4049. * @param {mixed} par the new parent
  4050. * @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`
  4051. * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
  4052. * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
  4053. * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
  4054. * @param {Boolean} instance internal parameter indicating if the node comes from another instance
  4055. * @trigger move_node.jstree
  4056. */
  4057. move_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
  4058. var t1, t2, old_par, old_pos, new_par, old_ins, is_multi, dpc, tmp, i, j, k, l, p;
  4059. par = this.get_node(par);
  4060. pos = pos === undefined ? 0 : pos;
  4061. if(!par) { return false; }
  4062. if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
  4063. return this.load_node(par, function () { this.move_node(obj, par, pos, callback, true, false, origin); });
  4064. }
  4065. if($.isArray(obj)) {
  4066. if(obj.length === 1) {
  4067. obj = obj[0];
  4068. }
  4069. else {
  4070. //obj = obj.slice();
  4071. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4072. if((tmp = this.move_node(obj[t1], par, pos, callback, is_loaded, false, origin))) {
  4073. par = tmp;
  4074. pos = "after";
  4075. }
  4076. }
  4077. this.redraw();
  4078. return true;
  4079. }
  4080. }
  4081. obj = obj && obj.id ? obj : this.get_node(obj);
  4082. if(!obj || obj.id === $.jstree.root) { return false; }
  4083. old_par = (obj.parent || $.jstree.root).toString();
  4084. new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
  4085. old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
  4086. is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
  4087. 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;
  4088. if(old_ins && old_ins._id) {
  4089. obj = old_ins._model.data[obj.id];
  4090. }
  4091. if(is_multi) {
  4092. if((tmp = this.copy_node(obj, par, pos, callback, is_loaded, false, origin))) {
  4093. if(old_ins) { old_ins.delete_node(obj); }
  4094. return tmp;
  4095. }
  4096. return false;
  4097. }
  4098. //var m = this._model.data;
  4099. if(par.id === $.jstree.root) {
  4100. if(pos === "before") { pos = "first"; }
  4101. if(pos === "after") { pos = "last"; }
  4102. }
  4103. switch(pos) {
  4104. case "before":
  4105. pos = $.inArray(par.id, new_par.children);
  4106. break;
  4107. case "after" :
  4108. pos = $.inArray(par.id, new_par.children) + 1;
  4109. break;
  4110. case "inside":
  4111. case "first":
  4112. pos = 0;
  4113. break;
  4114. case "last":
  4115. pos = new_par.children.length;
  4116. break;
  4117. default:
  4118. if(!pos) { pos = 0; }
  4119. break;
  4120. }
  4121. if(pos > new_par.children.length) { pos = new_par.children.length; }
  4122. 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) })) {
  4123. this.settings.core.error.call(this, this._data.core.last_error);
  4124. return false;
  4125. }
  4126. if(obj.parent === new_par.id) {
  4127. dpc = new_par.children.concat();
  4128. tmp = $.inArray(obj.id, dpc);
  4129. if(tmp !== -1) {
  4130. dpc = $.vakata.array_remove(dpc, tmp);
  4131. if(pos > tmp) { pos--; }
  4132. }
  4133. tmp = [];
  4134. for(i = 0, j = dpc.length; i < j; i++) {
  4135. tmp[i >= pos ? i+1 : i] = dpc[i];
  4136. }
  4137. tmp[pos] = obj.id;
  4138. new_par.children = tmp;
  4139. this._node_changed(new_par.id);
  4140. this.redraw(new_par.id === $.jstree.root);
  4141. }
  4142. else {
  4143. // clean old parent and up
  4144. tmp = obj.children_d.concat();
  4145. tmp.push(obj.id);
  4146. for(i = 0, j = obj.parents.length; i < j; i++) {
  4147. dpc = [];
  4148. p = old_ins._model.data[obj.parents[i]].children_d;
  4149. for(k = 0, l = p.length; k < l; k++) {
  4150. if($.inArray(p[k], tmp) === -1) {
  4151. dpc.push(p[k]);
  4152. }
  4153. }
  4154. old_ins._model.data[obj.parents[i]].children_d = dpc;
  4155. }
  4156. old_ins._model.data[old_par].children = $.vakata.array_remove_item(old_ins._model.data[old_par].children, obj.id);
  4157. // insert into new parent and up
  4158. for(i = 0, j = new_par.parents.length; i < j; i++) {
  4159. this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(tmp);
  4160. }
  4161. dpc = [];
  4162. for(i = 0, j = new_par.children.length; i < j; i++) {
  4163. dpc[i >= pos ? i+1 : i] = new_par.children[i];
  4164. }
  4165. dpc[pos] = obj.id;
  4166. new_par.children = dpc;
  4167. new_par.children_d.push(obj.id);
  4168. new_par.children_d = new_par.children_d.concat(obj.children_d);
  4169. // update object
  4170. obj.parent = new_par.id;
  4171. tmp = new_par.parents.concat();
  4172. tmp.unshift(new_par.id);
  4173. p = obj.parents.length;
  4174. obj.parents = tmp;
  4175. // update object children
  4176. tmp = tmp.concat();
  4177. for(i = 0, j = obj.children_d.length; i < j; i++) {
  4178. this._model.data[obj.children_d[i]].parents = this._model.data[obj.children_d[i]].parents.slice(0,p*-1);
  4179. Array.prototype.push.apply(this._model.data[obj.children_d[i]].parents, tmp);
  4180. }
  4181. if(old_par === $.jstree.root || new_par.id === $.jstree.root) {
  4182. this._model.force_full_redraw = true;
  4183. }
  4184. if(!this._model.force_full_redraw) {
  4185. this._node_changed(old_par);
  4186. this._node_changed(new_par.id);
  4187. }
  4188. if(!skip_redraw) {
  4189. this.redraw();
  4190. }
  4191. }
  4192. if(callback) { callback.call(this, obj, new_par, pos); }
  4193. /**
  4194. * triggered when a node is moved
  4195. * @event
  4196. * @name move_node.jstree
  4197. * @param {Object} node
  4198. * @param {String} parent the parent's ID
  4199. * @param {Number} position the position of the node among the parent's children
  4200. * @param {String} old_parent the old parent of the node
  4201. * @param {Number} old_position the old position of the node
  4202. * @param {Boolean} is_multi do the node and new parent belong to different instances
  4203. * @param {jsTree} old_instance the instance the node came from
  4204. * @param {jsTree} new_instance the instance of the new parent
  4205. */
  4206. 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 });
  4207. return obj.id;
  4208. },
  4209. /**
  4210. * copy a node to a new parent
  4211. * @name copy_node(obj, par [, pos, callback, is_loaded])
  4212. * @param {mixed} obj the node to copy, pass an array to copy multiple nodes
  4213. * @param {mixed} par the new parent
  4214. * @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`
  4215. * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
  4216. * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
  4217. * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
  4218. * @param {Boolean} instance internal parameter indicating if the node comes from another instance
  4219. * @trigger model.jstree copy_node.jstree
  4220. */
  4221. copy_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
  4222. var t1, t2, dpc, tmp, i, j, node, old_par, new_par, old_ins, is_multi;
  4223. par = this.get_node(par);
  4224. pos = pos === undefined ? 0 : pos;
  4225. if(!par) { return false; }
  4226. if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
  4227. return this.load_node(par, function () { this.copy_node(obj, par, pos, callback, true, false, origin); });
  4228. }
  4229. if($.isArray(obj)) {
  4230. if(obj.length === 1) {
  4231. obj = obj[0];
  4232. }
  4233. else {
  4234. //obj = obj.slice();
  4235. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4236. if((tmp = this.copy_node(obj[t1], par, pos, callback, is_loaded, true, origin))) {
  4237. par = tmp;
  4238. pos = "after";
  4239. }
  4240. }
  4241. this.redraw();
  4242. return true;
  4243. }
  4244. }
  4245. obj = obj && obj.id ? obj : this.get_node(obj);
  4246. if(!obj || obj.id === $.jstree.root) { return false; }
  4247. old_par = (obj.parent || $.jstree.root).toString();
  4248. new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
  4249. old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
  4250. is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
  4251. if(old_ins && old_ins._id) {
  4252. obj = old_ins._model.data[obj.id];
  4253. }
  4254. if(par.id === $.jstree.root) {
  4255. if(pos === "before") { pos = "first"; }
  4256. if(pos === "after") { pos = "last"; }
  4257. }
  4258. switch(pos) {
  4259. case "before":
  4260. pos = $.inArray(par.id, new_par.children);
  4261. break;
  4262. case "after" :
  4263. pos = $.inArray(par.id, new_par.children) + 1;
  4264. break;
  4265. case "inside":
  4266. case "first":
  4267. pos = 0;
  4268. break;
  4269. case "last":
  4270. pos = new_par.children.length;
  4271. break;
  4272. default:
  4273. if(!pos) { pos = 0; }
  4274. break;
  4275. }
  4276. if(pos > new_par.children.length) { pos = new_par.children.length; }
  4277. 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) })) {
  4278. this.settings.core.error.call(this, this._data.core.last_error);
  4279. return false;
  4280. }
  4281. node = old_ins ? old_ins.get_json(obj, { no_id : true, no_data : true, no_state : true }) : obj;
  4282. if(!node) { return false; }
  4283. if(node.id === true) { delete node.id; }
  4284. node = this._parse_model_from_json(node, new_par.id, new_par.parents.concat());
  4285. if(!node) { return false; }
  4286. tmp = this.get_node(node);
  4287. if(obj && obj.state && obj.state.loaded === false) { tmp.state.loaded = false; }
  4288. dpc = [];
  4289. dpc.push(node);
  4290. dpc = dpc.concat(tmp.children_d);
  4291. this.trigger('model', { "nodes" : dpc, "parent" : new_par.id });
  4292. // insert into new parent and up
  4293. for(i = 0, j = new_par.parents.length; i < j; i++) {
  4294. this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(dpc);
  4295. }
  4296. dpc = [];
  4297. for(i = 0, j = new_par.children.length; i < j; i++) {
  4298. dpc[i >= pos ? i+1 : i] = new_par.children[i];
  4299. }
  4300. dpc[pos] = tmp.id;
  4301. new_par.children = dpc;
  4302. new_par.children_d.push(tmp.id);
  4303. new_par.children_d = new_par.children_d.concat(tmp.children_d);
  4304. if(new_par.id === $.jstree.root) {
  4305. this._model.force_full_redraw = true;
  4306. }
  4307. if(!this._model.force_full_redraw) {
  4308. this._node_changed(new_par.id);
  4309. }
  4310. if(!skip_redraw) {
  4311. this.redraw(new_par.id === $.jstree.root);
  4312. }
  4313. if(callback) { callback.call(this, tmp, new_par, pos); }
  4314. /**
  4315. * triggered when a node is copied
  4316. * @event
  4317. * @name copy_node.jstree
  4318. * @param {Object} node the copied node
  4319. * @param {Object} original the original node
  4320. * @param {String} parent the parent's ID
  4321. * @param {Number} position the position of the node among the parent's children
  4322. * @param {String} old_parent the old parent of the node
  4323. * @param {Number} old_position the position of the original node
  4324. * @param {Boolean} is_multi do the node and new parent belong to different instances
  4325. * @param {jsTree} old_instance the instance the node came from
  4326. * @param {jsTree} new_instance the instance of the new parent
  4327. */
  4328. 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 });
  4329. return tmp.id;
  4330. },
  4331. /**
  4332. * cut a node (a later call to `paste(obj)` would move the node)
  4333. * @name cut(obj)
  4334. * @param {mixed} obj multiple objects can be passed using an array
  4335. * @trigger cut.jstree
  4336. */
  4337. cut : function (obj) {
  4338. if(!obj) { obj = this._data.core.selected.concat(); }
  4339. if(!$.isArray(obj)) { obj = [obj]; }
  4340. if(!obj.length) { return false; }
  4341. var tmp = [], o, t1, t2;
  4342. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4343. o = this.get_node(obj[t1]);
  4344. if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
  4345. }
  4346. if(!tmp.length) { return false; }
  4347. ccp_node = tmp;
  4348. ccp_inst = this;
  4349. ccp_mode = 'move_node';
  4350. /**
  4351. * triggered when nodes are added to the buffer for moving
  4352. * @event
  4353. * @name cut.jstree
  4354. * @param {Array} node
  4355. */
  4356. this.trigger('cut', { "node" : obj });
  4357. },
  4358. /**
  4359. * copy a node (a later call to `paste(obj)` would copy the node)
  4360. * @name copy(obj)
  4361. * @param {mixed} obj multiple objects can be passed using an array
  4362. * @trigger copy.jstree
  4363. */
  4364. copy : function (obj) {
  4365. if(!obj) { obj = this._data.core.selected.concat(); }
  4366. if(!$.isArray(obj)) { obj = [obj]; }
  4367. if(!obj.length) { return false; }
  4368. var tmp = [], o, t1, t2;
  4369. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4370. o = this.get_node(obj[t1]);
  4371. if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
  4372. }
  4373. if(!tmp.length) { return false; }
  4374. ccp_node = tmp;
  4375. ccp_inst = this;
  4376. ccp_mode = 'copy_node';
  4377. /**
  4378. * triggered when nodes are added to the buffer for copying
  4379. * @event
  4380. * @name copy.jstree
  4381. * @param {Array} node
  4382. */
  4383. this.trigger('copy', { "node" : obj });
  4384. },
  4385. /**
  4386. * get the current buffer (any nodes that are waiting for a paste operation)
  4387. * @name get_buffer()
  4388. * @return {Object} an object consisting of `mode` ("copy_node" or "move_node"), `node` (an array of objects) and `inst` (the instance)
  4389. */
  4390. get_buffer : function () {
  4391. return { 'mode' : ccp_mode, 'node' : ccp_node, 'inst' : ccp_inst };
  4392. },
  4393. /**
  4394. * check if there is something in the buffer to paste
  4395. * @name can_paste()
  4396. * @return {Boolean}
  4397. */
  4398. can_paste : function () {
  4399. return ccp_mode !== false && ccp_node !== false; // && ccp_inst._model.data[ccp_node];
  4400. },
  4401. /**
  4402. * copy or move the previously cut or copied nodes to a new parent
  4403. * @name paste(obj [, pos])
  4404. * @param {mixed} obj the new parent
  4405. * @param {mixed} pos the position to insert at (besides integer, "first" and "last" are supported), defaults to integer `0`
  4406. * @trigger paste.jstree
  4407. */
  4408. paste : function (obj, pos) {
  4409. obj = this.get_node(obj);
  4410. if(!obj || !ccp_mode || !ccp_mode.match(/^(copy_node|move_node)$/) || !ccp_node) { return false; }
  4411. if(this[ccp_mode](ccp_node, obj, pos, false, false, false, ccp_inst)) {
  4412. /**
  4413. * triggered when paste is invoked
  4414. * @event
  4415. * @name paste.jstree
  4416. * @param {String} parent the ID of the receiving node
  4417. * @param {Array} node the nodes in the buffer
  4418. * @param {String} mode the performed operation - "copy_node" or "move_node"
  4419. */
  4420. this.trigger('paste', { "parent" : obj.id, "node" : ccp_node, "mode" : ccp_mode });
  4421. }
  4422. ccp_node = false;
  4423. ccp_mode = false;
  4424. ccp_inst = false;
  4425. },
  4426. /**
  4427. * clear the buffer of previously copied or cut nodes
  4428. * @name clear_buffer()
  4429. * @trigger clear_buffer.jstree
  4430. */
  4431. clear_buffer : function () {
  4432. ccp_node = false;
  4433. ccp_mode = false;
  4434. ccp_inst = false;
  4435. /**
  4436. * triggered when the copy / cut buffer is cleared
  4437. * @event
  4438. * @name clear_buffer.jstree
  4439. */
  4440. this.trigger('clear_buffer');
  4441. },
  4442. /**
  4443. * put a node in edit mode (input field to rename the node)
  4444. * @name edit(obj [, default_text, callback])
  4445. * @param {mixed} obj
  4446. * @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)
  4447. * @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
  4448. */
  4449. edit : function (obj, default_text, callback) {
  4450. var rtl, w, a, s, t, h1, h2, fn, tmp, cancel = false;
  4451. obj = this.get_node(obj);
  4452. if(!obj) { return false; }
  4453. if(!this.check("edit", obj, this.get_parent(obj))) {
  4454. this.settings.core.error.call(this, this._data.core.last_error);
  4455. return false;
  4456. }
  4457. tmp = obj;
  4458. default_text = typeof default_text === 'string' ? default_text : obj.text;
  4459. this.set_text(obj, "");
  4460. obj = this._open_to(obj);
  4461. tmp.text = default_text;
  4462. rtl = this._data.core.rtl;
  4463. w = this.element.width();
  4464. this._data.core.focused = tmp.id;
  4465. a = obj.children('.jstree-anchor').focus();
  4466. s = $('<span></span>');
  4467. /*!
  4468. oi = obj.children("i:visible"),
  4469. ai = a.children("i:visible"),
  4470. w1 = oi.width() * oi.length,
  4471. w2 = ai.width() * ai.length,
  4472. */
  4473. t = default_text;
  4474. h1 = $("<"+"div></div>", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo(document.body);
  4475. h2 = $("<"+"input />", {
  4476. "value" : t,
  4477. "class" : "jstree-rename-input",
  4478. // "size" : t.length,
  4479. "css" : {
  4480. "padding" : "0",
  4481. "border" : "1px solid silver",
  4482. "box-sizing" : "border-box",
  4483. "display" : "inline-block",
  4484. "height" : (this._data.core.li_height) + "px",
  4485. "lineHeight" : (this._data.core.li_height) + "px",
  4486. "width" : "150px" // will be set a bit further down
  4487. },
  4488. "blur" : $.proxy(function (e) {
  4489. e.stopImmediatePropagation();
  4490. e.preventDefault();
  4491. var i = s.children(".jstree-rename-input"),
  4492. v = i.val(),
  4493. f = this.settings.core.force_text,
  4494. nv;
  4495. if(v === "") { v = t; }
  4496. h1.remove();
  4497. s.replaceWith(a);
  4498. s.remove();
  4499. t = f ? t : $('<div></div>').append($.parseHTML(t)).html();
  4500. obj = this.get_node(obj);
  4501. this.set_text(obj, t);
  4502. nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html());
  4503. if(!nv) {
  4504. this.set_text(obj, t); // move this up? and fix #483
  4505. }
  4506. this._data.core.focused = tmp.id;
  4507. setTimeout($.proxy(function () {
  4508. var node = this.get_node(tmp.id, true);
  4509. if(node.length) {
  4510. this._data.core.focused = tmp.id;
  4511. node.children('.jstree-anchor').focus();
  4512. }
  4513. }, this), 0);
  4514. if(callback) {
  4515. callback.call(this, tmp, nv, cancel);
  4516. }
  4517. h2 = null;
  4518. }, this),
  4519. "keydown" : function (e) {
  4520. var key = e.which;
  4521. if(key === 27) {
  4522. cancel = true;
  4523. this.value = t;
  4524. }
  4525. if(key === 27 || key === 13 || key === 37 || key === 38 || key === 39 || key === 40 || key === 32) {
  4526. e.stopImmediatePropagation();
  4527. }
  4528. if(key === 27 || key === 13) {
  4529. e.preventDefault();
  4530. this.blur();
  4531. }
  4532. },
  4533. "click" : function (e) { e.stopImmediatePropagation(); },
  4534. "mousedown" : function (e) { e.stopImmediatePropagation(); },
  4535. "keyup" : function (e) {
  4536. h2.width(Math.min(h1.text("pW" + this.value).width(),w));
  4537. },
  4538. "keypress" : function(e) {
  4539. if(e.which === 13) { return false; }
  4540. }
  4541. });
  4542. fn = {
  4543. fontFamily : a.css('fontFamily') || '',
  4544. fontSize : a.css('fontSize') || '',
  4545. fontWeight : a.css('fontWeight') || '',
  4546. fontStyle : a.css('fontStyle') || '',
  4547. fontStretch : a.css('fontStretch') || '',
  4548. fontVariant : a.css('fontVariant') || '',
  4549. letterSpacing : a.css('letterSpacing') || '',
  4550. wordSpacing : a.css('wordSpacing') || ''
  4551. };
  4552. s.attr('class', a.attr('class')).append(a.contents().clone()).append(h2);
  4553. a.replaceWith(s);
  4554. h1.css(fn);
  4555. h2.css(fn).width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
  4556. $(document).one('mousedown.jstree touchstart.jstree dnd_start.vakata', function (e) {
  4557. if (h2 && e.target !== h2) {
  4558. $(h2).blur();
  4559. }
  4560. });
  4561. },
  4562. /**
  4563. * changes the theme
  4564. * @name set_theme(theme_name [, theme_url])
  4565. * @param {String} theme_name the name of the new theme to apply
  4566. * @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.
  4567. * @trigger set_theme.jstree
  4568. */
  4569. set_theme : function (theme_name, theme_url) {
  4570. if(!theme_name) { return false; }
  4571. if(theme_url === true) {
  4572. var dir = this.settings.core.themes.dir;
  4573. if(!dir) { dir = $.jstree.path + '/themes'; }
  4574. theme_url = dir + '/' + theme_name + '/style.css';
  4575. }
  4576. if(theme_url && $.inArray(theme_url, themes_loaded) === -1) {
  4577. $('head').append('<'+'link rel="stylesheet" href="' + theme_url + '" type="text/css" />');
  4578. themes_loaded.push(theme_url);
  4579. }
  4580. if(this._data.core.themes.name) {
  4581. this.element.removeClass('jstree-' + this._data.core.themes.name);
  4582. }
  4583. this._data.core.themes.name = theme_name;
  4584. this.element.addClass('jstree-' + theme_name);
  4585. this.element[this.settings.core.themes.responsive ? 'addClass' : 'removeClass' ]('jstree-' + theme_name + '-responsive');
  4586. /**
  4587. * triggered when a theme is set
  4588. * @event
  4589. * @name set_theme.jstree
  4590. * @param {String} theme the new theme
  4591. */
  4592. this.trigger('set_theme', { 'theme' : theme_name });
  4593. },
  4594. /**
  4595. * gets the name of the currently applied theme name
  4596. * @name get_theme()
  4597. * @return {String}
  4598. */
  4599. get_theme : function () { return this._data.core.themes.name; },
  4600. /**
  4601. * changes the theme variant (if the theme has variants)
  4602. * @name set_theme_variant(variant_name)
  4603. * @param {String|Boolean} variant_name the variant to apply (if `false` is used the current variant is removed)
  4604. */
  4605. set_theme_variant : function (variant_name) {
  4606. if(this._data.core.themes.variant) {
  4607. this.element.removeClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
  4608. }
  4609. this._data.core.themes.variant = variant_name;
  4610. if(variant_name) {
  4611. this.element.addClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
  4612. }
  4613. },
  4614. /**
  4615. * gets the name of the currently applied theme variant
  4616. * @name get_theme()
  4617. * @return {String}
  4618. */
  4619. get_theme_variant : function () { return this._data.core.themes.variant; },
  4620. /**
  4621. * shows a striped background on the container (if the theme supports it)
  4622. * @name show_stripes()
  4623. */
  4624. show_stripes : function () {
  4625. this._data.core.themes.stripes = true;
  4626. this.get_container_ul().addClass("jstree-striped");
  4627. /**
  4628. * triggered when stripes are shown
  4629. * @event
  4630. * @name show_stripes.jstree
  4631. */
  4632. this.trigger('show_stripes');
  4633. },
  4634. /**
  4635. * hides the striped background on the container
  4636. * @name hide_stripes()
  4637. */
  4638. hide_stripes : function () {
  4639. this._data.core.themes.stripes = false;
  4640. this.get_container_ul().removeClass("jstree-striped");
  4641. /**
  4642. * triggered when stripes are hidden
  4643. * @event
  4644. * @name hide_stripes.jstree
  4645. */
  4646. this.trigger('hide_stripes');
  4647. },
  4648. /**
  4649. * toggles the striped background on the container
  4650. * @name toggle_stripes()
  4651. */
  4652. toggle_stripes : function () { if(this._data.core.themes.stripes) { this.hide_stripes(); } else { this.show_stripes(); } },
  4653. /**
  4654. * shows the connecting dots (if the theme supports it)
  4655. * @name show_dots()
  4656. */
  4657. show_dots : function () {
  4658. this._data.core.themes.dots = true;
  4659. this.get_container_ul().removeClass("jstree-no-dots");
  4660. /**
  4661. * triggered when dots are shown
  4662. * @event
  4663. * @name show_dots.jstree
  4664. */
  4665. this.trigger('show_dots');
  4666. },
  4667. /**
  4668. * hides the connecting dots
  4669. * @name hide_dots()
  4670. */
  4671. hide_dots : function () {
  4672. this._data.core.themes.dots = false;
  4673. this.get_container_ul().addClass("jstree-no-dots");
  4674. /**
  4675. * triggered when dots are hidden
  4676. * @event
  4677. * @name hide_dots.jstree
  4678. */
  4679. this.trigger('hide_dots');
  4680. },
  4681. /**
  4682. * toggles the connecting dots
  4683. * @name toggle_dots()
  4684. */
  4685. toggle_dots : function () { if(this._data.core.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
  4686. /**
  4687. * show the node icons
  4688. * @name show_icons()
  4689. */
  4690. show_icons : function () {
  4691. this._data.core.themes.icons = true;
  4692. this.get_container_ul().removeClass("jstree-no-icons");
  4693. /**
  4694. * triggered when icons are shown
  4695. * @event
  4696. * @name show_icons.jstree
  4697. */
  4698. this.trigger('show_icons');
  4699. },
  4700. /**
  4701. * hide the node icons
  4702. * @name hide_icons()
  4703. */
  4704. hide_icons : function () {
  4705. this._data.core.themes.icons = false;
  4706. this.get_container_ul().addClass("jstree-no-icons");
  4707. /**
  4708. * triggered when icons are hidden
  4709. * @event
  4710. * @name hide_icons.jstree
  4711. */
  4712. this.trigger('hide_icons');
  4713. },
  4714. /**
  4715. * toggle the node icons
  4716. * @name toggle_icons()
  4717. */
  4718. toggle_icons : function () { if(this._data.core.themes.icons) { this.hide_icons(); } else { this.show_icons(); } },
  4719. /**
  4720. * show the node ellipsis
  4721. * @name show_icons()
  4722. */
  4723. show_ellipsis : function () {
  4724. this._data.core.themes.ellipsis = true;
  4725. this.get_container_ul().addClass("jstree-ellipsis");
  4726. /**
  4727. * triggered when ellisis is shown
  4728. * @event
  4729. * @name show_ellipsis.jstree
  4730. */
  4731. this.trigger('show_ellipsis');
  4732. },
  4733. /**
  4734. * hide the node ellipsis
  4735. * @name hide_ellipsis()
  4736. */
  4737. hide_ellipsis : function () {
  4738. this._data.core.themes.ellipsis = false;
  4739. this.get_container_ul().removeClass("jstree-ellipsis");
  4740. /**
  4741. * triggered when ellisis is hidden
  4742. * @event
  4743. * @name hide_ellipsis.jstree
  4744. */
  4745. this.trigger('hide_ellipsis');
  4746. },
  4747. /**
  4748. * toggle the node ellipsis
  4749. * @name toggle_icons()
  4750. */
  4751. toggle_ellipsis : function () { if(this._data.core.themes.ellipsis) { this.hide_ellipsis(); } else { this.show_ellipsis(); } },
  4752. /**
  4753. * set the node icon for a node
  4754. * @name set_icon(obj, icon)
  4755. * @param {mixed} obj
  4756. * @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
  4757. */
  4758. set_icon : function (obj, icon) {
  4759. var t1, t2, dom, old;
  4760. if($.isArray(obj)) {
  4761. obj = obj.slice();
  4762. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4763. this.set_icon(obj[t1], icon);
  4764. }
  4765. return true;
  4766. }
  4767. obj = this.get_node(obj);
  4768. if(!obj || obj.id === $.jstree.root) { return false; }
  4769. old = obj.icon;
  4770. obj.icon = icon === true || icon === null || icon === undefined || icon === '' ? true : icon;
  4771. dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
  4772. if(icon === false) {
  4773. dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
  4774. this.hide_icon(obj);
  4775. }
  4776. else if(icon === true || icon === null || icon === undefined || icon === '') {
  4777. dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
  4778. if(old === false) { this.show_icon(obj); }
  4779. }
  4780. else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
  4781. dom.removeClass(old).css("background","");
  4782. dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
  4783. if(old === false) { this.show_icon(obj); }
  4784. }
  4785. else {
  4786. dom.removeClass(old).css("background","");
  4787. dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
  4788. if(old === false) { this.show_icon(obj); }
  4789. }
  4790. return true;
  4791. },
  4792. /**
  4793. * get the node icon for a node
  4794. * @name get_icon(obj)
  4795. * @param {mixed} obj
  4796. * @return {String}
  4797. */
  4798. get_icon : function (obj) {
  4799. obj = this.get_node(obj);
  4800. return (!obj || obj.id === $.jstree.root) ? false : obj.icon;
  4801. },
  4802. /**
  4803. * hide the icon on an individual node
  4804. * @name hide_icon(obj)
  4805. * @param {mixed} obj
  4806. */
  4807. hide_icon : function (obj) {
  4808. var t1, t2;
  4809. if($.isArray(obj)) {
  4810. obj = obj.slice();
  4811. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4812. this.hide_icon(obj[t1]);
  4813. }
  4814. return true;
  4815. }
  4816. obj = this.get_node(obj);
  4817. if(!obj || obj === $.jstree.root) { return false; }
  4818. obj.icon = false;
  4819. this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon").addClass('jstree-themeicon-hidden');
  4820. return true;
  4821. },
  4822. /**
  4823. * show the icon on an individual node
  4824. * @name show_icon(obj)
  4825. * @param {mixed} obj
  4826. */
  4827. show_icon : function (obj) {
  4828. var t1, t2, dom;
  4829. if($.isArray(obj)) {
  4830. obj = obj.slice();
  4831. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  4832. this.show_icon(obj[t1]);
  4833. }
  4834. return true;
  4835. }
  4836. obj = this.get_node(obj);
  4837. if(!obj || obj === $.jstree.root) { return false; }
  4838. dom = this.get_node(obj, true);
  4839. obj.icon = dom.length ? dom.children(".jstree-anchor").children(".jstree-themeicon").attr('rel') : true;
  4840. if(!obj.icon) { obj.icon = true; }
  4841. dom.children(".jstree-anchor").children(".jstree-themeicon").removeClass('jstree-themeicon-hidden');
  4842. return true;
  4843. }
  4844. };
  4845. // helpers
  4846. $.vakata = {};
  4847. // collect attributes
  4848. $.vakata.attributes = function(node, with_values) {
  4849. node = $(node)[0];
  4850. var attr = with_values ? {} : [];
  4851. if(node && node.attributes) {
  4852. $.each(node.attributes, function (i, v) {
  4853. if($.inArray(v.name.toLowerCase(),['style','contenteditable','hasfocus','tabindex']) !== -1) { return; }
  4854. if(v.value !== null && $.trim(v.value) !== '') {
  4855. if(with_values) { attr[v.name] = v.value; }
  4856. else { attr.push(v.name); }
  4857. }
  4858. });
  4859. }
  4860. return attr;
  4861. };
  4862. $.vakata.array_unique = function(array) {
  4863. var a = [], i, j, l, o = {};
  4864. for(i = 0, l = array.length; i < l; i++) {
  4865. if(o[array[i]] === undefined) {
  4866. a.push(array[i]);
  4867. o[array[i]] = true;
  4868. }
  4869. }
  4870. return a;
  4871. };
  4872. // remove item from array
  4873. $.vakata.array_remove = function(array, from) {
  4874. array.splice(from, 1);
  4875. return array;
  4876. //var rest = array.slice((to || from) + 1 || array.length);
  4877. //array.length = from < 0 ? array.length + from : from;
  4878. //array.push.apply(array, rest);
  4879. //return array;
  4880. };
  4881. // remove item from array
  4882. $.vakata.array_remove_item = function(array, item) {
  4883. var tmp = $.inArray(item, array);
  4884. return tmp !== -1 ? $.vakata.array_remove(array, tmp) : array;
  4885. };
  4886. $.vakata.array_filter = function(c,a,b,d,e) {
  4887. if (c.filter) {
  4888. return c.filter(a, b);
  4889. }
  4890. d=[];
  4891. for (e in c) {
  4892. if (~~e+''===e+'' && e>=0 && a.call(b,c[e],+e,c)) {
  4893. d.push(c[e]);
  4894. }
  4895. }
  4896. return d;
  4897. };
  4898. /**
  4899. * ### Changed plugin
  4900. *
  4901. * 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.
  4902. */
  4903. $.jstree.plugins.changed = function (options, parent) {
  4904. var last = [];
  4905. this.trigger = function (ev, data) {
  4906. var i, j;
  4907. if(!data) {
  4908. data = {};
  4909. }
  4910. if(ev.replace('.jstree','') === 'changed') {
  4911. data.changed = { selected : [], deselected : [] };
  4912. var tmp = {};
  4913. for(i = 0, j = last.length; i < j; i++) {
  4914. tmp[last[i]] = 1;
  4915. }
  4916. for(i = 0, j = data.selected.length; i < j; i++) {
  4917. if(!tmp[data.selected[i]]) {
  4918. data.changed.selected.push(data.selected[i]);
  4919. }
  4920. else {
  4921. tmp[data.selected[i]] = 2;
  4922. }
  4923. }
  4924. for(i = 0, j = last.length; i < j; i++) {
  4925. if(tmp[last[i]] === 1) {
  4926. data.changed.deselected.push(last[i]);
  4927. }
  4928. }
  4929. last = data.selected.slice();
  4930. }
  4931. /**
  4932. * triggered when selection changes (the "changed" plugin enhances the original event with more data)
  4933. * @event
  4934. * @name changed.jstree
  4935. * @param {Object} node
  4936. * @param {Object} action the action that caused the selection to change
  4937. * @param {Array} selected the current selection
  4938. * @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
  4939. * @param {Object} event the event (if any) that triggered this changed event
  4940. * @plugin changed
  4941. */
  4942. parent.trigger.call(this, ev, data);
  4943. };
  4944. this.refresh = function (skip_loading, forget_state) {
  4945. last = [];
  4946. return parent.refresh.apply(this, arguments);
  4947. };
  4948. };
  4949. /**
  4950. * ### Checkbox plugin
  4951. *
  4952. * This plugin renders checkbox icons in front of each node, making multiple selection much easier.
  4953. * 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.
  4954. */
  4955. var _i = document.createElement('I');
  4956. _i.className = 'jstree-icon jstree-checkbox';
  4957. _i.setAttribute('role', 'presentation');
  4958. /**
  4959. * stores all defaults for the checkbox plugin
  4960. * @name $.jstree.defaults.checkbox
  4961. * @plugin checkbox
  4962. */
  4963. $.jstree.defaults.checkbox = {
  4964. /**
  4965. * a boolean indicating if checkboxes should be visible (can be changed at a later time using `show_checkboxes()` and `hide_checkboxes`). Defaults to `true`.
  4966. * @name $.jstree.defaults.checkbox.visible
  4967. * @plugin checkbox
  4968. */
  4969. visible : true,
  4970. /**
  4971. * a boolean indicating if checkboxes should cascade down and have an undetermined state. Defaults to `true`.
  4972. * @name $.jstree.defaults.checkbox.three_state
  4973. * @plugin checkbox
  4974. */
  4975. three_state : true,
  4976. /**
  4977. * a boolean indicating if clicking anywhere on the node should act as clicking on the checkbox. Defaults to `true`.
  4978. * @name $.jstree.defaults.checkbox.whole_node
  4979. * @plugin checkbox
  4980. */
  4981. whole_node : true,
  4982. /**
  4983. * a boolean indicating if the selected style of a node should be kept, or removed. Defaults to `true`.
  4984. * @name $.jstree.defaults.checkbox.keep_selected_style
  4985. * @plugin checkbox
  4986. */
  4987. keep_selected_style : true,
  4988. /**
  4989. * This setting controls how cascading and undetermined nodes are applied.
  4990. * 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.
  4991. * If `three_state` is set to `true` this setting is automatically set to 'up+down+undetermined'. Defaults to ''.
  4992. * @name $.jstree.defaults.checkbox.cascade
  4993. * @plugin checkbox
  4994. */
  4995. cascade : '',
  4996. /**
  4997. * 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.
  4998. * @name $.jstree.defaults.checkbox.tie_selection
  4999. * @plugin checkbox
  5000. */
  5001. tie_selection : true,
  5002. /**
  5003. * This setting controls if cascading down affects disabled checkboxes
  5004. * @name $.jstree.defaults.checkbox.cascade_to_disabled
  5005. * @plugin checkbox
  5006. */
  5007. cascade_to_disabled : true,
  5008. /**
  5009. * This setting controls if cascading down affects hidden checkboxes
  5010. * @name $.jstree.defaults.checkbox.cascade_to_hidden
  5011. * @plugin checkbox
  5012. */
  5013. cascade_to_hidden : true
  5014. };
  5015. $.jstree.plugins.checkbox = function (options, parent) {
  5016. this.bind = function () {
  5017. parent.bind.call(this);
  5018. this._data.checkbox.uto = false;
  5019. this._data.checkbox.selected = [];
  5020. if(this.settings.checkbox.three_state) {
  5021. this.settings.checkbox.cascade = 'up+down+undetermined';
  5022. }
  5023. this.element
  5024. .on("init.jstree", $.proxy(function () {
  5025. this._data.checkbox.visible = this.settings.checkbox.visible;
  5026. if(!this.settings.checkbox.keep_selected_style) {
  5027. this.element.addClass('jstree-checkbox-no-clicked');
  5028. }
  5029. if(this.settings.checkbox.tie_selection) {
  5030. this.element.addClass('jstree-checkbox-selection');
  5031. }
  5032. }, this))
  5033. .on("loading.jstree", $.proxy(function () {
  5034. this[ this._data.checkbox.visible ? 'show_checkboxes' : 'hide_checkboxes' ]();
  5035. }, this));
  5036. if(this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
  5037. this.element
  5038. .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 () {
  5039. // only if undetermined is in setting
  5040. if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
  5041. this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
  5042. }, this));
  5043. }
  5044. if(!this.settings.checkbox.tie_selection) {
  5045. this.element
  5046. .on('model.jstree', $.proxy(function (e, data) {
  5047. var m = this._model.data,
  5048. p = m[data.parent],
  5049. dpc = data.nodes,
  5050. i, j;
  5051. for(i = 0, j = dpc.length; i < j; i++) {
  5052. 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);
  5053. if(m[dpc[i]].state.checked) {
  5054. this._data.checkbox.selected.push(dpc[i]);
  5055. }
  5056. }
  5057. }, this));
  5058. }
  5059. if(this.settings.checkbox.cascade.indexOf('up') !== -1 || this.settings.checkbox.cascade.indexOf('down') !== -1) {
  5060. this.element
  5061. .on('model.jstree', $.proxy(function (e, data) {
  5062. var m = this._model.data,
  5063. p = m[data.parent],
  5064. dpc = data.nodes,
  5065. chd = [],
  5066. c, i, j, k, l, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection;
  5067. if(s.indexOf('down') !== -1) {
  5068. // apply down
  5069. if(p.state[ t ? 'selected' : 'checked' ]) {
  5070. for(i = 0, j = dpc.length; i < j; i++) {
  5071. m[dpc[i]].state[ t ? 'selected' : 'checked' ] = true;
  5072. }
  5073. this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(dpc);
  5074. }
  5075. else {
  5076. for(i = 0, j = dpc.length; i < j; i++) {
  5077. if(m[dpc[i]].state[ t ? 'selected' : 'checked' ]) {
  5078. for(k = 0, l = m[dpc[i]].children_d.length; k < l; k++) {
  5079. m[m[dpc[i]].children_d[k]].state[ t ? 'selected' : 'checked' ] = true;
  5080. }
  5081. this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(m[dpc[i]].children_d);
  5082. }
  5083. }
  5084. }
  5085. }
  5086. if(s.indexOf('up') !== -1) {
  5087. // apply up
  5088. for(i = 0, j = p.children_d.length; i < j; i++) {
  5089. if(!m[p.children_d[i]].children.length) {
  5090. chd.push(m[p.children_d[i]].parent);
  5091. }
  5092. }
  5093. chd = $.vakata.array_unique(chd);
  5094. for(k = 0, l = chd.length; k < l; k++) {
  5095. p = m[chd[k]];
  5096. while(p && p.id !== $.jstree.root) {
  5097. c = 0;
  5098. for(i = 0, j = p.children.length; i < j; i++) {
  5099. c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
  5100. }
  5101. if(c === j) {
  5102. p.state[ t ? 'selected' : 'checked' ] = true;
  5103. this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
  5104. tmp = this.get_node(p, true);
  5105. if(tmp && tmp.length) {
  5106. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass( t ? 'jstree-clicked' : 'jstree-checked');
  5107. }
  5108. }
  5109. else {
  5110. break;
  5111. }
  5112. p = this.get_node(p.parent);
  5113. }
  5114. }
  5115. }
  5116. this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected);
  5117. }, this))
  5118. .on(this.settings.checkbox.tie_selection ? 'select_node.jstree' : 'check_node.jstree', $.proxy(function (e, data) {
  5119. var self = this,
  5120. obj = data.node,
  5121. m = this._model.data,
  5122. par = this.get_node(obj.parent),
  5123. i, j, c, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
  5124. sel = {}, cur = this._data[ t ? 'core' : 'checkbox' ].selected;
  5125. for (i = 0, j = cur.length; i < j; i++) {
  5126. sel[cur[i]] = true;
  5127. }
  5128. // apply down
  5129. if(s.indexOf('down') !== -1) {
  5130. //this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected.concat(obj.children_d));
  5131. var selectedIds = this._cascade_new_checked_state(obj.id, true);
  5132. var temp = obj.children_d.concat(obj.id);
  5133. for (i = 0, j = temp.length; i < j; i++) {
  5134. if (selectedIds.indexOf(temp[i]) > -1) {
  5135. sel[temp[i]] = true;
  5136. }
  5137. else {
  5138. delete sel[temp[i]];
  5139. }
  5140. }
  5141. }
  5142. // apply up
  5143. if(s.indexOf('up') !== -1) {
  5144. while(par && par.id !== $.jstree.root) {
  5145. c = 0;
  5146. for(i = 0, j = par.children.length; i < j; i++) {
  5147. c += m[par.children[i]].state[ t ? 'selected' : 'checked' ];
  5148. }
  5149. if(c === j) {
  5150. par.state[ t ? 'selected' : 'checked' ] = true;
  5151. sel[par.id] = true;
  5152. //this._data[ t ? 'core' : 'checkbox' ].selected.push(par.id);
  5153. tmp = this.get_node(par, true);
  5154. if(tmp && tmp.length) {
  5155. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5156. }
  5157. }
  5158. else {
  5159. break;
  5160. }
  5161. par = this.get_node(par.parent);
  5162. }
  5163. }
  5164. cur = [];
  5165. for (i in sel) {
  5166. if (sel.hasOwnProperty(i)) {
  5167. cur.push(i);
  5168. }
  5169. }
  5170. this._data[ t ? 'core' : 'checkbox' ].selected = cur;
  5171. }, this))
  5172. .on(this.settings.checkbox.tie_selection ? 'deselect_all.jstree' : 'uncheck_all.jstree', $.proxy(function (e, data) {
  5173. var obj = this.get_node($.jstree.root),
  5174. m = this._model.data,
  5175. i, j, tmp;
  5176. for(i = 0, j = obj.children_d.length; i < j; i++) {
  5177. tmp = m[obj.children_d[i]];
  5178. if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
  5179. tmp.original.state.undetermined = false;
  5180. }
  5181. }
  5182. }, this))
  5183. .on(this.settings.checkbox.tie_selection ? 'deselect_node.jstree' : 'uncheck_node.jstree', $.proxy(function (e, data) {
  5184. var self = this,
  5185. obj = data.node,
  5186. dom = this.get_node(obj, true),
  5187. i, j, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
  5188. cur = this._data[ t ? 'core' : 'checkbox' ].selected, sel = {},
  5189. stillSelectedIds = [],
  5190. allIds = obj.children_d.concat(obj.id);
  5191. // apply down
  5192. if(s.indexOf('down') !== -1) {
  5193. var selectedIds = this._cascade_new_checked_state(obj.id, false);
  5194. cur = $.vakata.array_filter(cur, function(id) {
  5195. return allIds.indexOf(id) === -1 || selectedIds.indexOf(id) > -1;
  5196. });
  5197. }
  5198. // only apply up if cascade up is enabled and if this node is not selected
  5199. // (if all child nodes are disabled and cascade_to_disabled === false then this node will till be selected).
  5200. if(s.indexOf('up') !== -1 && cur.indexOf(obj.id) === -1) {
  5201. for(i = 0, j = obj.parents.length; i < j; i++) {
  5202. tmp = this._model.data[obj.parents[i]];
  5203. tmp.state[ t ? 'selected' : 'checked' ] = false;
  5204. if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
  5205. tmp.original.state.undetermined = false;
  5206. }
  5207. tmp = this.get_node(obj.parents[i], true);
  5208. if(tmp && tmp.length) {
  5209. tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
  5210. }
  5211. }
  5212. cur = $.vakata.array_filter(cur, function(id) {
  5213. return obj.parents.indexOf(id) === -1;
  5214. });
  5215. }
  5216. this._data[ t ? 'core' : 'checkbox' ].selected = cur;
  5217. }, this));
  5218. }
  5219. if(this.settings.checkbox.cascade.indexOf('up') !== -1) {
  5220. this.element
  5221. .on('delete_node.jstree', $.proxy(function (e, data) {
  5222. // apply up (whole handler)
  5223. var p = this.get_node(data.parent),
  5224. m = this._model.data,
  5225. i, j, c, tmp, t = this.settings.checkbox.tie_selection;
  5226. while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
  5227. c = 0;
  5228. for(i = 0, j = p.children.length; i < j; i++) {
  5229. c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
  5230. }
  5231. if(j > 0 && c === j) {
  5232. p.state[ t ? 'selected' : 'checked' ] = true;
  5233. this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
  5234. tmp = this.get_node(p, true);
  5235. if(tmp && tmp.length) {
  5236. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5237. }
  5238. }
  5239. else {
  5240. break;
  5241. }
  5242. p = this.get_node(p.parent);
  5243. }
  5244. }, this))
  5245. .on('move_node.jstree', $.proxy(function (e, data) {
  5246. // apply up (whole handler)
  5247. var is_multi = data.is_multi,
  5248. old_par = data.old_parent,
  5249. new_par = this.get_node(data.parent),
  5250. m = this._model.data,
  5251. p, c, i, j, tmp, t = this.settings.checkbox.tie_selection;
  5252. if(!is_multi) {
  5253. p = this.get_node(old_par);
  5254. while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
  5255. c = 0;
  5256. for(i = 0, j = p.children.length; i < j; i++) {
  5257. c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
  5258. }
  5259. if(j > 0 && c === j) {
  5260. p.state[ t ? 'selected' : 'checked' ] = true;
  5261. this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
  5262. tmp = this.get_node(p, true);
  5263. if(tmp && tmp.length) {
  5264. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5265. }
  5266. }
  5267. else {
  5268. break;
  5269. }
  5270. p = this.get_node(p.parent);
  5271. }
  5272. }
  5273. p = new_par;
  5274. while(p && p.id !== $.jstree.root) {
  5275. c = 0;
  5276. for(i = 0, j = p.children.length; i < j; i++) {
  5277. c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
  5278. }
  5279. if(c === j) {
  5280. if(!p.state[ t ? 'selected' : 'checked' ]) {
  5281. p.state[ t ? 'selected' : 'checked' ] = true;
  5282. this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
  5283. tmp = this.get_node(p, true);
  5284. if(tmp && tmp.length) {
  5285. tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5286. }
  5287. }
  5288. }
  5289. else {
  5290. if(p.state[ t ? 'selected' : 'checked' ]) {
  5291. p.state[ t ? 'selected' : 'checked' ] = false;
  5292. this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_remove_item(this._data[ t ? 'core' : 'checkbox' ].selected, p.id);
  5293. tmp = this.get_node(p, true);
  5294. if(tmp && tmp.length) {
  5295. tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
  5296. }
  5297. }
  5298. else {
  5299. break;
  5300. }
  5301. }
  5302. p = this.get_node(p.parent);
  5303. }
  5304. }, this));
  5305. }
  5306. };
  5307. /**
  5308. * get an array of all nodes whose state is "undetermined"
  5309. * @name get_undetermined([full])
  5310. * @param {boolean} full: if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  5311. * @return {Array}
  5312. * @plugin checkbox
  5313. */
  5314. this.get_undetermined = function (full) {
  5315. if (this.settings.checkbox.cascade.indexOf('undetermined') === -1) {
  5316. return [];
  5317. }
  5318. 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 = [];
  5319. for(i = 0, j = s.length; i < j; i++) {
  5320. if(m[s[i]] && m[s[i]].parents) {
  5321. for(k = 0, l = m[s[i]].parents.length; k < l; k++) {
  5322. if(o[m[s[i]].parents[k]] !== undefined) {
  5323. break;
  5324. }
  5325. if(m[s[i]].parents[k] !== $.jstree.root) {
  5326. o[m[s[i]].parents[k]] = true;
  5327. p.push(m[s[i]].parents[k]);
  5328. }
  5329. }
  5330. }
  5331. }
  5332. // attempt for server side undetermined state
  5333. this.element.find('.jstree-closed').not(':has(.jstree-children)')
  5334. .each(function () {
  5335. var tmp = tt.get_node(this), tmp2;
  5336. if(!tmp) { return; }
  5337. if(!tmp.state.loaded) {
  5338. if(tmp.original && tmp.original.state && tmp.original.state.undetermined && tmp.original.state.undetermined === true) {
  5339. if(o[tmp.id] === undefined && tmp.id !== $.jstree.root) {
  5340. o[tmp.id] = true;
  5341. p.push(tmp.id);
  5342. }
  5343. for(k = 0, l = tmp.parents.length; k < l; k++) {
  5344. if(o[tmp.parents[k]] === undefined && tmp.parents[k] !== $.jstree.root) {
  5345. o[tmp.parents[k]] = true;
  5346. p.push(tmp.parents[k]);
  5347. }
  5348. }
  5349. }
  5350. }
  5351. else {
  5352. for(i = 0, j = tmp.children_d.length; i < j; i++) {
  5353. tmp2 = m[tmp.children_d[i]];
  5354. if(!tmp2.state.loaded && tmp2.original && tmp2.original.state && tmp2.original.state.undetermined && tmp2.original.state.undetermined === true) {
  5355. if(o[tmp2.id] === undefined && tmp2.id !== $.jstree.root) {
  5356. o[tmp2.id] = true;
  5357. p.push(tmp2.id);
  5358. }
  5359. for(k = 0, l = tmp2.parents.length; k < l; k++) {
  5360. if(o[tmp2.parents[k]] === undefined && tmp2.parents[k] !== $.jstree.root) {
  5361. o[tmp2.parents[k]] = true;
  5362. p.push(tmp2.parents[k]);
  5363. }
  5364. }
  5365. }
  5366. }
  5367. }
  5368. });
  5369. for (i = 0, j = p.length; i < j; i++) {
  5370. if(!m[p[i]].state[ t ? 'selected' : 'checked' ]) {
  5371. r.push(full ? m[p[i]] : p[i]);
  5372. }
  5373. }
  5374. return r;
  5375. };
  5376. /**
  5377. * set the undetermined state where and if necessary. Used internally.
  5378. * @private
  5379. * @name _undetermined()
  5380. * @plugin checkbox
  5381. */
  5382. this._undetermined = function () {
  5383. if(this.element === null) { return; }
  5384. var p = this.get_undetermined(false), i, j, s;
  5385. this.element.find('.jstree-undetermined').removeClass('jstree-undetermined');
  5386. for (i = 0, j = p.length; i < j; i++) {
  5387. s = this.get_node(p[i], true);
  5388. if(s && s.length) {
  5389. s.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-undetermined');
  5390. }
  5391. }
  5392. };
  5393. this.redraw_node = function(obj, deep, is_callback, force_render) {
  5394. obj = parent.redraw_node.apply(this, arguments);
  5395. if(obj) {
  5396. var i, j, tmp = null, icon = null;
  5397. for(i = 0, j = obj.childNodes.length; i < j; i++) {
  5398. if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
  5399. tmp = obj.childNodes[i];
  5400. break;
  5401. }
  5402. }
  5403. if(tmp) {
  5404. if(!this.settings.checkbox.tie_selection && this._model.data[obj.id].state.checked) { tmp.className += ' jstree-checked'; }
  5405. icon = _i.cloneNode(false);
  5406. if(this._model.data[obj.id].state.checkbox_disabled) { icon.className += ' jstree-checkbox-disabled'; }
  5407. tmp.insertBefore(icon, tmp.childNodes[0]);
  5408. }
  5409. }
  5410. if(!is_callback && this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
  5411. if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
  5412. this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
  5413. }
  5414. return obj;
  5415. };
  5416. /**
  5417. * show the node checkbox icons
  5418. * @name show_checkboxes()
  5419. * @plugin checkbox
  5420. */
  5421. this.show_checkboxes = function () { this._data.core.themes.checkboxes = true; this.get_container_ul().removeClass("jstree-no-checkboxes"); };
  5422. /**
  5423. * hide the node checkbox icons
  5424. * @name hide_checkboxes()
  5425. * @plugin checkbox
  5426. */
  5427. this.hide_checkboxes = function () { this._data.core.themes.checkboxes = false; this.get_container_ul().addClass("jstree-no-checkboxes"); };
  5428. /**
  5429. * toggle the node icons
  5430. * @name toggle_checkboxes()
  5431. * @plugin checkbox
  5432. */
  5433. this.toggle_checkboxes = function () { if(this._data.core.themes.checkboxes) { this.hide_checkboxes(); } else { this.show_checkboxes(); } };
  5434. /**
  5435. * checks if a node is in an undetermined state
  5436. * @name is_undetermined(obj)
  5437. * @param {mixed} obj
  5438. * @return {Boolean}
  5439. */
  5440. this.is_undetermined = function (obj) {
  5441. obj = this.get_node(obj);
  5442. 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;
  5443. if(!obj || obj.state[ t ? 'selected' : 'checked' ] === true || s.indexOf('undetermined') === -1 || (s.indexOf('down') === -1 && s.indexOf('up') === -1)) {
  5444. return false;
  5445. }
  5446. if(!obj.state.loaded && obj.original.state.undetermined === true) {
  5447. return true;
  5448. }
  5449. for(i = 0, j = obj.children_d.length; i < j; i++) {
  5450. if($.inArray(obj.children_d[i], d) !== -1 || (!m[obj.children_d[i]].state.loaded && m[obj.children_d[i]].original.state.undetermined)) {
  5451. return true;
  5452. }
  5453. }
  5454. return false;
  5455. };
  5456. /**
  5457. * disable a node's checkbox
  5458. * @name disable_checkbox(obj)
  5459. * @param {mixed} obj an array can be used too
  5460. * @trigger disable_checkbox.jstree
  5461. * @plugin checkbox
  5462. */
  5463. this.disable_checkbox = function (obj) {
  5464. var t1, t2, dom;
  5465. if($.isArray(obj)) {
  5466. obj = obj.slice();
  5467. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  5468. this.disable_checkbox(obj[t1]);
  5469. }
  5470. return true;
  5471. }
  5472. obj = this.get_node(obj);
  5473. if(!obj || obj.id === $.jstree.root) {
  5474. return false;
  5475. }
  5476. dom = this.get_node(obj, true);
  5477. if(!obj.state.checkbox_disabled) {
  5478. obj.state.checkbox_disabled = true;
  5479. if(dom && dom.length) {
  5480. dom.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-checkbox-disabled');
  5481. }
  5482. /**
  5483. * triggered when an node's checkbox is disabled
  5484. * @event
  5485. * @name disable_checkbox.jstree
  5486. * @param {Object} node
  5487. * @plugin checkbox
  5488. */
  5489. this.trigger('disable_checkbox', { 'node' : obj });
  5490. }
  5491. };
  5492. /**
  5493. * enable a node's checkbox
  5494. * @name enable_checkbox(obj)
  5495. * @param {mixed} obj an array can be used too
  5496. * @trigger enable_checkbox.jstree
  5497. * @plugin checkbox
  5498. */
  5499. this.enable_checkbox = function (obj) {
  5500. var t1, t2, dom;
  5501. if($.isArray(obj)) {
  5502. obj = obj.slice();
  5503. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  5504. this.enable_checkbox(obj[t1]);
  5505. }
  5506. return true;
  5507. }
  5508. obj = this.get_node(obj);
  5509. if(!obj || obj.id === $.jstree.root) {
  5510. return false;
  5511. }
  5512. dom = this.get_node(obj, true);
  5513. if(obj.state.checkbox_disabled) {
  5514. obj.state.checkbox_disabled = false;
  5515. if(dom && dom.length) {
  5516. dom.children('.jstree-anchor').children('.jstree-checkbox').removeClass('jstree-checkbox-disabled');
  5517. }
  5518. /**
  5519. * triggered when an node's checkbox is enabled
  5520. * @event
  5521. * @name enable_checkbox.jstree
  5522. * @param {Object} node
  5523. * @plugin checkbox
  5524. */
  5525. this.trigger('enable_checkbox', { 'node' : obj });
  5526. }
  5527. };
  5528. this.activate_node = function (obj, e) {
  5529. if($(e.target).hasClass('jstree-checkbox-disabled')) {
  5530. return false;
  5531. }
  5532. if(this.settings.checkbox.tie_selection && (this.settings.checkbox.whole_node || $(e.target).hasClass('jstree-checkbox'))) {
  5533. e.ctrlKey = true;
  5534. }
  5535. if(this.settings.checkbox.tie_selection || (!this.settings.checkbox.whole_node && !$(e.target).hasClass('jstree-checkbox'))) {
  5536. return parent.activate_node.call(this, obj, e);
  5537. }
  5538. if(this.is_disabled(obj)) {
  5539. return false;
  5540. }
  5541. if(this.is_checked(obj)) {
  5542. this.uncheck_node(obj, e);
  5543. }
  5544. else {
  5545. this.check_node(obj, e);
  5546. }
  5547. this.trigger('activate_node', { 'node' : this.get_node(obj) });
  5548. };
  5549. /**
  5550. * Cascades checked state to a node and all its descendants. This function does NOT affect hidden and disabled nodes (or their descendants).
  5551. * However if these unaffected nodes are already selected their ids will be included in the returned array.
  5552. * @private
  5553. * @param {string} id the node ID
  5554. * @param {bool} checkedState should the nodes be checked or not
  5555. * @returns {Array} Array of all node id's (in this tree branch) that are checked.
  5556. */
  5557. this._cascade_new_checked_state = function (id, checkedState) {
  5558. var self = this;
  5559. var t = this.settings.checkbox.tie_selection;
  5560. var node = this._model.data[id];
  5561. var selectedNodeIds = [];
  5562. var selectedChildrenIds = [], i, j, selectedChildIds;
  5563. if (
  5564. (this.settings.checkbox.cascade_to_disabled || !node.state.disabled) &&
  5565. (this.settings.checkbox.cascade_to_hidden || !node.state.hidden)
  5566. ) {
  5567. //First try and check/uncheck the children
  5568. if (node.children) {
  5569. for (i = 0, j = node.children.length; i < j; i++) {
  5570. var childId = node.children[i];
  5571. selectedChildIds = self._cascade_new_checked_state(childId, checkedState);
  5572. selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
  5573. if (selectedChildIds.indexOf(childId) > -1) {
  5574. selectedChildrenIds.push(childId);
  5575. }
  5576. }
  5577. }
  5578. var dom = self.get_node(node, true);
  5579. //A node's state is undetermined if some but not all of it's children are checked/selected .
  5580. var undetermined = selectedChildrenIds.length > 0 && selectedChildrenIds.length < node.children.length;
  5581. if(node.original && node.original.state && node.original.state.undetermined) {
  5582. node.original.state.undetermined = undetermined;
  5583. }
  5584. //If a node is undetermined then remove selected class
  5585. if (undetermined) {
  5586. node.state[ t ? 'selected' : 'checked' ] = false;
  5587. dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
  5588. }
  5589. //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),
  5590. //check the node and style it correctly.
  5591. else if (checkedState && selectedChildrenIds.length === node.children.length) {
  5592. node.state[ t ? 'selected' : 'checked' ] = checkedState;
  5593. selectedNodeIds.push(node.id);
  5594. dom.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
  5595. }
  5596. else {
  5597. node.state[ t ? 'selected' : 'checked' ] = false;
  5598. dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
  5599. }
  5600. }
  5601. else {
  5602. selectedChildIds = this.get_checked_descendants(id);
  5603. if (node.state[ t ? 'selected' : 'checked' ]) {
  5604. selectedChildIds.push(node.id);
  5605. }
  5606. selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
  5607. }
  5608. return selectedNodeIds;
  5609. };
  5610. /**
  5611. * Gets ids of nodes selected in branch (of tree) specified by id (does not include the node specified by id)
  5612. * @name get_checked_descendants(obj)
  5613. * @param {string} id the node ID
  5614. * @return {Array} array of IDs
  5615. * @plugin checkbox
  5616. */
  5617. this.get_checked_descendants = function (id) {
  5618. var self = this;
  5619. var t = self.settings.checkbox.tie_selection;
  5620. var node = self._model.data[id];
  5621. return $.vakata.array_filter(node.children_d, function(_id) {
  5622. return self._model.data[_id].state[ t ? 'selected' : 'checked' ];
  5623. });
  5624. };
  5625. /**
  5626. * check a node (only if tie_selection in checkbox settings is false, otherwise select_node will be called internally)
  5627. * @name check_node(obj)
  5628. * @param {mixed} obj an array can be used to check multiple nodes
  5629. * @trigger check_node.jstree
  5630. * @plugin checkbox
  5631. */
  5632. this.check_node = function (obj, e) {
  5633. if(this.settings.checkbox.tie_selection) { return this.select_node(obj, false, true, e); }
  5634. var dom, t1, t2, th;
  5635. if($.isArray(obj)) {
  5636. obj = obj.slice();
  5637. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  5638. this.check_node(obj[t1], e);
  5639. }
  5640. return true;
  5641. }
  5642. obj = this.get_node(obj);
  5643. if(!obj || obj.id === $.jstree.root) {
  5644. return false;
  5645. }
  5646. dom = this.get_node(obj, true);
  5647. if(!obj.state.checked) {
  5648. obj.state.checked = true;
  5649. this._data.checkbox.selected.push(obj.id);
  5650. if(dom && dom.length) {
  5651. dom.children('.jstree-anchor').addClass('jstree-checked');
  5652. }
  5653. /**
  5654. * triggered when an node is checked (only if tie_selection in checkbox settings is false)
  5655. * @event
  5656. * @name check_node.jstree
  5657. * @param {Object} node
  5658. * @param {Array} selected the current selection
  5659. * @param {Object} event the event (if any) that triggered this check_node
  5660. * @plugin checkbox
  5661. */
  5662. this.trigger('check_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
  5663. }
  5664. };
  5665. /**
  5666. * uncheck a node (only if tie_selection in checkbox settings is false, otherwise deselect_node will be called internally)
  5667. * @name uncheck_node(obj)
  5668. * @param {mixed} obj an array can be used to uncheck multiple nodes
  5669. * @trigger uncheck_node.jstree
  5670. * @plugin checkbox
  5671. */
  5672. this.uncheck_node = function (obj, e) {
  5673. if(this.settings.checkbox.tie_selection) { return this.deselect_node(obj, false, e); }
  5674. var t1, t2, dom;
  5675. if($.isArray(obj)) {
  5676. obj = obj.slice();
  5677. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  5678. this.uncheck_node(obj[t1], e);
  5679. }
  5680. return true;
  5681. }
  5682. obj = this.get_node(obj);
  5683. if(!obj || obj.id === $.jstree.root) {
  5684. return false;
  5685. }
  5686. dom = this.get_node(obj, true);
  5687. if(obj.state.checked) {
  5688. obj.state.checked = false;
  5689. this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, obj.id);
  5690. if(dom.length) {
  5691. dom.children('.jstree-anchor').removeClass('jstree-checked');
  5692. }
  5693. /**
  5694. * triggered when an node is unchecked (only if tie_selection in checkbox settings is false)
  5695. * @event
  5696. * @name uncheck_node.jstree
  5697. * @param {Object} node
  5698. * @param {Array} selected the current selection
  5699. * @param {Object} event the event (if any) that triggered this uncheck_node
  5700. * @plugin checkbox
  5701. */
  5702. this.trigger('uncheck_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
  5703. }
  5704. };
  5705. /**
  5706. * checks all nodes in the tree (only if tie_selection in checkbox settings is false, otherwise select_all will be called internally)
  5707. * @name check_all()
  5708. * @trigger check_all.jstree, changed.jstree
  5709. * @plugin checkbox
  5710. */
  5711. this.check_all = function () {
  5712. if(this.settings.checkbox.tie_selection) { return this.select_all(); }
  5713. var tmp = this._data.checkbox.selected.concat([]), i, j;
  5714. this._data.checkbox.selected = this._model.data[$.jstree.root].children_d.concat();
  5715. for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
  5716. if(this._model.data[this._data.checkbox.selected[i]]) {
  5717. this._model.data[this._data.checkbox.selected[i]].state.checked = true;
  5718. }
  5719. }
  5720. this.redraw(true);
  5721. /**
  5722. * triggered when all nodes are checked (only if tie_selection in checkbox settings is false)
  5723. * @event
  5724. * @name check_all.jstree
  5725. * @param {Array} selected the current selection
  5726. * @plugin checkbox
  5727. */
  5728. this.trigger('check_all', { 'selected' : this._data.checkbox.selected });
  5729. };
  5730. /**
  5731. * uncheck all checked nodes (only if tie_selection in checkbox settings is false, otherwise deselect_all will be called internally)
  5732. * @name uncheck_all()
  5733. * @trigger uncheck_all.jstree
  5734. * @plugin checkbox
  5735. */
  5736. this.uncheck_all = function () {
  5737. if(this.settings.checkbox.tie_selection) { return this.deselect_all(); }
  5738. var tmp = this._data.checkbox.selected.concat([]), i, j;
  5739. for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
  5740. if(this._model.data[this._data.checkbox.selected[i]]) {
  5741. this._model.data[this._data.checkbox.selected[i]].state.checked = false;
  5742. }
  5743. }
  5744. this._data.checkbox.selected = [];
  5745. this.element.find('.jstree-checked').removeClass('jstree-checked');
  5746. /**
  5747. * triggered when all nodes are unchecked (only if tie_selection in checkbox settings is false)
  5748. * @event
  5749. * @name uncheck_all.jstree
  5750. * @param {Object} node the previous selection
  5751. * @param {Array} selected the current selection
  5752. * @plugin checkbox
  5753. */
  5754. this.trigger('uncheck_all', { 'selected' : this._data.checkbox.selected, 'node' : tmp });
  5755. };
  5756. /**
  5757. * checks if a node is checked (if tie_selection is on in the settings this function will return the same as is_selected)
  5758. * @name is_checked(obj)
  5759. * @param {mixed} obj
  5760. * @return {Boolean}
  5761. * @plugin checkbox
  5762. */
  5763. this.is_checked = function (obj) {
  5764. if(this.settings.checkbox.tie_selection) { return this.is_selected(obj); }
  5765. obj = this.get_node(obj);
  5766. if(!obj || obj.id === $.jstree.root) { return false; }
  5767. return obj.state.checked;
  5768. };
  5769. /**
  5770. * get an array of all checked nodes (if tie_selection is on in the settings this function will return the same as get_selected)
  5771. * @name get_checked([full])
  5772. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  5773. * @return {Array}
  5774. * @plugin checkbox
  5775. */
  5776. this.get_checked = function (full) {
  5777. if(this.settings.checkbox.tie_selection) { return this.get_selected(full); }
  5778. return full ? $.map(this._data.checkbox.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.checkbox.selected.slice();
  5779. };
  5780. /**
  5781. * 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)
  5782. * @name get_top_checked([full])
  5783. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  5784. * @return {Array}
  5785. * @plugin checkbox
  5786. */
  5787. this.get_top_checked = function (full) {
  5788. if(this.settings.checkbox.tie_selection) { return this.get_top_selected(full); }
  5789. var tmp = this.get_checked(true),
  5790. obj = {}, i, j, k, l;
  5791. for(i = 0, j = tmp.length; i < j; i++) {
  5792. obj[tmp[i].id] = tmp[i];
  5793. }
  5794. for(i = 0, j = tmp.length; i < j; i++) {
  5795. for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
  5796. if(obj[tmp[i].children_d[k]]) {
  5797. delete obj[tmp[i].children_d[k]];
  5798. }
  5799. }
  5800. }
  5801. tmp = [];
  5802. for(i in obj) {
  5803. if(obj.hasOwnProperty(i)) {
  5804. tmp.push(i);
  5805. }
  5806. }
  5807. return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
  5808. };
  5809. /**
  5810. * 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)
  5811. * @name get_bottom_checked([full])
  5812. * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
  5813. * @return {Array}
  5814. * @plugin checkbox
  5815. */
  5816. this.get_bottom_checked = function (full) {
  5817. if(this.settings.checkbox.tie_selection) { return this.get_bottom_selected(full); }
  5818. var tmp = this.get_checked(true),
  5819. obj = [], i, j;
  5820. for(i = 0, j = tmp.length; i < j; i++) {
  5821. if(!tmp[i].children.length) {
  5822. obj.push(tmp[i].id);
  5823. }
  5824. }
  5825. return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
  5826. };
  5827. this.load_node = function (obj, callback) {
  5828. var k, l, i, j, c, tmp;
  5829. if(!$.isArray(obj) && !this.settings.checkbox.tie_selection) {
  5830. tmp = this.get_node(obj);
  5831. if(tmp && tmp.state.loaded) {
  5832. for(k = 0, l = tmp.children_d.length; k < l; k++) {
  5833. if(this._model.data[tmp.children_d[k]].state.checked) {
  5834. c = true;
  5835. this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, tmp.children_d[k]);
  5836. }
  5837. }
  5838. }
  5839. }
  5840. return parent.load_node.apply(this, arguments);
  5841. };
  5842. this.get_state = function () {
  5843. var state = parent.get_state.apply(this, arguments);
  5844. if(this.settings.checkbox.tie_selection) { return state; }
  5845. state.checkbox = this._data.checkbox.selected.slice();
  5846. return state;
  5847. };
  5848. this.set_state = function (state, callback) {
  5849. var res = parent.set_state.apply(this, arguments);
  5850. if(res && state.checkbox) {
  5851. if(!this.settings.checkbox.tie_selection) {
  5852. this.uncheck_all();
  5853. var _this = this;
  5854. $.each(state.checkbox, function (i, v) {
  5855. _this.check_node(v);
  5856. });
  5857. }
  5858. delete state.checkbox;
  5859. this.set_state(state, callback);
  5860. return false;
  5861. }
  5862. return res;
  5863. };
  5864. this.refresh = function (skip_loading, forget_state) {
  5865. if(this.settings.checkbox.tie_selection) {
  5866. this._data.checkbox.selected = [];
  5867. }
  5868. return parent.refresh.apply(this, arguments);
  5869. };
  5870. };
  5871. // include the checkbox plugin by default
  5872. // $.jstree.defaults.plugins.push("checkbox");
  5873. /**
  5874. * ### Conditionalselect plugin
  5875. *
  5876. * This plugin allows defining a callback to allow or deny node selection by user input (activate node method).
  5877. */
  5878. /**
  5879. * 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`.
  5880. * @name $.jstree.defaults.checkbox.visible
  5881. * @plugin checkbox
  5882. */
  5883. $.jstree.defaults.conditionalselect = function () { return true; };
  5884. $.jstree.plugins.conditionalselect = function (options, parent) {
  5885. // own function
  5886. this.activate_node = function (obj, e) {
  5887. if(this.settings.conditionalselect.call(this, this.get_node(obj), e)) {
  5888. return parent.activate_node.call(this, obj, e);
  5889. }
  5890. };
  5891. };
  5892. /**
  5893. * ### Contextmenu plugin
  5894. *
  5895. * Shows a context menu when a node is right-clicked.
  5896. */
  5897. /**
  5898. * stores all defaults for the contextmenu plugin
  5899. * @name $.jstree.defaults.contextmenu
  5900. * @plugin contextmenu
  5901. */
  5902. $.jstree.defaults.contextmenu = {
  5903. /**
  5904. * a boolean indicating if the node should be selected when the context menu is invoked on it. Defaults to `true`.
  5905. * @name $.jstree.defaults.contextmenu.select_node
  5906. * @plugin contextmenu
  5907. */
  5908. select_node : true,
  5909. /**
  5910. * a boolean indicating if the menu should be shown aligned with the node. Defaults to `true`, otherwise the mouse coordinates are used.
  5911. * @name $.jstree.defaults.contextmenu.show_at_node
  5912. * @plugin contextmenu
  5913. */
  5914. show_at_node : true,
  5915. /**
  5916. * 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).
  5917. *
  5918. * 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.
  5919. *
  5920. * * `separator_before` - a boolean indicating if there should be a separator before this item
  5921. * * `separator_after` - a boolean indicating if there should be a separator after this item
  5922. * * `_disabled` - a boolean indicating if this action should be disabled
  5923. * * `label` - a string - the name of the action (could be a function returning a string)
  5924. * * `title` - a string - an optional tooltip for the item
  5925. * * `action` - a function to be executed if this item is chosen, the function will receive
  5926. * * `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
  5927. * * `shortcut` - keyCode which will trigger the action if the menu is open (for example `113` for rename, which equals F2)
  5928. * * `shortcut_label` - shortcut label (like for example `F2` for rename)
  5929. * * `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
  5930. *
  5931. * @name $.jstree.defaults.contextmenu.items
  5932. * @plugin contextmenu
  5933. */
  5934. items : function (o, cb) { // Could be an object directly
  5935. return {
  5936. "create" : {
  5937. "separator_before" : false,
  5938. "separator_after" : true,
  5939. "_disabled" : false, //(this.check("create_node", data.reference, {}, "last")),
  5940. "label" : "Create",
  5941. "action" : function (data) {
  5942. var inst = $.jstree.reference(data.reference),
  5943. obj = inst.get_node(data.reference);
  5944. inst.create_node(obj, {}, "last", function (new_node) {
  5945. try {
  5946. inst.edit(new_node);
  5947. } catch (ex) {
  5948. setTimeout(function () { inst.edit(new_node); },0);
  5949. }
  5950. });
  5951. }
  5952. },
  5953. "rename" : {
  5954. "separator_before" : false,
  5955. "separator_after" : false,
  5956. "_disabled" : false, //(this.check("rename_node", data.reference, this.get_parent(data.reference), "")),
  5957. "label" : "Rename",
  5958. /*!
  5959. "shortcut" : 113,
  5960. "shortcut_label" : 'F2',
  5961. "icon" : "glyphicon glyphicon-leaf",
  5962. */
  5963. "action" : function (data) {
  5964. var inst = $.jstree.reference(data.reference),
  5965. obj = inst.get_node(data.reference);
  5966. inst.edit(obj);
  5967. }
  5968. },
  5969. "remove" : {
  5970. "separator_before" : false,
  5971. "icon" : false,
  5972. "separator_after" : false,
  5973. "_disabled" : false, //(this.check("delete_node", data.reference, this.get_parent(data.reference), "")),
  5974. "label" : "Delete",
  5975. "action" : function (data) {
  5976. var inst = $.jstree.reference(data.reference),
  5977. obj = inst.get_node(data.reference);
  5978. if(inst.is_selected(obj)) {
  5979. inst.delete_node(inst.get_selected());
  5980. }
  5981. else {
  5982. inst.delete_node(obj);
  5983. }
  5984. }
  5985. },
  5986. "ccp" : {
  5987. "separator_before" : true,
  5988. "icon" : false,
  5989. "separator_after" : false,
  5990. "label" : "Edit",
  5991. "action" : false,
  5992. "submenu" : {
  5993. "cut" : {
  5994. "separator_before" : false,
  5995. "separator_after" : false,
  5996. "label" : "Cut",
  5997. "action" : function (data) {
  5998. var inst = $.jstree.reference(data.reference),
  5999. obj = inst.get_node(data.reference);
  6000. if(inst.is_selected(obj)) {
  6001. inst.cut(inst.get_top_selected());
  6002. }
  6003. else {
  6004. inst.cut(obj);
  6005. }
  6006. }
  6007. },
  6008. "copy" : {
  6009. "separator_before" : false,
  6010. "icon" : false,
  6011. "separator_after" : false,
  6012. "label" : "Copy",
  6013. "action" : function (data) {
  6014. var inst = $.jstree.reference(data.reference),
  6015. obj = inst.get_node(data.reference);
  6016. if(inst.is_selected(obj)) {
  6017. inst.copy(inst.get_top_selected());
  6018. }
  6019. else {
  6020. inst.copy(obj);
  6021. }
  6022. }
  6023. },
  6024. "paste" : {
  6025. "separator_before" : false,
  6026. "icon" : false,
  6027. "_disabled" : function (data) {
  6028. return !$.jstree.reference(data.reference).can_paste();
  6029. },
  6030. "separator_after" : false,
  6031. "label" : "Paste",
  6032. "action" : function (data) {
  6033. var inst = $.jstree.reference(data.reference),
  6034. obj = inst.get_node(data.reference);
  6035. inst.paste(obj);
  6036. }
  6037. }
  6038. }
  6039. }
  6040. };
  6041. }
  6042. };
  6043. $.jstree.plugins.contextmenu = function (options, parent) {
  6044. this.bind = function () {
  6045. parent.bind.call(this);
  6046. var last_ts = 0, cto = null, ex, ey;
  6047. this.element
  6048. .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
  6049. this.get_container_ul().addClass('jstree-contextmenu');
  6050. }, this))
  6051. .on("contextmenu.jstree", ".jstree-anchor", $.proxy(function (e, data) {
  6052. if (e.target.tagName.toLowerCase() === 'input') {
  6053. return;
  6054. }
  6055. e.preventDefault();
  6056. last_ts = e.ctrlKey ? +new Date() : 0;
  6057. if(data || cto) {
  6058. last_ts = (+new Date()) + 10000;
  6059. }
  6060. if(cto) {
  6061. clearTimeout(cto);
  6062. }
  6063. if(!this.is_loading(e.currentTarget)) {
  6064. this.show_contextmenu(e.currentTarget, e.pageX, e.pageY, e);
  6065. }
  6066. }, this))
  6067. .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
  6068. if(this._data.contextmenu.visible && (!last_ts || (+new Date()) - last_ts > 250)) { // work around safari & macOS ctrl+click
  6069. $.vakata.context.hide();
  6070. }
  6071. last_ts = 0;
  6072. }, this))
  6073. .on("touchstart.jstree", ".jstree-anchor", function (e) {
  6074. if(!e.originalEvent || !e.originalEvent.changedTouches || !e.originalEvent.changedTouches[0]) {
  6075. return;
  6076. }
  6077. ex = e.originalEvent.changedTouches[0].clientX;
  6078. ey = e.originalEvent.changedTouches[0].clientY;
  6079. cto = setTimeout(function () {
  6080. $(e.currentTarget).trigger('contextmenu', true);
  6081. }, 750);
  6082. })
  6083. .on('touchmove.vakata.jstree', function (e) {
  6084. 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)) {
  6085. clearTimeout(cto);
  6086. $.vakata.context.hide();
  6087. }
  6088. })
  6089. .on('touchend.vakata.jstree', function (e) {
  6090. if(cto) {
  6091. clearTimeout(cto);
  6092. }
  6093. });
  6094. /*!
  6095. if(!('oncontextmenu' in document.body) && ('ontouchstart' in document.body)) {
  6096. var el = null, tm = null;
  6097. this.element
  6098. .on("touchstart", ".jstree-anchor", function (e) {
  6099. el = e.currentTarget;
  6100. tm = +new Date();
  6101. $(document).one("touchend", function (e) {
  6102. e.target = document.elementFromPoint(e.originalEvent.targetTouches[0].pageX - window.pageXOffset, e.originalEvent.targetTouches[0].pageY - window.pageYOffset);
  6103. e.currentTarget = e.target;
  6104. tm = ((+(new Date())) - tm);
  6105. if(e.target === el && tm > 600 && tm < 1000) {
  6106. e.preventDefault();
  6107. $(el).trigger('contextmenu', e);
  6108. }
  6109. el = null;
  6110. tm = null;
  6111. });
  6112. });
  6113. }
  6114. */
  6115. $(document).on("context_hide.vakata.jstree", $.proxy(function (e, data) {
  6116. this._data.contextmenu.visible = false;
  6117. $(data.reference).removeClass('jstree-context');
  6118. }, this));
  6119. };
  6120. this.teardown = function () {
  6121. if(this._data.contextmenu.visible) {
  6122. $.vakata.context.hide();
  6123. }
  6124. parent.teardown.call(this);
  6125. };
  6126. /**
  6127. * prepare and show the context menu for a node
  6128. * @name show_contextmenu(obj [, x, y])
  6129. * @param {mixed} obj the node
  6130. * @param {Number} x the x-coordinate relative to the document to show the menu at
  6131. * @param {Number} y the y-coordinate relative to the document to show the menu at
  6132. * @param {Object} e the event if available that triggered the contextmenu
  6133. * @plugin contextmenu
  6134. * @trigger show_contextmenu.jstree
  6135. */
  6136. this.show_contextmenu = function (obj, x, y, e) {
  6137. obj = this.get_node(obj);
  6138. if(!obj || obj.id === $.jstree.root) { return false; }
  6139. var s = this.settings.contextmenu,
  6140. d = this.get_node(obj, true),
  6141. a = d.children(".jstree-anchor"),
  6142. o = false,
  6143. i = false;
  6144. if(s.show_at_node || x === undefined || y === undefined) {
  6145. o = a.offset();
  6146. x = o.left;
  6147. y = o.top + this._data.core.li_height;
  6148. }
  6149. if(this.settings.contextmenu.select_node && !this.is_selected(obj)) {
  6150. this.activate_node(obj, e);
  6151. }
  6152. i = s.items;
  6153. if($.isFunction(i)) {
  6154. i = i.call(this, obj, $.proxy(function (i) {
  6155. this._show_contextmenu(obj, x, y, i);
  6156. }, this));
  6157. }
  6158. if($.isPlainObject(i)) {
  6159. this._show_contextmenu(obj, x, y, i);
  6160. }
  6161. };
  6162. /**
  6163. * show the prepared context menu for a node
  6164. * @name _show_contextmenu(obj, x, y, i)
  6165. * @param {mixed} obj the node
  6166. * @param {Number} x the x-coordinate relative to the document to show the menu at
  6167. * @param {Number} y the y-coordinate relative to the document to show the menu at
  6168. * @param {Number} i the object of items to show
  6169. * @plugin contextmenu
  6170. * @trigger show_contextmenu.jstree
  6171. * @private
  6172. */
  6173. this._show_contextmenu = function (obj, x, y, i) {
  6174. var d = this.get_node(obj, true),
  6175. a = d.children(".jstree-anchor");
  6176. $(document).one("context_show.vakata.jstree", $.proxy(function (e, data) {
  6177. var cls = 'jstree-contextmenu jstree-' + this.get_theme() + '-contextmenu';
  6178. $(data.element).addClass(cls);
  6179. a.addClass('jstree-context');
  6180. }, this));
  6181. this._data.contextmenu.visible = true;
  6182. $.vakata.context.show(a, { 'x' : x, 'y' : y }, i);
  6183. /**
  6184. * triggered when the contextmenu is shown for a node
  6185. * @event
  6186. * @name show_contextmenu.jstree
  6187. * @param {Object} node the node
  6188. * @param {Number} x the x-coordinate of the menu relative to the document
  6189. * @param {Number} y the y-coordinate of the menu relative to the document
  6190. * @plugin contextmenu
  6191. */
  6192. this.trigger('show_contextmenu', { "node" : obj, "x" : x, "y" : y });
  6193. };
  6194. };
  6195. // contextmenu helper
  6196. (function ($) {
  6197. var right_to_left = false,
  6198. vakata_context = {
  6199. element : false,
  6200. reference : false,
  6201. position_x : 0,
  6202. position_y : 0,
  6203. items : [],
  6204. html : "",
  6205. is_visible : false
  6206. };
  6207. $.vakata.context = {
  6208. settings : {
  6209. hide_onmouseleave : 0,
  6210. icons : true
  6211. },
  6212. _trigger : function (event_name) {
  6213. $(document).triggerHandler("context_" + event_name + ".vakata", {
  6214. "reference" : vakata_context.reference,
  6215. "element" : vakata_context.element,
  6216. "position" : {
  6217. "x" : vakata_context.position_x,
  6218. "y" : vakata_context.position_y
  6219. }
  6220. });
  6221. },
  6222. _execute : function (i) {
  6223. i = vakata_context.items[i];
  6224. 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, {
  6225. "item" : i,
  6226. "reference" : vakata_context.reference,
  6227. "element" : vakata_context.element,
  6228. "position" : {
  6229. "x" : vakata_context.position_x,
  6230. "y" : vakata_context.position_y
  6231. }
  6232. }) : false;
  6233. },
  6234. _parse : function (o, is_callback) {
  6235. if(!o) { return false; }
  6236. if(!is_callback) {
  6237. vakata_context.html = "";
  6238. vakata_context.items = [];
  6239. }
  6240. var str = "",
  6241. sep = false,
  6242. tmp;
  6243. if(is_callback) { str += "<"+"ul>"; }
  6244. $.each(o, function (i, val) {
  6245. if(!val) { return true; }
  6246. vakata_context.items.push(val);
  6247. if(!sep && val.separator_before) {
  6248. str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
  6249. }
  6250. sep = false;
  6251. 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+"' ":'')+">";
  6252. str += "<"+"a href='#' rel='" + (vakata_context.items.length - 1) + "' " + (val.title ? "title='" + val.title + "'" : "") + ">";
  6253. if($.vakata.context.settings.icons) {
  6254. str += "<"+"i ";
  6255. if(val.icon) {
  6256. if(val.icon.indexOf("/") !== -1 || val.icon.indexOf(".") !== -1) { str += " style='background:url(\"" + val.icon + "\") center center no-repeat' "; }
  6257. else { str += " class='" + val.icon + "' "; }
  6258. }
  6259. str += "><"+"/i><"+"span class='vakata-contextmenu-sep'>&#160;<"+"/span>";
  6260. }
  6261. 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>";
  6262. if(val.submenu) {
  6263. tmp = $.vakata.context._parse(val.submenu, true);
  6264. if(tmp) { str += tmp; }
  6265. }
  6266. str += "<"+"/li>";
  6267. if(val.separator_after) {
  6268. str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
  6269. sep = true;
  6270. }
  6271. });
  6272. str = str.replace(/<li class\='vakata-context-separator'\><\/li\>$/,"");
  6273. if(is_callback) { str += "</ul>"; }
  6274. /**
  6275. * triggered on the document when the contextmenu is parsed (HTML is built)
  6276. * @event
  6277. * @plugin contextmenu
  6278. * @name context_parse.vakata
  6279. * @param {jQuery} reference the element that was right clicked
  6280. * @param {jQuery} element the DOM element of the menu itself
  6281. * @param {Object} position the x & y coordinates of the menu
  6282. */
  6283. if(!is_callback) { vakata_context.html = str; $.vakata.context._trigger("parse"); }
  6284. return str.length > 10 ? str : false;
  6285. },
  6286. _show_submenu : function (o) {
  6287. o = $(o);
  6288. if(!o.length || !o.children("ul").length) { return; }
  6289. var e = o.children("ul"),
  6290. xl = o.offset().left,
  6291. x = xl + o.outerWidth(),
  6292. y = o.offset().top,
  6293. w = e.width(),
  6294. h = e.height(),
  6295. dw = $(window).width() + $(window).scrollLeft(),
  6296. dh = $(window).height() + $(window).scrollTop();
  6297. // може да се спести е една проверка - дали няма някой от класовете вече нагоре
  6298. if(right_to_left) {
  6299. o[x - (w + 10 + o.outerWidth()) < 0 ? "addClass" : "removeClass"]("vakata-context-left");
  6300. }
  6301. else {
  6302. o[x + w > dw && xl > dw - x ? "addClass" : "removeClass"]("vakata-context-right");
  6303. }
  6304. if(y + h + 10 > dh) {
  6305. e.css("bottom","-1px");
  6306. }
  6307. //if does not fit - stick it to the side
  6308. if (o.hasClass('vakata-context-right')) {
  6309. if (xl < w) {
  6310. e.css("margin-right", xl - w);
  6311. }
  6312. } else {
  6313. if (dw - x < w) {
  6314. e.css("margin-left", dw - x - w);
  6315. }
  6316. }
  6317. e.show();
  6318. },
  6319. show : function (reference, position, data) {
  6320. var o, e, x, y, w, h, dw, dh, cond = true;
  6321. if(vakata_context.element && vakata_context.element.length) {
  6322. vakata_context.element.width('');
  6323. }
  6324. switch(cond) {
  6325. case (!position && !reference):
  6326. return false;
  6327. case (!!position && !!reference):
  6328. vakata_context.reference = reference;
  6329. vakata_context.position_x = position.x;
  6330. vakata_context.position_y = position.y;
  6331. break;
  6332. case (!position && !!reference):
  6333. vakata_context.reference = reference;
  6334. o = reference.offset();
  6335. vakata_context.position_x = o.left + reference.outerHeight();
  6336. vakata_context.position_y = o.top;
  6337. break;
  6338. case (!!position && !reference):
  6339. vakata_context.position_x = position.x;
  6340. vakata_context.position_y = position.y;
  6341. break;
  6342. }
  6343. if(!!reference && !data && $(reference).data('vakata_contextmenu')) {
  6344. data = $(reference).data('vakata_contextmenu');
  6345. }
  6346. if($.vakata.context._parse(data)) {
  6347. vakata_context.element.html(vakata_context.html);
  6348. }
  6349. if(vakata_context.items.length) {
  6350. vakata_context.element.appendTo(document.body);
  6351. e = vakata_context.element;
  6352. x = vakata_context.position_x;
  6353. y = vakata_context.position_y;
  6354. w = e.width();
  6355. h = e.height();
  6356. dw = $(window).width() + $(window).scrollLeft();
  6357. dh = $(window).height() + $(window).scrollTop();
  6358. if(right_to_left) {
  6359. x -= (e.outerWidth() - $(reference).outerWidth());
  6360. if(x < $(window).scrollLeft() + 20) {
  6361. x = $(window).scrollLeft() + 20;
  6362. }
  6363. }
  6364. if(x + w + 20 > dw) {
  6365. x = dw - (w + 20);
  6366. }
  6367. if(y + h + 20 > dh) {
  6368. y = dh - (h + 20);
  6369. }
  6370. vakata_context.element
  6371. .css({ "left" : x, "top" : y })
  6372. .show()
  6373. .find('a').first().focus().parent().addClass("vakata-context-hover");
  6374. vakata_context.is_visible = true;
  6375. /**
  6376. * triggered on the document when the contextmenu is shown
  6377. * @event
  6378. * @plugin contextmenu
  6379. * @name context_show.vakata
  6380. * @param {jQuery} reference the element that was right clicked
  6381. * @param {jQuery} element the DOM element of the menu itself
  6382. * @param {Object} position the x & y coordinates of the menu
  6383. */
  6384. $.vakata.context._trigger("show");
  6385. }
  6386. },
  6387. hide : function () {
  6388. if(vakata_context.is_visible) {
  6389. vakata_context.element.hide().find("ul").hide().end().find(':focus').blur().end().detach();
  6390. vakata_context.is_visible = false;
  6391. /**
  6392. * triggered on the document when the contextmenu is hidden
  6393. * @event
  6394. * @plugin contextmenu
  6395. * @name context_hide.vakata
  6396. * @param {jQuery} reference the element that was right clicked
  6397. * @param {jQuery} element the DOM element of the menu itself
  6398. * @param {Object} position the x & y coordinates of the menu
  6399. */
  6400. $.vakata.context._trigger("hide");
  6401. }
  6402. }
  6403. };
  6404. $(function () {
  6405. right_to_left = $(document.body).css("direction") === "rtl";
  6406. var to = false;
  6407. vakata_context.element = $("<ul class='vakata-context'></ul>");
  6408. vakata_context.element
  6409. .on("mouseenter", "li", function (e) {
  6410. e.stopImmediatePropagation();
  6411. if($.contains(this, e.relatedTarget)) {
  6412. // премахнато заради delegate mouseleave по-долу
  6413. // $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
  6414. return;
  6415. }
  6416. if(to) { clearTimeout(to); }
  6417. vakata_context.element.find(".vakata-context-hover").removeClass("vakata-context-hover").end();
  6418. $(this)
  6419. .siblings().find("ul").hide().end().end()
  6420. .parentsUntil(".vakata-context", "li").addBack().addClass("vakata-context-hover");
  6421. $.vakata.context._show_submenu(this);
  6422. })
  6423. // тестово - дали не натоварва?
  6424. .on("mouseleave", "li", function (e) {
  6425. if($.contains(this, e.relatedTarget)) { return; }
  6426. $(this).find(".vakata-context-hover").addBack().removeClass("vakata-context-hover");
  6427. })
  6428. .on("mouseleave", function (e) {
  6429. $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
  6430. if($.vakata.context.settings.hide_onmouseleave) {
  6431. to = setTimeout(
  6432. (function (t) {
  6433. return function () { $.vakata.context.hide(); };
  6434. }(this)), $.vakata.context.settings.hide_onmouseleave);
  6435. }
  6436. })
  6437. .on("click", "a", function (e) {
  6438. e.preventDefault();
  6439. //})
  6440. //.on("mouseup", "a", function (e) {
  6441. if(!$(this).blur().parent().hasClass("vakata-context-disabled") && $.vakata.context._execute($(this).attr("rel")) !== false) {
  6442. $.vakata.context.hide();
  6443. }
  6444. })
  6445. .on('keydown', 'a', function (e) {
  6446. var o = null;
  6447. switch(e.which) {
  6448. case 13:
  6449. case 32:
  6450. e.type = "click";
  6451. e.preventDefault();
  6452. $(e.currentTarget).trigger(e);
  6453. break;
  6454. case 37:
  6455. if(vakata_context.is_visible) {
  6456. 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();
  6457. e.stopImmediatePropagation();
  6458. e.preventDefault();
  6459. }
  6460. break;
  6461. case 38:
  6462. if(vakata_context.is_visible) {
  6463. o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").prevAll("li:not(.vakata-context-separator)").first();
  6464. if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").last(); }
  6465. o.addClass("vakata-context-hover").children('a').focus();
  6466. e.stopImmediatePropagation();
  6467. e.preventDefault();
  6468. }
  6469. break;
  6470. case 39:
  6471. if(vakata_context.is_visible) {
  6472. 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();
  6473. e.stopImmediatePropagation();
  6474. e.preventDefault();
  6475. }
  6476. break;
  6477. case 40:
  6478. if(vakata_context.is_visible) {
  6479. o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").nextAll("li:not(.vakata-context-separator)").first();
  6480. if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").first(); }
  6481. o.addClass("vakata-context-hover").children('a').focus();
  6482. e.stopImmediatePropagation();
  6483. e.preventDefault();
  6484. }
  6485. break;
  6486. case 27:
  6487. $.vakata.context.hide();
  6488. e.preventDefault();
  6489. break;
  6490. default:
  6491. //console.log(e.which);
  6492. break;
  6493. }
  6494. })
  6495. .on('keydown', function (e) {
  6496. e.preventDefault();
  6497. var a = vakata_context.element.find('.vakata-contextmenu-shortcut-' + e.which).parent();
  6498. if(a.parent().not('.vakata-context-disabled')) {
  6499. a.click();
  6500. }
  6501. });
  6502. $(document)
  6503. .on("mousedown.vakata.jstree", function (e) {
  6504. if(vakata_context.is_visible && vakata_context.element[0] !== e.target && !$.contains(vakata_context.element[0], e.target)) {
  6505. $.vakata.context.hide();
  6506. }
  6507. })
  6508. .on("context_show.vakata.jstree", function (e, data) {
  6509. vakata_context.element.find("li:has(ul)").children("a").addClass("vakata-context-parent");
  6510. if(right_to_left) {
  6511. vakata_context.element.addClass("vakata-context-rtl").css("direction", "rtl");
  6512. }
  6513. // also apply a RTL class?
  6514. vakata_context.element.find("ul").hide().end();
  6515. });
  6516. });
  6517. }($));
  6518. // $.jstree.defaults.plugins.push("contextmenu");
  6519. /**
  6520. * ### Drag'n'drop plugin
  6521. *
  6522. * Enables dragging and dropping of nodes in the tree, resulting in a move or copy operations.
  6523. */
  6524. /**
  6525. * stores all defaults for the drag'n'drop plugin
  6526. * @name $.jstree.defaults.dnd
  6527. * @plugin dnd
  6528. */
  6529. $.jstree.defaults.dnd = {
  6530. /**
  6531. * a boolean indicating if a copy should be possible while dragging (by pressint the meta key or Ctrl). Defaults to `true`.
  6532. * @name $.jstree.defaults.dnd.copy
  6533. * @plugin dnd
  6534. */
  6535. copy : true,
  6536. /**
  6537. * a number indicating how long a node should remain hovered while dragging to be opened. Defaults to `500`.
  6538. * @name $.jstree.defaults.dnd.open_timeout
  6539. * @plugin dnd
  6540. */
  6541. open_timeout : 500,
  6542. /**
  6543. * 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
  6544. * @name $.jstree.defaults.dnd.is_draggable
  6545. * @plugin dnd
  6546. */
  6547. is_draggable : true,
  6548. /**
  6549. * 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`
  6550. * @name $.jstree.defaults.dnd.check_while_dragging
  6551. * @plugin dnd
  6552. */
  6553. check_while_dragging : true,
  6554. /**
  6555. * a boolean indicating if nodes from this tree should only be copied with dnd (as opposed to moved), default is `false`
  6556. * @name $.jstree.defaults.dnd.always_copy
  6557. * @plugin dnd
  6558. */
  6559. always_copy : false,
  6560. /**
  6561. * 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`
  6562. * @name $.jstree.defaults.dnd.inside_pos
  6563. * @plugin dnd
  6564. */
  6565. inside_pos : 0,
  6566. /**
  6567. * 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
  6568. * @name $.jstree.defaults.dnd.drag_selection
  6569. * @plugin dnd
  6570. */
  6571. drag_selection : true,
  6572. /**
  6573. * 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.
  6574. * @name $.jstree.defaults.dnd.touch
  6575. * @plugin dnd
  6576. */
  6577. touch : true,
  6578. /**
  6579. * 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.
  6580. * @name $.jstree.defaults.dnd.large_drop_target
  6581. * @plugin dnd
  6582. */
  6583. large_drop_target : false,
  6584. /**
  6585. * 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".
  6586. * @name $.jstree.defaults.dnd.large_drag_target
  6587. * @plugin dnd
  6588. */
  6589. large_drag_target : false,
  6590. /**
  6591. * controls whether use HTML5 dnd api instead of classical. That will allow better integration of dnd events with other HTML5 controls.
  6592. * @reference http://caniuse.com/#feat=dragndrop
  6593. * @name $.jstree.defaults.dnd.use_html5
  6594. * @plugin dnd
  6595. */
  6596. use_html5: false
  6597. };
  6598. var drg, elm;
  6599. // TODO: now check works by checking for each node individually, how about max_children, unique, etc?
  6600. $.jstree.plugins.dnd = function (options, parent) {
  6601. this.init = function (el, options) {
  6602. parent.init.call(this, el, options);
  6603. this.settings.dnd.use_html5 = this.settings.dnd.use_html5 && ('draggable' in document.createElement('span'));
  6604. };
  6605. this.bind = function () {
  6606. parent.bind.call(this);
  6607. this.element
  6608. .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) {
  6609. if(this.settings.dnd.large_drag_target && $(e.target).closest('.jstree-node')[0] !== e.currentTarget) {
  6610. return true;
  6611. }
  6612. if(e.type === "touchstart" && (!this.settings.dnd.touch || (this.settings.dnd.touch === 'selected' && !$(e.currentTarget).closest('.jstree-node').children('.jstree-anchor').hasClass('jstree-clicked')))) {
  6613. return true;
  6614. }
  6615. var obj = this.get_node(e.target),
  6616. mlt = this.is_selected(obj) && this.settings.dnd.drag_selection ? this.get_top_selected().length : 1,
  6617. txt = (mlt > 1 ? mlt + ' ' + this.get_string('nodes') : this.get_text(e.currentTarget));
  6618. if(this.settings.core.force_text) {
  6619. txt = $.vakata.html.escape(txt);
  6620. }
  6621. if(obj && obj.id && obj.id !== $.jstree.root && (e.which === 1 || e.type === "touchstart" || e.type === "dragstart") &&
  6622. (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)))
  6623. ) {
  6624. drg = { 'jstree' : true, 'origin' : this, 'obj' : this.get_node(obj,true), 'nodes' : mlt > 1 ? this.get_top_selected() : [obj.id] };
  6625. elm = e.currentTarget;
  6626. if (this.settings.dnd.use_html5) {
  6627. $.vakata.dnd._trigger('start', e, { 'helper': $(), 'element': elm, 'data': drg });
  6628. } else {
  6629. this.element.trigger('mousedown.jstree');
  6630. 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>');
  6631. }
  6632. }
  6633. }, this));
  6634. if (this.settings.dnd.use_html5) {
  6635. this.element
  6636. .on('dragover.jstree', function (e) {
  6637. e.preventDefault();
  6638. $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
  6639. return false;
  6640. })
  6641. //.on('dragenter.jstree', this.settings.dnd.large_drop_target ? '.jstree-node' : '.jstree-anchor', $.proxy(function (e) {
  6642. // e.preventDefault();
  6643. // $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
  6644. // return false;
  6645. // }, this))
  6646. .on('drop.jstree', $.proxy(function (e) {
  6647. e.preventDefault();
  6648. $.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
  6649. return false;
  6650. }, this));
  6651. }
  6652. };
  6653. this.redraw_node = function(obj, deep, callback, force_render) {
  6654. obj = parent.redraw_node.apply(this, arguments);
  6655. if (obj && this.settings.dnd.use_html5) {
  6656. if (this.settings.dnd.large_drag_target) {
  6657. obj.setAttribute('draggable', true);
  6658. } else {
  6659. var i, j, tmp = null;
  6660. for(i = 0, j = obj.childNodes.length; i < j; i++) {
  6661. if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
  6662. tmp = obj.childNodes[i];
  6663. break;
  6664. }
  6665. }
  6666. if(tmp) {
  6667. tmp.setAttribute('draggable', true);
  6668. }
  6669. }
  6670. }
  6671. return obj;
  6672. };
  6673. };
  6674. $(function() {
  6675. // bind only once for all instances
  6676. var lastmv = false,
  6677. laster = false,
  6678. lastev = false,
  6679. opento = false,
  6680. marker = $('<div id="jstree-marker">&#160;</div>').hide(); //.appendTo('body');
  6681. $(document)
  6682. .on('dragover.vakata.jstree', function (e) {
  6683. if (elm) {
  6684. $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
  6685. }
  6686. })
  6687. .on('drop.vakata.jstree', function (e) {
  6688. if (elm) {
  6689. $.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
  6690. elm = null;
  6691. drg = null;
  6692. }
  6693. })
  6694. .on('dnd_start.vakata.jstree', function (e, data) {
  6695. lastmv = false;
  6696. lastev = false;
  6697. if(!data || !data.data || !data.data.jstree) { return; }
  6698. marker.appendTo(document.body); //.show();
  6699. })
  6700. .on('dnd_move.vakata.jstree', function (e, data) {
  6701. var isDifferentNode = data.event.target !== lastev.target;
  6702. if(opento) {
  6703. if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
  6704. clearTimeout(opento);
  6705. }
  6706. }
  6707. if(!data || !data.data || !data.data.jstree) { return; }
  6708. // if we are hovering the marker image do nothing (can happen on "inside" drags)
  6709. if(data.event.target.id && data.event.target.id === 'jstree-marker') {
  6710. return;
  6711. }
  6712. lastev = data.event;
  6713. var ins = $.jstree.reference(data.event.target),
  6714. ref = false,
  6715. off = false,
  6716. rel = false,
  6717. tmp, l, t, h, p, i, o, ok, t1, t2, op, ps, pr, ip, tm, is_copy, pn, c;
  6718. // if we are over an instance
  6719. if(ins && ins._data && ins._data.dnd) {
  6720. marker.attr('class', 'jstree-' + ins.get_theme() + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ));
  6721. is_copy = data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey)));
  6722. data.helper
  6723. .children().attr('class', 'jstree-' + ins.get_theme() + ' jstree-' + ins.get_theme() + '-' + ins.get_theme_variant() + ' ' + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ))
  6724. .find('.jstree-copy').first()[ is_copy ? 'show' : 'hide' ]();
  6725. // if are hovering the container itself add a new root node
  6726. //console.log(data.event);
  6727. if( (data.event.target === ins.element[0] || data.event.target === ins.get_container_ul()[0]) && ins.get_container_ul().children().length === 0) {
  6728. ok = true;
  6729. for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
  6730. 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) });
  6731. if(!ok) { break; }
  6732. }
  6733. if(ok) {
  6734. lastmv = { 'ins' : ins, 'par' : $.jstree.root, 'pos' : 'last' };
  6735. marker.hide();
  6736. data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
  6737. if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
  6738. data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
  6739. }
  6740. return;
  6741. }
  6742. }
  6743. else {
  6744. // if we are hovering a tree node
  6745. ref = ins.settings.dnd.large_drop_target ? $(data.event.target).closest('.jstree-node').children('.jstree-anchor') : $(data.event.target).closest('.jstree-anchor');
  6746. if(ref && ref.length && ref.parent().is('.jstree-closed, .jstree-open, .jstree-leaf')) {
  6747. off = ref.offset();
  6748. rel = (data.event.pageY !== undefined ? data.event.pageY : data.event.originalEvent.pageY) - off.top;
  6749. h = ref.outerHeight();
  6750. if(rel < h / 3) {
  6751. o = ['b', 'i', 'a'];
  6752. }
  6753. else if(rel > h - h / 3) {
  6754. o = ['a', 'i', 'b'];
  6755. }
  6756. else {
  6757. o = rel > h / 2 ? ['i', 'a', 'b'] : ['i', 'b', 'a'];
  6758. }
  6759. $.each(o, function (j, v) {
  6760. switch(v) {
  6761. case 'b':
  6762. l = off.left - 6;
  6763. t = off.top;
  6764. p = ins.get_parent(ref);
  6765. i = ref.parent().index();
  6766. c = 'jstree-below';
  6767. break;
  6768. case 'i':
  6769. ip = ins.settings.dnd.inside_pos;
  6770. tm = ins.get_node(ref.parent());
  6771. l = off.left - 2;
  6772. t = off.top + h / 2 + 1;
  6773. p = tm.id;
  6774. i = ip === 'first' ? 0 : (ip === 'last' ? tm.children.length : Math.min(ip, tm.children.length));
  6775. c = 'jstree-inside';
  6776. break;
  6777. case 'a':
  6778. l = off.left - 6;
  6779. t = off.top + h;
  6780. p = ins.get_parent(ref);
  6781. i = ref.parent().index() + 1;
  6782. c = 'jstree-above';
  6783. break;
  6784. }
  6785. ok = true;
  6786. for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
  6787. 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";
  6788. ps = i;
  6789. if(op === "move_node" && v === 'a' && (data.data.origin && data.data.origin === ins) && p === ins.get_parent(data.data.nodes[t1])) {
  6790. pr = ins.get_node(p);
  6791. if(ps > $.inArray(data.data.nodes[t1], pr.children)) {
  6792. ps -= 1;
  6793. }
  6794. }
  6795. 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) }) );
  6796. if(!ok) {
  6797. if(ins && ins.last_error) { laster = ins.last_error(); }
  6798. break;
  6799. }
  6800. }
  6801. if(v === 'i' && ref.parent().is('.jstree-closed') && ins.settings.dnd.open_timeout) {
  6802. if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
  6803. if (opento) { clearTimeout(opento); }
  6804. opento = setTimeout((function (x, z) { return function () { x.open_node(z); }; }(ins, ref)), ins.settings.dnd.open_timeout);
  6805. }
  6806. }
  6807. if(ok) {
  6808. pn = ins.get_node(p, true);
  6809. if (!pn.hasClass('.jstree-dnd-parent')) {
  6810. $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
  6811. pn.addClass('jstree-dnd-parent');
  6812. }
  6813. lastmv = { 'ins' : ins, 'par' : p, 'pos' : v === 'i' && ip === 'last' && i === 0 && !ins.is_loaded(tm) ? 'last' : i };
  6814. marker.css({ 'left' : l + 'px', 'top' : t + 'px' }).show();
  6815. marker.removeClass('jstree-above jstree-inside jstree-below').addClass(c);
  6816. data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
  6817. if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
  6818. data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
  6819. }
  6820. laster = {};
  6821. o = true;
  6822. return false;
  6823. }
  6824. });
  6825. if(o === true) { return; }
  6826. }
  6827. }
  6828. }
  6829. $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
  6830. lastmv = false;
  6831. data.helper.find('.jstree-icon').removeClass('jstree-ok').addClass('jstree-er');
  6832. if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
  6833. //data.event.originalEvent.dataTransfer.dropEffect = 'none';
  6834. }
  6835. marker.hide();
  6836. })
  6837. .on('dnd_scroll.vakata.jstree', function (e, data) {
  6838. if(!data || !data.data || !data.data.jstree) { return; }
  6839. marker.hide();
  6840. lastmv = false;
  6841. lastev = false;
  6842. data.helper.find('.jstree-icon').first().removeClass('jstree-ok').addClass('jstree-er');
  6843. })
  6844. .on('dnd_stop.vakata.jstree', function (e, data) {
  6845. $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
  6846. if(opento) { clearTimeout(opento); }
  6847. if(!data || !data.data || !data.data.jstree) { return; }
  6848. marker.hide().detach();
  6849. var i, j, nodes = [];
  6850. if(lastmv) {
  6851. for(i = 0, j = data.data.nodes.length; i < j; i++) {
  6852. nodes[i] = data.data.origin ? data.data.origin.get_node(data.data.nodes[i]) : data.data.nodes[i];
  6853. }
  6854. 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);
  6855. }
  6856. else {
  6857. i = $(data.event.target).closest('.jstree');
  6858. if(i.length && laster && laster.error && laster.error === 'check') {
  6859. i = i.jstree(true);
  6860. if(i) {
  6861. i.settings.core.error.call(this, laster);
  6862. }
  6863. }
  6864. }
  6865. lastev = false;
  6866. lastmv = false;
  6867. })
  6868. .on('keyup.jstree keydown.jstree', function (e, data) {
  6869. data = $.vakata.dnd._get();
  6870. if(data && data.data && data.data.jstree) {
  6871. if (e.type === "keyup" && e.which === 27) {
  6872. if (opento) { clearTimeout(opento); }
  6873. lastmv = false;
  6874. laster = false;
  6875. lastev = false;
  6876. opento = false;
  6877. marker.hide().detach();
  6878. $.vakata.dnd._clean();
  6879. } else {
  6880. 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' ]();
  6881. if(lastev) {
  6882. lastev.metaKey = e.metaKey;
  6883. lastev.ctrlKey = e.ctrlKey;
  6884. $.vakata.dnd._trigger('move', lastev);
  6885. }
  6886. }
  6887. }
  6888. });
  6889. });
  6890. // helpers
  6891. (function ($) {
  6892. $.vakata.html = {
  6893. div : $('<div></div>'),
  6894. escape : function (str) {
  6895. return $.vakata.html.div.text(str).html();
  6896. },
  6897. strip : function (str) {
  6898. return $.vakata.html.div.empty().append($.parseHTML(str)).text();
  6899. }
  6900. };
  6901. // private variable
  6902. var vakata_dnd = {
  6903. element : false,
  6904. target : false,
  6905. is_down : false,
  6906. is_drag : false,
  6907. helper : false,
  6908. helper_w: 0,
  6909. data : false,
  6910. init_x : 0,
  6911. init_y : 0,
  6912. scroll_l: 0,
  6913. scroll_t: 0,
  6914. scroll_e: false,
  6915. scroll_i: false,
  6916. is_touch: false
  6917. };
  6918. $.vakata.dnd = {
  6919. settings : {
  6920. scroll_speed : 10,
  6921. scroll_proximity : 20,
  6922. helper_left : 5,
  6923. helper_top : 10,
  6924. threshold : 5,
  6925. threshold_touch : 10
  6926. },
  6927. _trigger : function (event_name, e, data) {
  6928. if (data === undefined) {
  6929. data = $.vakata.dnd._get();
  6930. }
  6931. data.event = e;
  6932. $(document).triggerHandler("dnd_" + event_name + ".vakata", data);
  6933. },
  6934. _get : function () {
  6935. return {
  6936. "data" : vakata_dnd.data,
  6937. "element" : vakata_dnd.element,
  6938. "helper" : vakata_dnd.helper
  6939. };
  6940. },
  6941. _clean : function () {
  6942. if(vakata_dnd.helper) { vakata_dnd.helper.remove(); }
  6943. if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
  6944. vakata_dnd = {
  6945. element : false,
  6946. target : false,
  6947. is_down : false,
  6948. is_drag : false,
  6949. helper : false,
  6950. helper_w: 0,
  6951. data : false,
  6952. init_x : 0,
  6953. init_y : 0,
  6954. scroll_l: 0,
  6955. scroll_t: 0,
  6956. scroll_e: false,
  6957. scroll_i: false,
  6958. is_touch: false
  6959. };
  6960. elm = null;
  6961. $(document).off("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
  6962. $(document).off("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
  6963. },
  6964. _scroll : function (init_only) {
  6965. if(!vakata_dnd.scroll_e || (!vakata_dnd.scroll_l && !vakata_dnd.scroll_t)) {
  6966. if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
  6967. return false;
  6968. }
  6969. if(!vakata_dnd.scroll_i) {
  6970. vakata_dnd.scroll_i = setInterval($.vakata.dnd._scroll, 100);
  6971. return false;
  6972. }
  6973. if(init_only === true) { return false; }
  6974. var i = vakata_dnd.scroll_e.scrollTop(),
  6975. j = vakata_dnd.scroll_e.scrollLeft();
  6976. vakata_dnd.scroll_e.scrollTop(i + vakata_dnd.scroll_t * $.vakata.dnd.settings.scroll_speed);
  6977. vakata_dnd.scroll_e.scrollLeft(j + vakata_dnd.scroll_l * $.vakata.dnd.settings.scroll_speed);
  6978. if(i !== vakata_dnd.scroll_e.scrollTop() || j !== vakata_dnd.scroll_e.scrollLeft()) {
  6979. /**
  6980. * triggered on the document when a drag causes an element to scroll
  6981. * @event
  6982. * @plugin dnd
  6983. * @name dnd_scroll.vakata
  6984. * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
  6985. * @param {DOM} element the DOM element being dragged
  6986. * @param {jQuery} helper the helper shown next to the mouse
  6987. * @param {jQuery} event the element that is scrolling
  6988. */
  6989. $.vakata.dnd._trigger("scroll", vakata_dnd.scroll_e);
  6990. }
  6991. },
  6992. start : function (e, data, html) {
  6993. if(e.type === "touchstart" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
  6994. e.pageX = e.originalEvent.changedTouches[0].pageX;
  6995. e.pageY = e.originalEvent.changedTouches[0].pageY;
  6996. e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
  6997. }
  6998. if(vakata_dnd.is_drag) { $.vakata.dnd.stop({}); }
  6999. try {
  7000. e.currentTarget.unselectable = "on";
  7001. e.currentTarget.onselectstart = function() { return false; };
  7002. if(e.currentTarget.style) {
  7003. e.currentTarget.style.touchAction = "none";
  7004. e.currentTarget.style.msTouchAction = "none";
  7005. e.currentTarget.style.MozUserSelect = "none";
  7006. }
  7007. } catch(ignore) { }
  7008. vakata_dnd.init_x = e.pageX;
  7009. vakata_dnd.init_y = e.pageY;
  7010. vakata_dnd.data = data;
  7011. vakata_dnd.is_down = true;
  7012. vakata_dnd.element = e.currentTarget;
  7013. vakata_dnd.target = e.target;
  7014. vakata_dnd.is_touch = e.type === "touchstart";
  7015. if(html !== false) {
  7016. vakata_dnd.helper = $("<div id='vakata-dnd'></div>").html(html).css({
  7017. "display" : "block",
  7018. "margin" : "0",
  7019. "padding" : "0",
  7020. "position" : "absolute",
  7021. "top" : "-2000px",
  7022. "lineHeight" : "16px",
  7023. "zIndex" : "10000"
  7024. });
  7025. }
  7026. $(document).on("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
  7027. $(document).on("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
  7028. return false;
  7029. },
  7030. drag : function (e) {
  7031. if(e.type === "touchmove" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
  7032. e.pageX = e.originalEvent.changedTouches[0].pageX;
  7033. e.pageY = e.originalEvent.changedTouches[0].pageY;
  7034. e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
  7035. }
  7036. if(!vakata_dnd.is_down) { return; }
  7037. if(!vakata_dnd.is_drag) {
  7038. if(
  7039. Math.abs(e.pageX - vakata_dnd.init_x) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold) ||
  7040. Math.abs(e.pageY - vakata_dnd.init_y) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold)
  7041. ) {
  7042. if(vakata_dnd.helper) {
  7043. vakata_dnd.helper.appendTo(document.body);
  7044. vakata_dnd.helper_w = vakata_dnd.helper.outerWidth();
  7045. }
  7046. vakata_dnd.is_drag = true;
  7047. $(vakata_dnd.target).one('click.vakata', false);
  7048. /**
  7049. * triggered on the document when a drag starts
  7050. * @event
  7051. * @plugin dnd
  7052. * @name dnd_start.vakata
  7053. * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
  7054. * @param {DOM} element the DOM element being dragged
  7055. * @param {jQuery} helper the helper shown next to the mouse
  7056. * @param {Object} event the event that caused the start (probably mousemove)
  7057. */
  7058. $.vakata.dnd._trigger("start", e);
  7059. }
  7060. else { return; }
  7061. }
  7062. var d = false, w = false,
  7063. dh = false, wh = false,
  7064. dw = false, ww = false,
  7065. dt = false, dl = false,
  7066. ht = false, hl = false;
  7067. vakata_dnd.scroll_t = 0;
  7068. vakata_dnd.scroll_l = 0;
  7069. vakata_dnd.scroll_e = false;
  7070. $($(e.target).parentsUntil("body").addBack().get().reverse())
  7071. .filter(function () {
  7072. return (/^auto|scroll$/).test($(this).css("overflow")) &&
  7073. (this.scrollHeight > this.offsetHeight || this.scrollWidth > this.offsetWidth);
  7074. })
  7075. .each(function () {
  7076. var t = $(this), o = t.offset();
  7077. if(this.scrollHeight > this.offsetHeight) {
  7078. if(o.top + t.height() - e.pageY < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
  7079. if(e.pageY - o.top < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
  7080. }
  7081. if(this.scrollWidth > this.offsetWidth) {
  7082. if(o.left + t.width() - e.pageX < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
  7083. if(e.pageX - o.left < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
  7084. }
  7085. if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
  7086. vakata_dnd.scroll_e = $(this);
  7087. return false;
  7088. }
  7089. });
  7090. if(!vakata_dnd.scroll_e) {
  7091. d = $(document); w = $(window);
  7092. dh = d.height(); wh = w.height();
  7093. dw = d.width(); ww = w.width();
  7094. dt = d.scrollTop(); dl = d.scrollLeft();
  7095. if(dh > wh && e.pageY - dt < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
  7096. if(dh > wh && wh - (e.pageY - dt) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
  7097. if(dw > ww && e.pageX - dl < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
  7098. if(dw > ww && ww - (e.pageX - dl) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
  7099. if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
  7100. vakata_dnd.scroll_e = d;
  7101. }
  7102. }
  7103. if(vakata_dnd.scroll_e) { $.vakata.dnd._scroll(true); }
  7104. if(vakata_dnd.helper) {
  7105. ht = parseInt(e.pageY + $.vakata.dnd.settings.helper_top, 10);
  7106. hl = parseInt(e.pageX + $.vakata.dnd.settings.helper_left, 10);
  7107. if(dh && ht + 25 > dh) { ht = dh - 50; }
  7108. if(dw && hl + vakata_dnd.helper_w > dw) { hl = dw - (vakata_dnd.helper_w + 2); }
  7109. vakata_dnd.helper.css({
  7110. left : hl + "px",
  7111. top : ht + "px"
  7112. });
  7113. }
  7114. /**
  7115. * triggered on the document when a drag is in progress
  7116. * @event
  7117. * @plugin dnd
  7118. * @name dnd_move.vakata
  7119. * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
  7120. * @param {DOM} element the DOM element being dragged
  7121. * @param {jQuery} helper the helper shown next to the mouse
  7122. * @param {Object} event the event that caused this to trigger (most likely mousemove)
  7123. */
  7124. $.vakata.dnd._trigger("move", e);
  7125. return false;
  7126. },
  7127. stop : function (e) {
  7128. if(e.type === "touchend" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
  7129. e.pageX = e.originalEvent.changedTouches[0].pageX;
  7130. e.pageY = e.originalEvent.changedTouches[0].pageY;
  7131. e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
  7132. }
  7133. if(vakata_dnd.is_drag) {
  7134. /**
  7135. * triggered on the document when a drag stops (the dragged element is dropped)
  7136. * @event
  7137. * @plugin dnd
  7138. * @name dnd_stop.vakata
  7139. * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
  7140. * @param {DOM} element the DOM element being dragged
  7141. * @param {jQuery} helper the helper shown next to the mouse
  7142. * @param {Object} event the event that caused the stop
  7143. */
  7144. if (e.target !== vakata_dnd.target) {
  7145. $(vakata_dnd.target).off('click.vakata');
  7146. }
  7147. $.vakata.dnd._trigger("stop", e);
  7148. }
  7149. else {
  7150. if(e.type === "touchend" && e.target === vakata_dnd.target) {
  7151. var to = setTimeout(function () { $(e.target).click(); }, 100);
  7152. $(e.target).one('click', function() { if(to) { clearTimeout(to); } });
  7153. }
  7154. }
  7155. $.vakata.dnd._clean();
  7156. return false;
  7157. }
  7158. };
  7159. }($));
  7160. // include the dnd plugin by default
  7161. // $.jstree.defaults.plugins.push("dnd");
  7162. /**
  7163. * ### Massload plugin
  7164. *
  7165. * Adds massload functionality to jsTree, so that multiple nodes can be loaded in a single request (only useful with lazy loading).
  7166. */
  7167. /**
  7168. * massload configuration
  7169. *
  7170. * It is possible to set this to a standard jQuery-like AJAX config.
  7171. * 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.
  7172. *
  7173. * 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.
  7174. *
  7175. * 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.
  7176. *
  7177. * {
  7178. * "id1" : [{ "text" : "Child of ID1", "id" : "c1" }, { "text" : "Another child of ID1", "id" : "c2" }],
  7179. * "id2" : [{ "text" : "Child of ID2", "id" : "c3" }]
  7180. * }
  7181. *
  7182. * @name $.jstree.defaults.massload
  7183. * @plugin massload
  7184. */
  7185. $.jstree.defaults.massload = null;
  7186. $.jstree.plugins.massload = function (options, parent) {
  7187. this.init = function (el, options) {
  7188. this._data.massload = {};
  7189. parent.init.call(this, el, options);
  7190. };
  7191. this._load_nodes = function (nodes, callback, is_callback, force_reload) {
  7192. var s = this.settings.massload,
  7193. toLoad = [],
  7194. m = this._model.data,
  7195. i, j, dom;
  7196. if (!is_callback) {
  7197. for(i = 0, j = nodes.length; i < j; i++) {
  7198. if(!m[nodes[i]] || ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || force_reload) ) {
  7199. toLoad.push(nodes[i]);
  7200. dom = this.get_node(nodes[i], true);
  7201. if (dom && dom.length) {
  7202. dom.addClass("jstree-loading").attr('aria-busy',true);
  7203. }
  7204. }
  7205. }
  7206. this._data.massload = {};
  7207. if (toLoad.length) {
  7208. if($.isFunction(s)) {
  7209. return s.call(this, toLoad, $.proxy(function (data) {
  7210. var i, j;
  7211. if(data) {
  7212. for(i in data) {
  7213. if(data.hasOwnProperty(i)) {
  7214. this._data.massload[i] = data[i];
  7215. }
  7216. }
  7217. }
  7218. for(i = 0, j = nodes.length; i < j; i++) {
  7219. dom = this.get_node(nodes[i], true);
  7220. if (dom && dom.length) {
  7221. dom.removeClass("jstree-loading").attr('aria-busy',false);
  7222. }
  7223. }
  7224. parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
  7225. }, this));
  7226. }
  7227. if(typeof s === 'object' && s && s.url) {
  7228. s = $.extend(true, {}, s);
  7229. if($.isFunction(s.url)) {
  7230. s.url = s.url.call(this, toLoad);
  7231. }
  7232. if($.isFunction(s.data)) {
  7233. s.data = s.data.call(this, toLoad);
  7234. }
  7235. return $.ajax(s)
  7236. .done($.proxy(function (data,t,x) {
  7237. var i, j;
  7238. if(data) {
  7239. for(i in data) {
  7240. if(data.hasOwnProperty(i)) {
  7241. this._data.massload[i] = data[i];
  7242. }
  7243. }
  7244. }
  7245. for(i = 0, j = nodes.length; i < j; i++) {
  7246. dom = this.get_node(nodes[i], true);
  7247. if (dom && dom.length) {
  7248. dom.removeClass("jstree-loading").attr('aria-busy',false);
  7249. }
  7250. }
  7251. parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
  7252. }, this))
  7253. .fail($.proxy(function (f) {
  7254. parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
  7255. }, this));
  7256. }
  7257. }
  7258. }
  7259. return parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
  7260. };
  7261. this._load_node = function (obj, callback) {
  7262. var data = this._data.massload[obj.id],
  7263. rslt = null, dom;
  7264. if(data) {
  7265. rslt = this[typeof data === 'string' ? '_append_html_data' : '_append_json_data'](
  7266. obj,
  7267. typeof data === 'string' ? $($.parseHTML(data)).filter(function () { return this.nodeType !== 3; }) : data,
  7268. function (status) { callback.call(this, status); }
  7269. );
  7270. dom = this.get_node(obj.id, true);
  7271. if (dom && dom.length) {
  7272. dom.removeClass("jstree-loading").attr('aria-busy',false);
  7273. }
  7274. delete this._data.massload[obj.id];
  7275. return rslt;
  7276. }
  7277. return parent._load_node.call(this, obj, callback);
  7278. };
  7279. };
  7280. /**
  7281. * ### Search plugin
  7282. *
  7283. * Adds search functionality to jsTree.
  7284. */
  7285. /**
  7286. * stores all defaults for the search plugin
  7287. * @name $.jstree.defaults.search
  7288. * @plugin search
  7289. */
  7290. $.jstree.defaults.search = {
  7291. /**
  7292. * a jQuery-like AJAX config, which jstree uses if a server should be queried for results.
  7293. *
  7294. * 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.
  7295. * 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
  7296. * @name $.jstree.defaults.search.ajax
  7297. * @plugin search
  7298. */
  7299. ajax : false,
  7300. /**
  7301. * Indicates if the search should be fuzzy or not (should `chnd3` match `child node 3`). Default is `false`.
  7302. * @name $.jstree.defaults.search.fuzzy
  7303. * @plugin search
  7304. */
  7305. fuzzy : false,
  7306. /**
  7307. * Indicates if the search should be case sensitive. Default is `false`.
  7308. * @name $.jstree.defaults.search.case_sensitive
  7309. * @plugin search
  7310. */
  7311. case_sensitive : false,
  7312. /**
  7313. * 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).
  7314. * This setting can be changed at runtime when calling the search method. Default is `false`.
  7315. * @name $.jstree.defaults.search.show_only_matches
  7316. * @plugin search
  7317. */
  7318. show_only_matches : false,
  7319. /**
  7320. * Indicates if the children of matched element are shown (when show_only_matches is true)
  7321. * This setting can be changed at runtime when calling the search method. Default is `false`.
  7322. * @name $.jstree.defaults.search.show_only_matches_children
  7323. * @plugin search
  7324. */
  7325. show_only_matches_children : false,
  7326. /**
  7327. * 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`.
  7328. * @name $.jstree.defaults.search.close_opened_onclear
  7329. * @plugin search
  7330. */
  7331. close_opened_onclear : true,
  7332. /**
  7333. * Indicates if only leaf nodes should be included in search results. Default is `false`.
  7334. * @name $.jstree.defaults.search.search_leaves_only
  7335. * @plugin search
  7336. */
  7337. search_leaves_only : false,
  7338. /**
  7339. * 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).
  7340. * 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`.
  7341. * @name $.jstree.defaults.search.search_callback
  7342. * @plugin search
  7343. */
  7344. search_callback : false
  7345. };
  7346. $.jstree.plugins.search = function (options, parent) {
  7347. this.bind = function () {
  7348. parent.bind.call(this);
  7349. this._data.search.str = "";
  7350. this._data.search.dom = $();
  7351. this._data.search.res = [];
  7352. this._data.search.opn = [];
  7353. this._data.search.som = false;
  7354. this._data.search.smc = false;
  7355. this._data.search.hdn = [];
  7356. this.element
  7357. .on("search.jstree", $.proxy(function (e, data) {
  7358. if(this._data.search.som && data.res.length) {
  7359. var m = this._model.data, i, j, p = [], k, l;
  7360. for(i = 0, j = data.res.length; i < j; i++) {
  7361. if(m[data.res[i]] && !m[data.res[i]].state.hidden) {
  7362. p.push(data.res[i]);
  7363. p = p.concat(m[data.res[i]].parents);
  7364. if(this._data.search.smc) {
  7365. for (k = 0, l = m[data.res[i]].children_d.length; k < l; k++) {
  7366. if (m[m[data.res[i]].children_d[k]] && !m[m[data.res[i]].children_d[k]].state.hidden) {
  7367. p.push(m[data.res[i]].children_d[k]);
  7368. }
  7369. }
  7370. }
  7371. }
  7372. }
  7373. p = $.vakata.array_remove_item($.vakata.array_unique(p), $.jstree.root);
  7374. this._data.search.hdn = this.hide_all(true);
  7375. this.show_node(p, true);
  7376. this.redraw(true);
  7377. }
  7378. }, this))
  7379. .on("clear_search.jstree", $.proxy(function (e, data) {
  7380. if(this._data.search.som && data.res.length) {
  7381. this.show_node(this._data.search.hdn, true);
  7382. this.redraw(true);
  7383. }
  7384. }, this));
  7385. };
  7386. /**
  7387. * used to search the tree nodes for a given string
  7388. * @name search(str [, skip_async])
  7389. * @param {String} str the search string
  7390. * @param {Boolean} skip_async if set to true server will not be queried even if configured
  7391. * @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)
  7392. * @param {mixed} inside an optional node to whose children to limit the search
  7393. * @param {Boolean} append if set to true the results of this search are appended to the previous search
  7394. * @plugin search
  7395. * @trigger search.jstree
  7396. */
  7397. this.search = function (str, skip_async, show_only_matches, inside, append, show_only_matches_children) {
  7398. if(str === false || $.trim(str.toString()) === "") {
  7399. return this.clear_search();
  7400. }
  7401. inside = this.get_node(inside);
  7402. inside = inside && inside.id ? inside.id : null;
  7403. str = str.toString();
  7404. var s = this.settings.search,
  7405. a = s.ajax ? s.ajax : false,
  7406. m = this._model.data,
  7407. f = null,
  7408. r = [],
  7409. p = [], i, j;
  7410. if(this._data.search.res.length && !append) {
  7411. this.clear_search();
  7412. }
  7413. if(show_only_matches === undefined) {
  7414. show_only_matches = s.show_only_matches;
  7415. }
  7416. if(show_only_matches_children === undefined) {
  7417. show_only_matches_children = s.show_only_matches_children;
  7418. }
  7419. if(!skip_async && a !== false) {
  7420. if($.isFunction(a)) {
  7421. return a.call(this, str, $.proxy(function (d) {
  7422. if(d && d.d) { d = d.d; }
  7423. this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
  7424. this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
  7425. });
  7426. }, this), inside);
  7427. }
  7428. else {
  7429. a = $.extend({}, a);
  7430. if(!a.data) { a.data = {}; }
  7431. a.data.str = str;
  7432. if(inside) {
  7433. a.data.inside = inside;
  7434. }
  7435. if (this._data.search.lastRequest) {
  7436. this._data.search.lastRequest.abort();
  7437. }
  7438. this._data.search.lastRequest = $.ajax(a)
  7439. .fail($.proxy(function () {
  7440. this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'search', 'id' : 'search_01', 'reason' : 'Could not load search parents', 'data' : JSON.stringify(a) };
  7441. this.settings.core.error.call(this, this._data.core.last_error);
  7442. }, this))
  7443. .done($.proxy(function (d) {
  7444. if(d && d.d) { d = d.d; }
  7445. this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
  7446. this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
  7447. });
  7448. }, this));
  7449. return this._data.search.lastRequest;
  7450. }
  7451. }
  7452. if(!append) {
  7453. this._data.search.str = str;
  7454. this._data.search.dom = $();
  7455. this._data.search.res = [];
  7456. this._data.search.opn = [];
  7457. this._data.search.som = show_only_matches;
  7458. this._data.search.smc = show_only_matches_children;
  7459. }
  7460. f = new $.vakata.search(str, true, { caseSensitive : s.case_sensitive, fuzzy : s.fuzzy });
  7461. $.each(m[inside ? inside : $.jstree.root].children_d, function (ii, i) {
  7462. var v = m[i];
  7463. 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) ) ) {
  7464. r.push(i);
  7465. p = p.concat(v.parents);
  7466. }
  7467. });
  7468. if(r.length) {
  7469. p = $.vakata.array_unique(p);
  7470. for(i = 0, j = p.length; i < j; i++) {
  7471. if(p[i] !== $.jstree.root && m[p[i]] && this.open_node(p[i], null, 0) === true) {
  7472. this._data.search.opn.push(p[i]);
  7473. }
  7474. }
  7475. if(!append) {
  7476. 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(', #')));
  7477. this._data.search.res = r;
  7478. }
  7479. else {
  7480. 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(', #'))));
  7481. this._data.search.res = $.vakata.array_unique(this._data.search.res.concat(r));
  7482. }
  7483. this._data.search.dom.children(".jstree-anchor").addClass('jstree-search');
  7484. }
  7485. /**
  7486. * triggered after search is complete
  7487. * @event
  7488. * @name search.jstree
  7489. * @param {jQuery} nodes a jQuery collection of matching nodes
  7490. * @param {String} str the search string
  7491. * @param {Array} res a collection of objects represeing the matching nodes
  7492. * @plugin search
  7493. */
  7494. this.trigger('search', { nodes : this._data.search.dom, str : str, res : this._data.search.res, show_only_matches : show_only_matches });
  7495. };
  7496. /**
  7497. * used to clear the last search (removes classes and shows all nodes if filtering is on)
  7498. * @name clear_search()
  7499. * @plugin search
  7500. * @trigger clear_search.jstree
  7501. */
  7502. this.clear_search = function () {
  7503. if(this.settings.search.close_opened_onclear) {
  7504. this.close_node(this._data.search.opn, 0);
  7505. }
  7506. /**
  7507. * triggered after search is complete
  7508. * @event
  7509. * @name clear_search.jstree
  7510. * @param {jQuery} nodes a jQuery collection of matching nodes (the result from the last search)
  7511. * @param {String} str the search string (the last search string)
  7512. * @param {Array} res a collection of objects represeing the matching nodes (the result from the last search)
  7513. * @plugin search
  7514. */
  7515. this.trigger('clear_search', { 'nodes' : this._data.search.dom, str : this._data.search.str, res : this._data.search.res });
  7516. if(this._data.search.res.length) {
  7517. this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(this._data.search.res, function (v) {
  7518. return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&');
  7519. }).join(', #')));
  7520. this._data.search.dom.children(".jstree-anchor").removeClass("jstree-search");
  7521. }
  7522. this._data.search.str = "";
  7523. this._data.search.res = [];
  7524. this._data.search.opn = [];
  7525. this._data.search.dom = $();
  7526. };
  7527. this.redraw_node = function(obj, deep, callback, force_render) {
  7528. obj = parent.redraw_node.apply(this, arguments);
  7529. if(obj) {
  7530. if($.inArray(obj.id, this._data.search.res) !== -1) {
  7531. var i, j, tmp = null;
  7532. for(i = 0, j = obj.childNodes.length; i < j; i++) {
  7533. if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
  7534. tmp = obj.childNodes[i];
  7535. break;
  7536. }
  7537. }
  7538. if(tmp) {
  7539. tmp.className += ' jstree-search';
  7540. }
  7541. }
  7542. }
  7543. return obj;
  7544. };
  7545. };
  7546. // helpers
  7547. (function ($) {
  7548. // from http://kiro.me/projects/fuse.html
  7549. $.vakata.search = function(pattern, txt, options) {
  7550. options = options || {};
  7551. options = $.extend({}, $.vakata.search.defaults, options);
  7552. if(options.fuzzy !== false) {
  7553. options.fuzzy = true;
  7554. }
  7555. pattern = options.caseSensitive ? pattern : pattern.toLowerCase();
  7556. var MATCH_LOCATION = options.location,
  7557. MATCH_DISTANCE = options.distance,
  7558. MATCH_THRESHOLD = options.threshold,
  7559. patternLen = pattern.length,
  7560. matchmask, pattern_alphabet, match_bitapScore, search;
  7561. if(patternLen > 32) {
  7562. options.fuzzy = false;
  7563. }
  7564. if(options.fuzzy) {
  7565. matchmask = 1 << (patternLen - 1);
  7566. pattern_alphabet = (function () {
  7567. var mask = {},
  7568. i = 0;
  7569. for (i = 0; i < patternLen; i++) {
  7570. mask[pattern.charAt(i)] = 0;
  7571. }
  7572. for (i = 0; i < patternLen; i++) {
  7573. mask[pattern.charAt(i)] |= 1 << (patternLen - i - 1);
  7574. }
  7575. return mask;
  7576. }());
  7577. match_bitapScore = function (e, x) {
  7578. var accuracy = e / patternLen,
  7579. proximity = Math.abs(MATCH_LOCATION - x);
  7580. if(!MATCH_DISTANCE) {
  7581. return proximity ? 1.0 : accuracy;
  7582. }
  7583. return accuracy + (proximity / MATCH_DISTANCE);
  7584. };
  7585. }
  7586. search = function (text) {
  7587. text = options.caseSensitive ? text : text.toLowerCase();
  7588. if(pattern === text || text.indexOf(pattern) !== -1) {
  7589. return {
  7590. isMatch: true,
  7591. score: 0
  7592. };
  7593. }
  7594. if(!options.fuzzy) {
  7595. return {
  7596. isMatch: false,
  7597. score: 1
  7598. };
  7599. }
  7600. var i, j,
  7601. textLen = text.length,
  7602. scoreThreshold = MATCH_THRESHOLD,
  7603. bestLoc = text.indexOf(pattern, MATCH_LOCATION),
  7604. binMin, binMid,
  7605. binMax = patternLen + textLen,
  7606. lastRd, start, finish, rd, charMatch,
  7607. score = 1,
  7608. locations = [];
  7609. if (bestLoc !== -1) {
  7610. scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
  7611. bestLoc = text.lastIndexOf(pattern, MATCH_LOCATION + patternLen);
  7612. if (bestLoc !== -1) {
  7613. scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
  7614. }
  7615. }
  7616. bestLoc = -1;
  7617. for (i = 0; i < patternLen; i++) {
  7618. binMin = 0;
  7619. binMid = binMax;
  7620. while (binMin < binMid) {
  7621. if (match_bitapScore(i, MATCH_LOCATION + binMid) <= scoreThreshold) {
  7622. binMin = binMid;
  7623. } else {
  7624. binMax = binMid;
  7625. }
  7626. binMid = Math.floor((binMax - binMin) / 2 + binMin);
  7627. }
  7628. binMax = binMid;
  7629. start = Math.max(1, MATCH_LOCATION - binMid + 1);
  7630. finish = Math.min(MATCH_LOCATION + binMid, textLen) + patternLen;
  7631. rd = new Array(finish + 2);
  7632. rd[finish + 1] = (1 << i) - 1;
  7633. for (j = finish; j >= start; j--) {
  7634. charMatch = pattern_alphabet[text.charAt(j - 1)];
  7635. if (i === 0) {
  7636. rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
  7637. } else {
  7638. rd[j] = ((rd[j + 1] << 1) | 1) & charMatch | (((lastRd[j + 1] | lastRd[j]) << 1) | 1) | lastRd[j + 1];
  7639. }
  7640. if (rd[j] & matchmask) {
  7641. score = match_bitapScore(i, j - 1);
  7642. if (score <= scoreThreshold) {
  7643. scoreThreshold = score;
  7644. bestLoc = j - 1;
  7645. locations.push(bestLoc);
  7646. if (bestLoc > MATCH_LOCATION) {
  7647. start = Math.max(1, 2 * MATCH_LOCATION - bestLoc);
  7648. } else {
  7649. break;
  7650. }
  7651. }
  7652. }
  7653. }
  7654. if (match_bitapScore(i + 1, MATCH_LOCATION) > scoreThreshold) {
  7655. break;
  7656. }
  7657. lastRd = rd;
  7658. }
  7659. return {
  7660. isMatch: bestLoc >= 0,
  7661. score: score
  7662. };
  7663. };
  7664. return txt === true ? { 'search' : search } : search(txt);
  7665. };
  7666. $.vakata.search.defaults = {
  7667. location : 0,
  7668. distance : 100,
  7669. threshold : 0.6,
  7670. fuzzy : false,
  7671. caseSensitive : false
  7672. };
  7673. }($));
  7674. // include the search plugin by default
  7675. // $.jstree.defaults.plugins.push("search");
  7676. /**
  7677. * ### Sort plugin
  7678. *
  7679. * Automatically sorts all siblings in the tree according to a sorting function.
  7680. */
  7681. /**
  7682. * the settings function used to sort the nodes.
  7683. * It is executed in the tree's context, accepts two nodes as arguments and should return `1` or `-1`.
  7684. * @name $.jstree.defaults.sort
  7685. * @plugin sort
  7686. */
  7687. $.jstree.defaults.sort = function (a, b) {
  7688. //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);
  7689. return this.get_text(a) > this.get_text(b) ? 1 : -1;
  7690. };
  7691. $.jstree.plugins.sort = function (options, parent) {
  7692. this.bind = function () {
  7693. parent.bind.call(this);
  7694. this.element
  7695. .on("model.jstree", $.proxy(function (e, data) {
  7696. this.sort(data.parent, true);
  7697. }, this))
  7698. .on("rename_node.jstree create_node.jstree", $.proxy(function (e, data) {
  7699. this.sort(data.parent || data.node.parent, false);
  7700. this.redraw_node(data.parent || data.node.parent, true);
  7701. }, this))
  7702. .on("move_node.jstree copy_node.jstree", $.proxy(function (e, data) {
  7703. this.sort(data.parent, false);
  7704. this.redraw_node(data.parent, true);
  7705. }, this));
  7706. };
  7707. /**
  7708. * used to sort a node's children
  7709. * @private
  7710. * @name sort(obj [, deep])
  7711. * @param {mixed} obj the node
  7712. * @param {Boolean} deep if set to `true` nodes are sorted recursively.
  7713. * @plugin sort
  7714. * @trigger search.jstree
  7715. */
  7716. this.sort = function (obj, deep) {
  7717. var i, j;
  7718. obj = this.get_node(obj);
  7719. if(obj && obj.children && obj.children.length) {
  7720. obj.children.sort($.proxy(this.settings.sort, this));
  7721. if(deep) {
  7722. for(i = 0, j = obj.children_d.length; i < j; i++) {
  7723. this.sort(obj.children_d[i], false);
  7724. }
  7725. }
  7726. }
  7727. };
  7728. };
  7729. // include the sort plugin by default
  7730. // $.jstree.defaults.plugins.push("sort");
  7731. /**
  7732. * ### State plugin
  7733. *
  7734. * Saves the state of the tree (selected nodes, opened nodes) on the user's computer using available options (localStorage, cookies, etc)
  7735. */
  7736. var to = false;
  7737. /**
  7738. * stores all defaults for the state plugin
  7739. * @name $.jstree.defaults.state
  7740. * @plugin state
  7741. */
  7742. $.jstree.defaults.state = {
  7743. /**
  7744. * A string for the key to use when saving the current tree (change if using multiple trees in your project). Defaults to `jstree`.
  7745. * @name $.jstree.defaults.state.key
  7746. * @plugin state
  7747. */
  7748. key : 'jstree',
  7749. /**
  7750. * A space separated list of events that trigger a state save. Defaults to `changed.jstree open_node.jstree close_node.jstree`.
  7751. * @name $.jstree.defaults.state.events
  7752. * @plugin state
  7753. */
  7754. events : 'changed.jstree open_node.jstree close_node.jstree check_node.jstree uncheck_node.jstree',
  7755. /**
  7756. * Time in milliseconds after which the state will expire. Defaults to 'false' meaning - no expire.
  7757. * @name $.jstree.defaults.state.ttl
  7758. * @plugin state
  7759. */
  7760. ttl : false,
  7761. /**
  7762. * 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.
  7763. * @name $.jstree.defaults.state.filter
  7764. * @plugin state
  7765. */
  7766. filter : false,
  7767. /**
  7768. * 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`
  7769. * @name $.jstree.defaults.state.preserve_loaded
  7770. * @plugin state
  7771. */
  7772. preserve_loaded : false
  7773. };
  7774. $.jstree.plugins.state = function (options, parent) {
  7775. this.bind = function () {
  7776. parent.bind.call(this);
  7777. var bind = $.proxy(function () {
  7778. this.element.on(this.settings.state.events, $.proxy(function () {
  7779. if(to) { clearTimeout(to); }
  7780. to = setTimeout($.proxy(function () { this.save_state(); }, this), 100);
  7781. }, this));
  7782. /**
  7783. * triggered when the state plugin is finished restoring the state (and immediately after ready if there is no state to restore).
  7784. * @event
  7785. * @name state_ready.jstree
  7786. * @plugin state
  7787. */
  7788. this.trigger('state_ready');
  7789. }, this);
  7790. this.element
  7791. .on("ready.jstree", $.proxy(function (e, data) {
  7792. this.element.one("restore_state.jstree", bind);
  7793. if(!this.restore_state()) { bind(); }
  7794. }, this));
  7795. };
  7796. /**
  7797. * save the state
  7798. * @name save_state()
  7799. * @plugin state
  7800. */
  7801. this.save_state = function () {
  7802. var tm = this.get_state();
  7803. if (!this.settings.state.preserve_loaded) {
  7804. delete tm.core.loaded;
  7805. }
  7806. var st = { 'state' : tm, 'ttl' : this.settings.state.ttl, 'sec' : +(new Date()) };
  7807. $.vakata.storage.set(this.settings.state.key, JSON.stringify(st));
  7808. };
  7809. /**
  7810. * restore the state from the user's computer
  7811. * @name restore_state()
  7812. * @plugin state
  7813. */
  7814. this.restore_state = function () {
  7815. var k = $.vakata.storage.get(this.settings.state.key);
  7816. if(!!k) { try { k = JSON.parse(k); } catch(ex) { return false; } }
  7817. if(!!k && k.ttl && k.sec && +(new Date()) - k.sec > k.ttl) { return false; }
  7818. if(!!k && k.state) { k = k.state; }
  7819. if(!!k && $.isFunction(this.settings.state.filter)) { k = this.settings.state.filter.call(this, k); }
  7820. if(!!k) {
  7821. if (!this.settings.state.preserve_loaded) {
  7822. delete k.core.loaded;
  7823. }
  7824. this.element.one("set_state.jstree", function (e, data) { data.instance.trigger('restore_state', { 'state' : $.extend(true, {}, k) }); });
  7825. this.set_state(k);
  7826. return true;
  7827. }
  7828. return false;
  7829. };
  7830. /**
  7831. * clear the state on the user's computer
  7832. * @name clear_state()
  7833. * @plugin state
  7834. */
  7835. this.clear_state = function () {
  7836. return $.vakata.storage.del(this.settings.state.key);
  7837. };
  7838. };
  7839. (function ($, undefined) {
  7840. $.vakata.storage = {
  7841. // simply specifying the functions in FF throws an error
  7842. set : function (key, val) { return window.localStorage.setItem(key, val); },
  7843. get : function (key) { return window.localStorage.getItem(key); },
  7844. del : function (key) { return window.localStorage.removeItem(key); }
  7845. };
  7846. }($));
  7847. // include the state plugin by default
  7848. // $.jstree.defaults.plugins.push("state");
  7849. /**
  7850. * ### Types plugin
  7851. *
  7852. * 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.
  7853. */
  7854. /**
  7855. * 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).
  7856. *
  7857. * * `max_children` the maximum number of immediate children this node type can have. Do not specify or set to `-1` for unlimited.
  7858. * * `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.
  7859. * * `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.
  7860. * * `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.
  7861. * * `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)
  7862. * * `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)
  7863. *
  7864. * There are two predefined types:
  7865. *
  7866. * * `#` represents the root of the tree, for example `max_children` would control the maximum number of root nodes.
  7867. * * `default` represents the default node - any settings here will be applied to all nodes that do not have a type specified.
  7868. *
  7869. * @name $.jstree.defaults.types
  7870. * @plugin types
  7871. */
  7872. $.jstree.defaults.types = {
  7873. 'default' : {}
  7874. };
  7875. $.jstree.defaults.types[$.jstree.root] = {};
  7876. $.jstree.plugins.types = function (options, parent) {
  7877. this.init = function (el, options) {
  7878. var i, j;
  7879. if(options && options.types && options.types['default']) {
  7880. for(i in options.types) {
  7881. if(i !== "default" && i !== $.jstree.root && options.types.hasOwnProperty(i)) {
  7882. for(j in options.types['default']) {
  7883. if(options.types['default'].hasOwnProperty(j) && options.types[i][j] === undefined) {
  7884. options.types[i][j] = options.types['default'][j];
  7885. }
  7886. }
  7887. }
  7888. }
  7889. }
  7890. parent.init.call(this, el, options);
  7891. this._model.data[$.jstree.root].type = $.jstree.root;
  7892. };
  7893. this.refresh = function (skip_loading, forget_state) {
  7894. parent.refresh.call(this, skip_loading, forget_state);
  7895. this._model.data[$.jstree.root].type = $.jstree.root;
  7896. };
  7897. this.bind = function () {
  7898. this.element
  7899. .on('model.jstree', $.proxy(function (e, data) {
  7900. var m = this._model.data,
  7901. dpc = data.nodes,
  7902. t = this.settings.types,
  7903. i, j, c = 'default', k;
  7904. for(i = 0, j = dpc.length; i < j; i++) {
  7905. c = 'default';
  7906. if(m[dpc[i]].original && m[dpc[i]].original.type && t[m[dpc[i]].original.type]) {
  7907. c = m[dpc[i]].original.type;
  7908. }
  7909. if(m[dpc[i]].data && m[dpc[i]].data.jstree && m[dpc[i]].data.jstree.type && t[m[dpc[i]].data.jstree.type]) {
  7910. c = m[dpc[i]].data.jstree.type;
  7911. }
  7912. m[dpc[i]].type = c;
  7913. if(m[dpc[i]].icon === true && t[c].icon !== undefined) {
  7914. m[dpc[i]].icon = t[c].icon;
  7915. }
  7916. if(t[c].li_attr !== undefined && typeof t[c].li_attr === 'object') {
  7917. for (k in t[c].li_attr) {
  7918. if (t[c].li_attr.hasOwnProperty(k)) {
  7919. if (k === 'id') {
  7920. continue;
  7921. }
  7922. else if (m[dpc[i]].li_attr[k] === undefined) {
  7923. m[dpc[i]].li_attr[k] = t[c].li_attr[k];
  7924. }
  7925. else if (k === 'class') {
  7926. m[dpc[i]].li_attr['class'] = t[c].li_attr['class'] + ' ' + m[dpc[i]].li_attr['class'];
  7927. }
  7928. }
  7929. }
  7930. }
  7931. if(t[c].a_attr !== undefined && typeof t[c].a_attr === 'object') {
  7932. for (k in t[c].a_attr) {
  7933. if (t[c].a_attr.hasOwnProperty(k)) {
  7934. if (k === 'id') {
  7935. continue;
  7936. }
  7937. else if (m[dpc[i]].a_attr[k] === undefined) {
  7938. m[dpc[i]].a_attr[k] = t[c].a_attr[k];
  7939. }
  7940. else if (k === 'href' && m[dpc[i]].a_attr[k] === '#') {
  7941. m[dpc[i]].a_attr['href'] = t[c].a_attr['href'];
  7942. }
  7943. else if (k === 'class') {
  7944. m[dpc[i]].a_attr['class'] = t[c].a_attr['class'] + ' ' + m[dpc[i]].a_attr['class'];
  7945. }
  7946. }
  7947. }
  7948. }
  7949. }
  7950. m[$.jstree.root].type = $.jstree.root;
  7951. }, this));
  7952. parent.bind.call(this);
  7953. };
  7954. this.get_json = function (obj, options, flat) {
  7955. var i, j,
  7956. m = this._model.data,
  7957. opt = options ? $.extend(true, {}, options, {no_id:false}) : {},
  7958. tmp = parent.get_json.call(this, obj, opt, flat);
  7959. if(tmp === false) { return false; }
  7960. if($.isArray(tmp)) {
  7961. for(i = 0, j = tmp.length; i < j; i++) {
  7962. tmp[i].type = tmp[i].id && m[tmp[i].id] && m[tmp[i].id].type ? m[tmp[i].id].type : "default";
  7963. if(options && options.no_id) {
  7964. delete tmp[i].id;
  7965. if(tmp[i].li_attr && tmp[i].li_attr.id) {
  7966. delete tmp[i].li_attr.id;
  7967. }
  7968. if(tmp[i].a_attr && tmp[i].a_attr.id) {
  7969. delete tmp[i].a_attr.id;
  7970. }
  7971. }
  7972. }
  7973. }
  7974. else {
  7975. tmp.type = tmp.id && m[tmp.id] && m[tmp.id].type ? m[tmp.id].type : "default";
  7976. if(options && options.no_id) {
  7977. tmp = this._delete_ids(tmp);
  7978. }
  7979. }
  7980. return tmp;
  7981. };
  7982. this._delete_ids = function (tmp) {
  7983. if($.isArray(tmp)) {
  7984. for(var i = 0, j = tmp.length; i < j; i++) {
  7985. tmp[i] = this._delete_ids(tmp[i]);
  7986. }
  7987. return tmp;
  7988. }
  7989. delete tmp.id;
  7990. if(tmp.li_attr && tmp.li_attr.id) {
  7991. delete tmp.li_attr.id;
  7992. }
  7993. if(tmp.a_attr && tmp.a_attr.id) {
  7994. delete tmp.a_attr.id;
  7995. }
  7996. if(tmp.children && $.isArray(tmp.children)) {
  7997. tmp.children = this._delete_ids(tmp.children);
  7998. }
  7999. return tmp;
  8000. };
  8001. this.check = function (chk, obj, par, pos, more) {
  8002. if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
  8003. obj = obj && obj.id ? obj : this.get_node(obj);
  8004. par = par && par.id ? par : this.get_node(par);
  8005. var m = obj && obj.id ? (more && more.origin ? more.origin : $.jstree.reference(obj.id)) : null, tmp, d, i, j;
  8006. m = m && m._model && m._model.data ? m._model.data : null;
  8007. switch(chk) {
  8008. case "create_node":
  8009. case "move_node":
  8010. case "copy_node":
  8011. if(chk !== 'move_node' || $.inArray(obj.id, par.children) === -1) {
  8012. tmp = this.get_rules(par);
  8013. if(tmp.max_children !== undefined && tmp.max_children !== -1 && tmp.max_children === par.children.length) {
  8014. 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 }) };
  8015. return false;
  8016. }
  8017. if(tmp.valid_children !== undefined && tmp.valid_children !== -1 && $.inArray((obj.type || 'default'), tmp.valid_children) === -1) {
  8018. 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 }) };
  8019. return false;
  8020. }
  8021. if(m && obj.children_d && obj.parents) {
  8022. d = 0;
  8023. for(i = 0, j = obj.children_d.length; i < j; i++) {
  8024. d = Math.max(d, m[obj.children_d[i]].parents.length);
  8025. }
  8026. d = d - obj.parents.length + 1;
  8027. }
  8028. if(d <= 0 || d === undefined) { d = 1; }
  8029. do {
  8030. if(tmp.max_depth !== undefined && tmp.max_depth !== -1 && tmp.max_depth < d) {
  8031. 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 }) };
  8032. return false;
  8033. }
  8034. par = this.get_node(par.parent);
  8035. tmp = this.get_rules(par);
  8036. d++;
  8037. } while(par);
  8038. }
  8039. break;
  8040. }
  8041. return true;
  8042. };
  8043. /**
  8044. * used to retrieve the type settings object for a node
  8045. * @name get_rules(obj)
  8046. * @param {mixed} obj the node to find the rules for
  8047. * @return {Object}
  8048. * @plugin types
  8049. */
  8050. this.get_rules = function (obj) {
  8051. obj = this.get_node(obj);
  8052. if(!obj) { return false; }
  8053. var tmp = this.get_type(obj, true);
  8054. if(tmp.max_depth === undefined) { tmp.max_depth = -1; }
  8055. if(tmp.max_children === undefined) { tmp.max_children = -1; }
  8056. if(tmp.valid_children === undefined) { tmp.valid_children = -1; }
  8057. return tmp;
  8058. };
  8059. /**
  8060. * used to retrieve the type string or settings object for a node
  8061. * @name get_type(obj [, rules])
  8062. * @param {mixed} obj the node to find the rules for
  8063. * @param {Boolean} rules if set to `true` instead of a string the settings object will be returned
  8064. * @return {String|Object}
  8065. * @plugin types
  8066. */
  8067. this.get_type = function (obj, rules) {
  8068. obj = this.get_node(obj);
  8069. return (!obj) ? false : ( rules ? $.extend({ 'type' : obj.type }, this.settings.types[obj.type]) : obj.type);
  8070. };
  8071. /**
  8072. * used to change a node's type
  8073. * @name set_type(obj, type)
  8074. * @param {mixed} obj the node to change
  8075. * @param {String} type the new type
  8076. * @plugin types
  8077. */
  8078. this.set_type = function (obj, type) {
  8079. var m = this._model.data, t, t1, t2, old_type, old_icon, k, d, a;
  8080. if($.isArray(obj)) {
  8081. obj = obj.slice();
  8082. for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
  8083. this.set_type(obj[t1], type);
  8084. }
  8085. return true;
  8086. }
  8087. t = this.settings.types;
  8088. obj = this.get_node(obj);
  8089. if(!t[type] || !obj) { return false; }
  8090. d = this.get_node(obj, true);
  8091. if (d && d.length) {
  8092. a = d.children('.jstree-anchor');
  8093. }
  8094. old_type = obj.type;
  8095. old_icon = this.get_icon(obj);
  8096. obj.type = type;
  8097. if(old_icon === true || !t[old_type] || (t[old_type].icon !== undefined && old_icon === t[old_type].icon)) {
  8098. this.set_icon(obj, t[type].icon !== undefined ? t[type].icon : true);
  8099. }
  8100. // remove old type props
  8101. if(t[old_type] && t[old_type].li_attr !== undefined && typeof t[old_type].li_attr === 'object') {
  8102. for (k in t[old_type].li_attr) {
  8103. if (t[old_type].li_attr.hasOwnProperty(k)) {
  8104. if (k === 'id') {
  8105. continue;
  8106. }
  8107. else if (k === 'class') {
  8108. m[obj.id].li_attr['class'] = (m[obj.id].li_attr['class'] || '').replace(t[old_type].li_attr[k], '');
  8109. if (d) { d.removeClass(t[old_type].li_attr[k]); }
  8110. }
  8111. else if (m[obj.id].li_attr[k] === t[old_type].li_attr[k]) {
  8112. m[obj.id].li_attr[k] = null;
  8113. if (d) { d.removeAttr(k); }
  8114. }
  8115. }
  8116. }
  8117. }
  8118. if(t[old_type] && t[old_type].a_attr !== undefined && typeof t[old_type].a_attr === 'object') {
  8119. for (k in t[old_type].a_attr) {
  8120. if (t[old_type].a_attr.hasOwnProperty(k)) {
  8121. if (k === 'id') {
  8122. continue;
  8123. }
  8124. else if (k === 'class') {
  8125. m[obj.id].a_attr['class'] = (m[obj.id].a_attr['class'] || '').replace(t[old_type].a_attr[k], '');
  8126. if (a) { a.removeClass(t[old_type].a_attr[k]); }
  8127. }
  8128. else if (m[obj.id].a_attr[k] === t[old_type].a_attr[k]) {
  8129. if (k === 'href') {
  8130. m[obj.id].a_attr[k] = '#';
  8131. if (a) { a.attr('href', '#'); }
  8132. }
  8133. else {
  8134. delete m[obj.id].a_attr[k];
  8135. if (a) { a.removeAttr(k); }
  8136. }
  8137. }
  8138. }
  8139. }
  8140. }
  8141. // add new props
  8142. if(t[type].li_attr !== undefined && typeof t[type].li_attr === 'object') {
  8143. for (k in t[type].li_attr) {
  8144. if (t[type].li_attr.hasOwnProperty(k)) {
  8145. if (k === 'id') {
  8146. continue;
  8147. }
  8148. else if (m[obj.id].li_attr[k] === undefined) {
  8149. m[obj.id].li_attr[k] = t[type].li_attr[k];
  8150. if (d) {
  8151. if (k === 'class') {
  8152. d.addClass(t[type].li_attr[k]);
  8153. }
  8154. else {
  8155. d.attr(k, t[type].li_attr[k]);
  8156. }
  8157. }
  8158. }
  8159. else if (k === 'class') {
  8160. m[obj.id].li_attr['class'] = t[type].li_attr[k] + ' ' + m[obj.id].li_attr['class'];
  8161. if (d) { d.addClass(t[type].li_attr[k]); }
  8162. }
  8163. }
  8164. }
  8165. }
  8166. if(t[type].a_attr !== undefined && typeof t[type].a_attr === 'object') {
  8167. for (k in t[type].a_attr) {
  8168. if (t[type].a_attr.hasOwnProperty(k)) {
  8169. if (k === 'id') {
  8170. continue;
  8171. }
  8172. else if (m[obj.id].a_attr[k] === undefined) {
  8173. m[obj.id].a_attr[k] = t[type].a_attr[k];
  8174. if (a) {
  8175. if (k === 'class') {
  8176. a.addClass(t[type].a_attr[k]);
  8177. }
  8178. else {
  8179. a.attr(k, t[type].a_attr[k]);
  8180. }
  8181. }
  8182. }
  8183. else if (k === 'href' && m[obj.id].a_attr[k] === '#') {
  8184. m[obj.id].a_attr['href'] = t[type].a_attr['href'];
  8185. if (a) { a.attr('href', t[type].a_attr['href']); }
  8186. }
  8187. else if (k === 'class') {
  8188. m[obj.id].a_attr['class'] = t[type].a_attr['class'] + ' ' + m[obj.id].a_attr['class'];
  8189. if (a) { a.addClass(t[type].a_attr[k]); }
  8190. }
  8191. }
  8192. }
  8193. }
  8194. return true;
  8195. };
  8196. };
  8197. // include the types plugin by default
  8198. // $.jstree.defaults.plugins.push("types");
  8199. /**
  8200. * ### Unique plugin
  8201. *
  8202. * Enforces that no nodes with the same name can coexist as siblings.
  8203. */
  8204. /**
  8205. * stores all defaults for the unique plugin
  8206. * @name $.jstree.defaults.unique
  8207. * @plugin unique
  8208. */
  8209. $.jstree.defaults.unique = {
  8210. /**
  8211. * Indicates if the comparison should be case sensitive. Default is `false`.
  8212. * @name $.jstree.defaults.unique.case_sensitive
  8213. * @plugin unique
  8214. */
  8215. case_sensitive : false,
  8216. /**
  8217. * Indicates if white space should be trimmed before the comparison. Default is `false`.
  8218. * @name $.jstree.defaults.unique.trim_whitespace
  8219. * @plugin unique
  8220. */
  8221. trim_whitespace : false,
  8222. /**
  8223. * 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)`.
  8224. * @name $.jstree.defaults.unique.duplicate
  8225. * @plugin unique
  8226. */
  8227. duplicate : function (name, counter) {
  8228. return name + ' (' + counter + ')';
  8229. }
  8230. };
  8231. $.jstree.plugins.unique = function (options, parent) {
  8232. this.check = function (chk, obj, par, pos, more) {
  8233. if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
  8234. obj = obj && obj.id ? obj : this.get_node(obj);
  8235. par = par && par.id ? par : this.get_node(par);
  8236. if(!par || !par.children) { return true; }
  8237. var n = chk === "rename_node" ? pos : obj.text,
  8238. c = [],
  8239. s = this.settings.unique.case_sensitive,
  8240. w = this.settings.unique.trim_whitespace,
  8241. m = this._model.data, i, j, t;
  8242. for(i = 0, j = par.children.length; i < j; i++) {
  8243. t = m[par.children[i]].text;
  8244. if (!s) {
  8245. t = t.toLowerCase();
  8246. }
  8247. if (w) {
  8248. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8249. }
  8250. c.push(t);
  8251. }
  8252. if(!s) { n = n.toLowerCase(); }
  8253. if (w) { n = n.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }
  8254. switch(chk) {
  8255. case "delete_node":
  8256. return true;
  8257. case "rename_node":
  8258. t = obj.text || '';
  8259. if (!s) {
  8260. t = t.toLowerCase();
  8261. }
  8262. if (w) {
  8263. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8264. }
  8265. i = ($.inArray(n, c) === -1 || (obj.text && t === n));
  8266. if(!i) {
  8267. 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 }) };
  8268. }
  8269. return i;
  8270. case "create_node":
  8271. i = ($.inArray(n, c) === -1);
  8272. if(!i) {
  8273. 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 }) };
  8274. }
  8275. return i;
  8276. case "copy_node":
  8277. i = ($.inArray(n, c) === -1);
  8278. if(!i) {
  8279. 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 }) };
  8280. }
  8281. return i;
  8282. case "move_node":
  8283. i = ( (obj.parent === par.id && (!more || !more.is_multi)) || $.inArray(n, c) === -1);
  8284. if(!i) {
  8285. 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 }) };
  8286. }
  8287. return i;
  8288. }
  8289. return true;
  8290. };
  8291. this.create_node = function (par, node, pos, callback, is_loaded) {
  8292. if(!node || node.text === undefined) {
  8293. if(par === null) {
  8294. par = $.jstree.root;
  8295. }
  8296. par = this.get_node(par);
  8297. if(!par) {
  8298. return parent.create_node.call(this, par, node, pos, callback, is_loaded);
  8299. }
  8300. pos = pos === undefined ? "last" : pos;
  8301. if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
  8302. return parent.create_node.call(this, par, node, pos, callback, is_loaded);
  8303. }
  8304. if(!node) { node = {}; }
  8305. 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;
  8306. n = tmp = this.get_string('New node');
  8307. dpc = [];
  8308. for(i = 0, j = par.children.length; i < j; i++) {
  8309. t = m[par.children[i]].text;
  8310. if (!s) {
  8311. t = t.toLowerCase();
  8312. }
  8313. if (w) {
  8314. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8315. }
  8316. dpc.push(t);
  8317. }
  8318. i = 1;
  8319. t = n;
  8320. if (!s) {
  8321. t = t.toLowerCase();
  8322. }
  8323. if (w) {
  8324. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8325. }
  8326. while($.inArray(t, dpc) !== -1) {
  8327. n = cb.call(this, tmp, (++i)).toString();
  8328. t = n;
  8329. if (!s) {
  8330. t = t.toLowerCase();
  8331. }
  8332. if (w) {
  8333. t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8334. }
  8335. }
  8336. node.text = n;
  8337. }
  8338. return parent.create_node.call(this, par, node, pos, callback, is_loaded);
  8339. };
  8340. };
  8341. // include the unique plugin by default
  8342. // $.jstree.defaults.plugins.push("unique");
  8343. /**
  8344. * ### Wholerow plugin
  8345. *
  8346. * Makes each node appear block level. Making selection easier. May cause slow down for large trees in old browsers.
  8347. */
  8348. var div = document.createElement('DIV');
  8349. div.setAttribute('unselectable','on');
  8350. div.setAttribute('role','presentation');
  8351. div.className = 'jstree-wholerow';
  8352. div.innerHTML = '&#160;';
  8353. $.jstree.plugins.wholerow = function (options, parent) {
  8354. this.bind = function () {
  8355. parent.bind.call(this);
  8356. this.element
  8357. .on('ready.jstree set_state.jstree', $.proxy(function () {
  8358. this.hide_dots();
  8359. }, this))
  8360. .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
  8361. //div.style.height = this._data.core.li_height + 'px';
  8362. this.get_container_ul().addClass('jstree-wholerow-ul');
  8363. }, this))
  8364. .on("deselect_all.jstree", $.proxy(function (e, data) {
  8365. this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
  8366. }, this))
  8367. .on("changed.jstree", $.proxy(function (e, data) {
  8368. this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
  8369. var tmp = false, i, j;
  8370. for(i = 0, j = data.selected.length; i < j; i++) {
  8371. tmp = this.get_node(data.selected[i], true);
  8372. if(tmp && tmp.length) {
  8373. tmp.children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
  8374. }
  8375. }
  8376. }, this))
  8377. .on("open_node.jstree", $.proxy(function (e, data) {
  8378. this.get_node(data.node, true).find('.jstree-clicked').parent().children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
  8379. }, this))
  8380. .on("hover_node.jstree dehover_node.jstree", $.proxy(function (e, data) {
  8381. if(e.type === "hover_node" && this.is_disabled(data.node)) { return; }
  8382. this.get_node(data.node, true).children('.jstree-wholerow')[e.type === "hover_node"?"addClass":"removeClass"]('jstree-wholerow-hovered');
  8383. }, this))
  8384. .on("contextmenu.jstree", ".jstree-wholerow", $.proxy(function (e) {
  8385. if (this._data.contextmenu) {
  8386. e.preventDefault();
  8387. var tmp = $.Event('contextmenu', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey, pageX : e.pageX, pageY : e.pageY });
  8388. $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp);
  8389. }
  8390. }, this))
  8391. /*!
  8392. .on("mousedown.jstree touchstart.jstree", ".jstree-wholerow", function (e) {
  8393. if(e.target === e.currentTarget) {
  8394. var a = $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor");
  8395. e.target = a[0];
  8396. a.trigger(e);
  8397. }
  8398. })
  8399. */
  8400. .on("click.jstree", ".jstree-wholerow", function (e) {
  8401. e.stopImmediatePropagation();
  8402. var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
  8403. $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
  8404. })
  8405. .on("dblclick.jstree", ".jstree-wholerow", function (e) {
  8406. e.stopImmediatePropagation();
  8407. var tmp = $.Event('dblclick', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
  8408. $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
  8409. })
  8410. .on("click.jstree", ".jstree-leaf > .jstree-ocl", $.proxy(function (e) {
  8411. e.stopImmediatePropagation();
  8412. var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
  8413. $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
  8414. }, this))
  8415. .on("mouseover.jstree", ".jstree-wholerow, .jstree-icon", $.proxy(function (e) {
  8416. e.stopImmediatePropagation();
  8417. if(!this.is_disabled(e.currentTarget)) {
  8418. this.hover_node(e.currentTarget);
  8419. }
  8420. return false;
  8421. }, this))
  8422. .on("mouseleave.jstree", ".jstree-node", $.proxy(function (e) {
  8423. this.dehover_node(e.currentTarget);
  8424. }, this));
  8425. };
  8426. this.teardown = function () {
  8427. if(this.settings.wholerow) {
  8428. this.element.find(".jstree-wholerow").remove();
  8429. }
  8430. parent.teardown.call(this);
  8431. };
  8432. this.redraw_node = function(obj, deep, callback, force_render) {
  8433. obj = parent.redraw_node.apply(this, arguments);
  8434. if(obj) {
  8435. var tmp = div.cloneNode(true);
  8436. //tmp.style.height = this._data.core.li_height + 'px';
  8437. if($.inArray(obj.id, this._data.core.selected) !== -1) { tmp.className += ' jstree-wholerow-clicked'; }
  8438. if(this._data.core.focused && this._data.core.focused === obj.id) { tmp.className += ' jstree-wholerow-hovered'; }
  8439. obj.insertBefore(tmp, obj.childNodes[0]);
  8440. }
  8441. return obj;
  8442. };
  8443. };
  8444. // include the wholerow plugin by default
  8445. // $.jstree.defaults.plugins.push("wholerow");
  8446. if(window.customElements && Object && Object.create) {
  8447. var proto = Object.create(HTMLElement.prototype);
  8448. proto.createdCallback = function () {
  8449. var c = { core : {}, plugins : [] }, i;
  8450. for(i in $.jstree.plugins) {
  8451. if($.jstree.plugins.hasOwnProperty(i) && this.attributes[i]) {
  8452. c.plugins.push(i);
  8453. if(this.getAttribute(i) && JSON.parse(this.getAttribute(i))) {
  8454. c[i] = JSON.parse(this.getAttribute(i));
  8455. }
  8456. }
  8457. }
  8458. for(i in $.jstree.defaults.core) {
  8459. if($.jstree.defaults.core.hasOwnProperty(i) && this.attributes[i]) {
  8460. c.core[i] = JSON.parse(this.getAttribute(i)) || this.getAttribute(i);
  8461. }
  8462. }
  8463. $(this).jstree(c);
  8464. };
  8465. // proto.attributeChangedCallback = function (name, previous, value) { };
  8466. try {
  8467. window.customElements.define("vakata-jstree", function() {}, { prototype: proto });
  8468. } catch (ignore) { }
  8469. }
  8470. }));