source: sandbox/expresso-solr/solr/example/work/jetty-0.0.0.0-8983-solr.war-_solr-any-/webapp/js/lib/jquery.jstree.js @ 7588

Revision 7588, 130.5 KB checked in by adir, 11 years ago (diff)

Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade

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