jquery.jstree.js 180 KB

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