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