Xataface HTML Reports Module 0.2
HTML Reports Module for Xataface
|
00001 /* 00002 * jsTree 1.0-rc3 00003 * http://jstree.com/ 00004 * 00005 * Copyright (c) 2010 Ivan Bozhanov (vakata.com) 00006 * 00007 * Licensed same as jquery - under the terms of either the MIT License or the GPL Version 2 License 00008 * http://www.opensource.org/licenses/mit-license.php 00009 * http://www.gnu.org/licenses/gpl.html 00010 * 00011 * $Date: 2011-02-09 01:17:14 +0200 ( , 09 2011) $ 00012 * $Revision: 236 $ 00013 */ 00014 00015 /*jslint browser: true, onevar: true, undef: true, bitwise: true, strict: true */ 00016 /*global window : false, clearInterval: false, clearTimeout: false, document: false, setInterval: false, setTimeout: false, jQuery: false, navigator: false, XSLTProcessor: false, DOMParser: false, XMLSerializer: false*/ 00017 00018 "use strict"; 00019 00020 // top wrapper to prevent multiple inclusion (is this OK?) 00021 (function () { if(jQuery && jQuery.jstree) { return; } 00022 var is_ie6 = false, is_ie7 = false, is_ff2 = false; 00023 00024 /* 00025 * jsTree core 00026 */ 00027 (function ($) { 00028 // Common functions not related to jsTree 00029 // decided to move them to a `vakata` "namespace" 00030 $.vakata = {}; 00031 // CSS related functions 00032 $.vakata.css = { 00033 get_css : function(rule_name, delete_flag, sheet) { 00034 rule_name = rule_name.toLowerCase(); 00035 var css_rules = sheet.cssRules || sheet.rules, 00036 j = 0; 00037 do { 00038 if(css_rules.length && j > css_rules.length + 5) { return false; } 00039 if(css_rules[j].selectorText && css_rules[j].selectorText.toLowerCase() == rule_name) { 00040 if(delete_flag === true) { 00041 if(sheet.removeRule) { sheet.removeRule(j); } 00042 if(sheet.deleteRule) { sheet.deleteRule(j); } 00043 return true; 00044 } 00045 else { return css_rules[j]; } 00046 } 00047 } 00048 while (css_rules[++j]); 00049 return false; 00050 }, 00051 add_css : function(rule_name, sheet) { 00052 if($.jstree.css.get_css(rule_name, false, sheet)) { return false; } 00053 if(sheet.insertRule) { sheet.insertRule(rule_name + ' { }', 0); } else { sheet.addRule(rule_name, null, 0); } 00054 return $.vakata.css.get_css(rule_name); 00055 }, 00056 remove_css : function(rule_name, sheet) { 00057 return $.vakata.css.get_css(rule_name, true, sheet); 00058 }, 00059 add_sheet : function(opts) { 00060 var tmp = false, is_new = true; 00061 if(opts.str) { 00062 if(opts.title) { tmp = $("style[id='" + opts.title + "-stylesheet']")[0]; } 00063 if(tmp) { is_new = false; } 00064 else { 00065 tmp = document.createElement("style"); 00066 tmp.setAttribute('type',"text/css"); 00067 if(opts.title) { tmp.setAttribute("id", opts.title + "-stylesheet"); } 00068 } 00069 if(tmp.styleSheet) { 00070 if(is_new) { 00071 document.getElementsByTagName("head")[0].appendChild(tmp); 00072 tmp.styleSheet.cssText = opts.str; 00073 } 00074 else { 00075 tmp.styleSheet.cssText = tmp.styleSheet.cssText + " " + opts.str; 00076 } 00077 } 00078 else { 00079 tmp.appendChild(document.createTextNode(opts.str)); 00080 document.getElementsByTagName("head")[0].appendChild(tmp); 00081 } 00082 return tmp.sheet || tmp.styleSheet; 00083 } 00084 if(opts.url) { 00085 if(document.createStyleSheet) { 00086 try { tmp = document.createStyleSheet(opts.url); } catch (e) { } 00087 } 00088 else { 00089 tmp = document.createElement('link'); 00090 tmp.rel = 'stylesheet'; 00091 tmp.type = 'text/css'; 00092 tmp.media = "all"; 00093 tmp.href = opts.url; 00094 document.getElementsByTagName("head")[0].appendChild(tmp); 00095 return tmp.styleSheet; 00096 } 00097 } 00098 } 00099 }; 00100 00101 // private variables 00102 var instances = [], // instance array (used by $.jstree.reference/create/focused) 00103 focused_instance = -1, // the index in the instance array of the currently focused instance 00104 plugins = {}, // list of included plugins 00105 prepared_move = {}; // for the move_node function 00106 00107 // jQuery plugin wrapper (thanks to jquery UI widget function) 00108 $.fn.jstree = function (settings) { 00109 var isMethodCall = (typeof settings == 'string'), // is this a method call like $().jstree("open_node") 00110 args = Array.prototype.slice.call(arguments, 1), 00111 returnValue = this; 00112 00113 // if a method call execute the method on all selected instances 00114 if(isMethodCall) { 00115 if(settings.substring(0, 1) == '_') { return returnValue; } 00116 this.each(function() { 00117 var instance = instances[$.data(this, "jstree_instance_id")], 00118 methodValue = (instance && $.isFunction(instance[settings])) ? instance[settings].apply(instance, args) : instance; 00119 if(typeof methodValue !== "undefined" && (settings.indexOf("is_") === 0 || (methodValue !== true && methodValue !== false))) { returnValue = methodValue; return false; } 00120 }); 00121 } 00122 else { 00123 this.each(function() { 00124 // extend settings and allow for multiple hashes and $.data 00125 var instance_id = $.data(this, "jstree_instance_id"), 00126 a = [], 00127 b = settings ? $.extend({}, true, settings) : {}, 00128 c = $(this), 00129 s = false, 00130 t = []; 00131 a = a.concat(args); 00132 if(c.data("jstree")) { a.push(c.data("jstree")); } 00133 b = a.length ? $.extend.apply(null, [true, b].concat(a)) : b; 00134 00135 // if an instance already exists, destroy it first 00136 if(typeof instance_id !== "undefined" && instances[instance_id]) { instances[instance_id].destroy(); } 00137 // push a new empty object to the instances array 00138 instance_id = parseInt(instances.push({}),10) - 1; 00139 // store the jstree instance id to the container element 00140 $.data(this, "jstree_instance_id", instance_id); 00141 // clean up all plugins 00142 b.plugins = $.isArray(b.plugins) ? b.plugins : $.jstree.defaults.plugins.slice(); 00143 b.plugins.unshift("core"); 00144 // only unique plugins 00145 b.plugins = b.plugins.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(","); 00146 00147 // extend defaults with passed data 00148 s = $.extend(true, {}, $.jstree.defaults, b); 00149 s.plugins = b.plugins; 00150 $.each(plugins, function (i, val) { 00151 if($.inArray(i, s.plugins) === -1) { s[i] = null; delete s[i]; } 00152 else { t.push(i); } 00153 }); 00154 s.plugins = t; 00155 00156 // push the new object to the instances array (at the same time set the default classes to the container) and init 00157 instances[instance_id] = new $.jstree._instance(instance_id, $(this).addClass("jstree jstree-" + instance_id), s); 00158 // init all activated plugins for this instance 00159 $.each(instances[instance_id]._get_settings().plugins, function (i, val) { instances[instance_id].data[val] = {}; }); 00160 $.each(instances[instance_id]._get_settings().plugins, function (i, val) { if(plugins[val]) { plugins[val].__init.apply(instances[instance_id]); } }); 00161 // initialize the instance 00162 setTimeout(function() { if(instances[instance_id]) { instances[instance_id].init(); } }, 0); 00163 }); 00164 } 00165 // return the jquery selection (or if it was a method call that returned a value - the returned value) 00166 return returnValue; 00167 }; 00168 // object to store exposed functions and objects 00169 $.jstree = { 00170 defaults : { 00171 plugins : [] 00172 }, 00173 _focused : function () { return instances[focused_instance] || null; }, 00174 _reference : function (needle) { 00175 // get by instance id 00176 if(instances[needle]) { return instances[needle]; } 00177 // get by DOM (if still no luck - return null 00178 var o = $(needle); 00179 if(!o.length && typeof needle === "string") { o = $("#" + needle); } 00180 if(!o.length) { return null; } 00181 return instances[o.closest(".jstree").data("jstree_instance_id")] || null; 00182 }, 00183 _instance : function (index, container, settings) { 00184 // for plugins to store data in 00185 this.data = { core : {} }; 00186 this.get_settings = function () { return $.extend(true, {}, settings); }; 00187 this._get_settings = function () { return settings; }; 00188 this.get_index = function () { return index; }; 00189 this.get_container = function () { return container; }; 00190 this.get_container_ul = function () { return container.children("ul:eq(0)"); }; 00191 this._set_settings = function (s) { 00192 settings = $.extend(true, {}, settings, s); 00193 }; 00194 }, 00195 _fn : { }, 00196 plugin : function (pname, pdata) { 00197 pdata = $.extend({}, { 00198 __init : $.noop, 00199 __destroy : $.noop, 00200 _fn : {}, 00201 defaults : false 00202 }, pdata); 00203 plugins[pname] = pdata; 00204 00205 $.jstree.defaults[pname] = pdata.defaults; 00206 $.each(pdata._fn, function (i, val) { 00207 val.plugin = pname; 00208 val.old = $.jstree._fn[i]; 00209 $.jstree._fn[i] = function () { 00210 var rslt, 00211 func = val, 00212 args = Array.prototype.slice.call(arguments), 00213 evnt = new $.Event("before.jstree"), 00214 rlbk = false; 00215 00216 if(this.data.core.locked === true && i !== "unlock" && i !== "is_locked") { return; } 00217 00218 // Check if function belongs to the included plugins of this instance 00219 do { 00220 if(func && func.plugin && $.inArray(func.plugin, this._get_settings().plugins) !== -1) { break; } 00221 func = func.old; 00222 } while(func); 00223 if(!func) { return; } 00224 00225 // context and function to trigger events, then finally call the function 00226 if(i.indexOf("_") === 0) { 00227 rslt = func.apply(this, args); 00228 } 00229 else { 00230 rslt = this.get_container().triggerHandler(evnt, { "func" : i, "inst" : this, "args" : args, "plugin" : func.plugin }); 00231 if(rslt === false) { return; } 00232 if(typeof rslt !== "undefined") { args = rslt; } 00233 00234 rslt = func.apply( 00235 $.extend({}, this, { 00236 __callback : function (data) { 00237 this.get_container().triggerHandler( i + '.jstree', { "inst" : this, "args" : args, "rslt" : data, "rlbk" : rlbk }); 00238 }, 00239 __rollback : function () { 00240 rlbk = this.get_rollback(); 00241 return rlbk; 00242 }, 00243 __call_old : function (replace_arguments) { 00244 return func.old.apply(this, (replace_arguments ? Array.prototype.slice.call(arguments, 1) : args ) ); 00245 } 00246 }), args); 00247 } 00248 00249 // return the result 00250 return rslt; 00251 }; 00252 $.jstree._fn[i].old = val.old; 00253 $.jstree._fn[i].plugin = pname; 00254 }); 00255 }, 00256 rollback : function (rb) { 00257 if(rb) { 00258 if(!$.isArray(rb)) { rb = [ rb ]; } 00259 $.each(rb, function (i, val) { 00260 instances[val.i].set_rollback(val.h, val.d); 00261 }); 00262 } 00263 } 00264 }; 00265 // set the prototype for all instances 00266 $.jstree._fn = $.jstree._instance.prototype = {}; 00267 00268 // load the css when DOM is ready 00269 $(function() { 00270 // code is copied from jQuery ($.browser is deprecated + there is a bug in IE) 00271 var u = navigator.userAgent.toLowerCase(), 00272 v = (u.match( /.+?(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1], 00273 css_string = '' + 00274 '.jstree ul, .jstree li { display:block; margin:0 0 0 0; padding:0 0 0 0; list-style-type:none; } ' + 00275 '.jstree li { display:block; min-height:18px; line-height:18px; white-space:nowrap; margin-left:18px; min-width:18px; } ' + 00276 '.jstree-rtl li { margin-left:0; margin-right:18px; } ' + 00277 '.jstree > ul > li { margin-left:0px; } ' + 00278 '.jstree-rtl > ul > li { margin-right:0px; } ' + 00279 '.jstree ins { display:inline-block; text-decoration:none; width:18px; height:18px; margin:0 0 0 0; padding:0; } ' + 00280 '.jstree a { display:inline-block; line-height:16px; height:16px; color:black; white-space:nowrap; text-decoration:none; padding:1px 2px; margin:0; } ' + 00281 '.jstree a:focus { outline: none; } ' + 00282 '.jstree a > ins { height:16px; width:16px; } ' + 00283 '.jstree a > .jstree-icon { margin-right:3px; } ' + 00284 '.jstree-rtl a > .jstree-icon { margin-left:3px; margin-right:0; } ' + 00285 'li.jstree-open > ul { display:block; } ' + 00286 'li.jstree-closed > ul { display:none; } '; 00287 // Correct IE 6 (does not support the > CSS selector) 00288 if(/msie/.test(u) && parseInt(v, 10) == 6) { 00289 is_ie6 = true; 00290 00291 // fix image flicker and lack of caching 00292 try { 00293 document.execCommand("BackgroundImageCache", false, true); 00294 } catch (err) { } 00295 00296 css_string += '' + 00297 '.jstree li { height:18px; margin-left:0; margin-right:0; } ' + 00298 '.jstree li li { margin-left:18px; } ' + 00299 '.jstree-rtl li li { margin-left:0px; margin-right:18px; } ' + 00300 'li.jstree-open ul { display:block; } ' + 00301 'li.jstree-closed ul { display:none !important; } ' + 00302 '.jstree li a { display:inline; border-width:0 !important; padding:0px 2px !important; } ' + 00303 '.jstree li a ins { height:16px; width:16px; margin-right:3px; } ' + 00304 '.jstree-rtl li a ins { margin-right:0px; margin-left:3px; } '; 00305 } 00306 // Correct IE 7 (shifts anchor nodes onhover) 00307 if(/msie/.test(u) && parseInt(v, 10) == 7) { 00308 is_ie7 = true; 00309 css_string += '.jstree li a { border-width:0 !important; padding:0px 2px !important; } '; 00310 } 00311 // correct ff2 lack of display:inline-block 00312 if(!/compatible/.test(u) && /mozilla/.test(u) && parseFloat(v, 10) < 1.9) { 00313 is_ff2 = true; 00314 css_string += '' + 00315 '.jstree ins { display:-moz-inline-box; } ' + 00316 '.jstree li { line-height:12px; } ' + // WHY?? 00317 '.jstree a { display:-moz-inline-box; } ' + 00318 '.jstree .jstree-no-icons .jstree-checkbox { display:-moz-inline-stack !important; } '; 00319 /* this shouldn't be here as it is theme specific */ 00320 } 00321 // the default stylesheet 00322 $.vakata.css.add_sheet({ str : css_string, title : "jstree" }); 00323 }); 00324 00325 // core functions (open, close, create, update, delete) 00326 $.jstree.plugin("core", { 00327 __init : function () { 00328 this.data.core.locked = false; 00329 this.data.core.to_open = this.get_settings().core.initially_open; 00330 this.data.core.to_load = this.get_settings().core.initially_load; 00331 }, 00332 defaults : { 00333 html_titles : false, 00334 animation : 500, 00335 initially_open : [], 00336 initially_load : [], 00337 open_parents : true, 00338 notify_plugins : true, 00339 rtl : false, 00340 load_open : false, 00341 strings : { 00342 loading : "Loading ...", 00343 new_node : "New node", 00344 multiple_selection : "Multiple selection" 00345 } 00346 }, 00347 _fn : { 00348 init : function () { 00349 this.set_focus(); 00350 if(this._get_settings().core.rtl) { 00351 this.get_container().addClass("jstree-rtl").css("direction", "rtl"); 00352 } 00353 this.get_container().html("<ul><li class='jstree-last jstree-leaf'><ins> </ins><a class='jstree-loading' href='#'><ins class='jstree-icon'> </ins>" + this._get_string("loading") + "</a></li></ul>"); 00354 this.data.core.li_height = this.get_container_ul().find("li.jstree-closed, li.jstree-leaf").eq(0).height() || 18; 00355 00356 this.get_container() 00357 .delegate("li > ins", "click.jstree", $.proxy(function (event) { 00358 var trgt = $(event.target); 00359 // if(trgt.is("ins") && event.pageY - trgt.offset().top < this.data.core.li_height) { this.toggle_node(trgt); } 00360 this.toggle_node(trgt); 00361 }, this)) 00362 .bind("mousedown.jstree", $.proxy(function () { 00363 this.set_focus(); // This used to be setTimeout(set_focus,0) - why? 00364 }, this)) 00365 .bind("dblclick.jstree", function (event) { 00366 var sel; 00367 if(document.selection && document.selection.empty) { document.selection.empty(); } 00368 else { 00369 if(window.getSelection) { 00370 sel = window.getSelection(); 00371 try { 00372 sel.removeAllRanges(); 00373 sel.collapse(); 00374 } catch (err) { } 00375 } 00376 } 00377 }); 00378 if(this._get_settings().core.notify_plugins) { 00379 this.get_container() 00380 .bind("load_node.jstree", $.proxy(function (e, data) { 00381 var o = this._get_node(data.rslt.obj), 00382 t = this; 00383 if(o === -1) { o = this.get_container_ul(); } 00384 if(!o.length) { return; } 00385 o.find("li").each(function () { 00386 var th = $(this); 00387 if(th.data("jstree")) { 00388 $.each(th.data("jstree"), function (plugin, values) { 00389 if(t.data[plugin] && $.isFunction(t["_" + plugin + "_notify"])) { 00390 t["_" + plugin + "_notify"].call(t, th, values); 00391 } 00392 }); 00393 } 00394 }); 00395 }, this)); 00396 } 00397 if(this._get_settings().core.load_open) { 00398 this.get_container() 00399 .bind("load_node.jstree", $.proxy(function (e, data) { 00400 var o = this._get_node(data.rslt.obj), 00401 t = this; 00402 if(o === -1) { o = this.get_container_ul(); } 00403 if(!o.length) { return; } 00404 o.find("li.jstree-open:not(:has(ul))").each(function () { 00405 t.load_node(this, $.noop, $.noop); 00406 }); 00407 }, this)); 00408 } 00409 this.__callback(); 00410 this.load_node(-1, function () { this.loaded(); this.reload_nodes(); }); 00411 }, 00412 destroy : function () { 00413 var i, 00414 n = this.get_index(), 00415 s = this._get_settings(), 00416 _this = this; 00417 00418 $.each(s.plugins, function (i, val) { 00419 try { plugins[val].__destroy.apply(_this); } catch(err) { } 00420 }); 00421 this.__callback(); 00422 // set focus to another instance if this one is focused 00423 if(this.is_focused()) { 00424 for(i in instances) { 00425 if(instances.hasOwnProperty(i) && i != n) { 00426 instances[i].set_focus(); 00427 break; 00428 } 00429 } 00430 } 00431 // if no other instance found 00432 if(n === focused_instance) { focused_instance = -1; } 00433 // remove all traces of jstree in the DOM (only the ones set using jstree*) and cleans all events 00434 this.get_container() 00435 .unbind(".jstree") 00436 .undelegate(".jstree") 00437 .removeData("jstree_instance_id") 00438 .find("[class^='jstree']") 00439 .andSelf() 00440 .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); }); 00441 $(document) 00442 .unbind(".jstree-" + n) 00443 .undelegate(".jstree-" + n); 00444 // remove the actual data 00445 instances[n] = null; 00446 delete instances[n]; 00447 }, 00448 00449 _core_notify : function (n, data) { 00450 if(data.opened) { 00451 this.open_node(n, false, true); 00452 } 00453 }, 00454 00455 lock : function () { 00456 this.data.core.locked = true; 00457 this.get_container().children("ul").addClass("jstree-locked").css("opacity","0.7"); 00458 this.__callback({}); 00459 }, 00460 unlock : function () { 00461 this.data.core.locked = false; 00462 this.get_container().children("ul").removeClass("jstree-locked").css("opacity","1"); 00463 this.__callback({}); 00464 }, 00465 is_locked : function () { return this.data.core.locked; }, 00466 save_opened : function () { 00467 var _this = this; 00468 this.data.core.to_open = []; 00469 this.get_container_ul().find("li.jstree-open").each(function () { 00470 if(this.id) { _this.data.core.to_open.push("#" + this.id.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:")); } 00471 }); 00472 this.__callback(_this.data.core.to_open); 00473 }, 00474 save_loaded : function () { }, 00475 reload_nodes : function (is_callback) { 00476 var _this = this, 00477 done = true, 00478 current = [], 00479 remaining = []; 00480 if(!is_callback) { 00481 this.data.core.reopen = false; 00482 this.data.core.refreshing = true; 00483 this.data.core.to_open = $.map($.makeArray(this.data.core.to_open), function (n) { return "#" + n.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:"); }); 00484 this.data.core.to_load = $.map($.makeArray(this.data.core.to_load), function (n) { return "#" + n.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:"); }); 00485 if(this.data.core.to_open.length) { 00486 this.data.core.to_load = this.data.core.to_load.concat(this.data.core.to_open); 00487 } 00488 } 00489 if(this.data.core.to_load.length) { 00490 $.each(this.data.core.to_load, function (i, val) { 00491 if(val == "#") { return true; } 00492 if($(val).length) { current.push(val); } 00493 else { remaining.push(val); } 00494 }); 00495 if(current.length) { 00496 this.data.core.to_load = remaining; 00497 $.each(current, function (i, val) { 00498 if(!_this._is_loaded(val)) { 00499 _this.load_node(val, function () { _this.reload_nodes(true); }, function () { _this.reload_nodes(true); }); 00500 done = false; 00501 } 00502 }); 00503 } 00504 } 00505 if(this.data.core.to_open.length) { 00506 $.each(this.data.core.to_open, function (i, val) { 00507 _this.open_node(val, false, true); 00508 }); 00509 } 00510 if(done) { 00511 // TODO: find a more elegant approach to syncronizing returning requests 00512 if(this.data.core.reopen) { clearTimeout(this.data.core.reopen); } 00513 this.data.core.reopen = setTimeout(function () { _this.__callback({}, _this); }, 50); 00514 this.data.core.refreshing = false; 00515 this.reopen(); 00516 } 00517 }, 00518 reopen : function () { 00519 var _this = this; 00520 if(this.data.core.to_open.length) { 00521 $.each(this.data.core.to_open, function (i, val) { 00522 _this.open_node(val, false, true); 00523 }); 00524 } 00525 this.__callback({}); 00526 }, 00527 refresh : function (obj) { 00528 var _this = this; 00529 this.save_opened(); 00530 if(!obj) { obj = -1; } 00531 obj = this._get_node(obj); 00532 if(!obj) { obj = -1; } 00533 if(obj !== -1) { obj.children("UL").remove(); } 00534 else { this.get_container_ul().empty(); } 00535 this.load_node(obj, function () { _this.__callback({ "obj" : obj}); _this.reload_nodes(); }); 00536 }, 00537 // Dummy function to fire after the first load (so that there is a jstree.loaded event) 00538 loaded : function () { 00539 this.__callback(); 00540 }, 00541 // deal with focus 00542 set_focus : function () { 00543 if(this.is_focused()) { return; } 00544 var f = $.jstree._focused(); 00545 if(f) { f.unset_focus(); } 00546 00547 this.get_container().addClass("jstree-focused"); 00548 focused_instance = this.get_index(); 00549 this.__callback(); 00550 }, 00551 is_focused : function () { 00552 return focused_instance == this.get_index(); 00553 }, 00554 unset_focus : function () { 00555 if(this.is_focused()) { 00556 this.get_container().removeClass("jstree-focused"); 00557 focused_instance = -1; 00558 } 00559 this.__callback(); 00560 }, 00561 00562 // traverse 00563 _get_node : function (obj) { 00564 var $obj = $(obj, this.get_container()); 00565 if($obj.is(".jstree") || obj == -1) { return -1; } 00566 $obj = $obj.closest("li", this.get_container()); 00567 return $obj.length ? $obj : false; 00568 }, 00569 _get_next : function (obj, strict) { 00570 obj = this._get_node(obj); 00571 if(obj === -1) { return this.get_container().find("> ul > li:first-child"); } 00572 if(!obj.length) { return false; } 00573 if(strict) { return (obj.nextAll("li").size() > 0) ? obj.nextAll("li:eq(0)") : false; } 00574 00575 if(obj.hasClass("jstree-open")) { return obj.find("li:eq(0)"); } 00576 else if(obj.nextAll("li").size() > 0) { return obj.nextAll("li:eq(0)"); } 00577 else { return obj.parentsUntil(".jstree","li").next("li").eq(0); } 00578 }, 00579 _get_prev : function (obj, strict) { 00580 obj = this._get_node(obj); 00581 if(obj === -1) { return this.get_container().find("> ul > li:last-child"); } 00582 if(!obj.length) { return false; } 00583 if(strict) { return (obj.prevAll("li").length > 0) ? obj.prevAll("li:eq(0)") : false; } 00584 00585 if(obj.prev("li").length) { 00586 obj = obj.prev("li").eq(0); 00587 while(obj.hasClass("jstree-open")) { obj = obj.children("ul:eq(0)").children("li:last"); } 00588 return obj; 00589 } 00590 else { var o = obj.parentsUntil(".jstree","li:eq(0)"); return o.length ? o : false; } 00591 }, 00592 _get_parent : function (obj) { 00593 obj = this._get_node(obj); 00594 if(obj == -1 || !obj.length) { return false; } 00595 var o = obj.parentsUntil(".jstree", "li:eq(0)"); 00596 return o.length ? o : -1; 00597 }, 00598 _get_children : function (obj) { 00599 obj = this._get_node(obj); 00600 if(obj === -1) { return this.get_container().children("ul:eq(0)").children("li"); } 00601 if(!obj.length) { return false; } 00602 return obj.children("ul:eq(0)").children("li"); 00603 }, 00604 get_path : function (obj, id_mode) { 00605 var p = [], 00606 _this = this; 00607 obj = this._get_node(obj); 00608 if(obj === -1 || !obj || !obj.length) { return false; } 00609 obj.parentsUntil(".jstree", "li").each(function () { 00610 p.push( id_mode ? this.id : _this.get_text(this) ); 00611 }); 00612 p.reverse(); 00613 p.push( id_mode ? obj.attr("id") : this.get_text(obj) ); 00614 return p; 00615 }, 00616 00617 // string functions 00618 _get_string : function (key) { 00619 return this._get_settings().core.strings[key] || key; 00620 }, 00621 00622 is_open : function (obj) { obj = this._get_node(obj); return obj && obj !== -1 && obj.hasClass("jstree-open"); }, 00623 is_closed : function (obj) { obj = this._get_node(obj); return obj && obj !== -1 && obj.hasClass("jstree-closed"); }, 00624 is_leaf : function (obj) { obj = this._get_node(obj); return obj && obj !== -1 && obj.hasClass("jstree-leaf"); }, 00625 correct_state : function (obj) { 00626 obj = this._get_node(obj); 00627 if(!obj || obj === -1) { return false; } 00628 obj.removeClass("jstree-closed jstree-open").addClass("jstree-leaf").children("ul").remove(); 00629 this.__callback({ "obj" : obj }); 00630 }, 00631 // open/close 00632 open_node : function (obj, callback, skip_animation) { 00633 obj = this._get_node(obj); 00634 if(!obj.length) { return false; } 00635 if(!obj.hasClass("jstree-closed")) { if(callback) { callback.call(); } return false; } 00636 var s = skip_animation || is_ie6 ? 0 : this._get_settings().core.animation, 00637 t = this; 00638 if(!this._is_loaded(obj)) { 00639 obj.children("a").addClass("jstree-loading"); 00640 this.load_node(obj, function () { t.open_node(obj, callback, skip_animation); }, callback); 00641 } 00642 else { 00643 if(this._get_settings().core.open_parents) { 00644 obj.parentsUntil(".jstree",".jstree-closed").each(function () { 00645 t.open_node(this, false, true); 00646 }); 00647 } 00648 if(s) { obj.children("ul").css("display","none"); } 00649 obj.removeClass("jstree-closed").addClass("jstree-open").children("a").removeClass("jstree-loading"); 00650 if(s) { obj.children("ul").stop(true, true).slideDown(s, function () { this.style.display = ""; t.after_open(obj); }); } 00651 else { t.after_open(obj); } 00652 this.__callback({ "obj" : obj }); 00653 if(callback) { callback.call(); } 00654 } 00655 }, 00656 after_open : function (obj) { this.__callback({ "obj" : obj }); }, 00657 close_node : function (obj, skip_animation) { 00658 obj = this._get_node(obj); 00659 var s = skip_animation || is_ie6 ? 0 : this._get_settings().core.animation, 00660 t = this; 00661 if(!obj.length || !obj.hasClass("jstree-open")) { return false; } 00662 if(s) { obj.children("ul").attr("style","display:block !important"); } 00663 obj.removeClass("jstree-open").addClass("jstree-closed"); 00664 if(s) { obj.children("ul").stop(true, true).slideUp(s, function () { this.style.display = ""; t.after_close(obj); }); } 00665 else { t.after_close(obj); } 00666 this.__callback({ "obj" : obj }); 00667 }, 00668 after_close : function (obj) { this.__callback({ "obj" : obj }); }, 00669 toggle_node : function (obj) { 00670 obj = this._get_node(obj); 00671 if(obj.hasClass("jstree-closed")) { return this.open_node(obj); } 00672 if(obj.hasClass("jstree-open")) { return this.close_node(obj); } 00673 }, 00674 open_all : function (obj, do_animation, original_obj) { 00675 obj = obj ? this._get_node(obj) : -1; 00676 if(!obj || obj === -1) { obj = this.get_container_ul(); } 00677 if(original_obj) { 00678 obj = obj.find("li.jstree-closed"); 00679 } 00680 else { 00681 original_obj = obj; 00682 if(obj.is(".jstree-closed")) { obj = obj.find("li.jstree-closed").andSelf(); } 00683 else { obj = obj.find("li.jstree-closed"); } 00684 } 00685 var _this = this; 00686 obj.each(function () { 00687 var __this = this; 00688 if(!_this._is_loaded(this)) { _this.open_node(this, function() { _this.open_all(__this, do_animation, original_obj); }, !do_animation); } 00689 else { _this.open_node(this, false, !do_animation); } 00690 }); 00691 // so that callback is fired AFTER all nodes are open 00692 if(original_obj.find('li.jstree-closed').length === 0) { this.__callback({ "obj" : original_obj }); } 00693 }, 00694 close_all : function (obj, do_animation) { 00695 var _this = this; 00696 obj = obj ? this._get_node(obj) : this.get_container(); 00697 if(!obj || obj === -1) { obj = this.get_container_ul(); } 00698 obj.find("li.jstree-open").andSelf().each(function () { _this.close_node(this, !do_animation); }); 00699 this.__callback({ "obj" : obj }); 00700 }, 00701 clean_node : function (obj) { 00702 obj = obj && obj != -1 ? $(obj) : this.get_container_ul(); 00703 obj = obj.is("li") ? obj.find("li").andSelf() : obj.find("li"); 00704 obj.removeClass("jstree-last") 00705 .filter("li:last-child").addClass("jstree-last").end() 00706 .filter(":has(li)") 00707 .not(".jstree-open").removeClass("jstree-leaf").addClass("jstree-closed"); 00708 obj.not(".jstree-open, .jstree-closed").addClass("jstree-leaf").children("ul").remove(); 00709 this.__callback({ "obj" : obj }); 00710 }, 00711 // rollback 00712 get_rollback : function () { 00713 this.__callback(); 00714 return { i : this.get_index(), h : this.get_container().children("ul").clone(true), d : this.data }; 00715 }, 00716 set_rollback : function (html, data) { 00717 this.get_container().empty().append(html); 00718 this.data = data; 00719 this.__callback(); 00720 }, 00721 // Dummy functions to be overwritten by any datastore plugin included 00722 load_node : function (obj, s_call, e_call) { this.__callback({ "obj" : obj }); }, 00723 _is_loaded : function (obj) { return true; }, 00724 00725 // Basic operations: create 00726 create_node : function (obj, position, js, callback, is_loaded) { 00727 obj = this._get_node(obj); 00728 position = typeof position === "undefined" ? "last" : position; 00729 var d = $("<li />"), 00730 s = this._get_settings().core, 00731 tmp; 00732 00733 if(obj !== -1 && !obj.length) { return false; } 00734 if(!is_loaded && !this._is_loaded(obj)) { this.load_node(obj, function () { this.create_node(obj, position, js, callback, true); }); return false; } 00735 00736 this.__rollback(); 00737 00738 if(typeof js === "string") { js = { "data" : js }; } 00739 if(!js) { js = {}; } 00740 if(js.attr) { d.attr(js.attr); } 00741 if(js.metadata) { d.data(js.metadata); } 00742 if(js.state) { d.addClass("jstree-" + js.state); } 00743 if(!js.data) { js.data = this._get_string("new_node"); } 00744 if(!$.isArray(js.data)) { tmp = js.data; js.data = []; js.data.push(tmp); } 00745 $.each(js.data, function (i, m) { 00746 tmp = $("<a />"); 00747 if($.isFunction(m)) { m = m.call(this, js); } 00748 if(typeof m == "string") { tmp.attr('href','#')[ s.html_titles ? "html" : "text" ](m); } 00749 else { 00750 if(!m.attr) { m.attr = {}; } 00751 if(!m.attr.href) { m.attr.href = '#'; } 00752 tmp.attr(m.attr)[ s.html_titles ? "html" : "text" ](m.title); 00753 if(m.language) { tmp.addClass(m.language); } 00754 } 00755 tmp.prepend("<ins class='jstree-icon'> </ins>"); 00756 if(!m.icon && js.icon) { m.icon = js.icon; } 00757 if(m.icon) { 00758 if(m.icon.indexOf("/") === -1) { tmp.children("ins").addClass(m.icon); } 00759 else { tmp.children("ins").css("background","url('" + m.icon + "') center center no-repeat"); } 00760 } 00761 d.append(tmp); 00762 }); 00763 d.prepend("<ins class='jstree-icon'> </ins>"); 00764 if(obj === -1) { 00765 obj = this.get_container(); 00766 if(position === "before") { position = "first"; } 00767 if(position === "after") { position = "last"; } 00768 } 00769 switch(position) { 00770 case "before": obj.before(d); tmp = this._get_parent(obj); break; 00771 case "after" : obj.after(d); tmp = this._get_parent(obj); break; 00772 case "inside": 00773 case "first" : 00774 if(!obj.children("ul").length) { obj.append("<ul />"); } 00775 obj.children("ul").prepend(d); 00776 tmp = obj; 00777 break; 00778 case "last": 00779 if(!obj.children("ul").length) { obj.append("<ul />"); } 00780 obj.children("ul").append(d); 00781 tmp = obj; 00782 break; 00783 default: 00784 if(!obj.children("ul").length) { obj.append("<ul />"); } 00785 if(!position) { position = 0; } 00786 tmp = obj.children("ul").children("li").eq(position); 00787 if(tmp.length) { tmp.before(d); } 00788 else { obj.children("ul").append(d); } 00789 tmp = obj; 00790 break; 00791 } 00792 if(tmp === -1 || tmp.get(0) === this.get_container().get(0)) { tmp = -1; } 00793 this.clean_node(tmp); 00794 this.__callback({ "obj" : d, "parent" : tmp }); 00795 if(callback) { callback.call(this, d); } 00796 return d; 00797 }, 00798 // Basic operations: rename (deal with text) 00799 get_text : function (obj) { 00800 obj = this._get_node(obj); 00801 if(!obj.length) { return false; } 00802 var s = this._get_settings().core.html_titles; 00803 obj = obj.children("a:eq(0)"); 00804 if(s) { 00805 obj = obj.clone(); 00806 obj.children("INS").remove(); 00807 return obj.html(); 00808 } 00809 else { 00810 obj = obj.contents().filter(function() { return this.nodeType == 3; })[0]; 00811 return obj.nodeValue; 00812 } 00813 }, 00814 set_text : function (obj, val) { 00815 obj = this._get_node(obj); 00816 if(!obj.length) { return false; } 00817 obj = obj.children("a:eq(0)"); 00818 if(this._get_settings().core.html_titles) { 00819 var tmp = obj.children("INS").clone(); 00820 obj.html(val).prepend(tmp); 00821 this.__callback({ "obj" : obj, "name" : val }); 00822 return true; 00823 } 00824 else { 00825 obj = obj.contents().filter(function() { return this.nodeType == 3; })[0]; 00826 this.__callback({ "obj" : obj, "name" : val }); 00827 return (obj.nodeValue = val); 00828 } 00829 }, 00830 rename_node : function (obj, val) { 00831 obj = this._get_node(obj); 00832 this.__rollback(); 00833 if(obj && obj.length && this.set_text.apply(this, Array.prototype.slice.call(arguments))) { this.__callback({ "obj" : obj, "name" : val }); } 00834 }, 00835 // Basic operations: deleting nodes 00836 delete_node : function (obj) { 00837 obj = this._get_node(obj); 00838 if(!obj.length) { return false; } 00839 this.__rollback(); 00840 var p = this._get_parent(obj), prev = $([]), t = this; 00841 obj.each(function () { 00842 prev = prev.add(t._get_prev(this)); 00843 }); 00844 obj = obj.detach(); 00845 if(p !== -1 && p.find("> ul > li").length === 0) { 00846 p.removeClass("jstree-open jstree-closed").addClass("jstree-leaf"); 00847 } 00848 this.clean_node(p); 00849 this.__callback({ "obj" : obj, "prev" : prev, "parent" : p }); 00850 return obj; 00851 }, 00852 prepare_move : function (o, r, pos, cb, is_cb) { 00853 var p = {}; 00854 00855 p.ot = $.jstree._reference(o) || this; 00856 p.o = p.ot._get_node(o); 00857 p.r = r === - 1 ? -1 : this._get_node(r); 00858 p.p = (typeof pos === "undefined" || pos === false) ? "last" : pos; // TODO: move to a setting 00859 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) { 00860 this.__callback(prepared_move); 00861 if(cb) { cb.call(this, prepared_move); } 00862 return; 00863 } 00864 p.ot = $.jstree._reference(p.o) || this; 00865 p.rt = $.jstree._reference(p.r) || this; // r === -1 ? p.ot : $.jstree._reference(p.r) || this 00866 if(p.r === -1 || !p.r) { 00867 p.cr = -1; 00868 switch(p.p) { 00869 case "first": 00870 case "before": 00871 case "inside": 00872 p.cp = 0; 00873 break; 00874 case "after": 00875 case "last": 00876 p.cp = p.rt.get_container().find(" > ul > li").length; 00877 break; 00878 default: 00879 p.cp = p.p; 00880 break; 00881 } 00882 } 00883 else { 00884 if(!/^(before|after)$/.test(p.p) && !this._is_loaded(p.r)) { 00885 return this.load_node(p.r, function () { this.prepare_move(o, r, pos, cb, true); }); 00886 } 00887 switch(p.p) { 00888 case "before": 00889 p.cp = p.r.index(); 00890 p.cr = p.rt._get_parent(p.r); 00891 break; 00892 case "after": 00893 p.cp = p.r.index() + 1; 00894 p.cr = p.rt._get_parent(p.r); 00895 break; 00896 case "inside": 00897 case "first": 00898 p.cp = 0; 00899 p.cr = p.r; 00900 break; 00901 case "last": 00902 p.cp = p.r.find(" > ul > li").length; 00903 p.cr = p.r; 00904 break; 00905 default: 00906 p.cp = p.p; 00907 p.cr = p.r; 00908 break; 00909 } 00910 } 00911 p.np = p.cr == -1 ? p.rt.get_container() : p.cr; 00912 p.op = p.ot._get_parent(p.o); 00913 p.cop = p.o.index(); 00914 if(p.op === -1) { p.op = p.ot ? p.ot.get_container() : this.get_container(); } 00915 if(!/^(before|after)$/.test(p.p) && p.op && p.np && p.op[0] === p.np[0] && p.o.index() < p.cp) { p.cp++; } 00916 //if(p.p === "before" && p.op && p.np && p.op[0] === p.np[0] && p.o.index() < p.cp) { p.cp--; } 00917 p.or = p.np.find(" > ul > li:nth-child(" + (p.cp + 1) + ")"); 00918 prepared_move = p; 00919 this.__callback(prepared_move); 00920 if(cb) { cb.call(this, prepared_move); } 00921 }, 00922 check_move : function () { 00923 var obj = prepared_move, ret = true, r = obj.r === -1 ? this.get_container() : obj.r; 00924 if(!obj || !obj.o || obj.or[0] === obj.o[0]) { return false; } 00925 if(obj.op && obj.np && obj.op[0] === obj.np[0] && obj.cp - 1 === obj.o.index()) { return false; } 00926 obj.o.each(function () { 00927 if(r.parentsUntil(".jstree", "li").andSelf().index(this) !== -1) { ret = false; return false; } 00928 }); 00929 return ret; 00930 }, 00931 move_node : function (obj, ref, position, is_copy, is_prepared, skip_check) { 00932 if(!is_prepared) { 00933 return this.prepare_move(obj, ref, position, function (p) { 00934 this.move_node(p, false, false, is_copy, true, skip_check); 00935 }); 00936 } 00937 if(is_copy) { 00938 prepared_move.cy = true; 00939 } 00940 if(!skip_check && !this.check_move()) { return false; } 00941 00942 this.__rollback(); 00943 var o = false; 00944 if(is_copy) { 00945 o = obj.o.clone(true); 00946 o.find("*[id]").andSelf().each(function () { 00947 if(this.id) { this.id = "copy_" + this.id; } 00948 }); 00949 } 00950 else { o = obj.o; } 00951 00952 if(obj.or.length) { obj.or.before(o); } 00953 else { 00954 if(!obj.np.children("ul").length) { $("<ul />").appendTo(obj.np); } 00955 obj.np.children("ul:eq(0)").append(o); 00956 } 00957 00958 try { 00959 obj.ot.clean_node(obj.op); 00960 obj.rt.clean_node(obj.np); 00961 if(!obj.op.find("> ul > li").length) { 00962 obj.op.removeClass("jstree-open jstree-closed").addClass("jstree-leaf").children("ul").remove(); 00963 } 00964 } catch (e) { } 00965 00966 if(is_copy) { 00967 prepared_move.cy = true; 00968 prepared_move.oc = o; 00969 } 00970 this.__callback(prepared_move); 00971 return prepared_move; 00972 }, 00973 _get_move : function () { return prepared_move; } 00974 } 00975 }); 00976 })(jQuery); 00977 //*/ 00978 00979 /* 00980 * jsTree ui plugin 00981 * This plugins handles selecting/deselecting/hovering/dehovering nodes 00982 */ 00983 (function ($) { 00984 var scrollbar_width, e1, e2; 00985 $(function() { 00986 if (/msie/.test(navigator.userAgent.toLowerCase())) { 00987 e1 = $('<textarea cols="10" rows="2"></textarea>').css({ position: 'absolute', top: -1000, left: 0 }).appendTo('body'); 00988 e2 = $('<textarea cols="10" rows="2" style="overflow: hidden;"></textarea>').css({ position: 'absolute', top: -1000, left: 0 }).appendTo('body'); 00989 scrollbar_width = e1.width() - e2.width(); 00990 e1.add(e2).remove(); 00991 } 00992 else { 00993 e1 = $('<div />').css({ width: 100, height: 100, overflow: 'auto', position: 'absolute', top: -1000, left: 0 }) 00994 .prependTo('body').append('<div />').find('div').css({ width: '100%', height: 200 }); 00995 scrollbar_width = 100 - e1.width(); 00996 e1.parent().remove(); 00997 } 00998 }); 00999 $.jstree.plugin("ui", { 01000 __init : function () { 01001 this.data.ui.selected = $(); 01002 this.data.ui.last_selected = false; 01003 this.data.ui.hovered = null; 01004 this.data.ui.to_select = this.get_settings().ui.initially_select; 01005 01006 this.get_container() 01007 .delegate("a", "click.jstree", $.proxy(function (event) { 01008 event.preventDefault(); 01009 event.currentTarget.blur(); 01010 if(!$(event.currentTarget).hasClass("jstree-loading")) { 01011 this.select_node(event.currentTarget, true, event); 01012 } 01013 }, this)) 01014 .delegate("a", "mouseenter.jstree", $.proxy(function (event) { 01015 if(!$(event.currentTarget).hasClass("jstree-loading")) { 01016 this.hover_node(event.target); 01017 } 01018 }, this)) 01019 .delegate("a", "mouseleave.jstree", $.proxy(function (event) { 01020 if(!$(event.currentTarget).hasClass("jstree-loading")) { 01021 this.dehover_node(event.target); 01022 } 01023 }, this)) 01024 .bind("reopen.jstree", $.proxy(function () { 01025 this.reselect(); 01026 }, this)) 01027 .bind("get_rollback.jstree", $.proxy(function () { 01028 this.dehover_node(); 01029 this.save_selected(); 01030 }, this)) 01031 .bind("set_rollback.jstree", $.proxy(function () { 01032 this.reselect(); 01033 }, this)) 01034 .bind("close_node.jstree", $.proxy(function (event, data) { 01035 var s = this._get_settings().ui, 01036 obj = this._get_node(data.rslt.obj), 01037 clk = (obj && obj.length) ? obj.children("ul").find("a.jstree-clicked") : $(), 01038 _this = this; 01039 if(s.selected_parent_close === false || !clk.length) { return; } 01040 clk.each(function () { 01041 _this.deselect_node(this); 01042 if(s.selected_parent_close === "select_parent") { _this.select_node(obj); } 01043 }); 01044 }, this)) 01045 .bind("delete_node.jstree", $.proxy(function (event, data) { 01046 var s = this._get_settings().ui.select_prev_on_delete, 01047 obj = this._get_node(data.rslt.obj), 01048 clk = (obj && obj.length) ? obj.find("a.jstree-clicked") : [], 01049 _this = this; 01050 clk.each(function () { _this.deselect_node(this); }); 01051 if(s && clk.length) { 01052 data.rslt.prev.each(function () { 01053 if(this.parentNode) { _this.select_node(this); return false; /* if return false is removed all prev nodes will be selected */} 01054 }); 01055 } 01056 }, this)) 01057 .bind("move_node.jstree", $.proxy(function (event, data) { 01058 if(data.rslt.cy) { 01059 data.rslt.oc.find("a.jstree-clicked").removeClass("jstree-clicked"); 01060 } 01061 }, this)); 01062 }, 01063 defaults : { 01064 select_limit : -1, // 0, 1, 2 ... or -1 for unlimited 01065 select_multiple_modifier : "ctrl", // on, or ctrl, shift, alt 01066 select_range_modifier : "shift", 01067 selected_parent_close : "select_parent", // false, "deselect", "select_parent" 01068 selected_parent_open : true, 01069 select_prev_on_delete : true, 01070 disable_selecting_children : false, 01071 initially_select : [] 01072 }, 01073 _fn : { 01074 _get_node : function (obj, allow_multiple) { 01075 if(typeof obj === "undefined" || obj === null) { return allow_multiple ? this.data.ui.selected : this.data.ui.last_selected; } 01076 var $obj = $(obj, this.get_container()); 01077 if($obj.is(".jstree") || obj == -1) { return -1; } 01078 $obj = $obj.closest("li", this.get_container()); 01079 return $obj.length ? $obj : false; 01080 }, 01081 _ui_notify : function (n, data) { 01082 if(data.selected) { 01083 this.select_node(n, false); 01084 } 01085 }, 01086 save_selected : function () { 01087 var _this = this; 01088 this.data.ui.to_select = []; 01089 this.data.ui.selected.each(function () { if(this.id) { _this.data.ui.to_select.push("#" + this.id.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:")); } }); 01090 this.__callback(this.data.ui.to_select); 01091 }, 01092 reselect : function () { 01093 var _this = this, 01094 s = this.data.ui.to_select; 01095 s = $.map($.makeArray(s), function (n) { return "#" + n.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:"); }); 01096 // this.deselect_all(); WHY deselect, breaks plugin state notifier? 01097 $.each(s, function (i, val) { if(val && val !== "#") { _this.select_node(val); } }); 01098 this.data.ui.selected = this.data.ui.selected.filter(function () { return this.parentNode; }); 01099 this.__callback(); 01100 }, 01101 refresh : function (obj) { 01102 this.save_selected(); 01103 return this.__call_old(); 01104 }, 01105 hover_node : function (obj) { 01106 obj = this._get_node(obj); 01107 if(!obj.length) { return false; } 01108 //if(this.data.ui.hovered && obj.get(0) === this.data.ui.hovered.get(0)) { return; } 01109 if(!obj.hasClass("jstree-hovered")) { this.dehover_node(); } 01110 this.data.ui.hovered = obj.children("a").addClass("jstree-hovered").parent(); 01111 this._fix_scroll(obj); 01112 this.__callback({ "obj" : obj }); 01113 }, 01114 dehover_node : function () { 01115 var obj = this.data.ui.hovered, p; 01116 if(!obj || !obj.length) { return false; } 01117 p = obj.children("a").removeClass("jstree-hovered").parent(); 01118 if(this.data.ui.hovered[0] === p[0]) { this.data.ui.hovered = null; } 01119 this.__callback({ "obj" : obj }); 01120 }, 01121 select_node : function (obj, check, e) { 01122 obj = this._get_node(obj); 01123 if(obj == -1 || !obj || !obj.length) { return false; } 01124 var s = this._get_settings().ui, 01125 is_multiple = (s.select_multiple_modifier == "on" || (s.select_multiple_modifier !== false && e && e[s.select_multiple_modifier + "Key"])), 01126 is_range = (s.select_range_modifier !== false && e && e[s.select_range_modifier + "Key"] && this.data.ui.last_selected && this.data.ui.last_selected[0] !== obj[0] && this.data.ui.last_selected.parent()[0] === obj.parent()[0]), 01127 is_selected = this.is_selected(obj), 01128 proceed = true, 01129 t = this; 01130 if(check) { 01131 if(s.disable_selecting_children && is_multiple && 01132 ( 01133 (obj.parentsUntil(".jstree","li").children("a.jstree-clicked").length) || 01134 (obj.children("ul").find("a.jstree-clicked:eq(0)").length) 01135 ) 01136 ) { 01137 return false; 01138 } 01139 proceed = false; 01140 switch(!0) { 01141 case (is_range): 01142 this.data.ui.last_selected.addClass("jstree-last-selected"); 01143 obj = obj[ obj.index() < this.data.ui.last_selected.index() ? "nextUntil" : "prevUntil" ](".jstree-last-selected").andSelf(); 01144 if(s.select_limit == -1 || obj.length < s.select_limit) { 01145 this.data.ui.last_selected.removeClass("jstree-last-selected"); 01146 this.data.ui.selected.each(function () { 01147 if(this !== t.data.ui.last_selected[0]) { t.deselect_node(this); } 01148 }); 01149 is_selected = false; 01150 proceed = true; 01151 } 01152 else { 01153 proceed = false; 01154 } 01155 break; 01156 case (is_selected && !is_multiple): 01157 this.deselect_all(); 01158 is_selected = false; 01159 proceed = true; 01160 break; 01161 case (!is_selected && !is_multiple): 01162 if(s.select_limit == -1 || s.select_limit > 0) { 01163 this.deselect_all(); 01164 proceed = true; 01165 } 01166 break; 01167 case (is_selected && is_multiple): 01168 this.deselect_node(obj); 01169 break; 01170 case (!is_selected && is_multiple): 01171 if(s.select_limit == -1 || this.data.ui.selected.length + 1 <= s.select_limit) { 01172 proceed = true; 01173 } 01174 break; 01175 } 01176 } 01177 if(proceed && !is_selected) { 01178 if(!is_range) { this.data.ui.last_selected = obj; } 01179 obj.children("a").addClass("jstree-clicked"); 01180 if(s.selected_parent_open) { 01181 obj.parents(".jstree-closed").each(function () { t.open_node(this, false, true); }); 01182 } 01183 this.data.ui.selected = this.data.ui.selected.add(obj); 01184 this._fix_scroll(obj.eq(0)); 01185 this.__callback({ "obj" : obj, "e" : e }); 01186 } 01187 }, 01188 _fix_scroll : function (obj) { 01189 var c = this.get_container()[0], t; 01190 if(c.scrollHeight > c.offsetHeight) { 01191 obj = this._get_node(obj); 01192 if(!obj || obj === -1 || !obj.length || !obj.is(":visible")) { return; } 01193 t = obj.offset().top - this.get_container().offset().top; 01194 if(t < 0) { 01195 c.scrollTop = c.scrollTop + t - 1; 01196 } 01197 if(t + this.data.core.li_height + (c.scrollWidth > c.offsetWidth ? scrollbar_width : 0) > c.offsetHeight) { 01198 c.scrollTop = c.scrollTop + (t - c.offsetHeight + this.data.core.li_height + 1 + (c.scrollWidth > c.offsetWidth ? scrollbar_width : 0)); 01199 } 01200 } 01201 }, 01202 deselect_node : function (obj) { 01203 obj = this._get_node(obj); 01204 if(!obj.length) { return false; } 01205 if(this.is_selected(obj)) { 01206 obj.children("a").removeClass("jstree-clicked"); 01207 this.data.ui.selected = this.data.ui.selected.not(obj); 01208 if(this.data.ui.last_selected.get(0) === obj.get(0)) { this.data.ui.last_selected = this.data.ui.selected.eq(0); } 01209 this.__callback({ "obj" : obj }); 01210 } 01211 }, 01212 toggle_select : function (obj) { 01213 obj = this._get_node(obj); 01214 if(!obj.length) { return false; } 01215 if(this.is_selected(obj)) { this.deselect_node(obj); } 01216 else { this.select_node(obj); } 01217 }, 01218 is_selected : function (obj) { return this.data.ui.selected.index(this._get_node(obj)) >= 0; }, 01219 get_selected : function (context) { 01220 return context ? $(context).find("a.jstree-clicked").parent() : this.data.ui.selected; 01221 }, 01222 deselect_all : function (context) { 01223 var ret = context ? $(context).find("a.jstree-clicked").parent() : this.get_container().find("a.jstree-clicked").parent(); 01224 ret.children("a.jstree-clicked").removeClass("jstree-clicked"); 01225 this.data.ui.selected = $([]); 01226 this.data.ui.last_selected = false; 01227 this.__callback({ "obj" : ret }); 01228 } 01229 } 01230 }); 01231 // include the selection plugin by default 01232 $.jstree.defaults.plugins.push("ui"); 01233 })(jQuery); 01234 //*/ 01235 01236 /* 01237 * jsTree CRRM plugin 01238 * Handles creating/renaming/removing/moving nodes by user interaction. 01239 */ 01240 (function ($) { 01241 $.jstree.plugin("crrm", { 01242 __init : function () { 01243 this.get_container() 01244 .bind("move_node.jstree", $.proxy(function (e, data) { 01245 if(this._get_settings().crrm.move.open_onmove) { 01246 var t = this; 01247 data.rslt.np.parentsUntil(".jstree").andSelf().filter(".jstree-closed").each(function () { 01248 t.open_node(this, false, true); 01249 }); 01250 } 01251 }, this)); 01252 }, 01253 defaults : { 01254 input_width_limit : 200, 01255 move : { 01256 always_copy : false, // false, true or "multitree" 01257 open_onmove : true, 01258 default_position : "last", 01259 check_move : function (m) { return true; } 01260 } 01261 }, 01262 _fn : { 01263 _show_input : function (obj, callback) { 01264 obj = this._get_node(obj); 01265 var rtl = this._get_settings().core.rtl, 01266 w = this._get_settings().crrm.input_width_limit, 01267 w1 = obj.children("ins").width(), 01268 w2 = obj.find("> a:visible > ins").width() * obj.find("> a:visible > ins").length, 01269 t = this.get_text(obj), 01270 h1 = $("<div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo("body"), 01271 h2 = obj.css("position","relative").append( 01272 $("<input />", { 01273 "value" : t, 01274 "class" : "jstree-rename-input", 01275 // "size" : t.length, 01276 "css" : { 01277 "padding" : "0", 01278 "border" : "1px solid silver", 01279 "position" : "absolute", 01280 "left" : (rtl ? "auto" : (w1 + w2 + 4) + "px"), 01281 "right" : (rtl ? (w1 + w2 + 4) + "px" : "auto"), 01282 "top" : "0px", 01283 "height" : (this.data.core.li_height - 2) + "px", 01284 "lineHeight" : (this.data.core.li_height - 2) + "px", 01285 "width" : "150px" // will be set a bit further down 01286 }, 01287 "blur" : $.proxy(function () { 01288 var i = obj.children(".jstree-rename-input"), 01289 v = i.val(); 01290 if(v === "") { v = t; } 01291 h1.remove(); 01292 i.remove(); // rollback purposes 01293 this.set_text(obj,t); // rollback purposes 01294 this.rename_node(obj, v); 01295 callback.call(this, obj, v, t); 01296 obj.css("position",""); 01297 }, this), 01298 "keyup" : function (event) { 01299 var key = event.keyCode || event.which; 01300 if(key == 27) { this.value = t; this.blur(); return; } 01301 else if(key == 13) { this.blur(); return; } 01302 else { 01303 h2.width(Math.min(h1.text("pW" + this.value).width(),w)); 01304 } 01305 }, 01306 "keypress" : function(event) { 01307 var key = event.keyCode || event.which; 01308 if(key == 13) { return false; } 01309 } 01310 }) 01311 ).children(".jstree-rename-input"); 01312 this.set_text(obj, ""); 01313 h1.css({ 01314 fontFamily : h2.css('fontFamily') || '', 01315 fontSize : h2.css('fontSize') || '', 01316 fontWeight : h2.css('fontWeight') || '', 01317 fontStyle : h2.css('fontStyle') || '', 01318 fontStretch : h2.css('fontStretch') || '', 01319 fontVariant : h2.css('fontVariant') || '', 01320 letterSpacing : h2.css('letterSpacing') || '', 01321 wordSpacing : h2.css('wordSpacing') || '' 01322 }); 01323 h2.width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select(); 01324 }, 01325 rename : function (obj) { 01326 obj = this._get_node(obj); 01327 this.__rollback(); 01328 var f = this.__callback; 01329 this._show_input(obj, function (obj, new_name, old_name) { 01330 f.call(this, { "obj" : obj, "new_name" : new_name, "old_name" : old_name }); 01331 }); 01332 }, 01333 create : function (obj, position, js, callback, skip_rename) { 01334 var t, _this = this; 01335 obj = this._get_node(obj); 01336 if(!obj) { obj = -1; } 01337 this.__rollback(); 01338 t = this.create_node(obj, position, js, function (t) { 01339 var p = this._get_parent(t), 01340 pos = $(t).index(); 01341 if(callback) { callback.call(this, t); } 01342 if(p.length && p.hasClass("jstree-closed")) { this.open_node(p, false, true); } 01343 if(!skip_rename) { 01344 this._show_input(t, function (obj, new_name, old_name) { 01345 _this.__callback({ "obj" : obj, "name" : new_name, "parent" : p, "position" : pos }); 01346 }); 01347 } 01348 else { _this.__callback({ "obj" : t, "name" : this.get_text(t), "parent" : p, "position" : pos }); } 01349 }); 01350 return t; 01351 }, 01352 remove : function (obj) { 01353 obj = this._get_node(obj, true); 01354 var p = this._get_parent(obj), prev = this._get_prev(obj); 01355 this.__rollback(); 01356 obj = this.delete_node(obj); 01357 if(obj !== false) { this.__callback({ "obj" : obj, "prev" : prev, "parent" : p }); } 01358 }, 01359 check_move : function () { 01360 if(!this.__call_old()) { return false; } 01361 var s = this._get_settings().crrm.move; 01362 if(!s.check_move.call(this, this._get_move())) { return false; } 01363 return true; 01364 }, 01365 move_node : function (obj, ref, position, is_copy, is_prepared, skip_check) { 01366 var s = this._get_settings().crrm.move; 01367 if(!is_prepared) { 01368 if(typeof position === "undefined") { position = s.default_position; } 01369 if(position === "inside" && !s.default_position.match(/^(before|after)$/)) { position = s.default_position; } 01370 return this.__call_old(true, obj, ref, position, is_copy, false, skip_check); 01371 } 01372 // if the move is already prepared 01373 if(s.always_copy === true || (s.always_copy === "multitree" && obj.rt.get_index() !== obj.ot.get_index() )) { 01374 is_copy = true; 01375 } 01376 this.__call_old(true, obj, ref, position, is_copy, true, skip_check); 01377 }, 01378 01379 cut : function (obj) { 01380 obj = this._get_node(obj, true); 01381 if(!obj || !obj.length) { return false; } 01382 this.data.crrm.cp_nodes = false; 01383 this.data.crrm.ct_nodes = obj; 01384 this.__callback({ "obj" : obj }); 01385 }, 01386 copy : function (obj) { 01387 obj = this._get_node(obj, true); 01388 if(!obj || !obj.length) { return false; } 01389 this.data.crrm.ct_nodes = false; 01390 this.data.crrm.cp_nodes = obj; 01391 this.__callback({ "obj" : obj }); 01392 }, 01393 paste : function (obj) { 01394 obj = this._get_node(obj); 01395 if(!obj || !obj.length) { return false; } 01396 var nodes = this.data.crrm.ct_nodes ? this.data.crrm.ct_nodes : this.data.crrm.cp_nodes; 01397 if(!this.data.crrm.ct_nodes && !this.data.crrm.cp_nodes) { return false; } 01398 if(this.data.crrm.ct_nodes) { this.move_node(this.data.crrm.ct_nodes, obj); this.data.crrm.ct_nodes = false; } 01399 if(this.data.crrm.cp_nodes) { this.move_node(this.data.crrm.cp_nodes, obj, false, true); } 01400 this.__callback({ "obj" : obj, "nodes" : nodes }); 01401 } 01402 } 01403 }); 01404 // include the crr plugin by default 01405 // $.jstree.defaults.plugins.push("crrm"); 01406 })(jQuery); 01407 //*/ 01408 01409 /* 01410 * jsTree themes plugin 01411 * Handles loading and setting themes, as well as detecting path to themes, etc. 01412 */ 01413 (function ($) { 01414 var themes_loaded = []; 01415 // this variable stores the path to the themes folder - if left as false - it will be autodetected 01416 $.jstree._themes = false; 01417 $.jstree.plugin("themes", { 01418 __init : function () { 01419 this.get_container() 01420 .bind("init.jstree", $.proxy(function () { 01421 var s = this._get_settings().themes; 01422 this.data.themes.dots = s.dots; 01423 this.data.themes.icons = s.icons; 01424 this.set_theme(s.theme, s.url); 01425 }, this)) 01426 .bind("loaded.jstree", $.proxy(function () { 01427 // bound here too, as simple HTML tree's won't honor dots & icons otherwise 01428 if(!this.data.themes.dots) { this.hide_dots(); } 01429 else { this.show_dots(); } 01430 if(!this.data.themes.icons) { this.hide_icons(); } 01431 else { this.show_icons(); } 01432 }, this)); 01433 }, 01434 defaults : { 01435 theme : "default", 01436 url : false, 01437 dots : true, 01438 icons : true 01439 }, 01440 _fn : { 01441 set_theme : function (theme_name, theme_url) { 01442 if(!theme_name) { return false; } 01443 if(!theme_url) { theme_url = $.jstree._themes + theme_name + '/style.css'; } 01444 if($.inArray(theme_url, themes_loaded) == -1) { 01445 $.vakata.css.add_sheet({ "url" : theme_url }); 01446 themes_loaded.push(theme_url); 01447 } 01448 if(this.data.themes.theme != theme_name) { 01449 this.get_container().removeClass('jstree-' + this.data.themes.theme); 01450 this.data.themes.theme = theme_name; 01451 } 01452 this.get_container().addClass('jstree-' + theme_name); 01453 if(!this.data.themes.dots) { this.hide_dots(); } 01454 else { this.show_dots(); } 01455 if(!this.data.themes.icons) { this.hide_icons(); } 01456 else { this.show_icons(); } 01457 this.__callback(); 01458 }, 01459 get_theme : function () { return this.data.themes.theme; }, 01460 01461 show_dots : function () { this.data.themes.dots = true; this.get_container().children("ul").removeClass("jstree-no-dots"); }, 01462 hide_dots : function () { this.data.themes.dots = false; this.get_container().children("ul").addClass("jstree-no-dots"); }, 01463 toggle_dots : function () { if(this.data.themes.dots) { this.hide_dots(); } else { this.show_dots(); } }, 01464 01465 show_icons : function () { this.data.themes.icons = true; this.get_container().children("ul").removeClass("jstree-no-icons"); }, 01466 hide_icons : function () { this.data.themes.icons = false; this.get_container().children("ul").addClass("jstree-no-icons"); }, 01467 toggle_icons: function () { if(this.data.themes.icons) { this.hide_icons(); } else { this.show_icons(); } } 01468 } 01469 }); 01470 // autodetect themes path 01471 $(function () { 01472 if($.jstree._themes === false) { 01473 $("script").each(function () { 01474 if(this.src.toString().match(/jquery\.jstree[^\/]*?\.js(\?.*)?$/)) { 01475 $.jstree._themes = this.src.toString().replace(/jquery\.jstree[^\/]*?\.js(\?.*)?$/, "") + 'themes/'; 01476 return false; 01477 } 01478 }); 01479 } 01480 if($.jstree._themes === false) { $.jstree._themes = "themes/"; } 01481 }); 01482 // include the themes plugin by default 01483 $.jstree.defaults.plugins.push("themes"); 01484 })(jQuery); 01485 //*/ 01486 01487 /* 01488 * jsTree hotkeys plugin 01489 * Enables keyboard navigation for all tree instances 01490 * Depends on the jstree ui & jquery hotkeys plugins 01491 */ 01492 (function ($) { 01493 var bound = []; 01494 function exec(i, event) { 01495 var f = $.jstree._focused(), tmp; 01496 if(f && f.data && f.data.hotkeys && f.data.hotkeys.enabled) { 01497 tmp = f._get_settings().hotkeys[i]; 01498 if(tmp) { return tmp.call(f, event); } 01499 } 01500 } 01501 $.jstree.plugin("hotkeys", { 01502 __init : function () { 01503 if(typeof $.hotkeys === "undefined") { throw "jsTree hotkeys: jQuery hotkeys plugin not included."; } 01504 if(!this.data.ui) { throw "jsTree hotkeys: jsTree UI plugin not included."; } 01505 $.each(this._get_settings().hotkeys, function (i, v) { 01506 if(v !== false && $.inArray(i, bound) == -1) { 01507 $(document).bind("keydown", i, function (event) { return exec(i, event); }); 01508 bound.push(i); 01509 } 01510 }); 01511 this.get_container() 01512 .bind("lock.jstree", $.proxy(function () { 01513 if(this.data.hotkeys.enabled) { this.data.hotkeys.enabled = false; this.data.hotkeys.revert = true; } 01514 }, this)) 01515 .bind("unlock.jstree", $.proxy(function () { 01516 if(this.data.hotkeys.revert) { this.data.hotkeys.enabled = true; } 01517 }, this)); 01518 this.enable_hotkeys(); 01519 }, 01520 defaults : { 01521 "up" : function () { 01522 var o = this.data.ui.hovered || this.data.ui.last_selected || -1; 01523 this.hover_node(this._get_prev(o)); 01524 return false; 01525 }, 01526 "ctrl+up" : function () { 01527 var o = this.data.ui.hovered || this.data.ui.last_selected || -1; 01528 this.hover_node(this._get_prev(o)); 01529 return false; 01530 }, 01531 "shift+up" : function () { 01532 var o = this.data.ui.hovered || this.data.ui.last_selected || -1; 01533 this.hover_node(this._get_prev(o)); 01534 return false; 01535 }, 01536 "down" : function () { 01537 var o = this.data.ui.hovered || this.data.ui.last_selected || -1; 01538 this.hover_node(this._get_next(o)); 01539 return false; 01540 }, 01541 "ctrl+down" : function () { 01542 var o = this.data.ui.hovered || this.data.ui.last_selected || -1; 01543 this.hover_node(this._get_next(o)); 01544 return false; 01545 }, 01546 "shift+down" : function () { 01547 var o = this.data.ui.hovered || this.data.ui.last_selected || -1; 01548 this.hover_node(this._get_next(o)); 01549 return false; 01550 }, 01551 "left" : function () { 01552 var o = this.data.ui.hovered || this.data.ui.last_selected; 01553 if(o) { 01554 if(o.hasClass("jstree-open")) { this.close_node(o); } 01555 else { this.hover_node(this._get_prev(o)); } 01556 } 01557 return false; 01558 }, 01559 "ctrl+left" : function () { 01560 var o = this.data.ui.hovered || this.data.ui.last_selected; 01561 if(o) { 01562 if(o.hasClass("jstree-open")) { this.close_node(o); } 01563 else { this.hover_node(this._get_prev(o)); } 01564 } 01565 return false; 01566 }, 01567 "shift+left" : function () { 01568 var o = this.data.ui.hovered || this.data.ui.last_selected; 01569 if(o) { 01570 if(o.hasClass("jstree-open")) { this.close_node(o); } 01571 else { this.hover_node(this._get_prev(o)); } 01572 } 01573 return false; 01574 }, 01575 "right" : function () { 01576 var o = this.data.ui.hovered || this.data.ui.last_selected; 01577 if(o && o.length) { 01578 if(o.hasClass("jstree-closed")) { this.open_node(o); } 01579 else { this.hover_node(this._get_next(o)); } 01580 } 01581 return false; 01582 }, 01583 "ctrl+right" : function () { 01584 var o = this.data.ui.hovered || this.data.ui.last_selected; 01585 if(o && o.length) { 01586 if(o.hasClass("jstree-closed")) { this.open_node(o); } 01587 else { this.hover_node(this._get_next(o)); } 01588 } 01589 return false; 01590 }, 01591 "shift+right" : function () { 01592 var o = this.data.ui.hovered || this.data.ui.last_selected; 01593 if(o && o.length) { 01594 if(o.hasClass("jstree-closed")) { this.open_node(o); } 01595 else { this.hover_node(this._get_next(o)); } 01596 } 01597 return false; 01598 }, 01599 "space" : function () { 01600 if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").click(); } 01601 return false; 01602 }, 01603 "ctrl+space" : function (event) { 01604 event.type = "click"; 01605 if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").trigger(event); } 01606 return false; 01607 }, 01608 "shift+space" : function (event) { 01609 event.type = "click"; 01610 if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").trigger(event); } 01611 return false; 01612 }, 01613 "f2" : function () { this.rename(this.data.ui.hovered || this.data.ui.last_selected); }, 01614 "del" : function () { this.remove(this.data.ui.hovered || this._get_node(null)); } 01615 }, 01616 _fn : { 01617 enable_hotkeys : function () { 01618 this.data.hotkeys.enabled = true; 01619 }, 01620 disable_hotkeys : function () { 01621 this.data.hotkeys.enabled = false; 01622 } 01623 } 01624 }); 01625 })(jQuery); 01626 //*/ 01627 01628 /* 01629 * jsTree JSON plugin 01630 * The JSON data store. Datastores are build by overriding the `load_node` and `_is_loaded` functions. 01631 */ 01632 (function ($) { 01633 $.jstree.plugin("json_data", { 01634 __init : function() { 01635 var s = this._get_settings().json_data; 01636 if(s.progressive_unload) { 01637 this.get_container().bind("after_close.jstree", function (e, data) { 01638 data.rslt.obj.children("ul").remove(); 01639 }); 01640 } 01641 }, 01642 defaults : { 01643 // `data` can be a function: 01644 // * accepts two arguments - node being loaded and a callback to pass the result to 01645 // * will be executed in the current tree's scope & ajax won't be supported 01646 data : false, 01647 ajax : false, 01648 correct_state : true, 01649 progressive_render : false, 01650 progressive_unload : false 01651 }, 01652 _fn : { 01653 load_node : function (obj, s_call, e_call) { var _this = this; this.load_node_json(obj, function () { _this.__callback({ "obj" : _this._get_node(obj) }); s_call.call(this); }, e_call); }, 01654 _is_loaded : function (obj) { 01655 var s = this._get_settings().json_data; 01656 obj = this._get_node(obj); 01657 return obj == -1 || !obj || (!s.ajax && !s.progressive_render && !$.isFunction(s.data)) || obj.is(".jstree-open, .jstree-leaf") || obj.children("ul").children("li").length > 0; 01658 }, 01659 refresh : function (obj) { 01660 obj = this._get_node(obj); 01661 var s = this._get_settings().json_data; 01662 if(obj && obj !== -1 && s.progressive_unload && ($.isFunction(s.data) || !!s.ajax)) { 01663 obj.removeData("jstree_children"); 01664 } 01665 return this.__call_old(); 01666 }, 01667 load_node_json : function (obj, s_call, e_call) { 01668 var s = this.get_settings().json_data, d, 01669 error_func = function () {}, 01670 success_func = function () {}; 01671 obj = this._get_node(obj); 01672 01673 if(obj && obj !== -1 && (s.progressive_render || s.progressive_unload) && !obj.is(".jstree-open, .jstree-leaf") && obj.children("ul").children("li").length === 0 && obj.data("jstree_children")) { 01674 d = this._parse_json(obj.data("jstree_children"), obj); 01675 if(d) { 01676 obj.append(d); 01677 if(!s.progressive_unload) { obj.removeData("jstree_children"); } 01678 } 01679 this.clean_node(obj); 01680 if(s_call) { s_call.call(this); } 01681 return; 01682 } 01683 01684 if(obj && obj !== -1) { 01685 if(obj.data("jstree_is_loading")) { return; } 01686 else { obj.data("jstree_is_loading",true); } 01687 } 01688 switch(!0) { 01689 case (!s.data && !s.ajax): throw "Neither data nor ajax settings supplied."; 01690 // function option added here for easier model integration (also supporting async - see callback) 01691 case ($.isFunction(s.data)): 01692 s.data.call(this, obj, $.proxy(function (d) { 01693 d = this._parse_json(d, obj); 01694 if(!d) { 01695 if(obj === -1 || !obj) { 01696 if(s.correct_state) { this.get_container().children("ul").empty(); } 01697 } 01698 else { 01699 obj.children("a.jstree-loading").removeClass("jstree-loading"); 01700 obj.removeData("jstree_is_loading"); 01701 if(s.correct_state) { this.correct_state(obj); } 01702 } 01703 if(e_call) { e_call.call(this); } 01704 } 01705 else { 01706 if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); } 01707 else { obj.append(d).children("a.jstree-loading").removeClass("jstree-loading"); obj.removeData("jstree_is_loading"); } 01708 this.clean_node(obj); 01709 if(s_call) { s_call.call(this); } 01710 } 01711 }, this)); 01712 break; 01713 case (!!s.data && !s.ajax) || (!!s.data && !!s.ajax && (!obj || obj === -1)): 01714 if(!obj || obj == -1) { 01715 d = this._parse_json(s.data, obj); 01716 if(d) { 01717 this.get_container().children("ul").empty().append(d.children()); 01718 this.clean_node(); 01719 } 01720 else { 01721 if(s.correct_state) { this.get_container().children("ul").empty(); } 01722 } 01723 } 01724 if(s_call) { s_call.call(this); } 01725 break; 01726 case (!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj && obj !== -1): 01727 error_func = function (x, t, e) { 01728 var ef = this.get_settings().json_data.ajax.error; 01729 if(ef) { ef.call(this, x, t, e); } 01730 if(obj != -1 && obj.length) { 01731 obj.children("a.jstree-loading").removeClass("jstree-loading"); 01732 obj.removeData("jstree_is_loading"); 01733 if(t === "success" && s.correct_state) { this.correct_state(obj); } 01734 } 01735 else { 01736 if(t === "success" && s.correct_state) { this.get_container().children("ul").empty(); } 01737 } 01738 if(e_call) { e_call.call(this); } 01739 }; 01740 success_func = function (d, t, x) { 01741 var sf = this.get_settings().json_data.ajax.success; 01742 if(sf) { d = sf.call(this,d,t,x) || d; } 01743 if(d === "" || (d && d.toString && d.toString().replace(/^[\s\n]+$/,"") === "") || (!$.isArray(d) && !$.isPlainObject(d))) { 01744 return error_func.call(this, x, t, ""); 01745 } 01746 d = this._parse_json(d, obj); 01747 if(d) { 01748 if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); } 01749 else { obj.append(d).children("a.jstree-loading").removeClass("jstree-loading"); obj.removeData("jstree_is_loading"); } 01750 this.clean_node(obj); 01751 if(s_call) { s_call.call(this); } 01752 } 01753 else { 01754 if(obj === -1 || !obj) { 01755 if(s.correct_state) { 01756 this.get_container().children("ul").empty(); 01757 if(s_call) { s_call.call(this); } 01758 } 01759 } 01760 else { 01761 obj.children("a.jstree-loading").removeClass("jstree-loading"); 01762 obj.removeData("jstree_is_loading"); 01763 if(s.correct_state) { 01764 this.correct_state(obj); 01765 if(s_call) { s_call.call(this); } 01766 } 01767 } 01768 } 01769 }; 01770 s.ajax.context = this; 01771 s.ajax.error = error_func; 01772 s.ajax.success = success_func; 01773 if(!s.ajax.dataType) { s.ajax.dataType = "json"; } 01774 if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); } 01775 if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); } 01776 $.ajax(s.ajax); 01777 break; 01778 } 01779 }, 01780 _parse_json : function (js, obj, is_callback) { 01781 var d = false, 01782 p = this._get_settings(), 01783 s = p.json_data, 01784 t = p.core.html_titles, 01785 tmp, i, j, ul1, ul2; 01786 01787 if(!js) { return d; } 01788 if(s.progressive_unload && obj && obj !== -1) { 01789 obj.data("jstree_children", d); 01790 } 01791 if($.isArray(js)) { 01792 d = $(); 01793 if(!js.length) { return false; } 01794 for(i = 0, j = js.length; i < j; i++) { 01795 tmp = this._parse_json(js[i], obj, true); 01796 if(tmp.length) { d = d.add(tmp); } 01797 } 01798 } 01799 else { 01800 if(typeof js == "string") { js = { data : js }; } 01801 if(!js.data && js.data !== "") { return d; } 01802 d = $("<li />"); 01803 if(js.attr) { d.attr(js.attr); } 01804 if(js.metadata) { d.data(js.metadata); } 01805 if(js.state) { d.addClass("jstree-" + js.state); } 01806 if(!$.isArray(js.data)) { tmp = js.data; js.data = []; js.data.push(tmp); } 01807 $.each(js.data, function (i, m) { 01808 tmp = $("<a />"); 01809 if($.isFunction(m)) { m = m.call(this, js); } 01810 if(typeof m == "string") { tmp.attr('href','#')[ t ? "html" : "text" ](m); } 01811 else { 01812 if(!m.attr) { m.attr = {}; } 01813 if(!m.attr.href) { m.attr.href = '#'; } 01814 tmp.attr(m.attr)[ t ? "html" : "text" ](m.title); 01815 if(m.language) { tmp.addClass(m.language); } 01816 } 01817 tmp.prepend("<ins class='jstree-icon'> </ins>"); 01818 if(!m.icon && js.icon) { m.icon = js.icon; } 01819 if(m.icon) { 01820 if(m.icon.indexOf("/") === -1) { tmp.children("ins").addClass(m.icon); } 01821 else { tmp.children("ins").css("background","url('" + m.icon + "') center center no-repeat"); } 01822 } 01823 d.append(tmp); 01824 }); 01825 d.prepend("<ins class='jstree-icon'> </ins>"); 01826 if(js.children) { 01827 if(s.progressive_render && js.state !== "open") { 01828 d.addClass("jstree-closed").data("jstree_children", js.children); 01829 } 01830 else { 01831 if(s.progressive_unload) { d.data("jstree_children", js.children); } 01832 if($.isArray(js.children) && js.children.length) { 01833 tmp = this._parse_json(js.children, obj, true); 01834 if(tmp.length) { 01835 ul2 = $("<ul />"); 01836 ul2.append(tmp); 01837 d.append(ul2); 01838 } 01839 } 01840 } 01841 } 01842 } 01843 if(!is_callback) { 01844 ul1 = $("<ul />"); 01845 ul1.append(d); 01846 d = ul1; 01847 } 01848 return d; 01849 }, 01850 get_json : function (obj, li_attr, a_attr, is_callback) { 01851 var result = [], 01852 s = this._get_settings(), 01853 _this = this, 01854 tmp1, tmp2, li, a, t, lang; 01855 obj = this._get_node(obj); 01856 if(!obj || obj === -1) { obj = this.get_container().find("> ul > li"); } 01857 li_attr = $.isArray(li_attr) ? li_attr : [ "id", "class" ]; 01858 if(!is_callback && this.data.types) { li_attr.push(s.types.type_attr); } 01859 a_attr = $.isArray(a_attr) ? a_attr : [ ]; 01860 01861 obj.each(function () { 01862 li = $(this); 01863 tmp1 = { data : [] }; 01864 if(li_attr.length) { tmp1.attr = { }; } 01865 $.each(li_attr, function (i, v) { 01866 tmp2 = li.attr(v); 01867 if(tmp2 && tmp2.length && tmp2.replace(/jstree[^ ]*/ig,'').length) { 01868 tmp1.attr[v] = (" " + tmp2).replace(/ jstree[^ ]*/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,""); 01869 } 01870 }); 01871 if(li.hasClass("jstree-open")) { tmp1.state = "open"; } 01872 if(li.hasClass("jstree-closed")) { tmp1.state = "closed"; } 01873 if(li.data()) { tmp1.metadata = li.data(); } 01874 a = li.children("a"); 01875 a.each(function () { 01876 t = $(this); 01877 if( 01878 a_attr.length || 01879 $.inArray("languages", s.plugins) !== -1 || 01880 t.children("ins").get(0).style.backgroundImage.length || 01881 (t.children("ins").get(0).className && t.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').length) 01882 ) { 01883 lang = false; 01884 if($.inArray("languages", s.plugins) !== -1 && $.isArray(s.languages) && s.languages.length) { 01885 $.each(s.languages, function (l, lv) { 01886 if(t.hasClass(lv)) { 01887 lang = lv; 01888 return false; 01889 } 01890 }); 01891 } 01892 tmp2 = { attr : { }, title : _this.get_text(t, lang) }; 01893 $.each(a_attr, function (k, z) { 01894 tmp2.attr[z] = (" " + (t.attr(z) || "")).replace(/ jstree[^ ]*/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,""); 01895 }); 01896 if($.inArray("languages", s.plugins) !== -1 && $.isArray(s.languages) && s.languages.length) { 01897 $.each(s.languages, function (k, z) { 01898 if(t.hasClass(z)) { tmp2.language = z; return true; } 01899 }); 01900 } 01901 if(t.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/^\s+$/ig,"").length) { 01902 tmp2.icon = t.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,""); 01903 } 01904 if(t.children("ins").get(0).style.backgroundImage.length) { 01905 tmp2.icon = t.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")",""); 01906 } 01907 } 01908 else { 01909 tmp2 = _this.get_text(t); 01910 } 01911 if(a.length > 1) { tmp1.data.push(tmp2); } 01912 else { tmp1.data = tmp2; } 01913 }); 01914 li = li.find("> ul > li"); 01915 if(li.length) { tmp1.children = _this.get_json(li, li_attr, a_attr, true); } 01916 result.push(tmp1); 01917 }); 01918 return result; 01919 } 01920 } 01921 }); 01922 })(jQuery); 01923 //*/ 01924 01925 /* 01926 * jsTree languages plugin 01927 * Adds support for multiple language versions in one tree 01928 * This basically allows for many titles coexisting in one node, but only one of them being visible at any given time 01929 * This is useful for maintaining the same structure in many languages (hence the name of the plugin) 01930 */ 01931 (function ($) { 01932 $.jstree.plugin("languages", { 01933 __init : function () { this._load_css(); }, 01934 defaults : [], 01935 _fn : { 01936 set_lang : function (i) { 01937 var langs = this._get_settings().languages, 01938 st = false, 01939 selector = ".jstree-" + this.get_index() + ' a'; 01940 if(!$.isArray(langs) || langs.length === 0) { return false; } 01941 if($.inArray(i,langs) == -1) { 01942 if(!!langs[i]) { i = langs[i]; } 01943 else { return false; } 01944 } 01945 if(i == this.data.languages.current_language) { return true; } 01946 st = $.vakata.css.get_css(selector + "." + this.data.languages.current_language, false, this.data.languages.language_css); 01947 if(st !== false) { st.style.display = "none"; } 01948 st = $.vakata.css.get_css(selector + "." + i, false, this.data.languages.language_css); 01949 if(st !== false) { st.style.display = ""; } 01950 this.data.languages.current_language = i; 01951 this.__callback(i); 01952 return true; 01953 }, 01954 get_lang : function () { 01955 return this.data.languages.current_language; 01956 }, 01957 _get_string : function (key, lang) { 01958 var langs = this._get_settings().languages, 01959 s = this._get_settings().core.strings; 01960 if($.isArray(langs) && langs.length) { 01961 lang = (lang && $.inArray(lang,langs) != -1) ? lang : this.data.languages.current_language; 01962 } 01963 if(s[lang] && s[lang][key]) { return s[lang][key]; } 01964 if(s[key]) { return s[key]; } 01965 return key; 01966 }, 01967 get_text : function (obj, lang) { 01968 obj = this._get_node(obj) || this.data.ui.last_selected; 01969 if(!obj.size()) { return false; } 01970 var langs = this._get_settings().languages, 01971 s = this._get_settings().core.html_titles; 01972 if($.isArray(langs) && langs.length) { 01973 lang = (lang && $.inArray(lang,langs) != -1) ? lang : this.data.languages.current_language; 01974 obj = obj.children("a." + lang); 01975 } 01976 else { obj = obj.children("a:eq(0)"); } 01977 if(s) { 01978 obj = obj.clone(); 01979 obj.children("INS").remove(); 01980 return obj.html(); 01981 } 01982 else { 01983 obj = obj.contents().filter(function() { return this.nodeType == 3; })[0]; 01984 return obj.nodeValue; 01985 } 01986 }, 01987 set_text : function (obj, val, lang) { 01988 obj = this._get_node(obj) || this.data.ui.last_selected; 01989 if(!obj.size()) { return false; } 01990 var langs = this._get_settings().languages, 01991 s = this._get_settings().core.html_titles, 01992 tmp; 01993 if($.isArray(langs) && langs.length) { 01994 lang = (lang && $.inArray(lang,langs) != -1) ? lang : this.data.languages.current_language; 01995 obj = obj.children("a." + lang); 01996 } 01997 else { obj = obj.children("a:eq(0)"); } 01998 if(s) { 01999 tmp = obj.children("INS").clone(); 02000 obj.html(val).prepend(tmp); 02001 this.__callback({ "obj" : obj, "name" : val, "lang" : lang }); 02002 return true; 02003 } 02004 else { 02005 obj = obj.contents().filter(function() { return this.nodeType == 3; })[0]; 02006 this.__callback({ "obj" : obj, "name" : val, "lang" : lang }); 02007 return (obj.nodeValue = val); 02008 } 02009 }, 02010 _load_css : function () { 02011 var langs = this._get_settings().languages, 02012 str = "/* languages css */", 02013 selector = ".jstree-" + this.get_index() + ' a', 02014 ln; 02015 if($.isArray(langs) && langs.length) { 02016 this.data.languages.current_language = langs[0]; 02017 for(ln = 0; ln < langs.length; ln++) { 02018 str += selector + "." + langs[ln] + " {"; 02019 if(langs[ln] != this.data.languages.current_language) { str += " display:none; "; } 02020 str += " } "; 02021 } 02022 this.data.languages.language_css = $.vakata.css.add_sheet({ 'str' : str, 'title' : "jstree-languages" }); 02023 } 02024 }, 02025 create_node : function (obj, position, js, callback) { 02026 var t = this.__call_old(true, obj, position, js, function (t) { 02027 var langs = this._get_settings().languages, 02028 a = t.children("a"), 02029 ln; 02030 if($.isArray(langs) && langs.length) { 02031 for(ln = 0; ln < langs.length; ln++) { 02032 if(!a.is("." + langs[ln])) { 02033 t.append(a.eq(0).clone().removeClass(langs.join(" ")).addClass(langs[ln])); 02034 } 02035 } 02036 a.not("." + langs.join(", .")).remove(); 02037 } 02038 if(callback) { callback.call(this, t); } 02039 }); 02040 return t; 02041 } 02042 } 02043 }); 02044 })(jQuery); 02045 //*/ 02046 02047 /* 02048 * jsTree cookies plugin 02049 * Stores the currently opened/selected nodes in a cookie and then restores them 02050 * Depends on the jquery.cookie plugin 02051 */ 02052 (function ($) { 02053 $.jstree.plugin("cookies", { 02054 __init : function () { 02055 if(typeof $.cookie === "undefined") { throw "jsTree cookie: jQuery cookie plugin not included."; } 02056 02057 var s = this._get_settings().cookies, 02058 tmp; 02059 if(!!s.save_loaded) { 02060 tmp = $.cookie(s.save_loaded); 02061 if(tmp && tmp.length) { this.data.core.to_load = tmp.split(","); } 02062 } 02063 if(!!s.save_opened) { 02064 tmp = $.cookie(s.save_opened); 02065 if(tmp && tmp.length) { this.data.core.to_open = tmp.split(","); } 02066 } 02067 if(!!s.save_selected) { 02068 tmp = $.cookie(s.save_selected); 02069 if(tmp && tmp.length && this.data.ui) { this.data.ui.to_select = tmp.split(","); } 02070 } 02071 this.get_container() 02072 .one( ( this.data.ui ? "reselect" : "reopen" ) + ".jstree", $.proxy(function () { 02073 this.get_container() 02074 .bind("open_node.jstree close_node.jstree select_node.jstree deselect_node.jstree", $.proxy(function (e) { 02075 if(this._get_settings().cookies.auto_save) { this.save_cookie((e.handleObj.namespace + e.handleObj.type).replace("jstree","")); } 02076 }, this)); 02077 }, this)); 02078 }, 02079 defaults : { 02080 save_loaded : "jstree_load", 02081 save_opened : "jstree_open", 02082 save_selected : "jstree_select", 02083 auto_save : true, 02084 cookie_options : {} 02085 }, 02086 _fn : { 02087 save_cookie : function (c) { 02088 if(this.data.core.refreshing) { return; } 02089 var s = this._get_settings().cookies; 02090 if(!c) { // if called manually and not by event 02091 if(s.save_loaded) { 02092 this.save_loaded(); 02093 $.cookie(s.save_loaded, this.data.core.to_load.join(","), s.cookie_options); 02094 } 02095 if(s.save_opened) { 02096 this.save_opened(); 02097 $.cookie(s.save_opened, this.data.core.to_open.join(","), s.cookie_options); 02098 } 02099 if(s.save_selected && this.data.ui) { 02100 this.save_selected(); 02101 $.cookie(s.save_selected, this.data.ui.to_select.join(","), s.cookie_options); 02102 } 02103 return; 02104 } 02105 switch(c) { 02106 case "open_node": 02107 case "close_node": 02108 if(!!s.save_opened) { 02109 this.save_opened(); 02110 $.cookie(s.save_opened, this.data.core.to_open.join(","), s.cookie_options); 02111 } 02112 if(!!s.save_loaded) { 02113 this.save_loaded(); 02114 $.cookie(s.save_loaded, this.data.core.to_load.join(","), s.cookie_options); 02115 } 02116 break; 02117 case "select_node": 02118 case "deselect_node": 02119 if(!!s.save_selected && this.data.ui) { 02120 this.save_selected(); 02121 $.cookie(s.save_selected, this.data.ui.to_select.join(","), s.cookie_options); 02122 } 02123 break; 02124 } 02125 } 02126 } 02127 }); 02128 // include cookies by default 02129 // $.jstree.defaults.plugins.push("cookies"); 02130 })(jQuery); 02131 //*/ 02132 02133 /* 02134 * jsTree sort plugin 02135 * Sorts items alphabetically (or using any other function) 02136 */ 02137 (function ($) { 02138 $.jstree.plugin("sort", { 02139 __init : function () { 02140 this.get_container() 02141 .bind("load_node.jstree", $.proxy(function (e, data) { 02142 var obj = this._get_node(data.rslt.obj); 02143 obj = obj === -1 ? this.get_container().children("ul") : obj.children("ul"); 02144 this.sort(obj); 02145 }, this)) 02146 .bind("rename_node.jstree create_node.jstree create.jstree", $.proxy(function (e, data) { 02147 this.sort(data.rslt.obj.parent()); 02148 }, this)) 02149 .bind("move_node.jstree", $.proxy(function (e, data) { 02150 var m = data.rslt.np == -1 ? this.get_container() : data.rslt.np; 02151 this.sort(m.children("ul")); 02152 }, this)); 02153 }, 02154 defaults : function (a, b) { return this.get_text(a) > this.get_text(b) ? 1 : -1; }, 02155 _fn : { 02156 sort : function (obj) { 02157 var s = this._get_settings().sort, 02158 t = this; 02159 obj.append($.makeArray(obj.children("li")).sort($.proxy(s, t))); 02160 obj.find("> li > ul").each(function() { t.sort($(this)); }); 02161 this.clean_node(obj); 02162 } 02163 } 02164 }); 02165 })(jQuery); 02166 //*/ 02167 02168 /* 02169 * jsTree DND plugin 02170 * Drag and drop plugin for moving/copying nodes 02171 */ 02172 (function ($) { 02173 var o = false, 02174 r = false, 02175 m = false, 02176 ml = false, 02177 sli = false, 02178 sti = false, 02179 dir1 = false, 02180 dir2 = false, 02181 last_pos = false; 02182 $.vakata.dnd = { 02183 is_down : false, 02184 is_drag : false, 02185 helper : false, 02186 scroll_spd : 10, 02187 init_x : 0, 02188 init_y : 0, 02189 threshold : 5, 02190 helper_left : 5, 02191 helper_top : 10, 02192 user_data : {}, 02193 02194 drag_start : function (e, data, html) { 02195 if($.vakata.dnd.is_drag) { $.vakata.drag_stop({}); } 02196 try { 02197 e.currentTarget.unselectable = "on"; 02198 e.currentTarget.onselectstart = function() { return false; }; 02199 if(e.currentTarget.style) { e.currentTarget.style.MozUserSelect = "none"; } 02200 } catch(err) { } 02201 $.vakata.dnd.init_x = e.pageX; 02202 $.vakata.dnd.init_y = e.pageY; 02203 $.vakata.dnd.user_data = data; 02204 $.vakata.dnd.is_down = true; 02205 $.vakata.dnd.helper = $("<div id='vakata-dragged' />").html(html); //.fadeTo(10,0.25); 02206 $(document).bind("mousemove", $.vakata.dnd.drag); 02207 $(document).bind("mouseup", $.vakata.dnd.drag_stop); 02208 return false; 02209 }, 02210 drag : function (e) { 02211 if(!$.vakata.dnd.is_down) { return; } 02212 if(!$.vakata.dnd.is_drag) { 02213 if(Math.abs(e.pageX - $.vakata.dnd.init_x) > 5 || Math.abs(e.pageY - $.vakata.dnd.init_y) > 5) { 02214 $.vakata.dnd.helper.appendTo("body"); 02215 $.vakata.dnd.is_drag = true; 02216 $(document).triggerHandler("drag_start.vakata", { "event" : e, "data" : $.vakata.dnd.user_data }); 02217 } 02218 else { return; } 02219 } 02220 02221 // maybe use a scrolling parent element instead of document? 02222 if(e.type === "mousemove") { // thought of adding scroll in order to move the helper, but mouse poisition is n/a 02223 var d = $(document), t = d.scrollTop(), l = d.scrollLeft(); 02224 if(e.pageY - t < 20) { 02225 if(sti && dir1 === "down") { clearInterval(sti); sti = false; } 02226 if(!sti) { dir1 = "up"; sti = setInterval(function () { $(document).scrollTop($(document).scrollTop() - $.vakata.dnd.scroll_spd); }, 150); } 02227 } 02228 else { 02229 if(sti && dir1 === "up") { clearInterval(sti); sti = false; } 02230 } 02231 if($(window).height() - (e.pageY - t) < 20) { 02232 if(sti && dir1 === "up") { clearInterval(sti); sti = false; } 02233 if(!sti) { dir1 = "down"; sti = setInterval(function () { $(document).scrollTop($(document).scrollTop() + $.vakata.dnd.scroll_spd); }, 150); } 02234 } 02235 else { 02236 if(sti && dir1 === "down") { clearInterval(sti); sti = false; } 02237 } 02238 02239 if(e.pageX - l < 20) { 02240 if(sli && dir2 === "right") { clearInterval(sli); sli = false; } 02241 if(!sli) { dir2 = "left"; sli = setInterval(function () { $(document).scrollLeft($(document).scrollLeft() - $.vakata.dnd.scroll_spd); }, 150); } 02242 } 02243 else { 02244 if(sli && dir2 === "left") { clearInterval(sli); sli = false; } 02245 } 02246 if($(window).width() - (e.pageX - l) < 20) { 02247 if(sli && dir2 === "left") { clearInterval(sli); sli = false; } 02248 if(!sli) { dir2 = "right"; sli = setInterval(function () { $(document).scrollLeft($(document).scrollLeft() + $.vakata.dnd.scroll_spd); }, 150); } 02249 } 02250 else { 02251 if(sli && dir2 === "right") { clearInterval(sli); sli = false; } 02252 } 02253 } 02254 02255 $.vakata.dnd.helper.css({ left : (e.pageX + $.vakata.dnd.helper_left) + "px", top : (e.pageY + $.vakata.dnd.helper_top) + "px" }); 02256 $(document).triggerHandler("drag.vakata", { "event" : e, "data" : $.vakata.dnd.user_data }); 02257 }, 02258 drag_stop : function (e) { 02259 if(sli) { clearInterval(sli); } 02260 if(sti) { clearInterval(sti); } 02261 $(document).unbind("mousemove", $.vakata.dnd.drag); 02262 $(document).unbind("mouseup", $.vakata.dnd.drag_stop); 02263 $(document).triggerHandler("drag_stop.vakata", { "event" : e, "data" : $.vakata.dnd.user_data }); 02264 $.vakata.dnd.helper.remove(); 02265 $.vakata.dnd.init_x = 0; 02266 $.vakata.dnd.init_y = 0; 02267 $.vakata.dnd.user_data = {}; 02268 $.vakata.dnd.is_down = false; 02269 $.vakata.dnd.is_drag = false; 02270 } 02271 }; 02272 $(function() { 02273 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; } '; 02274 $.vakata.css.add_sheet({ str : css_string, title : "vakata" }); 02275 }); 02276 02277 $.jstree.plugin("dnd", { 02278 __init : function () { 02279 this.data.dnd = { 02280 active : false, 02281 after : false, 02282 inside : false, 02283 before : false, 02284 off : false, 02285 prepared : false, 02286 w : 0, 02287 to1 : false, 02288 to2 : false, 02289 cof : false, 02290 cw : false, 02291 ch : false, 02292 i1 : false, 02293 i2 : false, 02294 mto : false 02295 }; 02296 this.get_container() 02297 .bind("mouseenter.jstree", $.proxy(function (e) { 02298 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) { 02299 if(this.data.themes) { 02300 m.attr("class", "jstree-" + this.data.themes.theme); 02301 if(ml) { ml.attr("class", "jstree-" + this.data.themes.theme); } 02302 $.vakata.dnd.helper.attr("class", "jstree-dnd-helper jstree-" + this.data.themes.theme); 02303 } 02304 //if($(e.currentTarget).find("> ul > li").length === 0) { 02305 if(e.currentTarget === e.target && $.vakata.dnd.user_data.obj && $($.vakata.dnd.user_data.obj).length && $($.vakata.dnd.user_data.obj).parents(".jstree:eq(0)")[0] !== e.target) { // node should not be from the same tree 02306 var tr = $.jstree._reference(e.target), dc; 02307 if(tr.data.dnd.foreign) { 02308 dc = tr._get_settings().dnd.drag_check.call(this, { "o" : o, "r" : tr.get_container(), is_root : true }); 02309 if(dc === true || dc.inside === true || dc.before === true || dc.after === true) { 02310 $.vakata.dnd.helper.children("ins").attr("class","jstree-ok"); 02311 } 02312 } 02313 else { 02314 tr.prepare_move(o, tr.get_container(), "last"); 02315 if(tr.check_move()) { 02316 $.vakata.dnd.helper.children("ins").attr("class","jstree-ok"); 02317 } 02318 } 02319 } 02320 } 02321 }, this)) 02322 .bind("mouseup.jstree", $.proxy(function (e) { 02323 //if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree && $(e.currentTarget).find("> ul > li").length === 0) { 02324 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree && e.currentTarget === e.target && $.vakata.dnd.user_data.obj && $($.vakata.dnd.user_data.obj).length && $($.vakata.dnd.user_data.obj).parents(".jstree:eq(0)")[0] !== e.target) { // node should not be from the same tree 02325 var tr = $.jstree._reference(e.currentTarget), dc; 02326 if(tr.data.dnd.foreign) { 02327 dc = tr._get_settings().dnd.drag_check.call(this, { "o" : o, "r" : tr.get_container(), is_root : true }); 02328 if(dc === true || dc.inside === true || dc.before === true || dc.after === true) { 02329 tr._get_settings().dnd.drag_finish.call(this, { "o" : o, "r" : tr.get_container(), is_root : true }); 02330 } 02331 } 02332 else { 02333 tr.move_node(o, tr.get_container(), "last", e[tr._get_settings().dnd.copy_modifier + "Key"]); 02334 } 02335 } 02336 }, this)) 02337 .bind("mouseleave.jstree", $.proxy(function (e) { 02338 if(e.relatedTarget && e.relatedTarget.id && e.relatedTarget.id === "jstree-marker-line") { 02339 return false; 02340 } 02341 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) { 02342 if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); } 02343 if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); } 02344 if(this.data.dnd.to1) { clearTimeout(this.data.dnd.to1); } 02345 if(this.data.dnd.to2) { clearTimeout(this.data.dnd.to2); } 02346 if($.vakata.dnd.helper.children("ins").hasClass("jstree-ok")) { 02347 $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid"); 02348 } 02349 } 02350 }, this)) 02351 .bind("mousemove.jstree", $.proxy(function (e) { 02352 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) { 02353 var cnt = this.get_container()[0]; 02354 02355 // Horizontal scroll 02356 if(e.pageX + 24 > this.data.dnd.cof.left + this.data.dnd.cw) { 02357 if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); } 02358 this.data.dnd.i1 = setInterval($.proxy(function () { this.scrollLeft += $.vakata.dnd.scroll_spd; }, cnt), 100); 02359 } 02360 else if(e.pageX - 24 < this.data.dnd.cof.left) { 02361 if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); } 02362 this.data.dnd.i1 = setInterval($.proxy(function () { this.scrollLeft -= $.vakata.dnd.scroll_spd; }, cnt), 100); 02363 } 02364 else { 02365 if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); } 02366 } 02367 02368 // Vertical scroll 02369 if(e.pageY + 24 > this.data.dnd.cof.top + this.data.dnd.ch) { 02370 if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); } 02371 this.data.dnd.i2 = setInterval($.proxy(function () { this.scrollTop += $.vakata.dnd.scroll_spd; }, cnt), 100); 02372 } 02373 else if(e.pageY - 24 < this.data.dnd.cof.top) { 02374 if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); } 02375 this.data.dnd.i2 = setInterval($.proxy(function () { this.scrollTop -= $.vakata.dnd.scroll_spd; }, cnt), 100); 02376 } 02377 else { 02378 if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); } 02379 } 02380 02381 } 02382 }, this)) 02383 .bind("scroll.jstree", $.proxy(function (e) { 02384 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree && m && ml) { 02385 m.hide(); 02386 ml.hide(); 02387 } 02388 }, this)) 02389 .delegate("a", "mousedown.jstree", $.proxy(function (e) { 02390 if(e.which === 1) { 02391 this.start_drag(e.currentTarget, e); 02392 return false; 02393 } 02394 }, this)) 02395 .delegate("a", "mouseenter.jstree", $.proxy(function (e) { 02396 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) { 02397 this.dnd_enter(e.currentTarget); 02398 } 02399 }, this)) 02400 .delegate("a", "mousemove.jstree", $.proxy(function (e) { 02401 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) { 02402 if(!r || !r.length || r.children("a")[0] !== e.currentTarget) { 02403 this.dnd_enter(e.currentTarget); 02404 } 02405 if(typeof this.data.dnd.off.top === "undefined") { this.data.dnd.off = $(e.target).offset(); } 02406 this.data.dnd.w = (e.pageY - (this.data.dnd.off.top || 0)) % this.data.core.li_height; 02407 if(this.data.dnd.w < 0) { this.data.dnd.w += this.data.core.li_height; } 02408 this.dnd_show(); 02409 } 02410 }, this)) 02411 .delegate("a", "mouseleave.jstree", $.proxy(function (e) { 02412 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) { 02413 if(e.relatedTarget && e.relatedTarget.id && e.relatedTarget.id === "jstree-marker-line") { 02414 return false; 02415 } 02416 if(m) { m.hide(); } 02417 if(ml) { ml.hide(); } 02418 /* 02419 var ec = $(e.currentTarget).closest("li"), 02420 er = $(e.relatedTarget).closest("li"); 02421 if(er[0] !== ec.prev()[0] && er[0] !== ec.next()[0]) { 02422 if(m) { m.hide(); } 02423 if(ml) { ml.hide(); } 02424 } 02425 */ 02426 this.data.dnd.mto = setTimeout( 02427 (function (t) { return function () { t.dnd_leave(e); }; })(this), 02428 0); 02429 } 02430 }, this)) 02431 .delegate("a", "mouseup.jstree", $.proxy(function (e) { 02432 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree) { 02433 this.dnd_finish(e); 02434 } 02435 }, this)); 02436 02437 $(document) 02438 .bind("drag_stop.vakata", $.proxy(function () { 02439 if(this.data.dnd.to1) { clearTimeout(this.data.dnd.to1); } 02440 if(this.data.dnd.to2) { clearTimeout(this.data.dnd.to2); } 02441 if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); } 02442 if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); } 02443 this.data.dnd.after = false; 02444 this.data.dnd.before = false; 02445 this.data.dnd.inside = false; 02446 this.data.dnd.off = false; 02447 this.data.dnd.prepared = false; 02448 this.data.dnd.w = false; 02449 this.data.dnd.to1 = false; 02450 this.data.dnd.to2 = false; 02451 this.data.dnd.i1 = false; 02452 this.data.dnd.i2 = false; 02453 this.data.dnd.active = false; 02454 this.data.dnd.foreign = false; 02455 if(m) { m.css({ "top" : "-2000px" }); } 02456 if(ml) { ml.css({ "top" : "-2000px" }); } 02457 }, this)) 02458 .bind("drag_start.vakata", $.proxy(function (e, data) { 02459 if(data.data.jstree) { 02460 var et = $(data.event.target); 02461 if(et.closest(".jstree").hasClass("jstree-" + this.get_index())) { 02462 this.dnd_enter(et); 02463 } 02464 } 02465 }, this)); 02466 /* 02467 .bind("keydown.jstree-" + this.get_index() + " keyup.jstree-" + this.get_index(), $.proxy(function(e) { 02468 if($.vakata.dnd.is_drag && $.vakata.dnd.user_data.jstree && !this.data.dnd.foreign) { 02469 var h = $.vakata.dnd.helper.children("ins"); 02470 if(e[this._get_settings().dnd.copy_modifier + "Key"] && h.hasClass("jstree-ok")) { 02471 h.parent().html(h.parent().html().replace(/ \(Copy\)$/, "") + " (Copy)"); 02472 } 02473 else { 02474 h.parent().html(h.parent().html().replace(/ \(Copy\)$/, "")); 02475 } 02476 } 02477 }, this)); */ 02478 02479 02480 02481 var s = this._get_settings().dnd; 02482 if(s.drag_target) { 02483 $(document) 02484 .delegate(s.drag_target, "mousedown.jstree-" + this.get_index(), $.proxy(function (e) { 02485 o = e.target; 02486 $.vakata.dnd.drag_start(e, { jstree : true, obj : e.target }, "<ins class='jstree-icon'></ins>" + $(e.target).text() ); 02487 if(this.data.themes) { 02488 if(m) { m.attr("class", "jstree-" + this.data.themes.theme); } 02489 if(ml) { ml.attr("class", "jstree-" + this.data.themes.theme); } 02490 $.vakata.dnd.helper.attr("class", "jstree-dnd-helper jstree-" + this.data.themes.theme); 02491 } 02492 $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid"); 02493 var cnt = this.get_container(); 02494 this.data.dnd.cof = cnt.offset(); 02495 this.data.dnd.cw = parseInt(cnt.width(),10); 02496 this.data.dnd.ch = parseInt(cnt.height(),10); 02497 this.data.dnd.foreign = true; 02498 e.preventDefault(); 02499 }, this)); 02500 } 02501 if(s.drop_target) { 02502 $(document) 02503 .delegate(s.drop_target, "mouseenter.jstree-" + this.get_index(), $.proxy(function (e) { 02504 if(this.data.dnd.active && this._get_settings().dnd.drop_check.call(this, { "o" : o, "r" : $(e.target), "e" : e })) { 02505 $.vakata.dnd.helper.children("ins").attr("class","jstree-ok"); 02506 } 02507 }, this)) 02508 .delegate(s.drop_target, "mouseleave.jstree-" + this.get_index(), $.proxy(function (e) { 02509 if(this.data.dnd.active) { 02510 $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid"); 02511 } 02512 }, this)) 02513 .delegate(s.drop_target, "mouseup.jstree-" + this.get_index(), $.proxy(function (e) { 02514 if(this.data.dnd.active && $.vakata.dnd.helper.children("ins").hasClass("jstree-ok")) { 02515 this._get_settings().dnd.drop_finish.call(this, { "o" : o, "r" : $(e.target), "e" : e }); 02516 } 02517 }, this)); 02518 } 02519 }, 02520 defaults : { 02521 copy_modifier : "ctrl", 02522 check_timeout : 100, 02523 open_timeout : 500, 02524 drop_target : ".jstree-drop", 02525 drop_check : function (data) { return true; }, 02526 drop_finish : $.noop, 02527 drag_target : ".jstree-draggable", 02528 drag_finish : $.noop, 02529 drag_check : function (data) { return { after : false, before : false, inside : true }; } 02530 }, 02531 _fn : { 02532 dnd_prepare : function () { 02533 if(!r || !r.length) { return; } 02534 this.data.dnd.off = r.offset(); 02535 if(this._get_settings().core.rtl) { 02536 this.data.dnd.off.right = this.data.dnd.off.left + r.width(); 02537 } 02538 if(this.data.dnd.foreign) { 02539 var a = this._get_settings().dnd.drag_check.call(this, { "o" : o, "r" : r }); 02540 this.data.dnd.after = a.after; 02541 this.data.dnd.before = a.before; 02542 this.data.dnd.inside = a.inside; 02543 this.data.dnd.prepared = true; 02544 return this.dnd_show(); 02545 } 02546 this.prepare_move(o, r, "before"); 02547 this.data.dnd.before = this.check_move(); 02548 this.prepare_move(o, r, "after"); 02549 this.data.dnd.after = this.check_move(); 02550 if(this._is_loaded(r)) { 02551 this.prepare_move(o, r, "inside"); 02552 this.data.dnd.inside = this.check_move(); 02553 } 02554 else { 02555 this.data.dnd.inside = false; 02556 } 02557 this.data.dnd.prepared = true; 02558 return this.dnd_show(); 02559 }, 02560 dnd_show : function () { 02561 if(!this.data.dnd.prepared) { return; } 02562 var o = ["before","inside","after"], 02563 r = false, 02564 rtl = this._get_settings().core.rtl, 02565 pos; 02566 if(this.data.dnd.w < this.data.core.li_height/3) { o = ["before","inside","after"]; } 02567 else if(this.data.dnd.w <= this.data.core.li_height*2/3) { 02568 o = this.data.dnd.w < this.data.core.li_height/2 ? ["inside","before","after"] : ["inside","after","before"]; 02569 } 02570 else { o = ["after","inside","before"]; } 02571 $.each(o, $.proxy(function (i, val) { 02572 if(this.data.dnd[val]) { 02573 $.vakata.dnd.helper.children("ins").attr("class","jstree-ok"); 02574 r = val; 02575 return false; 02576 } 02577 }, this)); 02578 if(r === false) { $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid"); } 02579 02580 pos = rtl ? (this.data.dnd.off.right - 18) : (this.data.dnd.off.left + 10); 02581 switch(r) { 02582 case "before": 02583 m.css({ "left" : pos + "px", "top" : (this.data.dnd.off.top - 6) + "px" }).show(); 02584 if(ml) { ml.css({ "left" : (pos + 8) + "px", "top" : (this.data.dnd.off.top - 1) + "px" }).show(); } 02585 break; 02586 case "after": 02587 m.css({ "left" : pos + "px", "top" : (this.data.dnd.off.top + this.data.core.li_height - 6) + "px" }).show(); 02588 if(ml) { ml.css({ "left" : (pos + 8) + "px", "top" : (this.data.dnd.off.top + this.data.core.li_height - 1) + "px" }).show(); } 02589 break; 02590 case "inside": 02591 m.css({ "left" : pos + ( rtl ? -4 : 4) + "px", "top" : (this.data.dnd.off.top + this.data.core.li_height/2 - 5) + "px" }).show(); 02592 if(ml) { ml.hide(); } 02593 break; 02594 default: 02595 m.hide(); 02596 if(ml) { ml.hide(); } 02597 break; 02598 } 02599 last_pos = r; 02600 return r; 02601 }, 02602 dnd_open : function () { 02603 this.data.dnd.to2 = false; 02604 this.open_node(r, $.proxy(this.dnd_prepare,this), true); 02605 }, 02606 dnd_finish : function (e) { 02607 if(this.data.dnd.foreign) { 02608 if(this.data.dnd.after || this.data.dnd.before || this.data.dnd.inside) { 02609 this._get_settings().dnd.drag_finish.call(this, { "o" : o, "r" : r, "p" : last_pos }); 02610 } 02611 } 02612 else { 02613 this.dnd_prepare(); 02614 this.move_node(o, r, last_pos, e[this._get_settings().dnd.copy_modifier + "Key"]); 02615 } 02616 o = false; 02617 r = false; 02618 m.hide(); 02619 if(ml) { ml.hide(); } 02620 }, 02621 dnd_enter : function (obj) { 02622 if(this.data.dnd.mto) { 02623 clearTimeout(this.data.dnd.mto); 02624 this.data.dnd.mto = false; 02625 } 02626 var s = this._get_settings().dnd; 02627 this.data.dnd.prepared = false; 02628 r = this._get_node(obj); 02629 if(s.check_timeout) { 02630 // do the calculations after a minimal timeout (users tend to drag quickly to the desired location) 02631 if(this.data.dnd.to1) { clearTimeout(this.data.dnd.to1); } 02632 this.data.dnd.to1 = setTimeout($.proxy(this.dnd_prepare, this), s.check_timeout); 02633 } 02634 else { 02635 this.dnd_prepare(); 02636 } 02637 if(s.open_timeout) { 02638 if(this.data.dnd.to2) { clearTimeout(this.data.dnd.to2); } 02639 if(r && r.length && r.hasClass("jstree-closed")) { 02640 // if the node is closed - open it, then recalculate 02641 this.data.dnd.to2 = setTimeout($.proxy(this.dnd_open, this), s.open_timeout); 02642 } 02643 } 02644 else { 02645 if(r && r.length && r.hasClass("jstree-closed")) { 02646 this.dnd_open(); 02647 } 02648 } 02649 }, 02650 dnd_leave : function (e) { 02651 this.data.dnd.after = false; 02652 this.data.dnd.before = false; 02653 this.data.dnd.inside = false; 02654 $.vakata.dnd.helper.children("ins").attr("class","jstree-invalid"); 02655 m.hide(); 02656 if(ml) { ml.hide(); } 02657 if(r && r[0] === e.target.parentNode) { 02658 if(this.data.dnd.to1) { 02659 clearTimeout(this.data.dnd.to1); 02660 this.data.dnd.to1 = false; 02661 } 02662 if(this.data.dnd.to2) { 02663 clearTimeout(this.data.dnd.to2); 02664 this.data.dnd.to2 = false; 02665 } 02666 } 02667 }, 02668 start_drag : function (obj, e) { 02669 o = this._get_node(obj); 02670 if(this.data.ui && this.is_selected(o)) { o = this._get_node(null, true); } 02671 var dt = o.length > 1 ? this._get_string("multiple_selection") : this.get_text(o), 02672 cnt = this.get_container(); 02673 if(!this._get_settings().core.html_titles) { dt = dt.replace(/</ig,"<").replace(/>/ig,">"); } 02674 $.vakata.dnd.drag_start(e, { jstree : true, obj : o }, "<ins class='jstree-icon'></ins>" + dt ); 02675 if(this.data.themes) { 02676 if(m) { m.attr("class", "jstree-" + this.data.themes.theme); } 02677 if(ml) { ml.attr("class", "jstree-" + this.data.themes.theme); } 02678 $.vakata.dnd.helper.attr("class", "jstree-dnd-helper jstree-" + this.data.themes.theme); 02679 } 02680 this.data.dnd.cof = cnt.offset(); 02681 this.data.dnd.cw = parseInt(cnt.width(),10); 02682 this.data.dnd.ch = parseInt(cnt.height(),10); 02683 this.data.dnd.active = true; 02684 } 02685 } 02686 }); 02687 $(function() { 02688 var css_string = '' + 02689 '#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; ' + 02690 ' -moz-border-radius:4px; border-radius:4px; -webkit-border-radius:4px; ' + 02691 '} ' + 02692 '#vakata-dragged .jstree-ok { background:green; } ' + 02693 '#vakata-dragged .jstree-invalid { background:red; } ' + 02694 '#jstree-marker { padding:0; margin:0; font-size:12px; overflow:hidden; height:12px; width:8px; position:absolute; top:-30px; z-index:10001; background-repeat:no-repeat; display:none; background-color:transparent; text-shadow:1px 1px 1px white; color:black; line-height:10px; } ' + 02695 '#jstree-marker-line { padding:0; margin:0; line-height:0%; font-size:1px; overflow:hidden; height:1px; width:100px; position:absolute; top:-30px; z-index:10000; background-repeat:no-repeat; display:none; background-color:#456c43; ' + 02696 ' cursor:pointer; border:1px solid #eeeeee; border-left:0; -moz-box-shadow: 0px 0px 2px #666; -webkit-box-shadow: 0px 0px 2px #666; box-shadow: 0px 0px 2px #666; ' + 02697 ' -moz-border-radius:1px; border-radius:1px; -webkit-border-radius:1px; ' + 02698 '}' + 02699 ''; 02700 $.vakata.css.add_sheet({ str : css_string, title : "jstree" }); 02701 m = $("<div />").attr({ id : "jstree-marker" }).hide().html("»") 02702 .bind("mouseleave mouseenter", function (e) { 02703 m.hide(); 02704 ml.hide(); 02705 e.preventDefault(); 02706 e.stopImmediatePropagation(); 02707 return false; 02708 }) 02709 .appendTo("body"); 02710 ml = $("<div />").attr({ id : "jstree-marker-line" }).hide() 02711 .bind("mouseup", function (e) { 02712 if(r && r.length) { 02713 r.children("a").trigger(e); 02714 e.preventDefault(); 02715 e.stopImmediatePropagation(); 02716 return false; 02717 } 02718 }) 02719 .bind("mouseleave", function (e) { 02720 var rt = $(e.relatedTarget); 02721 if(rt.is(".jstree") || rt.closest(".jstree").length === 0) { 02722 if(r && r.length) { 02723 r.children("a").trigger(e); 02724 m.hide(); 02725 ml.hide(); 02726 e.preventDefault(); 02727 e.stopImmediatePropagation(); 02728 return false; 02729 } 02730 } 02731 }) 02732 .appendTo("body"); 02733 $(document).bind("drag_start.vakata", function (e, data) { 02734 if(data.data.jstree) { m.show(); if(ml) { ml.show(); } } 02735 }); 02736 $(document).bind("drag_stop.vakata", function (e, data) { 02737 if(data.data.jstree) { m.hide(); if(ml) { ml.hide(); } } 02738 }); 02739 }); 02740 })(jQuery); 02741 //*/ 02742 02743 /* 02744 * jsTree checkbox plugin 02745 * Inserts checkboxes in front of every node 02746 * Depends on the ui plugin 02747 * DOES NOT WORK NICELY WITH MULTITREE DRAG'N'DROP 02748 */ 02749 (function ($) { 02750 $.jstree.plugin("checkbox", { 02751 __init : function () { 02752 this.data.checkbox.noui = this._get_settings().checkbox.override_ui; 02753 if(this.data.ui && this.data.checkbox.noui) { 02754 this.select_node = this.deselect_node = this.deselect_all = $.noop; 02755 this.get_selected = this.get_checked; 02756 } 02757 02758 this.get_container() 02759 .bind("open_node.jstree create_node.jstree clean_node.jstree refresh.jstree", $.proxy(function (e, data) { 02760 this._prepare_checkboxes(data.rslt.obj); 02761 }, this)) 02762 .bind("loaded.jstree", $.proxy(function (e) { 02763 this._prepare_checkboxes(); 02764 }, this)) 02765 .delegate( (this.data.ui && this.data.checkbox.noui ? "a" : "ins.jstree-checkbox") , "click.jstree", $.proxy(function (e) { 02766 e.preventDefault(); 02767 if(this._get_node(e.target).hasClass("jstree-checked")) { this.uncheck_node(e.target); } 02768 else { this.check_node(e.target); } 02769 if(this.data.ui && this.data.checkbox.noui) { 02770 this.save_selected(); 02771 if(this.data.cookies) { this.save_cookie("select_node"); } 02772 } 02773 else { 02774 e.stopImmediatePropagation(); 02775 return false; 02776 } 02777 }, this)); 02778 }, 02779 defaults : { 02780 override_ui : false, 02781 two_state : false, 02782 real_checkboxes : false, 02783 checked_parent_open : true, 02784 real_checkboxes_names : function (n) { return [ ("check_" + (n[0].id || Math.ceil(Math.random() * 10000))) , 1]; } 02785 }, 02786 __destroy : function () { 02787 this.get_container() 02788 .find("input.jstree-real-checkbox").removeClass("jstree-real-checkbox").end() 02789 .find("ins.jstree-checkbox").remove(); 02790 }, 02791 _fn : { 02792 _checkbox_notify : function (n, data) { 02793 if(data.checked) { 02794 this.check_node(n, false); 02795 } 02796 }, 02797 _prepare_checkboxes : function (obj) { 02798 obj = !obj || obj == -1 ? this.get_container().find("> ul > li") : this._get_node(obj); 02799 if(obj === false) { return; } // added for removing root nodes 02800 var c, _this = this, t, ts = this._get_settings().checkbox.two_state, rc = this._get_settings().checkbox.real_checkboxes, rcn = this._get_settings().checkbox.real_checkboxes_names; 02801 obj.each(function () { 02802 t = $(this); 02803 c = t.is("li") && (t.hasClass("jstree-checked") || (rc && t.children(":checked").length)) ? "jstree-checked" : "jstree-unchecked"; 02804 t.find("li").andSelf().each(function () { 02805 var $t = $(this), nm; 02806 $t.children("a" + (_this.data.languages ? "" : ":eq(0)") ).not(":has(.jstree-checkbox)").prepend("<ins class='jstree-checkbox'> </ins>").parent().not(".jstree-checked, .jstree-unchecked").addClass( ts ? "jstree-unchecked" : c ); 02807 if(rc) { 02808 if(!$t.children(":checkbox").length) { 02809 nm = rcn.call(_this, $t); 02810 $t.prepend("<input type='checkbox' class='jstree-real-checkbox' id='" + nm[0] + "' name='" + nm[0] + "' value='" + nm[1] + "' />"); 02811 } 02812 else { 02813 $t.children(":checkbox").addClass("jstree-real-checkbox"); 02814 } 02815 } 02816 if(!ts) { 02817 if(c === "jstree-checked" || $t.hasClass("jstree-checked") || $t.children(':checked').length) { 02818 $t.find("li").andSelf().addClass("jstree-checked").children(":checkbox").prop("checked", true); 02819 } 02820 } 02821 else { 02822 if($t.hasClass("jstree-checked") || $t.children(':checked').length) { 02823 $t.addClass("jstree-checked").children(":checkbox").prop("checked", true); 02824 } 02825 } 02826 }); 02827 }); 02828 if(!ts) { 02829 obj.find(".jstree-checked").parent().parent().each(function () { _this._repair_state(this); }); 02830 } 02831 }, 02832 change_state : function (obj, state) { 02833 obj = this._get_node(obj); 02834 var coll = false, rc = this._get_settings().checkbox.real_checkboxes; 02835 if(!obj || obj === -1) { return false; } 02836 state = (state === false || state === true) ? state : obj.hasClass("jstree-checked"); 02837 if(this._get_settings().checkbox.two_state) { 02838 if(state) { 02839 obj.removeClass("jstree-checked").addClass("jstree-unchecked"); 02840 if(rc) { obj.children(":checkbox").prop("checked", false); } 02841 } 02842 else { 02843 obj.removeClass("jstree-unchecked").addClass("jstree-checked"); 02844 if(rc) { obj.children(":checkbox").prop("checked", true); } 02845 } 02846 } 02847 else { 02848 if(state) { 02849 coll = obj.find("li").andSelf(); 02850 if(!coll.filter(".jstree-checked, .jstree-undetermined").length) { return false; } 02851 coll.removeClass("jstree-checked jstree-undetermined").addClass("jstree-unchecked"); 02852 if(rc) { coll.children(":checkbox").prop("checked", false); } 02853 } 02854 else { 02855 coll = obj.find("li").andSelf(); 02856 if(!coll.filter(".jstree-unchecked, .jstree-undetermined").length) { return false; } 02857 coll.removeClass("jstree-unchecked jstree-undetermined").addClass("jstree-checked"); 02858 if(rc) { coll.children(":checkbox").prop("checked", true); } 02859 if(this.data.ui) { this.data.ui.last_selected = obj; } 02860 this.data.checkbox.last_selected = obj; 02861 } 02862 obj.parentsUntil(".jstree", "li").each(function () { 02863 var $this = $(this); 02864 if(state) { 02865 if($this.children("ul").children("li.jstree-checked, li.jstree-undetermined").length) { 02866 $this.parentsUntil(".jstree", "li").andSelf().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined"); 02867 if(rc) { $this.parentsUntil(".jstree", "li").andSelf().children(":checkbox").prop("checked", false); } 02868 return false; 02869 } 02870 else { 02871 $this.removeClass("jstree-checked jstree-undetermined").addClass("jstree-unchecked"); 02872 if(rc) { $this.children(":checkbox").prop("checked", false); } 02873 } 02874 } 02875 else { 02876 if($this.children("ul").children("li.jstree-unchecked, li.jstree-undetermined").length) { 02877 $this.parentsUntil(".jstree", "li").andSelf().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined"); 02878 if(rc) { $this.parentsUntil(".jstree", "li").andSelf().children(":checkbox").prop("checked", false); } 02879 return false; 02880 } 02881 else { 02882 $this.removeClass("jstree-unchecked jstree-undetermined").addClass("jstree-checked"); 02883 if(rc) { $this.children(":checkbox").prop("checked", true); } 02884 } 02885 } 02886 }); 02887 } 02888 if(this.data.ui && this.data.checkbox.noui) { this.data.ui.selected = this.get_checked(); } 02889 this.__callback(obj); 02890 return true; 02891 }, 02892 check_node : function (obj) { 02893 if(this.change_state(obj, false)) { 02894 obj = this._get_node(obj); 02895 if(this._get_settings().checkbox.checked_parent_open) { 02896 var t = this; 02897 obj.parents(".jstree-closed").each(function () { t.open_node(this, false, true); }); 02898 } 02899 this.__callback({ "obj" : obj }); 02900 } 02901 }, 02902 uncheck_node : function (obj) { 02903 if(this.change_state(obj, true)) { this.__callback({ "obj" : this._get_node(obj) }); } 02904 }, 02905 check_all : function () { 02906 var _this = this, 02907 coll = this._get_settings().checkbox.two_state ? this.get_container_ul().find("li") : this.get_container_ul().children("li"); 02908 coll.each(function () { 02909 _this.change_state(this, false); 02910 }); 02911 this.__callback(); 02912 }, 02913 uncheck_all : function () { 02914 var _this = this, 02915 coll = this._get_settings().checkbox.two_state ? this.get_container_ul().find("li") : this.get_container_ul().children("li"); 02916 coll.each(function () { 02917 _this.change_state(this, true); 02918 }); 02919 this.__callback(); 02920 }, 02921 02922 is_checked : function(obj) { 02923 obj = this._get_node(obj); 02924 return obj.length ? obj.is(".jstree-checked") : false; 02925 }, 02926 get_checked : function (obj, get_all) { 02927 obj = !obj || obj === -1 ? this.get_container() : this._get_node(obj); 02928 return get_all || this._get_settings().checkbox.two_state ? obj.find(".jstree-checked") : obj.find("> ul > .jstree-checked, .jstree-undetermined > ul > .jstree-checked"); 02929 }, 02930 get_unchecked : function (obj, get_all) { 02931 obj = !obj || obj === -1 ? this.get_container() : this._get_node(obj); 02932 return get_all || this._get_settings().checkbox.two_state ? obj.find(".jstree-unchecked") : obj.find("> ul > .jstree-unchecked, .jstree-undetermined > ul > .jstree-unchecked"); 02933 }, 02934 02935 show_checkboxes : function () { this.get_container().children("ul").removeClass("jstree-no-checkboxes"); }, 02936 hide_checkboxes : function () { this.get_container().children("ul").addClass("jstree-no-checkboxes"); }, 02937 02938 _repair_state : function (obj) { 02939 obj = this._get_node(obj); 02940 if(!obj.length) { return; } 02941 if(this._get_settings().checkbox.two_state) { 02942 obj.find('li').andSelf().not('.jstree-checked').removeClass('jstree-undetermined').addClass('jstree-unchecked').children(':checkbox').prop('checked', true); 02943 return; 02944 } 02945 var rc = this._get_settings().checkbox.real_checkboxes, 02946 a = obj.find("> ul > .jstree-checked").length, 02947 b = obj.find("> ul > .jstree-undetermined").length, 02948 c = obj.find("> ul > li").length; 02949 if(c === 0) { if(obj.hasClass("jstree-undetermined")) { this.change_state(obj, false); } } 02950 else if(a === 0 && b === 0) { this.change_state(obj, true); } 02951 else if(a === c) { this.change_state(obj, false); } 02952 else { 02953 obj.parentsUntil(".jstree","li").andSelf().removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined"); 02954 if(rc) { obj.parentsUntil(".jstree", "li").andSelf().children(":checkbox").prop("checked", false); } 02955 } 02956 }, 02957 reselect : function () { 02958 if(this.data.ui && this.data.checkbox.noui) { 02959 var _this = this, 02960 s = this.data.ui.to_select; 02961 s = $.map($.makeArray(s), function (n) { return "#" + n.toString().replace(/^#/,"").replace(/\\\//g,"/").replace(/\//g,"\\\/").replace(/\\\./g,".").replace(/\./g,"\\.").replace(/\:/g,"\\:"); }); 02962 this.deselect_all(); 02963 $.each(s, function (i, val) { _this.check_node(val); }); 02964 this.__callback(); 02965 } 02966 else { 02967 this.__call_old(); 02968 } 02969 }, 02970 save_loaded : function () { 02971 var _this = this; 02972 this.data.core.to_load = []; 02973 this.get_container_ul().find("li.jstree-closed.jstree-undetermined").each(function () { 02974 if(this.id) { _this.data.core.to_load.push("#" + this.id); } 02975 }); 02976 } 02977 } 02978 }); 02979 $(function() { 02980 var css_string = '.jstree .jstree-real-checkbox { display:none; } '; 02981 $.vakata.css.add_sheet({ str : css_string, title : "jstree" }); 02982 }); 02983 })(jQuery); 02984 //*/ 02985 02986 /* 02987 * jsTree XML plugin 02988 * The XML data store. Datastores are build by overriding the `load_node` and `_is_loaded` functions. 02989 */ 02990 (function ($) { 02991 $.vakata.xslt = function (xml, xsl, callback) { 02992 var rs = "", xm, xs, processor, support; 02993 // TODO: IE9 no XSLTProcessor, no document.recalc 02994 if(document.recalc) { 02995 xm = document.createElement('xml'); 02996 xs = document.createElement('xml'); 02997 xm.innerHTML = xml; 02998 xs.innerHTML = xsl; 02999 $("body").append(xm).append(xs); 03000 setTimeout( (function (xm, xs, callback) { 03001 return function () { 03002 callback.call(null, xm.transformNode(xs.XMLDocument)); 03003 setTimeout( (function (xm, xs) { return function () { $(xm).remove(); $(xs).remove(); }; })(xm, xs), 200); 03004 }; 03005 })(xm, xs, callback), 100); 03006 return true; 03007 } 03008 if(typeof window.DOMParser !== "undefined" && typeof window.XMLHttpRequest !== "undefined" && typeof window.XSLTProcessor === "undefined") { 03009 xml = new DOMParser().parseFromString(xml, "text/xml"); 03010 xsl = new DOMParser().parseFromString(xsl, "text/xml"); 03011 // alert(xml.transformNode()); 03012 // callback.call(null, new XMLSerializer().serializeToString(rs)); 03013 03014 } 03015 if(typeof window.DOMParser !== "undefined" && typeof window.XMLHttpRequest !== "undefined" && typeof window.XSLTProcessor !== "undefined") { 03016 processor = new XSLTProcessor(); 03017 support = $.isFunction(processor.transformDocument) ? (typeof window.XMLSerializer !== "undefined") : true; 03018 if(!support) { return false; } 03019 xml = new DOMParser().parseFromString(xml, "text/xml"); 03020 xsl = new DOMParser().parseFromString(xsl, "text/xml"); 03021 if($.isFunction(processor.transformDocument)) { 03022 rs = document.implementation.createDocument("", "", null); 03023 processor.transformDocument(xml, xsl, rs, null); 03024 callback.call(null, new XMLSerializer().serializeToString(rs)); 03025 return true; 03026 } 03027 else { 03028 processor.importStylesheet(xsl); 03029 rs = processor.transformToFragment(xml, document); 03030 callback.call(null, $("<div />").append(rs).html()); 03031 return true; 03032 } 03033 } 03034 return false; 03035 }; 03036 var xsl = { 03037 'nest' : '<' + '?xml version="1.0" encoding="utf-8" ?>' + 03038 '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >' + 03039 '<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/html" />' + 03040 '<xsl:template match="/">' + 03041 ' <xsl:call-template name="nodes">' + 03042 ' <xsl:with-param name="node" select="/root" />' + 03043 ' </xsl:call-template>' + 03044 '</xsl:template>' + 03045 '<xsl:template name="nodes">' + 03046 ' <xsl:param name="node" />' + 03047 ' <ul>' + 03048 ' <xsl:for-each select="$node/item">' + 03049 ' <xsl:variable name="children" select="count(./item) > 0" />' + 03050 ' <li>' + 03051 ' <xsl:attribute name="class">' + 03052 ' <xsl:if test="position() = last()">jstree-last </xsl:if>' + 03053 ' <xsl:choose>' + 03054 ' <xsl:when test="@state = \'open\'">jstree-open </xsl:when>' + 03055 ' <xsl:when test="$children or @hasChildren or @state = \'closed\'">jstree-closed </xsl:when>' + 03056 ' <xsl:otherwise>jstree-leaf </xsl:otherwise>' + 03057 ' </xsl:choose>' + 03058 ' <xsl:value-of select="@class" />' + 03059 ' </xsl:attribute>' + 03060 ' <xsl:for-each select="@*">' + 03061 ' <xsl:if test="name() != \'class\' and name() != \'state\' and name() != \'hasChildren\'">' + 03062 ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' + 03063 ' </xsl:if>' + 03064 ' </xsl:for-each>' + 03065 ' <ins class="jstree-icon"><xsl:text> </xsl:text></ins>' + 03066 ' <xsl:for-each select="content/name">' + 03067 ' <a>' + 03068 ' <xsl:attribute name="href">' + 03069 ' <xsl:choose>' + 03070 ' <xsl:when test="@href"><xsl:value-of select="@href" /></xsl:when>' + 03071 ' <xsl:otherwise>#</xsl:otherwise>' + 03072 ' </xsl:choose>' + 03073 ' </xsl:attribute>' + 03074 ' <xsl:attribute name="class"><xsl:value-of select="@lang" /> <xsl:value-of select="@class" /></xsl:attribute>' + 03075 ' <xsl:attribute name="style"><xsl:value-of select="@style" /></xsl:attribute>' + 03076 ' <xsl:for-each select="@*">' + 03077 ' <xsl:if test="name() != \'style\' and name() != \'class\' and name() != \'href\'">' + 03078 ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' + 03079 ' </xsl:if>' + 03080 ' </xsl:for-each>' + 03081 ' <ins>' + 03082 ' <xsl:attribute name="class">jstree-icon ' + 03083 ' <xsl:if test="string-length(attribute::icon) > 0 and not(contains(@icon,\'/\'))"><xsl:value-of select="@icon" /></xsl:if>' + 03084 ' </xsl:attribute>' + 03085 ' <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>' + 03086 ' <xsl:text> </xsl:text>' + 03087 ' </ins>' + 03088 ' <xsl:copy-of select="./child::node()" />' + 03089 ' </a>' + 03090 ' </xsl:for-each>' + 03091 ' <xsl:if test="$children or @hasChildren"><xsl:call-template name="nodes"><xsl:with-param name="node" select="current()" /></xsl:call-template></xsl:if>' + 03092 ' </li>' + 03093 ' </xsl:for-each>' + 03094 ' </ul>' + 03095 '</xsl:template>' + 03096 '</xsl:stylesheet>', 03097 03098 'flat' : '<' + '?xml version="1.0" encoding="utf-8" ?>' + 03099 '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >' + 03100 '<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/xml" />' + 03101 '<xsl:template match="/">' + 03102 ' <ul>' + 03103 ' <xsl:for-each select="//item[not(@parent_id) or @parent_id=0 or not(@parent_id = //item/@id)]">' + /* the last `or` may be removed */ 03104 ' <xsl:call-template name="nodes">' + 03105 ' <xsl:with-param name="node" select="." />' + 03106 ' <xsl:with-param name="is_last" select="number(position() = last())" />' + 03107 ' </xsl:call-template>' + 03108 ' </xsl:for-each>' + 03109 ' </ul>' + 03110 '</xsl:template>' + 03111 '<xsl:template name="nodes">' + 03112 ' <xsl:param name="node" />' + 03113 ' <xsl:param name="is_last" />' + 03114 ' <xsl:variable name="children" select="count(//item[@parent_id=$node/attribute::id]) > 0" />' + 03115 ' <li>' + 03116 ' <xsl:attribute name="class">' + 03117 ' <xsl:if test="$is_last = true()">jstree-last </xsl:if>' + 03118 ' <xsl:choose>' + 03119 ' <xsl:when test="@state = \'open\'">jstree-open </xsl:when>' + 03120 ' <xsl:when test="$children or @hasChildren or @state = \'closed\'">jstree-closed </xsl:when>' + 03121 ' <xsl:otherwise>jstree-leaf </xsl:otherwise>' + 03122 ' </xsl:choose>' + 03123 ' <xsl:value-of select="@class" />' + 03124 ' </xsl:attribute>' + 03125 ' <xsl:for-each select="@*">' + 03126 ' <xsl:if test="name() != \'parent_id\' and name() != \'hasChildren\' and name() != \'class\' and name() != \'state\'">' + 03127 ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' + 03128 ' </xsl:if>' + 03129 ' </xsl:for-each>' + 03130 ' <ins class="jstree-icon"><xsl:text> </xsl:text></ins>' + 03131 ' <xsl:for-each select="content/name">' + 03132 ' <a>' + 03133 ' <xsl:attribute name="href">' + 03134 ' <xsl:choose>' + 03135 ' <xsl:when test="@href"><xsl:value-of select="@href" /></xsl:when>' + 03136 ' <xsl:otherwise>#</xsl:otherwise>' + 03137 ' </xsl:choose>' + 03138 ' </xsl:attribute>' + 03139 ' <xsl:attribute name="class"><xsl:value-of select="@lang" /> <xsl:value-of select="@class" /></xsl:attribute>' + 03140 ' <xsl:attribute name="style"><xsl:value-of select="@style" /></xsl:attribute>' + 03141 ' <xsl:for-each select="@*">' + 03142 ' <xsl:if test="name() != \'style\' and name() != \'class\' and name() != \'href\'">' + 03143 ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' + 03144 ' </xsl:if>' + 03145 ' </xsl:for-each>' + 03146 ' <ins>' + 03147 ' <xsl:attribute name="class">jstree-icon ' + 03148 ' <xsl:if test="string-length(attribute::icon) > 0 and not(contains(@icon,\'/\'))"><xsl:value-of select="@icon" /></xsl:if>' + 03149 ' </xsl:attribute>' + 03150 ' <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>' + 03151 ' <xsl:text> </xsl:text>' + 03152 ' </ins>' + 03153 ' <xsl:copy-of select="./child::node()" />' + 03154 ' </a>' + 03155 ' </xsl:for-each>' + 03156 ' <xsl:if test="$children">' + 03157 ' <ul>' + 03158 ' <xsl:for-each select="//item[@parent_id=$node/attribute::id]">' + 03159 ' <xsl:call-template name="nodes">' + 03160 ' <xsl:with-param name="node" select="." />' + 03161 ' <xsl:with-param name="is_last" select="number(position() = last())" />' + 03162 ' </xsl:call-template>' + 03163 ' </xsl:for-each>' + 03164 ' </ul>' + 03165 ' </xsl:if>' + 03166 ' </li>' + 03167 '</xsl:template>' + 03168 '</xsl:stylesheet>' 03169 }, 03170 escape_xml = function(string) { 03171 return string 03172 .toString() 03173 .replace(/&/g, '&') 03174 .replace(/</g, '<') 03175 .replace(/>/g, '>') 03176 .replace(/"/g, '"') 03177 .replace(/'/g, '''); 03178 }; 03179 $.jstree.plugin("xml_data", { 03180 defaults : { 03181 data : false, 03182 ajax : false, 03183 xsl : "flat", 03184 clean_node : false, 03185 correct_state : true, 03186 get_skip_empty : false, 03187 get_include_preamble : true 03188 }, 03189 _fn : { 03190 load_node : function (obj, s_call, e_call) { var _this = this; this.load_node_xml(obj, function () { _this.__callback({ "obj" : _this._get_node(obj) }); s_call.call(this); }, e_call); }, 03191 _is_loaded : function (obj) { 03192 var s = this._get_settings().xml_data; 03193 obj = this._get_node(obj); 03194 return obj == -1 || !obj || (!s.ajax && !$.isFunction(s.data)) || obj.is(".jstree-open, .jstree-leaf") || obj.children("ul").children("li").size() > 0; 03195 }, 03196 load_node_xml : function (obj, s_call, e_call) { 03197 var s = this.get_settings().xml_data, 03198 error_func = function () {}, 03199 success_func = function () {}; 03200 03201 obj = this._get_node(obj); 03202 if(obj && obj !== -1) { 03203 if(obj.data("jstree_is_loading")) { return; } 03204 else { obj.data("jstree_is_loading",true); } 03205 } 03206 switch(!0) { 03207 case (!s.data && !s.ajax): throw "Neither data nor ajax settings supplied."; 03208 case ($.isFunction(s.data)): 03209 s.data.call(this, obj, $.proxy(function (d) { 03210 this.parse_xml(d, $.proxy(function (d) { 03211 if(d) { 03212 d = d.replace(/ ?xmlns="[^"]*"/ig, ""); 03213 if(d.length > 10) { 03214 d = $(d); 03215 if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); } 03216 else { obj.children("a.jstree-loading").removeClass("jstree-loading"); obj.append(d); obj.removeData("jstree_is_loading"); } 03217 if(s.clean_node) { this.clean_node(obj); } 03218 if(s_call) { s_call.call(this); } 03219 } 03220 else { 03221 if(obj && obj !== -1) { 03222 obj.children("a.jstree-loading").removeClass("jstree-loading"); 03223 obj.removeData("jstree_is_loading"); 03224 if(s.correct_state) { 03225 this.correct_state(obj); 03226 if(s_call) { s_call.call(this); } 03227 } 03228 } 03229 else { 03230 if(s.correct_state) { 03231 this.get_container().children("ul").empty(); 03232 if(s_call) { s_call.call(this); } 03233 } 03234 } 03235 } 03236 } 03237 }, this)); 03238 }, this)); 03239 break; 03240 case (!!s.data && !s.ajax) || (!!s.data && !!s.ajax && (!obj || obj === -1)): 03241 if(!obj || obj == -1) { 03242 this.parse_xml(s.data, $.proxy(function (d) { 03243 if(d) { 03244 d = d.replace(/ ?xmlns="[^"]*"/ig, ""); 03245 if(d.length > 10) { 03246 d = $(d); 03247 this.get_container().children("ul").empty().append(d.children()); 03248 if(s.clean_node) { this.clean_node(obj); } 03249 if(s_call) { s_call.call(this); } 03250 } 03251 } 03252 else { 03253 if(s.correct_state) { 03254 this.get_container().children("ul").empty(); 03255 if(s_call) { s_call.call(this); } 03256 } 03257 } 03258 }, this)); 03259 } 03260 break; 03261 case (!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj && obj !== -1): 03262 error_func = function (x, t, e) { 03263 var ef = this.get_settings().xml_data.ajax.error; 03264 if(ef) { ef.call(this, x, t, e); } 03265 if(obj !== -1 && obj.length) { 03266 obj.children("a.jstree-loading").removeClass("jstree-loading"); 03267 obj.removeData("jstree_is_loading"); 03268 if(t === "success" && s.correct_state) { this.correct_state(obj); } 03269 } 03270 else { 03271 if(t === "success" && s.correct_state) { this.get_container().children("ul").empty(); } 03272 } 03273 if(e_call) { e_call.call(this); } 03274 }; 03275 success_func = function (d, t, x) { 03276 d = x.responseText; 03277 var sf = this.get_settings().xml_data.ajax.success; 03278 if(sf) { d = sf.call(this,d,t,x) || d; } 03279 if(d === "" || (d && d.toString && d.toString().replace(/^[\s\n]+$/,"") === "")) { 03280 return error_func.call(this, x, t, ""); 03281 } 03282 this.parse_xml(d, $.proxy(function (d) { 03283 if(d) { 03284 d = d.replace(/ ?xmlns="[^"]*"/ig, ""); 03285 if(d.length > 10) { 03286 d = $(d); 03287 if(obj === -1 || !obj) { this.get_container().children("ul").empty().append(d.children()); } 03288 else { obj.children("a.jstree-loading").removeClass("jstree-loading"); obj.append(d); obj.removeData("jstree_is_loading"); } 03289 if(s.clean_node) { this.clean_node(obj); } 03290 if(s_call) { s_call.call(this); } 03291 } 03292 else { 03293 if(obj && obj !== -1) { 03294 obj.children("a.jstree-loading").removeClass("jstree-loading"); 03295 obj.removeData("jstree_is_loading"); 03296 if(s.correct_state) { 03297 this.correct_state(obj); 03298 if(s_call) { s_call.call(this); } 03299 } 03300 } 03301 else { 03302 if(s.correct_state) { 03303 this.get_container().children("ul").empty(); 03304 if(s_call) { s_call.call(this); } 03305 } 03306 } 03307 } 03308 } 03309 }, this)); 03310 }; 03311 s.ajax.context = this; 03312 s.ajax.error = error_func; 03313 s.ajax.success = success_func; 03314 if(!s.ajax.dataType) { s.ajax.dataType = "xml"; } 03315 if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); } 03316 if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); } 03317 $.ajax(s.ajax); 03318 break; 03319 } 03320 }, 03321 parse_xml : function (xml, callback) { 03322 var s = this._get_settings().xml_data; 03323 $.vakata.xslt(xml, xsl[s.xsl], callback); 03324 }, 03325 get_xml : function (tp, obj, li_attr, a_attr, is_callback) { 03326 var result = "", 03327 s = this._get_settings(), 03328 _this = this, 03329 tmp1, tmp2, li, a, lang; 03330 if(!tp) { tp = "flat"; } 03331 if(!is_callback) { is_callback = 0; } 03332 obj = this._get_node(obj); 03333 if(!obj || obj === -1) { obj = this.get_container().find("> ul > li"); } 03334 li_attr = $.isArray(li_attr) ? li_attr : [ "id", "class" ]; 03335 if(!is_callback && this.data.types && $.inArray(s.types.type_attr, li_attr) === -1) { li_attr.push(s.types.type_attr); } 03336 03337 a_attr = $.isArray(a_attr) ? a_attr : [ ]; 03338 03339 if(!is_callback) { 03340 if(s.xml_data.get_include_preamble) { 03341 result += '<' + '?xml version="1.0" encoding="UTF-8"?' + '>'; 03342 } 03343 result += "<root>"; 03344 } 03345 obj.each(function () { 03346 result += "<item"; 03347 li = $(this); 03348 $.each(li_attr, function (i, v) { 03349 var t = li.attr(v); 03350 if(!s.xml_data.get_skip_empty || typeof t !== "undefined") { 03351 result += " " + v + "=\"" + escape_xml((" " + (t || "")).replace(/ jstree[^ ]*/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,"")) + "\""; 03352 } 03353 }); 03354 if(li.hasClass("jstree-open")) { result += " state=\"open\""; } 03355 if(li.hasClass("jstree-closed")) { result += " state=\"closed\""; } 03356 if(tp === "flat") { result += " parent_id=\"" + escape_xml(is_callback) + "\""; } 03357 result += ">"; 03358 result += "<content>"; 03359 a = li.children("a"); 03360 a.each(function () { 03361 tmp1 = $(this); 03362 lang = false; 03363 result += "<name"; 03364 if($.inArray("languages", s.plugins) !== -1) { 03365 $.each(s.languages, function (k, z) { 03366 if(tmp1.hasClass(z)) { result += " lang=\"" + escape_xml(z) + "\""; lang = z; return false; } 03367 }); 03368 } 03369 if(a_attr.length) { 03370 $.each(a_attr, function (k, z) { 03371 var t = tmp1.attr(z); 03372 if(!s.xml_data.get_skip_empty || typeof t !== "undefined") { 03373 result += " " + z + "=\"" + escape_xml((" " + t || "").replace(/ jstree[^ ]*/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,"")) + "\""; 03374 } 03375 }); 03376 } 03377 if(tmp1.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/^\s+$/ig,"").length) { 03378 result += ' icon="' + escape_xml(tmp1.children("ins").get(0).className.replace(/jstree[^ ]*|$/ig,'').replace(/\s+$/ig," ").replace(/^ /,"").replace(/ $/,"")) + '"'; 03379 } 03380 if(tmp1.children("ins").get(0).style.backgroundImage.length) { 03381 result += ' icon="' + escape_xml(tmp1.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")","").replace(/'/ig,"").replace(/"/ig,"")) + '"'; 03382 } 03383 result += ">"; 03384 result += "<![CDATA[" + _this.get_text(tmp1, lang) + "]]>"; 03385 result += "</name>"; 03386 }); 03387 result += "</content>"; 03388 tmp2 = li[0].id || true; 03389 li = li.find("> ul > li"); 03390 if(li.length) { tmp2 = _this.get_xml(tp, li, li_attr, a_attr, tmp2); } 03391 else { tmp2 = ""; } 03392 if(tp == "nest") { result += tmp2; } 03393 result += "</item>"; 03394 if(tp == "flat") { result += tmp2; } 03395 }); 03396 if(!is_callback) { result += "</root>"; } 03397 return result; 03398 } 03399 } 03400 }); 03401 })(jQuery); 03402 //*/ 03403 03404 /* 03405 * jsTree search plugin 03406 * Enables both sync and async search on the tree 03407 * DOES NOT WORK WITH JSON PROGRESSIVE RENDER 03408 */ 03409 (function ($) { 03410 $.expr[':'].jstree_contains = function(a,i,m){ 03411 return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase())>=0; 03412 }; 03413 $.expr[':'].jstree_title_contains = function(a,i,m) { 03414 return (a.getAttribute("title") || "").toLowerCase().indexOf(m[3].toLowerCase())>=0; 03415 }; 03416 $.jstree.plugin("search", { 03417 __init : function () { 03418 this.data.search.str = ""; 03419 this.data.search.result = $(); 03420 if(this._get_settings().search.show_only_matches) { 03421 this.get_container() 03422 .bind("search.jstree", function (e, data) { 03423 $(this).children("ul").find("li").hide().removeClass("jstree-last"); 03424 data.rslt.nodes.parentsUntil(".jstree").andSelf().show() 03425 .filter("ul").each(function () { $(this).children("li:visible").eq(-1).addClass("jstree-last"); }); 03426 }) 03427 .bind("clear_search.jstree", function () { 03428 $(this).children("ul").find("li").css("display","").end().end().jstree("clean_node", -1); 03429 }); 03430 } 03431 }, 03432 defaults : { 03433 ajax : false, 03434 search_method : "jstree_contains", // for case insensitive - jstree_contains 03435 show_only_matches : false 03436 }, 03437 _fn : { 03438 search : function (str, skip_async) { 03439 if($.trim(str) === "") { this.clear_search(); return; } 03440 var s = this.get_settings().search, 03441 t = this, 03442 error_func = function () { }, 03443 success_func = function () { }; 03444 this.data.search.str = str; 03445 03446 if(!skip_async && s.ajax !== false && this.get_container_ul().find("li.jstree-closed:not(:has(ul)):eq(0)").length > 0) { 03447 this.search.supress_callback = true; 03448 error_func = function () { }; 03449 success_func = function (d, t, x) { 03450 var sf = this.get_settings().search.ajax.success; 03451 if(sf) { d = sf.call(this,d,t,x) || d; } 03452 this.data.search.to_open = d; 03453 this._search_open(); 03454 }; 03455 s.ajax.context = this; 03456 s.ajax.error = error_func; 03457 s.ajax.success = success_func; 03458 if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, str); } 03459 if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, str); } 03460 if(!s.ajax.data) { s.ajax.data = { "search_string" : str }; } 03461 if(!s.ajax.dataType || /^json/.exec(s.ajax.dataType)) { s.ajax.dataType = "json"; } 03462 $.ajax(s.ajax); 03463 return; 03464 } 03465 if(this.data.search.result.length) { this.clear_search(); } 03466 this.data.search.result = this.get_container().find("a" + (this.data.languages ? "." + this.get_lang() : "" ) + ":" + (s.search_method) + "(" + this.data.search.str + ")"); 03467 this.data.search.result.addClass("jstree-search").parent().parents(".jstree-closed").each(function () { 03468 t.open_node(this, false, true); 03469 }); 03470 this.__callback({ nodes : this.data.search.result, str : str }); 03471 }, 03472 clear_search : function (str) { 03473 this.data.search.result.removeClass("jstree-search"); 03474 this.__callback(this.data.search.result); 03475 this.data.search.result = $(); 03476 }, 03477 _search_open : function (is_callback) { 03478 var _this = this, 03479 done = true, 03480 current = [], 03481 remaining = []; 03482 if(this.data.search.to_open.length) { 03483 $.each(this.data.search.to_open, function (i, val) { 03484 if(val == "#") { return true; } 03485 if($(val).length && $(val).is(".jstree-closed")) { current.push(val); } 03486 else { remaining.push(val); } 03487 }); 03488 if(current.length) { 03489 this.data.search.to_open = remaining; 03490 $.each(current, function (i, val) { 03491 _this.open_node(val, function () { _this._search_open(true); }); 03492 }); 03493 done = false; 03494 } 03495 } 03496 if(done) { this.search(this.data.search.str, true); } 03497 } 03498 } 03499 }); 03500 })(jQuery); 03501 //*/ 03502 03503 /* 03504 * jsTree contextmenu plugin 03505 */ 03506 (function ($) { 03507 $.vakata.context = { 03508 hide_on_mouseleave : false, 03509 03510 cnt : $("<div id='vakata-contextmenu' />"), 03511 vis : false, 03512 tgt : false, 03513 par : false, 03514 func : false, 03515 data : false, 03516 rtl : false, 03517 show : function (s, t, x, y, d, p, rtl) { 03518 $.vakata.context.rtl = !!rtl; 03519 var html = $.vakata.context.parse(s), h, w; 03520 if(!html) { return; } 03521 $.vakata.context.vis = true; 03522 $.vakata.context.tgt = t; 03523 $.vakata.context.par = p || t || null; 03524 $.vakata.context.data = d || null; 03525 $.vakata.context.cnt 03526 .html(html) 03527 .css({ "visibility" : "hidden", "display" : "block", "left" : 0, "top" : 0 }); 03528 03529 if($.vakata.context.hide_on_mouseleave) { 03530 $.vakata.context.cnt 03531 .one("mouseleave", function(e) { $.vakata.context.hide(); }); 03532 } 03533 03534 h = $.vakata.context.cnt.height(); 03535 w = $.vakata.context.cnt.width(); 03536 if(x + w > $(document).width()) { 03537 x = $(document).width() - (w + 5); 03538 $.vakata.context.cnt.find("li > ul").addClass("right"); 03539 } 03540 if(y + h > $(document).height()) { 03541 y = y - (h + t[0].offsetHeight); 03542 $.vakata.context.cnt.find("li > ul").addClass("bottom"); 03543 } 03544 03545 $.vakata.context.cnt 03546 .css({ "left" : x, "top" : y }) 03547 .find("li:has(ul)") 03548 .bind("mouseenter", function (e) { 03549 var w = $(document).width(), 03550 h = $(document).height(), 03551 ul = $(this).children("ul").show(); 03552 if(w !== $(document).width()) { ul.toggleClass("right"); } 03553 if(h !== $(document).height()) { ul.toggleClass("bottom"); } 03554 }) 03555 .bind("mouseleave", function (e) { 03556 $(this).children("ul").hide(); 03557 }) 03558 .end() 03559 .css({ "visibility" : "visible" }) 03560 .show(); 03561 $(document).triggerHandler("context_show.vakata"); 03562 }, 03563 hide : function () { 03564 $.vakata.context.vis = false; 03565 $.vakata.context.cnt.attr("class","").css({ "visibility" : "hidden" }); 03566 $(document).triggerHandler("context_hide.vakata"); 03567 }, 03568 parse : function (s, is_callback) { 03569 if(!s) { return false; } 03570 var str = "", 03571 tmp = false, 03572 was_sep = true; 03573 if(!is_callback) { $.vakata.context.func = {}; } 03574 str += "<ul>"; 03575 $.each(s, function (i, val) { 03576 if(!val) { return true; } 03577 $.vakata.context.func[i] = val.action; 03578 if(!was_sep && val.separator_before) { 03579 str += "<li class='vakata-separator vakata-separator-before'></li>"; 03580 } 03581 was_sep = false; 03582 str += "<li class='" + (val._class || "") + (val._disabled ? " jstree-contextmenu-disabled " : "") + "'><ins "; 03583 if(val.icon && val.icon.indexOf("/") === -1) { str += " class='" + val.icon + "' "; } 03584 if(val.icon && val.icon.indexOf("/") !== -1) { str += " style='background:url(" + val.icon + ") center center no-repeat;' "; } 03585 str += "> </ins><a href='#' rel='" + i + "'>"; 03586 if(val.submenu) { 03587 str += "<span style='float:" + ($.vakata.context.rtl ? "left" : "right") + ";'>»</span>"; 03588 } 03589 str += val.label + "</a>"; 03590 if(val.submenu) { 03591 tmp = $.vakata.context.parse(val.submenu, true); 03592 if(tmp) { str += tmp; } 03593 } 03594 str += "</li>"; 03595 if(val.separator_after) { 03596 str += "<li class='vakata-separator vakata-separator-after'></li>"; 03597 was_sep = true; 03598 } 03599 }); 03600 str = str.replace(/<li class\='vakata-separator vakata-separator-after'><\/li>$/,""); 03601 str += "</ul>"; 03602 $(document).triggerHandler("context_parse.vakata"); 03603 return str.length > 10 ? str : false; 03604 }, 03605 exec : function (i) { 03606 if($.isFunction($.vakata.context.func[i])) { 03607 // if is string - eval and call it! 03608 $.vakata.context.func[i].call($.vakata.context.data, $.vakata.context.par); 03609 return true; 03610 } 03611 else { return false; } 03612 } 03613 }; 03614 $(function () { 03615 var css_string = '' + 03616 '#vakata-contextmenu { display:block; visibility:hidden; left:0; top:-200px; position:absolute; margin:0; padding:0; min-width:180px; background:#ebebeb; border:1px solid silver; z-index:10000; *width:180px; } ' + 03617 '#vakata-contextmenu ul { min-width:180px; *width:180px; } ' + 03618 '#vakata-contextmenu ul, #vakata-contextmenu li { margin:0; padding:0; list-style-type:none; display:block; } ' + 03619 '#vakata-contextmenu li { line-height:20px; min-height:20px; position:relative; padding:0px; } ' + 03620 '#vakata-contextmenu li a { padding:1px 6px; line-height:17px; display:block; text-decoration:none; margin:1px 1px 0 1px; } ' + 03621 '#vakata-contextmenu li ins { float:left; width:16px; height:16px; text-decoration:none; margin-right:2px; } ' + 03622 '#vakata-contextmenu li a:hover, #vakata-contextmenu li.vakata-hover > a { background:gray; color:white; } ' + 03623 '#vakata-contextmenu li ul { display:none; position:absolute; top:-2px; left:100%; background:#ebebeb; border:1px solid gray; } ' + 03624 '#vakata-contextmenu .right { right:100%; left:auto; } ' + 03625 '#vakata-contextmenu .bottom { bottom:-1px; top:auto; } ' + 03626 '#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; } '; 03627 $.vakata.css.add_sheet({ str : css_string, title : "vakata" }); 03628 $.vakata.context.cnt 03629 .delegate("a","click", function (e) { e.preventDefault(); }) 03630 .delegate("a","mouseup", function (e) { 03631 if(!$(this).parent().hasClass("jstree-contextmenu-disabled") && $.vakata.context.exec($(this).attr("rel"))) { 03632 $.vakata.context.hide(); 03633 } 03634 else { $(this).blur(); } 03635 }) 03636 .delegate("a","mouseover", function () { 03637 $.vakata.context.cnt.find(".vakata-hover").removeClass("vakata-hover"); 03638 }) 03639 .appendTo("body"); 03640 $(document).bind("mousedown", function (e) { if($.vakata.context.vis && !$.contains($.vakata.context.cnt[0], e.target)) { $.vakata.context.hide(); } }); 03641 if(typeof $.hotkeys !== "undefined") { 03642 $(document) 03643 .bind("keydown", "up", function (e) { 03644 if($.vakata.context.vis) { 03645 var o = $.vakata.context.cnt.find("ul:visible").last().children(".vakata-hover").removeClass("vakata-hover").prevAll("li:not(.vakata-separator)").first(); 03646 if(!o.length) { o = $.vakata.context.cnt.find("ul:visible").last().children("li:not(.vakata-separator)").last(); } 03647 o.addClass("vakata-hover"); 03648 e.stopImmediatePropagation(); 03649 e.preventDefault(); 03650 } 03651 }) 03652 .bind("keydown", "down", function (e) { 03653 if($.vakata.context.vis) { 03654 var o = $.vakata.context.cnt.find("ul:visible").last().children(".vakata-hover").removeClass("vakata-hover").nextAll("li:not(.vakata-separator)").first(); 03655 if(!o.length) { o = $.vakata.context.cnt.find("ul:visible").last().children("li:not(.vakata-separator)").first(); } 03656 o.addClass("vakata-hover"); 03657 e.stopImmediatePropagation(); 03658 e.preventDefault(); 03659 } 03660 }) 03661 .bind("keydown", "right", function (e) { 03662 if($.vakata.context.vis) { 03663 $.vakata.context.cnt.find(".vakata-hover").children("ul").show().children("li:not(.vakata-separator)").removeClass("vakata-hover").first().addClass("vakata-hover"); 03664 e.stopImmediatePropagation(); 03665 e.preventDefault(); 03666 } 03667 }) 03668 .bind("keydown", "left", function (e) { 03669 if($.vakata.context.vis) { 03670 $.vakata.context.cnt.find(".vakata-hover").children("ul").hide().children(".vakata-separator").removeClass("vakata-hover"); 03671 e.stopImmediatePropagation(); 03672 e.preventDefault(); 03673 } 03674 }) 03675 .bind("keydown", "esc", function (e) { 03676 $.vakata.context.hide(); 03677 e.preventDefault(); 03678 }) 03679 .bind("keydown", "space", function (e) { 03680 $.vakata.context.cnt.find(".vakata-hover").last().children("a").click(); 03681 e.preventDefault(); 03682 }); 03683 } 03684 }); 03685 03686 $.jstree.plugin("contextmenu", { 03687 __init : function () { 03688 this.get_container() 03689 .delegate("a", "contextmenu.jstree", $.proxy(function (e) { 03690 e.preventDefault(); 03691 if(!$(e.currentTarget).hasClass("jstree-loading")) { 03692 this.show_contextmenu(e.currentTarget, e.pageX, e.pageY); 03693 } 03694 }, this)) 03695 .delegate("a", "click.jstree", $.proxy(function (e) { 03696 if(this.data.contextmenu) { 03697 $.vakata.context.hide(); 03698 } 03699 }, this)) 03700 .bind("destroy.jstree", $.proxy(function () { 03701 // TODO: move this to descruct method 03702 if(this.data.contextmenu) { 03703 $.vakata.context.hide(); 03704 } 03705 }, this)); 03706 $(document).bind("context_hide.vakata", $.proxy(function () { this.data.contextmenu = false; }, this)); 03707 }, 03708 defaults : { 03709 select_node : false, // requires UI plugin 03710 show_at_node : true, 03711 items : { // Could be a function that should return an object like this one 03712 "create" : { 03713 "separator_before" : false, 03714 "separator_after" : true, 03715 "label" : "Create", 03716 "action" : function (obj) { this.create(obj); } 03717 }, 03718 "rename" : { 03719 "separator_before" : false, 03720 "separator_after" : false, 03721 "label" : "Rename", 03722 "action" : function (obj) { this.rename(obj); } 03723 }, 03724 "remove" : { 03725 "separator_before" : false, 03726 "icon" : false, 03727 "separator_after" : false, 03728 "label" : "Delete", 03729 "action" : function (obj) { if(this.is_selected(obj)) { this.remove(); } else { this.remove(obj); } } 03730 }, 03731 "ccp" : { 03732 "separator_before" : true, 03733 "icon" : false, 03734 "separator_after" : false, 03735 "label" : "Edit", 03736 "action" : false, 03737 "submenu" : { 03738 "cut" : { 03739 "separator_before" : false, 03740 "separator_after" : false, 03741 "label" : "Cut", 03742 "action" : function (obj) { this.cut(obj); } 03743 }, 03744 "copy" : { 03745 "separator_before" : false, 03746 "icon" : false, 03747 "separator_after" : false, 03748 "label" : "Copy", 03749 "action" : function (obj) { this.copy(obj); } 03750 }, 03751 "paste" : { 03752 "separator_before" : false, 03753 "icon" : false, 03754 "separator_after" : false, 03755 "label" : "Paste", 03756 "action" : function (obj) { this.paste(obj); } 03757 } 03758 } 03759 } 03760 } 03761 }, 03762 _fn : { 03763 show_contextmenu : function (obj, x, y) { 03764 obj = this._get_node(obj); 03765 var s = this.get_settings().contextmenu, 03766 a = obj.children("a:visible:eq(0)"), 03767 o = false, 03768 i = false; 03769 if(s.select_node && this.data.ui && !this.is_selected(obj)) { 03770 this.deselect_all(); 03771 this.select_node(obj, true); 03772 } 03773 if(s.show_at_node || typeof x === "undefined" || typeof y === "undefined") { 03774 o = a.offset(); 03775 x = o.left; 03776 y = o.top + this.data.core.li_height; 03777 } 03778 i = obj.data("jstree") && obj.data("jstree").contextmenu ? obj.data("jstree").contextmenu : s.items; 03779 if($.isFunction(i)) { i = i.call(this, obj); } 03780 this.data.contextmenu = true; 03781 $.vakata.context.show(i, a, x, y, this, obj, this._get_settings().core.rtl); 03782 if(this.data.themes) { $.vakata.context.cnt.attr("class", "jstree-" + this.data.themes.theme + "-context"); } 03783 } 03784 } 03785 }); 03786 })(jQuery); 03787 //*/ 03788 03789 /* 03790 * jsTree types plugin 03791 * Adds support types of nodes 03792 * You can set an attribute on each li node, that represents its type. 03793 * According to the type setting the node may get custom icon/validation rules 03794 */ 03795 (function ($) { 03796 $.jstree.plugin("types", { 03797 __init : function () { 03798 var s = this._get_settings().types; 03799 this.data.types.attach_to = []; 03800 this.get_container() 03801 .bind("init.jstree", $.proxy(function () { 03802 var types = s.types, 03803 attr = s.type_attr, 03804 icons_css = "", 03805 _this = this; 03806 03807 $.each(types, function (i, tp) { 03808 $.each(tp, function (k, v) { 03809 if(!/^(max_depth|max_children|icon|valid_children)$/.test(k)) { _this.data.types.attach_to.push(k); } 03810 }); 03811 if(!tp.icon) { return true; } 03812 if( tp.icon.image || tp.icon.position) { 03813 if(i == "default") { icons_css += '.jstree-' + _this.get_index() + ' a > .jstree-icon { '; } 03814 else { icons_css += '.jstree-' + _this.get_index() + ' li[' + attr + '="' + i + '"] > a > .jstree-icon { '; } 03815 if(tp.icon.image) { icons_css += ' background-image:url(' + tp.icon.image + '); '; } 03816 if(tp.icon.position){ icons_css += ' background-position:' + tp.icon.position + '; '; } 03817 else { icons_css += ' background-position:0 0; '; } 03818 icons_css += '} '; 03819 } 03820 }); 03821 if(icons_css !== "") { $.vakata.css.add_sheet({ 'str' : icons_css, title : "jstree-types" }); } 03822 }, this)) 03823 .bind("before.jstree", $.proxy(function (e, data) { 03824 var s, t, 03825 o = this._get_settings().types.use_data ? this._get_node(data.args[0]) : false, 03826 d = o && o !== -1 && o.length ? o.data("jstree") : false; 03827 if(d && d.types && d.types[data.func] === false) { e.stopImmediatePropagation(); return false; } 03828 if($.inArray(data.func, this.data.types.attach_to) !== -1) { 03829 if(!data.args[0] || (!data.args[0].tagName && !data.args[0].jquery)) { return; } 03830 s = this._get_settings().types.types; 03831 t = this._get_type(data.args[0]); 03832 if( 03833 ( 03834 (s[t] && typeof s[t][data.func] !== "undefined") || 03835 (s["default"] && typeof s["default"][data.func] !== "undefined") 03836 ) && this._check(data.func, data.args[0]) === false 03837 ) { 03838 e.stopImmediatePropagation(); 03839 return false; 03840 } 03841 } 03842 }, this)); 03843 if(is_ie6) { 03844 this.get_container() 03845 .bind("load_node.jstree set_type.jstree", $.proxy(function (e, data) { 03846 var r = data && data.rslt && data.rslt.obj && data.rslt.obj !== -1 ? this._get_node(data.rslt.obj).parent() : this.get_container_ul(), 03847 c = false, 03848 s = this._get_settings().types; 03849 $.each(s.types, function (i, tp) { 03850 if(tp.icon && (tp.icon.image || tp.icon.position)) { 03851 c = i === "default" ? r.find("li > a > .jstree-icon") : r.find("li[" + s.type_attr + "='" + i + "'] > a > .jstree-icon"); 03852 if(tp.icon.image) { c.css("backgroundImage","url(" + tp.icon.image + ")"); } 03853 c.css("backgroundPosition", tp.icon.position || "0 0"); 03854 } 03855 }); 03856 }, this)); 03857 } 03858 }, 03859 defaults : { 03860 // defines maximum number of root nodes (-1 means unlimited, -2 means disable max_children checking) 03861 max_children : -1, 03862 // defines the maximum depth of the tree (-1 means unlimited, -2 means disable max_depth checking) 03863 max_depth : -1, 03864 // defines valid node types for the root nodes 03865 valid_children : "all", 03866 03867 // whether to use $.data 03868 use_data : false, 03869 // where is the type stores (the rel attribute of the LI element) 03870 type_attr : "rel", 03871 // a list of types 03872 types : { 03873 // the default type 03874 "default" : { 03875 "max_children" : -1, 03876 "max_depth" : -1, 03877 "valid_children": "all" 03878 03879 // Bound functions - you can bind any other function here (using boolean or function) 03880 //"select_node" : true 03881 } 03882 } 03883 }, 03884 _fn : { 03885 _types_notify : function (n, data) { 03886 if(data.type && this._get_settings().types.use_data) { 03887 this.set_type(data.type, n); 03888 } 03889 }, 03890 _get_type : function (obj) { 03891 obj = this._get_node(obj); 03892 return (!obj || !obj.length) ? false : obj.attr(this._get_settings().types.type_attr) || "default"; 03893 }, 03894 set_type : function (str, obj) { 03895 obj = this._get_node(obj); 03896 var ret = (!obj.length || !str) ? false : obj.attr(this._get_settings().types.type_attr, str); 03897 if(ret) { this.__callback({ obj : obj, type : str}); } 03898 return ret; 03899 }, 03900 _check : function (rule, obj, opts) { 03901 obj = this._get_node(obj); 03902 var v = false, t = this._get_type(obj), d = 0, _this = this, s = this._get_settings().types, data = false; 03903 if(obj === -1) { 03904 if(!!s[rule]) { v = s[rule]; } 03905 else { return; } 03906 } 03907 else { 03908 if(t === false) { return; } 03909 data = s.use_data ? obj.data("jstree") : false; 03910 if(data && data.types && typeof data.types[rule] !== "undefined") { v = data.types[rule]; } 03911 else if(!!s.types[t] && typeof s.types[t][rule] !== "undefined") { v = s.types[t][rule]; } 03912 else if(!!s.types["default"] && typeof s.types["default"][rule] !== "undefined") { v = s.types["default"][rule]; } 03913 } 03914 if($.isFunction(v)) { v = v.call(this, obj); } 03915 if(rule === "max_depth" && obj !== -1 && opts !== false && s.max_depth !== -2 && v !== 0) { 03916 // also include the node itself - otherwise if root node it is not checked 03917 obj.children("a:eq(0)").parentsUntil(".jstree","li").each(function (i) { 03918 // check if current depth already exceeds global tree depth 03919 if(s.max_depth !== -1 && s.max_depth - (i + 1) <= 0) { v = 0; return false; } 03920 d = (i === 0) ? v : _this._check(rule, this, false); 03921 // check if current node max depth is already matched or exceeded 03922 if(d !== -1 && d - (i + 1) <= 0) { v = 0; return false; } 03923 // otherwise - set the max depth to the current value minus current depth 03924 if(d >= 0 && (d - (i + 1) < v || v < 0) ) { v = d - (i + 1); } 03925 // if the global tree depth exists and it minus the nodes calculated so far is less than `v` or `v` is unlimited 03926 if(s.max_depth >= 0 && (s.max_depth - (i + 1) < v || v < 0) ) { v = s.max_depth - (i + 1); } 03927 }); 03928 } 03929 return v; 03930 }, 03931 check_move : function () { 03932 if(!this.__call_old()) { return false; } 03933 var m = this._get_move(), 03934 s = m.rt._get_settings().types, 03935 mc = m.rt._check("max_children", m.cr), 03936 md = m.rt._check("max_depth", m.cr), 03937 vc = m.rt._check("valid_children", m.cr), 03938 ch = 0, d = 1, t; 03939 03940 if(vc === "none") { return false; } 03941 if($.isArray(vc) && m.ot && m.ot._get_type) { 03942 m.o.each(function () { 03943 if($.inArray(m.ot._get_type(this), vc) === -1) { d = false; return false; } 03944 }); 03945 if(d === false) { return false; } 03946 } 03947 if(s.max_children !== -2 && mc !== -1) { 03948 ch = m.cr === -1 ? this.get_container().find("> ul > li").not(m.o).length : m.cr.find("> ul > li").not(m.o).length; 03949 if(ch + m.o.length > mc) { return false; } 03950 } 03951 if(s.max_depth !== -2 && md !== -1) { 03952 d = 0; 03953 if(md === 0) { return false; } 03954 if(typeof m.o.d === "undefined") { 03955 // TODO: deal with progressive rendering and async when checking max_depth (how to know the depth of the moved node) 03956 t = m.o; 03957 while(t.length > 0) { 03958 t = t.find("> ul > li"); 03959 d ++; 03960 } 03961 m.o.d = d; 03962 } 03963 if(md - m.o.d < 0) { return false; } 03964 } 03965 return true; 03966 }, 03967 create_node : function (obj, position, js, callback, is_loaded, skip_check) { 03968 if(!skip_check && (is_loaded || this._is_loaded(obj))) { 03969 var p = (typeof position == "string" && position.match(/^before|after$/i) && obj !== -1) ? this._get_parent(obj) : this._get_node(obj), 03970 s = this._get_settings().types, 03971 mc = this._check("max_children", p), 03972 md = this._check("max_depth", p), 03973 vc = this._check("valid_children", p), 03974 ch; 03975 if(typeof js === "string") { js = { data : js }; } 03976 if(!js) { js = {}; } 03977 if(vc === "none") { return false; } 03978 if($.isArray(vc)) { 03979 if(!js.attr || !js.attr[s.type_attr]) { 03980 if(!js.attr) { js.attr = {}; } 03981 js.attr[s.type_attr] = vc[0]; 03982 } 03983 else { 03984 if($.inArray(js.attr[s.type_attr], vc) === -1) { return false; } 03985 } 03986 } 03987 if(s.max_children !== -2 && mc !== -1) { 03988 ch = p === -1 ? this.get_container().find("> ul > li").length : p.find("> ul > li").length; 03989 if(ch + 1 > mc) { return false; } 03990 } 03991 if(s.max_depth !== -2 && md !== -1 && (md - 1) < 0) { return false; } 03992 } 03993 return this.__call_old(true, obj, position, js, callback, is_loaded, skip_check); 03994 } 03995 } 03996 }); 03997 })(jQuery); 03998 //*/ 03999 04000 /* 04001 * jsTree HTML plugin 04002 * The HTML data store. Datastores are build by replacing the `load_node` and `_is_loaded` functions. 04003 */ 04004 (function ($) { 04005 $.jstree.plugin("html_data", { 04006 __init : function () { 04007 // this used to use html() and clean the whitespace, but this way any attached data was lost 04008 this.data.html_data.original_container_html = this.get_container().find(" > ul > li").clone(true); 04009 // remove white space from LI node - otherwise nodes appear a bit to the right 04010 this.data.html_data.original_container_html.find("li").andSelf().contents().filter(function() { return this.nodeType == 3; }).remove(); 04011 }, 04012 defaults : { 04013 data : false, 04014 ajax : false, 04015 correct_state : true 04016 }, 04017 _fn : { 04018 load_node : function (obj, s_call, e_call) { var _this = this; this.load_node_html(obj, function () { _this.__callback({ "obj" : _this._get_node(obj) }); s_call.call(this); }, e_call); }, 04019 _is_loaded : function (obj) { 04020 obj = this._get_node(obj); 04021 return obj == -1 || !obj || (!this._get_settings().html_data.ajax && !$.isFunction(this._get_settings().html_data.data)) || obj.is(".jstree-open, .jstree-leaf") || obj.children("ul").children("li").size() > 0; 04022 }, 04023 load_node_html : function (obj, s_call, e_call) { 04024 var d, 04025 s = this.get_settings().html_data, 04026 error_func = function () {}, 04027 success_func = function () {}; 04028 obj = this._get_node(obj); 04029 if(obj && obj !== -1) { 04030 if(obj.data("jstree_is_loading")) { return; } 04031 else { obj.data("jstree_is_loading",true); } 04032 } 04033 switch(!0) { 04034 case ($.isFunction(s.data)): 04035 s.data.call(this, obj, $.proxy(function (d) { 04036 if(d && d !== "" && d.toString && d.toString().replace(/^[\s\n]+$/,"") !== "") { 04037 d = $(d); 04038 if(!d.is("ul")) { d = $("<ul />").append(d); } 04039 if(obj == -1 || !obj) { this.get_container().children("ul").empty().append(d.children()).find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'> </ins>").end().filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); } 04040 else { obj.children("a.jstree-loading").removeClass("jstree-loading"); obj.append(d).children("ul").find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'> </ins>").end().filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); obj.removeData("jstree_is_loading"); } 04041 this.clean_node(obj); 04042 if(s_call) { s_call.call(this); } 04043 } 04044 else { 04045 if(obj && obj !== -1) { 04046 obj.children("a.jstree-loading").removeClass("jstree-loading"); 04047 obj.removeData("jstree_is_loading"); 04048 if(s.correct_state) { 04049 this.correct_state(obj); 04050 if(s_call) { s_call.call(this); } 04051 } 04052 } 04053 else { 04054 if(s.correct_state) { 04055 this.get_container().children("ul").empty(); 04056 if(s_call) { s_call.call(this); } 04057 } 04058 } 04059 } 04060 }, this)); 04061 break; 04062 case (!s.data && !s.ajax): 04063 if(!obj || obj == -1) { 04064 this.get_container() 04065 .children("ul").empty() 04066 .append(this.data.html_data.original_container_html) 04067 .find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'> </ins>").end() 04068 .filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); 04069 this.clean_node(); 04070 } 04071 if(s_call) { s_call.call(this); } 04072 break; 04073 case (!!s.data && !s.ajax) || (!!s.data && !!s.ajax && (!obj || obj === -1)): 04074 if(!obj || obj == -1) { 04075 d = $(s.data); 04076 if(!d.is("ul")) { d = $("<ul />").append(d); } 04077 this.get_container() 04078 .children("ul").empty().append(d.children()) 04079 .find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'> </ins>").end() 04080 .filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); 04081 this.clean_node(); 04082 } 04083 if(s_call) { s_call.call(this); } 04084 break; 04085 case (!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj && obj !== -1): 04086 obj = this._get_node(obj); 04087 error_func = function (x, t, e) { 04088 var ef = this.get_settings().html_data.ajax.error; 04089 if(ef) { ef.call(this, x, t, e); } 04090 if(obj != -1 && obj.length) { 04091 obj.children("a.jstree-loading").removeClass("jstree-loading"); 04092 obj.removeData("jstree_is_loading"); 04093 if(t === "success" && s.correct_state) { this.correct_state(obj); } 04094 } 04095 else { 04096 if(t === "success" && s.correct_state) { this.get_container().children("ul").empty(); } 04097 } 04098 if(e_call) { e_call.call(this); } 04099 }; 04100 success_func = function (d, t, x) { 04101 var sf = this.get_settings().html_data.ajax.success; 04102 if(sf) { d = sf.call(this,d,t,x) || d; } 04103 if(d === "" || (d && d.toString && d.toString().replace(/^[\s\n]+$/,"") === "")) { 04104 return error_func.call(this, x, t, ""); 04105 } 04106 if(d) { 04107 d = $(d); 04108 if(!d.is("ul")) { d = $("<ul />").append(d); } 04109 if(obj == -1 || !obj) { this.get_container().children("ul").empty().append(d.children()).find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'> </ins>").end().filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); } 04110 else { obj.children("a.jstree-loading").removeClass("jstree-loading"); obj.append(d).children("ul").find("li, a").filter(function () { return !this.firstChild || !this.firstChild.tagName || this.firstChild.tagName !== "INS"; }).prepend("<ins class='jstree-icon'> </ins>").end().filter("a").children("ins:first-child").not(".jstree-icon").addClass("jstree-icon"); obj.removeData("jstree_is_loading"); } 04111 this.clean_node(obj); 04112 if(s_call) { s_call.call(this); } 04113 } 04114 else { 04115 if(obj && obj !== -1) { 04116 obj.children("a.jstree-loading").removeClass("jstree-loading"); 04117 obj.removeData("jstree_is_loading"); 04118 if(s.correct_state) { 04119 this.correct_state(obj); 04120 if(s_call) { s_call.call(this); } 04121 } 04122 } 04123 else { 04124 if(s.correct_state) { 04125 this.get_container().children("ul").empty(); 04126 if(s_call) { s_call.call(this); } 04127 } 04128 } 04129 } 04130 }; 04131 s.ajax.context = this; 04132 s.ajax.error = error_func; 04133 s.ajax.success = success_func; 04134 if(!s.ajax.dataType) { s.ajax.dataType = "html"; } 04135 if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); } 04136 if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); } 04137 $.ajax(s.ajax); 04138 break; 04139 } 04140 } 04141 } 04142 }); 04143 // include the HTML data plugin by default 04144 $.jstree.defaults.plugins.push("html_data"); 04145 })(jQuery); 04146 //*/ 04147 04148 /* 04149 * jsTree themeroller plugin 04150 * Adds support for jQuery UI themes. Include this at the end of your plugins list, also make sure "themes" is not included. 04151 */ 04152 (function ($) { 04153 $.jstree.plugin("themeroller", { 04154 __init : function () { 04155 var s = this._get_settings().themeroller; 04156 this.get_container() 04157 .addClass("ui-widget-content") 04158 .addClass("jstree-themeroller") 04159 .delegate("a","mouseenter.jstree", function (e) { 04160 if(!$(e.currentTarget).hasClass("jstree-loading")) { 04161 $(this).addClass(s.item_h); 04162 } 04163 }) 04164 .delegate("a","mouseleave.jstree", function () { 04165 $(this).removeClass(s.item_h); 04166 }) 04167 .bind("init.jstree", $.proxy(function (e, data) { 04168 data.inst.get_container().find("> ul > li > .jstree-loading > ins").addClass("ui-icon-refresh"); 04169 this._themeroller(data.inst.get_container().find("> ul > li")); 04170 }, this)) 04171 .bind("open_node.jstree create_node.jstree", $.proxy(function (e, data) { 04172 this._themeroller(data.rslt.obj); 04173 }, this)) 04174 .bind("loaded.jstree refresh.jstree", $.proxy(function (e) { 04175 this._themeroller(); 04176 }, this)) 04177 .bind("close_node.jstree", $.proxy(function (e, data) { 04178 this._themeroller(data.rslt.obj); 04179 }, this)) 04180 .bind("delete_node.jstree", $.proxy(function (e, data) { 04181 this._themeroller(data.rslt.parent); 04182 }, this)) 04183 .bind("correct_state.jstree", $.proxy(function (e, data) { 04184 data.rslt.obj 04185 .children("ins.jstree-icon").removeClass(s.opened + " " + s.closed + " ui-icon").end() 04186 .find("> a > ins.ui-icon") 04187 .filter(function() { 04188 return this.className.toString() 04189 .replace(s.item_clsd,"").replace(s.item_open,"").replace(s.item_leaf,"") 04190 .indexOf("ui-icon-") === -1; 04191 }).removeClass(s.item_open + " " + s.item_clsd).addClass(s.item_leaf || "jstree-no-icon"); 04192 }, this)) 04193 .bind("select_node.jstree", $.proxy(function (e, data) { 04194 data.rslt.obj.children("a").addClass(s.item_a); 04195 }, this)) 04196 .bind("deselect_node.jstree deselect_all.jstree", $.proxy(function (e, data) { 04197 this.get_container() 04198 .find("a." + s.item_a).removeClass(s.item_a).end() 04199 .find("a.jstree-clicked").addClass(s.item_a); 04200 }, this)) 04201 .bind("dehover_node.jstree", $.proxy(function (e, data) { 04202 data.rslt.obj.children("a").removeClass(s.item_h); 04203 }, this)) 04204 .bind("hover_node.jstree", $.proxy(function (e, data) { 04205 this.get_container() 04206 .find("a." + s.item_h).not(data.rslt.obj).removeClass(s.item_h); 04207 data.rslt.obj.children("a").addClass(s.item_h); 04208 }, this)) 04209 .bind("move_node.jstree", $.proxy(function (e, data) { 04210 this._themeroller(data.rslt.o); 04211 this._themeroller(data.rslt.op); 04212 }, this)); 04213 }, 04214 __destroy : function () { 04215 var s = this._get_settings().themeroller, 04216 c = [ "ui-icon" ]; 04217 $.each(s, function (i, v) { 04218 v = v.split(" "); 04219 if(v.length) { c = c.concat(v); } 04220 }); 04221 this.get_container() 04222 .removeClass("ui-widget-content") 04223 .find("." + c.join(", .")).removeClass(c.join(" ")); 04224 }, 04225 _fn : { 04226 _themeroller : function (obj) { 04227 var s = this._get_settings().themeroller; 04228 obj = !obj || obj == -1 ? this.get_container_ul() : this._get_node(obj).parent(); 04229 obj 04230 .find("li.jstree-closed") 04231 .children("ins.jstree-icon").removeClass(s.opened).addClass("ui-icon " + s.closed).end() 04232 .children("a").addClass(s.item) 04233 .children("ins.jstree-icon").addClass("ui-icon") 04234 .filter(function() { 04235 return this.className.toString() 04236 .replace(s.item_clsd,"").replace(s.item_open,"").replace(s.item_leaf,"") 04237 .indexOf("ui-icon-") === -1; 04238 }).removeClass(s.item_leaf + " " + s.item_open).addClass(s.item_clsd || "jstree-no-icon") 04239 .end() 04240 .end() 04241 .end() 04242 .end() 04243 .find("li.jstree-open") 04244 .children("ins.jstree-icon").removeClass(s.closed).addClass("ui-icon " + s.opened).end() 04245 .children("a").addClass(s.item) 04246 .children("ins.jstree-icon").addClass("ui-icon") 04247 .filter(function() { 04248 return this.className.toString() 04249 .replace(s.item_clsd,"").replace(s.item_open,"").replace(s.item_leaf,"") 04250 .indexOf("ui-icon-") === -1; 04251 }).removeClass(s.item_leaf + " " + s.item_clsd).addClass(s.item_open || "jstree-no-icon") 04252 .end() 04253 .end() 04254 .end() 04255 .end() 04256 .find("li.jstree-leaf") 04257 .children("ins.jstree-icon").removeClass(s.closed + " ui-icon " + s.opened).end() 04258 .children("a").addClass(s.item) 04259 .children("ins.jstree-icon").addClass("ui-icon") 04260 .filter(function() { 04261 return this.className.toString() 04262 .replace(s.item_clsd,"").replace(s.item_open,"").replace(s.item_leaf,"") 04263 .indexOf("ui-icon-") === -1; 04264 }).removeClass(s.item_clsd + " " + s.item_open).addClass(s.item_leaf || "jstree-no-icon"); 04265 } 04266 }, 04267 defaults : { 04268 "opened" : "ui-icon-triangle-1-se", 04269 "closed" : "ui-icon-triangle-1-e", 04270 "item" : "ui-state-default", 04271 "item_h" : "ui-state-hover", 04272 "item_a" : "ui-state-active", 04273 "item_open" : "ui-icon-folder-open", 04274 "item_clsd" : "ui-icon-folder-collapsed", 04275 "item_leaf" : "ui-icon-document" 04276 } 04277 }); 04278 $(function() { 04279 var css_string = '' + 04280 '.jstree-themeroller .ui-icon { overflow:visible; } ' + 04281 '.jstree-themeroller a { padding:0 2px; } ' + 04282 '.jstree-themeroller .jstree-no-icon { display:none; }'; 04283 $.vakata.css.add_sheet({ str : css_string, title : "jstree" }); 04284 }); 04285 })(jQuery); 04286 //*/ 04287 04288 /* 04289 * jsTree unique plugin 04290 * Forces different names amongst siblings (still a bit experimental) 04291 * NOTE: does not check language versions (it will not be possible to have nodes with the same title, even in different languages) 04292 */ 04293 (function ($) { 04294 $.jstree.plugin("unique", { 04295 __init : function () { 04296 this.get_container() 04297 .bind("before.jstree", $.proxy(function (e, data) { 04298 var nms = [], res = true, p, t; 04299 if(data.func == "move_node") { 04300 // obj, ref, position, is_copy, is_prepared, skip_check 04301 if(data.args[4] === true) { 04302 if(data.args[0].o && data.args[0].o.length) { 04303 data.args[0].o.children("a").each(function () { nms.push($(this).text().replace(/^\s+/g,"")); }); 04304 res = this._check_unique(nms, data.args[0].np.find("> ul > li").not(data.args[0].o), "move_node"); 04305 } 04306 } 04307 } 04308 if(data.func == "create_node") { 04309 // obj, position, js, callback, is_loaded 04310 if(data.args[4] || this._is_loaded(data.args[0])) { 04311 p = this._get_node(data.args[0]); 04312 if(data.args[1] && (data.args[1] === "before" || data.args[1] === "after")) { 04313 p = this._get_parent(data.args[0]); 04314 if(!p || p === -1) { p = this.get_container(); } 04315 } 04316 if(typeof data.args[2] === "string") { nms.push(data.args[2]); } 04317 else if(!data.args[2] || !data.args[2].data) { nms.push(this._get_string("new_node")); } 04318 else { nms.push(data.args[2].data); } 04319 res = this._check_unique(nms, p.find("> ul > li"), "create_node"); 04320 } 04321 } 04322 if(data.func == "rename_node") { 04323 // obj, val 04324 nms.push(data.args[1]); 04325 t = this._get_node(data.args[0]); 04326 p = this._get_parent(t); 04327 if(!p || p === -1) { p = this.get_container(); } 04328 res = this._check_unique(nms, p.find("> ul > li").not(t), "rename_node"); 04329 } 04330 if(!res) { 04331 e.stopPropagation(); 04332 return false; 04333 } 04334 }, this)); 04335 }, 04336 defaults : { 04337 error_callback : $.noop 04338 }, 04339 _fn : { 04340 _check_unique : function (nms, p, func) { 04341 var cnms = []; 04342 p.children("a").each(function () { cnms.push($(this).text().replace(/^\s+/g,"")); }); 04343 if(!cnms.length || !nms.length) { return true; } 04344 cnms = cnms.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(","); 04345 if((cnms.length + nms.length) != cnms.concat(nms).sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",").length) { 04346 this._get_settings().unique.error_callback.call(null, nms, p, func); 04347 return false; 04348 } 04349 return true; 04350 }, 04351 check_move : function () { 04352 if(!this.__call_old()) { return false; } 04353 var p = this._get_move(), nms = []; 04354 if(p.o && p.o.length) { 04355 p.o.children("a").each(function () { nms.push($(this).text().replace(/^\s+/g,"")); }); 04356 return this._check_unique(nms, p.np.find("> ul > li").not(p.o), "check_move"); 04357 } 04358 return true; 04359 } 04360 } 04361 }); 04362 })(jQuery); 04363 //*/ 04364 04365 /* 04366 * jsTree wholerow plugin 04367 * Makes select and hover work on the entire width of the node 04368 * MAY BE HEAVY IN LARGE DOM 04369 */ 04370 (function ($) { 04371 $.jstree.plugin("wholerow", { 04372 __init : function () { 04373 if(!this.data.ui) { throw "jsTree wholerow: jsTree UI plugin not included."; } 04374 this.data.wholerow.html = false; 04375 this.data.wholerow.to = false; 04376 this.get_container() 04377 .bind("init.jstree", $.proxy(function (e, data) { 04378 this._get_settings().core.animation = 0; 04379 }, this)) 04380 .bind("open_node.jstree create_node.jstree clean_node.jstree loaded.jstree", $.proxy(function (e, data) { 04381 this._prepare_wholerow_span( data && data.rslt && data.rslt.obj ? data.rslt.obj : -1 ); 04382 }, this)) 04383 .bind("search.jstree clear_search.jstree reopen.jstree after_open.jstree after_close.jstree create_node.jstree delete_node.jstree clean_node.jstree", $.proxy(function (e, data) { 04384 if(this.data.to) { clearTimeout(this.data.to); } 04385 this.data.to = setTimeout( (function (t, o) { return function() { t._prepare_wholerow_ul(o); }; })(this, data && data.rslt && data.rslt.obj ? data.rslt.obj : -1), 0); 04386 }, this)) 04387 .bind("deselect_all.jstree", $.proxy(function (e, data) { 04388 this.get_container().find(" > .jstree-wholerow .jstree-clicked").removeClass("jstree-clicked " + (this.data.themeroller ? this._get_settings().themeroller.item_a : "" )); 04389 }, this)) 04390 .bind("select_node.jstree deselect_node.jstree ", $.proxy(function (e, data) { 04391 data.rslt.obj.each(function () { 04392 var ref = data.inst.get_container().find(" > .jstree-wholerow li:visible:eq(" + ( parseInt((($(this).offset().top - data.inst.get_container().offset().top + data.inst.get_container()[0].scrollTop) / data.inst.data.core.li_height),10)) + ")"); 04393 // ref.children("a")[e.type === "select_node" ? "addClass" : "removeClass"]("jstree-clicked"); 04394 ref.children("a").attr("class",data.rslt.obj.children("a").attr("class")); 04395 }); 04396 }, this)) 04397 .bind("hover_node.jstree dehover_node.jstree", $.proxy(function (e, data) { 04398 this.get_container().find(" > .jstree-wholerow .jstree-hovered").removeClass("jstree-hovered " + (this.data.themeroller ? this._get_settings().themeroller.item_h : "" )); 04399 if(e.type === "hover_node") { 04400 var ref = this.get_container().find(" > .jstree-wholerow li:visible:eq(" + ( parseInt(((data.rslt.obj.offset().top - this.get_container().offset().top + this.get_container()[0].scrollTop) / this.data.core.li_height),10)) + ")"); 04401 // ref.children("a").addClass("jstree-hovered"); 04402 ref.children("a").attr("class",data.rslt.obj.children(".jstree-hovered").attr("class")); 04403 } 04404 }, this)) 04405 .delegate(".jstree-wholerow-span, ins.jstree-icon, li", "click.jstree", function (e) { 04406 var n = $(e.currentTarget); 04407 if(e.target.tagName === "A" || (e.target.tagName === "INS" && n.closest("li").is(".jstree-open, .jstree-closed"))) { return; } 04408 n.closest("li").children("a:visible:eq(0)").click(); 04409 e.stopImmediatePropagation(); 04410 }) 04411 .delegate("li", "mouseover.jstree", $.proxy(function (e) { 04412 e.stopImmediatePropagation(); 04413 if($(e.currentTarget).children(".jstree-hovered, .jstree-clicked").length) { return false; } 04414 this.hover_node(e.currentTarget); 04415 return false; 04416 }, this)) 04417 .delegate("li", "mouseleave.jstree", $.proxy(function (e) { 04418 if($(e.currentTarget).children("a").hasClass("jstree-hovered").length) { return; } 04419 this.dehover_node(e.currentTarget); 04420 }, this)); 04421 if(is_ie7 || is_ie6) { 04422 $.vakata.css.add_sheet({ str : ".jstree-" + this.get_index() + " { position:relative; } ", title : "jstree" }); 04423 } 04424 }, 04425 defaults : { 04426 }, 04427 __destroy : function () { 04428 this.get_container().children(".jstree-wholerow").remove(); 04429 this.get_container().find(".jstree-wholerow-span").remove(); 04430 }, 04431 _fn : { 04432 _prepare_wholerow_span : function (obj) { 04433 obj = !obj || obj == -1 ? this.get_container().find("> ul > li") : this._get_node(obj); 04434 if(obj === false) { return; } // added for removing root nodes 04435 obj.each(function () { 04436 $(this).find("li").andSelf().each(function () { 04437 var $t = $(this); 04438 if($t.children(".jstree-wholerow-span").length) { return true; } 04439 $t.prepend("<span class='jstree-wholerow-span' style='width:" + ($t.parentsUntil(".jstree","li").length * 18) + "px;'> </span>"); 04440 }); 04441 }); 04442 }, 04443 _prepare_wholerow_ul : function () { 04444 var o = this.get_container().children("ul").eq(0), h = o.html(); 04445 o.addClass("jstree-wholerow-real"); 04446 if(this.data.wholerow.last_html !== h) { 04447 this.data.wholerow.last_html = h; 04448 this.get_container().children(".jstree-wholerow").remove(); 04449 this.get_container().append( 04450 o.clone().removeClass("jstree-wholerow-real") 04451 .wrapAll("<div class='jstree-wholerow' />").parent() 04452 .width(o.parent()[0].scrollWidth) 04453 .css("top", (o.height() + ( is_ie7 ? 5 : 0)) * -1 ) 04454 .find("li[id]").each(function () { this.removeAttribute("id"); }).end() 04455 ); 04456 } 04457 } 04458 } 04459 }); 04460 $(function() { 04461 var css_string = '' + 04462 '.jstree .jstree-wholerow-real { position:relative; z-index:1; } ' + 04463 '.jstree .jstree-wholerow-real li { cursor:pointer; } ' + 04464 '.jstree .jstree-wholerow-real a { border-left-color:transparent !important; border-right-color:transparent !important; } ' + 04465 '.jstree .jstree-wholerow { position:relative; z-index:0; height:0; } ' + 04466 '.jstree .jstree-wholerow ul, .jstree .jstree-wholerow li { width:100%; } ' + 04467 '.jstree .jstree-wholerow, .jstree .jstree-wholerow ul, .jstree .jstree-wholerow li, .jstree .jstree-wholerow a { margin:0 !important; padding:0 !important; } ' + 04468 '.jstree .jstree-wholerow, .jstree .jstree-wholerow ul, .jstree .jstree-wholerow li { background:transparent !important; }' + 04469 '.jstree .jstree-wholerow ins, .jstree .jstree-wholerow span, .jstree .jstree-wholerow input { display:none !important; }' + 04470 '.jstree .jstree-wholerow a, .jstree .jstree-wholerow a:hover { text-indent:-9999px; !important; width:100%; padding:0 !important; border-right-width:0px !important; border-left-width:0px !important; } ' + 04471 '.jstree .jstree-wholerow-span { position:absolute; left:0; margin:0px; padding:0; height:18px; border-width:0; padding:0; z-index:0; }'; 04472 if(is_ff2) { 04473 css_string += '' + 04474 '.jstree .jstree-wholerow a { display:block; height:18px; margin:0; padding:0; border:0; } ' + 04475 '.jstree .jstree-wholerow-real a { border-color:transparent !important; } '; 04476 } 04477 if(is_ie7 || is_ie6) { 04478 css_string += '' + 04479 '.jstree .jstree-wholerow, .jstree .jstree-wholerow li, .jstree .jstree-wholerow ul, .jstree .jstree-wholerow a { margin:0; padding:0; line-height:18px; } ' + 04480 '.jstree .jstree-wholerow a { display:block; height:18px; line-height:18px; overflow:hidden; } '; 04481 } 04482 $.vakata.css.add_sheet({ str : css_string, title : "jstree" }); 04483 }); 04484 })(jQuery); 04485 //*/ 04486 04487 /* 04488 * jsTree model plugin 04489 * This plugin gets jstree to use a class model to retrieve data, creating great dynamism 04490 */ 04491 (function ($) { 04492 var nodeInterface = ["getChildren","getChildrenCount","getAttr","getName","getProps"], 04493 validateInterface = function(obj, inter) { 04494 var valid = true; 04495 obj = obj || {}; 04496 inter = [].concat(inter); 04497 $.each(inter, function (i, v) { 04498 if(!$.isFunction(obj[v])) { valid = false; return false; } 04499 }); 04500 return valid; 04501 }; 04502 $.jstree.plugin("model", { 04503 __init : function () { 04504 if(!this.data.json_data) { throw "jsTree model: jsTree json_data plugin not included."; } 04505 this._get_settings().json_data.data = function (n, b) { 04506 var obj = (n == -1) ? this._get_settings().model.object : n.data("jstree_model"); 04507 if(!validateInterface(obj, nodeInterface)) { return b.call(null, false); } 04508 if(this._get_settings().model.async) { 04509 obj.getChildren($.proxy(function (data) { 04510 this.model_done(data, b); 04511 }, this)); 04512 } 04513 else { 04514 this.model_done(obj.getChildren(), b); 04515 } 04516 }; 04517 }, 04518 defaults : { 04519 object : false, 04520 id_prefix : false, 04521 async : false 04522 }, 04523 _fn : { 04524 model_done : function (data, callback) { 04525 var ret = [], 04526 s = this._get_settings(), 04527 _this = this; 04528 04529 if(!$.isArray(data)) { data = [data]; } 04530 $.each(data, function (i, nd) { 04531 var r = nd.getProps() || {}; 04532 r.attr = nd.getAttr() || {}; 04533 if(nd.getChildrenCount()) { r.state = "closed"; } 04534 r.data = nd.getName(); 04535 if(!$.isArray(r.data)) { r.data = [r.data]; } 04536 if(_this.data.types && $.isFunction(nd.getType)) { 04537 r.attr[s.types.type_attr] = nd.getType(); 04538 } 04539 if(r.attr.id && s.model.id_prefix) { r.attr.id = s.model.id_prefix + r.attr.id; } 04540 if(!r.metadata) { r.metadata = { }; } 04541 r.metadata.jstree_model = nd; 04542 ret.push(r); 04543 }); 04544 callback.call(null, ret); 04545 } 04546 } 04547 }); 04548 })(jQuery); 04549 //*/ 04550 04551 })();