12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738 |
- (function (factory) {
- "use strict";
- if (typeof define === 'function' && define.amd) {
- define(['jquery'], factory);
- }
- else if(typeof module !== 'undefined' && module.exports) {
- module.exports = factory(require('jquery'));
- }
- else {
- factory(jQuery);
- }
- }(function ($, undefined) {
- "use strict";
-
- if($.jstree) {
- return;
- }
-
-
- var instance_counter = 0,
- ccp_node = false,
- ccp_mode = false,
- ccp_inst = false,
- themes_loaded = [],
- src = $('script:last').attr('src'),
- document = window.document;
- var setImmediate = window.setImmediate;
- var Promise = window.Promise;
- if (!setImmediate && Promise) {
-
- setImmediate = function (cb, arg) {
- Promise.resolve(arg).then(cb);
- };
- }
-
- $.jstree = {
-
- version : '3.3.15',
-
- defaults : {
-
- plugins : []
- },
-
- plugins : {},
- path : src && src.indexOf('/') !== -1 ? src.replace(/\/[^\/]+$/,'') : '',
- idregex : /[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g,
- root : '#'
- };
-
-
- $.jstree.create = function (el, options) {
- var tmp = new $.jstree.core(++instance_counter),
- opt = options;
- options = $.extend(true, {}, $.jstree.defaults, options);
- if(opt && opt.plugins) {
- options.plugins = opt.plugins;
- }
- $.each(options.plugins, function (i, k) {
- if(i !== 'core') {
- tmp = tmp.plugin(k, options[k]);
- }
- });
- $(el).data('jstree', tmp);
- tmp.init(el, options);
- return tmp;
- };
-
- $.jstree.destroy = function () {
- $('.jstree:jstree').jstree('destroy');
- $(document).off('.jstree');
- };
-
- $.jstree.core = function (id) {
- this._id = id;
- this._cnt = 0;
- this._wrk = null;
- this._data = {
- core : {
- themes : {
- name : false,
- dots : false,
- icons : false,
- ellipsis : false
- },
- selected : [],
- last_error : {},
- working : false,
- worker_queue : [],
- focused : null
- }
- };
- };
-
- $.jstree.reference = function (needle) {
- var tmp = null,
- obj = null;
- if(needle && needle.id && (!needle.tagName || !needle.nodeType)) { needle = needle.id; }
- if(!obj || !obj.length) {
- try { obj = $(needle); } catch (ignore) { }
- }
- if(!obj || !obj.length) {
- try { obj = $('#' + needle.replace($.jstree.idregex,'\\$&')); } catch (ignore) { }
- }
- if(obj && obj.length && (obj = obj.closest('.jstree')).length && (obj = obj.data('jstree'))) {
- tmp = obj;
- }
- else {
- $('.jstree').each(function () {
- var inst = $(this).data('jstree');
- if(inst && inst._model.data[needle]) {
- tmp = inst;
- return false;
- }
- });
- }
- return tmp;
- };
-
- $.fn.jstree = function (arg) {
-
- var is_method = (typeof arg === 'string'),
- args = Array.prototype.slice.call(arguments, 1),
- result = null;
- if(arg === true && !this.length) { return false; }
- this.each(function () {
-
- var instance = $.jstree.reference(this),
- method = is_method && instance ? instance[arg] : null;
-
- result = is_method && method ?
- method.apply(instance, args) :
- null;
-
- if(!instance && !is_method && (arg === undefined || $.isPlainObject(arg))) {
- $.jstree.create(this, arg);
- }
-
- if( (instance && !is_method) || arg === true ) {
- result = instance || false;
- }
-
- if(result !== null && result !== undefined) {
- return false;
- }
- });
-
- return result !== null && result !== undefined ?
- result : this;
- };
-
- $.expr.pseudos.jstree = $.expr.createPseudo(function(search) {
- return function(a) {
- return $(a).hasClass('jstree') &&
- $(a).data('jstree') !== undefined;
- };
- });
-
- $.jstree.defaults.core = {
-
- data : false,
-
- strings : false,
-
- check_callback : false,
-
- error : $.noop,
-
- animation : 200,
-
- multiple : true,
-
- themes : {
-
- name : false,
-
- url : false,
-
- dir : false,
-
- dots : true,
-
- icons : true,
-
- ellipsis : false,
-
- stripes : false,
-
- variant : false,
-
- responsive : false
- },
-
- expand_selected_onload : true,
-
- worker : true,
-
- force_text : false,
-
- dblclick_toggle : true,
-
- loaded_state : false,
-
- restore_focus : true,
-
- compute_elements_positions : false,
-
- keyboard : {
- 'ctrl-space': function (e) {
-
- e.type = "click";
- $(e.currentTarget).trigger(e);
- },
- 'enter': function (e) {
-
- e.type = "click";
- $(e.currentTarget).trigger(e);
- },
- 'left': function (e) {
-
- e.preventDefault();
- if(this.is_open(e.currentTarget)) {
- this.close_node(e.currentTarget);
- }
- else {
- var o = this.get_parent(e.currentTarget);
- if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').trigger('focus'); }
- }
- },
- 'up': function (e) {
-
- e.preventDefault();
- var o = this.get_prev_dom(e.currentTarget);
- if(o && o.length) { o.children('.jstree-anchor').trigger('focus'); }
- },
- 'right': function (e) {
-
- e.preventDefault();
- if(this.is_closed(e.currentTarget)) {
- this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').trigger('focus'); });
- }
- else if (this.is_open(e.currentTarget)) {
- var o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
- if(o) { $(this._firstChild(o)).children('.jstree-anchor').trigger('focus'); }
- }
- },
- 'down': function (e) {
-
- e.preventDefault();
- var o = this.get_next_dom(e.currentTarget);
- if(o && o.length) { o.children('.jstree-anchor').trigger('focus'); }
- },
- '*': function (e) {
-
- this.open_all();
- },
- 'home': function (e) {
-
- e.preventDefault();
- var o = this._firstChild(this.get_container_ul()[0]);
- if(o) { $(o).children('.jstree-anchor').filter(':visible').trigger('focus'); }
- },
- 'end': function (e) {
-
- e.preventDefault();
- this.element.find('.jstree-anchor').filter(':visible').last().trigger('focus');
- },
- 'f2': function (e) {
-
- e.preventDefault();
- this.edit(e.currentTarget);
- }
- }
- };
- $.jstree.core.prototype = {
-
- plugin : function (deco, opts) {
- var Child = $.jstree.plugins[deco];
- if(Child) {
- this._data[deco] = {};
- Child.prototype = this;
- return new Child(opts, this);
- }
- return this;
- },
-
- init : function (el, options) {
- this._model = {
- data : {},
- changed : [],
- force_full_redraw : false,
- redraw_timeout : false,
- default_state : {
- loaded : true,
- opened : false,
- selected : false,
- disabled : false
- }
- };
- this._model.data[$.jstree.root] = {
- id : $.jstree.root,
- parent : null,
- parents : [],
- children : [],
- children_d : [],
- state : { loaded : false }
- };
- this.element = $(el).addClass('jstree jstree-' + this._id);
- this.settings = options;
- this._data.core.ready = false;
- this._data.core.loaded = false;
- this._data.core.rtl = (this.element.css("direction") === "rtl");
- this.element[this._data.core.rtl ? 'addClass' : 'removeClass']("jstree-rtl");
- this.element.attr('role','tree');
- if(this.settings.core.multiple) {
- this.element.attr('aria-multiselectable', true);
- }
- if(!this.element.attr('tabindex')) {
- this.element.attr('tabindex','0');
- }
- this.bind();
-
- this.trigger("init");
- this._data.core.original_container_html = this.element.find(" > ul > li").clone(true);
- this._data.core.original_container_html
- .find("li").addBack()
- .contents().filter(function() {
- return this.nodeType === 3 && (!this.nodeValue || /^\s+$/.test(this.nodeValue));
- })
- .remove();
- 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='none'><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>");
- this.element.attr('aria-activedescendant','j' + this._id + '_loading');
- this._data.core.li_height = this.get_container_ul().children("li").first().outerHeight() || 24;
- this._data.core.node = this._create_prototype_node();
-
- this.trigger("loading");
- this.load_node($.jstree.root);
- },
-
- destroy : function (keep_html) {
-
- this.trigger("destroy");
- if(this._wrk) {
- try {
- window.URL.revokeObjectURL(this._wrk);
- this._wrk = null;
- }
- catch (ignore) { }
- }
- if(!keep_html) { this.element.empty(); }
- this.teardown();
- },
-
- _create_prototype_node : function () {
- var _node = document.createElement('LI'), _temp1, _temp2;
- _node.setAttribute('role', 'none');
- _temp1 = document.createElement('I');
- _temp1.className = 'jstree-icon jstree-ocl';
- _temp1.setAttribute('role', 'presentation');
- _node.appendChild(_temp1);
- _temp1 = document.createElement('A');
- _temp1.className = 'jstree-anchor';
- _temp1.setAttribute('href','#');
- _temp1.setAttribute('tabindex','-1');
- _temp1.setAttribute('role', 'treeitem');
- _temp2 = document.createElement('I');
- _temp2.className = 'jstree-icon jstree-themeicon';
- _temp2.setAttribute('role', 'presentation');
- _temp1.appendChild(_temp2);
- _node.appendChild(_temp1);
- _temp1 = _temp2 = null;
- return _node;
- },
- _kbevent_to_func : function (e) {
- var keys = {
- 8: "Backspace", 9: "Tab", 13: "Enter", 19: "Pause", 27: "Esc",
- 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home",
- 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "Print", 45: "Insert",
- 46: "Delete", 96: "Numpad0", 97: "Numpad1", 98: "Numpad2", 99 : "Numpad3",
- 100: "Numpad4", 101: "Numpad5", 102: "Numpad6", 103: "Numpad7",
- 104: "Numpad8", 105: "Numpad9", '-13': "NumpadEnter", 112: "F1",
- 113: "F2", 114: "F3", 115: "F4", 116: "F5", 117: "F6", 118: "F7",
- 119: "F8", 120: "F9", 121: "F10", 122: "F11", 123: "F12", 144: "Numlock",
- 145: "Scrolllock", 16: 'Shift', 17: 'Ctrl', 18: 'Alt',
- 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
- 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
- 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
- 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
- 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
- 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
- 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
- 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*', 173: '-'
- };
- var parts = [];
- if (e.ctrlKey) { parts.push('ctrl'); }
- if (e.altKey) { parts.push('alt'); }
- if (e.shiftKey) { parts.push('shift'); }
- parts.push(keys[e.which] ? keys[e.which].toLowerCase() : e.which);
- parts = parts.sort().join('-').toLowerCase();
- if (parts === 'shift-shift' || parts === 'ctrl-ctrl' || parts === 'alt-alt') {
- return null;
- }
- var kb = this.settings.core.keyboard, i, tmp;
- for (i in kb) {
- if (kb.hasOwnProperty(i)) {
- tmp = i;
- if (tmp !== '-' && tmp !== '+') {
- tmp = tmp.replace('--', '-MINUS').replace('+-', '-MINUS').replace('++', '-PLUS').replace('-+', '-PLUS');
- tmp = tmp.split(/-|\+/).sort().join('-').replace('MINUS', '-').replace('PLUS', '+').toLowerCase();
- }
- if (tmp === parts) {
- return kb[i];
- }
- }
- }
- return null;
- },
-
- teardown : function () {
- this.unbind();
- this.element
- .removeClass('jstree')
- .removeData('jstree')
- .find("[class^='jstree']")
- .addBack()
- .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });
- this.element = null;
- },
-
- bind : function () {
- var word = '',
- tout = null,
- was_click = 0;
- this.element
- .on("dblclick.jstree", function (e) {
- if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
- if(document.selection && document.selection.empty) {
- document.selection.empty();
- }
- else {
- if(window.getSelection) {
- var sel = window.getSelection();
- try {
- sel.removeAllRanges();
- sel.collapse();
- } catch (ignore) { }
- }
- }
- })
- .on("mousedown.jstree", function (e) {
- if(e.target === this.element[0]) {
- e.preventDefault();
- was_click = +(new Date());
- }
- }.bind(this))
- .on("mousedown.jstree", ".jstree-ocl", function (e) {
- e.preventDefault();
- })
- .on("click.jstree", ".jstree-ocl", function (e) {
- this.toggle_node(e.target);
- }.bind(this))
- .on("dblclick.jstree", ".jstree-anchor", function (e) {
- if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
- if(this.settings.core.dblclick_toggle) {
- this.toggle_node(e.target);
- }
- }.bind(this))
- .on("click.jstree", ".jstree-anchor", function (e) {
- e.preventDefault();
- if(e.currentTarget !== document.activeElement) { $(e.currentTarget).trigger('focus'); }
- this.activate_node(e.currentTarget, e);
- }.bind(this))
- .on('keydown.jstree', '.jstree-anchor', function (e) {
- if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
- if(this._data.core.rtl) {
- if(e.which === 37) { e.which = 39; }
- else if(e.which === 39) { e.which = 37; }
- }
- var f = this._kbevent_to_func(e);
- if (f) {
- var r = f.call(this, e);
- if (r === false || r === true) {
- return r;
- }
- }
- }.bind(this))
- .on("load_node.jstree", function (e, data) {
- if(data.status) {
- if(data.node.id === $.jstree.root && !this._data.core.loaded) {
- this._data.core.loaded = true;
- if(this._firstChild(this.get_container_ul()[0])) {
- this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
- }
-
- this.trigger("loaded");
- }
- if(!this._data.core.ready) {
- setTimeout(function() {
- if(this.element && !this.get_container_ul().find('.jstree-loading').length) {
- this._data.core.ready = true;
- if(this._data.core.selected.length) {
- if(this.settings.core.expand_selected_onload) {
- var tmp = [], i, j;
- for(i = 0, j = this._data.core.selected.length; i < j; i++) {
- tmp = tmp.concat(this._model.data[this._data.core.selected[i]].parents);
- }
- tmp = $.vakata.array_unique(tmp);
- for(i = 0, j = tmp.length; i < j; i++) {
- this.open_node(tmp[i], false, 0);
- }
- }
- this.trigger('changed', { 'action' : 'ready', 'selected' : this._data.core.selected });
- }
-
- this.trigger("ready");
- }
- }.bind(this), 0);
- }
- }
- }.bind(this))
-
- .on('keypress.jstree', function (e) {
- if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
- if(tout) { clearTimeout(tout); }
- tout = setTimeout(function () {
- word = '';
- }, 500);
- var chr = String.fromCharCode(e.which).toLowerCase(),
- col = this.element.find('.jstree-anchor').filter(':visible'),
- ind = col.index(document.activeElement) || 0,
- end = false;
- word += chr;
-
- if(word.length > 1) {
- col.slice(ind).each(function (i, v) {
- if($(v).text().toLowerCase().indexOf(word) === 0) {
- $(v).trigger('focus');
- end = true;
- return false;
- }
- }.bind(this));
- if(end) { return; }
-
- col.slice(0, ind).each(function (i, v) {
- if($(v).text().toLowerCase().indexOf(word) === 0) {
- $(v).trigger('focus');
- end = true;
- return false;
- }
- }.bind(this));
- if(end) { return; }
- }
-
- if(new RegExp('^' + chr.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '+$').test(word)) {
-
- col.slice(ind + 1).each(function (i, v) {
- if($(v).text().toLowerCase().charAt(0) === chr) {
- $(v).trigger('focus');
- end = true;
- return false;
- }
- }.bind(this));
- if(end) { return; }
-
- col.slice(0, ind + 1).each(function (i, v) {
- if($(v).text().toLowerCase().charAt(0) === chr) {
- $(v).trigger('focus');
- end = true;
- return false;
- }
- }.bind(this));
- if(end) { return; }
- }
- }.bind(this))
-
- .on("init.jstree", function () {
- var s = this.settings.core.themes;
- this._data.core.themes.dots = s.dots;
- this._data.core.themes.stripes = s.stripes;
- this._data.core.themes.icons = s.icons;
- this._data.core.themes.ellipsis = s.ellipsis;
- this.set_theme(s.name || "default", s.url);
- this.set_theme_variant(s.variant);
- }.bind(this))
- .on("loading.jstree", function () {
- this[ this._data.core.themes.dots ? "show_dots" : "hide_dots" ]();
- this[ this._data.core.themes.icons ? "show_icons" : "hide_icons" ]();
- this[ this._data.core.themes.stripes ? "show_stripes" : "hide_stripes" ]();
- this[ this._data.core.themes.ellipsis ? "show_ellipsis" : "hide_ellipsis" ]();
- }.bind(this))
- .on('blur.jstree', '.jstree-anchor', function (e) {
- this._data.core.focused = null;
- $(e.currentTarget).filter('.jstree-hovered').trigger('mouseleave');
- this.element.attr('tabindex', '0');
- $(e.currentTarget).attr('tabindex', '-1');
- }.bind(this))
- .on('focus.jstree', '.jstree-anchor', function (e) {
- var tmp = this.get_node(e.currentTarget);
- if(tmp && (tmp.id || tmp.id === 0)) {
- this._data.core.focused = tmp.id;
- }
- this.element.find('.jstree-hovered').not(e.currentTarget).trigger('mouseleave');
- $(e.currentTarget).trigger('mouseenter');
- this.element.attr('tabindex', '-1');
- $(e.currentTarget).attr('tabindex', '0');
- }.bind(this))
- .on('focus.jstree', function () {
- if(+(new Date()) - was_click > 500 && !this._data.core.focused && this.settings.core.restore_focus) {
- was_click = 0;
- var act = this.get_node(this.element.attr('aria-activedescendant'), true);
- if(act) {
- act.find('> .jstree-anchor').trigger('focus');
- }
- }
- }.bind(this))
- .on('mouseenter.jstree', '.jstree-anchor', function (e) {
- this.hover_node(e.currentTarget);
- }.bind(this))
- .on('mouseleave.jstree', '.jstree-anchor', function (e) {
- this.dehover_node(e.currentTarget);
- }.bind(this));
- },
-
- unbind : function () {
- this.element.off('.jstree');
- $(document).off('.jstree-' + this._id);
- },
-
- trigger : function (ev, data) {
- if(!data) {
- data = {};
- }
- data.instance = this;
- this.element.triggerHandler(ev.replace('.jstree','') + '.jstree', data);
- },
-
- get_container : function () {
- return this.element;
- },
-
- get_container_ul : function () {
- return this.element.children(".jstree-children").first();
- },
-
- get_string : function (key) {
- var a = this.settings.core.strings;
- if($.vakata.is_function(a)) { return a.call(this, key); }
- if(a && a[key]) { return a[key]; }
- return key;
- },
-
- _firstChild : function (dom) {
- dom = dom ? dom.firstChild : null;
- while(dom !== null && dom.nodeType !== 1) {
- dom = dom.nextSibling;
- }
- return dom;
- },
-
- _nextSibling : function (dom) {
- dom = dom ? dom.nextSibling : null;
- while(dom !== null && dom.nodeType !== 1) {
- dom = dom.nextSibling;
- }
- return dom;
- },
-
- _previousSibling : function (dom) {
- dom = dom ? dom.previousSibling : null;
- while(dom !== null && dom.nodeType !== 1) {
- dom = dom.previousSibling;
- }
- return dom;
- },
-
- get_node : function (obj, as_dom) {
- if(obj && (obj.id || obj.id === 0)) {
- obj = obj.id;
- }
- if (obj instanceof $ && obj.length && obj[0].id) {
- obj = obj[0].id;
- }
- var dom;
- try {
- if(this._model.data[obj]) {
- obj = this._model.data[obj];
- }
- else if(typeof obj === "string" && this._model.data[obj.replace(/^#/, '')]) {
- obj = this._model.data[obj.replace(/^#/, '')];
- }
- else if(typeof obj === "string" && (dom = $('#' + obj.replace($.jstree.idregex,'\\$&'), this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
- obj = this._model.data[dom.closest('.jstree-node').attr('id')];
- }
- else if((dom = this.element.find(obj)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
- obj = this._model.data[dom.closest('.jstree-node').attr('id')];
- }
- else if((dom = this.element.find(obj)).length && dom.hasClass('jstree')) {
- obj = this._model.data[$.jstree.root];
- }
- else {
- return false;
- }
- if(as_dom) {
- obj = obj.id === $.jstree.root ? this.element : $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
- }
- return obj;
- } catch (ex) { return false; }
- },
-
- get_path : function (obj, glue, ids) {
- obj = obj.parents ? obj : this.get_node(obj);
- if(!obj || obj.id === $.jstree.root || !obj.parents) {
- return false;
- }
- var i, j, p = [];
- p.push(ids ? obj.id : obj.text);
- for(i = 0, j = obj.parents.length; i < j; i++) {
- p.push(ids ? obj.parents[i] : this.get_text(obj.parents[i]));
- }
- p = p.reverse().slice(1);
- return glue ? p.join(glue) : p;
- },
-
- get_next_dom : function (obj, strict) {
- var tmp;
- obj = this.get_node(obj, true);
- if(obj[0] === this.element[0]) {
- tmp = this._firstChild(this.get_container_ul()[0]);
- while (tmp && tmp.offsetHeight === 0) {
- tmp = this._nextSibling(tmp);
- }
- return tmp ? $(tmp) : false;
- }
- if(!obj || !obj.length) {
- return false;
- }
- if(strict) {
- tmp = obj[0];
- do {
- tmp = this._nextSibling(tmp);
- } while (tmp && tmp.offsetHeight === 0);
- return tmp ? $(tmp) : false;
- }
- if(obj.hasClass("jstree-open")) {
- tmp = this._firstChild(obj.children('.jstree-children')[0]);
- while (tmp && tmp.offsetHeight === 0) {
- tmp = this._nextSibling(tmp);
- }
- if(tmp !== null) {
- return $(tmp);
- }
- }
- tmp = obj[0];
- do {
- tmp = this._nextSibling(tmp);
- } while (tmp && tmp.offsetHeight === 0);
- if(tmp !== null) {
- return $(tmp);
- }
- return obj.parentsUntil(".jstree",".jstree-node").nextAll(".jstree-node:visible").first();
- },
-
- get_prev_dom : function (obj, strict) {
- var tmp;
- obj = this.get_node(obj, true);
- if(obj[0] === this.element[0]) {
- tmp = this.get_container_ul()[0].lastChild;
- while (tmp && tmp.offsetHeight === 0) {
- tmp = this._previousSibling(tmp);
- }
- return tmp ? $(tmp) : false;
- }
- if(!obj || !obj.length) {
- return false;
- }
- if(strict) {
- tmp = obj[0];
- do {
- tmp = this._previousSibling(tmp);
- } while (tmp && tmp.offsetHeight === 0);
- return tmp ? $(tmp) : false;
- }
- tmp = obj[0];
- do {
- tmp = this._previousSibling(tmp);
- } while (tmp && tmp.offsetHeight === 0);
- if(tmp !== null) {
- obj = $(tmp);
- while(obj.hasClass("jstree-open")) {
- obj = obj.children(".jstree-children").first().children(".jstree-node:visible:last");
- }
- return obj;
- }
- tmp = obj[0].parentNode.parentNode;
- return tmp && tmp.className && tmp.className.indexOf('jstree-node') !== -1 ? $(tmp) : false;
- },
-
- get_parent : function (obj) {
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- return obj.parent;
- },
-
- get_children_dom : function (obj) {
- obj = this.get_node(obj, true);
- if(obj[0] === this.element[0]) {
- return this.get_container_ul().children(".jstree-node");
- }
- if(!obj || !obj.length) {
- return false;
- }
- return obj.children(".jstree-children").children(".jstree-node");
- },
-
- is_parent : function (obj) {
- obj = this.get_node(obj);
- return obj && (obj.state.loaded === false || obj.children.length > 0);
- },
-
- is_loaded : function (obj) {
- obj = this.get_node(obj);
- return obj && obj.state.loaded;
- },
-
- is_loading : function (obj) {
- obj = this.get_node(obj);
- return obj && obj.state && obj.state.loading;
- },
-
- is_open : function (obj) {
- obj = this.get_node(obj);
- return obj && obj.state.opened;
- },
-
- is_closed : function (obj) {
- obj = this.get_node(obj);
- return obj && this.is_parent(obj) && !obj.state.opened;
- },
-
- is_leaf : function (obj) {
- return !this.is_parent(obj);
- },
-
- load_node : function (obj, callback) {
- var dom = this.get_node(obj, true), k, l, i, j, c;
- if($.vakata.is_array(obj)) {
- this._load_nodes(obj.slice(), callback);
- return true;
- }
- obj = this.get_node(obj);
- if(!obj) {
- if(callback) { callback.call(this, obj, false); }
- return false;
- }
-
- if(obj.state.loaded) {
- obj.state.loaded = false;
- for(i = 0, j = obj.parents.length; i < j; i++) {
- this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
- return $.inArray(v, obj.children_d) === -1;
- });
- }
- for(k = 0, l = obj.children_d.length; k < l; k++) {
- if(this._model.data[obj.children_d[k]].state.selected) {
- c = true;
- }
- delete this._model.data[obj.children_d[k]];
- }
- if (c) {
- this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
- return $.inArray(v, obj.children_d) === -1;
- });
- }
- obj.children = [];
- obj.children_d = [];
- if(c) {
- this.trigger('changed', { 'action' : 'load_node', 'node' : obj, 'selected' : this._data.core.selected });
- }
- }
- obj.state.failed = false;
- obj.state.loading = true;
- if (obj.id !== $.jstree.root) {
- dom.children(".jstree-anchor").attr('aria-busy', true);
- } else {
- dom.attr('aria-busy', true);
- }
- dom.addClass("jstree-loading");
- this._load_node(obj, function (status) {
- obj = this._model.data[obj.id];
- obj.state.loading = false;
- obj.state.loaded = status;
- obj.state.failed = !obj.state.loaded;
- var dom = this.get_node(obj, true), i = 0, j = 0, m = this._model.data, has_children = false;
- for(i = 0, j = obj.children.length; i < j; i++) {
- if(m[obj.children[i]] && !m[obj.children[i]].state.hidden) {
- has_children = true;
- break;
- }
- }
- if(obj.state.loaded && dom && dom.length) {
- dom.removeClass('jstree-closed jstree-open jstree-leaf');
- if (!has_children) {
- dom.addClass('jstree-leaf');
- }
- else {
- if (obj.id !== '#') {
- dom.addClass(obj.state.opened ? 'jstree-open' : 'jstree-closed');
- }
- }
- }
- if (obj.id !== $.jstree.root) {
- dom.children(".jstree-anchor").attr('aria-busy', false);
- } else {
- dom.attr('aria-busy', false);
- }
- dom.removeClass("jstree-loading");
-
- this.trigger('load_node', { "node" : obj, "status" : status });
- if(callback) {
- callback.call(this, obj, status);
- }
- }.bind(this));
- return true;
- },
-
- _load_nodes : function (nodes, callback, is_callback, force_reload) {
- var r = true,
- c = function () { this._load_nodes(nodes, callback, true); },
- m = this._model.data, i, j, tmp = [];
- for(i = 0, j = nodes.length; i < j; i++) {
- if(m[nodes[i]] && ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || (!is_callback && force_reload) )) {
- if(!this.is_loading(nodes[i])) {
- this.load_node(nodes[i], c);
- }
- r = false;
- }
- }
- if(r) {
- for(i = 0, j = nodes.length; i < j; i++) {
- if(m[nodes[i]] && m[nodes[i]].state.loaded) {
- tmp.push(nodes[i]);
- }
- }
- if(callback && !callback.done) {
- callback.call(this, tmp);
- callback.done = true;
- }
- }
- },
-
- load_all : function (obj, callback) {
- if(!obj) { obj = $.jstree.root; }
- obj = this.get_node(obj);
- if(!obj) { return false; }
- var to_load = [],
- m = this._model.data,
- c = m[obj.id].children_d,
- i, j;
- if(obj.state && !obj.state.loaded) {
- to_load.push(obj.id);
- }
- for(i = 0, j = c.length; i < j; i++) {
- if(m[c[i]] && m[c[i]].state && !m[c[i]].state.loaded) {
- to_load.push(c[i]);
- }
- }
- if(to_load.length) {
- this._load_nodes(to_load, function () {
- this.load_all(obj, callback);
- });
- }
- else {
-
- if(callback) { callback.call(this, obj); }
- this.trigger('load_all', { "node" : obj });
- }
- },
-
- _load_node : function (obj, callback) {
- var s = this.settings.core.data, t;
- var notTextOrCommentNode = function notTextOrCommentNode () {
- return this.nodeType !== 3 && this.nodeType !== 8;
- };
-
- if(!s) {
- if(obj.id === $.jstree.root) {
- return this._append_html_data(obj, this._data.core.original_container_html.clone(true), function (status) {
- callback.call(this, status);
- });
- }
- else {
- return callback.call(this, false);
- }
-
- }
- if($.vakata.is_function(s)) {
- return s.call(this, obj, function (d) {
- if(d === false) {
- callback.call(this, false);
- }
- else {
- this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $($.parseHTML(d)).filter(notTextOrCommentNode) : d, function (status) {
- callback.call(this, status);
- });
- }
-
- }.bind(this));
- }
- if(typeof s === 'object') {
- if(s.url) {
- s = $.extend(true, {}, s);
- if($.vakata.is_function(s.url)) {
- s.url = s.url.call(this, obj);
- }
- if($.vakata.is_function(s.data)) {
- s.data = s.data.call(this, obj);
- }
- return $.ajax(s)
- .done(function (d,t,x) {
- var type = x.getResponseHeader('Content-Type');
- if((type && type.indexOf('json') !== -1) || typeof d === "object") {
- return this._append_json_data(obj, d, function (status) { callback.call(this, status); });
-
- }
- if((type && type.indexOf('html') !== -1) || typeof d === "string") {
- return this._append_html_data(obj, $($.parseHTML(d)).filter(notTextOrCommentNode), function (status) { callback.call(this, status); });
-
- }
- 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 }) };
- this.settings.core.error.call(this, this._data.core.last_error);
- return callback.call(this, false);
- }.bind(this))
- .fail(function (f) {
- 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 }) };
- callback.call(this, false);
- this.settings.core.error.call(this, this._data.core.last_error);
- }.bind(this));
- }
- if ($.vakata.is_array(s)) {
- t = $.extend(true, [], s);
- } else if ($.isPlainObject(s)) {
- t = $.extend(true, {}, s);
- } else {
- t = s;
- }
- if(obj.id === $.jstree.root) {
- return this._append_json_data(obj, t, function (status) {
- callback.call(this, status);
- });
- }
- else {
- this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_05', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
- this.settings.core.error.call(this, this._data.core.last_error);
- return callback.call(this, false);
- }
-
- }
- if(typeof s === 'string') {
- if(obj.id === $.jstree.root) {
- return this._append_html_data(obj, $($.parseHTML(s)).filter(notTextOrCommentNode), function (status) {
- callback.call(this, status);
- });
- }
- else {
- this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_06', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
- this.settings.core.error.call(this, this._data.core.last_error);
- return callback.call(this, false);
- }
-
- }
- return callback.call(this, false);
- },
-
- _node_changed : function (obj) {
- obj = this.get_node(obj);
- if (obj && $.inArray(obj.id, this._model.changed) === -1) {
- this._model.changed.push(obj.id);
- }
- },
-
- _append_html_data : function (dom, data, cb) {
- dom = this.get_node(dom);
- dom.children = [];
- dom.children_d = [];
- var dat = data.is('ul') ? data.children() : data,
- par = dom.id,
- chd = [],
- dpc = [],
- m = this._model.data,
- p = m[par],
- s = this._data.core.selected.length,
- tmp, i, j;
- dat.each(function (i, v) {
- tmp = this._parse_model_from_html($(v), par, p.parents.concat());
- if(tmp) {
- chd.push(tmp);
- dpc.push(tmp);
- if(m[tmp].children_d.length) {
- dpc = dpc.concat(m[tmp].children_d);
- }
- }
- }.bind(this));
- p.children = chd;
- p.children_d = dpc;
- for(i = 0, j = p.parents.length; i < j; i++) {
- m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
- }
-
- this.trigger('model', { "nodes" : dpc, 'parent' : par });
- if(par !== $.jstree.root) {
- this._node_changed(par);
- this.redraw();
- }
- else {
- this.get_container_ul().children('.jstree-initial-node').remove();
- this.redraw(true);
- }
- if(this._data.core.selected.length !== s) {
- this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
- }
- cb.call(this, true);
- },
-
- _append_json_data : function (dom, data, cb, force_processing) {
- if(this.element === null) { return; }
- dom = this.get_node(dom);
- dom.children = [];
- dom.children_d = [];
-
- if(data.d) {
- data = data.d;
- if(typeof data === "string") {
- data = JSON.parse(data);
- }
- }
- if(!$.vakata.is_array(data)) { data = [data]; }
- var w = null,
- args = {
- 'df' : this._model.default_state,
- 'dat' : data,
- 'par' : dom.id,
- 'm' : this._model.data,
- 't_id' : this._id,
- 't_cnt' : this._cnt,
- 'sel' : this._data.core.selected
- },
- inst = this,
- func = function (data, undefined) {
- if(data.data) { data = data.data; }
- var dat = data.dat,
- par = data.par,
- chd = [],
- dpc = [],
- add = [],
- df = data.df,
- t_id = data.t_id,
- t_cnt = data.t_cnt,
- m = data.m,
- p = m[par],
- sel = data.sel,
- tmp, i, j, rslt,
- parse_flat = function (d, p, ps) {
- if(!ps) { ps = []; }
- else { ps = ps.concat(); }
- if(p) { ps.unshift(p); }
- var tid = d.id.toString(),
- i, j, c, e,
- tmp = {
- id : tid,
- text : d.text || '',
- icon : d.icon !== undefined ? d.icon : true,
- parent : p,
- parents : ps,
- children : d.children || [],
- children_d : d.children_d || [],
- data : d.data,
- state : { },
- li_attr : { id : false },
- a_attr : { href : '#' },
- original : false
- };
- for(i in df) {
- if(df.hasOwnProperty(i)) {
- tmp.state[i] = df[i];
- }
- }
- if(d && d.data && d.data.jstree && d.data.jstree.icon) {
- tmp.icon = d.data.jstree.icon;
- }
- if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
- tmp.icon = true;
- }
- if(d && d.data) {
- tmp.data = d.data;
- if(d.data.jstree) {
- for(i in d.data.jstree) {
- if(d.data.jstree.hasOwnProperty(i)) {
- tmp.state[i] = d.data.jstree[i];
- }
- }
- }
- }
- if(d && typeof d.state === 'object') {
- for (i in d.state) {
- if(d.state.hasOwnProperty(i)) {
- tmp.state[i] = d.state[i];
- }
- }
- }
- if(d && typeof d.li_attr === 'object') {
- for (i in d.li_attr) {
- if(d.li_attr.hasOwnProperty(i)) {
- tmp.li_attr[i] = d.li_attr[i];
- }
- }
- }
- if(!tmp.li_attr.id) {
- tmp.li_attr.id = tid;
- }
- if(d && typeof d.a_attr === 'object') {
- for (i in d.a_attr) {
- if(d.a_attr.hasOwnProperty(i)) {
- tmp.a_attr[i] = d.a_attr[i];
- }
- }
- }
- if(d && d.children && d.children === true) {
- tmp.state.loaded = false;
- tmp.children = [];
- tmp.children_d = [];
- }
- m[tmp.id] = tmp;
- for(i = 0, j = tmp.children.length; i < j; i++) {
- c = parse_flat(m[tmp.children[i]], tmp.id, ps);
- e = m[c];
- tmp.children_d.push(c);
- if(e.children_d.length) {
- tmp.children_d = tmp.children_d.concat(e.children_d);
- }
- }
- delete d.data;
- delete d.children;
- m[tmp.id].original = d;
- if(tmp.state.selected) {
- add.push(tmp.id);
- }
- return tmp.id;
- },
- parse_nest = function (d, p, ps) {
- if(!ps) { ps = []; }
- else { ps = ps.concat(); }
- if(p) { ps.unshift(p); }
- var tid = false, i, j, c, e, tmp;
- do {
- tid = 'j' + t_id + '_' + (++t_cnt);
- } while(m[tid]);
- tmp = {
- id : false,
- text : typeof d === 'string' ? d : '',
- icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
- parent : p,
- parents : ps,
- children : [],
- children_d : [],
- data : null,
- state : { },
- li_attr : { id : false },
- a_attr : { href : '#' },
- original : false
- };
- for(i in df) {
- if(df.hasOwnProperty(i)) {
- tmp.state[i] = df[i];
- }
- }
- if(d && (d.id || d.id === 0)) { tmp.id = d.id.toString(); }
- if(d && d.text) { tmp.text = d.text; }
- if(d && d.data && d.data.jstree && d.data.jstree.icon) {
- tmp.icon = d.data.jstree.icon;
- }
- if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
- tmp.icon = true;
- }
- if(d && d.data) {
- tmp.data = d.data;
- if(d.data.jstree) {
- for(i in d.data.jstree) {
- if(d.data.jstree.hasOwnProperty(i)) {
- tmp.state[i] = d.data.jstree[i];
- }
- }
- }
- }
- if(d && typeof d.state === 'object') {
- for (i in d.state) {
- if(d.state.hasOwnProperty(i)) {
- tmp.state[i] = d.state[i];
- }
- }
- }
- if(d && typeof d.li_attr === 'object') {
- for (i in d.li_attr) {
- if(d.li_attr.hasOwnProperty(i)) {
- tmp.li_attr[i] = d.li_attr[i];
- }
- }
- }
- if(tmp.li_attr.id && !(tmp.id || tmp.id === 0)) {
- tmp.id = tmp.li_attr.id.toString();
- }
- if(!(tmp.id || tmp.id === 0)) {
- tmp.id = tid;
- }
- if(!tmp.li_attr.id) {
- tmp.li_attr.id = tmp.id;
- }
- if(d && typeof d.a_attr === 'object') {
- for (i in d.a_attr) {
- if(d.a_attr.hasOwnProperty(i)) {
- tmp.a_attr[i] = d.a_attr[i];
- }
- }
- }
- if(d && d.children && d.children.length) {
- for(i = 0, j = d.children.length; i < j; i++) {
- c = parse_nest(d.children[i], tmp.id, ps);
- e = m[c];
- tmp.children.push(c);
- if(e.children_d.length) {
- tmp.children_d = tmp.children_d.concat(e.children_d);
- }
- }
- tmp.children_d = tmp.children_d.concat(tmp.children);
- }
- if(d && d.children && d.children === true) {
- tmp.state.loaded = false;
- tmp.children = [];
- tmp.children_d = [];
- }
- delete d.data;
- delete d.children;
- tmp.original = d;
- m[tmp.id] = tmp;
- if(tmp.state.selected) {
- add.push(tmp.id);
- }
- return tmp.id;
- };
- if(dat.length && dat[0].id !== undefined && dat[0].parent !== undefined) {
-
-
- for(i = 0, j = dat.length; i < j; i++) {
- if(!dat[i].children) {
- dat[i].children = [];
- }
- if(!dat[i].state) {
- dat[i].state = {};
- }
- m[dat[i].id.toString()] = dat[i];
- }
-
- for(i = 0, j = dat.length; i < j; i++) {
- if (!m[dat[i].parent.toString()]) {
- if (typeof inst !== "undefined") {
- 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() }) };
- inst.settings.core.error.call(inst, inst._data.core.last_error);
- }
- continue;
- }
- m[dat[i].parent.toString()].children.push(dat[i].id.toString());
-
- p.children_d.push(dat[i].id.toString());
- }
-
- for(i = 0, j = p.children.length; i < j; i++) {
- tmp = parse_flat(m[p.children[i]], par, p.parents.concat());
- dpc.push(tmp);
- if(m[tmp].children_d.length) {
- dpc = dpc.concat(m[tmp].children_d);
- }
- }
- for(i = 0, j = p.parents.length; i < j; i++) {
- m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
- }
-
- rslt = {
- 'cnt' : t_cnt,
- 'mod' : m,
- 'sel' : sel,
- 'par' : par,
- 'dpc' : dpc,
- 'add' : add
- };
- }
- else {
- for(i = 0, j = dat.length; i < j; i++) {
- tmp = parse_nest(dat[i], par, p.parents.concat());
- if(tmp) {
- chd.push(tmp);
- dpc.push(tmp);
- if(m[tmp].children_d.length) {
- dpc = dpc.concat(m[tmp].children_d);
- }
- }
- }
- p.children = chd;
- p.children_d = dpc;
- for(i = 0, j = p.parents.length; i < j; i++) {
- m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
- }
- rslt = {
- 'cnt' : t_cnt,
- 'mod' : m,
- 'sel' : sel,
- 'par' : par,
- 'dpc' : dpc,
- 'add' : add
- };
- }
- if(typeof window === 'undefined' || typeof window.document === 'undefined') {
- postMessage(rslt);
- }
- else {
- return rslt;
- }
- },
- rslt = function (rslt, worker) {
- if(this.element === null) { return; }
- this._cnt = rslt.cnt;
- var i, m = this._model.data;
- for (i in m) {
- if (m.hasOwnProperty(i) && m[i].state && m[i].state.loading && rslt.mod[i]) {
- rslt.mod[i].state.loading = true;
- }
- }
- this._model.data = rslt.mod;
- if(worker) {
- var j, a = rslt.add, r = rslt.sel, s = this._data.core.selected.slice();
- m = this._model.data;
-
- if(r.length !== s.length || $.vakata.array_unique(r.concat(s)).length !== r.length) {
-
- for(i = 0, j = r.length; i < j; i++) {
- if($.inArray(r[i], a) === -1 && $.inArray(r[i], s) === -1) {
- m[r[i]].state.selected = false;
- }
- }
-
- for(i = 0, j = s.length; i < j; i++) {
- if($.inArray(s[i], r) === -1) {
- m[s[i]].state.selected = true;
- }
- }
- }
- }
- if(rslt.add.length) {
- this._data.core.selected = this._data.core.selected.concat(rslt.add);
- }
- this.trigger('model', { "nodes" : rslt.dpc, 'parent' : rslt.par });
- if(rslt.par !== $.jstree.root) {
- this._node_changed(rslt.par);
- this.redraw();
- }
- else {
-
- this.redraw(true);
- }
- if(rslt.add.length) {
- this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
- }
-
- if (!worker && setImmediate) {
- setImmediate(function(){
- cb.call(inst, true);
- });
- }
- else {
- cb.call(inst, true);
- }
- };
- if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
- try {
- if(this._wrk === null) {
- this._wrk = window.URL.createObjectURL(
- new window.Blob(
- ['self.onmessage = ' + func.toString()],
- {type:"text/javascript"}
- )
- );
- }
- if(!this._data.core.working || force_processing) {
- this._data.core.working = true;
- w = new window.Worker(this._wrk);
- w.onmessage = function (e) {
- rslt.call(this, e.data, true);
- try { w.terminate(); w = null; } catch(ignore) { }
- if(this._data.core.worker_queue.length) {
- this._append_json_data.apply(this, this._data.core.worker_queue.shift());
- }
- else {
- this._data.core.working = false;
- }
- }.bind(this);
- w.onerror = function (e) {
- rslt.call(this, func(args), false);
- if(this._data.core.worker_queue.length) {
- this._append_json_data.apply(this, this._data.core.worker_queue.shift());
- }
- else {
- this._data.core.working = false;
- }
- }.bind(this);
- if(!args.par) {
- if(this._data.core.worker_queue.length) {
- this._append_json_data.apply(this, this._data.core.worker_queue.shift());
- }
- else {
- this._data.core.working = false;
- }
- }
- else {
- w.postMessage(args);
- }
- }
- else {
- this._data.core.worker_queue.push([dom, data, cb, true]);
- }
- }
- catch(e) {
- rslt.call(this, func(args), false);
- if(this._data.core.worker_queue.length) {
- this._append_json_data.apply(this, this._data.core.worker_queue.shift());
- }
- else {
- this._data.core.working = false;
- }
- }
- }
- else {
- rslt.call(this, func(args), false);
- }
- },
-
- _parse_model_from_html : function (d, p, ps) {
- if(!ps) { ps = []; }
- else { ps = [].concat(ps); }
- if(p) { ps.unshift(p); }
- var c, e, m = this._model.data,
- data = {
- id : false,
- text : false,
- icon : true,
- parent : p,
- parents : ps,
- children : [],
- children_d : [],
- data : null,
- state : { },
- li_attr : { id : false },
- a_attr : { href : '#' },
- original : false
- }, i, tmp, tid;
- for(i in this._model.default_state) {
- if(this._model.default_state.hasOwnProperty(i)) {
- data.state[i] = this._model.default_state[i];
- }
- }
- tmp = $.vakata.attributes(d, true);
- $.each(tmp, function (i, v) {
- v = $.vakata.trim(v);
- if(!v.length) { return true; }
- data.li_attr[i] = v;
- if(i === 'id') {
- data.id = v.toString();
- }
- });
- tmp = d.children('a').first();
- if(tmp.length) {
- tmp = $.vakata.attributes(tmp, true);
- $.each(tmp, function (i, v) {
- v = $.vakata.trim(v);
- if(v.length) {
- data.a_attr[i] = v;
- }
- });
- }
- tmp = d.children("a").first().length ? d.children("a").first().clone() : d.clone();
- tmp.children("ins, i, ul").remove();
- tmp = tmp.html();
- tmp = $('<div></div>').html(tmp);
- data.text = this.settings.core.force_text ? tmp.text() : tmp.html();
- tmp = d.data();
- data.data = tmp ? $.extend(true, {}, tmp) : null;
- data.state.opened = d.hasClass('jstree-open');
- data.state.selected = d.children('a').hasClass('jstree-clicked');
- data.state.disabled = d.children('a').hasClass('jstree-disabled');
- if(data.data && data.data.jstree) {
- for(i in data.data.jstree) {
- if(data.data.jstree.hasOwnProperty(i)) {
- data.state[i] = data.data.jstree[i];
- }
- }
- }
- tmp = d.children("a").children(".jstree-themeicon");
- if(tmp.length) {
- data.icon = tmp.hasClass('jstree-themeicon-hidden') ? false : tmp.attr('rel');
- }
- if(data.state.icon !== undefined) {
- data.icon = data.state.icon;
- }
- if(data.icon === undefined || data.icon === null || data.icon === "") {
- data.icon = true;
- }
- tmp = d.children("ul").children("li");
- do {
- tid = 'j' + this._id + '_' + (++this._cnt);
- } while(m[tid]);
- data.id = data.li_attr.id ? data.li_attr.id.toString() : tid;
- if(tmp.length) {
- tmp.each(function (i, v) {
- c = this._parse_model_from_html($(v), data.id, ps);
- e = this._model.data[c];
- data.children.push(c);
- if(e.children_d.length) {
- data.children_d = data.children_d.concat(e.children_d);
- }
- }.bind(this));
- data.children_d = data.children_d.concat(data.children);
- }
- else {
- if(d.hasClass('jstree-closed')) {
- data.state.loaded = false;
- }
- }
- if(data.li_attr['class']) {
- data.li_attr['class'] = data.li_attr['class'].replace('jstree-closed','').replace('jstree-open','');
- }
- if(data.a_attr['class']) {
- data.a_attr['class'] = data.a_attr['class'].replace('jstree-clicked','').replace('jstree-disabled','');
- }
- m[data.id] = data;
- if(data.state.selected) {
- this._data.core.selected.push(data.id);
- }
- return data.id;
- },
-
- _parse_model_from_flat_json : function (d, p, ps) {
- if(!ps) { ps = []; }
- else { ps = ps.concat(); }
- if(p) { ps.unshift(p); }
- var tid = d.id.toString(),
- m = this._model.data,
- df = this._model.default_state,
- i, j, c, e,
- tmp = {
- id : tid,
- text : d.text || '',
- icon : d.icon !== undefined ? d.icon : true,
- parent : p,
- parents : ps,
- children : d.children || [],
- children_d : d.children_d || [],
- data : d.data,
- state : { },
- li_attr : { id : false },
- a_attr : { href : '#' },
- original : false
- };
- for(i in df) {
- if(df.hasOwnProperty(i)) {
- tmp.state[i] = df[i];
- }
- }
- if(d && d.data && d.data.jstree && d.data.jstree.icon) {
- tmp.icon = d.data.jstree.icon;
- }
- if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
- tmp.icon = true;
- }
- if(d && d.data) {
- tmp.data = d.data;
- if(d.data.jstree) {
- for(i in d.data.jstree) {
- if(d.data.jstree.hasOwnProperty(i)) {
- tmp.state[i] = d.data.jstree[i];
- }
- }
- }
- }
- if(d && typeof d.state === 'object') {
- for (i in d.state) {
- if(d.state.hasOwnProperty(i)) {
- tmp.state[i] = d.state[i];
- }
- }
- }
- if(d && typeof d.li_attr === 'object') {
- for (i in d.li_attr) {
- if(d.li_attr.hasOwnProperty(i)) {
- tmp.li_attr[i] = d.li_attr[i];
- }
- }
- }
- if(!tmp.li_attr.id) {
- tmp.li_attr.id = tid;
- }
- if(d && typeof d.a_attr === 'object') {
- for (i in d.a_attr) {
- if(d.a_attr.hasOwnProperty(i)) {
- tmp.a_attr[i] = d.a_attr[i];
- }
- }
- }
- if(d && d.children && d.children === true) {
- tmp.state.loaded = false;
- tmp.children = [];
- tmp.children_d = [];
- }
- m[tmp.id] = tmp;
- for(i = 0, j = tmp.children.length; i < j; i++) {
- c = this._parse_model_from_flat_json(m[tmp.children[i]], tmp.id, ps);
- e = m[c];
- tmp.children_d.push(c);
- if(e.children_d.length) {
- tmp.children_d = tmp.children_d.concat(e.children_d);
- }
- }
- delete d.data;
- delete d.children;
- m[tmp.id].original = d;
- if(tmp.state.selected) {
- this._data.core.selected.push(tmp.id);
- }
- return tmp.id;
- },
-
- _parse_model_from_json : function (d, p, ps) {
- if(!ps) { ps = []; }
- else { ps = ps.concat(); }
- if(p) { ps.unshift(p); }
- var tid = false, i, j, c, e, m = this._model.data, df = this._model.default_state, tmp;
- do {
- tid = 'j' + this._id + '_' + (++this._cnt);
- } while(m[tid]);
- tmp = {
- id : false,
- text : typeof d === 'string' ? d : '',
- icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
- parent : p,
- parents : ps,
- children : [],
- children_d : [],
- data : null,
- state : { },
- li_attr : { id : false },
- a_attr : { href : '#' },
- original : false
- };
- for(i in df) {
- if(df.hasOwnProperty(i)) {
- tmp.state[i] = df[i];
- }
- }
- if(d && (d.id || d.id === 0)) { tmp.id = d.id.toString(); }
- if(d && d.text) { tmp.text = d.text; }
- if(d && d.data && d.data.jstree && d.data.jstree.icon) {
- tmp.icon = d.data.jstree.icon;
- }
- if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
- tmp.icon = true;
- }
- if(d && d.data) {
- tmp.data = d.data;
- if(d.data.jstree) {
- for(i in d.data.jstree) {
- if(d.data.jstree.hasOwnProperty(i)) {
- tmp.state[i] = d.data.jstree[i];
- }
- }
- }
- }
- if(d && typeof d.state === 'object') {
- for (i in d.state) {
- if(d.state.hasOwnProperty(i)) {
- tmp.state[i] = d.state[i];
- }
- }
- }
- if(d && typeof d.li_attr === 'object') {
- for (i in d.li_attr) {
- if(d.li_attr.hasOwnProperty(i)) {
- tmp.li_attr[i] = d.li_attr[i];
- }
- }
- }
- if(tmp.li_attr.id && !(tmp.id || tmp.id === 0)) {
- tmp.id = tmp.li_attr.id.toString();
- }
- if(!(tmp.id || tmp.id === 0)) {
- tmp.id = tid;
- }
- if(!tmp.li_attr.id) {
- tmp.li_attr.id = tmp.id;
- }
- if(d && typeof d.a_attr === 'object') {
- for (i in d.a_attr) {
- if(d.a_attr.hasOwnProperty(i)) {
- tmp.a_attr[i] = d.a_attr[i];
- }
- }
- }
- if(d && d.children && d.children.length) {
- for(i = 0, j = d.children.length; i < j; i++) {
- c = this._parse_model_from_json(d.children[i], tmp.id, ps);
- e = m[c];
- tmp.children.push(c);
- if(e.children_d.length) {
- tmp.children_d = tmp.children_d.concat(e.children_d);
- }
- }
- tmp.children_d = tmp.children.concat(tmp.children_d);
- }
- if(d && d.children && d.children === true) {
- tmp.state.loaded = false;
- tmp.children = [];
- tmp.children_d = [];
- }
- delete d.data;
- delete d.children;
- tmp.original = d;
- m[tmp.id] = tmp;
- if(tmp.state.selected) {
- this._data.core.selected.push(tmp.id);
- }
- return tmp.id;
- },
-
- _redraw : function () {
- var nodes = this._model.force_full_redraw ? this._model.data[$.jstree.root].children.concat([]) : this._model.changed.concat([]),
- f = document.createElement('UL'), tmp, i, j, fe = this._data.core.focused;
- for(i = 0, j = nodes.length; i < j; i++) {
- tmp = this.redraw_node(nodes[i], true, this._model.force_full_redraw);
- if(tmp && this._model.force_full_redraw) {
- f.appendChild(tmp);
- }
- }
- if(this._model.force_full_redraw) {
- f.className = this.get_container_ul()[0].className;
- f.setAttribute('role','presentation');
- this.element.empty().append(f);
-
- }
- if(fe !== null && this.settings.core.restore_focus) {
- tmp = this.get_node(fe, true);
- if(tmp && tmp.length && tmp.children('.jstree-anchor')[0] !== document.activeElement) {
- tmp.children('.jstree-anchor').trigger('focus');
- }
- else {
- this._data.core.focused = null;
- }
- }
- this._model.force_full_redraw = false;
- this._model.changed = [];
-
- this.trigger('redraw', { "nodes" : nodes });
- },
-
- redraw : function (full) {
- if(full) {
- this._model.force_full_redraw = true;
- }
-
-
-
-
- this._redraw();
- },
-
- draw_children : function (node) {
- var obj = this.get_node(node),
- i = false,
- j = false,
- k = false,
- d = document;
- if(!obj) { return false; }
- if(obj.id === $.jstree.root) { return this.redraw(true); }
- node = this.get_node(node, true);
- if(!node || !node.length) { return false; }
- node.children('.jstree-children').remove();
- node = node[0];
- if(obj.children.length && obj.state.loaded) {
- k = d.createElement('UL');
- k.setAttribute('role', 'group');
- k.className = 'jstree-children';
- for(i = 0, j = obj.children.length; i < j; i++) {
- k.appendChild(this.redraw_node(obj.children[i], true, true));
- }
- node.appendChild(k);
- }
- },
-
- redraw_node : function (node, deep, is_callback, force_render) {
- var obj = this.get_node(node),
- par = false,
- ind = false,
- old = false,
- i = false,
- j = false,
- k = false,
- c = '',
- d = document,
- m = this._model.data,
- f = false,
- s = false,
- tmp = null,
- t = 0,
- l = 0,
- has_children = false,
- last_sibling = false;
- if(!obj) { return false; }
- if(obj.id === $.jstree.root) { return this.redraw(true); }
- deep = deep || obj.children.length === 0;
- 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,'\\$&')) );
- if(!node) {
- deep = true;
-
- if(!is_callback) {
- par = obj.parent !== $.jstree.root ? $('#' + obj.parent.replace($.jstree.idregex,'\\$&'), this.element)[0] : null;
- if(par !== null && (!par || !m[obj.parent].state.opened)) {
- return false;
- }
- ind = $.inArray(obj.id, par === null ? m[$.jstree.root].children : m[obj.parent].children);
- }
- }
- else {
- node = $(node);
- if(!is_callback) {
- par = node.parent().parent()[0];
- if(par === this.element[0]) {
- par = null;
- }
- ind = node.index();
- }
-
- if(!deep && obj.children.length && !node.children('.jstree-children').length) {
- deep = true;
- }
- if(!deep) {
- old = node.children('.jstree-children')[0];
- }
- f = node.children('.jstree-anchor')[0] === document.activeElement;
- node.remove();
-
-
- }
- node = this._data.core.node.cloneNode(true);
-
- c = 'jstree-node ';
- for(i in obj.li_attr) {
- if(obj.li_attr.hasOwnProperty(i)) {
- if(i === 'id') { continue; }
- if(i !== 'class') {
- node.setAttribute(i, obj.li_attr[i]);
- }
- else {
- c += obj.li_attr[i];
- }
- }
- }
- if(!obj.a_attr.id) {
- obj.a_attr.id = obj.id + '_anchor';
- }
- node.childNodes[1].setAttribute('aria-selected', !!obj.state.selected);
- node.childNodes[1].setAttribute('aria-level', obj.parents.length);
- if(this.settings.core.compute_elements_positions) {
- node.childNodes[1].setAttribute('aria-setsize', m[obj.parent].children.length);
- node.childNodes[1].setAttribute('aria-posinset', m[obj.parent].children.indexOf(obj.id) + 1);
- }
- if(obj.state.disabled) {
- node.childNodes[1].setAttribute('aria-disabled', true);
- }
- for(i = 0, j = obj.children.length; i < j; i++) {
- if(!m[obj.children[i]].state.hidden) {
- has_children = true;
- break;
- }
- }
- if(obj.parent !== null && m[obj.parent] && !obj.state.hidden) {
- i = $.inArray(obj.id, m[obj.parent].children);
- last_sibling = obj.id;
- if(i !== -1) {
- i++;
- for(j = m[obj.parent].children.length; i < j; i++) {
- if(!m[m[obj.parent].children[i]].state.hidden) {
- last_sibling = m[obj.parent].children[i];
- }
- if(last_sibling !== obj.id) {
- break;
- }
- }
- }
- }
- if(obj.state.hidden) {
- c += ' jstree-hidden';
- }
- if (obj.state.loading) {
- c += ' jstree-loading';
- }
- if(obj.state.loaded && !has_children) {
- c += ' jstree-leaf';
- }
- else {
- c += obj.state.opened && obj.state.loaded ? ' jstree-open' : ' jstree-closed';
- node.childNodes[1].setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
- }
- if(last_sibling === obj.id) {
- c += ' jstree-last';
- }
- node.id = obj.id;
- node.className = c;
- c = ( obj.state.selected ? ' jstree-clicked' : '') + ( obj.state.disabled ? ' jstree-disabled' : '');
- for(j in obj.a_attr) {
- if(obj.a_attr.hasOwnProperty(j)) {
- if(j === 'href' && obj.a_attr[j] === '#') { continue; }
- if(j !== 'class') {
- node.childNodes[1].setAttribute(j, obj.a_attr[j]);
- }
- else {
- c += ' ' + obj.a_attr[j];
- }
- }
- }
- if(c.length) {
- node.childNodes[1].className = 'jstree-anchor ' + c;
- }
- if((obj.icon && obj.icon !== true) || obj.icon === false) {
- if(obj.icon === false) {
- node.childNodes[1].childNodes[0].className += ' jstree-themeicon-hidden';
- }
- else if(obj.icon.indexOf('/') === -1 && obj.icon.indexOf('.') === -1) {
- node.childNodes[1].childNodes[0].className += ' ' + obj.icon + ' jstree-themeicon-custom';
- }
- else {
- node.childNodes[1].childNodes[0].style.backgroundImage = 'url("'+obj.icon+'")';
- node.childNodes[1].childNodes[0].style.backgroundPosition = 'center center';
- node.childNodes[1].childNodes[0].style.backgroundSize = 'auto';
- node.childNodes[1].childNodes[0].className += ' jstree-themeicon-custom';
- }
- }
- if(this.settings.core.force_text) {
- node.childNodes[1].appendChild(d.createTextNode(obj.text));
- }
- else {
- node.childNodes[1].innerHTML += obj.text;
- }
- if(deep && obj.children.length && (obj.state.opened || force_render) && obj.state.loaded) {
- k = d.createElement('UL');
- k.setAttribute('role', 'group');
- k.className = 'jstree-children';
- for(i = 0, j = obj.children.length; i < j; i++) {
- k.appendChild(this.redraw_node(obj.children[i], deep, true));
- }
- node.appendChild(k);
- }
- if(old) {
- node.appendChild(old);
- }
- if(!is_callback) {
-
- if(!par) {
- par = this.element[0];
- }
- for(i = 0, j = par.childNodes.length; i < j; i++) {
- if(par.childNodes[i] && par.childNodes[i].className && par.childNodes[i].className.indexOf('jstree-children') !== -1) {
- tmp = par.childNodes[i];
- break;
- }
- }
- if(!tmp) {
- tmp = d.createElement('UL');
- tmp.setAttribute('role', 'group');
- tmp.className = 'jstree-children';
- par.appendChild(tmp);
- }
- par = tmp;
- if(ind < par.childNodes.length) {
- par.insertBefore(node, par.childNodes[ind]);
- }
- else {
- par.appendChild(node);
- }
- if(f) {
- t = this.element[0].scrollTop;
- l = this.element[0].scrollLeft;
- node.childNodes[1].focus();
- this.element[0].scrollTop = t;
- this.element[0].scrollLeft = l;
- }
- }
- if(obj.state.opened && !obj.state.loaded) {
- obj.state.opened = false;
- setTimeout(function () {
- this.open_node(obj.id, false, 0);
- }.bind(this), 0);
- }
- return node;
- },
-
- open_node : function (obj, callback, animation) {
- var t1, t2, d, t;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.open_node(obj[t1], callback, animation);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- animation = animation === undefined ? this.settings.core.animation : animation;
- if(!this.is_closed(obj)) {
- if(callback) {
- callback.call(this, obj, false);
- }
- return false;
- }
- if(!this.is_loaded(obj)) {
- if(this.is_loading(obj)) {
- return setTimeout(function () {
- this.open_node(obj, callback, animation);
- }.bind(this), 500);
- }
- this.load_node(obj, function (o, ok) {
- return ok ? this.open_node(o, callback, animation) : (callback ? callback.call(this, o, false) : false);
- });
- }
- else {
- d = this.get_node(obj, true);
- t = this;
- if(d.length) {
- if(animation && d.children(".jstree-children").length) {
- d.children(".jstree-children").stop(true, true);
- }
- if(obj.children.length && !this._firstChild(d.children('.jstree-children')[0])) {
- this.draw_children(obj);
-
- }
- if(!animation) {
- this.trigger('before_open', { "node" : obj });
- d[0].className = d[0].className.replace('jstree-closed', 'jstree-open');
- d[0].childNodes[1].setAttribute("aria-expanded", true);
- }
- else {
- this.trigger('before_open', { "node" : obj });
- d
- .children(".jstree-children").css("display","none").end()
- .removeClass("jstree-closed").addClass("jstree-open")
- .children('.jstree-anchor').attr("aria-expanded", true).end()
- .children(".jstree-children").stop(true, true)
- .slideDown(animation, function () {
- this.style.display = "";
- if (t.element) {
- t.trigger("after_open", { "node" : obj });
- }
- });
- }
- }
- obj.state.opened = true;
- if(callback) {
- callback.call(this, obj, true);
- }
- if(!d.length) {
-
- this.trigger('before_open', { "node" : obj });
- }
-
- this.trigger('open_node', { "node" : obj });
- if(!animation || !d.length) {
-
- this.trigger("after_open", { "node" : obj });
- }
- return true;
- }
- },
-
- _open_to : function (obj) {
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- var i, j, p = obj.parents;
- for(i = 0, j = p.length; i < j; i+=1) {
- if(i !== $.jstree.root) {
- this.open_node(p[i], false, 0);
- }
- }
- return $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
- },
-
- close_node : function (obj, animation) {
- var t1, t2, t, d;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.close_node(obj[t1], animation);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- if(this.is_closed(obj)) {
- return false;
- }
- animation = animation === undefined ? this.settings.core.animation : animation;
- t = this;
- d = this.get_node(obj, true);
- obj.state.opened = false;
-
- this.trigger('close_node',{ "node" : obj });
- if(!d.length) {
-
- this.trigger("after_close", { "node" : obj });
- }
- else {
- if(!animation) {
- d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
- d.children('.jstree-anchor').attr("aria-expanded", false);
- d.children('.jstree-children').remove();
- this.trigger("after_close", { "node" : obj });
- }
- else {
- d
- .children(".jstree-children").attr("style","display:block !important").end()
- .removeClass("jstree-open").addClass("jstree-closed")
- .children('.jstree-anchor').attr("aria-expanded", false).end()
- .children(".jstree-children").stop(true, true).slideUp(animation, function () {
- this.style.display = "";
- d.children('.jstree-children').remove();
- if (t.element) {
- t.trigger("after_close", { "node" : obj });
- }
- });
- }
- }
- },
-
- toggle_node : function (obj) {
- var t1, t2;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.toggle_node(obj[t1]);
- }
- return true;
- }
- if(this.is_closed(obj)) {
- return this.open_node(obj);
- }
- if(this.is_open(obj)) {
- return this.close_node(obj);
- }
- },
-
- open_all : function (obj, animation, original_obj) {
- if(!obj) { obj = $.jstree.root; }
- obj = this.get_node(obj);
- if(!obj) { return false; }
- var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true), i, j, _this;
- if(!dom.length) {
- for(i = 0, j = obj.children_d.length; i < j; i++) {
- if(this.is_closed(this._model.data[obj.children_d[i]])) {
- this._model.data[obj.children_d[i]].state.opened = true;
- }
- }
- return this.trigger('open_all', { "node" : obj });
- }
- original_obj = original_obj || dom;
- _this = this;
- dom = this.is_closed(obj) ? dom.find('.jstree-closed').addBack() : dom.find('.jstree-closed');
- dom.each(function () {
- _this.open_node(
- this,
- function(node, status) { if(status && this.is_parent(node)) { this.open_all(node, animation, original_obj); } },
- animation || 0
- );
- });
- if(original_obj.find('.jstree-closed').length === 0) {
-
- this.trigger('open_all', { "node" : this.get_node(original_obj) });
- }
- },
-
- close_all : function (obj, animation) {
- if(!obj) { obj = $.jstree.root; }
- obj = this.get_node(obj);
- if(!obj) { return false; }
- var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true),
- _this = this, i, j;
- if(dom.length) {
- dom = this.is_open(obj) ? dom.find('.jstree-open').addBack() : dom.find('.jstree-open');
- $(dom.get().reverse()).each(function () { _this.close_node(this, animation || 0); });
- }
- for(i = 0, j = obj.children_d.length; i < j; i++) {
- this._model.data[obj.children_d[i]].state.opened = false;
- }
-
- this.trigger('close_all', { "node" : obj });
- },
-
- is_disabled : function (obj) {
- obj = this.get_node(obj);
- return obj && obj.state && obj.state.disabled;
- },
-
- enable_node : function (obj) {
- var t1, t2;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.enable_node(obj[t1]);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- obj.state.disabled = false;
- this.get_node(obj,true).children('.jstree-anchor').removeClass('jstree-disabled').attr('aria-disabled', false);
-
- this.trigger('enable_node', { 'node' : obj });
- },
-
- disable_node : function (obj) {
- var t1, t2;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.disable_node(obj[t1]);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- obj.state.disabled = true;
- this.get_node(obj,true).children('.jstree-anchor').addClass('jstree-disabled').attr('aria-disabled', true);
-
- this.trigger('disable_node', { 'node' : obj });
- },
-
- is_hidden : function (obj) {
- obj = this.get_node(obj);
- return obj.state.hidden === true;
- },
-
- hide_node : function (obj, skip_redraw) {
- var t1, t2;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.hide_node(obj[t1], true);
- }
- if (!skip_redraw) {
- this.redraw();
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- if(!obj.state.hidden) {
- obj.state.hidden = true;
- this._node_changed(obj.parent);
- if(!skip_redraw) {
- this.redraw();
- }
-
- this.trigger('hide_node', { 'node' : obj });
- }
- },
-
- show_node : function (obj, skip_redraw) {
- var t1, t2;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.show_node(obj[t1], true);
- }
- if (!skip_redraw) {
- this.redraw();
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- if(obj.state.hidden) {
- obj.state.hidden = false;
- this._node_changed(obj.parent);
- if(!skip_redraw) {
- this.redraw();
- }
-
- this.trigger('show_node', { 'node' : obj });
- }
- },
-
- hide_all : function (skip_redraw) {
- var i, m = this._model.data, ids = [];
- for(i in m) {
- if(m.hasOwnProperty(i) && i !== $.jstree.root && !m[i].state.hidden) {
- m[i].state.hidden = true;
- ids.push(i);
- }
- }
- this._model.force_full_redraw = true;
- if(!skip_redraw) {
- this.redraw();
- }
-
- this.trigger('hide_all', { 'nodes' : ids });
- return ids;
- },
-
- show_all : function (skip_redraw) {
- var i, m = this._model.data, ids = [];
- for(i in m) {
- if(m.hasOwnProperty(i) && i !== $.jstree.root && m[i].state.hidden) {
- m[i].state.hidden = false;
- ids.push(i);
- }
- }
- this._model.force_full_redraw = true;
- if(!skip_redraw) {
- this.redraw();
- }
-
- this.trigger('show_all', { 'nodes' : ids });
- return ids;
- },
-
- activate_node : function (obj, e) {
- if(this.is_disabled(obj)) {
- return false;
- }
- if(!e || typeof e !== 'object') {
- e = {};
- }
-
- 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;
- if(this._data.core.last_clicked && !this._data.core.last_clicked.state.selected) { this._data.core.last_clicked = null; }
- 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]); }
- 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 ) )) {
- if(!this.settings.core.multiple && (e.metaKey || e.ctrlKey || e.shiftKey) && this.is_selected(obj)) {
- this.deselect_node(obj, false, e);
- }
- else {
- if (!this.is_selected(obj) || this._data.core.selected.length !== 1) {
- this.deselect_all(true);
- this.select_node(obj, false, false, e);
- }
- this._data.core.last_clicked = this.get_node(obj);
- }
- }
- else {
- if(e.shiftKey) {
- var o = this.get_node(obj).id,
- l = this._data.core.last_clicked.id,
- p = this.get_node(this._data.core.last_clicked.parent).children,
- c = false,
- i, j;
- for(i = 0, j = p.length; i < j; i += 1) {
-
- if(p[i] === o) {
- c = !c;
- }
- if(p[i] === l) {
- c = !c;
- }
- if(!this.is_disabled(p[i]) && (c || p[i] === o || p[i] === l)) {
- if (!this.is_hidden(p[i])) {
- this.select_node(p[i], true, false, e);
- }
- }
- else {
- if (!e.ctrlKey) {
- this.deselect_node(p[i], true, e);
- }
- }
- }
- this.trigger('changed', { 'action' : 'select_node', 'node' : this.get_node(obj), 'selected' : this._data.core.selected, 'event' : e });
- }
- else {
- if(!this.is_selected(obj)) {
- if (e.ctrlKey) {
- this._data.core.last_clicked = this.get_node(obj);
- }
- this.select_node(obj, false, false, e);
- }
- else {
- this.deselect_node(obj, false, e);
- }
- }
- }
-
- this.trigger('activate_node', { 'node' : this.get_node(obj), 'event' : e });
- },
-
- hover_node : function (obj) {
- obj = this.get_node(obj, true);
- if(!obj || !obj.length || obj.children('.jstree-hovered').length) {
- return false;
- }
- var o = this.element.find('.jstree-hovered'), t = this.element;
- if(o && o.length) { this.dehover_node(o); }
- obj.children('.jstree-anchor').addClass('jstree-hovered');
-
- this.trigger('hover_node', { 'node' : this.get_node(obj) });
- setTimeout(function () { t.attr('aria-activedescendant', obj[0].id); }, 0);
- },
-
- dehover_node : function (obj) {
- obj = this.get_node(obj, true);
- if(!obj || !obj.length || !obj.children('.jstree-hovered').length) {
- return false;
- }
- obj.children('.jstree-anchor').removeClass('jstree-hovered');
-
- this.trigger('dehover_node', { 'node' : this.get_node(obj) });
- },
-
- select_node : function (obj, supress_event, prevent_open, e) {
- var dom, t1, t2, th;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.select_node(obj[t1], supress_event, prevent_open, e);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- dom = this.get_node(obj, true);
- if(!obj.state.selected) {
- obj.state.selected = true;
- this._data.core.selected.push(obj.id);
- if(!prevent_open) {
- dom = this._open_to(obj);
- }
- if(dom && dom.length) {
- dom.children('.jstree-anchor').addClass('jstree-clicked').attr('aria-selected', true);
- }
-
- this.trigger('select_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
- if(!supress_event) {
-
- this.trigger('changed', { 'action' : 'select_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
- }
- }
- },
-
- deselect_node : function (obj, supress_event, e) {
- var t1, t2, dom;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.deselect_node(obj[t1], supress_event, e);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- dom = this.get_node(obj, true);
- if(obj.state.selected) {
- obj.state.selected = false;
- this._data.core.selected = $.vakata.array_remove_item(this._data.core.selected, obj.id);
- if(dom.length) {
- dom.children('.jstree-anchor').removeClass('jstree-clicked').attr('aria-selected', false);
- }
-
- this.trigger('deselect_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
- if(!supress_event) {
- this.trigger('changed', { 'action' : 'deselect_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
- }
- }
- },
-
- select_all : function (supress_event) {
- var tmp = this._data.core.selected.concat([]), i, j;
- this._data.core.selected = this._model.data[$.jstree.root].children_d.concat();
- for(i = 0, j = this._data.core.selected.length; i < j; i++) {
- if(this._model.data[this._data.core.selected[i]]) {
- this._model.data[this._data.core.selected[i]].state.selected = true;
- }
- }
- this.redraw(true);
-
- this.trigger('select_all', { 'selected' : this._data.core.selected });
- if(!supress_event) {
- this.trigger('changed', { 'action' : 'select_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
- }
- },
-
- deselect_all : function (supress_event) {
- var tmp = this._data.core.selected.concat([]), i, j;
- for(i = 0, j = this._data.core.selected.length; i < j; i++) {
- if(this._model.data[this._data.core.selected[i]]) {
- this._model.data[this._data.core.selected[i]].state.selected = false;
- }
- }
- this._data.core.selected = [];
- this.element.find('.jstree-clicked').removeClass('jstree-clicked').attr('aria-selected', false);
-
- this.trigger('deselect_all', { 'selected' : this._data.core.selected, 'node' : tmp });
- if(!supress_event) {
- this.trigger('changed', { 'action' : 'deselect_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
- }
- },
-
- is_selected : function (obj) {
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- return obj.state.selected;
- },
-
- get_selected : function (full) {
- return full ? $.map(this._data.core.selected, function (i) { return this.get_node(i); }.bind(this)) : this._data.core.selected.slice();
- },
-
- get_top_selected : function (full) {
- var tmp = this.get_selected(true),
- obj = {}, i, j, k, l;
- for(i = 0, j = tmp.length; i < j; i++) {
- obj[tmp[i].id] = tmp[i];
- }
- for(i = 0, j = tmp.length; i < j; i++) {
- for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
- if(obj[tmp[i].children_d[k]]) {
- delete obj[tmp[i].children_d[k]];
- }
- }
- }
- tmp = [];
- for(i in obj) {
- if(obj.hasOwnProperty(i)) {
- tmp.push(i);
- }
- }
- return full ? $.map(tmp, function (i) { return this.get_node(i); }.bind(this)) : tmp;
- },
-
- get_bottom_selected : function (full) {
- var tmp = this.get_selected(true),
- obj = [], i, j;
- for(i = 0, j = tmp.length; i < j; i++) {
- if(!tmp[i].children.length) {
- obj.push(tmp[i].id);
- }
- }
- return full ? $.map(obj, function (i) { return this.get_node(i); }.bind(this)) : obj;
- },
-
- get_state : function () {
- var state = {
- 'core' : {
- 'open' : [],
- 'loaded' : [],
- 'scroll' : {
- 'left' : this.element.scrollLeft(),
- 'top' : this.element.scrollTop()
- },
-
- 'selected' : []
- }
- }, i;
- for(i in this._model.data) {
- if(this._model.data.hasOwnProperty(i)) {
- if(i !== $.jstree.root) {
- if(this._model.data[i].state.loaded && this.settings.core.loaded_state) {
- state.core.loaded.push(i);
- }
- if(this._model.data[i].state.opened) {
- state.core.open.push(i);
- }
- if(this._model.data[i].state.selected) {
- state.core.selected.push(i);
- }
- }
- }
- }
- return state;
- },
-
- set_state : function (state, callback) {
- if(state) {
- if(state.core && state.core.selected && state.core.initial_selection === undefined) {
- state.core.initial_selection = this._data.core.selected.concat([]).sort().join(',');
- }
- if(state.core) {
- var res, n, t, _this, i;
- if(state.core.loaded) {
- if(!this.settings.core.loaded_state || !$.vakata.is_array(state.core.loaded) || !state.core.loaded.length) {
- delete state.core.loaded;
- this.set_state(state, callback);
- }
- else {
- this._load_nodes(state.core.loaded, function (nodes) {
- delete state.core.loaded;
- this.set_state(state, callback);
- });
- }
- return false;
- }
- if(state.core.open) {
- if(!$.vakata.is_array(state.core.open) || !state.core.open.length) {
- delete state.core.open;
- this.set_state(state, callback);
- }
- else {
- this._load_nodes(state.core.open, function (nodes) {
- this.open_node(nodes, false, 0);
- delete state.core.open;
- this.set_state(state, callback);
- });
- }
- return false;
- }
- if(state.core.scroll) {
- if(state.core.scroll && state.core.scroll.left !== undefined) {
- this.element.scrollLeft(state.core.scroll.left);
- }
- if(state.core.scroll && state.core.scroll.top !== undefined) {
- this.element.scrollTop(state.core.scroll.top);
- }
- delete state.core.scroll;
- this.set_state(state, callback);
- return false;
- }
- if(state.core.selected) {
- _this = this;
- if (state.core.initial_selection === undefined ||
- state.core.initial_selection === this._data.core.selected.concat([]).sort().join(',')
- ) {
- this.deselect_all();
- $.each(state.core.selected, function (i, v) {
- _this.select_node(v, false, true);
- });
- }
- delete state.core.initial_selection;
- delete state.core.selected;
- this.set_state(state, callback);
- return false;
- }
- for(i in state) {
- if(state.hasOwnProperty(i) && i !== "core" && $.inArray(i, this.settings.plugins) === -1) {
- delete state[i];
- }
- }
- if($.isEmptyObject(state.core)) {
- delete state.core;
- this.set_state(state, callback);
- return false;
- }
- }
- if($.isEmptyObject(state)) {
- state = null;
- if(callback) { callback.call(this); }
-
- this.trigger('set_state');
- return false;
- }
- return true;
- }
- return false;
- },
-
- refresh : function (skip_loading, forget_state) {
- this._data.core.state = forget_state === true ? {} : this.get_state();
- if(forget_state && $.vakata.is_function(forget_state)) { this._data.core.state = forget_state.call(this, this._data.core.state); }
- this._cnt = 0;
- this._model.data = {};
- this._model.data[$.jstree.root] = {
- id : $.jstree.root,
- parent : null,
- parents : [],
- children : [],
- children_d : [],
- state : { loaded : false }
- };
- this._data.core.selected = [];
- this._data.core.last_clicked = null;
- this._data.core.focused = null;
- var c = this.get_container_ul()[0].className;
- if(!skip_loading) {
- this.element.html("<"+"ul class='"+c+"' role='group'><"+"li class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='none' 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>");
- this.element.attr('aria-activedescendant','j'+this._id+'_loading');
- }
- this.load_node($.jstree.root, function (o, s) {
- if(s) {
- this.get_container_ul()[0].className = c;
- if(this._firstChild(this.get_container_ul()[0])) {
- this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
- }
- this.set_state($.extend(true, {}, this._data.core.state), function () {
-
- this.trigger('refresh');
- });
- }
- this._data.core.state = null;
- });
- },
-
- refresh_node : function (obj) {
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- var opened = [], to_load = [], s = this._data.core.selected.concat([]);
- to_load.push(obj.id);
- if(obj.state.opened === true) { opened.push(obj.id); }
- this.get_node(obj, true).find('.jstree-open').each(function() { to_load.push(this.id); opened.push(this.id); });
- this._load_nodes(to_load, function (nodes) {
- this.open_node(opened, false, 0);
- this.select_node(s);
-
- this.trigger('refresh_node', { 'node' : obj, 'nodes' : nodes });
- }.bind(this), false, true);
- },
-
- set_id : function (obj, id) {
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- var i, j, m = this._model.data, old = obj.id;
- id = id.toString();
-
- m[obj.parent].children[$.inArray(obj.id, m[obj.parent].children)] = id;
- for(i = 0, j = obj.parents.length; i < j; i++) {
- m[obj.parents[i]].children_d[$.inArray(obj.id, m[obj.parents[i]].children_d)] = id;
- }
-
- for(i = 0, j = obj.children.length; i < j; i++) {
- m[obj.children[i]].parent = id;
- }
- for(i = 0, j = obj.children_d.length; i < j; i++) {
- m[obj.children_d[i]].parents[$.inArray(obj.id, m[obj.children_d[i]].parents)] = id;
- }
- i = $.inArray(obj.id, this._data.core.selected);
- if(i !== -1) { this._data.core.selected[i] = id; }
-
- i = this.get_node(obj.id, true);
- if(i) {
- i.attr('id', id);
- if(this.element.attr('aria-activedescendant') === obj.id) {
- this.element.attr('aria-activedescendant', id);
- }
- }
- delete m[obj.id];
- obj.id = id;
- obj.li_attr.id = id;
- m[id] = obj;
-
- this.trigger('set_id',{ "node" : obj, "new" : obj.id, "old" : old });
- return true;
- },
-
- get_text : function (obj) {
- obj = this.get_node(obj);
- return (!obj || obj.id === $.jstree.root) ? false : obj.text;
- },
-
- set_text : function (obj, val) {
- var t1, t2;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.set_text(obj[t1], val);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- obj.text = val;
- if(this.get_node(obj, true).length) {
- this.redraw_node(obj.id);
- }
-
- this.trigger('set_text',{ "obj" : obj, "text" : val });
- return true;
- },
-
- get_json : function (obj, options, flat) {
- obj = this.get_node(obj || $.jstree.root);
- if(!obj) { return false; }
- if(options && options.flat && !flat) { flat = []; }
- var tmp = {
- 'id' : obj.id,
- 'text' : obj.text,
- 'icon' : this.get_icon(obj),
- 'li_attr' : $.extend(true, {}, obj.li_attr),
- 'a_attr' : $.extend(true, {}, obj.a_attr),
- 'state' : {},
- 'data' : options && options.no_data ? false : $.extend(true, $.vakata.is_array(obj.data)?[]:{}, obj.data)
-
- }, i, j;
- if(options && options.flat) {
- tmp.parent = obj.parent;
- }
- else {
- tmp.children = [];
- }
- if(!options || !options.no_state) {
- for(i in obj.state) {
- if(obj.state.hasOwnProperty(i)) {
- tmp.state[i] = obj.state[i];
- }
- }
- } else {
- delete tmp.state;
- }
- if(options && options.no_li_attr) {
- delete tmp.li_attr;
- }
- if(options && options.no_a_attr) {
- delete tmp.a_attr;
- }
- if(options && options.no_id) {
- delete tmp.id;
- if(tmp.li_attr && tmp.li_attr.id) {
- delete tmp.li_attr.id;
- }
- if(tmp.a_attr && tmp.a_attr.id) {
- delete tmp.a_attr.id;
- }
- }
- if(options && options.flat && obj.id !== $.jstree.root) {
- flat.push(tmp);
- }
- if(!options || !options.no_children) {
- for(i = 0, j = obj.children.length; i < j; i++) {
- if(options && options.flat) {
- this.get_json(obj.children[i], options, flat);
- }
- else {
- tmp.children.push(this.get_json(obj.children[i], options));
- }
- }
- }
- return options && options.flat ? flat : (obj.id === $.jstree.root ? tmp.children : tmp);
- },
-
- create_node : function (par, node, pos, callback, is_loaded) {
- if(par === null) { par = $.jstree.root; }
- par = this.get_node(par);
- if(!par) { return false; }
- pos = pos === undefined ? "last" : pos;
- if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
- return this.load_node(par, function () { this.create_node(par, node, pos, callback, true); });
- }
- if(!node) { node = { "text" : this.get_string('New node') }; }
- if(typeof node === "string") {
- node = { "text" : node };
- } else {
- node = $.extend(true, {}, node);
- }
- if(node.text === undefined) { node.text = this.get_string('New node'); }
- var tmp, dpc, i, j;
- if(par.id === $.jstree.root) {
- if(pos === "before") { pos = "first"; }
- if(pos === "after") { pos = "last"; }
- }
- switch(pos) {
- case "before":
- tmp = this.get_node(par.parent);
- pos = $.inArray(par.id, tmp.children);
- par = tmp;
- break;
- case "after" :
- tmp = this.get_node(par.parent);
- pos = $.inArray(par.id, tmp.children) + 1;
- par = tmp;
- break;
- case "inside":
- case "first":
- pos = 0;
- break;
- case "last":
- pos = par.children.length;
- break;
- default:
- if(!pos) { pos = 0; }
- break;
- }
- if(pos > par.children.length) { pos = par.children.length; }
- if(node.id === undefined) { node.id = true; }
- if(!this.check("create_node", node, par, pos)) {
- this.settings.core.error.call(this, this._data.core.last_error);
- return false;
- }
- if(node.id === true) { delete node.id; }
- node = this._parse_model_from_json(node, par.id, par.parents.concat());
- if(!node) { return false; }
- tmp = this.get_node(node);
- dpc = [];
- dpc.push(node);
- dpc = dpc.concat(tmp.children_d);
- this.trigger('model', { "nodes" : dpc, "parent" : par.id });
- par.children_d = par.children_d.concat(dpc);
- for(i = 0, j = par.parents.length; i < j; i++) {
- this._model.data[par.parents[i]].children_d = this._model.data[par.parents[i]].children_d.concat(dpc);
- }
- node = tmp;
- tmp = [];
- for(i = 0, j = par.children.length; i < j; i++) {
- tmp[i >= pos ? i+1 : i] = par.children[i];
- }
- tmp[pos] = node.id;
- par.children = tmp;
- this.redraw_node(par, true);
-
- this.trigger('create_node', { "node" : this.get_node(node), "parent" : par.id, "position" : pos });
- if(callback) { callback.call(this, this.get_node(node)); }
- return node.id;
- },
-
- rename_node : function (obj, val) {
- var t1, t2, old;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.rename_node(obj[t1], val);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- old = obj.text;
- if(!this.check("rename_node", obj, this.get_parent(obj), val)) {
- this.settings.core.error.call(this, this._data.core.last_error);
- return false;
- }
- this.set_text(obj, val);
-
- this.trigger('rename_node', { "node" : obj, "text" : val, "old" : old });
- return true;
- },
-
- delete_node : function (obj) {
- var t1, t2, par, pos, tmp, i, j, k, l, c, top, lft;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.delete_node(obj[t1]);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- par = this.get_node(obj.parent);
- pos = $.inArray(obj.id, par.children);
- c = false;
- if(!this.check("delete_node", obj, par, pos)) {
- this.settings.core.error.call(this, this._data.core.last_error);
- return false;
- }
- if(pos !== -1) {
- par.children = $.vakata.array_remove(par.children, pos);
- }
- tmp = obj.children_d.concat([]);
- tmp.push(obj.id);
- for(i = 0, j = obj.parents.length; i < j; i++) {
- this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
- return $.inArray(v, tmp) === -1;
- });
- }
- for(k = 0, l = tmp.length; k < l; k++) {
- if(this._model.data[tmp[k]].state.selected) {
- c = true;
- break;
- }
- }
- if (c) {
- this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
- return $.inArray(v, tmp) === -1;
- });
- }
-
- this.trigger('delete_node', { "node" : obj, "parent" : par.id });
- if(c) {
- this.trigger('changed', { 'action' : 'delete_node', 'node' : obj, 'selected' : this._data.core.selected, 'parent' : par.id });
- }
- for(k = 0, l = tmp.length; k < l; k++) {
- delete this._model.data[tmp[k]];
- }
- if($.inArray(this._data.core.focused, tmp) !== -1) {
- this._data.core.focused = null;
- top = this.element[0].scrollTop;
- lft = this.element[0].scrollLeft;
- if(par.id === $.jstree.root) {
- if (this._model.data[$.jstree.root].children[0]) {
- this.get_node(this._model.data[$.jstree.root].children[0], true).children('.jstree-anchor').trigger('focus');
- }
- }
- else {
- this.get_node(par, true).children('.jstree-anchor').trigger('focus');
- }
- this.element[0].scrollTop = top;
- this.element[0].scrollLeft = lft;
- }
- this.redraw_node(par, true);
- return true;
- },
-
- check : function (chk, obj, par, pos, more) {
- obj = obj && obj.id ? obj : this.get_node(obj);
- par = par && par.id ? par : this.get_node(par);
- var tmp = chk.match(/^(move_node|copy_node|create_node)$/i) ? par : obj,
- chc = this.settings.core.check_callback;
- if(chk === "move_node" || chk === "copy_node") {
- if((!more || !more.is_multi) && (chk === "move_node" && $.inArray(obj.id, par.children) === pos)) {
- 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 }) };
- return false;
- }
- 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)) {
- 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 }) };
- return false;
- }
- }
- if(tmp && tmp.data) { tmp = tmp.data; }
- if(tmp && tmp.functions && (tmp.functions[chk] === false || tmp.functions[chk] === true)) {
- if(tmp.functions[chk] === false) {
- 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 }) };
- }
- return tmp.functions[chk];
- }
- if(chc === false || ($.vakata.is_function(chc) && chc.call(this, chk, obj, par, pos, more) === false) || (chc && chc[chk] === false)) {
- 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 }) };
- return false;
- }
- return true;
- },
-
- last_error : function () {
- return this._data.core.last_error;
- },
-
- move_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
- var t1, t2, old_par, old_pos, new_par, old_ins, is_multi, dpc, tmp, i, j, k, l, p;
- par = this.get_node(par);
- pos = pos === undefined ? 0 : pos;
- if(!par) { return false; }
- if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
- return this.load_node(par, function () { this.move_node(obj, par, pos, callback, true, false, origin); });
- }
- if($.vakata.is_array(obj)) {
- if(obj.length === 1) {
- obj = obj[0];
- }
- else {
-
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- if((tmp = this.move_node(obj[t1], par, pos, callback, is_loaded, false, origin))) {
- par = tmp;
- pos = "after";
- }
- }
- this.redraw();
- return true;
- }
- }
- obj = obj && (obj.id !== undefined) ? obj : this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- old_par = (obj.parent || $.jstree.root).toString();
- new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
- old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
- is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
- 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;
- if(old_ins && old_ins._id) {
- obj = old_ins._model.data[obj.id];
- }
- if(is_multi) {
- if((tmp = this.copy_node(obj, par, pos, callback, is_loaded, false, origin))) {
- if(old_ins) { old_ins.delete_node(obj); }
- return tmp;
- }
- return false;
- }
-
- if(par.id === $.jstree.root) {
- if(pos === "before") { pos = "first"; }
- if(pos === "after") { pos = "last"; }
- }
- switch(pos) {
- case "before":
- pos = $.inArray(par.id, new_par.children);
- break;
- case "after" :
- pos = $.inArray(par.id, new_par.children) + 1;
- break;
- case "inside":
- case "first":
- pos = 0;
- break;
- case "last":
- pos = new_par.children.length;
- break;
- default:
- if(!pos) { pos = 0; }
- break;
- }
- if(pos > new_par.children.length) { pos = new_par.children.length; }
- 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) })) {
- this.settings.core.error.call(this, this._data.core.last_error);
- return false;
- }
- if(obj.parent === new_par.id) {
- dpc = new_par.children.concat();
- tmp = $.inArray(obj.id, dpc);
- if(tmp !== -1) {
- dpc = $.vakata.array_remove(dpc, tmp);
- if(pos > tmp) { pos--; }
- }
- tmp = [];
- for(i = 0, j = dpc.length; i < j; i++) {
- tmp[i >= pos ? i+1 : i] = dpc[i];
- }
- tmp[pos] = obj.id;
- new_par.children = tmp;
- this._node_changed(new_par.id);
- this.redraw(new_par.id === $.jstree.root);
- }
- else {
-
- tmp = obj.children_d.concat();
- tmp.push(obj.id);
- for(i = 0, j = obj.parents.length; i < j; i++) {
- dpc = [];
- p = old_ins._model.data[obj.parents[i]].children_d;
- for(k = 0, l = p.length; k < l; k++) {
- if($.inArray(p[k], tmp) === -1) {
- dpc.push(p[k]);
- }
- }
- old_ins._model.data[obj.parents[i]].children_d = dpc;
- }
- old_ins._model.data[old_par].children = $.vakata.array_remove_item(old_ins._model.data[old_par].children, obj.id);
-
- for(i = 0, j = new_par.parents.length; i < j; i++) {
- this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(tmp);
- }
- dpc = [];
- for(i = 0, j = new_par.children.length; i < j; i++) {
- dpc[i >= pos ? i+1 : i] = new_par.children[i];
- }
- dpc[pos] = obj.id;
- new_par.children = dpc;
- new_par.children_d.push(obj.id);
- new_par.children_d = new_par.children_d.concat(obj.children_d);
-
- obj.parent = new_par.id;
- tmp = new_par.parents.concat();
- tmp.unshift(new_par.id);
- p = obj.parents.length;
- obj.parents = tmp;
-
- tmp = tmp.concat();
- for(i = 0, j = obj.children_d.length; i < j; i++) {
- this._model.data[obj.children_d[i]].parents = this._model.data[obj.children_d[i]].parents.slice(0,p*-1);
- Array.prototype.push.apply(this._model.data[obj.children_d[i]].parents, tmp);
- }
- if(old_par === $.jstree.root || new_par.id === $.jstree.root) {
- this._model.force_full_redraw = true;
- }
- if(!this._model.force_full_redraw) {
- this._node_changed(old_par);
- this._node_changed(new_par.id);
- }
- if(!skip_redraw) {
- this.redraw();
- }
- }
- if(callback) { callback.call(this, obj, new_par, pos); }
-
- 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 });
- return obj.id;
- },
-
- copy_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
- var t1, t2, dpc, tmp, i, j, node, old_par, new_par, old_ins, is_multi;
- par = this.get_node(par);
- pos = pos === undefined ? 0 : pos;
- if(!par) { return false; }
- if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
- return this.load_node(par, function () { this.copy_node(obj, par, pos, callback, true, false, origin); });
- }
- if($.vakata.is_array(obj)) {
- if(obj.length === 1) {
- obj = obj[0];
- }
- else {
-
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- if((tmp = this.copy_node(obj[t1], par, pos, callback, is_loaded, true, origin))) {
- par = tmp;
- pos = "after";
- }
- }
- this.redraw();
- return true;
- }
- }
- obj = obj && (obj.id !== undefined) ? obj : this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- old_par = (obj.parent || $.jstree.root).toString();
- new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
- old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
- is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
- if(old_ins && old_ins._id) {
- obj = old_ins._model.data[obj.id];
- }
- if(par.id === $.jstree.root) {
- if(pos === "before") { pos = "first"; }
- if(pos === "after") { pos = "last"; }
- }
- switch(pos) {
- case "before":
- pos = $.inArray(par.id, new_par.children);
- break;
- case "after" :
- pos = $.inArray(par.id, new_par.children) + 1;
- break;
- case "inside":
- case "first":
- pos = 0;
- break;
- case "last":
- pos = new_par.children.length;
- break;
- default:
- if(!pos) { pos = 0; }
- break;
- }
- if(pos > new_par.children.length) { pos = new_par.children.length; }
- 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) })) {
- this.settings.core.error.call(this, this._data.core.last_error);
- return false;
- }
- node = old_ins ? old_ins.get_json(obj, { no_id : true, no_data : true, no_state : true }) : obj;
- if(!node) { return false; }
- if(node.id === true) { delete node.id; }
- node = this._parse_model_from_json(node, new_par.id, new_par.parents.concat());
- if(!node) { return false; }
- tmp = this.get_node(node);
- if(obj && obj.state && obj.state.loaded === false) { tmp.state.loaded = false; }
- dpc = [];
- dpc.push(node);
- dpc = dpc.concat(tmp.children_d);
- this.trigger('model', { "nodes" : dpc, "parent" : new_par.id });
-
- for(i = 0, j = new_par.parents.length; i < j; i++) {
- this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(dpc);
- }
- dpc = [];
- for(i = 0, j = new_par.children.length; i < j; i++) {
- dpc[i >= pos ? i+1 : i] = new_par.children[i];
- }
- dpc[pos] = tmp.id;
- new_par.children = dpc;
- new_par.children_d.push(tmp.id);
- new_par.children_d = new_par.children_d.concat(tmp.children_d);
- if(new_par.id === $.jstree.root) {
- this._model.force_full_redraw = true;
- }
- if(!this._model.force_full_redraw) {
- this._node_changed(new_par.id);
- }
- if(!skip_redraw) {
- this.redraw(new_par.id === $.jstree.root);
- }
- if(callback) { callback.call(this, tmp, new_par, pos); }
-
- 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 });
- return tmp.id;
- },
-
- cut : function (obj) {
- if(!obj) { obj = this._data.core.selected.concat(); }
- if(!$.vakata.is_array(obj)) { obj = [obj]; }
- if(!obj.length) { return false; }
- var tmp = [], o, t1, t2;
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- o = this.get_node(obj[t1]);
- if(o && (o.id || o.id === 0) && o.id !== $.jstree.root) { tmp.push(o); }
- }
- if(!tmp.length) { return false; }
- ccp_node = tmp;
- ccp_inst = this;
- ccp_mode = 'move_node';
-
- this.trigger('cut', { "node" : obj });
- },
-
- copy : function (obj) {
- if(!obj) { obj = this._data.core.selected.concat(); }
- if(!$.vakata.is_array(obj)) { obj = [obj]; }
- if(!obj.length) { return false; }
- var tmp = [], o, t1, t2;
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- o = this.get_node(obj[t1]);
- if(o && (o.id !== undefined) && o.id !== $.jstree.root) { tmp.push(o); }
- }
- if(!tmp.length) { return false; }
- ccp_node = tmp;
- ccp_inst = this;
- ccp_mode = 'copy_node';
-
- this.trigger('copy', { "node" : obj });
- },
-
- get_buffer : function () {
- return { 'mode' : ccp_mode, 'node' : ccp_node, 'inst' : ccp_inst };
- },
-
- can_paste : function () {
- return ccp_mode !== false && ccp_node !== false;
- },
-
- paste : function (obj, pos) {
- obj = this.get_node(obj);
- if(!obj || !ccp_mode || !ccp_mode.match(/^(copy_node|move_node)$/) || !ccp_node) { return false; }
- if(this[ccp_mode](ccp_node, obj, pos, false, false, false, ccp_inst)) {
-
- this.trigger('paste', { "parent" : obj.id, "node" : ccp_node, "mode" : ccp_mode });
- }
- ccp_node = false;
- ccp_mode = false;
- ccp_inst = false;
- },
-
- clear_buffer : function () {
- ccp_node = false;
- ccp_mode = false;
- ccp_inst = false;
-
- this.trigger('clear_buffer');
- },
-
- edit : function (obj, default_text, callback) {
- var rtl, w, a, s, t, h1, h2, fn, tmp, cancel = false;
- obj = this.get_node(obj);
- if(!obj) { return false; }
- if(!this.check("edit", obj, this.get_parent(obj))) {
- this.settings.core.error.call(this, this._data.core.last_error);
- return false;
- }
- tmp = obj;
- default_text = typeof default_text === 'string' ? default_text : obj.text;
- this.set_text(obj, "");
- obj = this._open_to(obj);
- tmp.text = default_text;
- rtl = this._data.core.rtl;
- w = this.element.width();
- this._data.core.focused = tmp.id;
- a = obj.children('.jstree-anchor').trigger('focus');
- s = $('<span></span>');
-
- t = default_text;
- h1 = $("<"+"div></div>", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo(document.body);
- h2 = $("<"+"input />", {
- "value" : t,
- "class" : "jstree-rename-input",
-
- "css" : {
- "padding" : "0",
- "border" : "1px solid silver",
- "box-sizing" : "border-box",
- "display" : "inline-block",
- "height" : (this._data.core.li_height) + "px",
- "lineHeight" : (this._data.core.li_height) + "px",
- "width" : "150px"
- },
- "blur" : function (e) {
- e.stopImmediatePropagation();
- e.preventDefault();
- var i = s.children(".jstree-rename-input"),
- v = i.val(),
- f = this.settings.core.force_text,
- nv;
- if(v === "") { v = t; }
- h1.remove();
- s.replaceWith(a);
- s.remove();
- t = f ? t : $('<div></div>').append($.parseHTML(t)).html();
- obj = this.get_node(obj);
- this.set_text(obj, t);
- nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html());
- if(!nv) {
- this.set_text(obj, t);
- }
- this._data.core.focused = tmp.id;
- setTimeout(function () {
- var node = this.get_node(tmp.id, true);
- if(node.length) {
- this._data.core.focused = tmp.id;
- node.children('.jstree-anchor').trigger('focus');
- }
- }.bind(this), 0);
- if(callback) {
- callback.call(this, tmp, nv, cancel, v);
- }
- h2 = null;
- }.bind(this),
- "keydown" : function (e) {
- var key = e.which;
- if(key === 27) {
- cancel = true;
- this.value = t;
- }
- if(key === 27 || key === 13 || key === 37 || key === 38 || key === 39 || key === 40 || key === 32) {
- e.stopImmediatePropagation();
- }
- if(key === 27 || key === 13) {
- e.preventDefault();
- this.blur();
- }
- },
- "click" : function (e) { e.stopImmediatePropagation(); },
- "mousedown" : function (e) { e.stopImmediatePropagation(); },
- "keyup" : function (e) {
- h2.width(Math.min(h1.text("pW" + this.value).width(),w));
- },
- "keypress" : function(e) {
- if(e.which === 13) { return false; }
- }
- });
- fn = {
- fontFamily : a.css('fontFamily') || '',
- fontSize : a.css('fontSize') || '',
- fontWeight : a.css('fontWeight') || '',
- fontStyle : a.css('fontStyle') || '',
- fontStretch : a.css('fontStretch') || '',
- fontVariant : a.css('fontVariant') || '',
- letterSpacing : a.css('letterSpacing') || '',
- wordSpacing : a.css('wordSpacing') || ''
- };
- s.attr('class', a.attr('class')).append(a.contents().clone()).append(h2);
- a.replaceWith(s);
- h1.css(fn);
- h2.css(fn).width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
- $(document).one('mousedown.jstree touchstart.jstree dnd_start.vakata', function (e) {
- if (h2 && e.target !== h2) {
- $(h2).trigger('blur');
- }
- });
- },
-
- set_theme : function (theme_name, theme_url) {
- if(!theme_name) { return false; }
- if(theme_url === true) {
- var dir = this.settings.core.themes.dir;
- if(!dir) { dir = $.jstree.path + '/themes'; }
- theme_url = dir + '/' + theme_name + '/style.css';
- }
- if(theme_url && $.inArray(theme_url, themes_loaded) === -1) {
- $('head').append('<'+'link rel="stylesheet" href="' + theme_url + '" type="text/css" />');
- themes_loaded.push(theme_url);
- }
- if(this._data.core.themes.name) {
- this.element.removeClass('jstree-' + this._data.core.themes.name);
- }
- this._data.core.themes.name = theme_name;
- this.element.addClass('jstree-' + theme_name);
- this.element[this.settings.core.themes.responsive ? 'addClass' : 'removeClass' ]('jstree-' + theme_name + '-responsive');
-
- this.trigger('set_theme', { 'theme' : theme_name });
- },
-
- get_theme : function () { return this._data.core.themes.name; },
-
- set_theme_variant : function (variant_name) {
- if(this._data.core.themes.variant) {
- this.element.removeClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
- }
- this._data.core.themes.variant = variant_name;
- if(variant_name) {
- this.element.addClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
- }
- },
-
- get_theme_variant : function () { return this._data.core.themes.variant; },
-
- show_stripes : function () {
- this._data.core.themes.stripes = true;
- this.get_container_ul().addClass("jstree-striped");
-
- this.trigger('show_stripes');
- },
-
- hide_stripes : function () {
- this._data.core.themes.stripes = false;
- this.get_container_ul().removeClass("jstree-striped");
-
- this.trigger('hide_stripes');
- },
-
- toggle_stripes : function () { if(this._data.core.themes.stripes) { this.hide_stripes(); } else { this.show_stripes(); } },
-
- show_dots : function () {
- this._data.core.themes.dots = true;
- this.get_container_ul().removeClass("jstree-no-dots");
-
- this.trigger('show_dots');
- },
-
- hide_dots : function () {
- this._data.core.themes.dots = false;
- this.get_container_ul().addClass("jstree-no-dots");
-
- this.trigger('hide_dots');
- },
-
- toggle_dots : function () { if(this._data.core.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
-
- show_icons : function () {
- this._data.core.themes.icons = true;
- this.get_container_ul().removeClass("jstree-no-icons");
-
- this.trigger('show_icons');
- },
-
- hide_icons : function () {
- this._data.core.themes.icons = false;
- this.get_container_ul().addClass("jstree-no-icons");
-
- this.trigger('hide_icons');
- },
-
- toggle_icons : function () { if(this._data.core.themes.icons) { this.hide_icons(); } else { this.show_icons(); } },
-
- show_ellipsis : function () {
- this._data.core.themes.ellipsis = true;
- this.get_container_ul().addClass("jstree-ellipsis");
-
- this.trigger('show_ellipsis');
- },
-
- hide_ellipsis : function () {
- this._data.core.themes.ellipsis = false;
- this.get_container_ul().removeClass("jstree-ellipsis");
-
- this.trigger('hide_ellipsis');
- },
-
- toggle_ellipsis : function () { if(this._data.core.themes.ellipsis) { this.hide_ellipsis(); } else { this.show_ellipsis(); } },
-
- set_icon : function (obj, icon) {
- var t1, t2, dom, old;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.set_icon(obj[t1], icon);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- old = obj.icon;
- obj.icon = icon === true || icon === null || icon === undefined || icon === '' ? true : icon;
- dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
- if(icon === false) {
- dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
- this.hide_icon(obj);
- }
- else if(icon === true || icon === null || icon === undefined || icon === '') {
- dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
- if(old === false) { this.show_icon(obj); }
- }
- else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
- dom.removeClass(old).css("background","");
- dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
- if(old === false) { this.show_icon(obj); }
- }
- else {
- dom.removeClass(old).css("background","");
- dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
- if(old === false) { this.show_icon(obj); }
- }
- return true;
- },
-
- get_icon : function (obj) {
- obj = this.get_node(obj);
- return (!obj || obj.id === $.jstree.root) ? false : obj.icon;
- },
-
- hide_icon : function (obj) {
- var t1, t2;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.hide_icon(obj[t1]);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj === $.jstree.root) { return false; }
- obj.icon = false;
- this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon").addClass('jstree-themeicon-hidden');
- return true;
- },
-
- show_icon : function (obj) {
- var t1, t2, dom;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.show_icon(obj[t1]);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj === $.jstree.root) { return false; }
- dom = this.get_node(obj, true);
- obj.icon = dom.length ? dom.children(".jstree-anchor").children(".jstree-themeicon").attr('rel') : true;
- if(!obj.icon) { obj.icon = true; }
- dom.children(".jstree-anchor").children(".jstree-themeicon").removeClass('jstree-themeicon-hidden');
- return true;
- }
- };
-
- $.vakata = {};
-
- $.vakata.attributes = function(node, with_values) {
- node = $(node)[0];
- var attr = with_values ? {} : [];
- if(node && node.attributes) {
- $.each(node.attributes, function (i, v) {
- if($.inArray(v.name.toLowerCase(),['style','contenteditable','hasfocus','tabindex']) !== -1) { return; }
- if(v.value !== null && $.vakata.trim(v.value) !== '') {
- if(with_values) { attr[v.name] = v.value; }
- else { attr.push(v.name); }
- }
- });
- }
- return attr;
- };
- $.vakata.array_unique = function(array) {
- var a = [], i, j, l, o = {};
- for(i = 0, l = array.length; i < l; i++) {
- if(o[array[i]] === undefined) {
- a.push(array[i]);
- o[array[i]] = true;
- }
- }
- return a;
- };
-
- $.vakata.array_remove = function(array, from) {
- array.splice(from, 1);
- return array;
-
-
-
-
- };
-
- $.vakata.array_remove_item = function(array, item) {
- var tmp = $.inArray(item, array);
- return tmp !== -1 ? $.vakata.array_remove(array, tmp) : array;
- };
- $.vakata.array_filter = function(c,a,b,d,e) {
- if (c.filter) {
- return c.filter(a, b);
- }
- d=[];
- for (e in c) {
- if (~~e+''===e+'' && e>=0 && a.call(b,c[e],+e,c)) {
- d.push(c[e]);
- }
- }
- return d;
- };
- $.vakata.trim = function (text) {
- return String.prototype.trim ?
- String.prototype.trim.call(text.toString()) :
- text.toString().replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
- };
- $.vakata.is_function = function(obj) {
- return typeof obj === "function" && typeof obj.nodeType !== "number";
- };
- $.vakata.is_array = Array.isArray || function (obj) {
- return Object.prototype.toString.call(obj) === "[object Array]";
- };
-
- if (!Function.prototype.bind) {
- Function.prototype.bind = function () {
- var thatFunc = this, thatArg = arguments[0];
- var args = Array.prototype.slice.call(arguments, 1);
- if (typeof thatFunc !== 'function') {
-
-
- throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
- }
- return function(){
- var funcArgs = args.concat(Array.prototype.slice.call(arguments));
- return thatFunc.apply(thatArg, funcArgs);
- };
- };
- }
- $.jstree.plugins.changed = function (options, parent) {
- var last = [];
- this.trigger = function (ev, data) {
- var i, j;
- if(!data) {
- data = {};
- }
- if(ev.replace('.jstree','') === 'changed') {
- data.changed = { selected : [], deselected : [] };
- var tmp = {};
- for(i = 0, j = last.length; i < j; i++) {
- tmp[last[i]] = 1;
- }
- for(i = 0, j = data.selected.length; i < j; i++) {
- if(!tmp[data.selected[i]]) {
- data.changed.selected.push(data.selected[i]);
- }
- else {
- tmp[data.selected[i]] = 2;
- }
- }
- for(i = 0, j = last.length; i < j; i++) {
- if(tmp[last[i]] === 1) {
- data.changed.deselected.push(last[i]);
- }
- }
- last = data.selected.slice();
- }
-
- parent.trigger.call(this, ev, data);
- };
- this.refresh = function (skip_loading, forget_state) {
- last = [];
- return parent.refresh.apply(this, arguments);
- };
- };
- var _i = document.createElement('I');
- _i.className = 'jstree-icon jstree-checkbox';
- _i.setAttribute('role', 'presentation');
-
- $.jstree.defaults.checkbox = {
-
- visible : true,
-
- three_state : true,
-
- whole_node : true,
-
- keep_selected_style : true,
-
- cascade : '',
-
- tie_selection : true,
-
- cascade_to_disabled : true,
-
- cascade_to_hidden : true
- };
- $.jstree.plugins.checkbox = function (options, parent) {
- this.bind = function () {
- parent.bind.call(this);
- this._data.checkbox.uto = false;
- this._data.checkbox.selected = [];
- if(this.settings.checkbox.three_state) {
- this.settings.checkbox.cascade = 'up+down+undetermined';
- }
- this.element
- .on("init.jstree", function () {
- this._data.checkbox.visible = this.settings.checkbox.visible;
- if(!this.settings.checkbox.keep_selected_style) {
- this.element.addClass('jstree-checkbox-no-clicked');
- }
- if(this.settings.checkbox.tie_selection) {
- this.element.addClass('jstree-checkbox-selection');
- }
- }.bind(this))
- .on("loading.jstree", function () {
- this[ this._data.checkbox.visible ? 'show_checkboxes' : 'hide_checkboxes' ]();
- }.bind(this));
- if(this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
- this.element
- .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', function () {
-
- if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
- this._data.checkbox.uto = setTimeout(this._undetermined.bind(this), 50);
- }.bind(this));
- }
- if(!this.settings.checkbox.tie_selection) {
- this.element
- .on('model.jstree', function (e, data) {
- var m = this._model.data,
- p = m[data.parent],
- dpc = data.nodes,
- i, j;
- for(i = 0, j = dpc.length; i < j; i++) {
- 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);
- if(m[dpc[i]].state.checked) {
- this._data.checkbox.selected.push(dpc[i]);
- }
- }
- }.bind(this));
- }
- if(this.settings.checkbox.cascade.indexOf('up') !== -1 || this.settings.checkbox.cascade.indexOf('down') !== -1) {
- this.element
- .on('model.jstree', function (e, data) {
- var m = this._model.data,
- p = m[data.parent],
- dpc = data.nodes,
- chd = [],
- c, i, j, k, l, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection;
- if(s.indexOf('down') !== -1) {
-
- if(p.state[ t ? 'selected' : 'checked' ]) {
- for(i = 0, j = dpc.length; i < j; i++) {
- m[dpc[i]].state[ t ? 'selected' : 'checked' ] = true;
- }
- this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(dpc);
- }
- else {
- for(i = 0, j = dpc.length; i < j; i++) {
- if(m[dpc[i]].state[ t ? 'selected' : 'checked' ]) {
- for(k = 0, l = m[dpc[i]].children_d.length; k < l; k++) {
- m[m[dpc[i]].children_d[k]].state[ t ? 'selected' : 'checked' ] = true;
- }
- this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(m[dpc[i]].children_d);
- }
- }
- }
- }
- if(s.indexOf('up') !== -1) {
-
- for(i = 0, j = p.children_d.length; i < j; i++) {
- if(!m[p.children_d[i]].children.length) {
- chd.push(m[p.children_d[i]].parent);
- }
- }
- chd = $.vakata.array_unique(chd);
- for(k = 0, l = chd.length; k < l; k++) {
- p = m[chd[k]];
- while(p && p.id !== $.jstree.root) {
- c = 0;
- for(i = 0, j = p.children.length; i < j; i++) {
- c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
- }
- if(c === j) {
- p.state[ t ? 'selected' : 'checked' ] = true;
- this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
- tmp = this.get_node(p, true);
- if(tmp && tmp.length) {
- tmp.children('.jstree-anchor').attr('aria-selected', true).addClass( t ? 'jstree-clicked' : 'jstree-checked');
- }
- }
- else {
- break;
- }
- p = this.get_node(p.parent);
- }
- }
- }
- this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected);
- }.bind(this))
- .on(this.settings.checkbox.tie_selection ? 'select_node.jstree' : 'check_node.jstree', function (e, data) {
- var self = this,
- obj = data.node,
- m = this._model.data,
- par = this.get_node(obj.parent),
- i, j, c, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
- sel = {}, cur = this._data[ t ? 'core' : 'checkbox' ].selected;
- for (i = 0, j = cur.length; i < j; i++) {
- sel[cur[i]] = true;
- }
-
- if(s.indexOf('down') !== -1) {
-
- var selectedIds = this._cascade_new_checked_state(obj.id, true);
- var temp = obj.children_d.concat(obj.id);
- for (i = 0, j = temp.length; i < j; i++) {
- if (selectedIds.indexOf(temp[i]) > -1) {
- sel[temp[i]] = true;
- }
- else {
- delete sel[temp[i]];
- }
- }
- }
-
- if(s.indexOf('up') !== -1) {
- while(par && par.id !== $.jstree.root) {
- c = 0;
- for(i = 0, j = par.children.length; i < j; i++) {
- c += m[par.children[i]].state[ t ? 'selected' : 'checked' ];
- }
- if(c === j) {
- par.state[ t ? 'selected' : 'checked' ] = true;
- sel[par.id] = true;
-
- tmp = this.get_node(par, true);
- if(tmp && tmp.length) {
- tmp.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
- }
- }
- else {
- break;
- }
- par = this.get_node(par.parent);
- }
- }
- cur = [];
- for (i in sel) {
- if (sel.hasOwnProperty(i)) {
- cur.push(i);
- }
- }
- this._data[ t ? 'core' : 'checkbox' ].selected = cur;
- }.bind(this))
- .on(this.settings.checkbox.tie_selection ? 'deselect_all.jstree' : 'uncheck_all.jstree', function (e, data) {
- var obj = this.get_node($.jstree.root),
- m = this._model.data,
- i, j, tmp;
- for(i = 0, j = obj.children_d.length; i < j; i++) {
- tmp = m[obj.children_d[i]];
- if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
- tmp.original.state.undetermined = false;
- }
- }
- }.bind(this))
- .on(this.settings.checkbox.tie_selection ? 'deselect_node.jstree' : 'uncheck_node.jstree', function (e, data) {
- var self = this,
- obj = data.node,
- dom = this.get_node(obj, true),
- i, j, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
- cur = this._data[ t ? 'core' : 'checkbox' ].selected, sel = {},
- stillSelectedIds = [],
- allIds = obj.children_d.concat(obj.id);
-
- if(s.indexOf('down') !== -1) {
- var selectedIds = this._cascade_new_checked_state(obj.id, false);
- cur = $.vakata.array_filter(cur, function(id) {
- return allIds.indexOf(id) === -1 || selectedIds.indexOf(id) > -1;
- });
- }
-
-
- if(s.indexOf('up') !== -1 && cur.indexOf(obj.id) === -1) {
- for(i = 0, j = obj.parents.length; i < j; i++) {
- tmp = this._model.data[obj.parents[i]];
- tmp.state[ t ? 'selected' : 'checked' ] = false;
- if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
- tmp.original.state.undetermined = false;
- }
- tmp = this.get_node(obj.parents[i], true);
- if(tmp && tmp.length) {
- tmp.children('.jstree-anchor').attr('aria-selected', false).removeClass(t ? 'jstree-clicked' : 'jstree-checked');
- }
- }
- cur = $.vakata.array_filter(cur, function(id) {
- return obj.parents.indexOf(id) === -1;
- });
- }
- this._data[ t ? 'core' : 'checkbox' ].selected = cur;
- }.bind(this));
- }
- if(this.settings.checkbox.cascade.indexOf('up') !== -1) {
- this.element
- .on('delete_node.jstree', function (e, data) {
-
- var p = this.get_node(data.parent),
- m = this._model.data,
- i, j, c, tmp, t = this.settings.checkbox.tie_selection;
- while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
- c = 0;
- for(i = 0, j = p.children.length; i < j; i++) {
- c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
- }
- if(j > 0 && c === j) {
- p.state[ t ? 'selected' : 'checked' ] = true;
- this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
- tmp = this.get_node(p, true);
- if(tmp && tmp.length) {
- tmp.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
- }
- }
- else {
- break;
- }
- p = this.get_node(p.parent);
- }
- }.bind(this))
- .on('move_node.jstree', function (e, data) {
-
- var is_multi = data.is_multi,
- old_par = data.old_parent,
- new_par = this.get_node(data.parent),
- m = this._model.data,
- p, c, i, j, tmp, t = this.settings.checkbox.tie_selection;
- if(!is_multi) {
- p = this.get_node(old_par);
- while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
- c = 0;
- for(i = 0, j = p.children.length; i < j; i++) {
- c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
- }
- if(j > 0 && c === j) {
- p.state[ t ? 'selected' : 'checked' ] = true;
- this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
- tmp = this.get_node(p, true);
- if(tmp && tmp.length) {
- tmp.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
- }
- }
- else {
- break;
- }
- p = this.get_node(p.parent);
- }
- }
- p = new_par;
- while(p && p.id !== $.jstree.root) {
- c = 0;
- for(i = 0, j = p.children.length; i < j; i++) {
- c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
- }
- if(c === j) {
- if(!p.state[ t ? 'selected' : 'checked' ]) {
- p.state[ t ? 'selected' : 'checked' ] = true;
- this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
- tmp = this.get_node(p, true);
- if(tmp && tmp.length) {
- tmp.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
- }
- }
- }
- else {
- if(p.state[ t ? 'selected' : 'checked' ]) {
- p.state[ t ? 'selected' : 'checked' ] = false;
- this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_remove_item(this._data[ t ? 'core' : 'checkbox' ].selected, p.id);
- tmp = this.get_node(p, true);
- if(tmp && tmp.length) {
- tmp.children('.jstree-anchor').attr('aria-selected', false).removeClass(t ? 'jstree-clicked' : 'jstree-checked');
- }
- }
- else {
- break;
- }
- }
- p = this.get_node(p.parent);
- }
- }.bind(this));
- }
- };
-
- this.get_undetermined = function (full) {
- if (this.settings.checkbox.cascade.indexOf('undetermined') === -1) {
- return [];
- }
- 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 = [];
- for(i = 0, j = s.length; i < j; i++) {
- if(m[s[i]] && m[s[i]].parents) {
- for(k = 0, l = m[s[i]].parents.length; k < l; k++) {
- if(o[m[s[i]].parents[k]] !== undefined) {
- break;
- }
- if(m[s[i]].parents[k] !== $.jstree.root) {
- o[m[s[i]].parents[k]] = true;
- p.push(m[s[i]].parents[k]);
- }
- }
- }
- }
-
- this.element.find('.jstree-closed').not(':has(.jstree-children)')
- .each(function () {
- var tmp = tt.get_node(this), tmp2;
-
- if(!tmp) { return; }
-
- if(!tmp.state.loaded) {
- if(tmp.original && tmp.original.state && tmp.original.state.undetermined && tmp.original.state.undetermined === true) {
- if(o[tmp.id] === undefined && tmp.id !== $.jstree.root) {
- o[tmp.id] = true;
- p.push(tmp.id);
- }
- for(k = 0, l = tmp.parents.length; k < l; k++) {
- if(o[tmp.parents[k]] === undefined && tmp.parents[k] !== $.jstree.root) {
- o[tmp.parents[k]] = true;
- p.push(tmp.parents[k]);
- }
- }
- }
- }
- else {
- for(i = 0, j = tmp.children_d.length; i < j; i++) {
- tmp2 = m[tmp.children_d[i]];
- if(!tmp2.state.loaded && tmp2.original && tmp2.original.state && tmp2.original.state.undetermined && tmp2.original.state.undetermined === true) {
- if(o[tmp2.id] === undefined && tmp2.id !== $.jstree.root) {
- o[tmp2.id] = true;
- p.push(tmp2.id);
- }
- for(k = 0, l = tmp2.parents.length; k < l; k++) {
- if(o[tmp2.parents[k]] === undefined && tmp2.parents[k] !== $.jstree.root) {
- o[tmp2.parents[k]] = true;
- p.push(tmp2.parents[k]);
- }
- }
- }
- }
- }
- });
- for (i = 0, j = p.length; i < j; i++) {
- if(!m[p[i]].state[ t ? 'selected' : 'checked' ]) {
- r.push(full ? m[p[i]] : p[i]);
- }
- }
- return r;
- };
-
- this._undetermined = function () {
- if(this.element === null) { return; }
- var p = this.get_undetermined(false), i, j, s;
- this.element.find('.jstree-undetermined').removeClass('jstree-undetermined');
- for (i = 0, j = p.length; i < j; i++) {
- s = this.get_node(p[i], true);
- if(s && s.length) {
- s.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-undetermined');
- }
- }
- };
- this.redraw_node = function(obj, deep, is_callback, force_render) {
- obj = parent.redraw_node.apply(this, arguments);
- if(obj) {
- var i, j, tmp = null, icon = null;
- for(i = 0, j = obj.childNodes.length; i < j; i++) {
- if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
- tmp = obj.childNodes[i];
- break;
- }
- }
- if(tmp) {
- if(!this.settings.checkbox.tie_selection && this._model.data[obj.id].state.checked) { tmp.className += ' jstree-checked'; }
- icon = _i.cloneNode(false);
- if(this._model.data[obj.id].state.checkbox_disabled) { icon.className += ' jstree-checkbox-disabled'; }
- tmp.insertBefore(icon, tmp.childNodes[0]);
- }
- }
- if(!is_callback && this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
- if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
- this._data.checkbox.uto = setTimeout(this._undetermined.bind(this), 50);
- }
- return obj;
- };
-
- this.show_checkboxes = function () { this._data.core.themes.checkboxes = true; this.get_container_ul().removeClass("jstree-no-checkboxes"); };
-
- this.hide_checkboxes = function () { this._data.core.themes.checkboxes = false; this.get_container_ul().addClass("jstree-no-checkboxes"); };
-
- this.toggle_checkboxes = function () { if(this._data.core.themes.checkboxes) { this.hide_checkboxes(); } else { this.show_checkboxes(); } };
-
- this.is_undetermined = function (obj) {
- obj = this.get_node(obj);
- 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;
- if(!obj || obj.state[ t ? 'selected' : 'checked' ] === true || s.indexOf('undetermined') === -1 || (s.indexOf('down') === -1 && s.indexOf('up') === -1)) {
- return false;
- }
- if(!obj.state.loaded && obj.original.state.undetermined === true) {
- return true;
- }
- for(i = 0, j = obj.children_d.length; i < j; i++) {
- if($.inArray(obj.children_d[i], d) !== -1 || (!m[obj.children_d[i]].state.loaded && m[obj.children_d[i]].original.state.undetermined)) {
- return true;
- }
- }
- return false;
- };
-
- this.disable_checkbox = function (obj) {
- var t1, t2, dom;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.disable_checkbox(obj[t1]);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- dom = this.get_node(obj, true);
- if(!obj.state.checkbox_disabled) {
- obj.state.checkbox_disabled = true;
- if(dom && dom.length) {
- dom.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-checkbox-disabled');
- }
-
- this.trigger('disable_checkbox', { 'node' : obj });
- }
- };
-
- this.enable_checkbox = function (obj) {
- var t1, t2, dom;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.enable_checkbox(obj[t1]);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- dom = this.get_node(obj, true);
- if(obj.state.checkbox_disabled) {
- obj.state.checkbox_disabled = false;
- if(dom && dom.length) {
- dom.children('.jstree-anchor').children('.jstree-checkbox').removeClass('jstree-checkbox-disabled');
- }
-
- this.trigger('enable_checkbox', { 'node' : obj });
- }
- };
- this.activate_node = function (obj, e) {
- if($(e.target).hasClass('jstree-checkbox-disabled')) {
- return false;
- }
- if(this.settings.checkbox.tie_selection && (this.settings.checkbox.whole_node || $(e.target).hasClass('jstree-checkbox'))) {
- e.ctrlKey = true;
- }
- if(this.settings.checkbox.tie_selection || (!this.settings.checkbox.whole_node && !$(e.target).hasClass('jstree-checkbox'))) {
- return parent.activate_node.call(this, obj, e);
- }
- if(this.is_disabled(obj)) {
- return false;
- }
- if(this.is_checked(obj)) {
- this.uncheck_node(obj, e);
- }
- else {
- this.check_node(obj, e);
- }
- this.trigger('activate_node', { 'node' : this.get_node(obj) });
- };
- this.delete_node = function (obj) {
- if(this.settings.checkbox.tie_selection || $.vakata.is_array(obj)) {
- return parent.delete_node.call(this, obj);
- }
- var tmp, k, l, c = false;
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- tmp = obj.children_d.concat([]);
- tmp.push(obj.id);
- for(k = 0, l = tmp.length; k < l; k++) {
- if(this._model.data[tmp[k]].state.checked) {
- c = true;
- break;
- }
- }
- if (c) {
- this._data.checkbox.selected = $.vakata.array_filter(this._data.checkbox.selected, function (v) {
- return $.inArray(v, tmp) === -1;
- });
- }
- return parent.delete_node.call(this, obj);
- };
-
- this._cascade_new_checked_state = function (id, checkedState) {
- var self = this;
- var t = this.settings.checkbox.tie_selection;
- var node = this._model.data[id];
- var selectedNodeIds = [];
- var selectedChildrenIds = [], i, j, selectedChildIds;
- if (
- (this.settings.checkbox.cascade_to_disabled || !node.state.disabled) &&
- (this.settings.checkbox.cascade_to_hidden || !node.state.hidden)
- ) {
-
- if (node.children) {
- for (i = 0, j = node.children.length; i < j; i++) {
- var childId = node.children[i];
- selectedChildIds = self._cascade_new_checked_state(childId, checkedState);
- selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
- if (selectedChildIds.indexOf(childId) > -1) {
- selectedChildrenIds.push(childId);
- }
- }
- }
- var dom = self.get_node(node, true);
-
- var undetermined = selectedChildrenIds.length > 0 && selectedChildrenIds.length < node.children.length;
- if(node.original && node.original.state && node.original.state.undetermined) {
- node.original.state.undetermined = undetermined;
- }
-
- if (undetermined) {
- node.state[ t ? 'selected' : 'checked' ] = false;
- dom.children('.jstree-anchor').attr('aria-selected', false).removeClass(t ? 'jstree-clicked' : 'jstree-checked');
- }
-
-
- else if (checkedState && selectedChildrenIds.length === node.children.length) {
- node.state[ t ? 'selected' : 'checked' ] = checkedState;
- selectedNodeIds.push(node.id);
- dom.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
- }
- else {
- node.state[ t ? 'selected' : 'checked' ] = false;
- dom.children('.jstree-anchor').attr('aria-selected', false).removeClass(t ? 'jstree-clicked' : 'jstree-checked');
- }
- }
- else {
- selectedChildIds = this.get_checked_descendants(id);
- if (node.state[ t ? 'selected' : 'checked' ]) {
- selectedChildIds.push(node.id);
- }
- selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
- }
- return selectedNodeIds;
- };
-
- this.get_checked_descendants = function (id) {
- var self = this;
- var t = self.settings.checkbox.tie_selection;
- var node = self._model.data[id];
- return $.vakata.array_filter(node.children_d, function(_id) {
- return self._model.data[_id].state[ t ? 'selected' : 'checked' ];
- });
- };
-
- this.check_node = function (obj, e) {
- if(this.settings.checkbox.tie_selection) { return this.select_node(obj, false, true, e); }
- var dom, t1, t2, th;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.check_node(obj[t1], e);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- dom = this.get_node(obj, true);
- if(!obj.state.checked) {
- obj.state.checked = true;
- this._data.checkbox.selected.push(obj.id);
- if(dom && dom.length) {
- dom.children('.jstree-anchor').addClass('jstree-checked');
- }
-
- this.trigger('check_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
- }
- };
-
- this.uncheck_node = function (obj, e) {
- if(this.settings.checkbox.tie_selection) { return this.deselect_node(obj, false, e); }
- var t1, t2, dom;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.uncheck_node(obj[t1], e);
- }
- return true;
- }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) {
- return false;
- }
- dom = this.get_node(obj, true);
- if(obj.state.checked) {
- obj.state.checked = false;
- this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, obj.id);
- if(dom.length) {
- dom.children('.jstree-anchor').removeClass('jstree-checked');
- }
-
- this.trigger('uncheck_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
- }
- };
-
-
- this.check_all = function () {
- if(this.settings.checkbox.tie_selection) { return this.select_all(); }
- var tmp = this._data.checkbox.selected.concat([]), i, j;
- this._data.checkbox.selected = this._model.data[$.jstree.root].children_d.concat();
- for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
- if(this._model.data[this._data.checkbox.selected[i]]) {
- this._model.data[this._data.checkbox.selected[i]].state.checked = true;
- }
- }
- this.redraw(true);
-
- this.trigger('check_all', { 'selected' : this._data.checkbox.selected });
- };
-
- this.uncheck_all = function () {
- if(this.settings.checkbox.tie_selection) { return this.deselect_all(); }
- var tmp = this._data.checkbox.selected.concat([]), i, j;
- for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
- if(this._model.data[this._data.checkbox.selected[i]]) {
- this._model.data[this._data.checkbox.selected[i]].state.checked = false;
- }
- }
- this._data.checkbox.selected = [];
- this.element.find('.jstree-checked').removeClass('jstree-checked');
-
- this.trigger('uncheck_all', { 'selected' : this._data.checkbox.selected, 'node' : tmp });
- };
-
- this.is_checked = function (obj) {
- if(this.settings.checkbox.tie_selection) { return this.is_selected(obj); }
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- return obj.state.checked;
- };
-
- this.get_checked = function (full) {
- if(this.settings.checkbox.tie_selection) { return this.get_selected(full); }
- return full ? $.map(this._data.checkbox.selected, function (i) { return this.get_node(i); }.bind(this)) : this._data.checkbox.selected.slice();
- };
-
- this.get_top_checked = function (full) {
- if(this.settings.checkbox.tie_selection) { return this.get_top_selected(full); }
- var tmp = this.get_checked(true),
- obj = {}, i, j, k, l;
- for(i = 0, j = tmp.length; i < j; i++) {
- obj[tmp[i].id] = tmp[i];
- }
- for(i = 0, j = tmp.length; i < j; i++) {
- for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
- if(obj[tmp[i].children_d[k]]) {
- delete obj[tmp[i].children_d[k]];
- }
- }
- }
- tmp = [];
- for(i in obj) {
- if(obj.hasOwnProperty(i)) {
- tmp.push(i);
- }
- }
- return full ? $.map(tmp, function (i) { return this.get_node(i); }.bind(this)) : tmp;
- };
-
- this.get_bottom_checked = function (full) {
- if(this.settings.checkbox.tie_selection) { return this.get_bottom_selected(full); }
- var tmp = this.get_checked(true),
- obj = [], i, j;
- for(i = 0, j = tmp.length; i < j; i++) {
- if(!tmp[i].children.length) {
- obj.push(tmp[i].id);
- }
- }
- return full ? $.map(obj, function (i) { return this.get_node(i); }.bind(this)) : obj;
- };
- this.load_node = function (obj, callback) {
- var k, l, i, j, c, tmp;
- if(!$.vakata.is_array(obj) && !this.settings.checkbox.tie_selection) {
- tmp = this.get_node(obj);
- if(tmp && tmp.state.loaded) {
- for(k = 0, l = tmp.children_d.length; k < l; k++) {
- if(this._model.data[tmp.children_d[k]].state.checked) {
- c = true;
- this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, tmp.children_d[k]);
- }
- }
- }
- }
- return parent.load_node.apply(this, arguments);
- };
- this.get_state = function () {
- var state = parent.get_state.apply(this, arguments);
- if(this.settings.checkbox.tie_selection) { return state; }
- state.checkbox = this._data.checkbox.selected.slice();
- return state;
- };
- this.set_state = function (state, callback) {
- var res = parent.set_state.apply(this, arguments);
- if(res && state.checkbox) {
- if(!this.settings.checkbox.tie_selection) {
- this.uncheck_all();
- var _this = this;
- $.each(state.checkbox, function (i, v) {
- _this.check_node(v);
- });
- }
- delete state.checkbox;
- this.set_state(state, callback);
- return false;
- }
- return res;
- };
- this.refresh = function (skip_loading, forget_state) {
- if(this.settings.checkbox.tie_selection) {
- this._data.checkbox.selected = [];
- }
- return parent.refresh.apply(this, arguments);
- };
- };
-
-
-
- $.jstree.defaults.conditionalselect = function () { return true; };
- $.jstree.plugins.conditionalselect = function (options, parent) {
-
- this.activate_node = function (obj, e) {
- if(this.settings.conditionalselect.call(this, this.get_node(obj), e)) {
- return parent.activate_node.call(this, obj, e);
- }
- };
- };
-
- $.jstree.defaults.contextmenu = {
-
- select_node : true,
-
- show_at_node : true,
-
- items : function (o, cb) {
- return {
- "create" : {
- "separator_before" : false,
- "separator_after" : true,
- "_disabled" : false,
- "label" : "Create",
- "action" : function (data) {
- var inst = $.jstree.reference(data.reference),
- obj = inst.get_node(data.reference);
- inst.create_node(obj, {}, "last", function (new_node) {
- try {
- inst.edit(new_node);
- } catch (ex) {
- setTimeout(function () { inst.edit(new_node); },0);
- }
- });
- }
- },
- "rename" : {
- "separator_before" : false,
- "separator_after" : false,
- "_disabled" : false,
- "label" : "Rename",
-
- "action" : function (data) {
- var inst = $.jstree.reference(data.reference),
- obj = inst.get_node(data.reference);
- inst.edit(obj);
- }
- },
- "remove" : {
- "separator_before" : false,
- "icon" : false,
- "separator_after" : false,
- "_disabled" : false,
- "label" : "Delete",
- "action" : function (data) {
- var inst = $.jstree.reference(data.reference),
- obj = inst.get_node(data.reference);
- if(inst.is_selected(obj)) {
- inst.delete_node(inst.get_selected());
- }
- else {
- inst.delete_node(obj);
- }
- }
- },
- "ccp" : {
- "separator_before" : true,
- "icon" : false,
- "separator_after" : false,
- "label" : "Edit",
- "action" : false,
- "submenu" : {
- "cut" : {
- "separator_before" : false,
- "separator_after" : false,
- "label" : "Cut",
- "action" : function (data) {
- var inst = $.jstree.reference(data.reference),
- obj = inst.get_node(data.reference);
- if(inst.is_selected(obj)) {
- inst.cut(inst.get_top_selected());
- }
- else {
- inst.cut(obj);
- }
- }
- },
- "copy" : {
- "separator_before" : false,
- "icon" : false,
- "separator_after" : false,
- "label" : "Copy",
- "action" : function (data) {
- var inst = $.jstree.reference(data.reference),
- obj = inst.get_node(data.reference);
- if(inst.is_selected(obj)) {
- inst.copy(inst.get_top_selected());
- }
- else {
- inst.copy(obj);
- }
- }
- },
- "paste" : {
- "separator_before" : false,
- "icon" : false,
- "_disabled" : function (data) {
- return !$.jstree.reference(data.reference).can_paste();
- },
- "separator_after" : false,
- "label" : "Paste",
- "action" : function (data) {
- var inst = $.jstree.reference(data.reference),
- obj = inst.get_node(data.reference);
- inst.paste(obj);
- }
- }
- }
- }
- };
- }
- };
- $.jstree.plugins.contextmenu = function (options, parent) {
- this.bind = function () {
- parent.bind.call(this);
- var last_ts = 0, cto = null, ex, ey;
- this.element
- .on("init.jstree loading.jstree ready.jstree", function () {
- this.get_container_ul().addClass('jstree-contextmenu');
- }.bind(this))
- .on("contextmenu.jstree", ".jstree-anchor", function (e, data) {
- if (e.target.tagName.toLowerCase() === 'input') {
- return;
- }
- e.preventDefault();
- last_ts = e.ctrlKey ? +new Date() : 0;
- if(data || cto) {
- last_ts = (+new Date()) + 10000;
- }
- if(cto) {
- clearTimeout(cto);
- }
- if(!this.is_loading(e.currentTarget)) {
- this.show_contextmenu(e.currentTarget, e.pageX, e.pageY, e);
- }
- }.bind(this))
- .on("click.jstree", ".jstree-anchor", function (e) {
- if(this._data.contextmenu.visible && (!last_ts || (+new Date()) - last_ts > 250)) {
- $.vakata.context.hide();
- }
- last_ts = 0;
- }.bind(this))
- .on("touchstart.jstree", ".jstree-anchor", function (e) {
- if(!e.originalEvent || !e.originalEvent.changedTouches || !e.originalEvent.changedTouches[0]) {
- return;
- }
- ex = e.originalEvent.changedTouches[0].clientX;
- ey = e.originalEvent.changedTouches[0].clientY;
- cto = setTimeout(function () {
- $(e.currentTarget).trigger('contextmenu', true);
- }, 750);
- })
- .on('touchmove.vakata.jstree', function (e) {
- 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)) {
- clearTimeout(cto);
- $.vakata.context.hide();
- }
- })
- .on('touchend.vakata.jstree', function (e) {
- if(cto) {
- clearTimeout(cto);
- }
- });
-
- $(document).on("context_hide.vakata.jstree", function (e, data) {
- this._data.contextmenu.visible = false;
- $(data.reference).removeClass('jstree-context');
- }.bind(this));
- };
- this.teardown = function () {
- if(this._data.contextmenu.visible) {
- $.vakata.context.hide();
- }
- $(document).off("context_hide.vakata.jstree");
- parent.teardown.call(this);
- };
-
- this.show_contextmenu = function (obj, x, y, e) {
- obj = this.get_node(obj);
- if(!obj || obj.id === $.jstree.root) { return false; }
- var s = this.settings.contextmenu,
- d = this.get_node(obj, true),
- a = d.children(".jstree-anchor"),
- o = false,
- i = false;
- if(s.show_at_node || x === undefined || y === undefined) {
- o = a.offset();
- x = o.left;
- y = o.top + this._data.core.li_height;
- }
- if(this.settings.contextmenu.select_node && !this.is_selected(obj)) {
- this.activate_node(obj, e);
- }
- i = s.items;
- if($.vakata.is_function(i)) {
- i = i.call(this, obj, function (i) {
- this._show_contextmenu(obj, x, y, i);
- }.bind(this));
- }
- if($.isPlainObject(i)) {
- this._show_contextmenu(obj, x, y, i);
- }
- };
-
- this._show_contextmenu = function (obj, x, y, i) {
- var d = this.get_node(obj, true),
- a = d.children(".jstree-anchor");
- $(document).one("context_show.vakata.jstree", function (e, data) {
- var cls = 'jstree-contextmenu jstree-' + this.get_theme() + '-contextmenu';
- $(data.element).addClass(cls);
- a.addClass('jstree-context');
- }.bind(this));
- this._data.contextmenu.visible = true;
- $.vakata.context.show(a, { 'x' : x, 'y' : y }, i);
-
- this.trigger('show_contextmenu', { "node" : obj, "x" : x, "y" : y });
- };
- };
-
- (function ($) {
- var right_to_left = false,
- vakata_context = {
- element : false,
- reference : false,
- position_x : 0,
- position_y : 0,
- items : [],
- html : "",
- is_visible : false
- };
- $.vakata.context = {
- settings : {
- hide_onmouseleave : 0,
- icons : true
- },
- _trigger : function (event_name) {
- $(document).triggerHandler("context_" + event_name + ".vakata", {
- "reference" : vakata_context.reference,
- "element" : vakata_context.element,
- "position" : {
- "x" : vakata_context.position_x,
- "y" : vakata_context.position_y
- }
- });
- },
- _execute : function (i) {
- i = vakata_context.items[i];
- return i && (!i._disabled || ($.vakata.is_function(i._disabled) && !i._disabled({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }))) && i.action ? i.action.call(null, {
- "item" : i,
- "reference" : vakata_context.reference,
- "element" : vakata_context.element,
- "position" : {
- "x" : vakata_context.position_x,
- "y" : vakata_context.position_y
- }
- }) : false;
- },
- _parse : function (o, is_callback) {
- if(!o) { return false; }
- if(!is_callback) {
- vakata_context.html = "";
- vakata_context.items = [];
- }
- var str = "",
- sep = false,
- tmp;
- if(is_callback) { str += "<"+"ul>"; }
- $.each(o, function (i, val) {
- if(!val) { return true; }
- vakata_context.items.push(val);
- if(!sep && val.separator_before) {
- str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'class="vakata-context-no-icons"') + "> <"+"/a><"+"/li>";
- }
- sep = false;
- str += "<"+"li class='" + (val._class || "") + (val._disabled === true || ($.vakata.is_function(val._disabled) && val._disabled({ "item" : val, "reference" : vakata_context.reference, "element" : vakata_context.element })) ? " vakata-contextmenu-disabled " : "") + "' "+(val.shortcut?" data-shortcut='"+val.shortcut+"' ":'')+">";
- str += "<"+"a href='#' rel='" + (vakata_context.items.length - 1) + "' " + (val.title ? "title='" + val.title + "'" : "") + ">";
- if($.vakata.context.settings.icons) {
- str += "<"+"i ";
- if(val.icon) {
- if(val.icon.indexOf("/") !== -1 || val.icon.indexOf(".") !== -1) { str += " style='background:url(\"" + val.icon + "\") center center no-repeat' "; }
- else { str += " class='" + val.icon + "' "; }
- }
- str += "><"+"/i><"+"span class='vakata-contextmenu-sep'> <"+"/span>";
- }
- str += ($.vakata.is_function(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>";
- if(val.submenu) {
- tmp = $.vakata.context._parse(val.submenu, true);
- if(tmp) { str += tmp; }
- }
- str += "<"+"/li>";
- if(val.separator_after) {
- str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'class="vakata-context-no-icons"') + "> <"+"/a><"+"/li>";
- sep = true;
- }
- });
- str = str.replace(/<li class\='vakata-context-separator'\><\/li\>$/,"");
- if(is_callback) { str += "</ul>"; }
-
- if(!is_callback) { vakata_context.html = str; $.vakata.context._trigger("parse"); }
- return str.length > 10 ? str : false;
- },
- _show_submenu : function (o) {
- o = $(o);
- if(!o.length || !o.children("ul").length) { return; }
- var e = o.children("ul"),
- xl = o.offset().left,
- x = xl + o.outerWidth(),
- y = o.offset().top,
- w = e.width(),
- h = e.height(),
- dw = $(window).width() + $(window).scrollLeft(),
- dh = $(window).height() + $(window).scrollTop();
-
- if(right_to_left) {
- o[x - (w + 10 + o.outerWidth()) < 0 ? "addClass" : "removeClass"]("vakata-context-left");
- }
- else {
- o[x + w > dw && xl > dw - x ? "addClass" : "removeClass"]("vakata-context-right");
- }
- if(y + h + 10 > dh) {
- e.css("bottom","-1px");
- }
-
- if (o.hasClass('vakata-context-right')) {
- if (xl < w) {
- e.css("margin-right", xl - w);
- }
- } else {
- if (dw - x < w) {
- e.css("margin-left", dw - x - w);
- }
- }
- e.show();
- },
- show : function (reference, position, data) {
- var o, e, x, y, w, h, dw, dh, cond = true;
- if(vakata_context.element && vakata_context.element.length) {
- vakata_context.element.width('');
- }
- switch(cond) {
- case (!position && !reference):
- return false;
- case (!!position && !!reference):
- vakata_context.reference = reference;
- vakata_context.position_x = position.x;
- vakata_context.position_y = position.y;
- break;
- case (!position && !!reference):
- vakata_context.reference = reference;
- o = reference.offset();
- vakata_context.position_x = o.left + reference.outerHeight();
- vakata_context.position_y = o.top;
- break;
- case (!!position && !reference):
- vakata_context.position_x = position.x;
- vakata_context.position_y = position.y;
- break;
- }
- if(!!reference && !data && $(reference).data('vakata_contextmenu')) {
- data = $(reference).data('vakata_contextmenu');
- }
- if($.vakata.context._parse(data)) {
- vakata_context.element.html(vakata_context.html);
- }
- if(vakata_context.items.length) {
- vakata_context.element.appendTo(document.body);
- e = vakata_context.element;
- x = vakata_context.position_x;
- y = vakata_context.position_y;
- w = e.width();
- h = e.height();
- dw = $(window).width() + $(window).scrollLeft();
- dh = $(window).height() + $(window).scrollTop();
- if(right_to_left) {
- x -= (e.outerWidth() - $(reference).outerWidth());
- if(x < $(window).scrollLeft() + 20) {
- x = $(window).scrollLeft() + 20;
- }
- }
- if(x + w + 20 > dw) {
- x = dw - (w + 20);
- }
- if(y + h + 20 > dh) {
- y = dh - (h + 20);
- }
- vakata_context.element
- .css({ "left" : x, "top" : y })
- .show()
- .find('a').first().trigger('focus').parent().addClass("vakata-context-hover");
- vakata_context.is_visible = true;
-
- $.vakata.context._trigger("show");
- }
- },
- hide : function () {
- if(vakata_context.is_visible) {
- vakata_context.element.hide().find("ul").hide().end().find(':focus').trigger('blur').end().detach();
- vakata_context.is_visible = false;
-
- $.vakata.context._trigger("hide");
- }
- }
- };
- $(function () {
- right_to_left = $(document.body).css("direction") === "rtl";
- var to = false;
- vakata_context.element = $("<ul class='vakata-context'></ul>");
- vakata_context.element
- .on("mouseenter", "li", function (e) {
- e.stopImmediatePropagation();
- if($.contains(this, e.relatedTarget)) {
-
-
- return;
- }
- if(to) { clearTimeout(to); }
- vakata_context.element.find(".vakata-context-hover").removeClass("vakata-context-hover").end();
- $(this)
- .siblings().find("ul").hide().end().end()
- .parentsUntil(".vakata-context", "li").addBack().addClass("vakata-context-hover");
- $.vakata.context._show_submenu(this);
- })
-
- .on("mouseleave", "li", function (e) {
- if($.contains(this, e.relatedTarget)) { return; }
- $(this).find(".vakata-context-hover").addBack().removeClass("vakata-context-hover");
- })
- .on("mouseleave", function (e) {
- $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
- if($.vakata.context.settings.hide_onmouseleave) {
- to = setTimeout(
- (function (t) {
- return function () { $.vakata.context.hide(); };
- }(this)), $.vakata.context.settings.hide_onmouseleave);
- }
- })
- .on("click", "a", function (e) {
- e.preventDefault();
-
-
- if(!$(this).trigger('blur').parent().hasClass("vakata-context-disabled") && $.vakata.context._execute($(this).attr("rel")) !== false) {
- $.vakata.context.hide();
- }
- })
- .on('keydown', 'a', function (e) {
- var o = null;
- switch(e.which) {
- case 13:
- case 32:
- e.type = "click";
- e.preventDefault();
- $(e.currentTarget).trigger(e);
- break;
- case 37:
- if(vakata_context.is_visible) {
- 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').trigger('focus');
- e.stopImmediatePropagation();
- e.preventDefault();
- }
- break;
- case 38:
- if(vakata_context.is_visible) {
- o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").prevAll("li:not(.vakata-context-separator)").first();
- if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").last(); }
- o.addClass("vakata-context-hover").children('a').trigger('focus');
- e.stopImmediatePropagation();
- e.preventDefault();
- }
- break;
- case 39:
- if(vakata_context.is_visible) {
- 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').trigger('focus');
- e.stopImmediatePropagation();
- e.preventDefault();
- }
- break;
- case 40:
- if(vakata_context.is_visible) {
- o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").nextAll("li:not(.vakata-context-separator)").first();
- if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").first(); }
- o.addClass("vakata-context-hover").children('a').trigger('focus');
- e.stopImmediatePropagation();
- e.preventDefault();
- }
- break;
- case 27:
- $.vakata.context.hide();
- e.preventDefault();
- break;
- default:
-
- break;
- }
- })
- .on('keydown', function (e) {
- e.preventDefault();
- var a = vakata_context.element.find('.vakata-contextmenu-shortcut-' + e.which).parent();
- if(a.parent().not('.vakata-context-disabled')) {
- a.trigger('click');
- }
- });
- $(document)
- .on("mousedown.vakata.jstree", function (e) {
- if(vakata_context.is_visible && vakata_context.element[0] !== e.target && !$.contains(vakata_context.element[0], e.target)) {
- $.vakata.context.hide();
- }
- })
- .on("context_show.vakata.jstree", function (e, data) {
- vakata_context.element.find("li:has(ul)").children("a").addClass("vakata-context-parent");
- if(right_to_left) {
- vakata_context.element.addClass("vakata-context-rtl").css("direction", "rtl");
- }
-
- vakata_context.element.find("ul").hide().end();
- });
- });
- }($));
-
-
- $.jstree.defaults.dnd = {
-
- copy : true,
-
- open_timeout : 500,
-
- is_draggable : true,
-
- check_while_dragging : true,
-
- always_copy : false,
-
- inside_pos : 0,
-
- drag_selection : true,
-
- touch : true,
-
- large_drop_target : false,
-
- large_drag_target : false,
-
- use_html5: false,
-
- blank_space_drop: false
- };
- var drg, elm;
-
- $.jstree.plugins.dnd = function (options, parent) {
- this.init = function (el, options) {
- parent.init.call(this, el, options);
- this.settings.dnd.use_html5 = this.settings.dnd.use_html5 && ('draggable' in document.createElement('span'));
- };
- this.bind = function () {
- parent.bind.call(this);
- this.element
- .on(this.settings.dnd.use_html5 ? 'dragstart.jstree' : 'mousedown.jstree touchstart.jstree', this.settings.dnd.large_drag_target ? '.jstree-node' : '.jstree-anchor', function (e) {
- if(this.settings.dnd.large_drag_target && $(e.target).closest('.jstree-node')[0] !== e.currentTarget) {
- return true;
- }
- if(e.type === "touchstart" && (!this.settings.dnd.touch || (this.settings.dnd.touch === 'selected' && !$(e.currentTarget).closest('.jstree-node').children('.jstree-anchor').hasClass('jstree-clicked')))) {
- return true;
- }
- var obj = this.get_node(e.target),
- mlt = this.is_selected(obj) && this.settings.dnd.drag_selection ? this.get_top_selected().length : 1,
- txt = (mlt > 1 ? mlt + ' ' + this.get_string('nodes') : this.get_text(e.currentTarget));
- if(this.settings.core.force_text) {
- txt = $.vakata.html.escape(txt);
- }
- if(obj && (obj.id || obj.id === 0) && obj.id !== $.jstree.root && (e.which === 1 || e.type === "touchstart" || e.type === "dragstart") &&
- (this.settings.dnd.is_draggable === true || ($.vakata.is_function(this.settings.dnd.is_draggable) && this.settings.dnd.is_draggable.call(this, (mlt > 1 ? this.get_top_selected(true) : [obj]), e)))
- ) {
- drg = { 'jstree' : true, 'origin' : this, 'obj' : this.get_node(obj,true), 'nodes' : mlt > 1 ? this.get_top_selected() : [obj.id] };
- elm = e.currentTarget;
- if (this.settings.dnd.use_html5) {
- $.vakata.dnd._trigger('start', e, { 'helper': $(), 'element': elm, 'data': drg });
- } else {
- this.element.trigger('mousedown.jstree');
- 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">+</ins></div>');
- }
- }
- }.bind(this));
- if (this.settings.dnd.use_html5) {
- this.element
- .on('dragover.jstree', function (e) {
- e.preventDefault();
- $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
- return false;
- })
-
-
-
-
-
- .on('drop.jstree', function (e) {
- e.preventDefault();
- $.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
- return false;
- }.bind(this));
- }
- };
- this.redraw_node = function(obj, deep, callback, force_render) {
- obj = parent.redraw_node.apply(this, arguments);
- if (obj && this.settings.dnd.use_html5) {
- if (this.settings.dnd.large_drag_target) {
- obj.setAttribute('draggable', true);
- } else {
- var i, j, tmp = null;
- for(i = 0, j = obj.childNodes.length; i < j; i++) {
- if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
- tmp = obj.childNodes[i];
- break;
- }
- }
- if(tmp) {
- tmp.setAttribute('draggable', true);
- }
- }
- }
- return obj;
- };
- };
- $(function() {
-
- var lastmv = false,
- laster = false,
- lastev = false,
- opento = false,
- marker = $('<div id="jstree-marker"> </div>').hide();
- $(document)
- .on('dragover.vakata.jstree', function (e) {
- if (elm) {
- $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
- }
- })
- .on('drop.vakata.jstree', function (e) {
- if (elm) {
- $.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
- elm = null;
- drg = null;
- }
- })
- .on('dnd_start.vakata.jstree', function (e, data) {
- lastmv = false;
- lastev = false;
- if(!data || !data.data || !data.data.jstree) { return; }
- marker.appendTo(document.body);
- })
- .on('dnd_move.vakata.jstree', function (e, data) {
- var isDifferentNode = data.event.target !== lastev.target;
- if(opento) {
- if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
- clearTimeout(opento);
- }
- }
- if(!data || !data.data || !data.data.jstree) { return; }
-
- if(data.event.target.id && data.event.target.id === 'jstree-marker') {
- return;
- }
- lastev = data.event;
- var ins = $.jstree.reference(data.event.target),
- ref = false,
- off = false,
- rel = false,
- tmp, l, t, h, p, i, o, ok, t1, t2, op, ps, pr, ip, tm, is_copy, pn, c;
-
- if(ins && ins._data && ins._data.dnd) {
- marker.attr('class', 'jstree-' + ins.get_theme() + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ));
- is_copy = data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey)));
- data.helper
- .children().attr('class', 'jstree-' + ins.get_theme() + ' jstree-' + ins.get_theme() + '-' + ins.get_theme_variant() + ' ' + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ))
- .find('.jstree-copy').first()[ is_copy ? 'show' : 'hide' ]();
-
-
- if( (data.event.target === ins.element[0] || data.event.target === ins.get_container_ul()[0]) && (ins.get_container_ul().children().length === 0 || ins.settings.dnd.blank_space_drop)) {
- ok = true;
- for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
- 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) });
- if(!ok) { break; }
- }
- if(ok) {
- lastmv = { 'ins' : ins, 'par' : $.jstree.root, 'pos' : 'last' };
- marker.hide();
- data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
- if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
- data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
- }
- return;
- }
- }
- else {
-
- ref = ins.settings.dnd.large_drop_target ? $(data.event.target).closest('.jstree-node').children('.jstree-anchor') : $(data.event.target).closest('.jstree-anchor');
-
- if(ref && ref.length && ref.parent().is('.jstree-closed, .jstree-open, .jstree-leaf')) {
- off = ref.offset();
- rel = (data.event.pageY !== undefined ? data.event.pageY : data.event.originalEvent.pageY) - off.top;
- h = ref.outerHeight();
- if(rel < h / 3) {
- o = ['b', 'i', 'a'];
- }
- else if(rel > h - h / 3) {
- o = ['a', 'i', 'b'];
- }
- else {
- o = rel > h / 2 ? ['i', 'a', 'b'] : ['i', 'b', 'a'];
- }
- $.each(o, function (j, v) {
- switch(v) {
- case 'b':
- l = off.left - 6;
- t = off.top;
- p = ins.get_parent(ref);
- i = ref.parent().index();
- c = 'jstree-below';
- break;
- case 'i':
- ip = ins.settings.dnd.inside_pos;
- tm = ins.get_node(ref.parent());
- l = off.left - 2;
- t = off.top + h / 2 + 1;
- p = tm.id;
- i = ip === 'first' ? 0 : (ip === 'last' ? tm.children.length : Math.min(ip, tm.children.length));
- c = 'jstree-inside';
- break;
- case 'a':
- l = off.left - 6;
- t = off.top + h;
- p = ins.get_parent(ref);
- i = ref.parent().index() + 1;
- c = 'jstree-above';
- break;
- }
- ok = true;
- for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
- 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";
- ps = i;
- if(op === "move_node" && v === 'a' && (data.data.origin && data.data.origin === ins) && p === ins.get_parent(data.data.nodes[t1])) {
- pr = ins.get_node(p);
- if(ps > $.inArray(data.data.nodes[t1], pr.children)) {
- ps -= 1;
- }
- }
- 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) }) );
- if(!ok) {
- if(ins && ins.last_error) { laster = ins.last_error(); }
- break;
- }
- }
- if(v === 'i' && ref.parent().is('.jstree-closed') && ins.settings.dnd.open_timeout) {
- if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
- if (opento) { clearTimeout(opento); }
- opento = setTimeout((function (x, z) { return function () { x.open_node(z); }; }(ins, ref)), ins.settings.dnd.open_timeout);
- }
- }
- if(ok) {
- pn = ins.get_node(p, true);
- if (!pn.hasClass('.jstree-dnd-parent')) {
- $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
- pn.addClass('jstree-dnd-parent');
- }
- lastmv = { 'ins' : ins, 'par' : p, 'pos' : v === 'i' && ip === 'last' && i === 0 && !ins.is_loaded(tm) ? 'last' : i };
- marker.css({ 'left' : l + 'px', 'top' : t + 'px' }).show();
- marker.removeClass('jstree-above jstree-inside jstree-below').addClass(c);
- data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
- if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
- data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
- }
- laster = {};
- o = true;
- return false;
- }
- });
- if(o === true) { return; }
- }
- }
- }
- $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
- lastmv = false;
- data.helper.find('.jstree-icon').removeClass('jstree-ok').addClass('jstree-er');
- if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
-
- }
- marker.hide();
- })
- .on('dnd_scroll.vakata.jstree', function (e, data) {
- if(!data || !data.data || !data.data.jstree) { return; }
- marker.hide();
- lastmv = false;
- lastev = false;
- data.helper.find('.jstree-icon').first().removeClass('jstree-ok').addClass('jstree-er');
- })
- .on('dnd_stop.vakata.jstree', function (e, data) {
- $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
- if(opento) { clearTimeout(opento); }
- if(!data || !data.data || !data.data.jstree) { return; }
- marker.hide().detach();
- var i, j, nodes = [];
- if(lastmv) {
- for(i = 0, j = data.data.nodes.length; i < j; i++) {
- nodes[i] = data.data.origin ? data.data.origin.get_node(data.data.nodes[i]) : data.data.nodes[i];
- }
- 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);
- }
- else {
- i = $(data.event.target).closest('.jstree');
- if(i.length && laster && laster.error && laster.error === 'check') {
- i = i.jstree(true);
- if(i) {
- i.settings.core.error.call(this, laster);
- }
- }
- }
- lastev = false;
- lastmv = false;
- })
- .on('keyup.jstree keydown.jstree', function (e, data) {
- data = $.vakata.dnd._get();
- if(data && data.data && data.data.jstree) {
- if (e.type === "keyup" && e.which === 27) {
- if (opento) { clearTimeout(opento); }
- lastmv = false;
- laster = false;
- lastev = false;
- opento = false;
- marker.hide().detach();
- $.vakata.dnd._clean();
- } else {
- 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' ]();
- if(lastev) {
- lastev.metaKey = e.metaKey;
- lastev.ctrlKey = e.ctrlKey;
- $.vakata.dnd._trigger('move', lastev);
- }
- }
- }
- });
- });
-
- (function ($) {
- $.vakata.html = {
- div : $('<div></div>'),
- escape : function (str) {
- return $.vakata.html.div.text(str).html();
- },
- strip : function (str) {
- return $.vakata.html.div.empty().append($.parseHTML(str)).text();
- }
- };
-
- var vakata_dnd = {
- element : false,
- target : false,
- is_down : false,
- is_drag : false,
- helper : false,
- helper_w: 0,
- data : false,
- init_x : 0,
- init_y : 0,
- scroll_l: 0,
- scroll_t: 0,
- scroll_e: false,
- scroll_i: false,
- is_touch: false
- };
- $.vakata.dnd = {
- settings : {
- scroll_speed : 10,
- scroll_proximity : 20,
- helper_left : 5,
- helper_top : 10,
- threshold : 5,
- threshold_touch : 10
- },
- _trigger : function (event_name, e, data) {
- if (data === undefined) {
- data = $.vakata.dnd._get();
- }
- data.event = e;
- $(document).triggerHandler("dnd_" + event_name + ".vakata", data);
- },
- _get : function () {
- return {
- "data" : vakata_dnd.data,
- "element" : vakata_dnd.element,
- "helper" : vakata_dnd.helper
- };
- },
- _clean : function () {
- if(vakata_dnd.helper) { vakata_dnd.helper.remove(); }
- if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
- vakata_dnd = {
- element : false,
- target : false,
- is_down : false,
- is_drag : false,
- helper : false,
- helper_w: 0,
- data : false,
- init_x : 0,
- init_y : 0,
- scroll_l: 0,
- scroll_t: 0,
- scroll_e: false,
- scroll_i: false,
- is_touch: false
- };
- elm = null;
- $(document).off("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
- $(document).off("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
- },
- _scroll : function (init_only) {
- if(!vakata_dnd.scroll_e || (!vakata_dnd.scroll_l && !vakata_dnd.scroll_t)) {
- if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
- return false;
- }
- if(!vakata_dnd.scroll_i) {
- vakata_dnd.scroll_i = setInterval($.vakata.dnd._scroll, 100);
- return false;
- }
- if(init_only === true) { return false; }
- var i = vakata_dnd.scroll_e.scrollTop(),
- j = vakata_dnd.scroll_e.scrollLeft();
- vakata_dnd.scroll_e.scrollTop(i + vakata_dnd.scroll_t * $.vakata.dnd.settings.scroll_speed);
- vakata_dnd.scroll_e.scrollLeft(j + vakata_dnd.scroll_l * $.vakata.dnd.settings.scroll_speed);
- if(i !== vakata_dnd.scroll_e.scrollTop() || j !== vakata_dnd.scroll_e.scrollLeft()) {
-
- $.vakata.dnd._trigger("scroll", vakata_dnd.scroll_e);
- }
- },
- start : function (e, data, html) {
- if(e.type === "touchstart" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
- e.pageX = e.originalEvent.changedTouches[0].pageX;
- e.pageY = e.originalEvent.changedTouches[0].pageY;
- e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
- }
- if(vakata_dnd.is_drag) { $.vakata.dnd.stop({}); }
- try {
- e.currentTarget.unselectable = "on";
- e.currentTarget.onselectstart = function() { return false; };
- if(e.currentTarget.style) {
- e.currentTarget.style.touchAction = "none";
- e.currentTarget.style.msTouchAction = "none";
- e.currentTarget.style.MozUserSelect = "none";
- }
- } catch(ignore) { }
- vakata_dnd.init_x = e.pageX;
- vakata_dnd.init_y = e.pageY;
- vakata_dnd.data = data;
- vakata_dnd.is_down = true;
- vakata_dnd.element = e.currentTarget;
- vakata_dnd.target = e.target;
- vakata_dnd.is_touch = e.type === "touchstart";
- if(html !== false) {
- vakata_dnd.helper = $("<div id='vakata-dnd'></div>").html(html).css({
- "display" : "block",
- "margin" : "0",
- "padding" : "0",
- "position" : "absolute",
- "top" : "-2000px",
- "lineHeight" : "16px",
- "zIndex" : "10000"
- });
- }
- $(document).on("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
- $(document).on("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
- return false;
- },
- drag : function (e) {
- if(e.type === "touchmove" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
- e.pageX = e.originalEvent.changedTouches[0].pageX;
- e.pageY = e.originalEvent.changedTouches[0].pageY;
- e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
- }
- if(!vakata_dnd.is_down) { return; }
- if(!vakata_dnd.is_drag) {
- if(
- Math.abs(e.pageX - vakata_dnd.init_x) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold) ||
- Math.abs(e.pageY - vakata_dnd.init_y) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold)
- ) {
- if(vakata_dnd.helper) {
- vakata_dnd.helper.appendTo(document.body);
- vakata_dnd.helper_w = vakata_dnd.helper.outerWidth();
- }
- vakata_dnd.is_drag = true;
- $(vakata_dnd.target).one('click.vakata', false);
-
- $.vakata.dnd._trigger("start", e);
- }
- else { return; }
- }
- var d = false, w = false,
- dh = false, wh = false,
- dw = false, ww = false,
- dt = false, dl = false,
- ht = false, hl = false;
- vakata_dnd.scroll_t = 0;
- vakata_dnd.scroll_l = 0;
- vakata_dnd.scroll_e = false;
- $($(e.target).parentsUntil("body").addBack().get().reverse())
- .filter(function () {
- return this.ownerDocument && (/^auto|scroll$/).test($(this).css("overflow")) &&
- (this.scrollHeight > this.offsetHeight || this.scrollWidth > this.offsetWidth);
- })
- .each(function () {
- var t = $(this), o = t.offset();
- if(this.scrollHeight > this.offsetHeight) {
- if(o.top + t.height() - e.pageY < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
- if(e.pageY - o.top < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
- }
- if(this.scrollWidth > this.offsetWidth) {
- if(o.left + t.width() - e.pageX < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
- if(e.pageX - o.left < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
- }
- if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
- vakata_dnd.scroll_e = $(this);
- return false;
- }
- });
- if(!vakata_dnd.scroll_e) {
- d = $(document); w = $(window);
- dh = d.height(); wh = w.height();
- dw = d.width(); ww = w.width();
- dt = d.scrollTop(); dl = d.scrollLeft();
- if(dh > wh && e.pageY - dt < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
- if(dh > wh && wh - (e.pageY - dt) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
- if(dw > ww && e.pageX - dl < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
- if(dw > ww && ww - (e.pageX - dl) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
- if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
- vakata_dnd.scroll_e = d;
- }
- }
- if(vakata_dnd.scroll_e) { $.vakata.dnd._scroll(true); }
- if(vakata_dnd.helper) {
- ht = parseInt(e.pageY + $.vakata.dnd.settings.helper_top, 10);
- hl = parseInt(e.pageX + $.vakata.dnd.settings.helper_left, 10);
- if(dh && ht + 25 > dh) { ht = dh - 50; }
- if(dw && hl + vakata_dnd.helper_w > dw) { hl = dw - (vakata_dnd.helper_w + 2); }
- vakata_dnd.helper.css({
- left : hl + "px",
- top : ht + "px"
- });
- }
-
- $.vakata.dnd._trigger("move", e);
- return false;
- },
- stop : function (e) {
- if(e.type === "touchend" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
- e.pageX = e.originalEvent.changedTouches[0].pageX;
- e.pageY = e.originalEvent.changedTouches[0].pageY;
- e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
- }
- if(vakata_dnd.is_drag) {
-
- if (e.target !== vakata_dnd.target) {
- $(vakata_dnd.target).off('click.vakata');
- }
- $.vakata.dnd._trigger("stop", e);
- }
- else {
- if(e.type === "touchend" && e.target === vakata_dnd.target) {
- var to = setTimeout(function () { $(e.target).trigger('click'); }, 100);
- $(e.target).one('click', function() { if(to) { clearTimeout(to); } });
- }
- }
- $.vakata.dnd._clean();
- return false;
- }
- };
- }($));
-
-
-
- $.jstree.defaults.massload = null;
- $.jstree.plugins.massload = function (options, parent) {
- this.init = function (el, options) {
- this._data.massload = {};
- parent.init.call(this, el, options);
- };
- this._load_nodes = function (nodes, callback, is_callback, force_reload) {
- var s = this.settings.massload,
- toLoad = [],
- m = this._model.data,
- i, j, dom;
- if (!is_callback) {
- for(i = 0, j = nodes.length; i < j; i++) {
- if(!m[nodes[i]] || ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || force_reload) ) {
- toLoad.push(nodes[i]);
- dom = this.get_node(nodes[i], true);
- if (dom && dom.length) {
- dom.addClass("jstree-loading").attr('aria-busy',true);
- }
- }
- }
- this._data.massload = {};
- if (toLoad.length) {
- if($.vakata.is_function(s)) {
- return s.call(this, toLoad, function (data) {
- var i, j;
- if(data) {
- for(i in data) {
- if(data.hasOwnProperty(i)) {
- this._data.massload[i] = data[i];
- }
- }
- }
- for(i = 0, j = nodes.length; i < j; i++) {
- dom = this.get_node(nodes[i], true);
- if (dom && dom.length) {
- dom.removeClass("jstree-loading").attr('aria-busy',false);
- }
- }
- parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
- }.bind(this));
- }
- if(typeof s === 'object' && s && s.url) {
- s = $.extend(true, {}, s);
- if($.vakata.is_function(s.url)) {
- s.url = s.url.call(this, toLoad);
- }
- if($.vakata.is_function(s.data)) {
- s.data = s.data.call(this, toLoad);
- }
- return $.ajax(s)
- .done(function (data,t,x) {
- var i, j;
- if(data) {
- for(i in data) {
- if(data.hasOwnProperty(i)) {
- this._data.massload[i] = data[i];
- }
- }
- }
- for(i = 0, j = nodes.length; i < j; i++) {
- dom = this.get_node(nodes[i], true);
- if (dom && dom.length) {
- dom.removeClass("jstree-loading").attr('aria-busy',false);
- }
- }
- parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
- }.bind(this))
- .fail(function (f) {
- parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
- }.bind(this));
- }
- }
- }
- return parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
- };
- this._load_node = function (obj, callback) {
- var data = this._data.massload[obj.id],
- rslt = null, dom;
- if(data) {
- rslt = this[typeof data === 'string' ? '_append_html_data' : '_append_json_data'](
- obj,
- typeof data === 'string' ? $($.parseHTML(data)).filter(function () { return this.nodeType !== 3; }) : data,
- function (status) { callback.call(this, status); }
- );
- dom = this.get_node(obj.id, true);
- if (dom && dom.length) {
- dom.removeClass("jstree-loading").attr('aria-busy',false);
- }
- delete this._data.massload[obj.id];
- return rslt;
- }
- return parent._load_node.call(this, obj, callback);
- };
- };
-
- $.jstree.defaults.search = {
-
- ajax : false,
-
- fuzzy : false,
-
- case_sensitive : false,
-
- show_only_matches : false,
-
- show_only_matches_children : false,
-
- close_opened_onclear : true,
-
- search_leaves_only : false,
-
- search_callback : false
- };
- $.jstree.plugins.search = function (options, parent) {
- this.bind = function () {
- parent.bind.call(this);
- this._data.search.str = "";
- this._data.search.dom = $();
- this._data.search.res = [];
- this._data.search.opn = [];
- this._data.search.som = false;
- this._data.search.smc = false;
- this._data.search.hdn = [];
- this.element
- .on("search.jstree", function (e, data) {
- if(this._data.search.som && data.res.length) {
- var m = this._model.data, i, j, p = [], k, l;
- for(i = 0, j = data.res.length; i < j; i++) {
- if(m[data.res[i]] && !m[data.res[i]].state.hidden) {
- p.push(data.res[i]);
- p = p.concat(m[data.res[i]].parents);
- if(this._data.search.smc) {
- for (k = 0, l = m[data.res[i]].children_d.length; k < l; k++) {
- if (m[m[data.res[i]].children_d[k]] && !m[m[data.res[i]].children_d[k]].state.hidden) {
- p.push(m[data.res[i]].children_d[k]);
- }
- }
- }
- }
- }
- p = $.vakata.array_remove_item($.vakata.array_unique(p), $.jstree.root);
- this._data.search.hdn = this.hide_all(true);
- this.show_node(p, true);
- this.redraw(true);
- }
- }.bind(this))
- .on("clear_search.jstree", function (e, data) {
- if(this._data.search.som && data.res.length) {
- this.show_node(this._data.search.hdn, true);
- this.redraw(true);
- }
- }.bind(this));
- };
-
- this.search = function (str, skip_async, show_only_matches, inside, append, show_only_matches_children) {
- if(str === false || $.vakata.trim(str.toString()) === "") {
- return this.clear_search();
- }
- inside = this.get_node(inside);
- inside = inside && (inside.id || inside.id === 0) ? inside.id : null;
- str = str.toString();
- var s = this.settings.search,
- a = s.ajax ? s.ajax : false,
- m = this._model.data,
- f = null,
- r = [],
- p = [], i, j;
- if(this._data.search.res.length && !append) {
- this.clear_search();
- }
- if(show_only_matches === undefined) {
- show_only_matches = s.show_only_matches;
- }
- if(show_only_matches_children === undefined) {
- show_only_matches_children = s.show_only_matches_children;
- }
- if(!skip_async && a !== false) {
- if($.vakata.is_function(a)) {
- return a.call(this, str, function (d) {
- if(d && d.d) { d = d.d; }
- this._load_nodes(!$.vakata.is_array(d) ? [] : $.vakata.array_unique(d), function () {
- this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
- });
- }.bind(this), inside);
- }
- else {
- a = $.extend({}, a);
- if(!a.data) { a.data = {}; }
- a.data.str = str;
- if(inside) {
- a.data.inside = inside;
- }
- if (this._data.search.lastRequest) {
- this._data.search.lastRequest.abort();
- }
- this._data.search.lastRequest = $.ajax(a)
- .fail(function () {
- this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'search', 'id' : 'search_01', 'reason' : 'Could not load search parents', 'data' : JSON.stringify(a) };
- this.settings.core.error.call(this, this._data.core.last_error);
- }.bind(this))
- .done(function (d) {
- if(d && d.d) { d = d.d; }
- this._load_nodes(!$.vakata.is_array(d) ? [] : $.vakata.array_unique(d), function () {
- this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
- });
- }.bind(this));
- return this._data.search.lastRequest;
- }
- }
- if(!append) {
- this._data.search.str = str;
- this._data.search.dom = $();
- this._data.search.res = [];
- this._data.search.opn = [];
- this._data.search.som = show_only_matches;
- this._data.search.smc = show_only_matches_children;
- }
- f = new $.vakata.search(str, true, { caseSensitive : s.case_sensitive, fuzzy : s.fuzzy });
- $.each(m[inside ? inside : $.jstree.root].children_d, function (ii, i) {
- var v = m[i];
- 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) ) ) {
- r.push(i);
- p = p.concat(v.parents);
- }
- });
- if(r.length) {
- p = $.vakata.array_unique(p);
- for(i = 0, j = p.length; i < j; i++) {
- if(p[i] !== $.jstree.root && m[p[i]] && this.open_node(p[i], null, 0) === true) {
- this._data.search.opn.push(p[i]);
- }
- }
- if(!append) {
- 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(', #')));
- this._data.search.res = r;
- }
- else {
- 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(', #'))));
- this._data.search.res = $.vakata.array_unique(this._data.search.res.concat(r));
- }
- this._data.search.dom.children(".jstree-anchor").addClass('jstree-search');
- }
-
- this.trigger('search', { nodes : this._data.search.dom, str : str, res : this._data.search.res, show_only_matches : show_only_matches });
- };
-
- this.clear_search = function () {
- if(this.settings.search.close_opened_onclear) {
- this.close_node(this._data.search.opn, 0);
- }
-
- this.trigger('clear_search', { 'nodes' : this._data.search.dom, str : this._data.search.str, res : this._data.search.res });
- if(this._data.search.res.length) {
- this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(this._data.search.res, function (v) {
- return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&');
- }).join(', #')));
- this._data.search.dom.children(".jstree-anchor").removeClass("jstree-search");
- }
- this._data.search.str = "";
- this._data.search.res = [];
- this._data.search.opn = [];
- this._data.search.dom = $();
- };
- this.redraw_node = function(obj, deep, callback, force_render) {
- obj = parent.redraw_node.apply(this, arguments);
- if(obj) {
- if($.inArray(obj.id, this._data.search.res) !== -1) {
- var i, j, tmp = null;
- for(i = 0, j = obj.childNodes.length; i < j; i++) {
- if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
- tmp = obj.childNodes[i];
- break;
- }
- }
- if(tmp) {
- tmp.className += ' jstree-search';
- }
- }
- }
- return obj;
- };
- };
-
- (function ($) {
-
- $.vakata.search = function(pattern, txt, options) {
- options = options || {};
- options = $.extend({}, $.vakata.search.defaults, options);
- if(options.fuzzy !== false) {
- options.fuzzy = true;
- }
- pattern = options.caseSensitive ? pattern : pattern.toLowerCase();
- var MATCH_LOCATION = options.location,
- MATCH_DISTANCE = options.distance,
- MATCH_THRESHOLD = options.threshold,
- patternLen = pattern.length,
- matchmask, pattern_alphabet, match_bitapScore, search;
- if(patternLen > 32) {
- options.fuzzy = false;
- }
- if(options.fuzzy) {
- matchmask = 1 << (patternLen - 1);
- pattern_alphabet = (function () {
- var mask = {},
- i = 0;
- for (i = 0; i < patternLen; i++) {
- mask[pattern.charAt(i)] = 0;
- }
- for (i = 0; i < patternLen; i++) {
- mask[pattern.charAt(i)] |= 1 << (patternLen - i - 1);
- }
- return mask;
- }());
- match_bitapScore = function (e, x) {
- var accuracy = e / patternLen,
- proximity = Math.abs(MATCH_LOCATION - x);
- if(!MATCH_DISTANCE) {
- return proximity ? 1.0 : accuracy;
- }
- return accuracy + (proximity / MATCH_DISTANCE);
- };
- }
- search = function (text) {
- text = options.caseSensitive ? text.toString() : text.toString().toLowerCase();
- if(pattern === text || text.indexOf(pattern) !== -1) {
- return {
- isMatch: true,
- score: 0
- };
- }
- if(!options.fuzzy) {
- return {
- isMatch: false,
- score: 1
- };
- }
- var i, j,
- textLen = text.length,
- scoreThreshold = MATCH_THRESHOLD,
- bestLoc = text.indexOf(pattern, MATCH_LOCATION),
- binMin, binMid,
- binMax = patternLen + textLen,
- lastRd, start, finish, rd, charMatch,
- score = 1,
- locations = [];
- if (bestLoc !== -1) {
- scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
- bestLoc = text.lastIndexOf(pattern, MATCH_LOCATION + patternLen);
- if (bestLoc !== -1) {
- scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
- }
- }
- bestLoc = -1;
- for (i = 0; i < patternLen; i++) {
- binMin = 0;
- binMid = binMax;
- while (binMin < binMid) {
- if (match_bitapScore(i, MATCH_LOCATION + binMid) <= scoreThreshold) {
- binMin = binMid;
- } else {
- binMax = binMid;
- }
- binMid = Math.floor((binMax - binMin) / 2 + binMin);
- }
- binMax = binMid;
- start = Math.max(1, MATCH_LOCATION - binMid + 1);
- finish = Math.min(MATCH_LOCATION + binMid, textLen) + patternLen;
- rd = new Array(finish + 2);
- rd[finish + 1] = (1 << i) - 1;
- for (j = finish; j >= start; j--) {
- charMatch = pattern_alphabet[text.charAt(j - 1)];
- if (i === 0) {
- rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
- } else {
- rd[j] = ((rd[j + 1] << 1) | 1) & charMatch | (((lastRd[j + 1] | lastRd[j]) << 1) | 1) | lastRd[j + 1];
- }
- if (rd[j] & matchmask) {
- score = match_bitapScore(i, j - 1);
- if (score <= scoreThreshold) {
- scoreThreshold = score;
- bestLoc = j - 1;
- locations.push(bestLoc);
- if (bestLoc > MATCH_LOCATION) {
- start = Math.max(1, 2 * MATCH_LOCATION - bestLoc);
- } else {
- break;
- }
- }
- }
- }
- if (match_bitapScore(i + 1, MATCH_LOCATION) > scoreThreshold) {
- break;
- }
- lastRd = rd;
- }
- return {
- isMatch: bestLoc >= 0,
- score: score
- };
- };
- return txt === true ? { 'search' : search } : search(txt);
- };
- $.vakata.search.defaults = {
- location : 0,
- distance : 100,
- threshold : 0.6,
- fuzzy : false,
- caseSensitive : false
- };
- }($));
-
-
-
- $.jstree.defaults.sort = function (a, b) {
-
- return this.get_text(a) > this.get_text(b) ? 1 : -1;
- };
- $.jstree.plugins.sort = function (options, parent) {
- this.bind = function () {
- parent.bind.call(this);
- this.element
- .on("model.jstree", function (e, data) {
- this.sort(data.parent, true);
- }.bind(this))
- .on("rename_node.jstree create_node.jstree", function (e, data) {
- this.sort(data.parent || data.node.parent, false);
- this.redraw_node(data.parent || data.node.parent, true);
- }.bind(this))
- .on("move_node.jstree copy_node.jstree", function (e, data) {
- this.sort(data.parent, false);
- this.redraw_node(data.parent, true);
- }.bind(this));
- };
-
- this.sort = function (obj, deep) {
- var i, j;
- obj = this.get_node(obj);
- if(obj && obj.children && obj.children.length) {
- obj.children.sort(this.settings.sort.bind(this));
- if(deep) {
- for(i = 0, j = obj.children_d.length; i < j; i++) {
- this.sort(obj.children_d[i], false);
- }
- }
- }
- };
- };
-
-
- var to = false;
-
- $.jstree.defaults.state = {
-
- key : 'jstree',
-
- events : 'changed.jstree open_node.jstree close_node.jstree check_node.jstree uncheck_node.jstree',
-
- ttl : false,
-
- filter : false,
-
- preserve_loaded : false
- };
- $.jstree.plugins.state = function (options, parent) {
- this.bind = function () {
- parent.bind.call(this);
- var bind = function () {
- this.element.on(this.settings.state.events, function () {
- if(to) { clearTimeout(to); }
- to = setTimeout(function () { this.save_state(); }.bind(this), 100);
- }.bind(this));
-
- this.trigger('state_ready');
- }.bind(this);
- this.element
- .on("ready.jstree", function (e, data) {
- this.element.one("restore_state.jstree", bind);
- if(!this.restore_state()) { bind(); }
- }.bind(this));
- };
-
- this.save_state = function () {
- var tm = this.get_state();
- if (!this.settings.state.preserve_loaded) {
- delete tm.core.loaded;
- }
- var st = { 'state' : tm, 'ttl' : this.settings.state.ttl, 'sec' : +(new Date()) };
- $.vakata.storage.set(this.settings.state.key, JSON.stringify(st));
- };
-
- this.restore_state = function () {
- var k = $.vakata.storage.get(this.settings.state.key);
- if(!!k) { try { k = JSON.parse(k); } catch(ex) { return false; } }
- if(!!k && k.ttl && k.sec && +(new Date()) - k.sec > k.ttl) { return false; }
- if(!!k && k.state) { k = k.state; }
- if(!!k && $.vakata.is_function(this.settings.state.filter)) { k = this.settings.state.filter.call(this, k); }
- if(!!k) {
- if (!this.settings.state.preserve_loaded) {
- delete k.core.loaded;
- }
- this.element.one("set_state.jstree", function (e, data) { data.instance.trigger('restore_state', { 'state' : $.extend(true, {}, k) }); });
- this.set_state(k);
- return true;
- }
- return false;
- };
-
- this.clear_state = function () {
- return $.vakata.storage.del(this.settings.state.key);
- };
- };
- (function ($, undefined) {
- $.vakata.storage = {
-
- set : function (key, val) { return window.localStorage.setItem(key, val); },
- get : function (key) { return window.localStorage.getItem(key); },
- del : function (key) { return window.localStorage.removeItem(key); }
- };
- }($));
-
-
-
- $.jstree.defaults.types = {
- 'default' : {}
- };
- $.jstree.defaults.types[$.jstree.root] = {};
- $.jstree.plugins.types = function (options, parent) {
- this.init = function (el, options) {
- var i, j;
- if(options && options.types && options.types['default']) {
- for(i in options.types) {
- if(i !== "default" && i !== $.jstree.root && options.types.hasOwnProperty(i)) {
- for(j in options.types['default']) {
- if(options.types['default'].hasOwnProperty(j) && options.types[i][j] === undefined) {
- options.types[i][j] = options.types['default'][j];
- }
- }
- }
- }
- }
- parent.init.call(this, el, options);
- this._model.data[$.jstree.root].type = $.jstree.root;
- };
- this.refresh = function (skip_loading, forget_state) {
- parent.refresh.call(this, skip_loading, forget_state);
- this._model.data[$.jstree.root].type = $.jstree.root;
- };
- this.bind = function () {
- this.element
- .on('model.jstree', function (e, data) {
- var m = this._model.data,
- dpc = data.nodes,
- t = this.settings.types,
- i, j, c = 'default', k;
- for(i = 0, j = dpc.length; i < j; i++) {
- c = 'default';
- if(m[dpc[i]].original && m[dpc[i]].original.type && t[m[dpc[i]].original.type]) {
- c = m[dpc[i]].original.type;
- }
- if(m[dpc[i]].data && m[dpc[i]].data.jstree && m[dpc[i]].data.jstree.type && t[m[dpc[i]].data.jstree.type]) {
- c = m[dpc[i]].data.jstree.type;
- }
- m[dpc[i]].type = c;
- if(m[dpc[i]].icon === true && t[c].icon !== undefined) {
- m[dpc[i]].icon = t[c].icon;
- }
- if(t[c].li_attr !== undefined && typeof t[c].li_attr === 'object') {
- for (k in t[c].li_attr) {
- if (t[c].li_attr.hasOwnProperty(k)) {
- if (k === 'id') {
- continue;
- }
- else if (m[dpc[i]].li_attr[k] === undefined) {
- m[dpc[i]].li_attr[k] = t[c].li_attr[k];
- }
- else if (k === 'class') {
- m[dpc[i]].li_attr['class'] = t[c].li_attr['class'] + ' ' + m[dpc[i]].li_attr['class'];
- }
- }
- }
- }
- if(t[c].a_attr !== undefined && typeof t[c].a_attr === 'object') {
- for (k in t[c].a_attr) {
- if (t[c].a_attr.hasOwnProperty(k)) {
- if (k === 'id') {
- continue;
- }
- else if (m[dpc[i]].a_attr[k] === undefined) {
- m[dpc[i]].a_attr[k] = t[c].a_attr[k];
- }
- else if (k === 'href' && m[dpc[i]].a_attr[k] === '#') {
- m[dpc[i]].a_attr['href'] = t[c].a_attr['href'];
- }
- else if (k === 'class') {
- m[dpc[i]].a_attr['class'] = t[c].a_attr['class'] + ' ' + m[dpc[i]].a_attr['class'];
- }
- }
- }
- }
- }
- m[$.jstree.root].type = $.jstree.root;
- }.bind(this));
- parent.bind.call(this);
- };
- this.get_json = function (obj, options, flat) {
- var i, j,
- m = this._model.data,
- opt = options ? $.extend(true, {}, options, {no_id:false}) : {},
- tmp = parent.get_json.call(this, obj, opt, flat);
- if(tmp === false) { return false; }
- if($.vakata.is_array(tmp)) {
- for(i = 0, j = tmp.length; i < j; i++) {
- tmp[i].type = (tmp[i].id || tmp[i].id === 0) && m[tmp[i].id] && m[tmp[i].id].type ? m[tmp[i].id].type : "default";
- if(options && options.no_id) {
- delete tmp[i].id;
- if(tmp[i].li_attr && tmp[i].li_attr.id) {
- delete tmp[i].li_attr.id;
- }
- if(tmp[i].a_attr && tmp[i].a_attr.id) {
- delete tmp[i].a_attr.id;
- }
- }
- }
- }
- else {
- tmp.type = (tmp.id || tmp.id === 0) && m[tmp.id] && m[tmp.id].type ? m[tmp.id].type : "default";
- if(options && options.no_id) {
- tmp = this._delete_ids(tmp);
- }
- }
- return tmp;
- };
- this._delete_ids = function (tmp) {
- if($.vakata.is_array(tmp)) {
- for(var i = 0, j = tmp.length; i < j; i++) {
- tmp[i] = this._delete_ids(tmp[i]);
- }
- return tmp;
- }
- delete tmp.id;
- if(tmp.li_attr && tmp.li_attr.id) {
- delete tmp.li_attr.id;
- }
- if(tmp.a_attr && tmp.a_attr.id) {
- delete tmp.a_attr.id;
- }
- if(tmp.children && $.vakata.is_array(tmp.children)) {
- tmp.children = this._delete_ids(tmp.children);
- }
- return tmp;
- };
- this.check = function (chk, obj, par, pos, more) {
- if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
- obj = obj && (obj.id || obj.id === 0) ? obj : this.get_node(obj);
- par = par && (par.id || par.id === 0) ? par : this.get_node(par);
- var m = obj && (obj.id || obj.id === 0) ? (more && more.origin ? more.origin : $.jstree.reference(obj.id)) : null, tmp, d, i, j;
- m = m && m._model && m._model.data ? m._model.data : null;
- switch(chk) {
- case "create_node":
- case "move_node":
- case "copy_node":
- if(chk !== 'move_node' || $.inArray(obj.id, par.children) === -1) {
- tmp = this.get_rules(par);
- if(tmp.max_children !== undefined && tmp.max_children !== -1 && tmp.max_children === par.children.length) {
- 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 === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
- return false;
- }
- if(tmp.valid_children !== undefined && tmp.valid_children !== -1 && $.inArray((obj.type || 'default'), tmp.valid_children) === -1) {
- 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 === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
- return false;
- }
- if(m && obj.children_d && obj.parents) {
- d = 0;
- for(i = 0, j = obj.children_d.length; i < j; i++) {
- d = Math.max(d, m[obj.children_d[i]].parents.length);
- }
- d = d - obj.parents.length + 1;
- }
- if(d <= 0 || d === undefined) { d = 1; }
- do {
- if(tmp.max_depth !== undefined && tmp.max_depth !== -1 && tmp.max_depth < d) {
- 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 === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
- return false;
- }
- par = this.get_node(par.parent);
- tmp = this.get_rules(par);
- d++;
- } while(par);
- }
- break;
- }
- return true;
- };
-
- this.get_rules = function (obj) {
- obj = this.get_node(obj);
- if(!obj) { return false; }
- var tmp = this.get_type(obj, true);
- if(tmp.max_depth === undefined) { tmp.max_depth = -1; }
- if(tmp.max_children === undefined) { tmp.max_children = -1; }
- if(tmp.valid_children === undefined) { tmp.valid_children = -1; }
- return tmp;
- };
-
- this.get_type = function (obj, rules) {
- obj = this.get_node(obj);
- return (!obj) ? false : ( rules ? $.extend({ 'type' : obj.type }, this.settings.types[obj.type]) : obj.type);
- };
-
- this.set_type = function (obj, type) {
- var m = this._model.data, t, t1, t2, old_type, old_icon, k, d, a;
- if($.vakata.is_array(obj)) {
- obj = obj.slice();
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
- this.set_type(obj[t1], type);
- }
- return true;
- }
- t = this.settings.types;
- obj = this.get_node(obj);
- if(!t[type] || !obj) { return false; }
- d = this.get_node(obj, true);
- if (d && d.length) {
- a = d.children('.jstree-anchor');
- }
- old_type = obj.type;
- old_icon = this.get_icon(obj);
- obj.type = type;
- if(old_icon === true || !t[old_type] || (t[old_type].icon !== undefined && old_icon === t[old_type].icon)) {
- this.set_icon(obj, t[type].icon !== undefined ? t[type].icon : true);
- }
-
- if(t[old_type] && t[old_type].li_attr !== undefined && typeof t[old_type].li_attr === 'object') {
- for (k in t[old_type].li_attr) {
- if (t[old_type].li_attr.hasOwnProperty(k)) {
- if (k === 'id') {
- continue;
- }
- else if (k === 'class') {
- m[obj.id].li_attr['class'] = (m[obj.id].li_attr['class'] || '').replace(t[old_type].li_attr[k], '');
- if (d) { d.removeClass(t[old_type].li_attr[k]); }
- }
- else if (m[obj.id].li_attr[k] === t[old_type].li_attr[k]) {
- m[obj.id].li_attr[k] = null;
- if (d) { d.removeAttr(k); }
- }
- }
- }
- }
- if(t[old_type] && t[old_type].a_attr !== undefined && typeof t[old_type].a_attr === 'object') {
- for (k in t[old_type].a_attr) {
- if (t[old_type].a_attr.hasOwnProperty(k)) {
- if (k === 'id') {
- continue;
- }
- else if (k === 'class') {
- m[obj.id].a_attr['class'] = (m[obj.id].a_attr['class'] || '').replace(t[old_type].a_attr[k], '');
- if (a) { a.removeClass(t[old_type].a_attr[k]); }
- }
- else if (m[obj.id].a_attr[k] === t[old_type].a_attr[k]) {
- if (k === 'href') {
- m[obj.id].a_attr[k] = '#';
- if (a) { a.attr('href', '#'); }
- }
- else {
- delete m[obj.id].a_attr[k];
- if (a) { a.removeAttr(k); }
- }
- }
- }
- }
- }
-
- if(t[type].li_attr !== undefined && typeof t[type].li_attr === 'object') {
- for (k in t[type].li_attr) {
- if (t[type].li_attr.hasOwnProperty(k)) {
- if (k === 'id') {
- continue;
- }
- else if (m[obj.id].li_attr[k] === undefined) {
- m[obj.id].li_attr[k] = t[type].li_attr[k];
- if (d) {
- if (k === 'class') {
- d.addClass(t[type].li_attr[k]);
- }
- else {
- d.attr(k, t[type].li_attr[k]);
- }
- }
- }
- else if (k === 'class') {
- m[obj.id].li_attr['class'] = t[type].li_attr[k] + ' ' + m[obj.id].li_attr['class'];
- if (d) { d.addClass(t[type].li_attr[k]); }
- }
- }
- }
- }
- if(t[type].a_attr !== undefined && typeof t[type].a_attr === 'object') {
- for (k in t[type].a_attr) {
- if (t[type].a_attr.hasOwnProperty(k)) {
- if (k === 'id') {
- continue;
- }
- else if (m[obj.id].a_attr[k] === undefined) {
- m[obj.id].a_attr[k] = t[type].a_attr[k];
- if (a) {
- if (k === 'class') {
- a.addClass(t[type].a_attr[k]);
- }
- else {
- a.attr(k, t[type].a_attr[k]);
- }
- }
- }
- else if (k === 'href' && m[obj.id].a_attr[k] === '#') {
- m[obj.id].a_attr['href'] = t[type].a_attr['href'];
- if (a) { a.attr('href', t[type].a_attr['href']); }
- }
- else if (k === 'class') {
- m[obj.id].a_attr['class'] = t[type].a_attr['class'] + ' ' + m[obj.id].a_attr['class'];
- if (a) { a.addClass(t[type].a_attr[k]); }
- }
- }
- }
- }
- return true;
- };
- };
-
-
-
- $.jstree.defaults.unique = {
-
- case_sensitive : false,
-
- trim_whitespace : false,
-
- duplicate : function (name, counter) {
- return name + ' (' + counter + ')';
- }
- };
- $.jstree.plugins.unique = function (options, parent) {
- this.check = function (chk, obj, par, pos, more) {
- if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
- obj = obj && (obj.id || obj.id === 0) ? obj : this.get_node(obj);
- par = par && (par.id || par.id === 0) ? par : this.get_node(par);
- if(!par || !par.children) { return true; }
- var n = chk === "rename_node" ? pos : obj.text,
- c = [],
- s = this.settings.unique.case_sensitive,
- w = this.settings.unique.trim_whitespace,
- m = this._model.data, i, j, t;
- for(i = 0, j = par.children.length; i < j; i++) {
- t = m[par.children[i]].text;
- if (!s) {
- t = t.toLowerCase();
- }
- if (w) {
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
- }
- c.push(t);
- }
- if(!s) { n = n.toLowerCase(); }
- if (w) { n = n.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }
- switch(chk) {
- case "delete_node":
- return true;
- case "rename_node":
- t = obj.text || '';
- if (!s) {
- t = t.toLowerCase();
- }
- if (w) {
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
- }
- i = ($.inArray(n, c) === -1 || (obj.text && t === n));
- if(!i) {
- 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 === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
- }
- return i;
- case "create_node":
- i = ($.inArray(n, c) === -1);
- if(!i) {
- 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 === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
- }
- return i;
- case "copy_node":
- i = ($.inArray(n, c) === -1);
- if(!i) {
- 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 === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
- }
- return i;
- case "move_node":
- i = ( (obj.parent === par.id && (!more || !more.is_multi)) || $.inArray(n, c) === -1);
- if(!i) {
- 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 === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
- }
- return i;
- }
- return true;
- };
- this.create_node = function (par, node, pos, callback, is_loaded) {
- if(!node || (typeof node === 'object' && node.text === undefined)) {
- if(par === null) {
- par = $.jstree.root;
- }
- par = this.get_node(par);
- if(!par) {
- return parent.create_node.call(this, par, node, pos, callback, is_loaded);
- }
- pos = pos === undefined ? "last" : pos;
- if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
- return parent.create_node.call(this, par, node, pos, callback, is_loaded);
- }
- if(!node) { node = {}; }
- 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;
- n = tmp = this.get_string('New node');
- dpc = [];
- for(i = 0, j = par.children.length; i < j; i++) {
- t = m[par.children[i]].text;
- if (!s) {
- t = t.toLowerCase();
- }
- if (w) {
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
- }
- dpc.push(t);
- }
- i = 1;
- t = n;
- if (!s) {
- t = t.toLowerCase();
- }
- if (w) {
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
- }
- while($.inArray(t, dpc) !== -1) {
- n = cb.call(this, tmp, (++i)).toString();
- t = n;
- if (!s) {
- t = t.toLowerCase();
- }
- if (w) {
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
- }
- }
- node.text = n;
- }
- return parent.create_node.call(this, par, node, pos, callback, is_loaded);
- };
- };
-
-
- var div = document.createElement('DIV');
- div.setAttribute('unselectable','on');
- div.setAttribute('role','presentation');
- div.className = 'jstree-wholerow';
- div.innerHTML = ' ';
- $.jstree.plugins.wholerow = function (options, parent) {
- this.bind = function () {
- parent.bind.call(this);
- this.element
- .on('ready.jstree set_state.jstree', function () {
- this.hide_dots();
- }.bind(this))
- .on("init.jstree loading.jstree ready.jstree", function () {
-
- this.get_container_ul().addClass('jstree-wholerow-ul');
- }.bind(this))
- .on("deselect_all.jstree", function (e, data) {
- this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
- }.bind(this))
- .on("changed.jstree", function (e, data) {
- this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
- var tmp = false, i, j;
- for(i = 0, j = data.selected.length; i < j; i++) {
- tmp = this.get_node(data.selected[i], true);
- if(tmp && tmp.length) {
- tmp.children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
- }
- }
- }.bind(this))
- .on("open_node.jstree", function (e, data) {
- this.get_node(data.node, true).find('.jstree-clicked').parent().children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
- }.bind(this))
- .on("hover_node.jstree dehover_node.jstree", function (e, data) {
- if(e.type === "hover_node" && this.is_disabled(data.node)) { return; }
- this.get_node(data.node, true).children('.jstree-wholerow')[e.type === "hover_node"?"addClass":"removeClass"]('jstree-wholerow-hovered');
- }.bind(this))
- .on("contextmenu.jstree", ".jstree-wholerow", function (e) {
- if (this._data.contextmenu) {
- e.preventDefault();
- var tmp = $.Event('contextmenu', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey, pageX : e.pageX, pageY : e.pageY });
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp);
- }
- }.bind(this))
-
- .on("click.jstree", ".jstree-wholerow", function (e) {
- e.stopImmediatePropagation();
- var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).trigger('focus');
- })
- .on("dblclick.jstree", ".jstree-wholerow", function (e) {
- e.stopImmediatePropagation();
- var tmp = $.Event('dblclick', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).trigger('focus');
- })
- .on("click.jstree", ".jstree-leaf > .jstree-ocl", function (e) {
- e.stopImmediatePropagation();
- var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).trigger('focus');
- }.bind(this))
- .on("mouseover.jstree", ".jstree-wholerow, .jstree-icon", function (e) {
- e.stopImmediatePropagation();
- if(!this.is_disabled(e.currentTarget)) {
- this.hover_node(e.currentTarget);
- }
- return false;
- }.bind(this))
- .on("mouseleave.jstree", ".jstree-node", function (e) {
- this.dehover_node(e.currentTarget);
- }.bind(this));
- };
- this.teardown = function () {
- if(this.settings.wholerow) {
- this.element.find(".jstree-wholerow").remove();
- }
- parent.teardown.call(this);
- };
- this.redraw_node = function(obj, deep, callback, force_render) {
- obj = parent.redraw_node.apply(this, arguments);
- if(obj) {
- var tmp = div.cloneNode(true);
-
- if($.inArray(obj.id, this._data.core.selected) !== -1) { tmp.className += ' jstree-wholerow-clicked'; }
- if(this._data.core.focused && this._data.core.focused === obj.id) { tmp.className += ' jstree-wholerow-hovered'; }
- obj.insertBefore(tmp, obj.childNodes[0]);
- }
- return obj;
- };
- };
-
-
- if(window.customElements && Object && Object.create) {
- var proto = Object.create(HTMLElement.prototype);
- proto.createdCallback = function () {
- var c = { core : {}, plugins : [] }, i;
- for(i in $.jstree.plugins) {
- if($.jstree.plugins.hasOwnProperty(i) && this.attributes[i]) {
- c.plugins.push(i);
- if(this.getAttribute(i) && JSON.parse(this.getAttribute(i))) {
- c[i] = JSON.parse(this.getAttribute(i));
- }
- }
- }
- for(i in $.jstree.defaults.core) {
- if($.jstree.defaults.core.hasOwnProperty(i) && this.attributes[i]) {
- c.core[i] = JSON.parse(this.getAttribute(i)) || this.getAttribute(i);
- }
- }
- $(this).jstree(c);
- };
-
- try {
- window.customElements.define("vakata-jstree", function() {}, { prototype: proto });
- } catch (ignore) { }
- }
- }));
|