jquery.jstree.js 131 KB

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