jquery.jstree.js 191 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833
  1. /*
  2. * jsTree 1.0-rc3
  3. * http://jstree.com/
  4. *
  5. * Copyright (c) 2010 Ivan Bozhanov (vakata.com)
  6. *
  7. * Licensed same as jquery - under the terms of either the MIT License or the GPL Version 2 License
  8. * http://www.opensource.org/licenses/mit-license.php
  9. * http://www.gnu.org/licenses/gpl.html
  10. *
  11. * $Date: 2011-02-09 01:17:14 +0200 (ср, 09 февр 2011) $
  12. * $Revision: 236 $
  13. */
  14. /*jslint browser: true, onevar: true, undef: true, bitwise: true, strict: true */
  15. /*global window : false, clearInterval: false, clearTimeout: false, document: false, setInterval: false, setTimeout: false, jQuery: false, navigator: false, XSLTProcessor: false, DOMParser: false, XMLSerializer: false*/
  16. (function (factory) {
  17. if (typeof define === 'function' && define.amd) {
  18. define([
  19. "jquery",
  20. "jquery/jquery.cookie",
  21. "jquery/jstree/jquery.hotkeys"
  22. ], factory);
  23. } else {
  24. factory(jQuery);
  25. }
  26. }(function ($) {
  27. "use strict";
  28. // top wrapper to prevent multiple inclusion (is this OK?)
  29. (function () {
  30. var is_ie6 = false, is_ie7 = false, is_ff2 = false;
  31. /*
  32. * jsTree core
  33. */
  34. (function ($) {
  35. // Common functions not related to jsTree
  36. // decided to move them to a `vakata` "namespace"
  37. $.vakata = {};
  38. // CSS related functions
  39. $.vakata.css = {
  40. get_css : function(rule_name, delete_flag, sheet) {
  41. rule_name = rule_name.toLowerCase();
  42. var css_rules = sheet.cssRules || sheet.rules,
  43. j = 0;
  44. do {
  45. if(css_rules.length && j > css_rules.length + 5) { return false; }
  46. if(css_rules[j].selectorText && css_rules[j].selectorText.toLowerCase() == rule_name) {
  47. if(delete_flag === true) {
  48. if(sheet.removeRule) { sheet.removeRule(j); }
  49. if(sheet.deleteRule) { sheet.deleteRule(j); }
  50. return true;
  51. }
  52. else { return css_rules[j]; }
  53. }
  54. }
  55. while (css_rules[++j]);
  56. return false;
  57. },
  58. add_css : function(rule_name, sheet) {
  59. if($.jstree.css.get_css(rule_name, false, sheet)) { return false; }
  60. if(sheet.insertRule) { sheet.insertRule(rule_name + ' { }', 0); } else { sheet.addRule(rule_name, null, 0); }
  61. return $.vakata.css.get_css(rule_name);
  62. },
  63. remove_css : function(rule_name, sheet) {
  64. return $.vakata.css.get_css(rule_name, true, sheet);
  65. },
  66. add_sheet : function(opts) {
  67. var tmp = false, is_new = true;
  68. if(opts.str) {
  69. if(opts.title) { tmp = $("style[id='" + opts.title + "-stylesheet']")[0]; }
  70. if(tmp) { is_new = false; }
  71. else {
  72. tmp = document.createElement("style");
  73. tmp.setAttribute('type',"text/css");
  74. if(opts.title) { tmp.setAttribute("id", opts.title + "-stylesheet"); }
  75. }
  76. if(tmp.styleSheet) {
  77. if(is_new) {
  78. document.getElementsByTagName("head")[0].appendChild(tmp);
  79. tmp.styleSheet.cssText = opts.str;
  80. }
  81. else {
  82. tmp.styleSheet.cssText = tmp.styleSheet.cssText + " " + opts.str;
  83. }
  84. }
  85. else {
  86. tmp.appendChild(document.createTextNode(opts.str));
  87. document.getElementsByTagName("head")[0].appendChild(tmp);
  88. }
  89. return tmp.sheet || tmp.styleSheet;
  90. }
  91. if(opts.url) {
  92. if(document.createStyleSheet) {
  93. try { tmp = document.createStyleSheet(opts.url); } catch (e) { }
  94. }
  95. else {
  96. tmp = document.createElement('link');
  97. tmp.rel = 'stylesheet';
  98. tmp.type = 'text/css';
  99. tmp.media = "all";
  100. tmp.href = opts.url;
  101. document.getElementsByTagName("head")[0].appendChild(tmp);
  102. return tmp.styleSheet;
  103. }
  104. }
  105. }
  106. };
  107. // private variables
  108. var instances = [], // instance array (used by $.jstree.reference/create/focused)
  109. focused_instance = -1, // the index in the instance array of the currently focused instance
  110. plugins = {}, // list of included plugins
  111. prepared_move = {}; // for the move_node function
  112. // jQuery plugin wrapper (thanks to jquery UI widget function)
  113. $.fn.jstree = function (settings) {
  114. var isMethodCall = (typeof settings == 'string'), // is this a method call like $().jstree("open_node")
  115. args = Array.prototype.slice.call(arguments, 1),
  116. returnValue = this;
  117. // if a method call execute the method on all selected instances
  118. if(isMethodCall) {
  119. if(settings.substring(0, 1) == '_') { return returnValue; }
  120. this.each(function() {
  121. var instance = instances[$.data(this, "jstree_instance_id")],
  122. methodValue = (instance && $.isFunction(instance[settings])) ? instance[settings].apply(instance, args) : instance;
  123. if(typeof methodValue !== "undefined" && (settings.indexOf("is_") === 0 || (methodValue !== true && methodValue !== false))) { returnValue = methodValue; return false; }
  124. });
  125. }
  126. else {
  127. this.each(function() {
  128. // extend settings and allow for multiple hashes and $.data
  129. var instance_id = $.data(this, "jstree_instance_id"),
  130. a = [],
  131. b = settings ? $.extend({}, true, settings) : {},
  132. c = $(this),
  133. s = false,
  134. t = [];
  135. a = a.concat(args);
  136. if(c.data("jstree")) { a.push(c.data("jstree")); }
  137. b = a.length ? $.extend.apply(null, [true, b].concat(a)) : b;
  138. // if an instance already exists, destroy it first
  139. if(typeof instance_id !== "undefined" && instances[instance_id]) { instances[instance_id].destroy(); }
  140. // push a new empty object to the instances array
  141. instance_id = parseInt(instances.push({}),10) - 1;
  142. // store the jstree instance id to the container element
  143. $.data(this, "jstree_instance_id", instance_id);
  144. // clean up all plugins
  145. b.plugins = $.isArray(b.plugins) ? b.plugins : $.jstree.defaults.plugins.slice();
  146. b.plugins.unshift("core");
  147. // only unique plugins
  148. b.plugins = b.plugins.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",");
  149. // extend defaults with passed data
  150. s = $.extend(true, {}, $.jstree.defaults, b);
  151. s.plugins = b.plugins;
  152. $.each(plugins, function (i, val) {
  153. if($.inArray(i, s.plugins) === -1) { s[i] = null; delete s[i]; }
  154. else { t.push(i); }
  155. });
  156. s.plugins = t;
  157. // push the new object to the instances array (at the same time set the default classes to the container) and init
  158. instances[instance_id] = new $.jstree._instance(instance_id, $(this).addClass("jstree jstree-" + instance_id), s);
  159. // init all activated plugins for this instance
  160. $.each(instances[instance_id]._get_settings().plugins, function (i, val) { instances[instance_id].data[val] = {}; });
  161. $.each(instances[instance_id]._get_settings().plugins, function (i, val) { if(plugins[val]) { plugins[val].__init.apply(instances[instance_id]); } });
  162. // initialize the instance
  163. setTimeout(function() { if(instances[instance_id]) { instances[instance_id].init(); } }, 0);
  164. });
  165. }
  166. // return the jquery selection (or if it was a method call that returned a value - the returned value)
  167. return returnValue;
  168. };
  169. // object to store exposed functions and objects
  170. $.jstree = {
  171. defaults : {
  172. plugins : []
  173. },
  174. _focused : function () { return instances[focused_instance] || null; },
  175. _reference : function (needle) {
  176. // get by instance id
  177. if(instances[needle]) { return instances[needle]; }
  178. // get by DOM (if still no luck - return null
  179. var o = $(needle);
  180. if(!o.length && typeof needle === "string") { o = $("#" + needle); }
  181. if(!o.length) { return null; }
  182. return instances[o.closest(".jstree").data("jstree_instance_id")] || null;
  183. },
  184. _instance : function (index, container, settings) {
  185. // for plugins to store data in
  186. this.data = { core : {} };
  187. this.get_settings = function () { return $.extend(true, {}, settings); };
  188. this._get_settings = function () { return settings; };
  189. this.get_index = function () { return index; };
  190. this.get_container = function () { return container; };
  191. this.get_container_ul = function () { return container.children("ul:eq(0)"); };
  192. this._set_settings = function (s) {
  193. settings = $.extend(true, {}, settings, s);
  194. };
  195. },
  196. _fn : { },
  197. plugin : function (pname, pdata) {
  198. pdata = $.extend({}, {
  199. __init : $.noop,
  200. __destroy : $.noop,
  201. _fn : {},
  202. defaults : false
  203. }, pdata);
  204. plugins[pname] = pdata;
  205. $.jstree.defaults[pname] = pdata.defaults;
  206. $.each(pdata._fn, function (i, val) {
  207. val.plugin = pname;
  208. val.old = $.jstree._fn[i];
  209. $.jstree._fn[i] = function () {
  210. var rslt,
  211. func = val,
  212. args = Array.prototype.slice.call(arguments),
  213. evnt = new $.Event("before.jstree"),
  214. rlbk = false;
  215. if(this.data.core.locked === true && i !== "unlock" && i !== "is_locked") { return; }
  216. // Check if function belongs to the included plugins of this instance
  217. do {
  218. if(func && func.plugin && $.inArray(func.plugin, this._get_settings().plugins) !== -1) { break; }
  219. func = func.old;
  220. } while(func);
  221. if(!func) { return; }
  222. // context and function to trigger events, then finally call the function
  223. if(i.indexOf("_") === 0) {
  224. rslt = func.apply(this, args);
  225. }
  226. else {
  227. rslt = this.get_container().triggerHandler(evnt, { "func" : i, "inst" : this, "args" : args, "plugin" : func.plugin });
  228. if(rslt === false) { return; }
  229. if(typeof rslt !== "undefined") { args = rslt; }
  230. rslt = func.apply(
  231. $.extend({}, this, {
  232. __callback : function (data) {
  233. this.get_container().triggerHandler( i + '.jstree', { "inst" : this, "args" : args, "rslt" : data, "rlbk" : rlbk });
  234. },
  235. __rollback : function () {
  236. rlbk = this.get_rollback();
  237. return rlbk;
  238. },
  239. __call_old : function (replace_arguments) {
  240. return func.old.apply(this, (replace_arguments ? Array.prototype.slice.call(arguments, 1) : args ) );
  241. }
  242. }), args);
  243. }
  244. // return the result
  245. return rslt;
  246. };
  247. $.jstree._fn[i].old = val.old;
  248. $.jstree._fn[i].plugin = pname;
  249. });
  250. },
  251. rollback : function (rb) {
  252. if(rb) {
  253. if(!$.isArray(rb)) { rb = [ rb ]; }
  254. $.each(rb, function (i, val) {
  255. instances[val.i].set_rollback(val.h, val.d);
  256. });
  257. }
  258. }
  259. };
  260. // set the prototype for all instances
  261. $.jstree._fn = $.jstree._instance.prototype = {};
  262. // load the css when DOM is ready
  263. $(function() {
  264. // code is copied from jQuery ($.browser is deprecated + there is a bug in IE)
  265. var u = navigator.userAgent.toLowerCase(),
  266. v = (u.match( /.+?(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
  267. css_string = '' +
  268. '.jstree ul, .jstree li { display:block; margin:0 0 0 0; padding:0 0 0 0; list-style-type:none; } ' +
  269. '.jstree li { display:block; min-height:18px; line-height:18px; white-space:nowrap; margin-left:18px; min-width:18px; } ' +
  270. '.jstree-rtl li { margin-left:0; margin-right:18px; } ' +
  271. '.jstree > ul > li { margin-left:0px; } ' +
  272. '.jstree-rtl > ul > li { margin-right:0px; } ' +
  273. '.jstree ins { display:inline-block; text-decoration:none; width:18px; height:18px; margin:0 0 0 0; padding:0; } ' +
  274. '.jstree a { display:inline-block; line-height:16px; height:16px; color:black; white-space:nowrap; text-decoration:none; padding:1px 2px; margin:0; } ' +
  275. '.jstree a:focus { outline: none; } ' +
  276. '.jstree a > ins { height:16px; width:16px; } ' +
  277. '.jstree a > .jstree-icon { margin-right:3px; } ' +
  278. '.jstree-rtl a > .jstree-icon { margin-left:3px; margin-right:0; } ' +
  279. 'li.jstree-open > ul { display:block; } ' +
  280. 'li.jstree-closed > ul { display:none; } ';
  281. // Correct IE 6 (does not support the > CSS selector)
  282. if(/msie/.test(u) && parseInt(v, 10) == 6) {
  283. is_ie6 = true;
  284. // fix image flicker and lack of caching
  285. try {
  286. document.execCommand("BackgroundImageCache", false, true);
  287. } catch (err) { }
  288. css_string += '' +
  289. '.jstree li { height:18px; margin-left:0; margin-right:0; } ' +
  290. '.jstree li li { margin-left:18px; } ' +
  291. '.jstree-rtl li li { margin-left:0px; margin-right:18px; } ' +
  292. 'li.jstree-open ul { display:block; } ' +
  293. 'li.jstree-closed ul { display:none !important; } ' +
  294. '.jstree li a { display:inline; border-width:0 !important; padding:0px 2px !important; } ' +
  295. '.jstree li a ins { height:16px; width:16px; margin-right:3px; } ' +
  296. '.jstree-rtl li a ins { margin-right:0px; margin-left:3px; } ';
  297. }
  298. // Correct IE 7 (shifts anchor nodes onhover)
  299. if(/msie/.test(u) && parseInt(v, 10) == 7) {
  300. is_ie7 = true;
  301. css_string += '.jstree li a { border-width:0 !important; padding:0px 2px !important; } ';
  302. }
  303. // correct ff2 lack of display:inline-block
  304. if(!/compatible/.test(u) && /mozilla/.test(u) && parseFloat(v, 10) < 1.9) {
  305. is_ff2 = true;
  306. css_string += '' +
  307. '.jstree ins { display:-moz-inline-box; } ' +
  308. '.jstree li { line-height:12px; } ' + // WHY??
  309. '.jstree a { display:-moz-inline-box; } ' +
  310. '.jstree .jstree-no-icons .jstree-checkbox { display:-moz-inline-stack !important; } ';
  311. /* this shouldn't be here as it is theme specific */
  312. }
  313. // the default stylesheet
  314. $.vakata.css.add_sheet({ str : css_string, title : "jstree" });
  315. });
  316. // core functions (open, close, create, update, delete)
  317. $.jstree.plugin("core", {
  318. __init : function () {
  319. this.data.core.locked = false;
  320. this.data.core.to_open = this.get_settings().core.initially_open;
  321. this.data.core.to_load = this.get_settings().core.initially_load;
  322. },
  323. defaults : {
  324. html_titles : false,
  325. animation : 500,
  326. initially_open : [],
  327. initially_load : [],
  328. open_parents : true,
  329. notify_plugins : true,
  330. rtl : false,
  331. load_open : false,
  332. strings : {
  333. loading : "Loading ...",
  334. new_node : "New node",
  335. multiple_selection : "Multiple selection"
  336. }
  337. },
  338. _fn : {
  339. init : function () {
  340. this.set_focus();
  341. if(this._get_settings().core.rtl) {
  342. this.get_container().addClass("jstree-rtl").css("direction", "rtl");
  343. }
  344. this.get_container().html("<ul><li class='jstree-last jstree-leaf'><ins>&#160;</ins><a class='jstree-loading' href='#'><ins class='jstree-icon'>&#160;</ins>" + this._get_string("loading") + "</a></li></ul>");
  345. this.data.core.li_height = this.get_container_ul().find("li.jstree-closed, li.jstree-leaf").eq(0).height() || 18;
  346. this.get_container()
  347. .delegate("li > ins", "click.jstree", $.proxy(function (event) {
  348. var trgt = $(event.target);
  349. // if(trgt.is("ins") && event.pageY - trgt.offset().top < this.data.core.li_height) { this.toggle_node(trgt); }
  350. this.toggle_node(trgt);
  351. }, this))
  352. .bind("mousedown.jstree", $.proxy(function () {
  353. this.set_focus(); // This used to be setTimeout(set_focus,0) - why?
  354. }, this))
  355. .bind("dblclick.jstree", function (event) {
  356. var sel;
  357. if(document.selection && document.selection.empty) { document.selection.empty(); }
  358. else {
  359. if(window.getSelection) {
  360. sel = window.getSelection();
  361. try {
  362. sel.removeAllRanges();
  363. sel.collapse();
  364. } catch (err) { }
  365. }
  366. }
  367. });
  368. if(this._get_settings().core.notify_plugins) {
  369. this.get_container()
  370. .bind("load_node.jstree", $.proxy(function (e, data) {
  371. var o = this._get_node(data.rslt.obj),
  372. t = this;
  373. if(o === -1) { o = this.get_container_ul(); }
  374. if(!o.length) { return; }
  375. o.find("li").each(function () {
  376. var th = $(this);
  377. if(th.data("jstree")) {
  378. $.each(th.data("jstree"), function (plugin, values) {
  379. if(t.data[plugin] && $.isFunction(t["_" + plugin + "_notify"])) {
  380. t["_" + plugin + "_notify"].call(t, th, values);
  381. }
  382. });
  383. }
  384. });
  385. }, this));
  386. }
  387. if(this._get_settings().core.load_open) {
  388. this.get_container()
  389. .bind("load_node.jstree", $.proxy(function (e, data) {
  390. var o = this._get_node(data.rslt.obj),
  391. t = this;
  392. if(o === -1) { o = this.get_container_ul(); }
  393. if(!o.length) { return; }
  394. o.find("li.jstree-open:not(:has(ul))").each(function () {
  395. t.load_node(this, $.noop, $.noop);
  396. });
  397. }, this));
  398. }
  399. this.__callback();
  400. this.load_node(-1, function () { this.loaded(); this.reload_nodes(); });
  401. },
  402. destroy : function () {
  403. var i,
  404. n = this.get_index(),
  405. s = this._get_settings(),
  406. _this = this;
  407. $.each(s.plugins, function (i, val) {
  408. try { plugins[val].__destroy.apply(_this); } catch(err) { }
  409. });
  410. this.__callback();
  411. // set focus to another instance if this one is focused
  412. if(this.is_focused()) {
  413. for(i in instances) {
  414. if(instances.hasOwnProperty(i) && i != n) {
  415. instances[i].set_focus();
  416. break;
  417. }
  418. }
  419. }
  420. // if no other instance found
  421. if(n === focused_instance) { focused_instance = -1; }
  422. // remove all traces of jstree in the DOM (only the ones set using jstree*) and cleans all events
  423. this.get_container()
  424. .unbind(".jstree")
  425. .undelegate(".jstree")
  426. .removeData("jstree_instance_id")
  427. .find("[class^='jstree']")
  428. .addBack()
  429. .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });
  430. $(document)
  431. .unbind(".jstree-" + n)
  432. .undelegate(".jstree-" + n);
  433. // remove the actual data
  434. instances[n] = null;
  435. delete instances[n];
  436. },
  437. _core_notify : function (n, data) {
  438. if(data.opened) {
  439. this.open_node(n, false, true);
  440. }
  441. },
  442. lock : function () {
  443. this.data.core.locked = true;
  444. this.get_container().children("ul").addClass("jstree-locked").css("opacity","0.7");
  445. this.__callback({});
  446. },
  447. unlock : function () {
  448. this.data.core.locked = false;
  449. this.get_container().children("ul").removeClass("jstree-locked").css("opacity","1");
  450. this.__callback({});
  451. },
  452. is_locked : function () { return this.data.core.locked; },
  453. save_opened : function () {
  454. var _this = this;
  455. this.data.core.to_open = [];
  456. this.get_container_ul().find("li.jstree-open").each(function () {
  457. if(this.id) { _this.data.core.to_open.push("#" + this.id.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:")); }
  458. });
  459. this.__callback(_this.data.core.to_open);
  460. },
  461. save_loaded : function () { },
  462. reload_nodes : function (is_callback) {
  463. var _this = this,
  464. done = true,
  465. current = [],
  466. remaining = [];
  467. if(!is_callback) {
  468. this.data.core.reopen = false;
  469. this.data.core.refreshing = true;
  470. this.data.core.to_open = $.map($.makeArray(this.data.core.to_open), function (n) { return "#" + n.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:"); });
  471. this.data.core.to_load = $.map($.makeArray(this.data.core.to_load), function (n) { return "#" + n.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:"); });
  472. if(this.data.core.to_open.length) {
  473. this.data.core.to_load = this.data.core.to_load.concat(this.data.core.to_open);
  474. }
  475. }
  476. if(this.data.core.to_load.length) {
  477. $.each(this.data.core.to_load, function (i, val) {
  478. if(val == "#") { return true; }
  479. if($(val).length) { current.push(val); }
  480. else { remaining.push(val); }
  481. });
  482. if(current.length) {
  483. this.data.core.to_load = remaining;
  484. $.each(current, function (i, val) {
  485. if(!_this._is_loaded(val)) {
  486. _this.load_node(val, function () { _this.reload_nodes(true); }, function () { _this.reload_nodes(true); });
  487. done = false;
  488. }
  489. });
  490. }
  491. }
  492. if(this.data.core.to_open.length) {
  493. $.each(this.data.core.to_open, function (i, val) {
  494. _this.open_node(val, false, true);
  495. });
  496. }
  497. if(done) {
  498. // TODO: find a more elegant approach to syncronizing returning requests
  499. if(this.data.core.reopen) { clearTimeout(this.data.core.reopen); }
  500. this.data.core.reopen = setTimeout(function () { _this.__callback({}, _this); }, 50);
  501. this.data.core.refreshing = false;
  502. this.reopen();
  503. }
  504. },
  505. reopen : function () {
  506. var _this = this;
  507. if(this.data.core.to_open.length) {
  508. $.each(this.data.core.to_open, function (i, val) {
  509. _this.open_node(val, false, true);
  510. });
  511. }
  512. this.__callback({});
  513. },
  514. refresh : function (obj) {
  515. var _this = this;
  516. this.save_opened();
  517. if(!obj) { obj = -1; }
  518. obj = this._get_node(obj);
  519. if(!obj) { obj = -1; }
  520. if(obj !== -1) { obj.children("UL").remove(); }
  521. else { this.get_container_ul().empty(); }
  522. this.load_node(obj, function () { _this.__callback({ "obj" : obj}); _this.reload_nodes(); });
  523. },
  524. // Dummy function to fire after the first load (so that there is a jstree.loaded event)
  525. loaded : function () {
  526. this.__callback();
  527. },
  528. // deal with focus
  529. set_focus : function () {
  530. if(this.is_focused()) { return; }
  531. var f = $.jstree._focused();
  532. if(f) { f.unset_focus(); }
  533. this.get_container().addClass("jstree-focused");
  534. focused_instance = this.get_index();
  535. this.__callback();
  536. },
  537. is_focused : function () {
  538. return focused_instance == this.get_index();
  539. },
  540. unset_focus : function () {
  541. if(this.is_focused()) {
  542. this.get_container().removeClass("jstree-focused");
  543. focused_instance = -1;
  544. }
  545. this.__callback();
  546. },
  547. // traverse
  548. _get_node : function (obj) {
  549. var $obj = $(obj, this.get_container());
  550. if($obj.is(".jstree") || obj == -1) { return -1; }
  551. $obj = $obj.closest("li", this.get_container());
  552. return $obj.length ? $obj : false;
  553. },
  554. _get_next : function (obj, strict) {
  555. obj = this._get_node(obj);
  556. if(obj === -1) { return this.get_container().find("> ul > li:first-child"); }
  557. if(!obj.length) { return false; }
  558. if(strict) { return (obj.nextAll("li").size() > 0) ? obj.nextAll("li:eq(0)") : false; }
  559. if(obj.hasClass("jstree-open")) { return obj.find("li:eq(0)"); }
  560. else if(obj.nextAll("li").size() > 0) { return obj.nextAll("li:eq(0)"); }
  561. else { return obj.parentsUntil(".jstree","li").next("li").eq(0); }
  562. },
  563. _get_prev : function (obj, strict) {
  564. obj = this._get_node(obj);
  565. if(obj === -1) { return this.get_container().find("> ul > li:last-child"); }
  566. if(!obj.length) { return false; }
  567. if(strict) { return (obj.prevAll("li").length > 0) ? obj.prevAll("li:eq(0)") : false; }
  568. if(obj.prev("li").length) {
  569. obj = obj.prev("li").eq(0);
  570. while(obj.hasClass("jstree-open")) { obj = obj.children("ul:eq(0)").children("li:last"); }
  571. return obj;
  572. }
  573. else { var o = obj.parentsUntil(".jstree","li:eq(0)"); return o.length ? o : false; }
  574. },
  575. _get_parent : function (obj) {
  576. obj = this._get_node(obj);
  577. if(obj == -1 || !obj.length) { return false; }
  578. var o = obj.parentsUntil(".jstree", "li:eq(0)");
  579. return o.length ? o : -1;
  580. },
  581. _get_children : function (obj) {
  582. obj = this._get_node(obj);
  583. if(obj === -1) { return this.get_container().children("ul:eq(0)").children("li"); }
  584. if(!obj.length) { return false; }
  585. return obj.children("ul:eq(0)").children("li");
  586. },
  587. get_path : function (obj, id_mode) {
  588. var p = [],
  589. _this = this;
  590. obj = this._get_node(obj);
  591. if(obj === -1 || !obj || !obj.length) { return false; }
  592. obj.parentsUntil(".jstree", "li").each(function () {
  593. p.push( id_mode ? this.id : _this.get_text(this) );
  594. });
  595. p.reverse();
  596. p.push( id_mode ? obj.attr("id") : this.get_text(obj) );
  597. return p;
  598. },
  599. // string functions
  600. _get_string : function (key) {
  601. return this._get_settings().core.strings[key] || key;
  602. },
  603. is_open : function (obj) { obj = this._get_node(obj); return obj && obj !== -1 && obj.hasClass("jstree-open"); },
  604. is_closed : function (obj) { obj = this._get_node(obj); return obj && obj !== -1 && obj.hasClass("jstree-closed"); },
  605. is_leaf : function (obj) { obj = this._get_node(obj); return obj && obj !== -1 && obj.hasClass("jstree-leaf"); },
  606. correct_state : function (obj) {
  607. obj = this._get_node(obj);
  608. if(!obj || obj === -1) { return false; }
  609. obj.removeClass("jstree-closed jstree-open").addClass("jstree-leaf").children("ul").remove();
  610. this.__callback({ "obj" : obj });
  611. },
  612. // open/close
  613. open_node : function (obj, callback, skip_animation) {
  614. obj = this._get_node(obj);
  615. if(!obj.length) { return false; }
  616. if(!obj.hasClass("jstree-closed")) { if(callback) { callback.call(); } return false; }
  617. var s = skip_animation || is_ie6 ? 0 : this._get_settings().core.animation,
  618. t = this;
  619. if(!this._is_loaded(obj)) {
  620. obj.children("a").addClass("jstree-loading");
  621. this.load_node(obj, function () { t.open_node(obj, callback, skip_animation); }, callback);
  622. }
  623. else {
  624. if(this._get_settings().core.open_parents) {
  625. obj.parentsUntil(".jstree",".jstree-closed").each(function () {
  626. t.open_node(this, false, true);
  627. });
  628. }
  629. if(s) { obj.children("ul").css("display","none"); }
  630. obj.removeClass("jstree-closed").addClass("jstree-open").children("a").removeClass("jstree-loading");
  631. if(s) { obj.children("ul").stop(true, true).slideDown(s, function () { this.style.display = ""; t.after_open(obj); }); }
  632. else { t.after_open(obj); }
  633. this.__callback({ "obj" : obj });
  634. if(callback) { callback.call(); }
  635. }
  636. },
  637. after_open : function (obj) { this.__callback({ "obj" : obj }); },
  638. close_node : function (obj, skip_animation) {
  639. obj = this._get_node(obj);
  640. var s = skip_animation || is_ie6 ? 0 : this._get_settings().core.animation,
  641. t = this;
  642. if(!obj.length || !obj.hasClass("jstree-open")) { return false; }
  643. if(s) { obj.children("ul").attr("style","display:block !important"); }
  644. obj.removeClass("jstree-open").addClass("jstree-closed");
  645. if(s) { obj.children("ul").stop(true, true).slideUp(s, function () { this.style.display = ""; t.after_close(obj); }); }
  646. else { t.after_close(obj); }
  647. this.__callback({ "obj" : obj });
  648. },
  649. after_close : function (obj) { this.__callback({ "obj" : obj }); },
  650. toggle_node : function (obj) {
  651. obj = this._get_node(obj);
  652. if(obj.hasClass("jstree-closed")) { return this.open_node(obj); }
  653. if(obj.hasClass("jstree-open")) { return this.close_node(obj); }
  654. },
  655. open_all : function (obj, do_animation, original_obj) {
  656. obj = obj ? this._get_node(obj) : -1;
  657. if(!obj || obj === -1) { obj = this.get_container_ul(); }
  658. if(original_obj) {
  659. obj = obj.find("li.jstree-closed");
  660. }
  661. else {
  662. original_obj = obj;
  663. if(obj.is(".jstree-closed")) { obj = obj.find("li.jstree-closed").addBack(); }
  664. else { obj = obj.find("li.jstree-closed"); }
  665. }
  666. var _this = this;
  667. obj.each(function () {
  668. var __this = this;
  669. if(!_this._is_loaded(this)) { _this.open_node(this, function() { _this.open_all(__this, do_animation, original_obj); }, !do_animation); }
  670. else { _this.open_node(this, false, !do_animation); }
  671. });
  672. // so that callback is fired AFTER all nodes are open
  673. if(original_obj.find('li.jstree-closed').length === 0) { this.__callback({ "obj" : original_obj }); }
  674. },
  675. close_all : function (obj, do_animation) {
  676. var _this = this;
  677. obj = obj ? this._get_node(obj) : this.get_container();
  678. if(!obj || obj === -1) { obj = this.get_container_ul(); }
  679. obj.find("li.jstree-open").addBack().each(function () { _this.close_node(this, !do_animation); });
  680. this.__callback({ "obj" : obj });
  681. },
  682. clean_node : function (obj) {
  683. obj = obj && obj != -1 ? $(obj) : this.get_container_ul();
  684. obj = obj.is("li") ? obj.find("li").addBack() : obj.find("li");
  685. obj.removeClass("jstree-last")
  686. .filter("li:last-child").addClass("jstree-last").end()
  687. .filter(":has(li)")
  688. .not(".jstree-open").removeClass("jstree-leaf").addClass("jstree-closed");
  689. obj.not(".jstree-open, .jstree-closed").addClass("jstree-leaf").children("ul").remove();
  690. this.__callback({ "obj" : obj });
  691. },
  692. // rollback
  693. get_rollback : function () {
  694. this.__callback();
  695. return { i : this.get_index(), h : this.get_container().children("ul").clone(true), d : this.data };
  696. },
  697. set_rollback : function (html, data) {
  698. this.get_container().empty().append(html);
  699. this.data = data;
  700. this.__callback();
  701. },
  702. // Dummy functions to be overwritten by any datastore plugin included
  703. load_node : function (obj, s_call, e_call) { this.__callback({ "obj" : obj }); },
  704. _is_loaded : function (obj) { return true; },
  705. // Basic operations: create
  706. create_node : function (obj, position, js, callback, is_loaded) {
  707. obj = this._get_node(obj);
  708. position = typeof position === "undefined" ? "last" : position;
  709. var d = $("<li />"),
  710. s = this._get_settings().core,
  711. tmp;
  712. if(obj !== -1 && !obj.length) { return false; }
  713. if(!is_loaded && !this._is_loaded(obj)) { this.load_node(obj, function () { this.create_node(obj, position, js, callback, true); }); return false; }
  714. this.__rollback();
  715. if(typeof js === "string") { js = { "data" : js }; }
  716. if(!js) { js = {}; }
  717. if(js.attr) { d.attr(js.attr); }
  718. if(js.metadata) { d.data(js.metadata); }
  719. if(js.state) { d.addClass("jstree-" + js.state); }
  720. if(!js.data) { js.data = this._get_string("new_node"); }
  721. if(!$.isArray(js.data)) { tmp = js.data; js.data = []; js.data.push(tmp); }
  722. $.each(js.data, function (i, m) {
  723. tmp = $("<a />");
  724. if($.isFunction(m)) { m = m.call(this, js); }
  725. if(typeof m == "string") { tmp.attr('href','#')[ s.html_titles ? "html" : "text" ](m); }
  726. else {
  727. if(!m.attr) { m.attr = {}; }
  728. if(!m.attr.href) { m.attr.href = '#'; }
  729. tmp.attr(m.attr)[ s.html_titles ? "html" : "text" ](m.title);
  730. if(m.language) { tmp.addClass(m.language); }
  731. }
  732. tmp.prepend("<ins class='jstree-icon'>&#160;</ins>");
  733. if(!m.icon && js.icon) { m.icon = js.icon; }
  734. if(m.icon) {
  735. if(m.icon.indexOf("/") === -1) { tmp.children("ins").addClass(m.icon); }
  736. else { tmp.children("ins").css("background","url('" + m.icon + "') center center no-repeat"); }
  737. }
  738. d.append(tmp);
  739. });
  740. d.prepend("<ins class='jstree-icon'>&#160;</ins>");
  741. if(obj === -1) {
  742. obj = this.get_container();
  743. if(position === "before") { position = "first"; }
  744. if(position === "after") { position = "last"; }
  745. }
  746. switch(position) {
  747. case "before": obj.before(d); tmp = this._get_parent(obj); break;
  748. case "after" : obj.after(d); tmp = this._get_parent(obj); break;
  749. case "inside":
  750. case "first" :
  751. if(!obj.children("ul").length) { obj.append("<ul />"); }
  752. obj.children("ul").prepend(d);
  753. tmp = obj;
  754. break;
  755. case "last":
  756. if(!obj.children("ul").length) { obj.append("<ul />"); }
  757. obj.children("ul").append(d);
  758. tmp = obj;
  759. break;
  760. default:
  761. if(!obj.children("ul").length) { obj.append("<ul />"); }
  762. if(!position) { position = 0; }
  763. tmp = obj.children("ul").children("li").eq(position);
  764. if(tmp.length) { tmp.before(d); }
  765. else { obj.children("ul").append(d); }
  766. tmp = obj;
  767. break;
  768. }
  769. if(tmp === -1 || tmp.get(0) === this.get_container().get(0)) { tmp = -1; }
  770. this.clean_node(tmp);
  771. this.__callback({ "obj" : d, "parent" : tmp });
  772. if(callback) { callback.call(this, d); }
  773. return d;
  774. },
  775. // Basic operations: rename (deal with text)
  776. get_text : function (obj) {
  777. obj = this._get_node(obj);
  778. if(!obj.length) { return false; }
  779. var s = this._get_settings().core.html_titles;
  780. obj = obj.children("a:eq(0)");
  781. if(s) {
  782. obj = obj.clone();
  783. obj.children("INS").remove();
  784. return obj.html();
  785. }
  786. else {
  787. obj = obj.contents().filter(function() { return this.nodeType == 3; })[0];
  788. return obj.nodeValue;
  789. }
  790. },
  791. set_text : function (obj, val) {
  792. obj = this._get_node(obj);
  793. if(!obj.length) { return false; }
  794. obj = obj.children("a:eq(0)");
  795. if(this._get_settings().core.html_titles) {
  796. var tmp = obj.children("INS").clone();
  797. obj.html(val).prepend(tmp);
  798. this.__callback({ "obj" : obj, "name" : val });
  799. return true;
  800. }
  801. else {
  802. obj = obj.contents().filter(function() { return this.nodeType == 3; })[0];
  803. this.__callback({ "obj" : obj, "name" : val });
  804. return (obj.nodeValue = val);
  805. }
  806. },
  807. rename_node : function (obj, val) {
  808. obj = this._get_node(obj);
  809. this.__rollback();
  810. if(obj && obj.length && this.set_text.apply(this, Array.prototype.slice.call(arguments))) { this.__callback({ "obj" : obj, "name" : val }); }
  811. },
  812. // Basic operations: deleting nodes
  813. delete_node : function (obj) {
  814. obj = this._get_node(obj);
  815. if(!obj.length) { return false; }
  816. this.__rollback();
  817. var p = this._get_parent(obj), prev = $([]), t = this;
  818. obj.each(function () {
  819. prev = prev.add(t._get_prev(this));
  820. });
  821. obj = obj.detach();
  822. if(p !== -1 && p.find("> ul > li").length === 0) {
  823. p.removeClass("jstree-open jstree-closed").addClass("jstree-leaf");
  824. }
  825. this.clean_node(p);
  826. this.__callback({ "obj" : obj, "prev" : prev, "parent" : p });
  827. return obj;
  828. },
  829. prepare_move : function (o, r, pos, cb, is_cb) {
  830. var p = {};
  831. p.ot = $.jstree._reference(o) || this;
  832. p.o = p.ot._get_node(o);
  833. p.r = r === - 1 ? -1 : this._get_node(r);
  834. p.p = (typeof pos === "undefined" || pos === false) ? "last" : pos; // TODO: move to a setting
  835. if(!is_cb && prepared_move.o && prepared_move.o[0] === p.o[0] && prepared_move.r[0] === p.r[0] && prepared_move.p === p.p) {
  836. this.__callback(prepared_move);
  837. if(cb) { cb.call(this, prepared_move); }
  838. return;
  839. }
  840. p.ot = $.jstree._reference(p.o) || this;
  841. p.rt = $.jstree._reference(p.r) || this; // r === -1 ? p.ot : $.jstree._reference(p.r) || this
  842. if(p.r === -1 || !p.r) {
  843. p.cr = -1;
  844. switch(p.p) {
  845. case "first":
  846. case "before":
  847. case "inside":
  848. p.cp = 0;
  849. break;
  850. case "after":
  851. case "last":
  852. p.cp = p.rt.get_container().find(" > ul > li").length;
  853. break;
  854. default:
  855. p.cp = p.p;
  856. break;
  857. }
  858. }
  859. else {
  860. if(!/^(before|after)$/.test(p.p) && !this._is_loaded(p.r)) {
  861. return this.load_node(p.r, function () { this.prepare_move(o, r, pos, cb, true); });
  862. }
  863. switch(p.p) {
  864. case "before":
  865. p.cp = p.r.index();
  866. p.cr = p.rt._get_parent(p.r);
  867. break;
  868. case "after":
  869. p.cp = p.r.index() + 1;
  870. p.cr = p.rt._get_parent(p.r);
  871. break;
  872. case "inside":
  873. case "first":
  874. p.cp = 0;
  875. p.cr = p.r;
  876. break;
  877. case "last":
  878. p.cp = p.r.find(" > ul > li").length;
  879. p.cr = p.r;
  880. break;
  881. default:
  882. p.cp = p.p;
  883. p.cr = p.r;
  884. break;
  885. }
  886. }
  887. p.np = p.cr == -1 ? p.rt.get_container() : p.cr;
  888. p.op = p.ot._get_parent(p.o);
  889. p.cop = p.o.index();
  890. if(p.op === -1) { p.op = p.ot ? p.ot.get_container() : this.get_container(); }
  891. if(!/^(before|after)$/.test(p.p) && p.op && p.np && p.op[0] === p.np[0] && p.o.index() < p.cp) { p.cp++; }
  892. //if(p.p === "before" && p.op && p.np && p.op[0] === p.np[0] && p.o.index() < p.cp) { p.cp--; }
  893. p.or = p.np.find(" > ul > li:nth-child(" + (p.cp + 1) + ")");
  894. prepared_move = p;
  895. this.__callback(prepared_move);
  896. if(cb) { cb.call(this, prepared_move); }
  897. },
  898. check_move : function () {
  899. var obj = prepared_move, ret = true, r = obj.r === -1 ? this.get_container() : obj.r;
  900. if(!obj || !obj.o || obj.or[0] === obj.o[0]) { return false; }
  901. if(obj.op && obj.np && obj.op[0] === obj.np[0] && obj.cp - 1 === obj.o.index()) { return false; }
  902. obj.o.each(function () {
  903. if(r.parentsUntil(".jstree", "li").addBack().index(this) !== -1) { ret = false; return false; }
  904. });
  905. return ret;
  906. },
  907. move_node : function (obj, ref, position, is_copy, is_prepared, skip_check) {
  908. if(!is_prepared) {
  909. return this.prepare_move(obj, ref, position, function (p) {
  910. this.move_node(p, false, false, is_copy, true, skip_check);
  911. });
  912. }
  913. if(is_copy) {
  914. prepared_move.cy = true;
  915. }
  916. if(!skip_check && !this.check_move()) { return false; }
  917. this.__rollback();
  918. var o = false;
  919. if(is_copy) {
  920. o = obj.o.clone(true);
  921. o.find("*[id]").addBack().each(function () {
  922. if(this.id) { this.id = "copy_" + this.id; }
  923. });
  924. }
  925. else { o = obj.o; }
  926. if(obj.or.length) { obj.or.before(o); }
  927. else {
  928. if(!obj.np.children("ul").length) { $("<ul />").appendTo(obj.np); }
  929. obj.np.children("ul:eq(0)").append(o);
  930. }
  931. try {
  932. obj.ot.clean_node(obj.op);
  933. obj.rt.clean_node(obj.np);
  934. if(!obj.op.find("> ul > li").length) {
  935. obj.op.removeClass("jstree-open jstree-closed").addClass("jstree-leaf").children("ul").remove();
  936. }
  937. } catch (e) { }
  938. if(is_copy) {
  939. prepared_move.cy = true;
  940. prepared_move.oc = o;
  941. }
  942. this.__callback(prepared_move);
  943. return prepared_move;
  944. },
  945. _get_move : function () { return prepared_move; }
  946. }
  947. });
  948. })(jQuery);
  949. //*/
  950. /*
  951. * jsTree ui plugin
  952. * This plugins handles selecting/deselecting/hovering/dehovering nodes
  953. */
  954. (function ($) {
  955. var scrollbar_width, e1, e2;
  956. $(function() {
  957. if (/msie/.test(navigator.userAgent.toLowerCase())) {
  958. e1 = $('<textarea cols="10" rows="2"></textarea>').css({ position: 'absolute', top: -1000, left: 0 }).appendTo('body');
  959. e2 = $('<textarea cols="10" rows="2" style="overflow: hidden;"></textarea>').css({ position: 'absolute', top: -1000, left: 0 }).appendTo('body');
  960. scrollbar_width = e1.width() - e2.width();
  961. e1.add(e2).remove();
  962. }
  963. else {
  964. e1 = $('<div />').css({ width: 100, height: 100, overflow: 'auto', position: 'absolute', top: -1000, left: 0 })
  965. .prependTo('body').append('<div />').find('div').css({ width: '100%', height: 200 });
  966. scrollbar_width = 100 - e1.width();
  967. e1.parent().remove();
  968. }
  969. });
  970. $.jstree.plugin("ui", {
  971. __init : function () {
  972. this.data.ui.selected = $();
  973. this.data.ui.last_selected = false;
  974. this.data.ui.hovered = null;
  975. this.data.ui.to_select = this.get_settings().ui.initially_select;
  976. this.get_container()
  977. .delegate("a", "click.jstree", $.proxy(function (event) {
  978. event.preventDefault();
  979. event.currentTarget.blur();
  980. if(!$(event.currentTarget).hasClass("jstree-loading")) {
  981. this.select_node(event.currentTarget, true, event);
  982. }
  983. }, this))
  984. .delegate("a", "mouseenter.jstree", $.proxy(function (event) {
  985. if(!$(event.currentTarget).hasClass("jstree-loading")) {
  986. this.hover_node(event.target);
  987. }
  988. }, this))
  989. .delegate("a", "mouseleave.jstree", $.proxy(function (event) {
  990. if(!$(event.currentTarget).hasClass("jstree-loading")) {
  991. this.dehover_node(event.target);
  992. }
  993. }, this))
  994. .bind("reopen.jstree", $.proxy(function () {
  995. this.reselect();
  996. }, this))
  997. .bind("get_rollback.jstree", $.proxy(function () {
  998. this.dehover_node();
  999. this.save_selected();
  1000. }, this))
  1001. .bind("set_rollback.jstree", $.proxy(function () {
  1002. this.reselect();
  1003. }, this))
  1004. .bind("close_node.jstree", $.proxy(function (event, data) {
  1005. var s = this._get_settings().ui,
  1006. obj = this._get_node(data.rslt.obj),
  1007. clk = (obj && obj.length) ? obj.children("ul").find("a.jstree-clicked") : $(),
  1008. _this = this;
  1009. if(s.selected_parent_close === false || !clk.length) { return; }
  1010. clk.each(function () {
  1011. _this.deselect_node(this);
  1012. if(s.selected_parent_close === "select_parent") { _this.select_node(obj); }
  1013. });
  1014. }, this))
  1015. .bind("delete_node.jstree", $.proxy(function (event, data) {
  1016. var s = this._get_settings().ui.select_prev_on_delete,
  1017. obj = this._get_node(data.rslt.obj),
  1018. clk = (obj && obj.length) ? obj.find("a.jstree-clicked") : [],
  1019. _this = this;
  1020. clk.each(function () { _this.deselect_node(this); });
  1021. if(s && clk.length) {
  1022. data.rslt.prev.each(function () {
  1023. if(this.parentNode) { _this.select_node(this); return false; /* if return false is removed all prev nodes will be selected */}
  1024. });
  1025. }
  1026. }, this))
  1027. .bind("move_node.jstree", $.proxy(function (event, data) {
  1028. if(data.rslt.cy) {
  1029. data.rslt.oc.find("a.jstree-clicked").removeClass("jstree-clicked");
  1030. }
  1031. }, this));
  1032. },
  1033. defaults : {
  1034. select_limit : -1, // 0, 1, 2 ... or -1 for unlimited
  1035. select_multiple_modifier : "ctrl", // on, or ctrl, shift, alt
  1036. select_range_modifier : "shift",
  1037. selected_parent_close : "select_parent", // false, "deselect", "select_parent"
  1038. selected_parent_open : true,
  1039. select_prev_on_delete : true,
  1040. disable_selecting_children : false,
  1041. initially_select : []
  1042. },
  1043. _fn : {
  1044. _get_node : function (obj, allow_multiple) {
  1045. if(typeof obj === "undefined" || obj === null) { return allow_multiple ? this.data.ui.selected : this.data.ui.last_selected; }
  1046. var $obj = $(obj, this.get_container());
  1047. if($obj.is(".jstree") || obj == -1) { return -1; }
  1048. $obj = $obj.closest("li", this.get_container());
  1049. return $obj.length ? $obj : false;
  1050. },
  1051. _ui_notify : function (n, data) {
  1052. if(data.selected) {
  1053. this.select_node(n, false);
  1054. }
  1055. },
  1056. save_selected : function () {
  1057. var _this = this;
  1058. this.data.ui.to_select = [];
  1059. this.data.ui.selected.each(function () { if(this.id) { _this.data.ui.to_select.push("#" + this.id.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:")); } });
  1060. this.__callback(this.data.ui.to_select);
  1061. },
  1062. reselect : function () {
  1063. var _this = this,
  1064. s = this.data.ui.to_select;
  1065. s = $.map($.makeArray(s), function (n) { return "#" + n.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:"); });
  1066. // this.deselect_all(); WHY deselect, breaks plugin state notifier?
  1067. $.each(s, function (i, val) { if(val && val !== "#") { _this.select_node(val); } });
  1068. this.data.ui.selected = this.data.ui.selected.filter(function () { return this.parentNode; });
  1069. this.__callback();
  1070. },
  1071. refresh : function (obj) {
  1072. this.save_selected();
  1073. return this.__call_old();
  1074. },
  1075. hover_node : function (obj) {
  1076. obj = this._get_node(obj);
  1077. if(!obj.length) { return false; }
  1078. //if(this.data.ui.hovered && obj.get(0) === this.data.ui.hovered.get(0)) { return; }
  1079. if(!obj.hasClass("jstree-hovered")) { this.dehover_node(); }
  1080. this.data.ui.hovered = obj.children("a").addClass("jstree-hovered").parent();
  1081. this._fix_scroll(obj);
  1082. this.__callback({ "obj" : obj });
  1083. },
  1084. dehover_node : function () {
  1085. var obj = this.data.ui.hovered, p;
  1086. if(!obj || !obj.length) { return false; }
  1087. p = obj.children("a").removeClass("jstree-hovered").parent();
  1088. if(this.data.ui.hovered[0] === p[0]) { this.data.ui.hovered = null; }
  1089. this.__callback({ "obj" : obj });
  1090. },
  1091. select_node : function (obj, check, e) {
  1092. obj = this._get_node(obj);
  1093. if(obj == -1 || !obj || !obj.length) { return false; }
  1094. var s = this._get_settings().ui,
  1095. is_multiple = (s.select_multiple_modifier == "on" || (s.select_multiple_modifier !== false && e && e[s.select_multiple_modifier + "Key"])),
  1096. is_range = (s.select_range_modifier !== false && e && e[s.select_range_modifier + "Key"] && this.data.ui.last_selected && this.data.ui.last_selected[0] !== obj[0] && this.data.ui.last_selected.parent()[0] === obj.parent()[0]),
  1097. is_selected = this.is_selected(obj),
  1098. proceed = true,
  1099. t = this;
  1100. if(check) {
  1101. if(s.disable_selecting_children && is_multiple &&
  1102. (
  1103. (obj.parentsUntil(".jstree","li").children("a.jstree-clicked").length) ||
  1104. (obj.children("ul").find("a.jstree-clicked:eq(0)").length)
  1105. )
  1106. ) {
  1107. return false;
  1108. }
  1109. proceed = false;
  1110. switch(!0) {
  1111. case (is_range):
  1112. this.data.ui.last_selected.addClass("jstree-last-selected");
  1113. obj = obj[ obj.index() < this.data.ui.last_selected.index() ? "nextUntil" : "prevUntil" ](".jstree-last-selected").addBack();
  1114. if(s.select_limit == -1 || obj.length < s.select_limit) {
  1115. this.data.ui.last_selected.removeClass("jstree-last-selected");
  1116. this.data.ui.selected.each(function () {
  1117. if(this !== t.data.ui.last_selected[0]) { t.deselect_node(this); }
  1118. });
  1119. is_selected = false;
  1120. proceed = true;
  1121. }
  1122. else {
  1123. proceed = false;
  1124. }
  1125. break;
  1126. case (is_selected && !is_multiple):
  1127. this.deselect_all();
  1128. is_selected = false;
  1129. proceed = true;
  1130. break;
  1131. case (!is_selected && !is_multiple):
  1132. if(s.select_limit == -1 || s.select_limit > 0) {
  1133. this.deselect_all();
  1134. proceed = true;
  1135. }
  1136. break;
  1137. case (is_selected && is_multiple):
  1138. this.deselect_node(obj);
  1139. break;
  1140. case (!is_selected && is_multiple):
  1141. if(s.select_limit == -1 || this.data.ui.selected.length + 1 <= s.select_limit) {
  1142. proceed = true;
  1143. }
  1144. break;
  1145. }
  1146. }
  1147. if(proceed && !is_selected) {
  1148. if(!is_range) { this.data.ui.last_selected = obj; }
  1149. obj.children("a").addClass("jstree-clicked");
  1150. if(s.selected_parent_open) {
  1151. obj.parents(".jstree-closed").each(function () { t.open_node(this, false, true); });
  1152. }
  1153. this.data.ui.selected = this.data.ui.selected.add(obj);
  1154. this._fix_scroll(obj.eq(0));
  1155. this.__callback({ "obj" : obj, "e" : e });
  1156. }
  1157. },
  1158. _fix_scroll : function (obj) {
  1159. var c = this.get_container()[0], t;
  1160. if(c.scrollHeight > c.offsetHeight) {
  1161. obj = this._get_node(obj);
  1162. if(!obj || obj === -1 || !obj.length || !obj.is(":visible")) { return; }
  1163. t = obj.offset().top - this.get_container().offset().top;
  1164. if(t < 0) {
  1165. c.scrollTop = c.scrollTop + t - 1;
  1166. }
  1167. if(t + this.data.core.li_height + (c.scrollWidth > c.offsetWidth ? scrollbar_width : 0) > c.offsetHeight) {
  1168. c.scrollTop = c.scrollTop + (t - c.offsetHeight + this.data.core.li_height + 1 + (c.scrollWidth > c.offsetWidth ? scrollbar_width : 0));
  1169. }
  1170. }
  1171. },
  1172. deselect_node : function (obj) {
  1173. obj = this._get_node(obj);
  1174. if(!obj.length) { return false; }
  1175. if(this.is_selected(obj)) {
  1176. obj.children("a").removeClass("jstree-clicked");
  1177. this.data.ui.selected = this.data.ui.selected.not(obj);
  1178. if(this.data.ui.last_selected.get(0) === obj.get(0)) { this.data.ui.last_selected = this.data.ui.selected.eq(0); }
  1179. this.__callback({ "obj" : obj });
  1180. }
  1181. },
  1182. toggle_select : function (obj) {
  1183. obj = this._get_node(obj);
  1184. if(!obj.length) { return false; }
  1185. if(this.is_selected(obj)) { this.deselect_node(obj); }
  1186. else { this.select_node(obj); }
  1187. },
  1188. is_selected : function (obj) { return this.data.ui.selected.index(this._get_node(obj)) >= 0; },
  1189. get_selected : function (context) {
  1190. return context ? $(context).find("a.jstree-clicked").parent() : this.data.ui.selected;
  1191. },
  1192. deselect_all : function (context) {
  1193. var ret = context ? $(context).find("a.jstree-clicked").parent() : this.get_container().find("a.jstree-clicked").parent();
  1194. ret.children("a.jstree-clicked").removeClass("jstree-clicked");
  1195. this.data.ui.selected = $([]);
  1196. this.data.ui.last_selected = false;
  1197. this.__callback({ "obj" : ret });
  1198. }
  1199. }
  1200. });
  1201. // include the selection plugin by default
  1202. $.jstree.defaults.plugins.push("ui");
  1203. })(jQuery);
  1204. //*/
  1205. /*
  1206. * jsTree CRRM plugin
  1207. * Handles creating/renaming/removing/moving nodes by user interaction.
  1208. */
  1209. (function ($) {
  1210. $.jstree.plugin("crrm", {
  1211. __init : function () {
  1212. this.get_container()
  1213. .bind("move_node.jstree", $.proxy(function (e, data) {
  1214. if(this._get_settings().crrm.move.open_onmove) {
  1215. var t = this;
  1216. data.rslt.np.parentsUntil(".jstree").addBack().filter(".jstree-closed").each(function () {
  1217. t.open_node(this, false, true);
  1218. });
  1219. }
  1220. }, this));
  1221. },
  1222. defaults : {
  1223. input_width_limit : 200,
  1224. move : {
  1225. always_copy : false, // false, true or "multitree"
  1226. open_onmove : true,
  1227. default_position : "last",
  1228. check_move : function (m) { return true; }
  1229. }
  1230. },
  1231. _fn : {
  1232. _show_input : function (obj, callback) {
  1233. obj = this._get_node(obj);
  1234. var rtl = this._get_settings().core.rtl,
  1235. w = this._get_settings().crrm.input_width_limit,
  1236. w1 = obj.children("ins").width(),
  1237. w2 = obj.find("> a:visible > ins").width() * obj.find("> a:visible > ins").length,
  1238. t = this.get_text(obj),
  1239. h1 = $("<div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo("body"),
  1240. h2 = obj.css("position","relative").append(
  1241. $("<input />", {
  1242. "value" : t,
  1243. "class" : "jstree-rename-input",
  1244. // "size" : t.length,
  1245. "css" : {
  1246. "padding" : "0",
  1247. "border" : "1px solid silver",
  1248. "position" : "absolute",
  1249. "left" : (rtl ? "auto" : (w1 + w2 + 4) + "px"),
  1250. "right" : (rtl ? (w1 + w2 + 4) + "px" : "auto"),
  1251. "top" : "0px",
  1252. "height" : (this.data.core.li_height - 2) + "px",
  1253. "lineHeight" : (this.data.core.li_height - 2) + "px",
  1254. "width" : "150px" // will be set a bit further down
  1255. },
  1256. "blur" : $.proxy(function () {
  1257. var i = obj.children(".jstree-rename-input"),
  1258. v = i.val();
  1259. if(v === "") { v = t; }
  1260. h1.remove();
  1261. i.remove(); // rollback purposes
  1262. this.set_text(obj,t); // rollback purposes
  1263. this.rename_node(obj, v);
  1264. callback.call(this, obj, v, t);
  1265. obj.css("position","");
  1266. }, this),
  1267. "keyup" : function (event) {
  1268. var key = event.keyCode || event.which;
  1269. if(key == 27) { this.value = t; this.blur(); return; }
  1270. else if(key == 13) { this.blur(); return; }
  1271. else {
  1272. h2.width(Math.min(h1.text("pW" + this.value).width(),w));
  1273. }
  1274. },
  1275. "keypress" : function(event) {
  1276. var key = event.keyCode || event.which;
  1277. if(key == 13) { return false; }
  1278. }
  1279. })
  1280. ).children(".jstree-rename-input");
  1281. this.set_text(obj, "");
  1282. h1.css({
  1283. fontFamily : h2.css('fontFamily') || '',
  1284. fontSize : h2.css('fontSize') || '',
  1285. fontWeight : h2.css('fontWeight') || '',
  1286. fontStyle : h2.css('fontStyle') || '',
  1287. fontStretch : h2.css('fontStretch') || '',
  1288. fontVariant : h2.css('fontVariant') || '',
  1289. letterSpacing : h2.css('letterSpacing') || '',
  1290. wordSpacing : h2.css('wordSpacing') || ''
  1291. });
  1292. h2.width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
  1293. },
  1294. rename : function (obj) {
  1295. obj = this._get_node(obj);
  1296. this.__rollback();
  1297. var f = this.__callback;
  1298. this._show_input(obj, function (obj, new_name, old_name) {
  1299. f.call(this, { "obj" : obj, "new_name" : new_name, "old_name" : old_name });
  1300. });
  1301. },
  1302. create : function (obj, position, js, callback, skip_rename) {
  1303. var t, _this = this;
  1304. obj = this._get_node(obj);
  1305. if(!obj) { obj = -1; }
  1306. this.__rollback();
  1307. t = this.create_node(obj, position, js, function (t) {
  1308. var p = this._get_parent(t),
  1309. pos = $(t).index();
  1310. if(callback) { callback.call(this, t); }
  1311. if(p.length && p.hasClass("jstree-closed")) { this.open_node(p, false, true); }
  1312. if(!skip_rename) {
  1313. this._show_input(t, function (obj, new_name, old_name) {
  1314. _this.__callback({ "obj" : obj, "name" : new_name, "parent" : p, "position" : pos });
  1315. });
  1316. }
  1317. else { _this.__callback({ "obj" : t, "name" : this.get_text(t), "parent" : p, "position" : pos }); }
  1318. });
  1319. return t;
  1320. },
  1321. remove : function (obj) {
  1322. obj = this._get_node(obj, true);
  1323. var p = this._get_parent(obj), prev = this._get_prev(obj);
  1324. this.__rollback();
  1325. obj = this.delete_node(obj);
  1326. if(obj !== false) { this.__callback({ "obj" : obj, "prev" : prev, "parent" : p }); }
  1327. },
  1328. check_move : function () {
  1329. if(!this.__call_old()) { return false; }
  1330. var s = this._get_settings().crrm.move;
  1331. if(!s.check_move.call(this, this._get_move())) { return false; }
  1332. return true;
  1333. },
  1334. move_node : function (obj, ref, position, is_copy, is_prepared, skip_check) {
  1335. var s = this._get_settings().crrm.move;
  1336. if(!is_prepared) {
  1337. if(typeof position === "undefined") { position = s.default_position; }
  1338. if(position === "inside" && !s.default_position.match(/^(before|after)$/)) { position = s.default_position; }
  1339. return this.__call_old(true, obj, ref, position, is_copy, false, skip_check);
  1340. }
  1341. // if the move is already prepared
  1342. if(s.always_copy === true || (s.always_copy === "multitree" && obj.rt.get_index() !== obj.ot.get_index() )) {
  1343. is_copy = true;
  1344. }
  1345. this.__call_old(true, obj, ref, position, is_copy, true, skip_check);
  1346. },
  1347. cut : function (obj) {
  1348. obj = this._get_node(obj, true);
  1349. if(!obj || !obj.length) { return false; }
  1350. this.data.crrm.cp_nodes = false;
  1351. this.data.crrm.ct_nodes = obj;
  1352. this.__callback({ "obj" : obj });
  1353. },
  1354. copy : function (obj) {
  1355. obj = this._get_node(obj, true);
  1356. if(!obj || !obj.length) { return false; }
  1357. this.data.crrm.ct_nodes = false;
  1358. this.data.crrm.cp_nodes = obj;
  1359. this.__callback({ "obj" : obj });
  1360. },
  1361. paste : function (obj) {
  1362. obj = this._get_node(obj);
  1363. if(!obj || !obj.length) { return false; }
  1364. var nodes = this.data.crrm.ct_nodes ? this.data.crrm.ct_nodes : this.data.crrm.cp_nodes;
  1365. if(!this.data.crrm.ct_nodes && !this.data.crrm.cp_nodes) { return false; }
  1366. if(this.data.crrm.ct_nodes) { this.move_node(this.data.crrm.ct_nodes, obj); this.data.crrm.ct_nodes = false; }
  1367. if(this.data.crrm.cp_nodes) { this.move_node(this.data.crrm.cp_nodes, obj, false, true); }
  1368. this.__callback({ "obj" : obj, "nodes" : nodes });
  1369. }
  1370. }
  1371. });
  1372. // include the crr plugin by default
  1373. // $.jstree.defaults.plugins.push("crrm");
  1374. })(jQuery);
  1375. //*/
  1376. /*
  1377. * jsTree themes plugin
  1378. * Handles loading and setting themes, as well as detecting path to themes, etc.
  1379. */
  1380. (function ($) {
  1381. var themes_loaded = [];
  1382. // this variable stores the path to the themes folder - if left as false - it will be autodetected
  1383. $.jstree._themes = false;
  1384. $.jstree.plugin("themes", {
  1385. __init : function () {
  1386. this.get_container()
  1387. .bind("init.jstree", $.proxy(function () {
  1388. var s = this._get_settings().themes;
  1389. this.data.themes.dots = s.dots;
  1390. this.data.themes.icons = s.icons;
  1391. this.set_theme(s.theme, s.url);
  1392. }, this))
  1393. .bind("loaded.jstree", $.proxy(function () {
  1394. // bound here too, as simple HTML tree's won't honor dots & icons otherwise
  1395. if(!this.data.themes.dots) { this.hide_dots(); }
  1396. else { this.show_dots(); }
  1397. if(!this.data.themes.icons) { this.hide_icons(); }
  1398. else { this.show_icons(); }
  1399. }, this));
  1400. },
  1401. defaults : {
  1402. theme : "default",
  1403. url : false,
  1404. dots : false,
  1405. icons : true
  1406. },
  1407. _fn : {
  1408. set_theme : function (theme_name, theme_url) {
  1409. if(!theme_name) { return false; }
  1410. if(!theme_url) { theme_url = $.jstree._themes + theme_name + '/style.css'; }
  1411. if($.inArray(theme_url, themes_loaded) == -1) {
  1412. // $.vakata.css.add_sheet({ "url" : theme_url });
  1413. themes_loaded.push(theme_url);
  1414. }
  1415. if(this.data.themes.theme != theme_name) {
  1416. this.get_container().removeClass('jstree-' + this.data.themes.theme);
  1417. this.data.themes.theme = theme_name;
  1418. }
  1419. this.get_container().addClass('jstree-' + theme_name);
  1420. if(!this.data.themes.dots) { this.hide_dots(); }
  1421. else { this.show_dots(); }
  1422. if(!this.data.themes.icons) { this.hide_icons(); }
  1423. else { this.show_icons(); }
  1424. this.__callback();
  1425. },
  1426. get_theme : function () { return this.data.themes.theme; },
  1427. show_dots : function () { this.data.themes.dots = true; this.get_container().children("ul").removeClass("jstree-no-dots"); },
  1428. hide_dots : function () { this.data.themes.dots = false; this.get_container().children("ul").addClass("jstree-no-dots"); },
  1429. toggle_dots : function () { if(this.data.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
  1430. show_icons : function () { this.data.themes.icons = true; this.get_container().children("ul").removeClass("jstree-no-icons"); },
  1431. hide_icons : function () { this.data.themes.icons = false; this.get_container().children("ul").addClass("jstree-no-icons"); },
  1432. toggle_icons: function () { if(this.data.themes.icons) { this.hide_icons(); } else { this.show_icons(); } }
  1433. }
  1434. });
  1435. // autodetect themes path
  1436. $(function () {
  1437. if($.jstree._themes === false) {
  1438. $("script").each(function () {
  1439. if(this.src.toString().match(/jquery\.jstree[^\/]*?\.js(\?.*)?$/)) {
  1440. $.jstree._themes = this.src.toString().replace(/jquery\.jstree[^\/]*?\.js(\?.*)?$/, "") + 'themes/';
  1441. return false;
  1442. }
  1443. });
  1444. }
  1445. if($.jstree._themes === false) { $.jstree._themes = "themes/"; }
  1446. });
  1447. // include the themes plugin by default
  1448. $.jstree.defaults.plugins.push("themes");
  1449. })(jQuery);
  1450. //*/
  1451. /*
  1452. * jsTree hotkeys plugin
  1453. * Enables keyboard navigation for all tree instances
  1454. * Depends on the jstree ui & jquery hotkeys plugins
  1455. */
  1456. (function ($) {
  1457. var bound = [];
  1458. function exec(i, event) {
  1459. var f = $.jstree._focused(), tmp;
  1460. if(f && f.data && f.data.hotkeys && f.data.hotkeys.enabled) {
  1461. tmp = f._get_settings().hotkeys[i];
  1462. if(tmp) { return tmp.call(f, event); }
  1463. }
  1464. }
  1465. $.jstree.plugin("hotkeys", {
  1466. __init : function () {
  1467. if(typeof $.hotkeys === "undefined") { throw "jsTree hotkeys: jQuery hotkeys plugin not included."; }
  1468. if(!this.data.ui) { throw "jsTree hotkeys: jsTree UI plugin not included."; }
  1469. $.each(this._get_settings().hotkeys, function (i, v) {
  1470. if(v !== false && $.inArray(i, bound) == -1) {
  1471. $(document).bind("keydown", i, function (event) { return exec(i, event); });
  1472. bound.push(i);
  1473. }
  1474. });
  1475. this.get_container()
  1476. .bind("lock.jstree", $.proxy(function () {
  1477. if(this.data.hotkeys.enabled) { this.data.hotkeys.enabled = false; this.data.hotkeys.revert = true; }
  1478. }, this))
  1479. .bind("unlock.jstree", $.proxy(function () {
  1480. if(this.data.hotkeys.revert) { this.data.hotkeys.enabled = true; }
  1481. }, this));
  1482. this.enable_hotkeys();
  1483. },
  1484. defaults : {
  1485. "up" : function () {
  1486. var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
  1487. this.hover_node(this._get_prev(o));
  1488. return false;
  1489. },
  1490. "ctrl+up" : function () {
  1491. var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
  1492. this.hover_node(this._get_prev(o));
  1493. return false;
  1494. },
  1495. "shift+up" : function () {
  1496. var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
  1497. this.hover_node(this._get_prev(o));
  1498. return false;
  1499. },
  1500. "down" : function () {
  1501. var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
  1502. this.hover_node(this._get_next(o));
  1503. return false;
  1504. },
  1505. "ctrl+down" : function () {
  1506. var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
  1507. this.hover_node(this._get_next(o));
  1508. return false;
  1509. },
  1510. "shift+down" : function () {
  1511. var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
  1512. this.hover_node(this._get_next(o));
  1513. return false;
  1514. },
  1515. "left" : function () {
  1516. var o = this.data.ui.hovered || this.data.ui.last_selected;
  1517. if(o) {
  1518. if(o.hasClass("jstree-open")) { this.close_node(o); }
  1519. else { this.hover_node(this._get_prev(o)); }
  1520. }
  1521. return false;
  1522. },
  1523. "ctrl+left" : function () {
  1524. var o = this.data.ui.hovered || this.data.ui.last_selected;
  1525. if(o) {
  1526. if(o.hasClass("jstree-open")) { this.close_node(o); }
  1527. else { this.hover_node(this._get_prev(o)); }
  1528. }
  1529. return false;
  1530. },
  1531. "shift+left" : function () {
  1532. var o = this.data.ui.hovered || this.data.ui.last_selected;
  1533. if(o) {
  1534. if(o.hasClass("jstree-open")) { this.close_node(o); }
  1535. else { this.hover_node(this._get_prev(o)); }
  1536. }
  1537. return false;
  1538. },
  1539. "right" : function () {
  1540. var o = this.data.ui.hovered || this.data.ui.last_selected;
  1541. if(o && o.length) {
  1542. if(o.hasClass("jstree-closed")) { this.open_node(o); }
  1543. else { this.hover_node(this._get_next(o)); }
  1544. }
  1545. return false;
  1546. },
  1547. "ctrl+right" : function () {
  1548. var o = this.data.ui.hovered || this.data.ui.last_selected;
  1549. if(o && o.length) {
  1550. if(o.hasClass("jstree-closed")) { this.open_node(o); }
  1551. else { this.hover_node(this._get_next(o)); }
  1552. }
  1553. return false;
  1554. },
  1555. "shift+right" : function () {
  1556. var o = this.data.ui.hovered || this.data.ui.last_selected;
  1557. if(o && o.length) {
  1558. if(o.hasClass("jstree-closed")) { this.open_node(o); }
  1559. else { this.hover_node(this._get_next(o)); }
  1560. }
  1561. return false;
  1562. },
  1563. "space" : function () {
  1564. if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").click(); }
  1565. return false;
  1566. },
  1567. "ctrl+space" : function (event) {
  1568. event.type = "click";
  1569. if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").trigger(event); }
  1570. return false;
  1571. },
  1572. "shift+space" : function (event) {
  1573. event.type = "click";
  1574. if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").trigger(event); }
  1575. return false;
  1576. },
  1577. "f2" : function () { this.rename(this.data.ui.hovered || this.data.ui.last_selected); },
  1578. "del" : function () { this.remove(this.data.ui.hovered || this._get_node(null)); }
  1579. },
  1580. _fn : {
  1581. enable_hotkeys : function () {
  1582. this.data.hotkeys.enabled = true;
  1583. },
  1584. disable_hotkeys : function () {
  1585. this.data.hotkeys.enabled = false;
  1586. }
  1587. }
  1588. });
  1589. })(jQuery);
  1590. //*/
  1591. /*
  1592. * jsTree JSON plugin
  1593. * The JSON data store. Datastores are build by overriding the `load_node` and `_is_loaded` functions.
  1594. */
  1595. (function ($) {
  1596. $.jstree.plugin("json_data", {
  1597. __init : function() {
  1598. var s = this._get_settings().json_data;
  1599. if(s.progressive_unload) {
  1600. this.get_container().bind("after_close.jstree", function (e, data) {
  1601. data.rslt.obj.children("ul").remove();
  1602. });
  1603. }
  1604. },
  1605. defaults : {
  1606. // `data` can be a function:
  1607. // * accepts two arguments - node being loaded and a callback to pass the result to
  1608. // * will be executed in the current tree's scope & ajax won't be supported
  1609. data : false,
  1610. ajax : false,
  1611. correct_state : true,
  1612. progressive_render : false,
  1613. progressive_unload : false
  1614. },
  1615. _fn : {
  1616. load_node : function (obj, s_call, e_call) { var _this = this; this.load_node_json(obj, function () { _this.__callback({ "obj" : _this._get_node(obj) }); s_call.call(this); }, e_call); },
  1617. _is_loaded : function (obj) {
  1618. var s = this._get_settings().json_data;
  1619. obj = this._get_node(obj);
  1620. return obj == -1 || !obj || (!s.ajax && !s.progressive_render && !$.isFunction(s.data)) || obj.is(".jstree-open, .jstree-leaf") || obj.children("ul").children("li").length > 0;
  1621. },
  1622. refresh : function (obj) {
  1623. obj = this._get_node(obj);
  1624. var s = this._get_settings().json_data;
  1625. if(obj && obj !== -1 && s.progressive_unload && ($.isFunction(s.data) || !!s.ajax)) {
  1626. obj.removeData("jstree_children");
  1627. }
  1628. return this.__call_old();
  1629. },
  1630. load_node_json : function (obj, s_call, e_call) {
  1631. var s = this.get_settings().json_data, d,
  1632. error_func = function () {},
  1633. success_func = function () {};
  1634. obj = this._get_node(obj);
  1635. if(obj && obj !== -1 && (s.progressive_render || s.progressive_unload) && !obj.is(".jstree-open, .jstree-leaf") && obj.children("ul").children("li").length === 0 && obj.data("jstree_children")) {
  1636. d = this._parse_json(obj.data("jstree_children"), obj);
  1637. if(d) {
  1638. obj.append(d);
  1639. if(!s.progressive_unload) { obj.removeData("jstree_children"); }
  1640. }
  1641. this.clean_node(obj);
  1642. if(s_call) { s_call.call(this); }
  1643. return;
  1644. }
  1645. if(obj && obj !== -1) {
  1646. if(obj.data("jstree_is_loading")) { return; }
  1647. else { obj.data("jstree_is_loading",true); }
  1648. }
  1649. switch(!0) {
  1650. case (!s.data && !s.ajax): throw "Neither data nor ajax settings supplied.";
  1651. // function option added here for easier model integration (also supporting async - see callback)
  1652. case ($.isFunction(s.data)):
  1653. s.data.call(this, obj, $.proxy(function (d) {
  1654. d = this._parse_json(d, obj);
  1655. if(!d) {
  1656. if(obj === -1 || !obj) {
  1657. if(s.correct_state) { this.get_container().children("ul").empty(); }
  1658. }
  1659. else {
  1660. obj.children("a.jstree-loading").removeClass("jstree-loading");
  1661. obj.removeData("jstree_is_loading");
  1662. if(s.correct_state) { this.correct_state(obj); }
  1663. }
  1664. if(e_call) { e_call.call(this); }
  1665. }
  1666. else {
  1667. if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); }
  1668. else { obj.append(d).children("a.jstree-loading").removeClass("jstree-loading"); obj.removeData("jstree_is_loading"); }
  1669. this.clean_node(obj);
  1670. if(s_call) { s_call.call(this); }
  1671. }
  1672. }, this));
  1673. break;
  1674. case (!!s.data && !s.ajax) || (!!s.data && !!s.ajax && (!obj || obj === -1)):
  1675. if(!obj || obj == -1) {
  1676. d = this._parse_json(s.data, obj);
  1677. if(d) {
  1678. this.get_container().children("ul").empty().append(d.children());
  1679. this.clean_node();
  1680. }
  1681. else {
  1682. if(s.correct_state) { this.get_container().children("ul").empty(); }
  1683. }
  1684. }
  1685. if(s_call) { s_call.call(this); }
  1686. break;
  1687. case (!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj && obj !== -1):
  1688. error_func = function (x, t, e) {
  1689. var ef = this.get_settings().json_data.ajax.error;
  1690. if(ef) { ef.call(this, x, t, e); }
  1691. if(obj != -1 && obj.length) {
  1692. obj.children("a.jstree-loading").removeClass("jstree-loading");
  1693. obj.removeData("jstree_is_loading");
  1694. if(t === "success" && s.correct_state) { this.correct_state(obj); }
  1695. }
  1696. else {
  1697. if(t === "success" && s.correct_state) { this.get_container().children("ul").empty(); }
  1698. }
  1699. if(e_call) { e_call.call(this); }
  1700. };
  1701. success_func = function (d, t, x) {
  1702. var sf = this.get_settings().json_data.ajax.success;
  1703. if(sf) { d = sf.call(this,d,t,x) || d; }
  1704. if(d === "" || (d && d.toString && d.toString().replace(/^[\s\n]+$/,"") === "") || (!$.isArray(d) && !$.isPlainObject(d))) {
  1705. return error_func.call(this, x, t, "");
  1706. }
  1707. d = this._parse_json(d, obj);
  1708. if(d) {
  1709. if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); }
  1710. else { obj.append(d).children("a.jstree-loading").removeClass("jstree-loading"); obj.removeData("jstree_is_loading"); }
  1711. this.clean_node(obj);
  1712. if(s_call) { s_call.call(this); }
  1713. }
  1714. else {
  1715. if(obj === -1 || !obj) {
  1716. if(s.correct_state) {
  1717. this.get_container().children("ul").empty();
  1718. if(s_call) { s_call.call(this); }
  1719. }
  1720. }
  1721. else {
  1722. obj.children("a.jstree-loading").removeClass("jstree-loading");
  1723. obj.removeData("jstree_is_loading");
  1724. if(s.correct_state) {
  1725. this.correct_state(obj);
  1726. if(s_call) { s_call.call(this); }
  1727. }
  1728. }
  1729. }
  1730. };
  1731. s.ajax.context = this;
  1732. s.ajax.error = error_func;
  1733. s.ajax.success = success_func;
  1734. if(!s.ajax.dataType) { s.ajax.dataType = "json"; }
  1735. if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); }
  1736. if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); }
  1737. $.ajax(s.ajax);
  1738. break;
  1739. }
  1740. },
  1741. _parse_json : function (js, obj, is_callback) {
  1742. var d = false,
  1743. p = this._get_settings(),
  1744. s = p.json_data,
  1745. t = p.core.html_titles,
  1746. tmp, i, j, ul1, ul2;
  1747. if(!js) { return d; }
  1748. if(s.progressive_unload && obj && obj !== -1) {
  1749. obj.data("jstree_children", d);
  1750. }
  1751. if($.isArray(js)) {
  1752. d = $();
  1753. if(!js.length) { return false; }
  1754. for(i = 0, j = js.length; i < j; i++) {
  1755. tmp = this._parse_json(js[i], obj, true);
  1756. if(tmp.length) { d = d.add(tmp); }
  1757. }
  1758. }
  1759. else {
  1760. if(typeof js == "string") { js = { data : js }; }
  1761. if(!js.data && js.data !== "") { return d; }
  1762. d = $("<li />");
  1763. if(js.attr) { d.attr(js.attr); }
  1764. if(js.metadata) { d.data(js.metadata); }
  1765. if(js.state) { d.addClass("jstree-" + js.state); }
  1766. if(!$.isArray(js.data)) { tmp = js.data; js.data = []; js.data.push(tmp); }
  1767. $.each(js.data, function (i, m) {
  1768. tmp = $("<a />");
  1769. if($.isFunction(m)) { m = m.call(this, js); }
  1770. if(typeof m == "string") { tmp.attr('href','#')[ t ? "html" : "text" ](m); }
  1771. else {
  1772. if(!m.attr) { m.attr = {}; }
  1773. if(!m.attr.href) { m.attr.href = '#'; }
  1774. tmp.attr(m.attr)[ t ? "html" : "text" ](m.title);
  1775. if(m.language) { tmp.addClass(m.language); }
  1776. }
  1777. tmp.prepend("<ins class='jstree-icon'>&#160;</ins>");
  1778. if(!m.icon && js.icon) { m.icon = js.icon; }
  1779. if(m.icon) {
  1780. if(m.icon.indexOf("/") === -1) { tmp.children("ins").addClass(m.icon); }
  1781. else { tmp.children("ins").css("background","url('" + m.icon + "') center center no-repeat"); }
  1782. }
  1783. d.append(tmp);
  1784. });
  1785. d.prepend("<ins class='jstree-icon'>&#160;</ins>");
  1786. if(js.children) {
  1787. if(s.progressive_render && js.state !== "open") {
  1788. d.addClass("jstree-closed").data("jstree_children", js.children);
  1789. }
  1790. else {
  1791. if(s.progressive_unload) { d.data("jstree_children", js.children); }
  1792. if($.isArray(js.children) && js.children.length) {
  1793. tmp = this._parse_json(js.children, obj, true);
  1794. if(tmp.length) {
  1795. ul2 = $("<ul />");
  1796. ul2.append(tmp);
  1797. d.append(ul2);
  1798. }
  1799. }
  1800. }
  1801. }
  1802. }
  1803. if(!is_callback) {
  1804. ul1 = $("<ul />");
  1805. ul1.append(d);
  1806. d = ul1;
  1807. }
  1808. return d;
  1809. },
  1810. get_json : function (obj, li_attr, a_attr, is_callback) {
  1811. var result = [],
  1812. s = this._get_settings(),
  1813. _this = this,
  1814. tmp1, tmp2, li, a, t, lang;
  1815. obj = this._get_node(obj);
  1816. if(!obj || obj === -1) { obj = this.get_container().find("> ul > li"); }
  1817. li_attr = $.isArray(li_attr) ? li_attr : [ "id", "class" ];
  1818. if(!is_callback && this.data.types) { li_attr.push(s.types.type_attr); }
  1819. a_attr = $.isArray(a_attr) ? a_attr : [ ];
  1820. obj.each(function () {
  1821. li = $(this);
  1822. tmp1 = { data : [] };
  1823. if(li_attr.length) { tmp1.attr = { }; }
  1824. $.each(li_attr, function (i, v) {
  1825. tmp2 = li.attr(v);
  1826. if(tmp2 && tmp2.length && tmp2.replace(/jstree[^ ]*/ig,'').length) {
  1827. tmp1.attr[v] = (" " + tmp2).replace(/ jstree[^ ]*/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,"");
  1828. }
  1829. });
  1830. if(li.hasClass("jstree-open")) { tmp1.state = "open"; }
  1831. if(li.hasClass("jstree-closed")) { tmp1.state = "closed"; }
  1832. if(li.data()) { tmp1.metadata = li.data(); }
  1833. a = li.children("a");
  1834. a.each(function () {
  1835. t = $(this);
  1836. if(
  1837. a_attr.length ||
  1838. $.inArray("languages", s.plugins) !== -1 ||
  1839. t.children("ins").get(0).style.backgroundImage.length ||
  1840. (t.children("ins").get(0).className && t.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').length)
  1841. ) {
  1842. lang = false;
  1843. if($.inArray("languages", s.plugins) !== -1 && $.isArray(s.languages) && s.languages.length) {
  1844. $.each(s.languages, function (l, lv) {
  1845. if(t.hasClass(lv)) {
  1846. lang = lv;
  1847. return false;
  1848. }
  1849. });
  1850. }
  1851. tmp2 = { attr : { }, title : _this.get_text(t, lang) };
  1852. $.each(a_attr, function (k, z) {
  1853. tmp2.attr[z] = (" " + (t.attr(z) || "")).replace(/ jstree[^ ]*/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,"");
  1854. });
  1855. if($.inArray("languages", s.plugins) !== -1 && $.isArray(s.languages) && s.languages.length) {
  1856. $.each(s.languages, function (k, z) {
  1857. if(t.hasClass(z)) { tmp2.language = z; return true; }
  1858. });
  1859. }
  1860. if(t.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/^\s+$/ig,"").length) {
  1861. tmp2.icon = t.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,"");
  1862. }
  1863. if(t.children("ins").get(0).style.backgroundImage.length) {
  1864. tmp2.icon = t.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")","");
  1865. }
  1866. }
  1867. else {
  1868. tmp2 = _this.get_text(t);
  1869. }
  1870. if(a.length > 1) { tmp1.data.push(tmp2); }
  1871. else { tmp1.data = tmp2; }
  1872. });
  1873. li = li.find("> ul > li");
  1874. if(li.length) { tmp1.children = _this.get_json(li, li_attr, a_attr, true); }
  1875. result.push(tmp1);
  1876. });
  1877. return result;
  1878. }
  1879. }
  1880. });
  1881. })(jQuery);
  1882. //*/
  1883. /*
  1884. * jsTree languages plugin
  1885. * Adds support for multiple language versions in one tree
  1886. * This basically allows for many titles coexisting in one node, but only one of them being visible at any given time
  1887. * This is useful for maintaining the same structure in many languages (hence the name of the plugin)
  1888. */
  1889. (function ($) {
  1890. $.jstree.plugin("languages", {
  1891. __init : function () { this._load_css(); },
  1892. defaults : [],
  1893. _fn : {
  1894. set_lang : function (i) {
  1895. var langs = this._get_settings().languages,
  1896. st = false,
  1897. selector = ".jstree-" + this.get_index() + ' a';
  1898. if(!$.isArray(langs) || langs.length === 0) { return false; }
  1899. if($.inArray(i,langs) == -1) {
  1900. if(!!langs[i]) { i = langs[i]; }
  1901. else { return false; }
  1902. }
  1903. if(i == this.data.languages.current_language) { return true; }
  1904. st = $.vakata.css.get_css(selector + "." + this.data.languages.current_language, false, this.data.languages.language_css);
  1905. if(st !== false) { st.style.display = "none"; }
  1906. st = $.vakata.css.get_css(selector + "." + i, false, this.data.languages.language_css);
  1907. if(st !== false) { st.style.display = ""; }
  1908. this.data.languages.current_language = i;
  1909. this.__callback(i);
  1910. return true;
  1911. },
  1912. get_lang : function () {
  1913. return this.data.languages.current_language;
  1914. },
  1915. _get_string : function (key, lang) {
  1916. var langs = this._get_settings().languages,
  1917. s = this._get_settings().core.strings;
  1918. if($.isArray(langs) && langs.length) {
  1919. lang = (lang && $.inArray(lang,langs) != -1) ? lang : this.data.languages.current_language;
  1920. }
  1921. if(s[lang] && s[lang][key]) { return s[lang][key]; }
  1922. if(s[key]) { return s[key]; }
  1923. return key;
  1924. },
  1925. get_text : function (obj, lang) {
  1926. obj = this._get_node(obj) || this.data.ui.last_selected;
  1927. if(!obj.size()) { return false; }
  1928. var langs = this._get_settings().languages,
  1929. s = this._get_settings().core.html_titles;
  1930. if($.isArray(langs) && langs.length) {
  1931. lang = (lang && $.inArray(lang,langs) != -1) ? lang : this.data.languages.current_language;
  1932. obj = obj.children("a." + lang);
  1933. }
  1934. else { obj = obj.children("a:eq(0)"); }
  1935. if(s) {
  1936. obj = obj.clone();
  1937. obj.children("INS").remove();
  1938. return obj.html();
  1939. }
  1940. else {
  1941. obj = obj.contents().filter(function() { return this.nodeType == 3; })[0];
  1942. return obj.nodeValue;
  1943. }
  1944. },
  1945. set_text : function (obj, val, lang) {
  1946. obj = this._get_node(obj) || this.data.ui.last_selected;
  1947. if(!obj.size()) { return false; }
  1948. var langs = this._get_settings().languages,
  1949. s = this._get_settings().core.html_titles,
  1950. tmp;
  1951. if($.isArray(langs) && langs.length) {
  1952. lang = (lang && $.inArray(lang,langs) != -1) ? lang : this.data.languages.current_language;
  1953. obj = obj.children("a." + lang);
  1954. }
  1955. else { obj = obj.children("a:eq(0)"); }
  1956. if(s) {
  1957. tmp = obj.children("INS").clone();
  1958. obj.html(val).prepend(tmp);
  1959. this.__callback({ "obj" : obj, "name" : val, "lang" : lang });
  1960. return true;
  1961. }
  1962. else {
  1963. obj = obj.contents().filter(function() { return this.nodeType == 3; })[0];
  1964. this.__callback({ "obj" : obj, "name" : val, "lang" : lang });
  1965. return (obj.nodeValue = val);
  1966. }
  1967. },
  1968. _load_css : function () {
  1969. var langs = this._get_settings().languages,
  1970. str = "/* languages css */",
  1971. selector = ".jstree-" + this.get_index() + ' a',
  1972. ln;
  1973. if($.isArray(langs) && langs.length) {
  1974. this.data.languages.current_language = langs[0];
  1975. for(ln = 0; ln < langs.length; ln++) {
  1976. str += selector + "." + langs[ln] + " {";
  1977. if(langs[ln] != this.data.languages.current_language) { str += " display:none; "; }
  1978. str += " } ";
  1979. }
  1980. this.data.languages.language_css = $.vakata.css.add_sheet({ 'str' : str, 'title' : "jstree-languages" });
  1981. }
  1982. },
  1983. create_node : function (obj, position, js, callback) {
  1984. var t = this.__call_old(true, obj, position, js, function (t) {
  1985. var langs = this._get_settings().languages,
  1986. a = t.children("a"),
  1987. ln;
  1988. if($.isArray(langs) && langs.length) {
  1989. for(ln = 0; ln < langs.length; ln++) {
  1990. if(!a.is("." + langs[ln])) {
  1991. t.append(a.eq(0).clone().removeClass(langs.join(" ")).addClass(langs[ln]));
  1992. }
  1993. }
  1994. a.not("." + langs.join(", .")).remove();
  1995. }
  1996. if(callback) { callback.call(this, t); }
  1997. });
  1998. return t;
  1999. }
  2000. }
  2001. });
  2002. })(jQuery);
  2003. //*/
  2004. /*
  2005. * jsTree cookies plugin
  2006. * Stores the currently opened/selected nodes in a cookie and then restores them
  2007. * Depends on the jquery.cookie plugin
  2008. */
  2009. (function ($) {
  2010. $.jstree.plugin("cookies", {
  2011. __init : function () {
  2012. if(typeof $.cookie === "undefined") { throw "jsTree cookie: jQuery cookie plugin not included."; }
  2013. var s = this._get_settings().cookies,
  2014. tmp;
  2015. if(!!s.save_loaded) {
  2016. tmp = $.cookie(s.save_loaded);
  2017. if(tmp && tmp.length) { this.data.core.to_load = tmp.split(","); }
  2018. }
  2019. if(!!s.save_opened) {
  2020. tmp = $.cookie(s.save_opened);
  2021. if(tmp && tmp.length) { this.data.core.to_open = tmp.split(","); }
  2022. }
  2023. if(!!s.save_selected) {
  2024. tmp = $.cookie(s.save_selected);
  2025. if(tmp && tmp.length && this.data.ui) { this.data.ui.to_select = tmp.split(","); }
  2026. }
  2027. this.get_container()
  2028. .one( ( this.data.ui ? "reselect" : "reopen" ) + ".jstree", $.proxy(function () {
  2029. this.get_container()
  2030. .bind("open_node.jstree close_node.jstree select_node.jstree deselect_node.jstree", $.proxy(function (e) {
  2031. if(this._get_settings().cookies.auto_save) { this.save_cookie((e.handleObj.namespace + e.handleObj.type).replace("jstree","")); }
  2032. }, this));
  2033. }, this));
  2034. },
  2035. defaults : {
  2036. save_loaded : "jstree_load",
  2037. save_opened : "jstree_open",
  2038. save_selected : "jstree_select",
  2039. auto_save : true,
  2040. cookie_options : {}
  2041. },
  2042. _fn : {
  2043. save_cookie : function (c) {
  2044. if(this.data.core.refreshing) { return; }
  2045. var s = this._get_settings().cookies;
  2046. if(!c) { // if called manually and not by event
  2047. if(s.save_loaded) {
  2048. this.save_loaded();
  2049. $.cookie(s.save_loaded, this.data.core.to_load.join(","), s.cookie_options);
  2050. }
  2051. if(s.save_opened) {
  2052. this.save_opened();
  2053. $.cookie(s.save_opened, this.data.core.to_open.join(","), s.cookie_options);
  2054. }
  2055. if(s.save_selected && this.data.ui) {
  2056. this.save_selected();
  2057. $.cookie(s.save_selected, this.data.ui.to_select.join(","), s.cookie_options);
  2058. }
  2059. return;
  2060. }
  2061. switch(c) {
  2062. case "open_node":
  2063. case "close_node":
  2064. if(!!s.save_opened) {
  2065. this.save_opened();
  2066. $.cookie(s.save_opened, this.data.core.to_open.join(","), s.cookie_options);
  2067. }
  2068. if(!!s.save_loaded) {
  2069. this.save_loaded();
  2070. $.cookie(s.save_loaded, this.data.core.to_load.join(","), s.cookie_options);
  2071. }
  2072. break;
  2073. case "select_node":
  2074. case "deselect_node":
  2075. if(!!s.save_selected && this.data.ui) {
  2076. this.save_selected();
  2077. $.cookie(s.save_selected, this.data.ui.to_select.join(","), s.cookie_options);
  2078. }
  2079. break;
  2080. }
  2081. }
  2082. }
  2083. });
  2084. // include cookies by default
  2085. // $.jstree.defaults.plugins.push("cookies");
  2086. })(jQuery);
  2087. //*/
  2088. /*
  2089. * jsTree sort plugin
  2090. * Sorts items alphabetically (or using any other function)
  2091. */
  2092. (function ($) {
  2093. $.jstree.plugin("sort", {
  2094. __init : function () {
  2095. this.get_container()
  2096. .bind("load_node.jstree", $.proxy(function (e, data) {
  2097. var obj = this._get_node(data.rslt.obj);
  2098. obj = obj === -1 ? this.get_container().children("ul") : obj.children("ul");
  2099. this.sort(obj);
  2100. }, this))
  2101. .bind("rename_node.jstree create_node.jstree create.jstree", $.proxy(function (e, data) {
  2102. this.sort(data.rslt.obj.parent());
  2103. }, this))
  2104. .bind("move_node.jstree", $.proxy(function (e, data) {
  2105. var m = data.rslt.np == -1 ? this.get_container() : data.rslt.np;
  2106. this.sort(m.children("ul"));
  2107. }, this));
  2108. },
  2109. defaults : function (a, b) { return this.get_text(a) > this.get_text(b) ? 1 : -1; },
  2110. _fn : {
  2111. sort : function (obj) {
  2112. var s = this._get_settings().sort,
  2113. t = this;
  2114. obj.append($.makeArray(obj.children("li")).sort($.proxy(s, t)));
  2115. obj.find("> li > ul").each(function() { t.sort($(this)); });
  2116. this.clean_node(obj);
  2117. }
  2118. }
  2119. });
  2120. })(jQuery);
  2121. //*/
  2122. /*
  2123. * jsTree DND plugin
  2124. * Drag and drop plugin for moving/copying nodes
  2125. */
  2126. (function ($) {
  2127. var o = false,
  2128. r = false,
  2129. m = false,
  2130. ml = false,
  2131. sli = false,
  2132. sti = false,
  2133. dir1 = false,
  2134. dir2 = false,
  2135. last_pos = false;
  2136. $.vakata.dnd = {
  2137. is_down : false,
  2138. is_drag : false,
  2139. helper : false,
  2140. scroll_spd : 10,
  2141. init_x : 0,
  2142. init_y : 0,
  2143. threshold : 5,
  2144. helper_left : 5,
  2145. helper_top : 10,
  2146. user_data : {},
  2147. drag_start : function (e, data, html) {
  2148. if($.vakata.dnd.is_drag) { $.vakata.drag_stop({}); }
  2149. try {
  2150. e.currentTarget.unselectable = "on";
  2151. e.currentTarget.onselectstart = function() { return false; };
  2152. if(e.currentTarget.style) { e.currentTarget.style.MozUserSelect = "none"; }
  2153. } catch(err) { }
  2154. $.vakata.dnd.init_x = e.pageX;
  2155. $.vakata.dnd.init_y = e.pageY;
  2156. $.vakata.dnd.user_data = data;
  2157. $.vakata.dnd.is_down = true;
  2158. $.vakata.dnd.helper = $("<div id='vakata-dragged' />").html(html); //.fadeTo(10,0.25);
  2159. $(document).bind("mousemove", $.vakata.dnd.drag);
  2160. $(document).bind("mouseup", $.vakata.dnd.drag_stop);
  2161. return false;
  2162. },
  2163. drag : function (e) {
  2164. if(!$.vakata.dnd.is_down) { return; }
  2165. if(!$.vakata.dnd.is_drag) {
  2166. if(Math.abs(e.pageX - $.vakata.dnd.init_x) > 5 || Math.abs(e.pageY - $.vakata.dnd.init_y) > 5) {
  2167. $.vakata.dnd.helper.appendTo("body");
  2168. $.vakata.dnd.is_drag = true;
  2169. $(document).triggerHandler("drag_start.vakata", { "event" : e, "data" : $.vakata.dnd.user_data });
  2170. }
  2171. else { return; }
  2172. }
  2173. // maybe use a scrolling parent element instead of document?
  2174. if(e.type === "mousemove") { // thought of adding scroll in order to move the helper, but mouse poisition is n/a
  2175. var d = $(document), t = d.scrollTop(), l = d.scrollLeft();
  2176. if(e.pageY - t < 20) {
  2177. if(sti && dir1 === "down") { clearInterval(sti); sti = false; }
  2178. if(!sti) { dir1 = "up"; sti = setInterval(function () { $(document).scrollTop($(document).scrollTop() - $.vakata.dnd.scroll_spd); }, 150); }
  2179. }
  2180. else {
  2181. if(sti && dir1 === "up") { clearInterval(sti); sti = false; }
  2182. }
  2183. if($(window).height() - (e.pageY - t) < 20) {
  2184. if(sti && dir1 === "up") { clearInterval(sti); sti = false; }
  2185. if(!sti) { dir1 = "down"; sti = setInterval(function () { $(document).scrollTop($(document).scrollTop() + $.vakata.dnd.scroll_spd); }, 150); }
  2186. }
  2187. else {
  2188. if(sti && dir1 === "down") { clearInterval(sti); sti = false; }
  2189. }
  2190. if(e.pageX - l < 20) {
  2191. if(sli && dir2 === "right") { clearInterval(sli); sli = false; }
  2192. if(!sli) { dir2 = "left"; sli = setInterval(function () { $(document).scrollLeft($(document).scrollLeft() - $.vakata.dnd.scroll_spd); }, 150); }
  2193. }
  2194. else {
  2195. if(sli && dir2 === "left") { clearInterval(sli); sli = false; }
  2196. }
  2197. if($(window).width() - (e.pageX - l) < 20) {
  2198. if(sli && dir2 === "left") { clearInterval(sli); sli = false; }
  2199. if(!sli) { dir2 = "right"; sli = setInterval(function () { $(document).scrollLeft($(document).scrollLeft() + $.vakata.dnd.scroll_spd); }, 150); }
  2200. }
  2201. else {
  2202. if(sli && dir2 === "right") { clearInterval(sli); sli = false; }
  2203. }
  2204. }
  2205. $.vakata.dnd.helper.css({ left : (e.pageX + $.vakata.dnd.helper_left) + "px", top : (e.pageY + $.vakata.dnd.helper_top) + "px" });
  2206. $(document).triggerHandler("drag.vakata", { "event" : e, "data" : $.vakata.dnd.user_data });
  2207. },
  2208. drag_stop : function (e) {
  2209. if(sli) { clearInterval(sli); }
  2210. if(sti) { clearInterval(sti); }
  2211. $(document).unbind("mousemove", $.vakata.dnd.drag);
  2212. $(document).unbind("mouseup", $.vakata.dnd.drag_stop);
  2213. $(document).triggerHandler("drag_stop.vakata", { "event" : e, "data" : $.vakata.dnd.user_data });
  2214. $.vakata.dnd.helper.remove();
  2215. $.vakata.dnd.init_x = 0;
  2216. $.vakata.dnd.init_y = 0;
  2217. $.vakata.dnd.user_data = {};
  2218. $.vakata.dnd.is_down = false;
  2219. $.vakata.dnd.is_drag = false;
  2220. }
  2221. };
  2222. $(function() {
  2223. var css_string = '#vakata-dragged { display:block; margin:0 0 0 0; padding:4px 4px 4px 24px; position:absolute; top:-2000px; line-height:16px; z-index:10000; } ';
  2224. $.vakata.css.add_sheet({ str : css_string, title : "vakata" });
  2225. });
  2226. $.jstree.plugin("dnd", {
  2227. __init : function () {
  2228. this.data.dnd = {
  2229. active : false,
  2230. after : false,
  2231. inside : false,
  2232. before : false,
  2233. off : false,
  2234. prepared : false,
  2235. w : 0,
  2236. to1 : false,
  2237. to2 : false,
  2238. cof : false,
  2239. cw : false,
  2240. ch : false,
  2241. i1 : false,
  2242. i2 : false,
  2243. mto : false
  2244. };
  2245. this.get_container()
  2246. .bind("mouseenter.jstree", $.proxy(function (e) {
  2247. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  2248. if(this.data.themes) {
  2249. m.attr("class", "jstree-" + this.data.themes.theme);
  2250. if(ml) { ml.attr("class", "jstree-" + this.data.themes.theme); }
  2251. $.vakata.dnd.helper.attr("class", "jstree-dnd-helper jstree-" + this.data.themes.theme);
  2252. }
  2253. //if($(e.currentTarget).find("> ul > li").length === 0) {
  2254. if(e.currentTarget === e.target && $.vakata.dnd.user_data.obj && $($.vakata.dnd.user_data.obj).length && $($.vakata.dnd.user_data.obj).parents(".jstree:eq(0)")[0] !== e.target) { // node should not be from the same tree
  2255. var tr = $.jstree._reference(e.target), dc;
  2256. if(tr.data.dnd.foreign) {
  2257. dc = tr._get_settings().dnd.drag_check.call(this, { "o" : o, "r" : tr.get_container(), is_root : true });
  2258. if(dc === true || dc.inside === true || dc.before === true || dc.after === true) {
  2259. $.vakata.dnd.helper.children("ins").attr("class","jstree-ok");
  2260. }
  2261. }
  2262. else {
  2263. tr.prepare_move(o, tr.get_container(), "last");
  2264. if(tr.check_move()) {
  2265. $.vakata.dnd.helper.children("ins").attr("class","jstree-ok");
  2266. }
  2267. }
  2268. }
  2269. }
  2270. }, this))
  2271. .bind("mouseup.jstree", $.proxy(function (e) {
  2272. //if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree && $(e.currentTarget).find("> ul > li").length === 0) {
  2273. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree && e.currentTarget === e.target && $.vakata.dnd.user_data.obj && $($.vakata.dnd.user_data.obj).length && $($.vakata.dnd.user_data.obj).parents(".jstree:eq(0)")[0] !== e.target) { // node should not be from the same tree
  2274. var tr = $.jstree._reference(e.currentTarget), dc;
  2275. if(tr.data.dnd.foreign) {
  2276. dc = tr._get_settings().dnd.drag_check.call(this, { "o" : o, "r" : tr.get_container(), is_root : true });
  2277. if(dc === true || dc.inside === true || dc.before === true || dc.after === true) {
  2278. tr._get_settings().dnd.drag_finish.call(this, { "o" : o, "r" : tr.get_container(), is_root : true });
  2279. }
  2280. }
  2281. else {
  2282. tr.move_node(o, tr.get_container(), "last", e[tr._get_settings().dnd.copy_modifier + "Key"]);
  2283. }
  2284. }
  2285. }, this))
  2286. .bind("mouseleave.jstree", $.proxy(function (e) {
  2287. if(e.relatedTarget && e.relatedTarget.id && e.relatedTarget.id === "jstree-marker-line") {
  2288. return false;
  2289. }
  2290. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  2291. if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
  2292. if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
  2293. if(this.data.dnd.to1) { clearTimeout(this.data.dnd.to1); }
  2294. if(this.data.dnd.to2) { clearTimeout(this.data.dnd.to2); }
  2295. if($.vakata.dnd.helper.children("ins").hasClass("jstree-ok")) {
  2296. $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid");
  2297. }
  2298. }
  2299. }, this))
  2300. .bind("mousemove.jstree", $.proxy(function (e) {
  2301. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  2302. var cnt = this.get_container()[0];
  2303. // Horizontal scroll
  2304. if(e.pageX + 24 > this.data.dnd.cof.left + this.data.dnd.cw) {
  2305. if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
  2306. this.data.dnd.i1 = setInterval($.proxy(function () { this.scrollLeft += $.vakata.dnd.scroll_spd; }, cnt), 100);
  2307. }
  2308. else if(e.pageX - 24 < this.data.dnd.cof.left) {
  2309. if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
  2310. this.data.dnd.i1 = setInterval($.proxy(function () { this.scrollLeft -= $.vakata.dnd.scroll_spd; }, cnt), 100);
  2311. }
  2312. else {
  2313. if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
  2314. }
  2315. // Vertical scroll
  2316. if(e.pageY + 24 > this.data.dnd.cof.top + this.data.dnd.ch) {
  2317. if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
  2318. this.data.dnd.i2 = setInterval($.proxy(function () { this.scrollTop += $.vakata.dnd.scroll_spd; }, cnt), 100);
  2319. }
  2320. else if(e.pageY - 24 < this.data.dnd.cof.top) {
  2321. if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
  2322. this.data.dnd.i2 = setInterval($.proxy(function () { this.scrollTop -= $.vakata.dnd.scroll_spd; }, cnt), 100);
  2323. }
  2324. else {
  2325. if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
  2326. }
  2327. }
  2328. }, this))
  2329. .bind("scroll.jstree", $.proxy(function (e) {
  2330. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree && m && ml) {
  2331. m.hide();
  2332. ml.hide();
  2333. }
  2334. }, this))
  2335. .delegate("a", "mousedown.jstree", $.proxy(function (e) {
  2336. if(e.which === 1) {
  2337. this.start_drag(e.currentTarget, e);
  2338. return false;
  2339. }
  2340. }, this))
  2341. .delegate("a", "mouseenter.jstree", $.proxy(function (e) {
  2342. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  2343. this.dnd_enter(e.currentTarget);
  2344. }
  2345. }, this))
  2346. .delegate("a", "mousemove.jstree", $.proxy(function (e) {
  2347. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  2348. if(!r || !r.length || r.children("a")[0] !== e.currentTarget) {
  2349. this.dnd_enter(e.currentTarget);
  2350. }
  2351. if(typeof this.data.dnd.off.top === "undefined") { this.data.dnd.off = $(e.target).offset(); }
  2352. this.data.dnd.w = (e.pageY - (this.data.dnd.off.top || 0)) % this.data.core.li_height;
  2353. if(this.data.dnd.w < 0) { this.data.dnd.w += this.data.core.li_height; }
  2354. this.dnd_show();
  2355. }
  2356. }, this))
  2357. .delegate("a", "mouseleave.jstree", $.proxy(function (e) {
  2358. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  2359. if(e.relatedTarget && e.relatedTarget.id && e.relatedTarget.id === "jstree-marker-line") {
  2360. return false;
  2361. }
  2362. if(m) { m.hide(); }
  2363. if(ml) { ml.hide(); }
  2364. /*
  2365. var ec = $(e.currentTarget).closest("li"),
  2366. er = $(e.relatedTarget).closest("li");
  2367. if(er[0] !== ec.prev()[0] && er[0] !== ec.next()[0]) {
  2368. if(m) { m.hide(); }
  2369. if(ml) { ml.hide(); }
  2370. }
  2371. */
  2372. this.data.dnd.mto = setTimeout(
  2373. (function (t) { return function () { t.dnd_leave(e); }; })(this),
  2374. 0);
  2375. }
  2376. }, this))
  2377. .delegate("a", "mouseup.jstree", $.proxy(function (e) {
  2378. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  2379. this.dnd_finish(e);
  2380. }
  2381. }, this));
  2382. $(document)
  2383. .bind("drag_stop.vakata", $.proxy(function () {
  2384. if(this.data.dnd.to1) { clearTimeout(this.data.dnd.to1); }
  2385. if(this.data.dnd.to2) { clearTimeout(this.data.dnd.to2); }
  2386. if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
  2387. if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
  2388. this.data.dnd.after = false;
  2389. this.data.dnd.before = false;
  2390. this.data.dnd.inside = false;
  2391. this.data.dnd.off = false;
  2392. this.data.dnd.prepared = false;
  2393. this.data.dnd.w = false;
  2394. this.data.dnd.to1 = false;
  2395. this.data.dnd.to2 = false;
  2396. this.data.dnd.i1 = false;
  2397. this.data.dnd.i2 = false;
  2398. this.data.dnd.active = false;
  2399. this.data.dnd.foreign = false;
  2400. if(m) { m.css({ "top" : "-2000px" }); }
  2401. if(ml) { ml.css({ "top" : "-2000px" }); }
  2402. }, this))
  2403. .bind("drag_start.vakata", $.proxy(function (e, data) {
  2404. if(data.data.jstree) {
  2405. var et = $(data.event.target);
  2406. if(et.closest(".jstree").hasClass("jstree-" + this.get_index())) {
  2407. this.dnd_enter(et);
  2408. }
  2409. }
  2410. }, this));
  2411. /*
  2412. .bind("keydown.jstree-" + this.get_index() + " keyup.jstree-" + this.get_index(), $.proxy(function(e) {
  2413. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree && !this.data.dnd.foreign) {
  2414. var h = $.vakata.dnd.helper.children("ins");
  2415. if(e[this._get_settings().dnd.copy_modifier + "Key"] && h.hasClass("jstree-ok")) {
  2416. h.parent().html(h.parent().html().replace(/ \(Copy\)$/, "") + " (Copy)");
  2417. }
  2418. else {
  2419. h.parent().html(h.parent().html().replace(/ \(Copy\)$/, ""));
  2420. }
  2421. }
  2422. }, this)); */
  2423. var s = this._get_settings().dnd;
  2424. if(s.drag_target) {
  2425. $(document)
  2426. .delegate(s.drag_target, "mousedown.jstree-" + this.get_index(), $.proxy(function (e) {
  2427. o = e.target;
  2428. $.vakata.dnd.drag_start(e, { jstree : true, obj : e.target }, "<ins class='jstree-icon'></ins>" + $(e.target).text() );
  2429. if(this.data.themes) {
  2430. if(m) { m.attr("class", "jstree-" + this.data.themes.theme); }
  2431. if(ml) { ml.attr("class", "jstree-" + this.data.themes.theme); }
  2432. $.vakata.dnd.helper.attr("class", "jstree-dnd-helper jstree-" + this.data.themes.theme);
  2433. }
  2434. $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid");
  2435. var cnt = this.get_container();
  2436. this.data.dnd.cof = cnt.offset();
  2437. this.data.dnd.cw = parseInt(cnt.width(),10);
  2438. this.data.dnd.ch = parseInt(cnt.height(),10);
  2439. this.data.dnd.foreign = true;
  2440. e.preventDefault();
  2441. }, this));
  2442. }
  2443. if(s.drop_target) {
  2444. $(document)
  2445. .delegate(s.drop_target, "mouseenter.jstree-" + this.get_index(), $.proxy(function (e) {
  2446. if(this.data.dnd.active && this._get_settings().dnd.drop_check.call(this, { "o" : o, "r" : $(e.target), "e" : e })) {
  2447. $.vakata.dnd.helper.children("ins").attr("class","jstree-ok");
  2448. }
  2449. }, this))
  2450. .delegate(s.drop_target, "mouseleave.jstree-" + this.get_index(), $.proxy(function (e) {
  2451. if(this.data.dnd.active) {
  2452. $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid");
  2453. }
  2454. }, this))
  2455. .delegate(s.drop_target, "mouseup.jstree-" + this.get_index(), $.proxy(function (e) {
  2456. if(this.data.dnd.active && $.vakata.dnd.helper.children("ins").hasClass("jstree-ok")) {
  2457. this._get_settings().dnd.drop_finish.call(this, { "o" : o, "r" : $(e.target), "e" : e });
  2458. }
  2459. }, this));
  2460. }
  2461. },
  2462. defaults : {
  2463. copy_modifier : "ctrl",
  2464. check_timeout : 100,
  2465. open_timeout : 500,
  2466. drop_target : ".jstree-drop",
  2467. drop_check : function (data) { return true; },
  2468. drop_finish : $.noop,
  2469. drag_target : ".jstree-draggable",
  2470. drag_finish : $.noop,
  2471. drag_check : function (data) { return { after : false, before : false, inside : true }; }
  2472. },
  2473. _fn : {
  2474. dnd_prepare : function () {
  2475. if(!r || !r.length) { return; }
  2476. this.data.dnd.off = r.offset();
  2477. if(this._get_settings().core.rtl) {
  2478. this.data.dnd.off.right = this.data.dnd.off.left + r.width();
  2479. }
  2480. if(this.data.dnd.foreign) {
  2481. var a = this._get_settings().dnd.drag_check.call(this, { "o" : o, "r" : r });
  2482. this.data.dnd.after = a.after;
  2483. this.data.dnd.before = a.before;
  2484. this.data.dnd.inside = a.inside;
  2485. this.data.dnd.prepared = true;
  2486. return this.dnd_show();
  2487. }
  2488. this.prepare_move(o, r, "before");
  2489. this.data.dnd.before = this.check_move();
  2490. this.prepare_move(o, r, "after");
  2491. this.data.dnd.after = this.check_move();
  2492. if(this._is_loaded(r)) {
  2493. this.prepare_move(o, r, "inside");
  2494. this.data.dnd.inside = this.check_move();
  2495. }
  2496. else {
  2497. this.data.dnd.inside = false;
  2498. }
  2499. this.data.dnd.prepared = true;
  2500. return this.dnd_show();
  2501. },
  2502. dnd_show : function () {
  2503. if(!this.data.dnd.prepared) { return; }
  2504. var o = ["before","inside","after"],
  2505. r = false,
  2506. rtl = this._get_settings().core.rtl,
  2507. pos;
  2508. if(this.data.dnd.w < this.data.core.li_height/3) { o = ["before","inside","after"]; }
  2509. else if(this.data.dnd.w <= this.data.core.li_height*2/3) {
  2510. o = this.data.dnd.w < this.data.core.li_height/2 ? ["inside","before","after"] : ["inside","after","before"];
  2511. }
  2512. else { o = ["after","inside","before"]; }
  2513. $.each(o, $.proxy(function (i, val) {
  2514. if(this.data.dnd[val]) {
  2515. $.vakata.dnd.helper.children("ins").attr("class","jstree-ok");
  2516. r = val;
  2517. return false;
  2518. }
  2519. }, this));
  2520. if(r === false) { $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid"); }
  2521. pos = rtl ? (this.data.dnd.off.right - 18) : (this.data.dnd.off.left + 10);
  2522. switch(r) {
  2523. case "before":
  2524. m.css({ "left" : pos + "px", "top" : (this.data.dnd.off.top - 6) + "px" }).show();
  2525. if(ml) { ml.css({ "left" : (pos + 8) + "px", "top" : (this.data.dnd.off.top - 1) + "px" }).show(); }
  2526. break;
  2527. case "after":
  2528. m.css({ "left" : pos + "px", "top" : (this.data.dnd.off.top + this.data.core.li_height - 6) + "px" }).show();
  2529. if(ml) { ml.css({ "left" : (pos + 8) + "px", "top" : (this.data.dnd.off.top + this.data.core.li_height - 1) + "px" }).show(); }
  2530. break;
  2531. case "inside":
  2532. m.css({ "left" : pos + ( rtl ? -4 : 4) + "px", "top" : (this.data.dnd.off.top + this.data.core.li_height/2 - 5) + "px" }).show();
  2533. if(ml) { ml.hide(); }
  2534. break;
  2535. default:
  2536. m.hide();
  2537. if(ml) { ml.hide(); }
  2538. break;
  2539. }
  2540. last_pos = r;
  2541. return r;
  2542. },
  2543. dnd_open : function () {
  2544. this.data.dnd.to2 = false;
  2545. this.open_node(r, $.proxy(this.dnd_prepare,this), true);
  2546. },
  2547. dnd_finish : function (e) {
  2548. if(this.data.dnd.foreign) {
  2549. if(this.data.dnd.after || this.data.dnd.before || this.data.dnd.inside) {
  2550. this._get_settings().dnd.drag_finish.call(this, { "o" : o, "r" : r, "p" : last_pos });
  2551. }
  2552. }
  2553. else {
  2554. this.dnd_prepare();
  2555. this.move_node(o, r, last_pos, e[this._get_settings().dnd.copy_modifier + "Key"]);
  2556. }
  2557. o = false;
  2558. r = false;
  2559. m.hide();
  2560. if(ml) { ml.hide(); }
  2561. },
  2562. dnd_enter : function (obj) {
  2563. if(this.data.dnd.mto) {
  2564. clearTimeout(this.data.dnd.mto);
  2565. this.data.dnd.mto = false;
  2566. }
  2567. var s = this._get_settings().dnd;
  2568. this.data.dnd.prepared = false;
  2569. r = this._get_node(obj);
  2570. if(s.check_timeout) {
  2571. // do the calculations after a minimal timeout (users tend to drag quickly to the desired location)
  2572. if(this.data.dnd.to1) { clearTimeout(this.data.dnd.to1); }
  2573. this.data.dnd.to1 = setTimeout($.proxy(this.dnd_prepare, this), s.check_timeout);
  2574. }
  2575. else {
  2576. this.dnd_prepare();
  2577. }
  2578. if(s.open_timeout) {
  2579. if(this.data.dnd.to2) { clearTimeout(this.data.dnd.to2); }
  2580. if(r && r.length && r.hasClass("jstree-closed")) {
  2581. // if the node is closed - open it, then recalculate
  2582. this.data.dnd.to2 = setTimeout($.proxy(this.dnd_open, this), s.open_timeout);
  2583. }
  2584. }
  2585. else {
  2586. if(r && r.length && r.hasClass("jstree-closed")) {
  2587. this.dnd_open();
  2588. }
  2589. }
  2590. },
  2591. dnd_leave : function (e) {
  2592. this.data.dnd.after = false;
  2593. this.data.dnd.before = false;
  2594. this.data.dnd.inside = false;
  2595. $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid");
  2596. m.hide();
  2597. if(ml) { ml.hide(); }
  2598. if(r && r[0] === e.target.parentNode) {
  2599. if(this.data.dnd.to1) {
  2600. clearTimeout(this.data.dnd.to1);
  2601. this.data.dnd.to1 = false;
  2602. }
  2603. if(this.data.dnd.to2) {
  2604. clearTimeout(this.data.dnd.to2);
  2605. this.data.dnd.to2 = false;
  2606. }
  2607. }
  2608. },
  2609. start_drag : function (obj, e) {
  2610. o = this._get_node(obj);
  2611. if(this.data.ui && this.is_selected(o)) { o = this._get_node(null, true); }
  2612. var dt = o.length > 1 ? this._get_string("multiple_selection") : this.get_text(o),
  2613. cnt = this.get_container();
  2614. if(!this._get_settings().core.html_titles) { dt = dt.replace(/</ig,"&lt;").replace(/>/ig,"&gt;"); }
  2615. $.vakata.dnd.drag_start(e, { jstree : true, obj : o }, "<ins class='jstree-icon'></ins>" + dt );
  2616. if(this.data.themes) {
  2617. if(m) { m.attr("class", "jstree-" + this.data.themes.theme); }
  2618. if(ml) { ml.attr("class", "jstree-" + this.data.themes.theme); }
  2619. $.vakata.dnd.helper.attr("class", "jstree-dnd-helper jstree-" + this.data.themes.theme);
  2620. }
  2621. this.data.dnd.cof = cnt.offset();
  2622. this.data.dnd.cw = parseInt(cnt.width(),10);
  2623. this.data.dnd.ch = parseInt(cnt.height(),10);
  2624. this.data.dnd.active = true;
  2625. }
  2626. }
  2627. });
  2628. $(function() {
  2629. var css_string = '' +
  2630. '#vakata-dragged ins { display:block; text-decoration:none; width:16px; height:16px; margin:0 0 0 0; padding:0; position:absolute; top:4px; left:4px; ' +
  2631. ' -moz-border-radius:4px; border-radius:4px; -webkit-border-radius:4px; ' +
  2632. '} ' +
  2633. '#vakata-dragged .jstree-ok { background:green; } ' +
  2634. '#vakata-dragged .jstree-invalid { background:red; } ' +
  2635. '#jstree-marker { padding:0; margin:0; font-size:12px; overflow:hidden; height:12px; width:8px; position:absolute; top:-30px; z-index:10001; background-repeat:no-repeat; display:none; background-color:transparent; text-shadow:1px 1px 1px white; color:black; line-height:10px; } ' +
  2636. '#jstree-marker-line { padding:0; margin:0; line-height:0%; font-size:1px; overflow:hidden; height:1px; width:100px; position:absolute; top:-30px; z-index:10000; background-repeat:no-repeat; display:none; background-color:#456c43; ' +
  2637. ' cursor:pointer; border:1px solid #eeeeee; border-left:0; -moz-box-shadow: 0px 0px 2px #666; -webkit-box-shadow: 0px 0px 2px #666; box-shadow: 0px 0px 2px #666; ' +
  2638. ' -moz-border-radius:1px; border-radius:1px; -webkit-border-radius:1px; ' +
  2639. '}' +
  2640. '';
  2641. $.vakata.css.add_sheet({ str : css_string, title : "jstree" });
  2642. m = $("<div />").attr({ id : "jstree-marker" }).hide().html("&raquo;")
  2643. .bind("mouseleave mouseenter", function (e) {
  2644. m.hide();
  2645. ml.hide();
  2646. e.preventDefault();
  2647. e.stopImmediatePropagation();
  2648. return false;
  2649. })
  2650. .appendTo("body");
  2651. ml = $("<div />").attr({ id : "jstree-marker-line" }).hide()
  2652. .bind("mouseup", function (e) {
  2653. if(r && r.length) {
  2654. r.children("a").trigger(e);
  2655. e.preventDefault();
  2656. e.stopImmediatePropagation();
  2657. return false;
  2658. }
  2659. })
  2660. .bind("mouseleave", function (e) {
  2661. var rt = $(e.relatedTarget);
  2662. if(rt.is(".jstree") || rt.closest(".jstree").length === 0) {
  2663. if(r && r.length) {
  2664. r.children("a").trigger(e);
  2665. m.hide();
  2666. ml.hide();
  2667. e.preventDefault();
  2668. e.stopImmediatePropagation();
  2669. return false;
  2670. }
  2671. }
  2672. })
  2673. .appendTo("body");
  2674. $(document).bind("drag_start.vakata", function (e, data) {
  2675. if(data.data.jstree) { m.show(); if(ml) { ml.show(); } }
  2676. });
  2677. $(document).bind("drag_stop.vakata", function (e, data) {
  2678. if(data.data.jstree) { m.hide(); if(ml) { ml.hide(); } }
  2679. });
  2680. });
  2681. })(jQuery);
  2682. //*/
  2683. /*
  2684. * jsTree checkbox plugin
  2685. * Inserts checkboxes in front of every node
  2686. * Depends on the ui plugin
  2687. * DOES NOT WORK NICELY WITH MULTITREE DRAG'N'DROP
  2688. */
  2689. (function ($) {
  2690. $.jstree.plugin("checkbox", {
  2691. __init : function () {
  2692. this.data.checkbox.noui = this._get_settings().checkbox.override_ui;
  2693. if(this.data.ui && this.data.checkbox.noui) {
  2694. this.select_node = this.deselect_node = this.deselect_all = $.noop;
  2695. this.get_selected = this.get_checked;
  2696. }
  2697. this.get_container()
  2698. .bind("open_node.jstree create_node.jstree clean_node.jstree refresh.jstree", $.proxy(function (e, data) {
  2699. this._prepare_checkboxes(data.rslt.obj);
  2700. }, this))
  2701. .bind("loaded.jstree", $.proxy(function (e) {
  2702. this._prepare_checkboxes();
  2703. }, this))
  2704. .delegate( (this.data.ui && this.data.checkbox.noui ? "a" : "ins.jstree-checkbox") , "click.jstree", $.proxy(function (e) {
  2705. e.preventDefault();
  2706. if(this._get_node(e.target).hasClass("jstree-checked")) { this.uncheck_node(e.target); }
  2707. else { this.check_node(e.target); }
  2708. if(this.data.ui && this.data.checkbox.noui) {
  2709. this.save_selected();
  2710. if(this.data.cookies) { this.save_cookie("select_node"); }
  2711. }
  2712. else {
  2713. e.stopImmediatePropagation();
  2714. return false;
  2715. }
  2716. }, this));
  2717. },
  2718. defaults : {
  2719. override_ui : false,
  2720. two_state : false,
  2721. real_checkboxes : false,
  2722. checked_parent_open : true,
  2723. real_checkboxes_names : function (n) { return [ ("check_" + (n[0].id || Math.ceil(Math.random() * 10000))) , 1]; }
  2724. },
  2725. __destroy : function () {
  2726. this.get_container()
  2727. .find("input.jstree-real-checkbox").removeClass("jstree-real-checkbox").end()
  2728. .find("ins.jstree-checkbox").remove();
  2729. },
  2730. _fn : {
  2731. _checkbox_notify : function (n, data) {
  2732. if(data.checked) {
  2733. this.check_node(n, false);
  2734. }
  2735. },
  2736. _prepare_checkboxes : function (obj) {
  2737. obj = !obj || obj == -1 ? this.get_container().find("> ul > li") : this._get_node(obj);
  2738. if(obj === false) { return; } // added for removing root nodes
  2739. var c, _this = this, t, ts = this._get_settings().checkbox.two_state, rc = this._get_settings().checkbox.real_checkboxes, rcn = this._get_settings().checkbox.real_checkboxes_names;
  2740. obj.each(function () {
  2741. t = $(this);
  2742. c = t.is("li") && (t.hasClass("jstree-checked") || (rc && t.children(":checked").length)) ? "jstree-checked" : "jstree-unchecked";
  2743. t.find("li").addBack().each(function () {
  2744. var $t = $(this), nm;
  2745. $t.children("a" + (_this.data.languages ? "" : ":eq(0)") ).not(":has(.jstree-checkbox)").prepend("<ins class='jstree-checkbox'>&#160;</ins>").parent().not(".jstree-checked, .jstree-unchecked").addClass( ts ? "jstree-unchecked" : c );
  2746. if(rc) {
  2747. if(!$t.children(":checkbox").length) {
  2748. nm = rcn.call(_this, $t);
  2749. $t.prepend("<input type='checkbox' class='jstree-real-checkbox' id='" + nm[0] + "' name='" + nm[0] + "' value='" + nm[1] + "' />");
  2750. }
  2751. else {
  2752. $t.children(":checkbox").addClass("jstree-real-checkbox");
  2753. }
  2754. }
  2755. if(!ts) {
  2756. if(c === "jstree-checked" || $t.hasClass("jstree-checked") || $t.children(':checked').length) {
  2757. $t.find("li").addBack().addClass("jstree-checked").children(":checkbox").prop("checked", true);
  2758. }
  2759. }
  2760. else {
  2761. if($t.hasClass("jstree-checked") || $t.children(':checked').length) {
  2762. $t.addClass("jstree-checked").children(":checkbox").prop("checked", true);
  2763. }
  2764. }
  2765. });
  2766. });
  2767. if(!ts) {
  2768. obj.find(".jstree-checked").parent().parent().each(function () { _this._repair_state(this); });
  2769. }
  2770. },
  2771. change_state : function (obj, state) {
  2772. obj = this._get_node(obj);
  2773. var coll = false, rc = this._get_settings().checkbox.real_checkboxes;
  2774. if(!obj || obj === -1) { return false; }
  2775. state = (state === false || state === true) ? state : obj.hasClass("jstree-checked");
  2776. if(this._get_settings().checkbox.two_state) {
  2777. if(state) {
  2778. obj.removeClass("jstree-checked").addClass("jstree-unchecked");
  2779. if(rc) { obj.children(":checkbox").prop("checked", false); }
  2780. }
  2781. else {
  2782. obj.removeClass("jstree-unchecked").addClass("jstree-checked");
  2783. if(rc) { obj.children(":checkbox").prop("checked", true); }
  2784. }
  2785. }
  2786. else {
  2787. if(state) {
  2788. coll = obj.find("li").addBack();
  2789. if(!coll.filter(".jstree-checked, .jstree-undetermined").length) { return false; }
  2790. coll.removeClass("jstree-checked jstree-undetermined").addClass("jstree-unchecked");
  2791. if(rc) { coll.children(":checkbox").prop("checked", false); }
  2792. }
  2793. else {
  2794. coll = obj.find("li").addBack();
  2795. if(!coll.filter(".jstree-unchecked, .jstree-undetermined").length) { return false; }
  2796. coll.removeClass("jstree-unchecked jstree-undetermined").addClass("jstree-checked");
  2797. if(rc) { coll.children(":checkbox").prop("checked", true); }
  2798. if(this.data.ui) { this.data.ui.last_selected = obj; }
  2799. this.data.checkbox.last_selected = obj;
  2800. }
  2801. obj.parentsUntil(".jstree", "li").each(function () {
  2802. var $this = $(this);
  2803. if(state) {
  2804. if($this.children("ul").children("li.jstree-checked, li.jstree-undetermined").length) {
  2805. $this.parentsUntil(".jstree", "li").addBack().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
  2806. if(rc) { $this.parentsUntil(".jstree", "li").addBack().children(":checkbox").prop("checked", false); }
  2807. return false;
  2808. }
  2809. else {
  2810. $this.removeClass("jstree-checked jstree-undetermined").addClass("jstree-unchecked");
  2811. if(rc) { $this.children(":checkbox").prop("checked", false); }
  2812. }
  2813. }
  2814. else {
  2815. if($this.children("ul").children("li.jstree-unchecked, li.jstree-undetermined").length) {
  2816. $this.parentsUntil(".jstree", "li").addBack().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
  2817. if(rc) { $this.parentsUntil(".jstree", "li").addBack().children(":checkbox").prop("checked", false); }
  2818. return false;
  2819. }
  2820. else {
  2821. $this.removeClass("jstree-unchecked jstree-undetermined").addClass("jstree-checked");
  2822. if(rc) { $this.children(":checkbox").prop("checked", true); }
  2823. }
  2824. }
  2825. });
  2826. }
  2827. if(this.data.ui && this.data.checkbox.noui) { this.data.ui.selected = this.get_checked(); }
  2828. this.__callback(obj);
  2829. return true;
  2830. },
  2831. check_node : function (obj) {
  2832. if(this.change_state(obj, false)) {
  2833. obj = this._get_node(obj);
  2834. if(this._get_settings().checkbox.checked_parent_open) {
  2835. var t = this;
  2836. obj.parents(".jstree-closed").each(function () { t.open_node(this, false, true); });
  2837. }
  2838. this.__callback({ "obj" : obj });
  2839. }
  2840. },
  2841. uncheck_node : function (obj) {
  2842. if(this.change_state(obj, true)) { this.__callback({ "obj" : this._get_node(obj) }); }
  2843. },
  2844. check_all : function () {
  2845. var _this = this,
  2846. coll = this._get_settings().checkbox.two_state ? this.get_container_ul().find("li") : this.get_container_ul().children("li");
  2847. coll.each(function () {
  2848. _this.change_state(this, false);
  2849. });
  2850. this.__callback();
  2851. },
  2852. uncheck_all : function () {
  2853. var _this = this,
  2854. coll = this._get_settings().checkbox.two_state ? this.get_container_ul().find("li") : this.get_container_ul().children("li");
  2855. coll.each(function () {
  2856. _this.change_state(this, true);
  2857. });
  2858. this.__callback();
  2859. },
  2860. is_checked : function(obj) {
  2861. obj = this._get_node(obj);
  2862. return obj.length ? obj.is(".jstree-checked") : false;
  2863. },
  2864. get_checked : function (obj, get_all) {
  2865. obj = !obj || obj === -1 ? this.get_container() : this._get_node(obj);
  2866. return get_all || this._get_settings().checkbox.two_state ? obj.find(".jstree-checked") : obj.find("> ul > .jstree-checked, .jstree-undetermined > ul > .jstree-checked");
  2867. },
  2868. get_unchecked : function (obj, get_all) {
  2869. obj = !obj || obj === -1 ? this.get_container() : this._get_node(obj);
  2870. return get_all || this._get_settings().checkbox.two_state ? obj.find(".jstree-unchecked") : obj.find("> ul > .jstree-unchecked, .jstree-undetermined > ul > .jstree-unchecked");
  2871. },
  2872. show_checkboxes : function () { this.get_container().children("ul").removeClass("jstree-no-checkboxes"); },
  2873. hide_checkboxes : function () { this.get_container().children("ul").addClass("jstree-no-checkboxes"); },
  2874. _repair_state : function (obj) {
  2875. obj = this._get_node(obj);
  2876. if(!obj.length) { return; }
  2877. if(this._get_settings().checkbox.two_state) {
  2878. obj.find('li').addBack().not('.jstree-checked').removeClass('jstree-undetermined').addClass('jstree-unchecked').children(':checkbox').prop('checked', true);
  2879. return;
  2880. }
  2881. var rc = this._get_settings().checkbox.real_checkboxes,
  2882. a = obj.find("> ul > .jstree-checked").length,
  2883. b = obj.find("> ul > .jstree-undetermined").length,
  2884. c = obj.find("> ul > li").length;
  2885. if(c === 0) { if(obj.hasClass("jstree-undetermined")) { this.change_state(obj, false); } }
  2886. else if(a === 0 && b === 0) { this.change_state(obj, true); }
  2887. else if(a === c) { this.change_state(obj, false); }
  2888. else {
  2889. obj.parentsUntil(".jstree","li").addBack().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
  2890. if(rc) { obj.parentsUntil(".jstree", "li").addBack().children(":checkbox").prop("checked", false); }
  2891. }
  2892. },
  2893. reselect : function () {
  2894. if(this.data.ui && this.data.checkbox.noui) {
  2895. var _this = this,
  2896. s = this.data.ui.to_select;
  2897. s = $.map($.makeArray(s), function (n) { return "#" + n.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:"); });
  2898. this.deselect_all();
  2899. $.each(s, function (i, val) { _this.check_node(val); });
  2900. this.__callback();
  2901. }
  2902. else {
  2903. this.__call_old();
  2904. }
  2905. },
  2906. save_loaded : function () {
  2907. var _this = this;
  2908. this.data.core.to_load = [];
  2909. this.get_container_ul().find("li.jstree-closed.jstree-undetermined").each(function () {
  2910. if(this.id) { _this.data.core.to_load.push("#" + this.id); }
  2911. });
  2912. }
  2913. }
  2914. });
  2915. $(function() {
  2916. var css_string = '.jstree .jstree-real-checkbox { display:none; } ';
  2917. $.vakata.css.add_sheet({ str : css_string, title : "jstree" });
  2918. });
  2919. })(jQuery);
  2920. //*/
  2921. /*
  2922. * jsTree XML plugin
  2923. * The XML data store. Datastores are build by overriding the `load_node` and `_is_loaded` functions.
  2924. */
  2925. (function ($) {
  2926. $.vakata.xslt = function (xml, xsl, callback) {
  2927. var rs = "", xm, xs, processor, support;
  2928. // TODO: IE9 no XSLTProcessor, no document.recalc
  2929. if(document.recalc) {
  2930. xm = document.createElement('xml');
  2931. xs = document.createElement('xml');
  2932. xm.innerHTML = xml;
  2933. xs.innerHTML = xsl;
  2934. $("body").append(xm).append(xs);
  2935. setTimeout( (function (xm, xs, callback) {
  2936. return function () {
  2937. callback.call(null, xm.transformNode(xs.XMLDocument));
  2938. setTimeout( (function (xm, xs) { return function () { $(xm).remove(); $(xs).remove(); }; })(xm, xs), 200);
  2939. };
  2940. })(xm, xs, callback), 100);
  2941. return true;
  2942. }
  2943. if(typeof window.DOMParser !== "undefined" && typeof window.XMLHttpRequest !== "undefined" && typeof window.XSLTProcessor === "undefined") {
  2944. xml = new DOMParser().parseFromString(xml, "text/xml");
  2945. xsl = new DOMParser().parseFromString(xsl, "text/xml");
  2946. // alert(xml.transformNode());
  2947. // callback.call(null, new XMLSerializer().serializeToString(rs));
  2948. }
  2949. if(typeof window.DOMParser !== "undefined" && typeof window.XMLHttpRequest !== "undefined" && typeof window.XSLTProcessor !== "undefined") {
  2950. processor = new XSLTProcessor();
  2951. support = $.isFunction(processor.transformDocument) ? (typeof window.XMLSerializer !== "undefined") : true;
  2952. if(!support) { return false; }
  2953. xml = new DOMParser().parseFromString(xml, "text/xml");
  2954. xsl = new DOMParser().parseFromString(xsl, "text/xml");
  2955. if($.isFunction(processor.transformDocument)) {
  2956. rs = document.implementation.createDocument("", "", null);
  2957. processor.transformDocument(xml, xsl, rs, null);
  2958. callback.call(null, new XMLSerializer().serializeToString(rs));
  2959. return true;
  2960. }
  2961. else {
  2962. processor.importStylesheet(xsl);
  2963. rs = processor.transformToFragment(xml, document);
  2964. callback.call(null, $("<div />").append(rs).html());
  2965. return true;
  2966. }
  2967. }
  2968. return false;
  2969. };
  2970. var xsl = {
  2971. 'nest' : '<' + '?xml version="1.0" encoding="utf-8" ?>' +
  2972. '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >' +
  2973. '<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/html" />' +
  2974. '<xsl:template match="/">' +
  2975. ' <xsl:call-template name="nodes">' +
  2976. ' <xsl:with-param name="node" select="/root" />' +
  2977. ' </xsl:call-template>' +
  2978. '</xsl:template>' +
  2979. '<xsl:template name="nodes">' +
  2980. ' <xsl:param name="node" />' +
  2981. ' <ul>' +
  2982. ' <xsl:for-each select="$node/item">' +
  2983. ' <xsl:variable name="children" select="count(./item) &gt; 0" />' +
  2984. ' <li>' +
  2985. ' <xsl:attribute name="class">' +
  2986. ' <xsl:if test="position() = last()">jstree-last </xsl:if>' +
  2987. ' <xsl:choose>' +
  2988. ' <xsl:when test="@state = \'open\'">jstree-open </xsl:when>' +
  2989. ' <xsl:when test="$children or @hasChildren or @state = \'closed\'">jstree-closed </xsl:when>' +
  2990. ' <xsl:otherwise>jstree-leaf </xsl:otherwise>' +
  2991. ' </xsl:choose>' +
  2992. ' <xsl:value-of select="@class" />' +
  2993. ' </xsl:attribute>' +
  2994. ' <xsl:for-each select="@*">' +
  2995. ' <xsl:if test="name() != \'class\' and name() != \'state\' and name() != \'hasChildren\'">' +
  2996. ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' +
  2997. ' </xsl:if>' +
  2998. ' </xsl:for-each>' +
  2999. ' <ins class="jstree-icon"><xsl:text>&#xa0;</xsl:text></ins>' +
  3000. ' <xsl:for-each select="content/name">' +
  3001. ' <a>' +
  3002. ' <xsl:attribute name="href">' +
  3003. ' <xsl:choose>' +
  3004. ' <xsl:when test="@href"><xsl:value-of select="@href" /></xsl:when>' +
  3005. ' <xsl:otherwise>#</xsl:otherwise>' +
  3006. ' </xsl:choose>' +
  3007. ' </xsl:attribute>' +
  3008. ' <xsl:attribute name="class"><xsl:value-of select="@lang" /> <xsl:value-of select="@class" /></xsl:attribute>' +
  3009. ' <xsl:attribute name="style"><xsl:value-of select="@style" /></xsl:attribute>' +
  3010. ' <xsl:for-each select="@*">' +
  3011. ' <xsl:if test="name() != \'style\' and name() != \'class\' and name() != \'href\'">' +
  3012. ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' +
  3013. ' </xsl:if>' +
  3014. ' </xsl:for-each>' +
  3015. ' <ins>' +
  3016. ' <xsl:attribute name="class">jstree-icon ' +
  3017. ' <xsl:if test="string-length(attribute::icon) > 0 and not(contains(@icon,\'/\'))"><xsl:value-of select="@icon" /></xsl:if>' +
  3018. ' </xsl:attribute>' +
  3019. ' <xsl:if test="string-length(attribute::icon) > 0 and contains(@icon,\'/\')"><xsl:attribute name="style">background:url(<xsl:value-of select="@icon" />) center center no-repeat;</xsl:attribute></xsl:if>' +
  3020. ' <xsl:text>&#xa0;</xsl:text>' +
  3021. ' </ins>' +
  3022. ' <xsl:copy-of select="./child::node()" />' +
  3023. ' </a>' +
  3024. ' </xsl:for-each>' +
  3025. ' <xsl:if test="$children or @hasChildren"><xsl:call-template name="nodes"><xsl:with-param name="node" select="current()" /></xsl:call-template></xsl:if>' +
  3026. ' </li>' +
  3027. ' </xsl:for-each>' +
  3028. ' </ul>' +
  3029. '</xsl:template>' +
  3030. '</xsl:stylesheet>',
  3031. 'flat' : '<' + '?xml version="1.0" encoding="utf-8" ?>' +
  3032. '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >' +
  3033. '<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/xml" />' +
  3034. '<xsl:template match="/">' +
  3035. ' <ul>' +
  3036. ' <xsl:for-each select="//item[not(@parent_id) or @parent_id=0 or not(@parent_id = //item/@id)]">' + /* the last `or` may be removed */
  3037. ' <xsl:call-template name="nodes">' +
  3038. ' <xsl:with-param name="node" select="." />' +
  3039. ' <xsl:with-param name="is_last" select="number(position() = last())" />' +
  3040. ' </xsl:call-template>' +
  3041. ' </xsl:for-each>' +
  3042. ' </ul>' +
  3043. '</xsl:template>' +
  3044. '<xsl:template name="nodes">' +
  3045. ' <xsl:param name="node" />' +
  3046. ' <xsl:param name="is_last" />' +
  3047. ' <xsl:variable name="children" select="count(//item[@parent_id=$node/attribute::id]) &gt; 0" />' +
  3048. ' <li>' +
  3049. ' <xsl:attribute name="class">' +
  3050. ' <xsl:if test="$is_last = true()">jstree-last </xsl:if>' +
  3051. ' <xsl:choose>' +
  3052. ' <xsl:when test="@state = \'open\'">jstree-open </xsl:when>' +
  3053. ' <xsl:when test="$children or @hasChildren or @state = \'closed\'">jstree-closed </xsl:when>' +
  3054. ' <xsl:otherwise>jstree-leaf </xsl:otherwise>' +
  3055. ' </xsl:choose>' +
  3056. ' <xsl:value-of select="@class" />' +
  3057. ' </xsl:attribute>' +
  3058. ' <xsl:for-each select="@*">' +
  3059. ' <xsl:if test="name() != \'parent_id\' and name() != \'hasChildren\' and name() != \'class\' and name() != \'state\'">' +
  3060. ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' +
  3061. ' </xsl:if>' +
  3062. ' </xsl:for-each>' +
  3063. ' <ins class="jstree-icon"><xsl:text>&#xa0;</xsl:text></ins>' +
  3064. ' <xsl:for-each select="content/name">' +
  3065. ' <a>' +
  3066. ' <xsl:attribute name="href">' +
  3067. ' <xsl:choose>' +
  3068. ' <xsl:when test="@href"><xsl:value-of select="@href" /></xsl:when>' +
  3069. ' <xsl:otherwise>#</xsl:otherwise>' +
  3070. ' </xsl:choose>' +
  3071. ' </xsl:attribute>' +
  3072. ' <xsl:attribute name="class"><xsl:value-of select="@lang" /> <xsl:value-of select="@class" /></xsl:attribute>' +
  3073. ' <xsl:attribute name="style"><xsl:value-of select="@style" /></xsl:attribute>' +
  3074. ' <xsl:for-each select="@*">' +
  3075. ' <xsl:if test="name() != \'style\' and name() != \'class\' and name() != \'href\'">' +
  3076. ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' +
  3077. ' </xsl:if>' +
  3078. ' </xsl:for-each>' +
  3079. ' <ins>' +
  3080. ' <xsl:attribute name="class">jstree-icon ' +
  3081. ' <xsl:if test="string-length(attribute::icon) > 0 and not(contains(@icon,\'/\'))"><xsl:value-of select="@icon" /></xsl:if>' +
  3082. ' </xsl:attribute>' +
  3083. ' <xsl:if test="string-length(attribute::icon) > 0 and contains(@icon,\'/\')"><xsl:attribute name="style">background:url(<xsl:value-of select="@icon" />) center center no-repeat;</xsl:attribute></xsl:if>' +
  3084. ' <xsl:text>&#xa0;</xsl:text>' +
  3085. ' </ins>' +
  3086. ' <xsl:copy-of select="./child::node()" />' +
  3087. ' </a>' +
  3088. ' </xsl:for-each>' +
  3089. ' <xsl:if test="$children">' +
  3090. ' <ul>' +
  3091. ' <xsl:for-each select="//item[@parent_id=$node/attribute::id]">' +
  3092. ' <xsl:call-template name="nodes">' +
  3093. ' <xsl:with-param name="node" select="." />' +
  3094. ' <xsl:with-param name="is_last" select="number(position() = last())" />' +
  3095. ' </xsl:call-template>' +
  3096. ' </xsl:for-each>' +
  3097. ' </ul>' +
  3098. ' </xsl:if>' +
  3099. ' </li>' +
  3100. '</xsl:template>' +
  3101. '</xsl:stylesheet>'
  3102. },
  3103. escape_xml = function(string) {
  3104. return string
  3105. .toString()
  3106. .replace(/&/g, '&amp;')
  3107. .replace(/</g, '&lt;')
  3108. .replace(/>/g, '&gt;')
  3109. .replace(/"/g, '&quot;')
  3110. .replace(/'/g, '&apos;');
  3111. };
  3112. $.jstree.plugin("xml_data", {
  3113. defaults : {
  3114. data : false,
  3115. ajax : false,
  3116. xsl : "flat",
  3117. clean_node : false,
  3118. correct_state : true,
  3119. get_skip_empty : false,
  3120. get_include_preamble : true
  3121. },
  3122. _fn : {
  3123. load_node : function (obj, s_call, e_call) { var _this = this; this.load_node_xml(obj, function () { _this.__callback({ "obj" : _this._get_node(obj) }); s_call.call(this); }, e_call); },
  3124. _is_loaded : function (obj) {
  3125. var s = this._get_settings().xml_data;
  3126. obj = this._get_node(obj);
  3127. return obj == -1 || !obj || (!s.ajax && !$.isFunction(s.data)) || obj.is(".jstree-open, .jstree-leaf") || obj.children("ul").children("li").size() > 0;
  3128. },
  3129. load_node_xml : function (obj, s_call, e_call) {
  3130. var s = this.get_settings().xml_data,
  3131. error_func = function () {},
  3132. success_func = function () {};
  3133. obj = this._get_node(obj);
  3134. if(obj && obj !== -1) {
  3135. if(obj.data("jstree_is_loading")) { return; }
  3136. else { obj.data("jstree_is_loading",true); }
  3137. }
  3138. switch(!0) {
  3139. case (!s.data && !s.ajax): throw "Neither data nor ajax settings supplied.";
  3140. case ($.isFunction(s.data)):
  3141. s.data.call(this, obj, $.proxy(function (d) {
  3142. this.parse_xml(d, $.proxy(function (d) {
  3143. if(d) {
  3144. d = d.replace(/ ?xmlns="[^"]*"/ig, "");
  3145. if(d.length > 10) {
  3146. d = $(d);
  3147. if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); }
  3148. else { obj.children("a.jstree-loading").removeClass("jstree-loading"); obj.append(d); obj.removeData("jstree_is_loading"); }
  3149. if(s.clean_node) { this.clean_node(obj); }
  3150. if(s_call) { s_call.call(this); }
  3151. }
  3152. else {
  3153. if(obj && obj !== -1) {
  3154. obj.children("a.jstree-loading").removeClass("jstree-loading");
  3155. obj.removeData("jstree_is_loading");
  3156. if(s.correct_state) {
  3157. this.correct_state(obj);
  3158. if(s_call) { s_call.call(this); }
  3159. }
  3160. }
  3161. else {
  3162. if(s.correct_state) {
  3163. this.get_container().children("ul").empty();
  3164. if(s_call) { s_call.call(this); }
  3165. }
  3166. }
  3167. }
  3168. }
  3169. }, this));
  3170. }, this));
  3171. break;
  3172. case (!!s.data && !s.ajax) || (!!s.data && !!s.ajax && (!obj || obj === -1)):
  3173. if(!obj || obj == -1) {
  3174. this.parse_xml(s.data, $.proxy(function (d) {
  3175. if(d) {
  3176. d = d.replace(/ ?xmlns="[^"]*"/ig, "");
  3177. if(d.length > 10) {
  3178. d = $(d);
  3179. this.get_container().children("ul").empty().append(d.children());
  3180. if(s.clean_node) { this.clean_node(obj); }
  3181. if(s_call) { s_call.call(this); }
  3182. }
  3183. }
  3184. else {
  3185. if(s.correct_state) {
  3186. this.get_container().children("ul").empty();
  3187. if(s_call) { s_call.call(this); }
  3188. }
  3189. }
  3190. }, this));
  3191. }
  3192. break;
  3193. case (!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj && obj !== -1):
  3194. error_func = function (x, t, e) {
  3195. var ef = this.get_settings().xml_data.ajax.error;
  3196. if(ef) { ef.call(this, x, t, e); }
  3197. if(obj !== -1 && obj.length) {
  3198. obj.children("a.jstree-loading").removeClass("jstree-loading");
  3199. obj.removeData("jstree_is_loading");
  3200. if(t === "success" && s.correct_state) { this.correct_state(obj); }
  3201. }
  3202. else {
  3203. if(t === "success" && s.correct_state) { this.get_container().children("ul").empty(); }
  3204. }
  3205. if(e_call) { e_call.call(this); }
  3206. };
  3207. success_func = function (d, t, x) {
  3208. d = x.responseText;
  3209. var sf = this.get_settings().xml_data.ajax.success;
  3210. if(sf) { d = sf.call(this,d,t,x) || d; }
  3211. if(d === "" || (d && d.toString && d.toString().replace(/^[\s\n]+$/,"") === "")) {
  3212. return error_func.call(this, x, t, "");
  3213. }
  3214. this.parse_xml(d, $.proxy(function (d) {
  3215. if(d) {
  3216. d = d.replace(/ ?xmlns="[^"]*"/ig, "");
  3217. if(d.length > 10) {
  3218. d = $(d);
  3219. if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); }
  3220. else { obj.children("a.jstree-loading").removeClass("jstree-loading"); obj.append(d); obj.removeData("jstree_is_loading"); }
  3221. if(s.clean_node) { this.clean_node(obj); }
  3222. if(s_call) { s_call.call(this); }
  3223. }
  3224. else {
  3225. if(obj && obj !== -1) {
  3226. obj.children("a.jstree-loading").removeClass("jstree-loading");
  3227. obj.removeData("jstree_is_loading");
  3228. if(s.correct_state) {
  3229. this.correct_state(obj);
  3230. if(s_call) { s_call.call(this); }
  3231. }
  3232. }
  3233. else {
  3234. if(s.correct_state) {
  3235. this.get_container().children("ul").empty();
  3236. if(s_call) { s_call.call(this); }
  3237. }
  3238. }
  3239. }
  3240. }
  3241. }, this));
  3242. };
  3243. s.ajax.context = this;
  3244. s.ajax.error = error_func;
  3245. s.ajax.success = success_func;
  3246. if(!s.ajax.dataType) { s.ajax.dataType = "xml"; }
  3247. if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); }
  3248. if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); }
  3249. $.ajax(s.ajax);
  3250. break;
  3251. }
  3252. },
  3253. parse_xml : function (xml, callback) {
  3254. var s = this._get_settings().xml_data;
  3255. $.vakata.xslt(xml, xsl[s.xsl], callback);
  3256. },
  3257. get_xml : function (tp, obj, li_attr, a_attr, is_callback) {
  3258. var result = "",
  3259. s = this._get_settings(),
  3260. _this = this,
  3261. tmp1, tmp2, li, a, lang;
  3262. if(!tp) { tp = "flat"; }
  3263. if(!is_callback) { is_callback = 0; }
  3264. obj = this._get_node(obj);
  3265. if(!obj || obj === -1) { obj = this.get_container().find("> ul > li"); }
  3266. li_attr = $.isArray(li_attr) ? li_attr : [ "id", "class" ];
  3267. if(!is_callback && this.data.types && $.inArray(s.types.type_attr, li_attr) === -1) { li_attr.push(s.types.type_attr); }
  3268. a_attr = $.isArray(a_attr) ? a_attr : [ ];
  3269. if(!is_callback) {
  3270. if(s.xml_data.get_include_preamble) {
  3271. result += '<' + '?xml version="1.0" encoding="UTF-8"?' + '>';
  3272. }
  3273. result += "<root>";
  3274. }
  3275. obj.each(function () {
  3276. result += "<item";
  3277. li = $(this);
  3278. $.each(li_attr, function (i, v) {
  3279. var t = li.attr(v);
  3280. if(!s.xml_data.get_skip_empty || typeof t !== "undefined") {
  3281. result += " " + v + "=\"" + escape_xml((" " + (t || "")).replace(/ jstree[^ ]*/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,"")) + "\"";
  3282. }
  3283. });
  3284. if(li.hasClass("jstree-open")) { result += " state=\"open\""; }
  3285. if(li.hasClass("jstree-closed")) { result += " state=\"closed\""; }
  3286. if(tp === "flat") { result += " parent_id=\"" + escape_xml(is_callback) + "\""; }
  3287. result += ">";
  3288. result += "<content>";
  3289. a = li.children("a");
  3290. a.each(function () {
  3291. tmp1 = $(this);
  3292. lang = false;
  3293. result += "<name";
  3294. if($.inArray("languages", s.plugins) !== -1) {
  3295. $.each(s.languages, function (k, z) {
  3296. if(tmp1.hasClass(z)) { result += " lang=\"" + escape_xml(z) + "\""; lang = z; return false; }
  3297. });
  3298. }
  3299. if(a_attr.length) {
  3300. $.each(a_attr, function (k, z) {
  3301. var t = tmp1.attr(z);
  3302. if(!s.xml_data.get_skip_empty || typeof t !== "undefined") {
  3303. result += " " + z + "=\"" + escape_xml((" " + t || "").replace(/ jstree[^ ]*/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,"")) + "\"";
  3304. }
  3305. });
  3306. }
  3307. if(tmp1.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/^\s+$/ig,"").length) {
  3308. result += ' icon="' + escape_xml(tmp1.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,"")) + '"';
  3309. }
  3310. if(tmp1.children("ins").get(0).style.backgroundImage.length) {
  3311. result += ' icon="' + escape_xml(tmp1.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")","").replace(/'/ig,"").replace(/"/ig,"")) + '"';
  3312. }
  3313. result += ">";
  3314. result += "<![CDATA[" + _this.get_text(tmp1, lang) + "]]>";
  3315. result += "</name>";
  3316. });
  3317. result += "</content>";
  3318. tmp2 = li[0].id || true;
  3319. li = li.find("> ul > li");
  3320. if(li.length) { tmp2 = _this.get_xml(tp, li, li_attr, a_attr, tmp2); }
  3321. else { tmp2 = ""; }
  3322. if(tp == "nest") { result += tmp2; }
  3323. result += "</item>";
  3324. if(tp == "flat") { result += tmp2; }
  3325. });
  3326. if(!is_callback) { result += "</root>"; }
  3327. return result;
  3328. }
  3329. }
  3330. });
  3331. })(jQuery);
  3332. //*/
  3333. /*
  3334. * jsTree search plugin
  3335. * Enables both sync and async search on the tree
  3336. * DOES NOT WORK WITH JSON PROGRESSIVE RENDER
  3337. */
  3338. (function ($) {
  3339. $.expr[':'].jstree_contains = function(a,i,m){
  3340. return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase())>=0;
  3341. };
  3342. $.expr[':'].jstree_title_contains = function(a,i,m) {
  3343. return (a.getAttribute("title") || "").toLowerCase().indexOf(m[3].toLowerCase())>=0;
  3344. };
  3345. $.jstree.plugin("search", {
  3346. __init : function () {
  3347. this.data.search.str = "";
  3348. this.data.search.result = $();
  3349. if(this._get_settings().search.show_only_matches) {
  3350. this.get_container()
  3351. .bind("search.jstree", function (e, data) {
  3352. $(this).children("ul").find("li").hide().removeClass("jstree-last");
  3353. data.rslt.nodes.parentsUntil(".jstree").addBack().show()
  3354. .filter("ul").each(function () { $(this).children("li:visible").eq(-1).addClass("jstree-last"); });
  3355. })
  3356. .bind("clear_search.jstree", function () {
  3357. $(this).children("ul").find("li").css("display","").end().end().jstree("clean_node", -1);
  3358. });
  3359. }
  3360. },
  3361. defaults : {
  3362. ajax : false,
  3363. search_method : "jstree_contains", // for case insensitive - jstree_contains
  3364. show_only_matches : false
  3365. },
  3366. _fn : {
  3367. search : function (str, skip_async) {
  3368. if($.trim(str) === "") { this.clear_search(); return; }
  3369. var s = this.get_settings().search,
  3370. t = this,
  3371. error_func = function () { },
  3372. success_func = function () { };
  3373. this.data.search.str = str;
  3374. if(!skip_async && s.ajax !== false && this.get_container_ul().find("li.jstree-closed:not(:has(ul)):eq(0)").length > 0) {
  3375. this.search.supress_callback = true;
  3376. error_func = function () { };
  3377. success_func = function (d, t, x) {
  3378. var sf = this.get_settings().search.ajax.success;
  3379. if(sf) { d = sf.call(this,d,t,x) || d; }
  3380. this.data.search.to_open = d;
  3381. this._search_open();
  3382. };
  3383. s.ajax.context = this;
  3384. s.ajax.error = error_func;
  3385. s.ajax.success = success_func;
  3386. if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, str); }
  3387. if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, str); }
  3388. if(!s.ajax.data) { s.ajax.data = { "search_string" : str }; }
  3389. if(!s.ajax.dataType || /^json/.exec(s.ajax.dataType)) { s.ajax.dataType = "json"; }
  3390. $.ajax(s.ajax);
  3391. return;
  3392. }
  3393. if(this.data.search.result.length) { this.clear_search(); }
  3394. this.data.search.result = this.get_container().find("a" + (this.data.languages ? "." + this.get_lang() : "" ) + ":" + (s.search_method) + "(" + this.data.search.str + ")");
  3395. this.data.search.result.addClass("jstree-search").parent().parents(".jstree-closed").each(function () {
  3396. t.open_node(this, false, true);
  3397. });
  3398. this.__callback({ nodes : this.data.search.result, str : str });
  3399. },
  3400. clear_search : function (str) {
  3401. this.data.search.result.removeClass("jstree-search");
  3402. this.__callback(this.data.search.result);
  3403. this.data.search.result = $();
  3404. },
  3405. _search_open : function (is_callback) {
  3406. var _this = this,
  3407. done = true,
  3408. current = [],
  3409. remaining = [];
  3410. if(this.data.search.to_open.length) {
  3411. $.each(this.data.search.to_open, function (i, val) {
  3412. if(val == "#") { return true; }
  3413. if($(val).length && $(val).is(".jstree-closed")) { current.push(val); }
  3414. else { remaining.push(val); }
  3415. });
  3416. if(current.length) {
  3417. this.data.search.to_open = remaining;
  3418. $.each(current, function (i, val) {
  3419. _this.open_node(val, function () { _this._search_open(true); });
  3420. });
  3421. done = false;
  3422. }
  3423. }
  3424. if(done) { this.search(this.data.search.str, true); }
  3425. }
  3426. }
  3427. });
  3428. })(jQuery);
  3429. //*/
  3430. /*
  3431. * jsTree contextmenu plugin
  3432. */
  3433. (function ($) {
  3434. $.vakata.context = {
  3435. hide_on_mouseleave : false,
  3436. cnt : $("<div id='vakata-contextmenu' />"),
  3437. vis : false,
  3438. tgt : false,
  3439. par : false,
  3440. func : false,
  3441. data : false,
  3442. rtl : false,
  3443. show : function (s, t, x, y, d, p, rtl) {
  3444. $.vakata.context.rtl = !!rtl;
  3445. var html = $.vakata.context.parse(s), h, w;
  3446. if(!html) { return; }
  3447. $.vakata.context.vis = true;
  3448. $.vakata.context.tgt = t;
  3449. $.vakata.context.par = p || t || null;
  3450. $.vakata.context.data = d || null;
  3451. $.vakata.context.cnt
  3452. .html(html)
  3453. .css({ "visibility" : "hidden", "display" : "block", "left" : 0, "top" : 0 });
  3454. if($.vakata.context.hide_on_mouseleave) {
  3455. $.vakata.context.cnt
  3456. .one("mouseleave", function(e) { $.vakata.context.hide(); });
  3457. }
  3458. h = $.vakata.context.cnt.height();
  3459. w = $.vakata.context.cnt.width();
  3460. if(x + w > $(document).width()) {
  3461. x = $(document).width() - (w + 5);
  3462. $.vakata.context.cnt.find("li > ul").addClass("right");
  3463. }
  3464. if(y + h > $(document).height()) {
  3465. y = y - (h + t[0].offsetHeight);
  3466. $.vakata.context.cnt.find("li > ul").addClass("bottom");
  3467. }
  3468. $.vakata.context.cnt
  3469. .css({ "left" : x, "top" : y })
  3470. .find("li:has(ul)")
  3471. .bind("mouseenter", function (e) {
  3472. var w = $(document).width(),
  3473. h = $(document).height(),
  3474. ul = $(this).children("ul").show();
  3475. if(w !== $(document).width()) { ul.toggleClass("right"); }
  3476. if(h !== $(document).height()) { ul.toggleClass("bottom"); }
  3477. })
  3478. .bind("mouseleave", function (e) {
  3479. $(this).children("ul").hide();
  3480. })
  3481. .end()
  3482. .css({ "visibility" : "visible" })
  3483. .show();
  3484. $(document).triggerHandler("context_show.vakata");
  3485. },
  3486. hide : function () {
  3487. $.vakata.context.vis = false;
  3488. $.vakata.context.cnt.attr("class","").css({ "visibility" : "hidden" });
  3489. $(document).triggerHandler("context_hide.vakata");
  3490. },
  3491. parse : function (s, is_callback) {
  3492. if(!s) { return false; }
  3493. var str = "",
  3494. tmp = false,
  3495. was_sep = true;
  3496. if(!is_callback) { $.vakata.context.func = {}; }
  3497. str += "<ul>";
  3498. $.each(s, function (i, val) {
  3499. if(!val) { return true; }
  3500. $.vakata.context.func[i] = val.action;
  3501. if(!was_sep && val.separator_before) {
  3502. str += "<li class='vakata-separator vakata-separator-before'></li>";
  3503. }
  3504. was_sep = false;
  3505. str += "<li class='" + (val._class || "") + (val._disabled ? " jstree-contextmenu-disabled " : "") + "'><ins ";
  3506. if(val.icon && val.icon.indexOf("/") === -1) { str += " class='" + val.icon + "' "; }
  3507. if(val.icon && val.icon.indexOf("/") !== -1) { str += " style='background:url(" + val.icon + ") center center no-repeat;' "; }
  3508. str += ">&#160;</ins><a href='#' rel='" + i + "'>";
  3509. if(val.submenu) {
  3510. str += "<span style='float:" + ($.vakata.context.rtl ? "left" : "right") + ";'>&raquo;</span>";
  3511. }
  3512. str += val.label + "</a>";
  3513. if(val.submenu) {
  3514. tmp = $.vakata.context.parse(val.submenu, true);
  3515. if(tmp) { str += tmp; }
  3516. }
  3517. str += "</li>";
  3518. if(val.separator_after) {
  3519. str += "<li class='vakata-separator vakata-separator-after'></li>";
  3520. was_sep = true;
  3521. }
  3522. });
  3523. str = str.replace(/<li class\='vakata-separator vakata-separator-after'\><\/li\>$/,"");
  3524. str += "</ul>";
  3525. $(document).triggerHandler("context_parse.vakata");
  3526. return str.length > 10 ? str : false;
  3527. },
  3528. exec : function (i) {
  3529. if($.isFunction($.vakata.context.func[i])) {
  3530. // if is string - eval and call it!
  3531. $.vakata.context.func[i].call($.vakata.context.data, $.vakata.context.par);
  3532. return true;
  3533. }
  3534. else { return false; }
  3535. }
  3536. };
  3537. $(function () {
  3538. var css_string = '' +
  3539. '#vakata-contextmenu { display:block; visibility:hidden; left:0; top:-200px; position:absolute; margin:0; padding:0; min-width:180px; background:#ebebeb; border:1px solid silver; z-index:10000; *width:180px; } ' +
  3540. '#vakata-contextmenu ul { min-width:180px; *width:180px; } ' +
  3541. '#vakata-contextmenu ul, #vakata-contextmenu li { margin:0; padding:0; list-style-type:none; display:block; } ' +
  3542. '#vakata-contextmenu li { line-height:20px; min-height:20px; position:relative; padding:0px; } ' +
  3543. '#vakata-contextmenu li a { padding:1px 6px; line-height:17px; display:block; text-decoration:none; margin:1px 1px 0 1px; } ' +
  3544. '#vakata-contextmenu li ins { float:left; width:16px; height:16px; text-decoration:none; margin-right:2px; } ' +
  3545. '#vakata-contextmenu li a:hover, #vakata-contextmenu li.vakata-hover > a { background:gray; color:white; } ' +
  3546. '#vakata-contextmenu li ul { display:none; position:absolute; top:-2px; left:100%; background:#ebebeb; border:1px solid gray; } ' +
  3547. '#vakata-contextmenu .right { right:100%; left:auto; } ' +
  3548. '#vakata-contextmenu .bottom { bottom:-1px; top:auto; } ' +
  3549. '#vakata-contextmenu li.vakata-separator { min-height:0; height:1px; line-height:1px; font-size:1px; overflow:hidden; margin:0 2px; background:silver; /* border-top:1px solid #fefefe; */ padding:0; } ';
  3550. $.vakata.css.add_sheet({ str : css_string, title : "vakata" });
  3551. $.vakata.context.cnt
  3552. .delegate("a","click", function (e) { e.preventDefault(); })
  3553. .delegate("a","mouseup", function (e) {
  3554. if(!$(this).parent().hasClass("jstree-contextmenu-disabled") && $.vakata.context.exec($(this).attr("rel"))) {
  3555. $.vakata.context.hide();
  3556. }
  3557. else { $(this).blur(); }
  3558. })
  3559. .delegate("a","mouseover", function () {
  3560. $.vakata.context.cnt.find(".vakata-hover").removeClass("vakata-hover");
  3561. })
  3562. .appendTo("body");
  3563. $(document).bind("mousedown", function (e) { if($.vakata.context.vis && !$.contains($.vakata.context.cnt[0], e.target)) { $.vakata.context.hide(); } });
  3564. if(typeof $.hotkeys !== "undefined") {
  3565. $(document)
  3566. .bind("keydown", "up", function (e) {
  3567. if($.vakata.context.vis) {
  3568. var o = $.vakata.context.cnt.find("ul:visible").last().children(".vakata-hover").removeClass("vakata-hover").prevAll("li:not(.vakata-separator)").first();
  3569. if(!o.length) { o = $.vakata.context.cnt.find("ul:visible").last().children("li:not(.vakata-separator)").last(); }
  3570. o.addClass("vakata-hover");
  3571. e.stopImmediatePropagation();
  3572. e.preventDefault();
  3573. }
  3574. })
  3575. .bind("keydown", "down", function (e) {
  3576. if($.vakata.context.vis) {
  3577. var o = $.vakata.context.cnt.find("ul:visible").last().children(".vakata-hover").removeClass("vakata-hover").nextAll("li:not(.vakata-separator)").first();
  3578. if(!o.length) { o = $.vakata.context.cnt.find("ul:visible").last().children("li:not(.vakata-separator)").first(); }
  3579. o.addClass("vakata-hover");
  3580. e.stopImmediatePropagation();
  3581. e.preventDefault();
  3582. }
  3583. })
  3584. .bind("keydown", "right", function (e) {
  3585. if($.vakata.context.vis) {
  3586. $.vakata.context.cnt.find(".vakata-hover").children("ul").show().children("li:not(.vakata-separator)").removeClass("vakata-hover").first().addClass("vakata-hover");
  3587. e.stopImmediatePropagation();
  3588. e.preventDefault();
  3589. }
  3590. })
  3591. .bind("keydown", "left", function (e) {
  3592. if($.vakata.context.vis) {
  3593. $.vakata.context.cnt.find(".vakata-hover").children("ul").hide().children(".vakata-separator").removeClass("vakata-hover");
  3594. e.stopImmediatePropagation();
  3595. e.preventDefault();
  3596. }
  3597. })
  3598. .bind("keydown", "esc", function (e) {
  3599. $.vakata.context.hide();
  3600. e.preventDefault();
  3601. })
  3602. .bind("keydown", "space", function (e) {
  3603. $.vakata.context.cnt.find(".vakata-hover").last().children("a").click();
  3604. e.preventDefault();
  3605. });
  3606. }
  3607. });
  3608. $.jstree.plugin("contextmenu", {
  3609. __init : function () {
  3610. this.get_container()
  3611. .delegate("a", "contextmenu.jstree", $.proxy(function (e) {
  3612. e.preventDefault();
  3613. if(!$(e.currentTarget).hasClass("jstree-loading")) {
  3614. this.show_contextmenu(e.currentTarget, e.pageX, e.pageY);
  3615. }
  3616. }, this))
  3617. .delegate("a", "click.jstree", $.proxy(function (e) {
  3618. if(this.data.contextmenu) {
  3619. $.vakata.context.hide();
  3620. }
  3621. }, this))
  3622. .bind("destroy.jstree", $.proxy(function () {
  3623. // TODO: move this to descruct method
  3624. if(this.data.contextmenu) {
  3625. $.vakata.context.hide();
  3626. }
  3627. }, this));
  3628. $(document).bind("context_hide.vakata", $.proxy(function () { this.data.contextmenu = false; }, this));
  3629. },
  3630. defaults : {
  3631. select_node : false, // requires UI plugin
  3632. show_at_node : true,
  3633. items : { // Could be a function that should return an object like this one
  3634. "create" : {
  3635. "separator_before" : false,
  3636. "separator_after" : true,
  3637. "label" : "Create",
  3638. "action" : function (obj) { this.create(obj); }
  3639. },
  3640. "rename" : {
  3641. "separator_before" : false,
  3642. "separator_after" : false,
  3643. "label" : "Rename",
  3644. "action" : function (obj) { this.rename(obj); }
  3645. },
  3646. "remove" : {
  3647. "separator_before" : false,
  3648. "icon" : false,
  3649. "separator_after" : false,
  3650. "label" : "Delete",
  3651. "action" : function (obj) { if(this.is_selected(obj)) { this.remove(); } else { this.remove(obj); } }
  3652. },
  3653. "ccp" : {
  3654. "separator_before" : true,
  3655. "icon" : false,
  3656. "separator_after" : false,
  3657. "label" : "Edit",
  3658. "action" : false,
  3659. "submenu" : {
  3660. "cut" : {
  3661. "separator_before" : false,
  3662. "separator_after" : false,
  3663. "label" : "Cut",
  3664. "action" : function (obj) { this.cut(obj); }
  3665. },
  3666. "copy" : {
  3667. "separator_before" : false,
  3668. "icon" : false,
  3669. "separator_after" : false,
  3670. "label" : "Copy",
  3671. "action" : function (obj) { this.copy(obj); }
  3672. },
  3673. "paste" : {
  3674. "separator_before" : false,
  3675. "icon" : false,
  3676. "separator_after" : false,
  3677. "label" : "Paste",
  3678. "action" : function (obj) { this.paste(obj); }
  3679. }
  3680. }
  3681. }
  3682. }
  3683. },
  3684. _fn : {
  3685. show_contextmenu : function (obj, x, y) {
  3686. obj = this._get_node(obj);
  3687. var s = this.get_settings().contextmenu,
  3688. a = obj.children("a:visible:eq(0)"),
  3689. o = false,
  3690. i = false;
  3691. if(s.select_node && this.data.ui && !this.is_selected(obj)) {
  3692. this.deselect_all();
  3693. this.select_node(obj, true);
  3694. }
  3695. if(s.show_at_node || typeof x === "undefined" || typeof y === "undefined") {
  3696. o = a.offset();
  3697. x = o.left;
  3698. y = o.top + this.data.core.li_height;
  3699. }
  3700. i = obj.data("jstree") && obj.data("jstree").contextmenu ? obj.data("jstree").contextmenu : s.items;
  3701. if($.isFunction(i)) { i = i.call(this, obj); }
  3702. this.data.contextmenu = true;
  3703. $.vakata.context.show(i, a, x, y, this, obj, this._get_settings().core.rtl);
  3704. if(this.data.themes) { $.vakata.context.cnt.attr("class", "jstree-" + this.data.themes.theme + "-context"); }
  3705. }
  3706. }
  3707. });
  3708. })(jQuery);
  3709. //*/
  3710. /*
  3711. * jsTree types plugin
  3712. * Adds support types of nodes
  3713. * You can set an attribute on each li node, that represents its type.
  3714. * According to the type setting the node may get custom icon/validation rules
  3715. */
  3716. (function ($) {
  3717. $.jstree.plugin("types", {
  3718. __init : function () {
  3719. var s = this._get_settings().types;
  3720. this.data.types.attach_to = [];
  3721. this.get_container()
  3722. .bind("init.jstree", $.proxy(function () {
  3723. var types = s.types,
  3724. attr = s.type_attr,
  3725. icons_css = "",
  3726. _this = this;
  3727. $.each(types, function (i, tp) {
  3728. $.each(tp, function (k, v) {
  3729. if(!/^(max_depth|max_children|icon|valid_children)$/.test(k)) { _this.data.types.attach_to.push(k); }
  3730. });
  3731. if(!tp.icon) { return true; }
  3732. if( tp.icon.image || tp.icon.position) {
  3733. if(i == "default") { icons_css += '.jstree-' + _this.get_index() + ' a > .jstree-icon { '; }
  3734. else { icons_css += '.jstree-' + _this.get_index() + ' li[' + attr + '="' + i + '"] > a > .jstree-icon { '; }
  3735. if(tp.icon.image) { icons_css += ' background-image:url(' + tp.icon.image + '); '; }
  3736. if(tp.icon.position){ icons_css += ' background-position:' + tp.icon.position + '; '; }
  3737. else { icons_css += ' background-position:0 0; '; }
  3738. icons_css += '} ';
  3739. }
  3740. });
  3741. if(icons_css !== "") { $.vakata.css.add_sheet({ 'str' : icons_css, title : "jstree-types" }); }
  3742. }, this))
  3743. .bind("before.jstree", $.proxy(function (e, data) {
  3744. var s, t,
  3745. o = this._get_settings().types.use_data ? this._get_node(data.args[0]) : false,
  3746. d = o && o !== -1 && o.length ? o.data("jstree") : false;
  3747. if(d && d.types && d.types[data.func] === false) { e.stopImmediatePropagation(); return false; }
  3748. if($.inArray(data.func, this.data.types.attach_to) !== -1) {
  3749. if(!data.args[0] || (!data.args[0].tagName && !data.args[0].jquery)) { return; }
  3750. s = this._get_settings().types.types;
  3751. t = this._get_type(data.args[0]);
  3752. if(
  3753. (
  3754. (s[t] && typeof s[t][data.func] !== "undefined") ||
  3755. (s["default"] && typeof s["default"][data.func] !== "undefined")
  3756. ) && this._check(data.func, data.args[0]) === false
  3757. ) {
  3758. e.stopImmediatePropagation();
  3759. return false;
  3760. }
  3761. }
  3762. }, this));
  3763. if(is_ie6) {
  3764. this.get_container()
  3765. .bind("load_node.jstree set_type.jstree", $.proxy(function (e, data) {
  3766. var r = data && data.rslt && data.rslt.obj && data.rslt.obj !== -1 ? this._get_node(data.rslt.obj).parent() : this.get_container_ul(),
  3767. c = false,
  3768. s = this._get_settings().types;
  3769. $.each(s.types, function (i, tp) {
  3770. if(tp.icon && (tp.icon.image || tp.icon.position)) {
  3771. c = i === "default" ? r.find("li > a > .jstree-icon") : r.find("li[" + s.type_attr + "='" + i + "'] > a > .jstree-icon");
  3772. if(tp.icon.image) { c.css("backgroundImage","url(" + tp.icon.image + ")"); }
  3773. c.css("backgroundPosition", tp.icon.position || "0 0");
  3774. }
  3775. });
  3776. }, this));
  3777. }
  3778. },
  3779. defaults : {
  3780. // defines maximum number of root nodes (-1 means unlimited, -2 means disable max_children checking)
  3781. max_children : -1,
  3782. // defines the maximum depth of the tree (-1 means unlimited, -2 means disable max_depth checking)
  3783. max_depth : -1,
  3784. // defines valid node types for the root nodes
  3785. valid_children : "all",
  3786. // whether to use $.data
  3787. use_data : false,
  3788. // where is the type stores (the rel attribute of the LI element)
  3789. type_attr : "rel",
  3790. // a list of types
  3791. types : {
  3792. // the default type
  3793. "default" : {
  3794. "max_children" : -1,
  3795. "max_depth" : -1,
  3796. "valid_children": "all"
  3797. // Bound functions - you can bind any other function here (using boolean or function)
  3798. //"select_node" : true
  3799. }
  3800. }
  3801. },
  3802. _fn : {
  3803. _types_notify : function (n, data) {
  3804. if(data.type && this._get_settings().types.use_data) {
  3805. this.set_type(data.type, n);
  3806. }
  3807. },
  3808. _get_type : function (obj) {
  3809. obj = this._get_node(obj);
  3810. return (!obj || !obj.length) ? false : obj.attr(this._get_settings().types.type_attr) || "default";
  3811. },
  3812. set_type : function (str, obj) {
  3813. obj = this._get_node(obj);
  3814. var ret = (!obj.length || !str) ? false : obj.attr(this._get_settings().types.type_attr, str);
  3815. if(ret) { this.__callback({ obj : obj, type : str}); }
  3816. return ret;
  3817. },
  3818. _check : function (rule, obj, opts) {
  3819. obj = this._get_node(obj);
  3820. var v = false, t = this._get_type(obj), d = 0, _this = this, s = this._get_settings().types, data = false;
  3821. if(obj === -1) {
  3822. if(!!s[rule]) { v = s[rule]; }
  3823. else { return; }
  3824. }
  3825. else {
  3826. if(t === false) { return; }
  3827. data = s.use_data ? obj.data("jstree") : false;
  3828. if(data && data.types && typeof data.types[rule] !== "undefined") { v = data.types[rule]; }
  3829. else if(!!s.types[t] && typeof s.types[t][rule] !== "undefined") { v = s.types[t][rule]; }
  3830. else if(!!s.types["default"] && typeof s.types["default"][rule] !== "undefined") { v = s.types["default"][rule]; }
  3831. }
  3832. if($.isFunction(v)) { v = v.call(this, obj); }
  3833. if(rule === "max_depth" && obj !== -1 && opts !== false && s.max_depth !== -2 && v !== 0) {
  3834. // also include the node itself - otherwise if root node it is not checked
  3835. obj.children("a:eq(0)").parentsUntil(".jstree","li").each(function (i) {
  3836. // check if current depth already exceeds global tree depth
  3837. if(s.max_depth !== -1 && s.max_depth - (i + 1) <= 0) { v = 0; return false; }
  3838. d = (i === 0) ? v : _this._check(rule, this, false);
  3839. // check if current node max depth is already matched or exceeded
  3840. if(d !== -1 && d - (i + 1) <= 0) { v = 0; return false; }
  3841. // otherwise - set the max depth to the current value minus current depth
  3842. if(d >= 0 && (d - (i + 1) < v || v < 0) ) { v = d - (i + 1); }
  3843. // if the global tree depth exists and it minus the nodes calculated so far is less than `v` or `v` is unlimited
  3844. if(s.max_depth >= 0 && (s.max_depth - (i + 1) < v || v < 0) ) { v = s.max_depth - (i + 1); }
  3845. });
  3846. }
  3847. return v;
  3848. },
  3849. check_move : function () {
  3850. if(!this.__call_old()) { return false; }
  3851. var m = this._get_move(),
  3852. s = m.rt._get_settings().types,
  3853. mc = m.rt._check("max_children", m.cr),
  3854. md = m.rt._check("max_depth", m.cr),
  3855. vc = m.rt._check("valid_children", m.cr),
  3856. ch = 0, d = 1, t;
  3857. if(vc === "none") { return false; }
  3858. if($.isArray(vc) && m.ot && m.ot._get_type) {
  3859. m.o.each(function () {
  3860. if($.inArray(m.ot._get_type(this), vc) === -1) { d = false; return false; }
  3861. });
  3862. if(d === false) { return false; }
  3863. }
  3864. if(s.max_children !== -2 && mc !== -1) {
  3865. ch = m.cr === -1 ? this.get_container().find("> ul > li").not(m.o).length : m.cr.find("> ul > li").not(m.o).length;
  3866. if(ch + m.o.length > mc) { return false; }
  3867. }
  3868. if(s.max_depth !== -2 && md !== -1) {
  3869. d = 0;
  3870. if(md === 0) { return false; }
  3871. if(typeof m.o.d === "undefined") {
  3872. // TODO: deal with progressive rendering and async when checking max_depth (how to know the depth of the moved node)
  3873. t = m.o;
  3874. while(t.length > 0) {
  3875. t = t.find("> ul > li");
  3876. d ++;
  3877. }
  3878. m.o.d = d;
  3879. }
  3880. if(md - m.o.d < 0) { return false; }
  3881. }
  3882. return true;
  3883. },
  3884. create_node : function (obj, position, js, callback, is_loaded, skip_check) {
  3885. if(!skip_check && (is_loaded || this._is_loaded(obj))) {
  3886. var p = (typeof position == "string" && position.match(/^before|after$/i) && obj !== -1) ? this._get_parent(obj) : this._get_node(obj),
  3887. s = this._get_settings().types,
  3888. mc = this._check("max_children", p),
  3889. md = this._check("max_depth", p),
  3890. vc = this._check("valid_children", p),
  3891. ch;
  3892. if(typeof js === "string") { js = { data : js }; }
  3893. if(!js) { js = {}; }
  3894. if(vc === "none") { return false; }
  3895. if($.isArray(vc)) {
  3896. if(!js.attr || !js.attr[s.type_attr]) {
  3897. if(!js.attr) { js.attr = {}; }
  3898. js.attr[s.type_attr] = vc[0];
  3899. }
  3900. else {
  3901. if($.inArray(js.attr[s.type_attr], vc) === -1) { return false; }
  3902. }
  3903. }
  3904. if(s.max_children !== -2 && mc !== -1) {
  3905. ch = p === -1 ? this.get_container().find("> ul > li").length : p.find("> ul > li").length;
  3906. if(ch + 1 > mc) { return false; }
  3907. }
  3908. if(s.max_depth !== -2 && md !== -1 && (md - 1) < 0) { return false; }
  3909. }
  3910. return this.__call_old(true, obj, position, js, callback, is_loaded, skip_check);
  3911. }
  3912. }
  3913. });
  3914. })(jQuery);
  3915. //*/
  3916. /*
  3917. * jsTree HTML plugin
  3918. * The HTML data store. Datastores are build by replacing the `load_node` and `_is_loaded` functions.
  3919. */
  3920. (function ($) {
  3921. $.jstree.plugin("html_data", {
  3922. __init : function () {
  3923. // this used to use html() and clean the whitespace, but this way any attached data was lost
  3924. this.data.html_data.original_container_html = this.get_container().find(" > ul > li").clone(true);
  3925. // remove white space from LI node - otherwise nodes appear a bit to the right
  3926. this.data.html_data.original_container_html.find("li").addBack().contents().filter(function() { return this.nodeType == 3; }).remove();
  3927. },
  3928. defaults : {
  3929. data : false,
  3930. ajax : false,
  3931. correct_state : true
  3932. },
  3933. _fn : {
  3934. load_node : function (obj, s_call, e_call) { var _this = this; this.load_node_html(obj, function () { _this.__callback({ "obj" : _this._get_node(obj) }); s_call.call(this); }, e_call); },
  3935. _is_loaded : function (obj) {
  3936. obj = this._get_node(obj);
  3937. return obj == -1 || !obj || (!this._get_settings().html_data.ajax && !$.isFunction(this._get_settings().html_data.data)) || obj.is(".jstree-open, .jstree-leaf") || obj.children("ul").children("li").size() > 0;
  3938. },
  3939. load_node_html : function (obj, s_call, e_call) {
  3940. var d,
  3941. s = this.get_settings().html_data,
  3942. error_func = function () {},
  3943. success_func = function () {};
  3944. obj = this._get_node(obj);
  3945. if(obj && obj !== -1) {
  3946. if(obj.data("jstree_is_loading")) { return; }
  3947. else { obj.data("jstree_is_loading",true); }
  3948. }
  3949. switch(!0) {
  3950. case ($.isFunction(s.data)):
  3951. s.data.call(this, obj, $.proxy(function (d) {
  3952. if(d && d !== "" && d.toString && d.toString().replace(/^[\s\n]+$/,"") !== "") {
  3953. d = $(d);
  3954. if(!d.is("ul")) { d = $("<ul />").append(d); }
  3955. if(obj == -1 || !obj) { this.get_container().children("ul").empty().append(d.children()).find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'>&#160;</ins>").end().filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); }
  3956. else { obj.children("a.jstree-loading").removeClass("jstree-loading"); obj.append(d).children("ul").find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'>&#160;</ins>").end().filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); obj.removeData("jstree_is_loading"); }
  3957. this.clean_node(obj);
  3958. if(s_call) { s_call.call(this); }
  3959. }
  3960. else {
  3961. if(obj && obj !== -1) {
  3962. obj.children("a.jstree-loading").removeClass("jstree-loading");
  3963. obj.removeData("jstree_is_loading");
  3964. if(s.correct_state) {
  3965. this.correct_state(obj);
  3966. if(s_call) { s_call.call(this); }
  3967. }
  3968. }
  3969. else {
  3970. if(s.correct_state) {
  3971. this.get_container().children("ul").empty();
  3972. if(s_call) { s_call.call(this); }
  3973. }
  3974. }
  3975. }
  3976. }, this));
  3977. break;
  3978. case (!s.data && !s.ajax):
  3979. if(!obj || obj == -1) {
  3980. this.get_container()
  3981. .children("ul").empty()
  3982. .append(this.data.html_data.original_container_html)
  3983. .find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'>&#160;</ins>").end()
  3984. .filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon");
  3985. this.clean_node();
  3986. }
  3987. if(s_call) { s_call.call(this); }
  3988. break;
  3989. case (!!s.data && !s.ajax) || (!!s.data && !!s.ajax && (!obj || obj === -1)):
  3990. if(!obj || obj == -1) {
  3991. d = $(s.data);
  3992. if(!d.is("ul")) { d = $("<ul />").append(d); }
  3993. this.get_container()
  3994. .children("ul").empty().append(d.children())
  3995. .find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'>&#160;</ins>").end()
  3996. .filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon");
  3997. this.clean_node();
  3998. }
  3999. if(s_call) { s_call.call(this); }
  4000. break;
  4001. case (!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj && obj !== -1):
  4002. obj = this._get_node(obj);
  4003. error_func = function (x, t, e) {
  4004. var ef = this.get_settings().html_data.ajax.error;
  4005. if(ef) { ef.call(this, x, t, e); }
  4006. if(obj != -1 && obj.length) {
  4007. obj.children("a.jstree-loading").removeClass("jstree-loading");
  4008. obj.removeData("jstree_is_loading");
  4009. if(t === "success" && s.correct_state) { this.correct_state(obj); }
  4010. }
  4011. else {
  4012. if(t === "success" && s.correct_state) { this.get_container().children("ul").empty(); }
  4013. }
  4014. if(e_call) { e_call.call(this); }
  4015. };
  4016. success_func = function (d, t, x) {
  4017. var sf = this.get_settings().html_data.ajax.success;
  4018. if(sf) { d = sf.call(this,d,t,x) || d; }
  4019. if(d === "" || (d && d.toString && d.toString().replace(/^[\s\n]+$/,"") === "")) {
  4020. return error_func.call(this, x, t, "");
  4021. }
  4022. if(d) {
  4023. d = $(d);
  4024. if(!d.is("ul")) { d = $("<ul />").append(d); }
  4025. if(obj == -1 || !obj) { this.get_container().children("ul").empty().append(d.children()).find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'>&#160;</ins>").end().filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); }
  4026. else { obj.children("a.jstree-loading").removeClass("jstree-loading"); obj.append(d).children("ul").find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'>&#160;</ins>").end().filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); obj.removeData("jstree_is_loading"); }
  4027. this.clean_node(obj);
  4028. if(s_call) { s_call.call(this); }
  4029. }
  4030. else {
  4031. if(obj && obj !== -1) {
  4032. obj.children("a.jstree-loading").removeClass("jstree-loading");
  4033. obj.removeData("jstree_is_loading");
  4034. if(s.correct_state) {
  4035. this.correct_state(obj);
  4036. if(s_call) { s_call.call(this); }
  4037. }
  4038. }
  4039. else {
  4040. if(s.correct_state) {
  4041. this.get_container().children("ul").empty();
  4042. if(s_call) { s_call.call(this); }
  4043. }
  4044. }
  4045. }
  4046. };
  4047. s.ajax.context = this;
  4048. s.ajax.error = error_func;
  4049. s.ajax.success = success_func;
  4050. if(!s.ajax.dataType) { s.ajax.dataType = "html"; }
  4051. if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); }
  4052. if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); }
  4053. $.ajax(s.ajax);
  4054. break;
  4055. }
  4056. }
  4057. }
  4058. });
  4059. // include the HTML data plugin by default
  4060. $.jstree.defaults.plugins.push("html_data");
  4061. })(jQuery);
  4062. //*/
  4063. /*
  4064. * jsTree themeroller plugin
  4065. * Adds support for jQuery UI themes. Include this at the end of your plugins list, also make sure "themes" is not included.
  4066. */
  4067. (function ($) {
  4068. $.jstree.plugin("themeroller", {
  4069. __init : function () {
  4070. var s = this._get_settings().themeroller;
  4071. this.get_container()
  4072. .addClass("ui-widget-content")
  4073. .addClass("jstree-themeroller")
  4074. .delegate("a","mouseenter.jstree", function (e) {
  4075. if(!$(e.currentTarget).hasClass("jstree-loading")) {
  4076. $(this).addClass(s.item_h);
  4077. }
  4078. })
  4079. .delegate("a","mouseleave.jstree", function () {
  4080. $(this).removeClass(s.item_h);
  4081. })
  4082. .bind("init.jstree", $.proxy(function (e, data) {
  4083. data.inst.get_container().find("> ul > li > .jstree-loading > ins").addClass("ui-icon-refresh");
  4084. this._themeroller(data.inst.get_container().find("> ul > li"));
  4085. }, this))
  4086. .bind("open_node.jstree create_node.jstree", $.proxy(function (e, data) {
  4087. this._themeroller(data.rslt.obj);
  4088. }, this))
  4089. .bind("loaded.jstree refresh.jstree", $.proxy(function (e) {
  4090. this._themeroller();
  4091. }, this))
  4092. .bind("close_node.jstree", $.proxy(function (e, data) {
  4093. this._themeroller(data.rslt.obj);
  4094. }, this))
  4095. .bind("delete_node.jstree", $.proxy(function (e, data) {
  4096. this._themeroller(data.rslt.parent);
  4097. }, this))
  4098. .bind("correct_state.jstree", $.proxy(function (e, data) {
  4099. data.rslt.obj
  4100. .children("ins.jstree-icon").removeClass(s.opened + " " + s.closed + " ui-icon").end()
  4101. .find("> a > ins.ui-icon")
  4102. .filter(function() {
  4103. return this.className.toString()
  4104. .replace(s.item_clsd,"").replace(s.item_open,"").replace(s.item_leaf,"")
  4105. .indexOf("ui-icon-") === -1;
  4106. }).removeClass(s.item_open + " " + s.item_clsd).addClass(s.item_leaf || "jstree-no-icon");
  4107. }, this))
  4108. .bind("select_node.jstree", $.proxy(function (e, data) {
  4109. data.rslt.obj.children("a").addClass(s.item_a);
  4110. }, this))
  4111. .bind("deselect_node.jstree deselect_all.jstree", $.proxy(function (e, data) {
  4112. this.get_container()
  4113. .find("a." + s.item_a).removeClass(s.item_a).end()
  4114. .find("a.jstree-clicked").addClass(s.item_a);
  4115. }, this))
  4116. .bind("dehover_node.jstree", $.proxy(function (e, data) {
  4117. data.rslt.obj.children("a").removeClass(s.item_h);
  4118. }, this))
  4119. .bind("hover_node.jstree", $.proxy(function (e, data) {
  4120. this.get_container()
  4121. .find("a." + s.item_h).not(data.rslt.obj).removeClass(s.item_h);
  4122. data.rslt.obj.children("a").addClass(s.item_h);
  4123. }, this))
  4124. .bind("move_node.jstree", $.proxy(function (e, data) {
  4125. this._themeroller(data.rslt.o);
  4126. this._themeroller(data.rslt.op);
  4127. }, this));
  4128. },
  4129. __destroy : function () {
  4130. var s = this._get_settings().themeroller,
  4131. c = [ "ui-icon" ];
  4132. $.each(s, function (i, v) {
  4133. v = v.split(" ");
  4134. if(v.length) { c = c.concat(v); }
  4135. });
  4136. this.get_container()
  4137. .removeClass("ui-widget-content")
  4138. .find("." + c.join(", .")).removeClass(c.join(" "));
  4139. },
  4140. _fn : {
  4141. _themeroller : function (obj) {
  4142. var s = this._get_settings().themeroller;
  4143. obj = !obj || obj == -1 ? this.get_container_ul() : this._get_node(obj).parent();
  4144. obj
  4145. .find("li.jstree-closed")
  4146. .children("ins.jstree-icon").removeClass(s.opened).addClass("ui-icon " + s.closed).end()
  4147. .children("a").addClass(s.item)
  4148. .children("ins.jstree-icon").addClass("ui-icon")
  4149. .filter(function() {
  4150. return this.className.toString()
  4151. .replace(s.item_clsd,"").replace(s.item_open,"").replace(s.item_leaf,"")
  4152. .indexOf("ui-icon-") === -1;
  4153. }).removeClass(s.item_leaf + " " + s.item_open).addClass(s.item_clsd || "jstree-no-icon")
  4154. .end()
  4155. .end()
  4156. .end()
  4157. .end()
  4158. .find("li.jstree-open")
  4159. .children("ins.jstree-icon").removeClass(s.closed).addClass("ui-icon " + s.opened).end()
  4160. .children("a").addClass(s.item)
  4161. .children("ins.jstree-icon").addClass("ui-icon")
  4162. .filter(function() {
  4163. return this.className.toString()
  4164. .replace(s.item_clsd,"").replace(s.item_open,"").replace(s.item_leaf,"")
  4165. .indexOf("ui-icon-") === -1;
  4166. }).removeClass(s.item_leaf + " " + s.item_clsd).addClass(s.item_open || "jstree-no-icon")
  4167. .end()
  4168. .end()
  4169. .end()
  4170. .end()
  4171. .find("li.jstree-leaf")
  4172. .children("ins.jstree-icon").removeClass(s.closed + " ui-icon " + s.opened).end()
  4173. .children("a").addClass(s.item)
  4174. .children("ins.jstree-icon").addClass("ui-icon")
  4175. .filter(function() {
  4176. return this.className.toString()
  4177. .replace(s.item_clsd,"").replace(s.item_open,"").replace(s.item_leaf,"")
  4178. .indexOf("ui-icon-") === -1;
  4179. }).removeClass(s.item_clsd + " " + s.item_open).addClass(s.item_leaf || "jstree-no-icon");
  4180. }
  4181. },
  4182. defaults : {
  4183. "opened" : "ui-icon-triangle-1-se",
  4184. "closed" : "ui-icon-triangle-1-e",
  4185. "item" : "ui-state-default",
  4186. "item_h" : "ui-state-hover",
  4187. "item_a" : "ui-state-active",
  4188. "item_open" : "ui-icon-folder-open",
  4189. "item_clsd" : "ui-icon-folder-collapsed",
  4190. "item_leaf" : "ui-icon-document"
  4191. }
  4192. });
  4193. $(function() {
  4194. var css_string = '' +
  4195. '.jstree-themeroller .ui-icon { overflow:visible; } ' +
  4196. '.jstree-themeroller a { padding:0 2px; } ' +
  4197. '.jstree-themeroller .jstree-no-icon { display:none; }';
  4198. $.vakata.css.add_sheet({ str : css_string, title : "jstree" });
  4199. });
  4200. })(jQuery);
  4201. //*/
  4202. /*
  4203. * jsTree unique plugin
  4204. * Forces different names amongst siblings (still a bit experimental)
  4205. * NOTE: does not check language versions (it will not be possible to have nodes with the same title, even in different languages)
  4206. */
  4207. (function ($) {
  4208. $.jstree.plugin("unique", {
  4209. __init : function () {
  4210. this.get_container()
  4211. .bind("before.jstree", $.proxy(function (e, data) {
  4212. var nms = [], res = true, p, t;
  4213. if(data.func == "move_node") {
  4214. // obj, ref, position, is_copy, is_prepared, skip_check
  4215. if(data.args[4] === true) {
  4216. if(data.args[0].o && data.args[0].o.length) {
  4217. data.args[0].o.children("a").each(function () { nms.push($(this).text().replace(/^\s+/g,"")); });
  4218. res = this._check_unique(nms, data.args[0].np.find("> ul > li").not(data.args[0].o), "move_node");
  4219. }
  4220. }
  4221. }
  4222. if(data.func == "create_node") {
  4223. // obj, position, js, callback, is_loaded
  4224. if(data.args[4] || this._is_loaded(data.args[0])) {
  4225. p = this._get_node(data.args[0]);
  4226. if(data.args[1] && (data.args[1] === "before" || data.args[1] === "after")) {
  4227. p = this._get_parent(data.args[0]);
  4228. if(!p || p === -1) { p = this.get_container(); }
  4229. }
  4230. if(typeof data.args[2] === "string") { nms.push(data.args[2]); }
  4231. else if(!data.args[2] || !data.args[2].data) { nms.push(this._get_string("new_node")); }
  4232. else { nms.push(data.args[2].data); }
  4233. res = this._check_unique(nms, p.find("> ul > li"), "create_node");
  4234. }
  4235. }
  4236. if(data.func == "rename_node") {
  4237. // obj, val
  4238. nms.push(data.args[1]);
  4239. t = this._get_node(data.args[0]);
  4240. p = this._get_parent(t);
  4241. if(!p || p === -1) { p = this.get_container(); }
  4242. res = this._check_unique(nms, p.find("> ul > li").not(t), "rename_node");
  4243. }
  4244. if(!res) {
  4245. e.stopPropagation();
  4246. return false;
  4247. }
  4248. }, this));
  4249. },
  4250. defaults : {
  4251. error_callback : $.noop
  4252. },
  4253. _fn : {
  4254. _check_unique : function (nms, p, func) {
  4255. var cnms = [];
  4256. p.children("a").each(function () { cnms.push($(this).text().replace(/^\s+/g,"")); });
  4257. if(!cnms.length || !nms.length) { return true; }
  4258. cnms = cnms.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",");
  4259. if((cnms.length + nms.length) != cnms.concat(nms).sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",").length) {
  4260. this._get_settings().unique.error_callback.call(null, nms, p, func);
  4261. return false;
  4262. }
  4263. return true;
  4264. },
  4265. check_move : function () {
  4266. if(!this.__call_old()) { return false; }
  4267. var p = this._get_move(), nms = [];
  4268. if(p.o && p.o.length) {
  4269. p.o.children("a").each(function () { nms.push($(this).text().replace(/^\s+/g,"")); });
  4270. return this._check_unique(nms, p.np.find("> ul > li").not(p.o), "check_move");
  4271. }
  4272. return true;
  4273. }
  4274. }
  4275. });
  4276. })(jQuery);
  4277. //*/
  4278. /*
  4279. * jsTree wholerow plugin
  4280. * Makes select and hover work on the entire width of the node
  4281. * MAY BE HEAVY IN LARGE DOM
  4282. */
  4283. (function ($) {
  4284. $.jstree.plugin("wholerow", {
  4285. __init : function () {
  4286. if(!this.data.ui) { throw "jsTree wholerow: jsTree UI plugin not included."; }
  4287. this.data.wholerow.html = false;
  4288. this.data.wholerow.to = false;
  4289. this.get_container()
  4290. .bind("init.jstree", $.proxy(function (e, data) {
  4291. this._get_settings().core.animation = 0;
  4292. }, this))
  4293. .bind("open_node.jstree create_node.jstree clean_node.jstree loaded.jstree", $.proxy(function (e, data) {
  4294. this._prepare_wholerow_span( data && data.rslt && data.rslt.obj ? data.rslt.obj : -1 );
  4295. }, this))
  4296. .bind("search.jstree clear_search.jstree reopen.jstree after_open.jstree after_close.jstree create_node.jstree delete_node.jstree clean_node.jstree", $.proxy(function (e, data) {
  4297. if(this.data.to) { clearTimeout(this.data.to); }
  4298. this.data.to = setTimeout( (function (t, o) { return function() { t._prepare_wholerow_ul(o); }; })(this, data && data.rslt && data.rslt.obj ? data.rslt.obj : -1), 0);
  4299. }, this))
  4300. .bind("deselect_all.jstree", $.proxy(function (e, data) {
  4301. this.get_container().find(" > .jstree-wholerow .jstree-clicked").removeClass("jstree-clicked " + (this.data.themeroller ? this._get_settings().themeroller.item_a : "" ));
  4302. }, this))
  4303. .bind("select_node.jstree deselect_node.jstree ", $.proxy(function (e, data) {
  4304. data.rslt.obj.each(function () {
  4305. var ref = data.inst.get_container().find(" > .jstree-wholerow li:visible:eq(" + ( parseInt((($(this).offset().top - data.inst.get_container().offset().top + data.inst.get_container()[0].scrollTop) / data.inst.data.core.li_height),10)) + ")");
  4306. // ref.children("a")[e.type === "select_node" ? "addClass" : "removeClass"]("jstree-clicked");
  4307. ref.children("a").attr("class",data.rslt.obj.children("a").attr("class"));
  4308. });
  4309. }, this))
  4310. .bind("hover_node.jstree dehover_node.jstree", $.proxy(function (e, data) {
  4311. this.get_container().find(" > .jstree-wholerow .jstree-hovered").removeClass("jstree-hovered " + (this.data.themeroller ? this._get_settings().themeroller.item_h : "" ));
  4312. if(e.type === "hover_node") {
  4313. var ref = this.get_container().find(" > .jstree-wholerow li:visible:eq(" + ( parseInt(((data.rslt.obj.offset().top - this.get_container().offset().top + this.get_container()[0].scrollTop) / this.data.core.li_height),10)) + ")");
  4314. // ref.children("a").addClass("jstree-hovered");
  4315. ref.children("a").attr("class",data.rslt.obj.children(".jstree-hovered").attr("class"));
  4316. }
  4317. }, this))
  4318. .delegate(".jstree-wholerow-span, ins.jstree-icon, li", "click.jstree", function (e) {
  4319. var n = $(e.currentTarget);
  4320. if(e.target.tagName === "A" || (e.target.tagName === "INS" && n.closest("li").is(".jstree-open, .jstree-closed"))) { return; }
  4321. n.closest("li").children("a:visible:eq(0)").click();
  4322. e.stopImmediatePropagation();
  4323. })
  4324. .delegate("li", "mouseover.jstree", $.proxy(function (e) {
  4325. e.stopImmediatePropagation();
  4326. if($(e.currentTarget).children(".jstree-hovered, .jstree-clicked").length) { return false; }
  4327. this.hover_node(e.currentTarget);
  4328. return false;
  4329. }, this))
  4330. .delegate("li", "mouseleave.jstree", $.proxy(function (e) {
  4331. if($(e.currentTarget).children("a").hasClass("jstree-hovered").length) { return; }
  4332. this.dehover_node(e.currentTarget);
  4333. }, this));
  4334. if(is_ie7 || is_ie6) {
  4335. $.vakata.css.add_sheet({ str : ".jstree-" + this.get_index() + " { position:relative; } ", title : "jstree" });
  4336. }
  4337. },
  4338. defaults : {
  4339. },
  4340. __destroy : function () {
  4341. this.get_container().children(".jstree-wholerow").remove();
  4342. this.get_container().find(".jstree-wholerow-span").remove();
  4343. },
  4344. _fn : {
  4345. _prepare_wholerow_span : function (obj) {
  4346. obj = !obj || obj == -1 ? this.get_container().find("> ul > li") : this._get_node(obj);
  4347. if(obj === false) { return; } // added for removing root nodes
  4348. obj.each(function () {
  4349. $(this).find("li").addBack().each(function () {
  4350. var $t = $(this);
  4351. if($t.children(".jstree-wholerow-span").length) { return true; }
  4352. $t.prepend("<span class='jstree-wholerow-span' style='width:" + ($t.parentsUntil(".jstree","li").length * 18) + "px;'>&#160;</span>");
  4353. });
  4354. });
  4355. },
  4356. _prepare_wholerow_ul : function () {
  4357. var o = this.get_container().children("ul").eq(0), h = o.html();
  4358. o.addClass("jstree-wholerow-real");
  4359. if(this.data.wholerow.last_html !== h) {
  4360. this.data.wholerow.last_html = h;
  4361. this.get_container().children(".jstree-wholerow").remove();
  4362. this.get_container().append(
  4363. o.clone().removeClass("jstree-wholerow-real")
  4364. .wrapAll("<div class='jstree-wholerow' />").parent()
  4365. .width(o.parent()[0].scrollWidth)
  4366. .css("top", (o.height() + ( is_ie7 ? 5 : 0)) * -1 )
  4367. .find("li[id]").each(function () { this.removeAttribute("id"); }).end()
  4368. );
  4369. }
  4370. }
  4371. }
  4372. });
  4373. $(function() {
  4374. var css_string = '' +
  4375. '.jstree .jstree-wholerow-real { position:relative; z-index:1; } ' +
  4376. '.jstree .jstree-wholerow-real li { cursor:pointer; } ' +
  4377. '.jstree .jstree-wholerow-real a { border-left-color:transparent !important; border-right-color:transparent !important; } ' +
  4378. '.jstree .jstree-wholerow { position:relative; z-index:0; height:0; } ' +
  4379. '.jstree .jstree-wholerow ul, .jstree .jstree-wholerow li { width:100%; } ' +
  4380. '.jstree .jstree-wholerow, .jstree .jstree-wholerow ul, .jstree .jstree-wholerow li, .jstree .jstree-wholerow a { margin:0 !important; padding:0 !important; } ' +
  4381. '.jstree .jstree-wholerow, .jstree .jstree-wholerow ul, .jstree .jstree-wholerow li { background:transparent !important; }' +
  4382. '.jstree .jstree-wholerow ins, .jstree .jstree-wholerow span, .jstree .jstree-wholerow input { display:none !important; }' +
  4383. '.jstree .jstree-wholerow a, .jstree .jstree-wholerow a:hover { text-indent:-9999px; !important; width:100%; padding:0 !important; border-right-width:0px !important; border-left-width:0px !important; } ' +
  4384. '.jstree .jstree-wholerow-span { position:absolute; left:0; margin:0px; padding:0; height:18px; border-width:0; padding:0; z-index:0; }';
  4385. if(is_ff2) {
  4386. css_string += '' +
  4387. '.jstree .jstree-wholerow a { display:block; height:18px; margin:0; padding:0; border:0; } ' +
  4388. '.jstree .jstree-wholerow-real a { border-color:transparent !important; } ';
  4389. }
  4390. if(is_ie7 || is_ie6) {
  4391. css_string += '' +
  4392. '.jstree .jstree-wholerow, .jstree .jstree-wholerow li, .jstree .jstree-wholerow ul, .jstree .jstree-wholerow a { margin:0; padding:0; line-height:18px; } ' +
  4393. '.jstree .jstree-wholerow a { display:block; height:18px; line-height:18px; overflow:hidden; } ';
  4394. }
  4395. $.vakata.css.add_sheet({ str : css_string, title : "jstree" });
  4396. });
  4397. })(jQuery);
  4398. //*/
  4399. /*
  4400. * jsTree model plugin
  4401. * This plugin gets jstree to use a class model to retrieve data, creating great dynamism
  4402. */
  4403. (function ($) {
  4404. var nodeInterface = ["getChildren","getChildrenCount","getAttr","getName","getProps"],
  4405. validateInterface = function(obj, inter) {
  4406. var valid = true;
  4407. obj = obj || {};
  4408. inter = [].concat(inter);
  4409. $.each(inter, function (i, v) {
  4410. if(!$.isFunction(obj[v])) { valid = false; return false; }
  4411. });
  4412. return valid;
  4413. };
  4414. $.jstree.plugin("model", {
  4415. __init : function () {
  4416. if(!this.data.json_data) { throw "jsTree model: jsTree json_data plugin not included."; }
  4417. this._get_settings().json_data.data = function (n, b) {
  4418. var obj = (n == -1) ? this._get_settings().model.object : n.data("jstree_model");
  4419. if(!validateInterface(obj, nodeInterface)) { return b.call(null, false); }
  4420. if(this._get_settings().model.async) {
  4421. obj.getChildren($.proxy(function (data) {
  4422. this.model_done(data, b);
  4423. }, this));
  4424. }
  4425. else {
  4426. this.model_done(obj.getChildren(), b);
  4427. }
  4428. };
  4429. },
  4430. defaults : {
  4431. object : false,
  4432. id_prefix : false,
  4433. async : false
  4434. },
  4435. _fn : {
  4436. model_done : function (data, callback) {
  4437. var ret = [],
  4438. s = this._get_settings(),
  4439. _this = this;
  4440. if(!$.isArray(data)) { data = [data]; }
  4441. $.each(data, function (i, nd) {
  4442. var r = nd.getProps() || {};
  4443. r.attr = nd.getAttr() || {};
  4444. if(nd.getChildrenCount()) { r.state = "closed"; }
  4445. r.data = nd.getName();
  4446. if(!$.isArray(r.data)) { r.data = [r.data]; }
  4447. if(_this.data.types && $.isFunction(nd.getType)) {
  4448. r.attr[s.types.type_attr] = nd.getType();
  4449. }
  4450. if(r.attr.id && s.model.id_prefix) { r.attr.id = s.model.id_prefix + r.attr.id; }
  4451. if(!r.metadata) { r.metadata = { }; }
  4452. r.metadata.jstree_model = nd;
  4453. ret.push(r);
  4454. });
  4455. callback.call(null, ret);
  4456. }
  4457. }
  4458. });
  4459. })(jQuery);
  4460. //*/
  4461. /*
  4462. * jsTree checkbox plugin copy-paste
  4463. * change_state method was modified
  4464. * refactoring is needed after update to a newer version of jstree, that supports plugin extending
  4465. */
  4466. (function ($) {
  4467. $.jstree.plugin("vcheckbox", {
  4468. __init : function () {
  4469. this.data.vcheckbox.noui = this._get_settings().vcheckbox.override_ui;
  4470. if(this.data.ui && this.data.vcheckbox.noui) {
  4471. this.select_node = this.deselect_node = this.deselect_all = $.noop;
  4472. this.get_selected = this.get_checked;
  4473. }
  4474. this.get_container()
  4475. .bind("open_node.jstree create_node.jstree clean_node.jstree refresh.jstree", $.proxy(function (e, data) {
  4476. this._prepare_checkboxes(data.rslt.obj);
  4477. }, this))
  4478. .bind("loaded.jstree", $.proxy(function (e) {
  4479. this._prepare_checkboxes();
  4480. }, this))
  4481. .delegate( (this.data.ui && this.data.vcheckbox.noui ? "a" : "ins.jstree-checkbox") , "click.jstree", $.proxy(function (e) {
  4482. e.preventDefault();
  4483. if(this._get_node(e.target).hasClass("jstree-checked")) { this.uncheck_node(e.target); }
  4484. else { this.check_node(e.target); }
  4485. if(this.data.ui && this.data.vcheckbox.noui) {
  4486. this.save_selected();
  4487. if(this.data.cookies) { this.save_cookie("select_node"); }
  4488. }
  4489. else {
  4490. e.stopImmediatePropagation();
  4491. return false;
  4492. }
  4493. }, this));
  4494. },
  4495. defaults : {
  4496. override_ui : false,
  4497. two_state : false,
  4498. real_checkboxes : false,
  4499. checked_parent_open : true,
  4500. real_checkboxes_names : function (n) { return [ ("check_" + (n[0].id || Math.ceil(Math.random() * 10000))) , 1]; }
  4501. },
  4502. __destroy : function () {
  4503. this.get_container()
  4504. .find("input.jstree-real-checkbox").removeClass("jstree-real-checkbox").end()
  4505. .find("ins.jstree-checkbox").remove();
  4506. },
  4507. _fn : {
  4508. _checkbox_notify : function (n, data) {
  4509. if(data.checked) {
  4510. this.check_node(n, false);
  4511. }
  4512. },
  4513. _prepare_checkboxes : function (obj) {
  4514. obj = !obj || obj == -1 ? this.get_container().find("> ul > li") : this._get_node(obj);
  4515. if(obj === false) { return; } // added for removing root nodes
  4516. var c, _this = this, t, ts = this._get_settings().vcheckbox.two_state, rc = this._get_settings().vcheckbox.real_checkboxes, rcn = this._get_settings().vcheckbox.real_checkboxes_names;
  4517. obj.each(function () {
  4518. t = $(this);
  4519. c = t.is("li") && (t.hasClass("jstree-checked") || (rc && t.children(":checked").length)) ? "jstree-checked" : "jstree-unchecked";
  4520. t.find("li").addBack().each(function () {
  4521. var $t = $(this), nm;
  4522. $t.children("a" + (_this.data.languages ? "" : ":eq(0)") ).not(":has(.jstree-checkbox)").prepend("<ins class='jstree-checkbox'>&#160;</ins>").parent().not(".jstree-checked, .jstree-unchecked").addClass( ts ? "jstree-unchecked" : c );
  4523. if(rc) {
  4524. if(!$t.children(":checkbox").length) {
  4525. nm = rcn.call(_this, $t);
  4526. $t.prepend("<input type='checkbox' class='jstree-real-checkbox' id='" + nm[0] + "' name='" + nm[0] + "' value='" + nm[1] + "' />");
  4527. }
  4528. else {
  4529. $t.children(":checkbox").addClass("jstree-real-checkbox");
  4530. }
  4531. }
  4532. if(!ts) {
  4533. if(c === "jstree-checked" || $t.hasClass("jstree-checked") || $t.children(':checked').length) {
  4534. $t.find("li").addBack().addClass("jstree-checked").children(":checkbox").prop("checked", true);
  4535. }
  4536. }
  4537. else {
  4538. if($t.hasClass("jstree-checked") || $t.children(':checked').length) {
  4539. $t.addClass("jstree-checked").children(":checkbox").prop("checked", true);
  4540. }
  4541. }
  4542. });
  4543. });
  4544. if(!ts) {
  4545. obj.find(".jstree-checked").parent().parent().each(function () { _this._repair_state(this); });
  4546. }
  4547. },
  4548. change_state : function (obj, state) {
  4549. obj = this._get_node(obj);
  4550. var coll = false, rc = this._get_settings().vcheckbox.real_checkboxes;
  4551. if(!obj || obj === -1) { return false; }
  4552. state = (state === false || state === true) ? state : obj.hasClass("jstree-checked");
  4553. if(this._get_settings().vcheckbox.two_state) {
  4554. if(state) {
  4555. coll = obj.find("li").addBack();
  4556. if(!coll.filter(".jstree-checked").length) { return false; }
  4557. coll.removeClass("jstree-checked").addClass("jstree-unchecked");
  4558. if(rc) { coll.children(":checkbox").prop("checked", false); }
  4559. }
  4560. else {
  4561. coll = obj.find("li").addBack();
  4562. if(!coll.filter(".jstree-unchecked").length) { return false; }
  4563. coll.removeClass("jstree-unchecked").addClass("jstree-checked");
  4564. if(rc) { coll.children(":checkbox").prop("checked", true); }
  4565. if(this.data.ui) { this.data.ui.last_selected = obj; }
  4566. this.data.vcheckbox.last_selected = obj;
  4567. }
  4568. obj.parentsUntil(".jstree", "li").each(function () {
  4569. var $this = $(this);
  4570. if(state) {
  4571. if($this.children("ul").children("li.jstree-checked").length) {
  4572. $this.parentsUntil(".jstree", "li").addBack().removeClass("jstree-unchecked").addClass("jstree-checked");
  4573. if(rc) { $this.parentsUntil(".jstree", "li").addBack().children(":checkbox").prop("checked", true); }
  4574. return false;
  4575. }
  4576. }
  4577. else {
  4578. if($this.children("ul").children("li.jstree-unchecked").length) {
  4579. $this.parentsUntil(".jstree", "li").addBack().removeClass("jstree-unchecked").addClass("jstree-checked");
  4580. if(rc) { $this.parentsUntil(".jstree", "li").addBack().children(":checkbox").prop("checked", true); }
  4581. return false;
  4582. }
  4583. else {
  4584. $this.removeClass("jstree-unchecked").addClass("jstree-checked");
  4585. if(rc) { $this.children(":checkbox").prop("checked", true); }
  4586. }
  4587. }
  4588. });
  4589. }
  4590. else {
  4591. if(state) {
  4592. coll = obj.find("li").addBack();
  4593. if(!coll.filter(".jstree-checked, .jstree-undetermined").length) { return false; }
  4594. coll.removeClass("jstree-checked jstree-undetermined").addClass("jstree-unchecked");
  4595. if(rc) { coll.children(":checkbox").prop("checked", false); }
  4596. }
  4597. else {
  4598. coll = obj.find("li").addBack();
  4599. if(!coll.filter(".jstree-unchecked, .jstree-undetermined").length) { return false; }
  4600. coll.removeClass("jstree-unchecked jstree-undetermined").addClass("jstree-checked");
  4601. if(rc) { coll.children(":checkbox").prop("checked", true); }
  4602. if(this.data.ui) { this.data.ui.last_selected = obj; }
  4603. this.data.vcheckbox.last_selected = obj;
  4604. }
  4605. obj.parentsUntil(".jstree", "li").each(function () {
  4606. var $this = $(this);
  4607. if(state) {
  4608. if($this.children("ul").children("li.jstree-checked, li.jstree-undetermined").length) {
  4609. $this.parentsUntil(".jstree", "li").addBack().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
  4610. if(rc) { $this.parentsUntil(".jstree", "li").addBack().children(":checkbox").prop("checked", false); }
  4611. return false;
  4612. }
  4613. else {
  4614. $this.removeClass("jstree-checked jstree-undetermined").addClass("jstree-unchecked");
  4615. if(rc) { $this.children(":checkbox").prop("checked", false); }
  4616. }
  4617. }
  4618. else {
  4619. if($this.children("ul").children("li.jstree-unchecked, li.jstree-undetermined").length) {
  4620. $this.parentsUntil(".jstree", "li").addBack().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
  4621. if(rc) { $this.parentsUntil(".jstree", "li").addBack().children(":checkbox").prop("checked", false); }
  4622. return false;
  4623. }
  4624. else {
  4625. $this.removeClass("jstree-unchecked jstree-undetermined").addClass("jstree-checked");
  4626. if(rc) { $this.children(":checkbox").prop("checked", true); }
  4627. }
  4628. }
  4629. });
  4630. }
  4631. if(this.data.ui && this.data.vcheckbox.noui) { this.data.ui.selected = this.get_checked(); }
  4632. this.__callback(obj);
  4633. return true;
  4634. },
  4635. check_node : function (obj) {
  4636. if(this.change_state(obj, false)) {
  4637. obj = this._get_node(obj);
  4638. if(this._get_settings().vcheckbox.checked_parent_open) {
  4639. var t = this;
  4640. obj.parents(".jstree-closed").each(function () { t.open_node(this, false, true); });
  4641. }
  4642. this.__callback({ "obj" : obj });
  4643. }
  4644. },
  4645. uncheck_node : function (obj) {
  4646. if(this.change_state(obj, true)) { this.__callback({ "obj" : this._get_node(obj) }); }
  4647. },
  4648. check_all : function () {
  4649. var _this = this,
  4650. coll = this._get_settings().vcheckbox.two_state ? this.get_container_ul().find("li") : this.get_container_ul().children("li");
  4651. coll.each(function () {
  4652. _this.change_state(this, false);
  4653. });
  4654. this.__callback();
  4655. },
  4656. uncheck_all : function () {
  4657. var _this = this,
  4658. coll = this._get_settings().vcheckbox.two_state ? this.get_container_ul().find("li") : this.get_container_ul().children("li");
  4659. coll.each(function () {
  4660. _this.change_state(this, true);
  4661. });
  4662. this.__callback();
  4663. },
  4664. is_checked : function(obj) {
  4665. obj = this._get_node(obj);
  4666. return obj.length ? obj.is(".jstree-checked") : false;
  4667. },
  4668. get_checked : function (obj, get_all) {
  4669. obj = !obj || obj === -1 ? this.get_container() : this._get_node(obj);
  4670. return get_all || this._get_settings().vcheckbox.two_state ? obj.find(".jstree-checked") : obj.find("> ul > .jstree-checked, .jstree-undetermined > ul > .jstree-checked");
  4671. },
  4672. get_unchecked : function (obj, get_all) {
  4673. obj = !obj || obj === -1 ? this.get_container() : this._get_node(obj);
  4674. return get_all || this._get_settings().vcheckbox.two_state ? obj.find(".jstree-unchecked") : obj.find("> ul > .jstree-unchecked, .jstree-undetermined > ul > .jstree-unchecked");
  4675. },
  4676. show_checkboxes : function () { this.get_container().children("ul").removeClass("jstree-no-checkboxes"); },
  4677. hide_checkboxes : function () { this.get_container().children("ul").addClass("jstree-no-checkboxes"); },
  4678. _repair_state : function (obj) {
  4679. obj = this._get_node(obj);
  4680. if(!obj.length) { return; }
  4681. if(this._get_settings().vcheckbox.two_state) {
  4682. obj.find('li').addBack().not('.jstree-checked').removeClass('jstree-undetermined').addClass('jstree-unchecked').children(':checkbox').prop('checked', true);
  4683. return;
  4684. }
  4685. var rc = this._get_settings().vcheckbox.real_checkboxes,
  4686. a = obj.find("> ul > .jstree-checked").length,
  4687. b = obj.find("> ul > .jstree-undetermined").length,
  4688. c = obj.find("> ul > li").length;
  4689. if(c === 0) { if(obj.hasClass("jstree-undetermined")) { this.change_state(obj, false); } }
  4690. else if(a === 0 && b === 0) { this.change_state(obj, true); }
  4691. else if(a === c) { this.change_state(obj, false); }
  4692. else {
  4693. obj.parentsUntil(".jstree","li").addBack().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
  4694. if(rc) { obj.parentsUntil(".jstree", "li").addBack().children(":checkbox").prop("checked", false); }
  4695. }
  4696. },
  4697. reselect : function () {
  4698. if(this.data.ui && this.data.vcheckbox.noui) {
  4699. var _this = this,
  4700. s = this.data.ui.to_select;
  4701. s = $.map($.makeArray(s), function (n) { return "#" + n.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:"); });
  4702. this.deselect_all();
  4703. $.each(s, function (i, val) { _this.check_node(val); });
  4704. this.__callback();
  4705. }
  4706. else {
  4707. this.__call_old();
  4708. }
  4709. },
  4710. save_loaded : function () {
  4711. var _this = this;
  4712. this.data.core.to_load = [];
  4713. this.get_container_ul().find("li.jstree-closed.jstree-undetermined").each(function () {
  4714. if(this.id) { _this.data.core.to_load.push("#" + this.id); }
  4715. });
  4716. }
  4717. }
  4718. });
  4719. $(function() {
  4720. var css_string = '.jstree .jstree-real-checkbox { display:none; } ';
  4721. $.vakata.css.add_sheet({ str : css_string, title : "jstree" });
  4722. });
  4723. })(jQuery);
  4724. })();
  4725. }));