jquery.jstree.js 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534
  1. /*
  2. The MIT License (MIT)
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. /*
  20. * jsTree 1.0-rc1
  21. * http://jstree.com/
  22. *
  23. * Copyright (c) 2010 Ivan Bozhanov (vakata.com)
  24. *
  25. * Dual licensed under the MIT and GPL licenses (same as jQuery):
  26. * http://www.opensource.org/licenses/mit-license.php
  27. * http://www.gnu.org/licenses/gpl.html
  28. *
  29. * Date: 2010-07-01 10:51:11 +0300 (четв, 01 юли 2010) $
  30. * Revision: 191 $
  31. */
  32. /*jslint browser: true, onevar: true, undef: true, bitwise: true, strict: true */
  33. /*global window : false, clearInterval: false, clearTimeout: false, document: false, setInterval: false, setTimeout: false, jQuery: false, navigator: false, XSLTProcessor: false, DOMParser: false, XMLSerializer: false*/
  34. "use strict";
  35. // Common functions not related to jsTree
  36. // decided to move them to a `vakata` "namespace"
  37. (function ($) {
  38. $.vakata = {};
  39. // CSS related functions
  40. $.vakata.css = {
  41. get_css : function(rule_name, delete_flag, sheet) {
  42. rule_name = rule_name.toLowerCase();
  43. var css_rules = sheet.cssRules || sheet.rules,
  44. j = 0;
  45. do {
  46. if(css_rules.length && j > css_rules.length + 5) { return false; }
  47. if(css_rules[j].selectorText && css_rules[j].selectorText.toLowerCase() == rule_name) {
  48. if(delete_flag === true) {
  49. if(sheet.removeRule) { sheet.removeRule(j); }
  50. if(sheet.deleteRule) { sheet.deleteRule(j); }
  51. return true;
  52. }
  53. else { return css_rules[j]; }
  54. }
  55. }
  56. while (css_rules[++j]);
  57. return false;
  58. },
  59. add_css : function(rule_name, sheet) {
  60. if($.jstree.css.get_css(rule_name, false, sheet)) { return false; }
  61. if(sheet.insertRule) { sheet.insertRule(rule_name + ' { }', 0); } else { sheet.addRule(rule_name, null, 0); }
  62. return $.vakata.css.get_css(rule_name);
  63. },
  64. remove_css : function(rule_name, sheet) {
  65. return $.vakata.css.get_css(rule_name, true, sheet);
  66. },
  67. add_sheet : function(opts) {
  68. var tmp;
  69. if(opts.str) {
  70. tmp = document.createElement("style");
  71. tmp.setAttribute('type',"text/css");
  72. if(tmp.styleSheet) {
  73. document.getElementsByTagName("head")[0].appendChild(tmp);
  74. tmp.styleSheet.cssText = opts.str;
  75. }
  76. else {
  77. tmp.appendChild(document.createTextNode(opts.str));
  78. document.getElementsByTagName("head")[0].appendChild(tmp);
  79. }
  80. return tmp.sheet || tmp.styleSheet;
  81. }
  82. if(opts.url) {
  83. if(document.createStyleSheet) {
  84. try { tmp = document.createStyleSheet(opts.url); } catch (e) { }
  85. }
  86. else {
  87. tmp = document.createElement('link');
  88. tmp.rel = 'stylesheet';
  89. tmp.type = 'text/css';
  90. tmp.media = "all";
  91. tmp.href = opts.url;
  92. document.getElementsByTagName("head")[0].appendChild(tmp);
  93. return tmp.styleSheet;
  94. }
  95. }
  96. }
  97. };
  98. })(jQuery);
  99. /*
  100. * jsTree core 1.0
  101. */
  102. (function ($) {
  103. // private variables
  104. var instances = [], // instance array (used by $.jstree.reference/create/focused)
  105. focused_instance = -1, // the index in the instance array of the currently focused instance
  106. plugins = {}, // list of included plugins
  107. prepared_move = {}, // for the move plugin
  108. is_ie6 = false;
  109. // jQuery plugin wrapper (thanks to jquery UI widget function)
  110. $.fn.jstree = function (settings) {
  111. var isMethodCall = (typeof settings == 'string'), // is this a method call like $().jstree("open_node")
  112. args = Array.prototype.slice.call(arguments, 1),
  113. returnValue = this;
  114. // extend settings and allow for multiple hashes and metadata
  115. if(!isMethodCall && $.meta) { args.push($.metadata.get(this).jstree); }
  116. settings = !isMethodCall && args.length ? $.extend.apply(null, [true, settings].concat(args)) : settings;
  117. // block calls to "private" methods
  118. if(isMethodCall && settings.substring(0, 1) == '_') { return returnValue; }
  119. // if a method call execute the method on all selected instances
  120. if(isMethodCall) {
  121. this.each(function() {
  122. var instance = instances[$.data(this, "jstree-instance-id")],
  123. methodValue = (instance && $.isFunction(instance[settings])) ? instance[settings].apply(instance, args) : instance;
  124. if(typeof methodValue !== "undefined" && (settings.indexOf("is_" === 0) || (methodValue !== true && methodValue !== false))) { returnValue = methodValue; return false; }
  125. });
  126. }
  127. else {
  128. this.each(function() {
  129. var instance_id = $.data(this, "jstree-instance-id"),
  130. s = false;
  131. // if an instance already exists, destroy it first
  132. if(typeof instance_id !== "undefined" && instances[instance_id]) { instances[instance_id].destroy(); }
  133. // push a new empty object to the instances array
  134. instance_id = parseInt(instances.push({}),10) - 1;
  135. // store the jstree instance id to the container element
  136. $.data(this, "jstree-instance-id", instance_id);
  137. // clean up all plugins
  138. if(!settings) { settings = {}; }
  139. settings.plugins = $.isArray(settings.plugins) ? settings.plugins : $.jstree.defaults.plugins;
  140. if($.inArray("core", settings.plugins) === -1) { settings.plugins.unshift("core"); }
  141. // only unique plugins (NOT WORKING)
  142. // settings.plugins = settings.plugins.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",");
  143. // extend defaults with passed data
  144. s = $.extend(true, {}, $.jstree.defaults, settings);
  145. s.plugins = settings.plugins;
  146. $.each(plugins, function (i, val) { if($.inArray(i, s.plugins) === -1) { s[i] = null; delete s[i]; } });
  147. // push the new object to the instances array (at the same time set the default classes to the container) and init
  148. instances[instance_id] = new $.jstree._instance(instance_id, $(this).addClass("jstree jstree-" + instance_id), s);
  149. // init all activated plugins for this instance
  150. $.each(instances[instance_id]._get_settings().plugins, function (i, val) { instances[instance_id].data[val] = {}; });
  151. $.each(instances[instance_id]._get_settings().plugins, function (i, val) { if(plugins[val]) { plugins[val].__init.apply(instances[instance_id]); } });
  152. // initialize the instance
  153. instances[instance_id].init();
  154. });
  155. }
  156. // return the jquery selection (or if it was a method call that returned a value - the returned value)
  157. return returnValue;
  158. };
  159. // object to store exposed functions and objects
  160. $.jstree = {
  161. defaults : {
  162. plugins : []
  163. },
  164. _focused : function () { return instances[focused_instance] || null; },
  165. _reference : function (needle) {
  166. // get by instance id
  167. if(instances[needle]) { return instances[needle]; }
  168. // get by DOM (if still no luck - return null
  169. var o = $(needle);
  170. if(!o.length && typeof needle === "string") { o = $("#" + needle); }
  171. if(!o.length) { return null; }
  172. return instances[o.closest(".jstree").data("jstree-instance-id")] || null;
  173. },
  174. _instance : function (index, container, settings) {
  175. // for plugins to store data in
  176. this.data = { core : {} };
  177. this.get_settings = function () { return $.extend(true, {}, settings); };
  178. this._get_settings = function () { return settings; };
  179. this.get_index = function () { return index; };
  180. this.get_container = function () { return container; };
  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. // Check if function belongs to the included plugins of this instance
  205. do {
  206. if(func && func.plugin && $.inArray(func.plugin, this._get_settings().plugins) !== -1) { break; }
  207. func = func.old;
  208. } while(func);
  209. if(!func) { return; }
  210. // a chance to stop execution (or change arguments):
  211. // * just bind to jstree.before
  212. // * check the additional data object (func property)
  213. // * call event.stopImmediatePropagation()
  214. // * return false (or an array of arguments)
  215. rslt = this.get_container().triggerHandler(evnt, { "func" : i, "inst" : this, "args" : args });
  216. if(rslt === false) { return; }
  217. if(typeof rslt !== "undefined") { args = rslt; }
  218. // context and function to trigger events, then finally call the function
  219. if(i.indexOf("_") === 0) {
  220. rslt = func.apply(this, args);
  221. }
  222. else {
  223. rslt = func.apply(
  224. $.extend({}, this, {
  225. __callback : function (data) {
  226. this.get_container().triggerHandler( i + '.jstree', { "inst" : this, "args" : args, "rslt" : data, "rlbk" : rlbk });
  227. },
  228. __rollback : function () {
  229. rlbk = this.get_rollback();
  230. return rlbk;
  231. },
  232. __call_old : function (replace_arguments) {
  233. return func.old.apply(this, (replace_arguments ? Array.prototype.slice.call(arguments, 1) : args ) );
  234. }
  235. }), args);
  236. }
  237. // return the result
  238. return rslt;
  239. };
  240. $.jstree._fn[i].old = val.old;
  241. $.jstree._fn[i].plugin = pname;
  242. });
  243. },
  244. rollback : function (rb) {
  245. if(rb) {
  246. if(!$.isArray(rb)) { rb = [ rb ]; }
  247. $.each(rb, function (i, val) {
  248. instances[val.i].set_rollback(val.h, val.d);
  249. });
  250. }
  251. }
  252. };
  253. // set the prototype for all instances
  254. $.jstree._fn = $.jstree._instance.prototype = {};
  255. // css functions - used internally
  256. // load the css when DOM is ready
  257. $(function() {
  258. // code is copied form jQuery ($.browser is deprecated + there is a bug in IE)
  259. var u = navigator.userAgent.toLowerCase(),
  260. v = (u.match( /.+?(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
  261. css_string = '' +
  262. '.jstree ul, .jstree li { display:block; margin:0 0 0 0; padding:0 0 0 0; list-style-type:none; } ' +
  263. '.jstree li { display:block; min-height:18px; line-height:18px; white-space:nowrap; margin-left:18px; } ' +
  264. '.jstree-rtl li { margin-left:0; margin-right:18px; } ' +
  265. '.jstree > ul > li { margin-left:0px; } ' +
  266. '.jstree-rtl > ul > li { margin-right:0px; } ' +
  267. '.jstree ins { display:inline-block; text-decoration:none; width:18px; height:18px; margin:0 0 0 0; padding:0; } ' +
  268. '.jstree a { display:inline-block; line-height:16px; height:16px; color:black; white-space:nowrap; text-decoration:none; padding:1px 2px; margin:0; } ' +
  269. '.jstree a:focus { outline: none; } ' +
  270. '.jstree a > ins { height:16px; width:16px; } ' +
  271. '.jstree a > .jstree-icon { margin-right:3px; } ' +
  272. '.jstree-rtl a > .jstree-icon { margin-left:3px; margin-right:0; } ' +
  273. 'li.jstree-open > ul { display:block; } ' +
  274. 'li.jstree-closed > ul { display:none; } ';
  275. // Correct IE 6 (does not support the > CSS selector)
  276. if(/msie/.test(u) && parseInt(v, 10) == 6) {
  277. is_ie6 = true;
  278. css_string += '' +
  279. '.jstree li { height:18px; margin-left:0; margin-right:0; } ' +
  280. '.jstree li li { margin-left:18px; } ' +
  281. '.jstree-rtl li li { margin-left:0px; margin-right:18px; } ' +
  282. 'li.jstree-open ul { display:block; } ' +
  283. 'li.jstree-closed ul { display:none !important; } ' +
  284. '.jstree li a { display:inline; border-width:0 !important; padding:0px 2px !important; } ' +
  285. '.jstree li a ins { height:16px; width:16px; margin-right:3px; } ' +
  286. '.jstree-rtl li a ins { margin-right:0px; margin-left:3px; } ';
  287. }
  288. // Correct IE 7 (shifts anchor nodes onhover)
  289. if(/msie/.test(u) && parseInt(v, 10) == 7) {
  290. css_string += '.jstree li a { border-width:0 !important; padding:0px 2px !important; } ';
  291. }
  292. $.vakata.css.add_sheet({ str : css_string });
  293. });
  294. // core functions (open, close, create, update, delete)
  295. $.jstree.plugin("core", {
  296. __init : function () {
  297. this.data.core.to_open = $.map($.makeArray(this.get_settings().core.initially_open), function (n) { return "#" + n.toString().replace(/^#/,"").replace('\\/','/').replace('/','\\/'); });
  298. },
  299. defaults : {
  300. html_titles : false,
  301. animation : 500,
  302. initially_open : [],
  303. rtl : false,
  304. strings : {
  305. loading : "Loading ...",
  306. new_node : "New node"
  307. }
  308. },
  309. _fn : {
  310. init : function () {
  311. this.set_focus();
  312. if(this._get_settings().core.rtl) {
  313. this.get_container().addClass("jstree-rtl").css("direction", "rtl");
  314. }
  315. 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_settings().core.strings.loading + "</a></li></ul>");
  316. this.data.core.li_height = this.get_container().find("ul li.jstree-closed, ul li.jstree-leaf").eq(0).height() || 18;
  317. this.get_container()
  318. .delegate("li > ins", "click.jstree", $.proxy(function (event) {
  319. var trgt = $(event.target);
  320. if(trgt.is("ins") && event.pageY - trgt.offset().top < this.data.core.li_height) { this.toggle_node(trgt); }
  321. }, this))
  322. .bind("mousedown.jstree", $.proxy(function () {
  323. this.set_focus(); // This used to be setTimeout(set_focus,0) - why?
  324. }, this))
  325. .bind("dblclick.jstree", function (event) {
  326. var sel;
  327. if(document.selection && document.selection.empty) { document.selection.empty(); }
  328. else {
  329. if(window.getSelection) {
  330. sel = window.getSelection();
  331. try {
  332. sel.removeAllRanges();
  333. sel.collapse();
  334. } catch (err) { }
  335. }
  336. }
  337. });
  338. this.__callback();
  339. this.load_node(-1, function () { this.loaded(); this.reopen(); });
  340. },
  341. destroy : function () {
  342. var i,
  343. n = this.get_index(),
  344. s = this._get_settings(),
  345. _this = this;
  346. $.each(s.plugins, function (i, val) {
  347. try { plugins[val].__destroy.apply(_this); } catch(err) { }
  348. });
  349. this.__callback();
  350. // set focus to another instance if this one is focused
  351. if(this.is_focused()) {
  352. for(i in instances) {
  353. if(instances.hasOwnProperty(i) && i != n) {
  354. instances[i].set_focus();
  355. break;
  356. }
  357. }
  358. }
  359. // if no other instance found
  360. if(n === focused_instance) { focused_instance = -1; }
  361. // remove all traces of jstree in the DOM (only the ones set using jstree*) and cleans all events
  362. this.get_container()
  363. .unbind(".jstree")
  364. .undelegate(".jstree")
  365. .removeData("jstree-instance-id")
  366. .find("[class^='jstree']")
  367. .andSelf()
  368. .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });
  369. // remove the actual data
  370. instances[n] = null;
  371. delete instances[n];
  372. },
  373. save_opened : function () {
  374. var _this = this;
  375. this.data.core.to_open = [];
  376. this.get_container().find(".jstree-open").each(function () {
  377. _this.data.core.to_open.push("#" + this.id.toString().replace(/^#/,"").replace('\\/','/').replace('/','\\/'));
  378. });
  379. this.__callback(_this.data.core.to_open);
  380. },
  381. reopen : function (is_callback) {
  382. var _this = this,
  383. done = true,
  384. current = [],
  385. remaining = [];
  386. if(!is_callback) { this.data.core.reopen = false; this.data.core.refreshing = true; }
  387. if(this.data.core.to_open.length) {
  388. $.each(this.data.core.to_open, function (i, val) {
  389. if(val == "#") { return true; }
  390. if($(val).length && $(val).is(".jstree-closed")) { current.push(val); }
  391. else { remaining.push(val); }
  392. });
  393. if(current.length) {
  394. this.data.core.to_open = remaining;
  395. $.each(current, function (i, val) {
  396. _this.open_node(val, function () { _this.reopen(true); }, true);
  397. });
  398. done = false;
  399. }
  400. }
  401. if(done) {
  402. // TODO: find a more elegant approach to syncronizing returning requests
  403. if(this.data.core.reopen) { clearTimeout(this.data.core.reopen); }
  404. this.data.core.reopen = setTimeout(function () { _this.__callback({}, _this); }, 50);
  405. this.data.core.refreshing = false;
  406. }
  407. },
  408. refresh : function (obj) {
  409. var _this = this;
  410. this.save_opened();
  411. if(!obj) { obj = -1; }
  412. obj = this._get_node(obj);
  413. if(!obj) { obj = -1; }
  414. if(obj !== -1) { obj.children("UL").remove(); }
  415. this.load_node(obj, function () { _this.__callback({ "obj" : obj}); _this.reopen(); });
  416. },
  417. // Dummy function to fire after the first load (so that there is a jstree.loaded event)
  418. loaded : function () {
  419. this.__callback();
  420. },
  421. // deal with focus
  422. set_focus : function () {
  423. var f = $.jstree._focused();
  424. if(f && f !== this) {
  425. f.get_container().removeClass("jstree-focused");
  426. }
  427. if(f !== this) {
  428. this.get_container().addClass("jstree-focused");
  429. focused_instance = this.get_index();
  430. }
  431. this.__callback();
  432. },
  433. is_focused : function () {
  434. return focused_instance == this.get_index();
  435. },
  436. // traverse
  437. _get_node : function (obj) {
  438. var $obj = $(obj, this.get_container());
  439. if($obj.is(".jstree") || obj == -1) { return -1; }
  440. $obj = $obj.closest("li", this.get_container());
  441. return $obj.length ? $obj : false;
  442. },
  443. _get_next : function (obj, strict) {
  444. obj = this._get_node(obj);
  445. if(obj === -1) { return this.get_container().find("> ul > li:first-child"); }
  446. if(!obj.length) { return false; }
  447. if(strict) { return (obj.nextAll("li").size() > 0) ? obj.nextAll("li:eq(0)") : false; }
  448. if(obj.hasClass("jstree-open")) { return obj.find("li:eq(0)"); }
  449. else if(obj.nextAll("li").size() > 0) { return obj.nextAll("li:eq(0)"); }
  450. else { return obj.parentsUntil(".jstree","li").next("li").eq(0); }
  451. },
  452. _get_prev : function (obj, strict) {
  453. obj = this._get_node(obj);
  454. if(obj === -1) { return this.get_container().find("> ul > li:last-child"); }
  455. if(!obj.length) { return false; }
  456. if(strict) { return (obj.prevAll("li").length > 0) ? obj.prevAll("li:eq(0)") : false; }
  457. if(obj.prev("li").length) {
  458. obj = obj.prev("li").eq(0);
  459. while(obj.hasClass("jstree-open")) { obj = obj.children("ul:eq(0)").children("li:last"); }
  460. return obj;
  461. }
  462. else { var o = obj.parentsUntil(".jstree","li:eq(0)"); return o.length ? o : false; }
  463. },
  464. _get_parent : function (obj) {
  465. obj = this._get_node(obj);
  466. if(obj == -1 || !obj.length) { return false; }
  467. var o = obj.parentsUntil(".jstree", "li:eq(0)");
  468. return o.length ? o : -1;
  469. },
  470. _get_children : function (obj) {
  471. obj = this._get_node(obj);
  472. if(obj === -1) { return this.get_container().children("ul:eq(0)").children("li"); }
  473. if(!obj.length) { return false; }
  474. return obj.children("ul:eq(0)").children("li");
  475. },
  476. get_path : function (obj, id_mode) {
  477. var p = [],
  478. _this = this;
  479. obj = this._get_node(obj);
  480. if(obj === -1 || !obj || !obj.length) { return false; }
  481. obj.parentsUntil(".jstree", "li").each(function () {
  482. p.push( id_mode ? this.id : _this.get_text(this) );
  483. });
  484. p.reverse();
  485. p.push( id_mode ? obj.attr("id") : this.get_text(obj) );
  486. return p;
  487. },
  488. is_open : function (obj) { obj = this._get_node(obj); return obj && obj !== -1 && obj.hasClass("jstree-open"); },
  489. is_closed : function (obj) { obj = this._get_node(obj); return obj && obj !== -1 && obj.hasClass("jstree-closed"); },
  490. is_leaf : function (obj) { obj = this._get_node(obj); return obj && obj !== -1 && obj.hasClass("jstree-leaf"); },
  491. // open/close
  492. open_node : function (obj, callback, skip_animation) {
  493. obj = this._get_node(obj);
  494. if(!obj.length) { return false; }
  495. if(!obj.hasClass("jstree-closed")) { if(callback) { callback.call(); } return false; }
  496. var s = skip_animation || is_ie6 ? 0 : this._get_settings().core.animation,
  497. t = this;
  498. if(!this._is_loaded(obj)) {
  499. obj.children("a").addClass("jstree-loading");
  500. this.load_node(obj, function () { t.open_node(obj, callback, skip_animation); }, callback);
  501. }
  502. else {
  503. if(s) { obj.children("ul").css("display","none"); }
  504. obj.removeClass("jstree-closed").addClass("jstree-open").children("a").removeClass("jstree-loading");
  505. if(s) { obj.children("ul").stop(true).slideDown(s, function () { this.style.display = ""; }); }
  506. this.__callback({ "obj" : obj });
  507. if(callback) { callback.call(); }
  508. }
  509. },
  510. close_node : function (obj, skip_animation) {
  511. obj = this._get_node(obj);
  512. var s = skip_animation || is_ie6 ? 0 : this._get_settings().core.animation;
  513. if(!obj.length || !obj.hasClass("jstree-open")) { return false; }
  514. if(s) { obj.children("ul").attr("style","display:block !important"); }
  515. obj.removeClass("jstree-open").addClass("jstree-closed");
  516. if(s) { obj.children("ul").stop(true).slideUp(s, function () { this.style.display = ""; }); }
  517. this.__callback({ "obj" : obj });
  518. },
  519. toggle_node : function (obj) {
  520. obj = this._get_node(obj);
  521. if(obj.hasClass("jstree-closed")) { return this.open_node(obj); }
  522. if(obj.hasClass("jstree-open")) { return this.close_node(obj); }
  523. },
  524. open_all : function (obj, original_obj) {
  525. obj = obj ? this._get_node(obj) : this.get_container();
  526. if(!obj || obj === -1) { obj = this.get_container(); }
  527. if(original_obj) {
  528. obj = obj.find("li.jstree-closed");
  529. }
  530. else {
  531. original_obj = obj;
  532. if(obj.is(".jstree-closed")) { obj = obj.find("li.jstree-closed").andSelf(); }
  533. else { obj = obj.find("li.jstree-closed"); }
  534. }
  535. var _this = this;
  536. obj.each(function () {
  537. var __this = this;
  538. if(!_this._is_loaded(this)) { _this.open_node(this, function() { _this.open_all(__this, original_obj); }, true); }
  539. else { _this.open_node(this, false, true); }
  540. });
  541. // so that callback is fired AFTER all nodes are open
  542. if(original_obj.find('li.jstree-closed').length === 0) { this.__callback({ "obj" : original_obj }); }
  543. },
  544. close_all : function (obj) {
  545. var _this = this;
  546. obj = obj ? this._get_node(obj) : this.get_container();
  547. if(!obj || obj === -1) { obj = this.get_container(); }
  548. obj.find("li.jstree-open").andSelf().each(function () { _this.close_node(this); });
  549. this.__callback({ "obj" : obj });
  550. },
  551. clean_node : function (obj) {
  552. obj = obj && obj != -1 ? $(obj) : this.get_container();
  553. obj = obj.is("li") ? obj.find("li").andSelf() : obj.find("li");
  554. obj.removeClass("jstree-last")
  555. .filter("li:last-child").addClass("jstree-last").end()
  556. .filter(":has(li)")
  557. .not(".jstree-open").removeClass("jstree-leaf").addClass("jstree-closed");
  558. obj.not(".jstree-open, .jstree-closed").addClass("jstree-leaf").children("ul").remove();
  559. this.__callback({ "obj" : obj });
  560. },
  561. // rollback
  562. get_rollback : function () {
  563. this.__callback();
  564. return { i : this.get_index(), h : this.get_container().children("ul").clone(true), d : this.data };
  565. },
  566. set_rollback : function (html, data) {
  567. this.get_container().empty().append(html);
  568. this.data = data;
  569. this.__callback();
  570. },
  571. // Dummy functions to be overwritten by any datastore plugin included
  572. load_node : function (obj, s_call, e_call) { this.__callback({ "obj" : obj }); },
  573. _is_loaded : function (obj) { return true; },
  574. // Basic operations: create
  575. create_node : function (obj, position, js, callback, is_loaded) {
  576. obj = this._get_node(obj);
  577. position = typeof position === "undefined" ? "last" : position;
  578. var d = $("<li>"),
  579. s = this._get_settings().core,
  580. tmp;
  581. if(obj !== -1 && !obj.length) { return false; }
  582. if(!is_loaded && !this._is_loaded(obj)) { this.load_node(obj, function () { this.create_node(obj, position, js, callback, true); }); return false; }
  583. this.__rollback();
  584. if(typeof js === "string") { js = { "data" : js }; }
  585. if(!js) { js = {}; }
  586. if(js.attr) { d.attr(js.attr); }
  587. if(js.state) { d.addClass("jstree-" + js.state); }
  588. if(!js.data) { js.data = s.strings.new_node; }
  589. if(!$.isArray(js.data)) { tmp = js.data; js.data = []; js.data.push(tmp); }
  590. $.each(js.data, function (i, m) {
  591. tmp = $("<a>");
  592. if($.isFunction(m)) { m = m.call(this, js); }
  593. if(typeof m == "string") { tmp.attr('href','#')[ s.html_titles ? "html" : "text" ](m); }
  594. else {
  595. if(!m.attr) { m.attr = {}; }
  596. if(!m.attr.href) { m.attr.href = '#'; }
  597. tmp.attr(m.attr)[ s.html_titles ? "html" : "text" ](m.title);
  598. if(m.language) { tmp.addClass(m.language); }
  599. }
  600. tmp.prepend("<ins class='jstree-icon'>&#160;</ins>");
  601. if(m.icon) {
  602. if(m.icon.indexOf("/") === -1) { tmp.children("ins").addClass(m.icon); }
  603. else { tmp.children("ins").css("background","url('" + m.icon + "') center center no-repeat"); }
  604. }
  605. d.append(tmp);
  606. });
  607. d.prepend("<ins class='jstree-icon'>&#160;</ins>");
  608. if(obj === -1) {
  609. obj = this.get_container();
  610. if(position === "before") { position = "first"; }
  611. if(position === "after") { position = "last"; }
  612. }
  613. switch(position) {
  614. case "before": obj.before(d); tmp = this._get_parent(obj); break;
  615. case "after" : obj.after(d); tmp = this._get_parent(obj); break;
  616. case "inside":
  617. case "first" :
  618. if(!obj.children("ul").length) { obj.append("<ul>"); }
  619. obj.children("ul").prepend(d);
  620. tmp = obj;
  621. break;
  622. case "last":
  623. if(!obj.children("ul").length) { obj.append("<ul>"); }
  624. obj.children("ul").append(d);
  625. tmp = obj;
  626. break;
  627. default:
  628. if(!obj.children("ul").length) { obj.append("<ul>"); }
  629. if(!position) { position = 0; }
  630. tmp = obj.children("ul").children("li").eq(position);
  631. if(tmp.length) { tmp.before(d); }
  632. else { obj.children("ul").append(d); }
  633. tmp = obj;
  634. break;
  635. }
  636. if(tmp === -1 || tmp.get(0) === this.get_container().get(0)) { tmp = -1; }
  637. this.clean_node(tmp);
  638. this.__callback({ "obj" : d, "parent" : tmp });
  639. if(callback) { callback.call(this, d); }
  640. return d;
  641. },
  642. // Basic operations: rename (deal with text)
  643. get_text : function (obj) {
  644. obj = this._get_node(obj);
  645. if(!obj.length) { return false; }
  646. var s = this._get_settings().core.html_titles;
  647. obj = obj.children("a:eq(0)");
  648. if(s) {
  649. obj = obj.clone();
  650. obj.children("INS").remove();
  651. return obj.html();
  652. }
  653. else {
  654. obj = obj.contents().filter(function() { return this.nodeType == 3; })[0];
  655. return obj.nodeValue;
  656. }
  657. },
  658. set_text : function (obj, val) {
  659. obj = this._get_node(obj);
  660. if(!obj.length) { return false; }
  661. obj = obj.children("a:eq(0)");
  662. if(this._get_settings().core.html_titles) {
  663. var tmp = obj.children("INS").clone();
  664. obj.html(val).prepend(tmp);
  665. this.__callback({ "obj" : obj, "name" : val });
  666. return true;
  667. }
  668. else {
  669. obj = obj.contents().filter(function() { return this.nodeType == 3; })[0];
  670. this.__callback({ "obj" : obj, "name" : val });
  671. return (obj.nodeValue = val);
  672. }
  673. },
  674. rename_node : function (obj, val) {
  675. obj = this._get_node(obj);
  676. this.__rollback();
  677. if(obj && obj.length && this.set_text.apply(this, Array.prototype.slice.call(arguments))) { this.__callback({ "obj" : obj, "name" : val }); }
  678. },
  679. // Basic operations: deleting nodes
  680. delete_node : function (obj) {
  681. obj = this._get_node(obj);
  682. if(!obj.length) { return false; }
  683. this.__rollback();
  684. var p = this._get_parent(obj), prev = this._get_prev(obj);
  685. obj = obj.remove();
  686. if(p !== -1 && p.find("> ul > li").length === 0) {
  687. p.removeClass("jstree-open jstree-closed").addClass("jstree-leaf");
  688. }
  689. this.clean_node(p);
  690. this.__callback({ "obj" : obj, "prev" : prev });
  691. return obj;
  692. },
  693. prepare_move : function (o, r, pos, cb, is_cb) {
  694. var p = {};
  695. p.ot = $.jstree._reference(p.o) || this;
  696. p.o = p.ot._get_node(o);
  697. p.r = r === - 1 ? -1 : this._get_node(r);
  698. p.p = (typeof p === "undefined") ? "last" : pos; // TODO: move to a setting
  699. 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) {
  700. this.__callback(prepared_move);
  701. if(cb) { cb.call(this, prepared_move); }
  702. return;
  703. }
  704. p.ot = $.jstree._reference(p.o) || this;
  705. p.rt = r === -1 ? p.ot : $.jstree._reference(p.r) || this;
  706. if(p.r === -1) {
  707. p.cr = -1;
  708. switch(p.p) {
  709. case "first":
  710. case "before":
  711. case "inside":
  712. p.cp = 0;
  713. break;
  714. case "after":
  715. case "last":
  716. p.cp = p.rt.get_container().find(" > ul > li").length;
  717. break;
  718. default:
  719. p.cp = p.p;
  720. break;
  721. }
  722. }
  723. else {
  724. if(!/^(before|after)$/.test(p.p) && !this._is_loaded(p.r)) {
  725. return this.load_node(p.r, function () { this.prepare_move(o, r, pos, cb, true); });
  726. }
  727. switch(p.p) {
  728. case "before":
  729. p.cp = p.r.index();
  730. p.cr = p.rt._get_parent(p.r);
  731. break;
  732. case "after":
  733. p.cp = p.r.index() + 1;
  734. p.cr = p.rt._get_parent(p.r);
  735. break;
  736. case "inside":
  737. case "first":
  738. p.cp = 0;
  739. p.cr = p.r;
  740. break;
  741. case "last":
  742. p.cp = p.r.find(" > ul > li").length;
  743. p.cr = p.r;
  744. break;
  745. default:
  746. p.cp = p.p;
  747. p.cr = p.r;
  748. break;
  749. }
  750. }
  751. p.np = p.cr == -1 ? p.rt.get_container() : p.cr;
  752. p.op = p.ot._get_parent(p.o);
  753. p.or = p.np.find(" > ul > li:nth-child(" + (p.cp + 1) + ")");
  754. prepared_move = p;
  755. this.__callback(prepared_move);
  756. if(cb) { cb.call(this, prepared_move); }
  757. },
  758. check_move : function () {
  759. var obj = prepared_move, ret = true;
  760. if(obj.or[0] === obj.o[0]) { return false; }
  761. obj.o.each(function () {
  762. if(obj.r.parentsUntil(".jstree").andSelf().filter("li").index(this) !== -1) { ret = false; return false; }
  763. });
  764. return ret;
  765. },
  766. move_node : function (obj, ref, position, is_copy, is_prepared, skip_check) {
  767. if(!is_prepared) {
  768. return this.prepare_move(obj, ref, position, function (p) {
  769. this.move_node(p, false, false, is_copy, true, skip_check);
  770. });
  771. }
  772. if(!skip_check && !this.check_move()) { return false; }
  773. this.__rollback();
  774. var o = false;
  775. if(is_copy) {
  776. o = obj.o.clone();
  777. o.find("*[id]").andSelf().each(function () {
  778. if(this.id) { this.id = "copy_" + this.id; }
  779. });
  780. }
  781. else { o = obj.o; }
  782. if(obj.or.length) { obj.or.before(o); }
  783. else {
  784. if(!obj.np.children("ul").length) { $("<ul>").appendTo(obj.np); }
  785. obj.np.children("ul:eq(0)").append(o);
  786. }
  787. try {
  788. obj.ot.clean_node(obj.op);
  789. obj.rt.clean_node(obj.np);
  790. if(!obj.op.find("> ul > li").length) {
  791. obj.op.removeClass("jstree-open jstree-closed").addClass("jstree-leaf").children("ul").remove();
  792. }
  793. } catch (e) { }
  794. if(is_copy) {
  795. prepared_move.cy = true;
  796. prepared_move.oc = o;
  797. }
  798. this.__callback(prepared_move);
  799. return prepared_move;
  800. },
  801. _get_move : function () { return prepared_move; }
  802. }
  803. });
  804. })(jQuery);
  805. //*/
  806. /*
  807. * jsTree ui plugin 1.0
  808. * This plugins handles selecting/deselecting/hovering/dehovering nodes
  809. */
  810. (function ($) {
  811. $.jstree.plugin("ui", {
  812. __init : function () {
  813. this.data.ui.selected = $();
  814. this.data.ui.last_selected = false;
  815. this.data.ui.hovered = null;
  816. this.data.ui.to_select = this.get_settings().ui.initially_select;
  817. this.get_container()
  818. .delegate("a", "click.jstree", $.proxy(function (event) {
  819. event.preventDefault();
  820. this.select_node(event.currentTarget, true, event);
  821. }, this))
  822. .delegate("a", "mouseenter.jstree", $.proxy(function (event) {
  823. this.hover_node(event.target);
  824. }, this))
  825. .delegate("a", "mouseleave.jstree", $.proxy(function (event) {
  826. this.dehover_node(event.target);
  827. }, this))
  828. .bind("reopen.jstree", $.proxy(function () {
  829. this.reselect();
  830. }, this))
  831. .bind("get_rollback.jstree", $.proxy(function () {
  832. this.dehover_node();
  833. this.save_selected();
  834. }, this))
  835. .bind("set_rollback.jstree", $.proxy(function () {
  836. this.reselect();
  837. }, this))
  838. .bind("close_node.jstree", $.proxy(function (event, data) {
  839. var s = this._get_settings().ui,
  840. obj = this._get_node(data.rslt.obj),
  841. clk = (obj && obj.length) ? obj.children("ul").find(".jstree-clicked") : $(),
  842. _this = this;
  843. if(s.selected_parent_close === false || !clk.length) { return; }
  844. clk.each(function () {
  845. _this.deselect_node(this);
  846. if(s.selected_parent_close === "select_parent") { _this.select_node(obj); }
  847. });
  848. }, this))
  849. .bind("delete_node.jstree", $.proxy(function (event, data) {
  850. var s = this._get_settings().ui.select_prev_on_delete,
  851. obj = this._get_node(data.rslt.obj),
  852. clk = (obj && obj.length) ? obj.find(".jstree-clicked") : [],
  853. _this = this;
  854. clk.each(function () { _this.deselect_node(this); });
  855. if(s && clk.length) { this.select_node(data.rslt.prev); }
  856. }, this))
  857. .bind("move_node.jstree", $.proxy(function (event, data) {
  858. if(data.rslt.cy) {
  859. data.rslt.oc.find(".jstree-clicked").removeClass("jstree-clicked");
  860. }
  861. }, this));
  862. },
  863. defaults : {
  864. select_limit : -1, // 0, 1, 2 ... or -1 for unlimited
  865. select_multiple_modifier : "ctrl", // on, or ctrl, shift, alt
  866. selected_parent_close : "select_parent", // false, "deselect", "select_parent"
  867. select_prev_on_delete : true,
  868. disable_selecting_children : false,
  869. initially_select : []
  870. },
  871. _fn : {
  872. _get_node : function (obj, allow_multiple) {
  873. if(typeof obj === "undefined" || obj === null) { return allow_multiple ? this.data.ui.selected : this.data.ui.last_selected; }
  874. var $obj = $(obj, this.get_container());
  875. if($obj.is(".jstree") || obj == -1) { return -1; }
  876. $obj = $obj.closest("li", this.get_container());
  877. return $obj.length ? $obj : false;
  878. },
  879. save_selected : function () {
  880. var _this = this;
  881. this.data.ui.to_select = [];
  882. this.data.ui.selected.each(function () { _this.data.ui.to_select.push("#" + this.id.toString().replace(/^#/,"").replace('\\/','/').replace('/','\\/')); });
  883. this.__callback(this.data.ui.to_select);
  884. },
  885. reselect : function () {
  886. var _this = this,
  887. s = this.data.ui.to_select;
  888. s = $.map($.makeArray(s), function (n) { return "#" + n.toString().replace(/^#/,"").replace('\\/','/').replace('/','\\/'); });
  889. this.deselect_all();
  890. $.each(s, function (i, val) { if(val && val !== "#") { _this.select_node(val); } });
  891. this.__callback();
  892. },
  893. refresh : function (obj) {
  894. this.save_selected();
  895. return this.__call_old();
  896. },
  897. hover_node : function (obj) {
  898. obj = this._get_node(obj);
  899. if(!obj.length) { return false; }
  900. //if(this.data.ui.hovered && obj.get(0) === this.data.ui.hovered.get(0)) { return; }
  901. if(!obj.hasClass("jstree-hovered")) { this.dehover_node(); }
  902. this.data.ui.hovered = obj.children("a").addClass("jstree-hovered").parent();
  903. this.__callback({ "obj" : obj });
  904. },
  905. dehover_node : function () {
  906. var obj = this.data.ui.hovered, p;
  907. if(!obj || !obj.length) { return false; }
  908. p = obj.children("a").removeClass("jstree-hovered").parent();
  909. if(this.data.ui.hovered[0] === p[0]) { this.data.ui.hovered = null; }
  910. this.__callback({ "obj" : obj });
  911. },
  912. select_node : function (obj, check, e) {
  913. obj = this._get_node(obj);
  914. if(obj == -1 || !obj || !obj.length) { return false; }
  915. var s = this._get_settings().ui,
  916. is_multiple = (s.select_multiple_modifier == "on" || (s.select_multiple_modifier !== false && e && e[s.select_multiple_modifier + "Key"])),
  917. is_selected = this.is_selected(obj),
  918. proceed = true;
  919. if(check) {
  920. if(s.disable_selecting_children && is_multiple && obj.parents("li", this.get_container()).children(".jstree-clicked").length) {
  921. return false;
  922. }
  923. proceed = false;
  924. switch(!0) {
  925. case (is_selected && !is_multiple):
  926. this.deselect_all();
  927. is_selected = false;
  928. proceed = true;
  929. break;
  930. case (!is_selected && !is_multiple):
  931. if(s.select_limit == -1 || s.select_limit > 0) {
  932. this.deselect_all();
  933. proceed = true;
  934. }
  935. break;
  936. case (is_selected && is_multiple):
  937. this.deselect_node(obj);
  938. break;
  939. case (!is_selected && is_multiple):
  940. if(s.select_limit == -1 || this.data.ui.selected.length + 1 <= s.select_limit) {
  941. proceed = true;
  942. }
  943. break;
  944. }
  945. }
  946. if(proceed && !is_selected) {
  947. obj.children("a").addClass("jstree-clicked");
  948. this.data.ui.selected = this.data.ui.selected.add(obj);
  949. this.data.ui.last_selected = obj;
  950. this.__callback({ "obj" : obj });
  951. }
  952. },
  953. deselect_node : function (obj) {
  954. obj = this._get_node(obj);
  955. if(!obj.length) { return false; }
  956. if(this.is_selected(obj)) {
  957. obj.children("a").removeClass("jstree-clicked");
  958. this.data.ui.selected = this.data.ui.selected.not(obj);
  959. if(this.data.ui.last_selected.get(0) === obj.get(0)) { this.data.ui.last_selected = this.data.ui.selected.eq(0); }
  960. this.__callback({ "obj" : obj });
  961. }
  962. },
  963. toggle_select : function (obj) {
  964. obj = this._get_node(obj);
  965. if(!obj.length) { return false; }
  966. if(this.is_selected(obj)) { this.deselect_node(obj); }
  967. else { this.select_node(obj); }
  968. },
  969. is_selected : function (obj) { return this.data.ui.selected.index(this._get_node(obj)) >= 0; },
  970. get_selected : function (context) {
  971. return context ? $(context).find(".jstree-clicked").parent() : this.data.ui.selected;
  972. },
  973. deselect_all : function (context) {
  974. if(context) { $(context).find(".jstree-clicked").removeClass("jstree-clicked"); }
  975. else { this.get_container().find(".jstree-clicked").removeClass("jstree-clicked"); }
  976. this.data.ui.selected = $([]);
  977. this.data.ui.last_selected = false;
  978. this.__callback();
  979. }
  980. }
  981. });
  982. // include the selection plugin by default
  983. $.jstree.defaults.plugins.push("ui");
  984. })(jQuery);
  985. //*/
  986. /*
  987. * jsTree CRRM plugin 1.0
  988. * Handles creating/renaming/removing/moving nodes by user interaction.
  989. */
  990. (function ($) {
  991. $.jstree.plugin("crrm", {
  992. __init : function () {
  993. this.get_container()
  994. .bind("move_node.jstree", $.proxy(function (e, data) {
  995. if(this._get_settings().crrm.move.open_onmove) {
  996. var t = this;
  997. data.rslt.np.parentsUntil(".jstree").andSelf().filter(".jstree-closed").each(function () {
  998. t.open_node(this, false, true);
  999. });
  1000. }
  1001. }, this));
  1002. },
  1003. defaults : {
  1004. input_width_limit : 200,
  1005. move : {
  1006. always_copy : false, // false, true or "multitree"
  1007. open_onmove : true,
  1008. default_position : "last",
  1009. check_move : function (m) { return true; }
  1010. }
  1011. },
  1012. _fn : {
  1013. _show_input : function (obj, callback) {
  1014. obj = this._get_node(obj);
  1015. var rtl = this._get_settings().core.rtl,
  1016. w = this._get_settings().crrm.input_width_limit,
  1017. w1 = obj.children("ins").width(),
  1018. w2 = obj.find("> a:visible > ins").width() * obj.find("> a:visible > ins").length,
  1019. t = this.get_text(obj),
  1020. h1 = $("<div>", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo("body"),
  1021. h2 = obj.css("position","relative").append(
  1022. $("<input>", {
  1023. "value" : t,
  1024. // "size" : t.length,
  1025. "css" : {
  1026. "padding" : "0",
  1027. "border" : "1px solid silver",
  1028. "position" : "absolute",
  1029. "left" : (rtl ? "auto" : (w1 + w2 + 4) + "px"),
  1030. "right" : (rtl ? (w1 + w2 + 4) + "px" : "auto"),
  1031. "top" : "0px",
  1032. "height" : (this.data.core.li_height - 2) + "px",
  1033. "lineHeight" : (this.data.core.li_height - 2) + "px",
  1034. "width" : "150px" // will be set a bit further down
  1035. },
  1036. "blur" : $.proxy(function () {
  1037. var i = obj.children("input"),
  1038. v = i.val();
  1039. if(v === "") { v = t; }
  1040. i.remove(); // rollback purposes
  1041. this.set_text(obj,t); // rollback purposes
  1042. this.rename_node(obj, v);
  1043. callback.call(this, obj, v, t);
  1044. obj.css("position","");
  1045. }, this),
  1046. "keyup" : function (event) {
  1047. var key = event.keyCode || event.which;
  1048. if(key == 27) { this.value = t; this.blur(); return; }
  1049. else if(key == 13) { this.blur(); return; }
  1050. else {
  1051. h2.width(Math.min(h1.text("pW" + this.value).width(),w));
  1052. }
  1053. }
  1054. })
  1055. ).children("input");
  1056. this.set_text(obj, "");
  1057. h1.css({
  1058. fontFamily : h2.css('fontFamily') || '',
  1059. fontSize : h2.css('fontSize') || '',
  1060. fontWeight : h2.css('fontWeight') || '',
  1061. fontStyle : h2.css('fontStyle') || '',
  1062. fontStretch : h2.css('fontStretch') || '',
  1063. fontVariant : h2.css('fontVariant') || '',
  1064. letterSpacing : h2.css('letterSpacing') || '',
  1065. wordSpacing : h2.css('wordSpacing') || ''
  1066. });
  1067. h2.width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
  1068. },
  1069. rename : function (obj) {
  1070. obj = this._get_node(obj);
  1071. this.__rollback();
  1072. var f = this.__callback;
  1073. this._show_input(obj, function (obj, new_name, old_name) {
  1074. f.call(this, { "obj" : obj, "new_name" : new_name, "old_name" : old_name });
  1075. });
  1076. },
  1077. create : function (obj, position, js, callback, skip_rename) {
  1078. var t, _this = this;
  1079. obj = this._get_node(obj);
  1080. if(!obj) { obj = -1; }
  1081. this.__rollback();
  1082. t = this.create_node(obj, position, js, function (t) {
  1083. var p = this._get_parent(t),
  1084. pos = $(t).index();
  1085. if(callback) { callback.call(this, t); }
  1086. if(p.length && p.hasClass("jstree-closed")) { this.open_node(p, false, true); }
  1087. if(!skip_rename) {
  1088. this._show_input(t, function (obj, new_name, old_name) {
  1089. _this.__callback({ "obj" : obj, "name" : new_name, "parent" : p, "position" : pos });
  1090. });
  1091. }
  1092. else { _this.__callback({ "obj" : t, "name" : this.get_text(t), "parent" : p, "position" : pos }); }
  1093. });
  1094. return t;
  1095. },
  1096. remove : function (obj) {
  1097. obj = this._get_node(obj, true);
  1098. this.__rollback();
  1099. this.delete_node(obj);
  1100. this.__callback({ "obj" : obj });
  1101. },
  1102. check_move : function () {
  1103. if(!this.__call_old()) { return false; }
  1104. var s = this._get_settings().crrm.move;
  1105. if(!s.check_move.call(this, this._get_move())) { return false; }
  1106. return true;
  1107. },
  1108. move_node : function (obj, ref, position, is_copy, is_prepared, skip_check) {
  1109. var s = this._get_settings().crrm.move;
  1110. if(!is_prepared) {
  1111. if(!position) { position = s.default_position; }
  1112. if(position === "inside" && !s.default_position.match(/^(before|after)$/)) { position = s.default_position; }
  1113. return this.__call_old(true, obj, ref, position, is_copy, false, skip_check);
  1114. }
  1115. // if the move is already prepared
  1116. if(s.always_copy === true || (s.always_copy === "multitree" && obj.rt.get_index() !== obj.ot.get_index() )) {
  1117. is_copy = true;
  1118. }
  1119. this.__call_old(true, obj, ref, position, is_copy, true, skip_check);
  1120. },
  1121. cut : function (obj) {
  1122. obj = this._get_node(obj);
  1123. this.data.crrm.cp_nodes = false;
  1124. this.data.crrm.ct_nodes = false;
  1125. if(!obj || !obj.length) { return false; }
  1126. this.data.crrm.ct_nodes = obj;
  1127. },
  1128. copy : function (obj) {
  1129. obj = this._get_node(obj);
  1130. this.data.crrm.cp_nodes = false;
  1131. this.data.crrm.ct_nodes = false;
  1132. if(!obj || !obj.length) { return false; }
  1133. this.data.crrm.cp_nodes = obj;
  1134. },
  1135. paste : function (obj) {
  1136. obj = this._get_node(obj);
  1137. if(!obj || !obj.length) { return false; }
  1138. if(!this.data.crrm.ct_nodes && !this.data.crrm.cp_nodes) { return false; }
  1139. if(this.data.crrm.ct_nodes) { this.move_node(this.data.crrm.ct_nodes, obj); }
  1140. if(this.data.crrm.cp_nodes) { this.move_node(this.data.crrm.cp_nodes, obj, false, true); }
  1141. this.data.crrm.cp_nodes = false;
  1142. this.data.crrm.ct_nodes = false;
  1143. }
  1144. }
  1145. });
  1146. // include the crr plugin by default
  1147. $.jstree.defaults.plugins.push("crrm");
  1148. })(jQuery);
  1149. /*
  1150. * jsTree themes plugin 1.0
  1151. * Handles loading and setting themes, as well as detecting path to themes, etc.
  1152. */
  1153. (function ($) {
  1154. var themes_loaded = [];
  1155. // this variable stores the path to the themes folder - if left as false - it will be autodetected
  1156. $.jstree._themes = false;
  1157. $.jstree.plugin("themes", {
  1158. __init : function () {
  1159. this.get_container()
  1160. .bind("init.jstree", $.proxy(function () {
  1161. var s = this._get_settings().themes;
  1162. this.data.themes.dots = s.dots;
  1163. this.data.themes.icons = s.icons;
  1164. //alert(s.dots);
  1165. this.set_theme(s.theme, s.url);
  1166. }, this))
  1167. .bind("loaded.jstree", $.proxy(function () {
  1168. // bound here too, as simple HTML tree's won't honor dots & icons otherwise
  1169. if(!this.data.themes.dots) { this.hide_dots(); }
  1170. else { this.show_dots(); }
  1171. if(!this.data.themes.icons) { this.hide_icons(); }
  1172. else { this.show_icons(); }
  1173. }, this));
  1174. },
  1175. defaults : {
  1176. theme : "default",
  1177. url : false,
  1178. dots : true,
  1179. icons : true
  1180. },
  1181. _fn : {
  1182. set_theme : function (theme_name, theme_url) {
  1183. if(!theme_name) { return false; }
  1184. if(!theme_url) { theme_url = $.jstree._themes + theme_name + '/style.css'; }
  1185. if($.inArray(theme_url, themes_loaded) == -1) {
  1186. $.vakata.css.add_sheet({ "url" : theme_url, "rel" : "jstree" });
  1187. themes_loaded.push(theme_url);
  1188. }
  1189. if(this.data.themes.theme != theme_name) {
  1190. this.get_container().removeClass('jstree-' + this.data.themes.theme);
  1191. this.data.themes.theme = theme_name;
  1192. }
  1193. this.get_container().addClass('jstree-' + theme_name);
  1194. if(!this.data.themes.dots) { this.hide_dots(); }
  1195. else { this.show_dots(); }
  1196. if(!this.data.themes.icons) { this.hide_icons(); }
  1197. else { this.show_icons(); }
  1198. this.__callback();
  1199. },
  1200. get_theme : function () { return this.data.themes.theme; },
  1201. show_dots : function () { this.data.themes.dots = true; this.get_container().children("ul").removeClass("jstree-no-dots"); },
  1202. hide_dots : function () { this.data.themes.dots = false; this.get_container().children("ul").addClass("jstree-no-dots"); },
  1203. toggle_dots : function () { if(this.data.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
  1204. show_icons : function () { this.data.themes.icons = true; this.get_container().children("ul").removeClass("jstree-no-icons"); },
  1205. hide_icons : function () { this.data.themes.icons = false; this.get_container().children("ul").addClass("jstree-no-icons"); },
  1206. toggle_icons: function () { if(this.data.themes.icons) { this.hide_icons(); } else { this.show_icons(); } }
  1207. }
  1208. });
  1209. // autodetect themes path
  1210. $(function () {
  1211. if($.jstree._themes === false) {
  1212. $("script").each(function () {
  1213. if(this.src.toString().match(/jquery\.jstree[^\/]*?\.js(\?.*)?$/)) {
  1214. $.jstree._themes = this.src.toString().replace(/jquery\.jstree[^\/]*?\.js(\?.*)?$/, "") + 'themes/';
  1215. return false;
  1216. }
  1217. });
  1218. }
  1219. if($.jstree._themes === false) { $.jstree._themes = "themes/"; }
  1220. });
  1221. // include the themes plugin by default
  1222. $.jstree.defaults.plugins.push("themes");
  1223. })(jQuery);
  1224. //*/
  1225. /*
  1226. * jsTree hotkeys plugin 1.0
  1227. * Enables keyboard navigation for all tree instances
  1228. * Depends on the jstree ui & jquery hotkeys plugins
  1229. */
  1230. (function ($) {
  1231. var bound = [];
  1232. function exec(i, event) {
  1233. var f = $.jstree._focused(), tmp;
  1234. if(f && f.data && f.data.hotkeys && f.data.hotkeys.enabled) {
  1235. tmp = f._get_settings().hotkeys[i];
  1236. if(tmp) { return tmp.call(f, event); }
  1237. }
  1238. }
  1239. $.jstree.plugin("hotkeys", {
  1240. __init : function () {
  1241. if(typeof $.hotkeys === "undefined") { throw "jsTree hotkeys: jQuery hotkeys plugin not included."; }
  1242. if(!this.data.ui) { throw "jsTree hotkeys: jsTree UI plugin not included."; }
  1243. $.each(this._get_settings().hotkeys, function (i, val) {
  1244. if($.inArray(i, bound) == -1) {
  1245. $(document).bind("keydown", i, function (event) { return exec(i, event); });
  1246. bound.push(i);
  1247. }
  1248. });
  1249. this.enable_hotkeys();
  1250. },
  1251. defaults : {
  1252. "up" : function () {
  1253. var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
  1254. this.hover_node(this._get_prev(o));
  1255. return false;
  1256. },
  1257. "down" : function () {
  1258. var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
  1259. this.hover_node(this._get_next(o));
  1260. return false;
  1261. },
  1262. "left" : function () {
  1263. var o = this.data.ui.hovered || this.data.ui.last_selected;
  1264. if(o) {
  1265. if(o.hasClass("jstree-open")) { this.close_node(o); }
  1266. else { this.hover_node(this._get_prev(o)); }
  1267. }
  1268. return false;
  1269. },
  1270. "right" : function () {
  1271. var o = this.data.ui.hovered || this.data.ui.last_selected;
  1272. if(o && o.length) {
  1273. if(o.hasClass("jstree-closed")) { this.open_node(o); }
  1274. else { this.hover_node(this._get_next(o)); }
  1275. }
  1276. return false;
  1277. },
  1278. "space" : function () {
  1279. if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").click(); }
  1280. return false;
  1281. },
  1282. "ctrl+space" : function (event) {
  1283. event.type = "click";
  1284. if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").trigger(event); }
  1285. return false;
  1286. },
  1287. "f2" : function () { this.rename(this.data.ui.hovered || this.data.ui.last_selected); },
  1288. "del" : function () { this.remove(this.data.ui.hovered || this._get_node(null)); }
  1289. },
  1290. _fn : {
  1291. enable_hotkeys : function () {
  1292. this.data.hotkeys.enabled = true;
  1293. },
  1294. disable_hotkeys : function () {
  1295. this.data.hotkeys.enabled = false;
  1296. }
  1297. }
  1298. });
  1299. })(jQuery);
  1300. //*/
  1301. /*
  1302. * jsTree JSON 1.0
  1303. * The JSON data store. Datastores are build by overriding the `load_node` and `_is_loaded` functions.
  1304. */
  1305. (function ($) {
  1306. $.jstree.plugin("json_data", {
  1307. defaults : {
  1308. data : false,
  1309. ajax : false,
  1310. correct_state : true,
  1311. progressive_render : false
  1312. },
  1313. _fn : {
  1314. load_node : function (obj, s_call, e_call) { var _this = this; this.load_node_json(obj, function () { _this.__callback({ "obj" : obj }); s_call.call(this); }, e_call); },
  1315. _is_loaded : function (obj) {
  1316. var s = this._get_settings().json_data, d;
  1317. obj = this._get_node(obj);
  1318. if(obj && obj !== -1 && s.progressive_render && !obj.is(".jstree-open, .jstree-leaf") && obj.children("ul").children("li").length === 0 && obj.data("jstree-children")) {
  1319. d = this._parse_json(obj.data("jstree-children"));
  1320. if(d) {
  1321. obj.append(d);
  1322. $.removeData(obj, "jstree-children");
  1323. }
  1324. this.clean_node(obj);
  1325. return true;
  1326. }
  1327. return obj == -1 || !obj || !s.ajax || obj.is(".jstree-open, .jstree-leaf") || obj.children("ul").children("li").size() > 0;
  1328. },
  1329. load_node_json : function (obj, s_call, e_call) {
  1330. var s = this.get_settings().json_data, d,
  1331. error_func = function () {},
  1332. success_func = function () {};
  1333. obj = this._get_node(obj);
  1334. if(obj && obj !== -1) {
  1335. if(obj.data("jstree-is-loading")) { return; }
  1336. else { obj.data("jstree-is-loading",true); }
  1337. }
  1338. switch(!0) {
  1339. case (!s.data && !s.ajax): throw "Neither data nor ajax settings supplied.";
  1340. case (!!s.data && !s.ajax) || (!!s.data && !!s.ajax && (!obj || obj === -1)):
  1341. if(!obj || obj == -1) {
  1342. d = this._parse_json(s.data);
  1343. if(d) {
  1344. this.get_container().children("ul").empty().append(d.children());
  1345. this.clean_node();
  1346. }
  1347. else {
  1348. if(s.correct_state) { this.get_container().children("ul").empty(); }
  1349. }
  1350. }
  1351. if(s_call) { s_call.call(this); }
  1352. break;
  1353. case (!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj && obj !== -1):
  1354. error_func = function (x, t, e) {
  1355. var ef = this.get_settings().json_data.ajax.error;
  1356. if(ef) { ef.call(this, x, t, e); }
  1357. if(obj != -1 && obj.length) {
  1358. obj.children(".jstree-loading").removeClass("jstree-loading");
  1359. obj.data("jstree-is-loading",false);
  1360. if(t === "success" && s.correct_state) { obj.removeClass("jstree-open jstree-closed").addClass("jstree-leaf"); }
  1361. }
  1362. else {
  1363. if(t === "success" && s.correct_state) { this.get_container().children("ul").empty(); }
  1364. }
  1365. if(e_call) { e_call.call(this); }
  1366. };
  1367. success_func = function (d, t, x) {
  1368. var sf = this.get_settings().json_data.ajax.success;
  1369. if(sf) { d = sf.call(this,d,t,x) || d; }
  1370. if(d === "" || (!$.isArray(d) && !$.isPlainObject(d))) {
  1371. return error_func.call(this, x, t, "");
  1372. }
  1373. d = this._parse_json(d);
  1374. if(d) {
  1375. if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); }
  1376. else { obj.append(d).children(".jstree-loading").removeClass("jstree-loading"); obj.data("jstree-is-loading",false); }
  1377. this.clean_node(obj);
  1378. if(s_call) { s_call.call(this); }
  1379. }
  1380. else {
  1381. if(obj === -1 || !obj) {
  1382. if(s.correct_state) {
  1383. this.get_container().children("ul").empty();
  1384. if(s_call) { s_call.call(this); }
  1385. }
  1386. }
  1387. else {
  1388. obj.children(".jstree-loading").removeClass("jstree-loading");
  1389. obj.data("jstree-is-loading",false);
  1390. if(s.correct_state) {
  1391. obj.removeClass("jstree-open jstree-closed").addClass("jstree-leaf");
  1392. if(s_call) { s_call.call(this); }
  1393. }
  1394. }
  1395. }
  1396. };
  1397. s.ajax.context = this;
  1398. s.ajax.error = error_func;
  1399. s.ajax.success = success_func;
  1400. if(!s.ajax.dataType) { s.ajax.dataType = "json"; }
  1401. if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); }
  1402. if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); }
  1403. $.ajax(s.ajax);
  1404. break;
  1405. }
  1406. },
  1407. _parse_json : function (js, is_callback) {
  1408. var d = false,
  1409. p = this._get_settings(),
  1410. s = p.json_data,
  1411. t = p.core.html_titles,
  1412. tmp, i, j, ul1, ul2;
  1413. if(!js) { return d; }
  1414. if($.isFunction(js)) {
  1415. js = js.call(this);
  1416. }
  1417. if($.isArray(js)) {
  1418. d = $();
  1419. if(!js.length) { return false; }
  1420. for(i = 0, j = js.length; i < j; i++) {
  1421. tmp = this._parse_json(js[i], true);
  1422. if(tmp.length) { d = d.add(tmp); }
  1423. }
  1424. }
  1425. else {
  1426. if(typeof js == "string") { js = { data : js }; }
  1427. if(!js.data && js.data !== "") { return d; }
  1428. d = $("<li>");
  1429. if(js.attr) { d.attr(js.attr); }
  1430. if(js.metadata) { d.data("jstree", js.metadata); }
  1431. if(js.state) { d.addClass("jstree-" + js.state); }
  1432. if(!$.isArray(js.data)) { tmp = js.data; js.data = []; js.data.push(tmp); }
  1433. $.each(js.data, function (i, m) {
  1434. tmp = $("<a>");
  1435. if($.isFunction(m)) { m = m.call(this, js); }
  1436. if(typeof m == "string") { tmp.attr('href','#')[ t ? "html" : "text" ](m); }
  1437. else {
  1438. if(!m.attr) { m.attr = {}; }
  1439. if(!m.attr.href) { m.attr.href = '#'; }
  1440. tmp.attr(m.attr)[ t ? "html" : "text" ](m.title);
  1441. if(m.language) { tmp.addClass(m.language); }
  1442. }
  1443. tmp.prepend("<ins class='jstree-icon'>&#160;</ins>");
  1444. if(!m.icon && js.icon) { m.icon = js.icon; }
  1445. if(m.icon) {
  1446. if(m.icon.indexOf("/") === -1) { tmp.children("ins").addClass(m.icon); }
  1447. else { tmp.children("ins").css("background","url('" + m.icon + "') center center no-repeat"); }
  1448. }
  1449. d.append(tmp);
  1450. });
  1451. d.prepend("<ins class='jstree-icon'>&#160;</ins>");
  1452. if(js.children) {
  1453. if(s.progressive_render && js.state !== "open") {
  1454. d.addClass("jstree-closed").data("jstree-children", js.children);
  1455. }
  1456. else {
  1457. if($.isFunction(js.children)) {
  1458. js.children = js.children.call(this, js);
  1459. }
  1460. if($.isArray(js.children) && js.children.length) {
  1461. tmp = this._parse_json(js.children, true);
  1462. if(tmp.length) {
  1463. ul2 = $("<ul>");
  1464. ul2.append(tmp);
  1465. d.append(ul2);
  1466. }
  1467. }
  1468. }
  1469. }
  1470. }
  1471. if(!is_callback) {
  1472. ul1 = $("<ul>");
  1473. ul1.append(d);
  1474. d = ul1;
  1475. }
  1476. return d;
  1477. },
  1478. get_json : function (obj, li_attr, a_attr, is_callback) {
  1479. var result = [],
  1480. s = this._get_settings(),
  1481. _this = this,
  1482. tmp1, tmp2, li, a, t, lang;
  1483. obj = this._get_node(obj);
  1484. if(!obj || obj === -1) { obj = this.get_container().find("> ul > li"); }
  1485. li_attr = $.isArray(li_attr) ? li_attr : [ "id", "class" ];
  1486. if(!is_callback && this.data.types) { li_attr.push(s.types.type_attr); }
  1487. a_attr = $.isArray(a_attr) ? a_attr : [ ];
  1488. obj.each(function () {
  1489. li = $(this);
  1490. tmp1 = { data : [] };
  1491. if(li_attr.length) { tmp1.attr = { }; }
  1492. $.each(li_attr, function (i, v) {
  1493. tmp2 = li.attr(v);
  1494. if(tmp2 && tmp2.length && tmp2.replace(/jstree[^ ]*|$/ig,'').length) {
  1495. tmp1.attr[v] = tmp2.replace(/jstree[^ ]*|$/ig,'');
  1496. }
  1497. });
  1498. if(li.hasClass("jstree-open")) { tmp1.state = "open"; }
  1499. if(li.hasClass("jstree-closed")) { tmp1.state = "closed"; }
  1500. a = li.children("a");
  1501. a.each(function () {
  1502. t = $(this);
  1503. if(
  1504. a_attr.length ||
  1505. $.inArray("languages", s.plugins) !== -1 ||
  1506. t.children("ins").get(0).style.backgroundImage.length ||
  1507. (t.children("ins").get(0).className && t.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').length)
  1508. ) {
  1509. lang = false;
  1510. if($.inArray("languages", s.plugins) !== -1 && $.isArray(s.languages) && s.languages.length) {
  1511. $.each(s.languages, function (l, lv) {
  1512. if(t.hasClass(lv)) {
  1513. lang = lv;
  1514. return false;
  1515. }
  1516. });
  1517. }
  1518. tmp2 = { attr : { }, title : _this.get_text(t, lang) };
  1519. $.each(a_attr, function (k, z) {
  1520. tmp1.attr[z] = (t.attr(z) || "").replace(/jstree[^ ]*|$/ig,'');
  1521. });
  1522. $.each(s.languages, function (k, z) {
  1523. if(t.hasClass(z)) { tmp2.language = z; return true; }
  1524. });
  1525. if(t.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/^\s+$/ig,"").length) {
  1526. tmp2.icon = t.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/^\s+$/ig,"");
  1527. }
  1528. if(t.children("ins").get(0).style.backgroundImage.length) {
  1529. tmp2.icon = t.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")","");
  1530. }
  1531. }
  1532. else {
  1533. tmp2 = _this.get_text(t);
  1534. }
  1535. if(a.length > 1) { tmp1.data.push(tmp2); }
  1536. else { tmp1.data = tmp2; }
  1537. });
  1538. li = li.find("> ul > li");
  1539. if(li.length) { tmp1.children = _this.get_json(li, li_attr, a_attr, true); }
  1540. result.push(tmp1);
  1541. });
  1542. return result;
  1543. }
  1544. }
  1545. });
  1546. })(jQuery);
  1547. //*/
  1548. /*
  1549. * jsTree languages plugin 1.0
  1550. * Adds support for multiple language versions in one tree
  1551. * This basically allows for many titles coexisting in one node, but only one of them being visible at any given time
  1552. * This is useful for maintaining the same structure in many languages (hence the name of the plugin)
  1553. */
  1554. (function ($) {
  1555. $.jstree.plugin("languages", {
  1556. __init : function () { this._load_css(); },
  1557. defaults : [],
  1558. _fn : {
  1559. set_lang : function (i) {
  1560. var langs = this._get_settings().languages,
  1561. st = false,
  1562. selector = ".jstree-" + this.get_index() + ' a';
  1563. if(!$.isArray(langs) || langs.length === 0) { return false; }
  1564. if($.inArray(i,langs) == -1) {
  1565. if(!!langs[i]) { i = langs[i]; }
  1566. else { return false; }
  1567. }
  1568. if(i == this.data.languages.current_language) { return true; }
  1569. st = $.vakata.css.get_css(selector + "." + this.data.languages.current_language, false, this.data.languages.language_css);
  1570. if(st !== false) { st.style.display = "none"; }
  1571. st = $.vakata.css.get_css(selector + "." + i, false, this.data.languages.language_css);
  1572. if(st !== false) { st.style.display = ""; }
  1573. this.data.languages.current_language = i;
  1574. this.__callback(i);
  1575. return true;
  1576. },
  1577. get_lang : function () {
  1578. return this.data.languages.current_language;
  1579. },
  1580. get_text : function (obj, lang) {
  1581. obj = this._get_node(obj) || this.data.ui.last_selected;
  1582. if(!obj.size()) { return false; }
  1583. var langs = this._get_settings().languages,
  1584. s = this._get_settings().core.html_titles;
  1585. if($.isArray(langs) && langs.length) {
  1586. lang = (lang && $.inArray(lang,langs) != -1) ? lang : this.data.languages.current_language;
  1587. obj = obj.children("a." + lang);
  1588. }
  1589. else { obj = obj.children("a:eq(0)"); }
  1590. if(s) {
  1591. obj = obj.clone();
  1592. obj.children("INS").remove();
  1593. return obj.html();
  1594. }
  1595. else {
  1596. obj = obj.contents().filter(function() { return this.nodeType == 3; })[0];
  1597. return obj.nodeValue;
  1598. }
  1599. },
  1600. set_text : function (obj, val, lang) {
  1601. obj = this._get_node(obj) || this.data.ui.last_selected;
  1602. if(!obj.size()) { return false; }
  1603. var langs = this._get_settings().languages,
  1604. s = this._get_settings().core.html_titles,
  1605. tmp;
  1606. if($.isArray(langs) && langs.length) {
  1607. lang = (lang && $.inArray(lang,langs) != -1) ? lang : this.data.languages.current_language;
  1608. obj = obj.children("a." + lang);
  1609. }
  1610. else { obj = obj.children("a:eq(0)"); }
  1611. if(s) {
  1612. tmp = obj.children("INS").clone();
  1613. obj.html(val).prepend(tmp);
  1614. this.__callback({ "obj" : obj, "name" : val, "lang" : lang });
  1615. return true;
  1616. }
  1617. else {
  1618. obj = obj.contents().filter(function() { return this.nodeType == 3; })[0];
  1619. this.__callback({ "obj" : obj, "name" : val, "lang" : lang });
  1620. return (obj.nodeValue = val);
  1621. }
  1622. },
  1623. _load_css : function () {
  1624. var langs = this._get_settings().languages,
  1625. str = "/* languages css */",
  1626. selector = ".jstree-" + this.get_index() + ' a',
  1627. ln;
  1628. if($.isArray(langs) && langs.length) {
  1629. this.data.languages.current_language = langs[0];
  1630. for(ln = 0; ln < langs.length; ln++) {
  1631. str += selector + "." + langs[ln] + " {";
  1632. if(langs[ln] != this.data.languages.current_language) { str += " display:none; "; }
  1633. str += " } ";
  1634. }
  1635. this.data.languages.language_css = $.vakata.css.add_sheet({ 'str' : str });
  1636. }
  1637. },
  1638. create_node : function (obj, position, js, callback) {
  1639. var t = this.__call_old(true, obj, position, js, function (t) {
  1640. var langs = this._get_settings().languages,
  1641. a = t.children("a"),
  1642. ln;
  1643. if($.isArray(langs) && langs.length) {
  1644. for(ln = 0; ln < langs.length; ln++) {
  1645. if(!a.is("." + langs[ln])) {
  1646. t.append(a.eq(0).clone().removeClass(langs.join(" ")).addClass(langs[ln]));
  1647. }
  1648. }
  1649. a.not("." + langs.join(", .")).remove();
  1650. }
  1651. if(callback) { callback.call(this, t); }
  1652. });
  1653. return t;
  1654. }
  1655. }
  1656. });
  1657. })(jQuery);
  1658. //*/
  1659. /*
  1660. * jsTree cookies plugin 1.0
  1661. * Stores the currently opened/selected nodes in a cookie and then restores them
  1662. * Depends on the jquery.cookie plugin
  1663. */
  1664. (function ($) {
  1665. $.jstree.plugin("cookies", {
  1666. __init : function () {
  1667. if(typeof $.cookie === "undefined") { throw "jsTree cookie: jQuery cookie plugin not included."; }
  1668. var s = this._get_settings().cookies,
  1669. tmp;
  1670. if(!!s.save_opened) {
  1671. tmp = $.cookie(s.save_opened);
  1672. if(tmp && tmp.length) { this.data.core.to_open = tmp.split(","); }
  1673. }
  1674. if(!!s.save_selected) {
  1675. tmp = $.cookie(s.save_selected);
  1676. if(tmp && tmp.length && this.data.ui) { this.data.ui.to_select = tmp.split(","); }
  1677. }
  1678. this.get_container()
  1679. .one( ( this.data.ui ? "reselect" : "reopen" ) + ".jstree", $.proxy(function () {
  1680. this.get_container()
  1681. .bind("open_node.jstree close_node.jstree select_node.jstree deselect_node.jstree", $.proxy(function (e) {
  1682. if(this._get_settings().cookies.auto_save) { this.save_cookie((e.handleObj.namespace + e.handleObj.type).replace("jstree","")); }
  1683. }, this));
  1684. }, this));
  1685. },
  1686. defaults : {
  1687. save_opened : "jstree_open",
  1688. save_selected : "jstree_select",
  1689. auto_save : true,
  1690. cookie_options : {}
  1691. },
  1692. _fn : {
  1693. save_cookie : function (c) {
  1694. if(this.data.core.refreshing) { return; }
  1695. var s = this._get_settings().cookies;
  1696. if(!c) { // if called manually and not by event
  1697. if(s.save_opened) {
  1698. this.save_opened();
  1699. $.cookie(s.save_opened, this.data.core.to_open.join(","), s.cookie_options);
  1700. }
  1701. if(s.save_selected && this.data.ui) {
  1702. this.save_selected();
  1703. $.cookie(s.save_selected, this.data.ui.to_select.join(","), s.cookie_options);
  1704. }
  1705. return;
  1706. }
  1707. switch(c) {
  1708. case "open_node":
  1709. case "close_node":
  1710. if(!!s.save_opened) {
  1711. this.save_opened();
  1712. $.cookie(s.save_opened, this.data.core.to_open.join(","), s.cookie_options);
  1713. }
  1714. break;
  1715. case "select_node":
  1716. case "deselect_node":
  1717. if(!!s.save_selected && this.data.ui) {
  1718. this.save_selected();
  1719. $.cookie(s.save_selected, this.data.ui.to_select.join(","), s.cookie_options);
  1720. }
  1721. break;
  1722. }
  1723. }
  1724. }
  1725. });
  1726. // include cookies by default
  1727. $.jstree.defaults.plugins.push("cookies");
  1728. })(jQuery);
  1729. //*/
  1730. /*
  1731. * jsTree sort plugin 1.0
  1732. * Sorts items alphabetically (or using any other function)
  1733. */
  1734. (function ($) {
  1735. $.jstree.plugin("sort", {
  1736. __init : function () {
  1737. this.get_container()
  1738. .bind("load_node.jstree", $.proxy(function (e, data) {
  1739. var obj = this._get_node(data.rslt.obj);
  1740. obj = obj === -1 ? this.get_container().children("ul") : obj.children("ul");
  1741. this.sort(obj);
  1742. }, this))
  1743. .bind("rename_node.jstree", $.proxy(function (e, data) {
  1744. this.sort(data.rslt.obj.parent());
  1745. }, this))
  1746. .bind("move_node.jstree", $.proxy(function (e, data) {
  1747. var m = data.rslt.np == -1 ? this.get_container() : data.rslt.np;
  1748. this.sort(m.children("ul"));
  1749. }, this));
  1750. },
  1751. defaults : function (a, b) { return this.get_text(a) > this.get_text(b) ? 1 : -1; },
  1752. _fn : {
  1753. sort : function (obj) {
  1754. var s = this._get_settings().sort,
  1755. t = this;
  1756. obj.append($.makeArray(obj.children("li")).sort($.proxy(s, t)));
  1757. obj.find("> li > ul").each(function() { t.sort($(this)); });
  1758. this.clean_node(obj);
  1759. }
  1760. }
  1761. });
  1762. })(jQuery);
  1763. //*/
  1764. /*
  1765. * jsTree DND plugin 1.0
  1766. * Drag and drop plugin for moving/copying nodes
  1767. */
  1768. (function ($) {
  1769. var o = false,
  1770. r = false,
  1771. m = false,
  1772. sli = false,
  1773. sti = false,
  1774. dir1 = false,
  1775. dir2 = false;
  1776. $.vakata.dnd = {
  1777. is_down : false,
  1778. is_drag : false,
  1779. helper : false,
  1780. scroll_spd : 10,
  1781. init_x : 0,
  1782. init_y : 0,
  1783. threshold : 5,
  1784. user_data : {},
  1785. drag_start : function (e, data, html) {
  1786. if($.vakata.dnd.is_drag) { $.vakata.drag_stop({}); }
  1787. try {
  1788. e.currentTarget.unselectable = "on";
  1789. e.currentTarget.onselectstart = function() { return false; };
  1790. if(e.currentTarget.style) { e.currentTarget.style.MozUserSelect = "none"; }
  1791. } catch(err) { }
  1792. $.vakata.dnd.init_x = e.pageX;
  1793. $.vakata.dnd.init_y = e.pageY;
  1794. $.vakata.dnd.user_data = data;
  1795. $.vakata.dnd.is_down = true;
  1796. $.vakata.dnd.helper = $("<div id='vakata-dragged'>").html(html).css("opacity", "0.75");
  1797. $(document).bind("mousemove", $.vakata.dnd.drag);
  1798. $(document).bind("mouseup", $.vakata.dnd.drag_stop);
  1799. return false;
  1800. },
  1801. drag : function (e) {
  1802. if(!$.vakata.dnd.is_down) { return; }
  1803. if(!$.vakata.dnd.is_drag) {
  1804. if(Math.abs(e.pageX - $.vakata.dnd.init_x) > 5 || Math.abs(e.pageY - $.vakata.dnd.init_y) > 5) {
  1805. $.vakata.dnd.helper.appendTo("body");
  1806. $.vakata.dnd.is_drag = true;
  1807. $(document).triggerHandler("drag_start.vakata", { "event" : e, "data" : $.vakata.dnd.user_data });
  1808. }
  1809. else { return; }
  1810. }
  1811. // maybe use a scrolling parent element instead of document?
  1812. if(e.type === "mousemove") { // thought of adding scroll in order to move the helper, but mouse poisition is n/a
  1813. var d = $(document), t = d.scrollTop(), l = d.scrollLeft();
  1814. if(e.pageY - t < 20) {
  1815. if(sti && dir1 === "down") { clearInterval(sti); sti = false; }
  1816. if(!sti) { dir1 = "up"; sti = setInterval(function () { $(document).scrollTop($(document).scrollTop() - $.vakata.dnd.scroll_spd); }, 150); }
  1817. }
  1818. else {
  1819. if(sti && dir1 === "up") { clearInterval(sti); sti = false; }
  1820. }
  1821. if($(window).height() - (e.pageY - t) < 20) {
  1822. if(sti && dir1 === "up") { clearInterval(sti); sti = false; }
  1823. if(!sti) { dir1 = "down"; sti = setInterval(function () { $(document).scrollTop($(document).scrollTop() + $.vakata.dnd.scroll_spd); }, 150); }
  1824. }
  1825. else {
  1826. if(sti && dir1 === "down") { clearInterval(sti); sti = false; }
  1827. }
  1828. if(e.pageX - l < 20) {
  1829. if(sli && dir2 === "right") { clearInterval(sli); sli = false; }
  1830. if(!sli) { dir2 = "left"; sli = setInterval(function () { $(document).scrollLeft($(document).scrollLeft() - $.vakata.dnd.scroll_spd); }, 150); }
  1831. }
  1832. else {
  1833. if(sli && dir2 === "left") { clearInterval(sli); sli = false; }
  1834. }
  1835. if($(window).width() - (e.pageX - l) < 20) {
  1836. if(sli && dir2 === "left") { clearInterval(sli); sli = false; }
  1837. if(!sli) { dir2 = "right"; sli = setInterval(function () { $(document).scrollLeft($(document).scrollLeft() + $.vakata.dnd.scroll_spd); }, 150); }
  1838. }
  1839. else {
  1840. if(sli && dir2 === "right") { clearInterval(sli); sli = false; }
  1841. }
  1842. }
  1843. $.vakata.dnd.helper.css({ left : (e.pageX + 5) + "px", top : (e.pageY + 10) + "px" });
  1844. $(document).triggerHandler("drag.vakata", { "event" : e, "data" : $.vakata.dnd.user_data });
  1845. },
  1846. drag_stop : function (e) {
  1847. $(document).unbind("mousemove", $.vakata.dnd.drag);
  1848. $(document).unbind("mouseup", $.vakata.dnd.drag_stop);
  1849. $(document).triggerHandler("drag_stop.vakata", { "event" : e, "data" : $.vakata.dnd.user_data });
  1850. $.vakata.dnd.helper.remove();
  1851. $.vakata.dnd.init_x = 0;
  1852. $.vakata.dnd.init_y = 0;
  1853. $.vakata.dnd.user_data = {};
  1854. $.vakata.dnd.is_down = false;
  1855. $.vakata.dnd.is_drag = false;
  1856. }
  1857. };
  1858. $(function() {
  1859. 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; } ';
  1860. $.vakata.css.add_sheet({ str : css_string });
  1861. });
  1862. $.jstree.plugin("dnd", {
  1863. __init : function () {
  1864. this.data.dnd = {
  1865. active : false,
  1866. after : false,
  1867. inside : false,
  1868. before : false,
  1869. off : false,
  1870. prepared : false,
  1871. w : 0,
  1872. to1 : false,
  1873. to2 : false,
  1874. cof : false,
  1875. cw : false,
  1876. ch : false,
  1877. i1 : false,
  1878. i2 : false
  1879. };
  1880. this.get_container()
  1881. .bind("mouseenter.jstree", $.proxy(function () {
  1882. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree && this.data.themes) {
  1883. m.attr("class", "jstree-" + this.data.themes.theme);
  1884. $.vakata.dnd.helper.attr("class", "jstree-dnd-helper jstree-" + this.data.themes.theme);
  1885. }
  1886. }, this))
  1887. .bind("mouseleave.jstree", $.proxy(function () {
  1888. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  1889. if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
  1890. if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
  1891. }
  1892. }, this))
  1893. .bind("mousemove.jstree", $.proxy(function (e) {
  1894. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  1895. var cnt = this.get_container()[0];
  1896. // Horizontal scroll
  1897. if(e.pageX + 24 > this.data.dnd.cof.left + this.data.dnd.cw) {
  1898. if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
  1899. this.data.dnd.i1 = setInterval($.proxy(function () { this.scrollLeft += $.vakata.dnd.scroll_spd; }, cnt), 100);
  1900. }
  1901. else if(e.pageX - 24 < this.data.dnd.cof.left) {
  1902. if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
  1903. this.data.dnd.i1 = setInterval($.proxy(function () { this.scrollLeft -= $.vakata.dnd.scroll_spd; }, cnt), 100);
  1904. }
  1905. else {
  1906. if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
  1907. }
  1908. // Vertical scroll
  1909. if(e.pageY + 24 > this.data.dnd.cof.top + this.data.dnd.ch) {
  1910. if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
  1911. this.data.dnd.i2 = setInterval($.proxy(function () { this.scrollTop += $.vakata.dnd.scroll_spd; }, cnt), 100);
  1912. }
  1913. else if(e.pageY - 24 < this.data.dnd.cof.top) {
  1914. if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
  1915. this.data.dnd.i2 = setInterval($.proxy(function () { this.scrollTop -= $.vakata.dnd.scroll_spd; }, cnt), 100);
  1916. }
  1917. else {
  1918. if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
  1919. }
  1920. }
  1921. }, this))
  1922. .delegate("a", "mousedown.jstree", $.proxy(function (e) {
  1923. if(e.which === 1) {
  1924. this.start_drag(e.currentTarget, e);
  1925. return false;
  1926. }
  1927. }, this))
  1928. .delegate("a", "mouseenter.jstree", $.proxy(function (e) {
  1929. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  1930. this.dnd_enter(e.currentTarget);
  1931. }
  1932. }, this))
  1933. .delegate("a", "mousemove.jstree", $.proxy(function (e) {
  1934. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  1935. if(typeof this.data.dnd.off.top === "undefined") { this.data.dnd.off = $(e.target).offset(); }
  1936. this.data.dnd.w = (e.pageY - (this.data.dnd.off.top || 0)) % this.data.core.li_height;
  1937. if(this.data.dnd.w < 0) { this.data.dnd.w += this.data.core.li_height; }
  1938. this.dnd_show();
  1939. }
  1940. }, this))
  1941. .delegate("a", "mouseleave.jstree", $.proxy(function (e) {
  1942. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  1943. this.data.dnd.after = false;
  1944. this.data.dnd.before = false;
  1945. this.data.dnd.inside = false;
  1946. $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid");
  1947. m.hide();
  1948. if(r && r[0] === e.target.parentNode) {
  1949. if(this.data.dnd.to1) {
  1950. clearTimeout(this.data.dnd.to1);
  1951. this.data.dnd.to1 = false;
  1952. }
  1953. if(this.data.dnd.to2) {
  1954. clearTimeout(this.data.dnd.to2);
  1955. this.data.dnd.to2 = false;
  1956. }
  1957. }
  1958. }
  1959. }, this))
  1960. .delegate("a", "mouseup.jstree", $.proxy(function (e) {
  1961. if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) {
  1962. this.dnd_finish(e);
  1963. }
  1964. }, this));
  1965. $(document)
  1966. .bind("drag_stop.vakata", $.proxy(function () {
  1967. this.data.dnd.after = false;
  1968. this.data.dnd.before = false;
  1969. this.data.dnd.inside = false;
  1970. this.data.dnd.off = false;
  1971. this.data.dnd.prepared = false;
  1972. this.data.dnd.w = false;
  1973. this.data.dnd.to1 = false;
  1974. this.data.dnd.to2 = false;
  1975. this.data.dnd.active = false;
  1976. this.data.dnd.foreign = false;
  1977. if(m) { m.css({ "top" : "-2000px" }); }
  1978. }, this))
  1979. .bind("drag_start.vakata", $.proxy(function (e, data) {
  1980. if(data.data.jstree) {
  1981. var et = $(data.event.target);
  1982. if(et.closest(".jstree").hasClass("jstree-" + this.get_index())) {
  1983. this.dnd_enter(et);
  1984. }
  1985. }
  1986. }, this));
  1987. var s = this._get_settings().dnd;
  1988. if(s.drag_target) {
  1989. $(document)
  1990. .delegate(s.drag_target, "mousedown.jstree", $.proxy(function (e) {
  1991. o = e.target;
  1992. $.vakata.dnd.drag_start(e, { jstree : true, obj : e.target }, "<ins class='jstree-icon'></ins>" + $(e.target).text() );
  1993. if(this.data.themes) {
  1994. m.attr("class", "jstree-" + this.data.themes.theme);
  1995. $.vakata.dnd.helper.attr("class", "jstree-dnd-helper jstree-" + this.data.themes.theme);
  1996. }
  1997. $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid");
  1998. var cnt = this.get_container();
  1999. this.data.dnd.cof = cnt.offset();
  2000. this.data.dnd.cw = parseInt(cnt.width(),10);
  2001. this.data.dnd.ch = parseInt(cnt.height(),10);
  2002. this.data.dnd.foreign = true;
  2003. return false;
  2004. }, this));
  2005. }
  2006. if(s.drop_target) {
  2007. $(document)
  2008. .delegate(s.drop_target, "mouseenter.jstree", $.proxy(function (e) {
  2009. if(this.data.dnd.active && this._get_settings().dnd.drop_check.call(this, { "o" : o, "r" : $(e.target) })) {
  2010. $.vakata.dnd.helper.children("ins").attr("class","jstree-ok");
  2011. }
  2012. }, this))
  2013. .delegate(s.drop_target, "mouseleave.jstree", $.proxy(function (e) {
  2014. if(this.data.dnd.active) {
  2015. $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid");
  2016. }
  2017. }, this))
  2018. .delegate(s.drop_target, "mouseup.jstree", $.proxy(function (e) {
  2019. if(this.data.dnd.active && $.vakata.dnd.helper.children("ins").hasClass("jstree-ok")) {
  2020. this._get_settings().dnd.drop_finish.call(this, { "o" : o, "r" : $(e.target) });
  2021. }
  2022. }, this));
  2023. }
  2024. },
  2025. defaults : {
  2026. copy_modifier : "ctrl",
  2027. check_timeout : 200,
  2028. open_timeout : 500,
  2029. drop_target : ".jstree-drop",
  2030. drop_check : function (data) { return true; },
  2031. drop_finish : $.noop,
  2032. drag_target : ".jstree-draggable",
  2033. drag_finish : $.noop,
  2034. drag_check : function (data) { return { after : false, before : false, inside : true }; }
  2035. },
  2036. _fn : {
  2037. dnd_prepare : function () {
  2038. if(!r || !r.length) { return; }
  2039. this.data.dnd.off = r.offset();
  2040. if(this._get_settings().core.rtl) {
  2041. this.data.dnd.off.right = this.data.dnd.off.left + r.width();
  2042. }
  2043. if(this.data.dnd.foreign) {
  2044. var a = this._get_settings().dnd.drag_check.call(this, { "o" : o, "r" : r });
  2045. this.data.dnd.after = a.after;
  2046. this.data.dnd.before = a.before;
  2047. this.data.dnd.inside = a.inside;
  2048. this.data.dnd.prepared = true;
  2049. return this.dnd_show();
  2050. }
  2051. this.prepare_move(o, r, "before");
  2052. this.data.dnd.before = this.check_move();
  2053. this.prepare_move(o, r, "after");
  2054. this.data.dnd.after = this.check_move();
  2055. if(this._is_loaded(r)) {
  2056. this.prepare_move(o, r, "inside");
  2057. this.data.dnd.inside = this.check_move();
  2058. }
  2059. else {
  2060. this.data.dnd.inside = false;
  2061. }
  2062. this.data.dnd.prepared = true;
  2063. return this.dnd_show();
  2064. },
  2065. dnd_show : function () {
  2066. if(!this.data.dnd.prepared) { return; }
  2067. var o = ["before","inside","after"],
  2068. r = false,
  2069. rtl = this._get_settings().core.rtl,
  2070. pos;
  2071. if(this.data.dnd.w < this.data.core.li_height/3) { o = ["before","inside","after"]; }
  2072. else if(this.data.dnd.w <= this.data.core.li_height*2/3) {
  2073. o = this.data.dnd.w < this.data.core.li_height/2 ? ["inside","before","after"] : ["inside","after","before"];
  2074. }
  2075. else { o = ["after","inside","before"]; }
  2076. $.each(o, $.proxy(function (i, val) {
  2077. if(this.data.dnd[val]) {
  2078. $.vakata.dnd.helper.children("ins").attr("class","jstree-ok");
  2079. r = val;
  2080. return false;
  2081. }
  2082. }, this));
  2083. if(r === false) { $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid"); }
  2084. pos = rtl ? (this.data.dnd.off.right - 18) : (this.data.dnd.off.left + 10);
  2085. switch(r) {
  2086. case "before":
  2087. m.css({ "left" : pos + "px", "top" : (this.data.dnd.off.top - 6) + "px" }).show();
  2088. break;
  2089. case "after":
  2090. m.css({ "left" : pos + "px", "top" : (this.data.dnd.off.top + this.data.core.li_height - 7) + "px" }).show();
  2091. break;
  2092. case "inside":
  2093. m.css({ "left" : pos + ( rtl ? -4 : 4) + "px", "top" : (this.data.dnd.off.top + this.data.core.li_height/2 - 5) + "px" }).show();
  2094. break;
  2095. default:
  2096. m.hide();
  2097. break;
  2098. }
  2099. return r;
  2100. },
  2101. dnd_open : function () {
  2102. this.data.dnd.to2 = false;
  2103. this.open_node(r, $.proxy(this.dnd_prepare,this), true);
  2104. },
  2105. dnd_finish : function (e) {
  2106. if(this.data.dnd.foreign) {
  2107. if(this.data.dnd.after || this.data.dnd.before || this.data.dnd.inside) {
  2108. this._get_settings().dnd.drag_finish.call(this, { "o" : o, "r" : r });
  2109. }
  2110. }
  2111. else {
  2112. this.dnd_prepare();
  2113. this.move_node(o, r, this.dnd_show(), e[this._get_settings().dnd.copy_modifier + "Key"]);
  2114. }
  2115. o = false;
  2116. r = false;
  2117. m.hide();
  2118. },
  2119. dnd_enter : function (obj) {
  2120. var s = this._get_settings().dnd;
  2121. this.data.dnd.prepared = false;
  2122. r = this._get_node(obj);
  2123. if(s.check_timeout) {
  2124. // do the calculations after a minimal timeout (users tend to drag quickly to the desired location)
  2125. if(this.data.dnd.to1) { clearTimeout(this.data.dnd.to1); }
  2126. this.data.dnd.to1 = setTimeout($.proxy(this.dnd_prepare, this), s.check_timeout);
  2127. }
  2128. else {
  2129. this.dnd_prepare();
  2130. }
  2131. if(s.open_timeout) {
  2132. if(this.data.dnd.to2) { clearTimeout(this.data.dnd.to2); }
  2133. if(r && r.length && r.hasClass("jstree-closed")) {
  2134. // if the node is closed - open it, then recalculate
  2135. this.data.dnd.to2 = setTimeout($.proxy(this.dnd_open, this), s.open_timeout);
  2136. }
  2137. }
  2138. else {
  2139. if(r && r.length && r.hasClass("jstree-closed")) {
  2140. this.dnd_open();
  2141. }
  2142. }
  2143. },
  2144. start_drag : function (obj, e) {
  2145. o = this._get_node(obj);
  2146. if(this.data.ui && this.is_selected(o)) { o = this._get_node(null, true); }
  2147. $.vakata.dnd.drag_start(e, { jstree : true, obj : o }, "<ins class='jstree-icon'></ins>" + (o.length > 1 ? "Multiple selection" : this.get_text(o)) );
  2148. if(this.data.themes) {
  2149. m.attr("class", "jstree-" + this.data.themes.theme);
  2150. $.vakata.dnd.helper.attr("class", "jstree-dnd-helper jstree-" + this.data.themes.theme);
  2151. }
  2152. var cnt = this.get_container();
  2153. this.data.dnd.cof = cnt.children("ul").offset();
  2154. this.data.dnd.cw = parseInt(cnt.width(),10);
  2155. this.data.dnd.ch = parseInt(cnt.height(),10);
  2156. this.data.dnd.active = true;
  2157. }
  2158. }
  2159. });
  2160. $(function() {
  2161. var css_string = '' +
  2162. '#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; } ' +
  2163. '#vakata-dragged .jstree-ok { background:green; } ' +
  2164. '#vakata-dragged .jstree-invalid { background:red; } ' +
  2165. '#jstree-marker { padding:0; margin:0; line-height:12px; font-size:1px; overflow:hidden; height:12px; width:8px; position:absolute; top:-30px; z-index:10000; background-repeat:no-repeat; display:none; background-color:silver; } ';
  2166. $.vakata.css.add_sheet({ str : css_string });
  2167. m = $("<div>").attr({ id : "jstree-marker" }).hide().appendTo("body");
  2168. $(document).bind("drag_start.vakata", function (e, data) {
  2169. if(data.data.jstree) {
  2170. m.show();
  2171. }
  2172. });
  2173. $(document).bind("drag_stop.vakata", function (e, data) {
  2174. if(data.data.jstree) { m.hide(); }
  2175. });
  2176. });
  2177. })(jQuery);
  2178. //*/
  2179. /*
  2180. * jsTree checkbox plugin 1.0
  2181. * Inserts checkboxes in front of every node
  2182. * Depends on the ui plugin
  2183. * DOES NOT WORK NICELY WITH MULTITREE DRAG'N'DROP
  2184. */
  2185. (function ($) {
  2186. $.jstree.plugin("checkbox", {
  2187. __init : function () {
  2188. this.select_node = this.deselect_node = this.deselect_all = $.noop;
  2189. this.get_selected = this.get_checked;
  2190. this.get_container()
  2191. .bind("open_node.jstree create_node.jstree clean_node.jstree", $.proxy(function (e, data) {
  2192. this._prepare_checkboxes(data.rslt.obj);
  2193. }, this))
  2194. .bind("loaded.jstree", $.proxy(function (e) {
  2195. this._prepare_checkboxes();
  2196. }, this))
  2197. .delegate("a", "click.jstree", $.proxy(function (e) {
  2198. if(this._get_node(e.target).hasClass("jstree-checked")) { this.uncheck_node(e.target); }
  2199. else { this.check_node(e.target); }
  2200. if(this.data.ui) { this.save_selected(); }
  2201. if(this.data.cookies) { this.save_cookie("select_node"); }
  2202. e.preventDefault();
  2203. }, this));
  2204. },
  2205. __destroy : function () {
  2206. this.get_container().find(".jstree-checkbox").remove();
  2207. },
  2208. _fn : {
  2209. _prepare_checkboxes : function (obj) {
  2210. obj = !obj || obj == -1 ? this.get_container() : this._get_node(obj);
  2211. var c, _this = this, t;
  2212. obj.each(function () {
  2213. t = $(this);
  2214. c = t.is("li") && t.hasClass("jstree-checked") ? "jstree-checked" : "jstree-unchecked";
  2215. t.find("a").not(":has(.jstree-checkbox)").prepend("<ins class='jstree-checkbox'>&#160;</ins>").parent().not(".jstree-checked, .jstree-unchecked").addClass(c);
  2216. });
  2217. if(obj.is("li")) { this._repair_state(obj); }
  2218. else { obj.find("> ul > li").each(function () { _this._repair_state(this); }); }
  2219. },
  2220. change_state : function (obj, state) {
  2221. obj = this._get_node(obj);
  2222. state = (state === false || state === true) ? state : obj.hasClass("jstree-checked");
  2223. if(state) { obj.find("li").andSelf().removeClass("jstree-checked jstree-undetermined").addClass("jstree-unchecked"); }
  2224. else {
  2225. obj.find("li").andSelf().removeClass("jstree-unchecked jstree-undetermined").addClass("jstree-checked");
  2226. if(this.data.ui) { this.data.ui.last_selected = obj; }
  2227. this.data.checkbox.last_selected = obj;
  2228. }
  2229. obj.parentsUntil(".jstree", "li").each(function () {
  2230. var $this = $(this);
  2231. if(state) {
  2232. if($this.children("ul").children(".jstree-checked, .jstree-undetermined").length) {
  2233. $this.parentsUntil(".jstree", "li").andSelf().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
  2234. return false;
  2235. }
  2236. else {
  2237. $this.removeClass("jstree-checked jstree-undetermined").addClass("jstree-unchecked");
  2238. }
  2239. }
  2240. else {
  2241. if($this.children("ul").children(".jstree-unchecked, .jstree-undetermined").length) {
  2242. $this.parentsUntil(".jstree", "li").andSelf().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
  2243. return false;
  2244. }
  2245. else {
  2246. $this.removeClass("jstree-unchecked jstree-undetermined").addClass("jstree-checked");
  2247. }
  2248. }
  2249. });
  2250. if(this.data.ui) { this.data.ui.selected = this.get_checked(); }
  2251. this.__callback(obj);
  2252. },
  2253. check_node : function (obj) {
  2254. this.change_state(obj, false);
  2255. },
  2256. uncheck_node : function (obj) {
  2257. this.change_state(obj, true);
  2258. },
  2259. check_all : function () {
  2260. var _this = this;
  2261. this.get_container().children("ul").children("li").each(function () {
  2262. _this.check_node(this, false);
  2263. });
  2264. },
  2265. uncheck_all : function () {
  2266. var _this = this;
  2267. this.get_container().children("ul").children("li").each(function () {
  2268. _this.change_state(this, true);
  2269. });
  2270. },
  2271. is_checked : function(obj) {
  2272. obj = this._get_node(obj);
  2273. return obj.length ? obj.is(".jstree-checked") : false;
  2274. },
  2275. get_checked : function (obj) {
  2276. obj = !obj || obj === -1 ? this.get_container() : this._get_node(obj);
  2277. return obj.find("> ul > .jstree-checked, .jstree-undetermined > ul > .jstree-checked");
  2278. },
  2279. get_unchecked : function (obj) {
  2280. obj = !obj || obj === -1 ? this.get_container() : this._get_node(obj);
  2281. return obj.find("> ul > .jstree-unchecked, .jstree-undetermined > ul > .jstree-unchecked");
  2282. },
  2283. show_checkboxes : function () { this.get_container().children("ul").removeClass("jstree-no-checkboxes"); },
  2284. hide_checkboxes : function () { this.get_container().children("ul").addClass("jstree-no-checkboxes"); },
  2285. _repair_state : function (obj) {
  2286. obj = this._get_node(obj);
  2287. if(!obj.length) { return; }
  2288. var a = obj.find("> ul > .jstree-checked").length,
  2289. b = obj.find("> ul > .jstree-undetermined").length,
  2290. c = obj.find("> ul > li").length;
  2291. if(c === 0) { if(obj.hasClass("jstree-undetermined")) { this.check_node(obj); } }
  2292. else if(a === 0 && b === 0) { this.uncheck_node(obj); }
  2293. else if(a === c) { this.check_node(obj); }
  2294. else {
  2295. obj.parentsUntil(".jstree","li").removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
  2296. }
  2297. },
  2298. reselect : function () {
  2299. if(this.data.ui) {
  2300. var _this = this,
  2301. s = this.data.ui.to_select;
  2302. s = $.map($.makeArray(s), function (n) { return "#" + n.toString().replace(/^#/,"").replace('\\/','/').replace('/','\\/'); });
  2303. this.deselect_all();
  2304. $.each(s, function (i, val) { _this.check_node(val); });
  2305. this.__callback();
  2306. }
  2307. }
  2308. }
  2309. });
  2310. })(jQuery);
  2311. //*/
  2312. /*
  2313. * jsTree XML 1.0
  2314. * The XML data store. Datastores are build by overriding the `load_node` and `_is_loaded` functions.
  2315. */
  2316. (function ($) {
  2317. $.vakata.xslt = function (xml, xsl, callback) {
  2318. var rs = "", xm, xs, processor, support;
  2319. if(document.recalc) {
  2320. xm = document.createElement('xml');
  2321. xs = document.createElement('xml');
  2322. xm.innerHTML = xml;
  2323. xs.innerHTML = xsl;
  2324. $("body").append(xm).append(xs);
  2325. setTimeout( (function (xm, xs, callback) {
  2326. return function () {
  2327. callback.call(null, xm.transformNode(xs.XMLDocument));
  2328. setTimeout( (function (xm, xs) { return function () { jQuery("body").remove(xm).remove(xs); }; })(xm, xs), 200);
  2329. };
  2330. }) (xm, xs, callback), 100);
  2331. return true;
  2332. }
  2333. if(typeof window.DOMParser !== "undefined" && typeof window.XMLHttpRequest !== "undefined" && typeof window.XSLTProcessor !== "undefined") {
  2334. processor = new XSLTProcessor();
  2335. support = $.isFunction(processor.transformDocument) ? (typeof window.XMLSerializer !== "undefined") : true;
  2336. if(!support) { return false; }
  2337. xml = new DOMParser().parseFromString(xml, "text/xml");
  2338. xsl = new DOMParser().parseFromString(xsl, "text/xml");
  2339. if($.isFunction(processor.transformDocument)) {
  2340. rs = document.implementation.createDocument("", "", null);
  2341. processor.transformDocument(xml, xsl, rs, null);
  2342. callback.call(null, XMLSerializer().serializeToString(rs));
  2343. return true;
  2344. }
  2345. else {
  2346. processor.importStylesheet(xsl);
  2347. rs = processor.transformToFragment(xml, document);
  2348. callback.call(null, $("<div>").append(rs).html());
  2349. return true;
  2350. }
  2351. }
  2352. return false;
  2353. };
  2354. var xsl = {
  2355. 'nest' : '<?xml version="1.0" encoding="utf-8" ?>' +
  2356. '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >' +
  2357. '<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/html" />' +
  2358. '<xsl:template match="/">' +
  2359. ' <xsl:call-template name="nodes">' +
  2360. ' <xsl:with-param name="node" select="/root" />' +
  2361. ' </xsl:call-template>' +
  2362. '</xsl:template>' +
  2363. '<xsl:template name="nodes">' +
  2364. ' <xsl:param name="node" />' +
  2365. ' <ul>' +
  2366. ' <xsl:for-each select="$node/item">' +
  2367. ' <xsl:variable name="children" select="count(./item) &gt; 0" />' +
  2368. ' <li>' +
  2369. ' <xsl:attribute name="class">' +
  2370. ' <xsl:if test="position() = last()">jstree-last </xsl:if>' +
  2371. ' <xsl:choose>' +
  2372. ' <xsl:when test="@state = \'open\'">jstree-open </xsl:when>' +
  2373. ' <xsl:when test="$children or @hasChildren or @state = \'closed\'">jstree-closed </xsl:when>' +
  2374. ' <xsl:otherwise>jstree-leaf </xsl:otherwise>' +
  2375. ' </xsl:choose>' +
  2376. ' <xsl:value-of select="@class" />' +
  2377. ' </xsl:attribute>' +
  2378. ' <xsl:for-each select="@*">' +
  2379. ' <xsl:if test="name() != \'class\' and name() != \'state\' and name() != \'hasChildren\'">' +
  2380. ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' +
  2381. ' </xsl:if>' +
  2382. ' </xsl:for-each>' +
  2383. ' <ins class="jstree-icon"><xsl:text>&#xa0;</xsl:text></ins>' +
  2384. ' <xsl:for-each select="content/name">' +
  2385. ' <a>' +
  2386. ' <xsl:attribute name="href">' +
  2387. ' <xsl:choose>' +
  2388. ' <xsl:when test="@href"><xsl:value-of select="@href" /></xsl:when>' +
  2389. ' <xsl:otherwise>#</xsl:otherwise>' +
  2390. ' </xsl:choose>' +
  2391. ' </xsl:attribute>' +
  2392. ' <xsl:attribute name="class"><xsl:value-of select="@lang" /> <xsl:value-of select="@class" /></xsl:attribute>' +
  2393. ' <xsl:attribute name="style"><xsl:value-of select="@style" /></xsl:attribute>' +
  2394. ' <xsl:for-each select="@*">' +
  2395. ' <xsl:if test="name() != \'style\' and name() != \'class\' and name() != \'href\'">' +
  2396. ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' +
  2397. ' </xsl:if>' +
  2398. ' </xsl:for-each>' +
  2399. ' <ins>' +
  2400. ' <xsl:attribute name="class">jstree-icon ' +
  2401. ' <xsl:if test="string-length(attribute::icon) > 0 and not(contains(@icon,\'/\'))"><xsl:value-of select="@icon" /></xsl:if>' +
  2402. ' </xsl:attribute>' +
  2403. ' <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>' +
  2404. ' <xsl:text>&#xa0;</xsl:text>' +
  2405. ' </ins>' +
  2406. ' <xsl:value-of select="current()" />' +
  2407. ' </a>' +
  2408. ' </xsl:for-each>' +
  2409. ' <xsl:if test="$children or @hasChildren"><xsl:call-template name="nodes"><xsl:with-param name="node" select="current()" /></xsl:call-template></xsl:if>' +
  2410. ' </li>' +
  2411. ' </xsl:for-each>' +
  2412. ' </ul>' +
  2413. '</xsl:template>' +
  2414. '</xsl:stylesheet>',
  2415. 'flat' : '<?xml version="1.0" encoding="utf-8" ?>' +
  2416. '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >' +
  2417. '<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/xml" />' +
  2418. '<xsl:template match="/">' +
  2419. ' <ul>' +
  2420. ' <xsl:for-each select="//item[not(@parent_id) or @parent_id=0 or not(@parent_id = //item/@id)]">' + /* the last `or` may be removed */
  2421. ' <xsl:call-template name="nodes">' +
  2422. ' <xsl:with-param name="node" select="." />' +
  2423. ' <xsl:with-param name="is_last" select="number(position() = last())" />' +
  2424. ' </xsl:call-template>' +
  2425. ' </xsl:for-each>' +
  2426. ' </ul>' +
  2427. '</xsl:template>' +
  2428. '<xsl:template name="nodes">' +
  2429. ' <xsl:param name="node" />' +
  2430. ' <xsl:param name="is_last" />' +
  2431. ' <xsl:variable name="children" select="count(//item[@parent_id=$node/attribute::id]) &gt; 0" />' +
  2432. ' <li>' +
  2433. ' <xsl:attribute name="class">' +
  2434. ' <xsl:if test="$is_last = true()">jstree-last </xsl:if>' +
  2435. ' <xsl:choose>' +
  2436. ' <xsl:when test="@state = \'open\'">jstree-open </xsl:when>' +
  2437. ' <xsl:when test="$children or @hasChildren or @state = \'closed\'">jstree-closed </xsl:when>' +
  2438. ' <xsl:otherwise>jstree-leaf </xsl:otherwise>' +
  2439. ' </xsl:choose>' +
  2440. ' <xsl:value-of select="@class" />' +
  2441. ' </xsl:attribute>' +
  2442. ' <xsl:for-each select="@*">' +
  2443. ' <xsl:if test="name() != \'parent_id\' and name() != \'hasChildren\' and name() != \'class\' and name() != \'state\'">' +
  2444. ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' +
  2445. ' </xsl:if>' +
  2446. ' </xsl:for-each>' +
  2447. ' <ins class="jstree-icon"><xsl:text>&#xa0;</xsl:text></ins>' +
  2448. ' <xsl:for-each select="content/name">' +
  2449. ' <a>' +
  2450. ' <xsl:attribute name="href">' +
  2451. ' <xsl:choose>' +
  2452. ' <xsl:when test="@href"><xsl:value-of select="@href" /></xsl:when>' +
  2453. ' <xsl:otherwise>#</xsl:otherwise>' +
  2454. ' </xsl:choose>' +
  2455. ' </xsl:attribute>' +
  2456. ' <xsl:attribute name="class"><xsl:value-of select="@lang" /> <xsl:value-of select="@class" /></xsl:attribute>' +
  2457. ' <xsl:attribute name="style"><xsl:value-of select="@style" /></xsl:attribute>' +
  2458. ' <xsl:for-each select="@*">' +
  2459. ' <xsl:if test="name() != \'style\' and name() != \'class\' and name() != \'href\'">' +
  2460. ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' +
  2461. ' </xsl:if>' +
  2462. ' </xsl:for-each>' +
  2463. ' <ins>' +
  2464. ' <xsl:attribute name="class">jstree-icon ' +
  2465. ' <xsl:if test="string-length(attribute::icon) > 0 and not(contains(@icon,\'/\'))"><xsl:value-of select="@icon" /></xsl:if>' +
  2466. ' </xsl:attribute>' +
  2467. ' <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>' +
  2468. ' <xsl:text>&#xa0;</xsl:text>' +
  2469. ' </ins>' +
  2470. ' <xsl:value-of select="current()" />' +
  2471. ' </a>' +
  2472. ' </xsl:for-each>' +
  2473. ' <xsl:if test="$children">' +
  2474. ' <ul>' +
  2475. ' <xsl:for-each select="//item[@parent_id=$node/attribute::id]">' +
  2476. ' <xsl:call-template name="nodes">' +
  2477. ' <xsl:with-param name="node" select="." />' +
  2478. ' <xsl:with-param name="is_last" select="number(position() = last())" />' +
  2479. ' </xsl:call-template>' +
  2480. ' </xsl:for-each>' +
  2481. ' </ul>' +
  2482. ' </xsl:if>' +
  2483. ' </li>' +
  2484. '</xsl:template>' +
  2485. '</xsl:stylesheet>'
  2486. };
  2487. $.jstree.plugin("xml_data", {
  2488. defaults : {
  2489. data : false,
  2490. ajax : false,
  2491. xsl : "flat",
  2492. clean_node : false,
  2493. correct_state : true
  2494. },
  2495. _fn : {
  2496. load_node : function (obj, s_call, e_call) { var _this = this; this.load_node_xml(obj, function () { _this.__callback({ "obj" : obj }); s_call.call(this); }, e_call); },
  2497. _is_loaded : function (obj) {
  2498. var s = this._get_settings().xml_data;
  2499. obj = this._get_node(obj);
  2500. return obj == -1 || !obj || !s.ajax || obj.is(".jstree-open, .jstree-leaf") || obj.children("ul").children("li").size() > 0;
  2501. },
  2502. load_node_xml : function (obj, s_call, e_call) {
  2503. var s = this.get_settings().xml_data,
  2504. error_func = function () {},
  2505. success_func = function () {};
  2506. obj = this._get_node(obj);
  2507. if(obj && obj !== -1) {
  2508. if(obj.data("jstree-is-loading")) { return; }
  2509. else { obj.data("jstree-is-loading",true); }
  2510. }
  2511. switch(!0) {
  2512. case (!s.data && !s.ajax): throw "Neither data nor ajax settings supplied.";
  2513. case (!!s.data && !s.ajax) || (!!s.data && !!s.ajax && (!obj || obj === -1)):
  2514. if(!obj || obj == -1) {
  2515. this.parse_xml(s.data, $.proxy(function (d) {
  2516. if(d) {
  2517. d = d.replace(/ ?xmlns="[^"]*"/ig, "");
  2518. if(d.length > 10) {
  2519. d = $(d);
  2520. this.get_container().children("ul").empty().append(d.children());
  2521. if(s.clean_node) { this.clean_node(obj); }
  2522. if(s_call) { s_call.call(this); }
  2523. }
  2524. }
  2525. else {
  2526. if(s.correct_state) {
  2527. this.get_container().children("ul").empty();
  2528. if(s_call) { s_call.call(this); }
  2529. }
  2530. }
  2531. }, this));
  2532. }
  2533. break;
  2534. case (!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj && obj !== -1):
  2535. error_func = function (x, t, e) {
  2536. var ef = this.get_settings().xml_data.ajax.error;
  2537. if(ef) { ef.call(this, x, t, e); }
  2538. if(obj !== -1 && obj.length) {
  2539. obj.children(".jstree-loading").removeClass("jstree-loading");
  2540. obj.data("jstree-is-loading",false);
  2541. if(t === "success" && s.correct_state) { obj.removeClass("jstree-open jstree-closed").addClass("jstree-leaf"); }
  2542. }
  2543. else {
  2544. if(t === "success" && s.correct_state) { this.get_container().children("ul").empty(); }
  2545. }
  2546. if(e_call) { e_call.call(this); }
  2547. };
  2548. success_func = function (d, t, x) {
  2549. d = x.responseText;
  2550. var sf = this.get_settings().xml_data.ajax.success;
  2551. if(sf) { d = sf.call(this,d,t,x) || d; }
  2552. if(d == "") {
  2553. return error_func.call(this, x, t, "");
  2554. }
  2555. this.parse_xml(d, $.proxy(function (d) {
  2556. if(d) {
  2557. d = d.replace(/ ?xmlns="[^"]*"/ig, "");
  2558. if(d.length > 10) {
  2559. d = $(d);
  2560. if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); }
  2561. else { obj.children(".jstree-loading").removeClass("jstree-loading"); obj.append(d); obj.data("jstree-is-loading",false); }
  2562. if(s.clean_node) { this.clean_node(obj); }
  2563. if(s_call) { s_call.call(this); }
  2564. }
  2565. else {
  2566. if(obj && obj !== -1) {
  2567. obj.children(".jstree-loading").removeClass("jstree-loading");
  2568. obj.data("jstree-is-loading",false);
  2569. if(s.correct_state) {
  2570. obj.removeClass("jstree-open jstree-closed").addClass("jstree-leaf");
  2571. if(s_call) { s_call.call(this); }
  2572. }
  2573. }
  2574. else {
  2575. if(s.correct_state) {
  2576. this.get_container().children("ul").empty();
  2577. if(s_call) { s_call.call(this); }
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }, this));
  2583. };
  2584. s.ajax.context = this;
  2585. s.ajax.error = error_func;
  2586. s.ajax.success = success_func;
  2587. if(!s.ajax.dataType) { s.ajax.dataType = "xml"; }
  2588. if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); }
  2589. if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); }
  2590. $.ajax(s.ajax);
  2591. break;
  2592. }
  2593. },
  2594. parse_xml : function (xml, callback) {
  2595. var s = this._get_settings().xml_data;
  2596. $.vakata.xslt(xml, xsl[s.xsl], callback);
  2597. },
  2598. get_xml : function (tp, obj, li_attr, a_attr, is_callback) {
  2599. var result = "",
  2600. s = this._get_settings(),
  2601. _this = this,
  2602. tmp1, tmp2, li, a, lang;
  2603. if(!tp) { tp = "flat"; }
  2604. if(!is_callback) { is_callback = 0; }
  2605. obj = this._get_node(obj);
  2606. if(!obj || obj === -1) { obj = this.get_container().find("> ul > li"); }
  2607. li_attr = $.isArray(li_attr) ? li_attr : [ "id", "class" ];
  2608. if(!is_callback && this.data.types && $.inArray(s.types.type_attr, li_attr) === -1) { li_attr.push(s.types.type_attr); }
  2609. a_attr = $.isArray(a_attr) ? a_attr : [ ];
  2610. if(!is_callback) { result += "<root>"; }
  2611. obj.each(function () {
  2612. result += "<item";
  2613. li = $(this);
  2614. $.each(li_attr, function (i, v) { result += " " + v + "=\"" + (li.attr(v) || "").replace(/jstree[^ ]*|$/ig,'').replace(/^\s+$/ig,"") + "\""; });
  2615. if(li.hasClass("jstree-open")) { result += " state=\"open\""; }
  2616. if(li.hasClass("jstree-closed")) { result += " state=\"closed\""; }
  2617. if(tp === "flat") { result += " parent_id=\"" + is_callback + "\""; }
  2618. result += ">";
  2619. result += "<content>";
  2620. a = li.children("a");
  2621. a.each(function () {
  2622. tmp1 = $(this);
  2623. lang = false;
  2624. result += "<name";
  2625. if($.inArray("languages", s.plugins) !== -1) {
  2626. $.each(s.languages, function (k, z) {
  2627. if(tmp1.hasClass(z)) { result += " lang=\"" + z + "\""; lang = z; return false; }
  2628. });
  2629. }
  2630. if(a_attr.length) {
  2631. $.each(a_attr, function (k, z) {
  2632. result += " " + z + "=\"" + (tmp1.attr(z) || "").replace(/jstree[^ ]*|$/ig,'') + "\"";
  2633. });
  2634. }
  2635. if(tmp1.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/^\s+$/ig,"").length) {
  2636. result += ' icon="' + tmp1.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/^\s+$/ig,"") + '"';
  2637. }
  2638. if(tmp1.children("ins").get(0).style.backgroundImage.length) {
  2639. result += ' icon="' + tmp1.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")","") + '"';
  2640. }
  2641. result += ">";
  2642. result += "<![CDATA[" + _this.get_text(tmp1, lang) + "]]>";
  2643. result += "</name>";
  2644. });
  2645. result += "</content>";
  2646. tmp2 = li[0].id;
  2647. li = li.find("> ul > li");
  2648. if(li.length) { tmp2 = _this.get_xml(tp, li, li_attr, a_attr, tmp2); }
  2649. else { tmp2 = ""; }
  2650. if(tp == "nest") { result += tmp2; }
  2651. result += "</item>";
  2652. if(tp == "flat") { result += tmp2; }
  2653. });
  2654. if(!is_callback) { result += "</root>"; }
  2655. return result;
  2656. }
  2657. }
  2658. });
  2659. })(jQuery);
  2660. //*/
  2661. /*
  2662. * jsTree search plugin 1.0
  2663. * Enables both sync and async search on the tree
  2664. * DOES NOT WORK WITH JSON PROGRESSIVE RENDER
  2665. */
  2666. (function ($) {
  2667. $.expr[':'].jstree_contains = function(a,i,m){
  2668. return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase())>=0;
  2669. };
  2670. $.jstree.plugin("search", {
  2671. __init : function () {
  2672. this.data.search.str = "";
  2673. this.data.search.result = $();
  2674. },
  2675. defaults : {
  2676. ajax : false, // OR ajax object
  2677. case_insensitive : false
  2678. },
  2679. _fn : {
  2680. search : function (str, skip_async) {
  2681. if(str === "") { return; }
  2682. var s = this.get_settings().search,
  2683. t = this,
  2684. error_func = function () { },
  2685. success_func = function () { };
  2686. this.data.search.str = str;
  2687. if(!skip_async && s.ajax !== false && this.get_container().find(".jstree-closed:eq(0)").length > 0) {
  2688. this.search.supress_callback = true;
  2689. error_func = function () { };
  2690. success_func = function (d, t, x) {
  2691. var sf = this.get_settings().search.ajax.success;
  2692. if(sf) { d = sf.call(this,d,t,x) || d; }
  2693. this.data.search.to_open = d;
  2694. this._search_open();
  2695. };
  2696. s.ajax.context = this;
  2697. s.ajax.error = error_func;
  2698. s.ajax.success = success_func;
  2699. if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, str); }
  2700. if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, str); }
  2701. if(!s.ajax.data) { s.ajax.data = { "search_string" : str }; }
  2702. if(!s.ajax.dataType || /^json/.exec(s.ajax.dataType)) { s.ajax.dataType = "json"; }
  2703. $.ajax(s.ajax);
  2704. return;
  2705. }
  2706. if(this.data.search.result.length) { this.clear_search(); }
  2707. this.data.search.result = this.get_container().find("a" + (this.data.languages ? "." + this.get_lang() : "" ) + ":" + (s.case_insensitive ? "jstree_contains" : "contains") + "(" + this.data.search.str + ")");
  2708. this.data.search.result.addClass("jstree-search").parents(".jstree-closed").each(function () {
  2709. t.open_node(this, false, true);
  2710. });
  2711. this.__callback({ nodes : this.data.search.result, str : str });
  2712. },
  2713. clear_search : function (str) {
  2714. this.data.search.result.removeClass("jstree-search");
  2715. this.__callback(this.data.search.result);
  2716. this.data.search.result = $();
  2717. },
  2718. _search_open : function (is_callback) {
  2719. var _this = this,
  2720. done = true,
  2721. current = [],
  2722. remaining = [];
  2723. if(this.data.search.to_open.length) {
  2724. $.each(this.data.search.to_open, function (i, val) {
  2725. if(val == "#") { return true; }
  2726. if($(val).length && $(val).is(".jstree-closed")) { current.push(val); }
  2727. else { remaining.push(val); }
  2728. });
  2729. if(current.length) {
  2730. this.data.search.to_open = remaining;
  2731. $.each(current, function (i, val) {
  2732. _this.open_node(val, function () { _this._search_open(true); });
  2733. });
  2734. done = false;
  2735. }
  2736. }
  2737. if(done) { this.search(this.data.search.str, true); }
  2738. }
  2739. }
  2740. });
  2741. })(jQuery);
  2742. //*/
  2743. /*
  2744. * jsTree contextmenu plugin 1.0
  2745. */
  2746. (function ($) {
  2747. $.vakata.context = {
  2748. cnt : $("<div id='vakata-contextmenu'>"),
  2749. vis : false,
  2750. tgt : false,
  2751. par : false,
  2752. func : false,
  2753. data : false,
  2754. show : function (s, t, x, y, d, p) {
  2755. var html = $.vakata.context.parse(s), h, w;
  2756. if(!html) { return; }
  2757. $.vakata.context.vis = true;
  2758. $.vakata.context.tgt = t;
  2759. $.vakata.context.par = p || t || null;
  2760. $.vakata.context.data = d || null;
  2761. $.vakata.context.cnt
  2762. .html(html)
  2763. .css({ "visibility" : "hidden", "display" : "block", "left" : 0, "top" : 0 });
  2764. h = $.vakata.context.cnt.height();
  2765. w = $.vakata.context.cnt.width();
  2766. if(x + w > $(document).width()) {
  2767. x = $(document).width() - (w + 5);
  2768. $.vakata.context.cnt.find("li > ul").addClass("right");
  2769. }
  2770. if(y + h > $(document).height()) {
  2771. y = y - (h + t[0].offsetHeight);
  2772. $.vakata.context.cnt.find("li > ul").addClass("bottom");
  2773. }
  2774. $.vakata.context.cnt
  2775. .css({ "left" : x, "top" : y })
  2776. .find("li:has(ul)")
  2777. .bind("mouseenter", function (e) {
  2778. var w = $(document).width(),
  2779. h = $(document).height(),
  2780. ul = $(this).children("ul").show();
  2781. if(w !== $(document).width()) { ul.toggleClass("right"); }
  2782. if(h !== $(document).height()) { ul.toggleClass("bottom"); }
  2783. })
  2784. .bind("mouseleave", function (e) {
  2785. $(this).children("ul").hide();
  2786. })
  2787. .end()
  2788. .css({ "visibility" : "visible" })
  2789. .show();
  2790. $(document).triggerHandler("context_show.vakata");
  2791. },
  2792. hide : function () {
  2793. $.vakata.context.vis = false;
  2794. $.vakata.context.cnt.attr("class","").hide();
  2795. $(document).triggerHandler("context_hide.vakata");
  2796. },
  2797. parse : function (s, is_callback) {
  2798. if(!s) { return false; }
  2799. var str = "",
  2800. tmp = false,
  2801. was_sep = true;
  2802. if(!is_callback) { $.vakata.context.func = {}; }
  2803. str += "<ul>";
  2804. $.each(s, function (i, val) {
  2805. if(!val) { return true; }
  2806. $.vakata.context.func[i] = val.action;
  2807. if(!was_sep && val.separator_before) {
  2808. str += "<li class='vakata-separator vakata-separator-before'></li>";
  2809. }
  2810. was_sep = false;
  2811. str += "<li class='" + (val._class || "") + (val._disabled ? " jstree-contextmenu-disabled " : "") + "'><ins ";
  2812. if(val.icon && val.icon.indexOf("/") === -1) { str += " class='" + val.icon + "' "; }
  2813. if(val.icon && val.icon.indexOf("/") !== -1) { str += " style='background:url(" + val.icon + ") center center no-repeat;' "; }
  2814. str += ">&#160;</ins><a href='#' rel='" + i + "'>";
  2815. if(val.submenu) {
  2816. str += "<span style='float:right;'>&raquo;</span>";
  2817. }
  2818. str += val.label + "</a>";
  2819. if(val.submenu) {
  2820. tmp = $.vakata.context.parse(val.submenu, true);
  2821. if(tmp) { str += tmp; }
  2822. }
  2823. str += "</li>";
  2824. if(val.separator_after) {
  2825. str += "<li class='vakata-separator vakata-separator-after'></li>";
  2826. was_sep = true;
  2827. }
  2828. });
  2829. str = str.replace(/<li class\='vakata-separator vakata-separator-after'\><\/li\>$/,"");
  2830. str += "</ul>";
  2831. return str.length > 10 ? str : false;
  2832. },
  2833. exec : function (i) {
  2834. if($.isFunction($.vakata.context.func[i])) {
  2835. $.vakata.context.func[i].call($.vakata.context.data, $.vakata.context.par);
  2836. return true;
  2837. }
  2838. else { return false; }
  2839. }
  2840. };
  2841. $(function () {
  2842. var css_string = '' +
  2843. '#vakata-contextmenu { display:none; position:absolute; margin:0; padding:0; min-width:180px; background:#ebebeb; border:1px solid silver; z-index:10000; *width:180px; } ' +
  2844. '#vakata-contextmenu ul { min-width:180px; *width:180px; } ' +
  2845. '#vakata-contextmenu ul, #vakata-contextmenu li { margin:0; padding:0; list-style-type:none; display:block; } ' +
  2846. '#vakata-contextmenu li { line-height:20px; min-height:20px; position:relative; padding:0px; } ' +
  2847. '#vakata-contextmenu li a { padding:1px 6px; line-height:17px; display:block; text-decoration:none; margin:1px 1px 0 1px; } ' +
  2848. '#vakata-contextmenu li ins { float:left; width:16px; height:16px; text-decoration:none; margin-right:2px; } ' +
  2849. '#vakata-contextmenu li a:hover, #vakata-contextmenu li.vakata-hover > a { background:gray; color:white; } ' +
  2850. '#vakata-contextmenu li ul { display:none; position:absolute; top:-2px; left:100%; background:#ebebeb; border:1px solid gray; } ' +
  2851. '#vakata-contextmenu .right { right:100%; left:auto; } ' +
  2852. '#vakata-contextmenu .bottom { bottom:-1px; top:auto; } ' +
  2853. '#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; } ';
  2854. $.vakata.css.add_sheet({ str : css_string });
  2855. $.vakata.context.cnt
  2856. .delegate("a","click", function (e) { e.preventDefault(); })
  2857. .delegate("a","mouseup", function (e) {
  2858. if(!$(this).parent().hasClass("jstree-contextmenu-disabled") && $.vakata.context.exec($(this).attr("rel"))) {
  2859. $.vakata.context.hide();
  2860. }
  2861. else { $(this).blur(); }
  2862. })
  2863. .delegate("a","mouseover", function () {
  2864. $.vakata.context.cnt.find(".vakata-hover").removeClass("vakata-hover");
  2865. })
  2866. .appendTo("body");
  2867. $(document).bind("mousedown", function (e) { if($.vakata.context.vis && !$.contains($.vakata.context.cnt[0], e.target)) { $.vakata.context.hide(); } });
  2868. if(typeof $.hotkeys !== "undefined") {
  2869. $(document)
  2870. .bind("keydown", "up", function (e) {
  2871. if($.vakata.context.vis) {
  2872. var o = $.vakata.context.cnt.find("ul:visible").last().children(".vakata-hover").removeClass("vakata-hover").prevAll("li:not(.vakata-separator)").first();
  2873. if(!o.length) { o = $.vakata.context.cnt.find("ul:visible").last().children("li:not(.vakata-separator)").last(); }
  2874. o.addClass("vakata-hover");
  2875. e.stopImmediatePropagation();
  2876. e.preventDefault();
  2877. }
  2878. })
  2879. .bind("keydown", "down", function (e) {
  2880. if($.vakata.context.vis) {
  2881. var o = $.vakata.context.cnt.find("ul:visible").last().children(".vakata-hover").removeClass("vakata-hover").nextAll("li:not(.vakata-separator)").first();
  2882. if(!o.length) { o = $.vakata.context.cnt.find("ul:visible").last().children("li:not(.vakata-separator)").first(); }
  2883. o.addClass("vakata-hover");
  2884. e.stopImmediatePropagation();
  2885. e.preventDefault();
  2886. }
  2887. })
  2888. .bind("keydown", "right", function (e) {
  2889. if($.vakata.context.vis) {
  2890. $.vakata.context.cnt.find(".vakata-hover").children("ul").show().children("li:not(.vakata-separator)").removeClass("vakata-hover").first().addClass("vakata-hover");
  2891. e.stopImmediatePropagation();
  2892. e.preventDefault();
  2893. }
  2894. })
  2895. .bind("keydown", "left", function (e) {
  2896. if($.vakata.context.vis) {
  2897. $.vakata.context.cnt.find(".vakata-hover").children("ul").hide().children(".vakata-separator").removeClass("vakata-hover");
  2898. e.stopImmediatePropagation();
  2899. e.preventDefault();
  2900. }
  2901. })
  2902. .bind("keydown", "esc", function (e) {
  2903. $.vakata.context.hide();
  2904. e.preventDefault();
  2905. })
  2906. .bind("keydown", "space", function (e) {
  2907. $.vakata.context.cnt.find(".vakata-hover").last().children("a").click();
  2908. e.preventDefault();
  2909. });
  2910. }
  2911. });
  2912. $.jstree.plugin("contextmenu", {
  2913. __init : function () {
  2914. this.get_container()
  2915. .delegate("a", "contextmenu.jstree", $.proxy(function (e) {
  2916. e.preventDefault();
  2917. this.show_contextmenu(e.currentTarget, e.pageX, e.pageY);
  2918. }, this))
  2919. .bind("destroy.jstree", $.proxy(function () {
  2920. if(this.data.contextmenu) {
  2921. $.vakata.context.hide();
  2922. }
  2923. }, this));
  2924. $(document).bind("context_hide.vakata", $.proxy(function () { this.data.contextmenu = false; }, this));
  2925. },
  2926. defaults : {
  2927. select_node : false, // requires UI plugin
  2928. show_at_node : true,
  2929. items : { // Could be a function that should return an object like this one
  2930. "create" : {
  2931. "separator_before" : false,
  2932. "separator_after" : true,
  2933. "label" : "Create",
  2934. "action" : function (obj) { this.create(obj); }
  2935. },
  2936. "rename" : {
  2937. "separator_before" : false,
  2938. "separator_after" : false,
  2939. "label" : "Rename",
  2940. "action" : function (obj) { this.rename(obj); }
  2941. },
  2942. "remove" : {
  2943. "separator_before" : false,
  2944. "icon" : false,
  2945. "separator_after" : false,
  2946. "label" : "Delete",
  2947. "action" : function (obj) { this.remove(obj); }
  2948. },
  2949. "ccp" : {
  2950. "separator_before" : true,
  2951. "icon" : false,
  2952. "separator_after" : false,
  2953. "label" : "Edit",
  2954. "action" : false,
  2955. "submenu" : {
  2956. "cut" : {
  2957. "separator_before" : false,
  2958. "separator_after" : false,
  2959. "label" : "Cut",
  2960. "action" : function (obj) { this.cut(obj); }
  2961. },
  2962. "copy" : {
  2963. "separator_before" : false,
  2964. "icon" : false,
  2965. "separator_after" : false,
  2966. "label" : "Copy",
  2967. "action" : function (obj) { this.copy(obj); }
  2968. },
  2969. "paste" : {
  2970. "separator_before" : false,
  2971. "icon" : false,
  2972. "separator_after" : false,
  2973. "label" : "Paste",
  2974. "action" : function (obj) { this.paste(obj); }
  2975. }
  2976. }
  2977. }
  2978. }
  2979. },
  2980. _fn : {
  2981. show_contextmenu : function (obj, x, y) {
  2982. obj = this._get_node(obj);
  2983. var s = this.get_settings().contextmenu,
  2984. a = obj.children("a:visible:eq(0)"),
  2985. o = false;
  2986. if(s.select_node && this.data.ui && !this.is_selected(obj)) {
  2987. this.deselect_all();
  2988. this.select_node(obj, true);
  2989. }
  2990. if(s.show_at_node || typeof x === "undefined" || typeof y === "undefined") {
  2991. o = a.offset();
  2992. x = o.left;
  2993. y = o.top + this.data.core.li_height;
  2994. }
  2995. if($.isFunction(s.items)) { s.items = s.items.call(this, obj); }
  2996. this.data.contextmenu = true;
  2997. $.vakata.context.show(s.items, a, x, y, this, obj);
  2998. if(this.data.themes) { $.vakata.context.cnt.attr("class", "jstree-" + this.data.themes.theme + "-context"); }
  2999. }
  3000. }
  3001. });
  3002. })(jQuery);
  3003. //*/
  3004. /*
  3005. * jsTree types plugin 1.0
  3006. * Adds support types of nodes
  3007. * You can set an attribute on each li node, that represents its type.
  3008. * According to the type setting the node may get custom icon/validation rules
  3009. */
  3010. (function ($) {
  3011. $.jstree.plugin("types", {
  3012. __init : function () {
  3013. var s = this._get_settings().types;
  3014. this.data.types.attach_to = [];
  3015. this.get_container()
  3016. .bind("init.jstree", $.proxy(function () {
  3017. var types = s.types,
  3018. attr = s.type_attr,
  3019. icons_css = "",
  3020. _this = this;
  3021. $.each(types, function (i, tp) {
  3022. $.each(tp, function (k, v) {
  3023. if(!/^(max_depth|max_children|icon|valid_children)$/.test(k)) { _this.data.types.attach_to.push(k); }
  3024. });
  3025. if(!tp.icon) { return true; }
  3026. if( tp.icon.image || tp.icon.position) {
  3027. if(i == "default") { icons_css += '.jstree-' + _this.get_index() + ' a > .jstree-icon { '; }
  3028. else { icons_css += '.jstree-' + _this.get_index() + ' li[' + attr + '=' + i + '] > a > .jstree-icon { '; }
  3029. if(tp.icon.image) { icons_css += ' background-image:url(' + tp.icon.image + '); '; }
  3030. if(tp.icon.position){ icons_css += ' background-position:' + tp.icon.position + '; '; }
  3031. else { icons_css += ' background-position:0 0; '; }
  3032. icons_css += '} ';
  3033. }
  3034. });
  3035. if(icons_css != "") { $.vakata.css.add_sheet({ 'str' : icons_css }); }
  3036. }, this))
  3037. .bind("before.jstree", $.proxy(function (e, data) {
  3038. if($.inArray(data.func, this.data.types.attach_to) !== -1) {
  3039. var s = this._get_settings().types.types,
  3040. t = this._get_type(data.args[0]);
  3041. if(
  3042. (
  3043. (s[t] && typeof s[t][data.func] !== "undefined") ||
  3044. (s["default"] && typeof s["default"][data.func] !== "undefined")
  3045. ) && !this._check(data.func, data.args[0])
  3046. ) {
  3047. e.stopImmediatePropagation();
  3048. return false;
  3049. }
  3050. }
  3051. }, this));
  3052. },
  3053. defaults : {
  3054. // defines maximum number of root nodes (-1 means unlimited, -2 means disable max_children checking)
  3055. max_children : -1,
  3056. // defines the maximum depth of the tree (-1 means unlimited, -2 means disable max_depth checking)
  3057. max_depth : -1,
  3058. // defines valid node types for the root nodes
  3059. valid_children : "all",
  3060. // where is the type stores (the rel attribute of the LI element)
  3061. type_attr : "rel",
  3062. // a list of types
  3063. types : {
  3064. // the default type
  3065. "default" : {
  3066. "max_children" : -1,
  3067. "max_depth" : -1,
  3068. "valid_children": "all"
  3069. // Bound functions - you can bind any other function here (using boolean or function)
  3070. //"select_node" : true,
  3071. //"open_node" : true,
  3072. //"close_node" : true,
  3073. //"create_node" : true,
  3074. //"delete_node" : true
  3075. }
  3076. }
  3077. },
  3078. _fn : {
  3079. _get_type : function (obj) {
  3080. obj = this._get_node(obj);
  3081. return (!obj || !obj.length) ? false : obj.attr(this._get_settings().types.type_attr) || "default";
  3082. },
  3083. set_type : function (str, obj) {
  3084. obj = this._get_node(obj);
  3085. return (!obj.length || !str) ? false : obj.attr(this._get_settings().types.type_attr, str);
  3086. },
  3087. _check : function (rule, obj, opts) {
  3088. var v = false, t = this._get_type(obj), d = 0, _this = this, s = this._get_settings().types;
  3089. if(obj === -1) {
  3090. if(!!s[rule]) { v = s[rule]; }
  3091. else { return; }
  3092. }
  3093. else {
  3094. if(t === false) { return; }
  3095. if(!!s.types[t] && !!s.types[t][rule]) { v = s.types[t][rule]; }
  3096. else if(!!s.types["default"] && !!s.types["default"][rule]) { v = s.types["default"][rule]; }
  3097. }
  3098. if($.isFunction(v)) { v = v.call(this, obj); }
  3099. if(rule === "max_depth" && obj !== -1 && opts !== false && s.max_depth !== -2 && v !== 0) {
  3100. // also include the node itself - otherwise if root node it is not checked
  3101. this._get_node(obj).children("a:eq(0)").parentsUntil(".jstree","li").each(function (i) {
  3102. // check if current depth already exceeds global tree depth
  3103. if(s.max_depth !== -1 && s.max_depth - (i + 1) <= 0) { v = 0; return false; }
  3104. d = (i === 0) ? v : _this._check(rule, this, false);
  3105. // check if current node max depth is already matched or exceeded
  3106. if(d !== -1 && d - (i + 1) <= 0) { v = 0; return false; }
  3107. // otherwise - set the max depth to the current value minus current depth
  3108. if(d >= 0 && (d - (i + 1) < v || v < 0) ) { v = d - (i + 1); }
  3109. // if the global tree depth exists and it minus the nodes calculated so far is less than `v` or `v` is unlimited
  3110. if(s.max_depth >= 0 && (s.max_depth - (i + 1) < v || v < 0) ) { v = s.max_depth - (i + 1); }
  3111. });
  3112. }
  3113. return v;
  3114. },
  3115. check_move : function () {
  3116. if(!this.__call_old()) { return false; }
  3117. var m = this._get_move(),
  3118. s = m.rt._get_settings().types,
  3119. mc = m.rt._check("max_children", m.cr),
  3120. md = m.rt._check("max_depth", m.cr),
  3121. vc = m.rt._check("valid_children", m.cr),
  3122. ch = 0, d = 1, t;
  3123. if(vc === "none") { return false; }
  3124. if($.isArray(vc) && m.ot && m.ot._get_type) {
  3125. m.o.each(function () {
  3126. if($.inArray(m.ot._get_type(this), vc) === -1) { d = false; return false; }
  3127. });
  3128. if(d === false) { return false; }
  3129. }
  3130. if(s.max_children !== -2 && mc !== -1) {
  3131. ch = m.cr === -1 ? this.get_container().children("> ul > li").not(m.o).length : m.cr.children("> ul > li").not(m.o).length;
  3132. if(ch + m.o.length > mc) { return false; }
  3133. }
  3134. if(s.max_depth !== -2 && md !== -1) {
  3135. d = 0;
  3136. if(md === 0) { return false; }
  3137. if(typeof m.o.d === "undefined") {
  3138. // TODO: deal with progressive rendering and async when checking max_depth (how to know the depth of the moved node)
  3139. t = m.o;
  3140. while(t.length > 0) {
  3141. t = t.find("> ul > li");
  3142. d ++;
  3143. }
  3144. m.o.d = d;
  3145. }
  3146. if(md - m.o.d < 0) { return false; }
  3147. }
  3148. return true;
  3149. },
  3150. create_node : function (obj, position, js, callback, is_loaded, skip_check) {
  3151. if(!skip_check && (is_loaded || this._is_loaded(obj))) {
  3152. var p = (position && position.match(/^before|after$/i) && obj !== -1) ? this._get_parent(obj) : this._get_node(obj),
  3153. s = this._get_settings().types,
  3154. mc = this._check("max_children", p),
  3155. md = this._check("max_depth", p),
  3156. vc = this._check("valid_children", p),
  3157. ch;
  3158. if(!js) { js = {}; }
  3159. if(vc === "none") { return false; }
  3160. if($.isArray(vc)) {
  3161. if(!js.attr || !js.attr[s.type_attr]) {
  3162. if(!js.attr) { js.attr = {}; }
  3163. js.attr[s.type_attr] = vc[0];
  3164. }
  3165. else {
  3166. if($.inArray(js.attr[s.type_attr], vc) === -1) { return false; }
  3167. }
  3168. }
  3169. if(s.max_children !== -2 && mc !== -1) {
  3170. ch = p === -1 ? this.get_container().children("> ul > li").length : p.children("> ul > li").length;
  3171. if(ch + 1 > mc) { return false; }
  3172. }
  3173. if(s.max_depth !== -2 && md !== -1 && (md - 1) < 0) { return false; }
  3174. }
  3175. return this.__call_old(true, obj, position, js, callback, is_loaded, skip_check);
  3176. }
  3177. }
  3178. });
  3179. })(jQuery);
  3180. //*/
  3181. /*
  3182. * jsTree HTML data 1.0
  3183. * The HTML data store. Datastores are build by replacing the `load_node` and `_is_loaded` functions.
  3184. */
  3185. (function ($) {
  3186. $.jstree.plugin("html_data", {
  3187. __init : function () {
  3188. // this used to use html() and clean the whitespace, but this way any attached data was lost
  3189. this.data.html_data.original_container_html = this.get_container().find(" > ul > li").clone(true);
  3190. // remove white space from LI node - otherwise nodes appear a bit to the right
  3191. this.data.html_data.original_container_html.find("li").andSelf().contents().filter(function() { return this.nodeType == 3; }).remove();
  3192. },
  3193. defaults : {
  3194. data : false,
  3195. ajax : false,
  3196. correct_state : true
  3197. },
  3198. _fn : {
  3199. load_node : function (obj, s_call, e_call) { var _this = this; this.load_node_html(obj, function () { _this.__callback({ "obj" : obj }); s_call.call(this); }, e_call); },
  3200. _is_loaded : function (obj) {
  3201. obj = this._get_node(obj);
  3202. return obj == -1 || !obj || !this._get_settings().html_data.ajax || obj.is(".jstree-open, .jstree-leaf") || obj.children("ul").children("li").size() > 0;
  3203. },
  3204. load_node_html : function (obj, s_call, e_call) {
  3205. var d,
  3206. s = this.get_settings().html_data,
  3207. error_func = function () {},
  3208. success_func = function () {};
  3209. obj = this._get_node(obj);
  3210. if(obj && obj !== -1) {
  3211. if(obj.data("jstree-is-loading")) { return; }
  3212. else { obj.data("jstree-is-loading",true); }
  3213. }
  3214. switch(!0) {
  3215. case (!s.data && !s.ajax):
  3216. if(!obj || obj == -1) {
  3217. this.get_container()
  3218. .children("ul").empty()
  3219. .append(this.data.html_data.original_container_html)
  3220. .find("li, a").filter(function () { return this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'>&#160;</ins>").end()
  3221. .filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon");
  3222. this.clean_node();
  3223. }
  3224. if(s_call) { s_call.call(this); }
  3225. break;
  3226. case (!!s.data && !s.ajax) || (!!s.data && !!s.ajax && (!obj || obj === -1)):
  3227. if(!obj || obj == -1) {
  3228. d = $(s.data);
  3229. if(!d.is("ul")) { d = $("<ul>").append(d); }
  3230. this.get_container()
  3231. .children("ul").empty().append(d.children())
  3232. .find("li, a").filter(function () { return this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'>&#160;</ins>").end()
  3233. .filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon");
  3234. this.clean_node();
  3235. }
  3236. if(s_call) { s_call.call(this); }
  3237. break;
  3238. case (!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj && obj !== -1):
  3239. obj = this._get_node(obj);
  3240. error_func = function (x, t, e) {
  3241. var ef = this.get_settings().html_data.ajax.error;
  3242. if(ef) { ef.call(this, x, t, e); }
  3243. if(obj != -1 && obj.length) {
  3244. obj.children(".jstree-loading").removeClass("jstree-loading");
  3245. obj.data("jstree-is-loading",false);
  3246. if(t === "success" && s.correct_state) { obj.removeClass("jstree-open jstree-closed").addClass("jstree-leaf"); }
  3247. }
  3248. else {
  3249. if(t === "success" && s.correct_state) { this.get_container().children("ul").empty(); }
  3250. }
  3251. if(e_call) { e_call.call(this); }
  3252. };
  3253. success_func = function (d, t, x) {
  3254. var sf = this.get_settings().html_data.ajax.success;
  3255. if(sf) { d = sf.call(this,d,t,x) || d; }
  3256. if(d == "") {
  3257. return error_func.call(this, x, t, "");
  3258. }
  3259. if(d) {
  3260. d = $(d);
  3261. if(!d.is("ul")) { d = $("<ul>").append(d); }
  3262. if(obj == -1 || !obj) { this.get_container().children("ul").empty().append(d.children()).find("li, a").filter(function () { return this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'>&#160;</ins>").end().filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); }
  3263. else { obj.children(".jstree-loading").removeClass("jstree-loading"); obj.append(d).find("li, a").filter(function () { return 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.data("jstree-is-loading",false); }
  3264. this.clean_node(obj);
  3265. if(s_call) { s_call.call(this); }
  3266. }
  3267. else {
  3268. if(obj && obj !== -1) {
  3269. obj.children(".jstree-loading").removeClass("jstree-loading");
  3270. obj.data("jstree-is-loading",false);
  3271. if(s.correct_state) {
  3272. obj.removeClass("jstree-open jstree-closed").addClass("jstree-leaf");
  3273. if(s_call) { s_call.call(this); }
  3274. }
  3275. }
  3276. else {
  3277. if(s.correct_state) {
  3278. this.get_container().children("ul").empty();
  3279. if(s_call) { s_call.call(this); }
  3280. }
  3281. }
  3282. }
  3283. };
  3284. s.ajax.context = this;
  3285. s.ajax.error = error_func;
  3286. s.ajax.success = success_func;
  3287. if(!s.ajax.dataType) { s.ajax.dataType = "html"; }
  3288. if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); }
  3289. if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); }
  3290. $.ajax(s.ajax);
  3291. break;
  3292. }
  3293. }
  3294. }
  3295. });
  3296. // include the HTML data plugin by default
  3297. $.jstree.defaults.plugins.push("html_data");
  3298. })(jQuery);
  3299. //*/
  3300. /*
  3301. * jsTree themeroller plugin 1.0
  3302. * Adds support for jQuery UI themes. Include this at the end of your plugins list, also make sure "themes" is not included.
  3303. */
  3304. (function ($) {
  3305. $.jstree.plugin("themeroller", {
  3306. __init : function () {
  3307. var s = this._get_settings().themeroller;
  3308. this.get_container()
  3309. .addClass("ui-widget-content")
  3310. .delegate("a","mouseenter.jstree", function () {
  3311. $(this).addClass(s.item_h);
  3312. })
  3313. .delegate("a","mouseleave.jstree", function () {
  3314. $(this).removeClass(s.item_h);
  3315. })
  3316. .bind("open_node.jstree create_node.jstree", $.proxy(function (e, data) {
  3317. this._themeroller(data.rslt.obj);
  3318. }, this))
  3319. .bind("loaded.jstree refresh.jstree", $.proxy(function (e) {
  3320. this._themeroller();
  3321. }, this))
  3322. .bind("close_node.jstree", $.proxy(function (e, data) {
  3323. data.rslt.obj.children("ins").removeClass(s.opened).addClass(s.closed);
  3324. }, this))
  3325. .bind("select_node.jstree", $.proxy(function (e, data) {
  3326. data.rslt.obj.children("a").addClass(s.item_a);
  3327. }, this))
  3328. .bind("deselect_node.jstree deselect_all.jstree", $.proxy(function (e, data) {
  3329. this.get_container()
  3330. .find("." + s.item_a).removeClass(s.item_a).end()
  3331. .find(".jstree-clicked").addClass(s.item_a);
  3332. }, this))
  3333. .bind("move_node.jstree", $.proxy(function (e, data) {
  3334. this._themeroller(data.rslt.o);
  3335. }, this));
  3336. },
  3337. __destroy : function () {
  3338. var s = this._get_settings().themeroller,
  3339. c = [ "ui-icon" ];
  3340. $.each(s, function (i, v) {
  3341. v = v.split(" ");
  3342. if(v.length) { c = c.concat(v); }
  3343. });
  3344. this.get_container()
  3345. .removeClass("ui-widget-content")
  3346. .find("." + c.join(", .")).removeClass(c.join(" "));
  3347. },
  3348. _fn : {
  3349. _themeroller : function (obj) {
  3350. var s = this._get_settings().themeroller;
  3351. obj = !obj || obj == -1 ? this.get_container() : this._get_node(obj).parent();
  3352. obj
  3353. .find("li.jstree-closed > ins.jstree-icon").removeClass(s.opened).addClass("ui-icon " + s.closed).end()
  3354. .find("li.jstree-open > ins.jstree-icon").removeClass(s.closed).addClass("ui-icon " + s.opened).end()
  3355. .find("a").addClass(s.item)
  3356. .children("ins.jstree-icon").addClass("ui-icon " + s.item_icon);
  3357. }
  3358. },
  3359. defaults : {
  3360. "opened" : "ui-icon-triangle-1-se",
  3361. "closed" : "ui-icon-triangle-1-e",
  3362. "item" : "ui-state-default",
  3363. "item_h" : "ui-state-hover",
  3364. "item_a" : "ui-state-active",
  3365. "item_icon" : "ui-icon-folder-collapsed"
  3366. }
  3367. });
  3368. $(function() {
  3369. var css_string = '.jstree .ui-icon { overflow:visible; } .jstree a { padding:0 2px; }';
  3370. $.vakata.css.add_sheet({ str : css_string });
  3371. });
  3372. })(jQuery);
  3373. //*/
  3374. /*
  3375. * jsTree unique plugin 1.0
  3376. * Forces different names amongst siblings (still a bit experimental)
  3377. * NOTE: does not check language versions (it will not be possible to have nodes with the same title, even in different languages)
  3378. */
  3379. (function ($) {
  3380. $.jstree.plugin("unique", {
  3381. __init : function () {
  3382. this.get_container()
  3383. .bind("before.jstree", $.proxy(function (e, data) {
  3384. var nms = [], res = true, p, t;
  3385. if(data.func == "move_node") {
  3386. // obj, ref, position, is_copy, is_prepared, skip_check
  3387. if(data.args[4] === true) {
  3388. if(data.args[0].o && data.args[0].o.length) {
  3389. data.args[0].o.children("a").each(function () { nms.push($(this).text().replace(/^\s+/g,"")); });
  3390. res = this._check_unique(nms, data.args[0].np.find("> ul > li").not(data.args[0].o));
  3391. }
  3392. }
  3393. }
  3394. if(data.func == "create_node") {
  3395. // obj, position, js, callback, is_loaded
  3396. if(data.args[4] || this._is_loaded(data.args[0])) {
  3397. p = this._get_node(data.args[0]);
  3398. if(data.args[1] && (data.args[1] === "before" || data.args[1] === "after")) {
  3399. p = this._get_parent(data.args[0]);
  3400. if(!p || p === -1) { p = this.get_container(); }
  3401. }
  3402. if(typeof data.args[2] === "string") { nms.push(data.args[2]); }
  3403. else if(!data.args[2] || !data.args[2].data) { nms.push(this._get_settings().core.strings.new_node); }
  3404. else { nms.push(data.args[2].data); }
  3405. res = this._check_unique(nms, p.find("> ul > li"));
  3406. }
  3407. }
  3408. if(data.func == "rename_node") {
  3409. // obj, val
  3410. nms.push(data.args[1]);
  3411. t = this._get_node(data.args[0]);
  3412. p = this._get_parent(t);
  3413. if(!p || p === -1) { p = this.get_container(); }
  3414. res = this._check_unique(nms, p.find("> ul > li").not(t));
  3415. }
  3416. if(!res) {
  3417. e.stopPropagation();
  3418. return false;
  3419. }
  3420. }, this));
  3421. },
  3422. _fn : {
  3423. _check_unique : function (nms, p) {
  3424. var cnms = [];
  3425. p.children("a").each(function () { cnms.push($(this).text().replace(/^\s+/g,"")); });
  3426. if(!cnms.length || !nms.length) { return true; }
  3427. cnms = cnms.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",");
  3428. if((cnms.length + nms.length) != cnms.concat(nms).sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",").length) {
  3429. return false;
  3430. }
  3431. return true;
  3432. },
  3433. check_move : function () {
  3434. if(!this.__call_old()) { return false; }
  3435. var p = this._get_move(), nms = [];
  3436. if(p.o && p.o.length) {
  3437. p.o.children("a").each(function () { nms.push($(this).text().replace(/^\s+/g,"")); });
  3438. return this._check_unique(nms, p.np.find("> ul > li").not(p.o));
  3439. }
  3440. return true;
  3441. }
  3442. }
  3443. });
  3444. })(jQuery);
  3445. //*/