/* * jsTree 0.9.8 * http://jstree.com/ * * Copyright (c) 2009 Ivan Bozhanov (vakata.com) * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Date: 2009-05-15 * */ (function($){$.fn.tree=function(opts){return this.each(function(){var conf=$.extend({},opts);if(tree_component.inst&&tree_component.inst[$(this).attr('id')])tree_component.inst[$(this).attr('id')].destroy();if(conf!==false)new tree_component().init(this,conf)})};$.tree_create=function(){return new tree_component()};$.tree_focused=function(){return tree_component.inst[tree_component.focused]};$.tree_reference=function(id){return tree_component.inst[id]||null};$.tree_rollback=function(data){for(var i in data){if(typeof data[i]=="function")continue;var tmp=tree_component.inst[i];var lock=!tmp.locked;if(lock)tmp.lock(true);if(tmp.inp)tmp.inp.val("").blur();tmp.context.append=false;tmp.container.html(data[i].html).find(".dragged").removeClass("dragged").end().find("div.context").remove();if(data[i].selected){tmp.selected=$("#"+data[i].selected);tmp.selected_arr=[];tmp.container.find("a.clicked").each(function(){tmp.selected_arr.push(tmp.get_node(this))})}if(lock)tmp.lock(false);delete lock;delete tmp}};function tree_component(){if(typeof tree_component.inst=="undefined"){tree_component.cntr=0;tree_component.inst={};tree_component.drag_drop={isdown:false,drag_node:false,drag_help:false,init_x:false,init_y:false,moving:false,origin_tree:false,marker:false,move_type:false,ref_node:false,appended:false,foreign:false,droppable:[],open_time:false,scroll_time:false};tree_component.mousedown=function(event){var tmp=$(event.target);if(tree_component.drag_drop.droppable.length&&tmp.is("."+tree_component.drag_drop.droppable.join(", ."))){tree_component.drag_drop.drag_help=$("
");tree_component.drag_drop.drag_node=tree_component.drag_drop.drag_help.find("li:eq(0)");tree_component.drag_drop.isdown=true;tree_component.drag_drop.foreign=tmp;tmp.blur();event.preventDefault();event.stopPropagation();return false}event.stopPropagation();return true};tree_component.mouseup=function(event){var tmp=tree_component.drag_drop;if(tmp.open_time)clearTimeout(tmp.open_time);if(tmp.scroll_time)clearTimeout(tmp.scroll_time);if(tmp.foreign===false&&tmp.drag_node&&tmp.drag_node.size()){tmp.drag_help.remove();if(tmp.move_type){var tree1=tree_component.inst[tmp.ref_node.parents(".tree:eq(0)").attr("id")];if(tree1)tree1.moved(tmp.origin_tree.container.find("li.dragged"),tmp.ref_node,tmp.move_type,false,(tmp.origin_tree.settings.rules.drag_copy=="on"||(tmp.origin_tree.settings.rules.drag_copy=="ctrl"&&event.ctrlKey)))}tmp.move_type=false;tmp.ref_node=false}if(tmp.drag_node&&tmp.foreign!==false){tmp.drag_help.remove();if(tmp.move_type){var tree1=tree_component.inst[tmp.ref_node.parents(".tree:eq(0)").attr("id")];if(tree1)tree1.settings.callback.ondrop.call(null,tmp.foreign.get(0),tree1.get_node(tmp.ref_node).get(0),tmp.move_type,tree1)}tmp.foreign=false;tmp.move_type=false;tmp.ref_node=false}tree_component.drag_drop.marker.hide();tmp.drag_help=false;tmp.drag_node=false;tmp.isdown=false;tmp.init_x=false;tmp.init_y=false;tmp.moving=false;tmp.appended=false;$("li.dragged").removeClass("dragged");tmp.origin_tree=false;event.preventDefault();event.stopPropagation();return false};tree_component.mousemove=function(event){var tmp=tree_component.drag_drop;if(tmp.isdown){if(!tmp.moving&&Math.abs(tmp.init_x-event.pageX)<5&&Math.abs(tmp.init_y-event.pageY)<5){event.preventDefault();event.stopPropagation();return false}else tree_component.drag_drop.moving=true;if(tmp.open_time)clearTimeout(tmp.open_time);if(!tmp.appended){if(tmp.foreign!==false)tmp.origin_tree=$.tree_focused();$("body").append(tmp.drag_help);tmp.w=tmp.drag_help.width();tmp.appended=true}tmp.drag_help.css({"left":(event.pageX-(tmp.origin_tree.settings.ui.rtl?tmp.w:-5)),"top":(event.pageY+15)});if(event.target.tagName=="IMG"&&event.target.id=="marker")return false;var et=$(event.target);var cnt=et.is(".tree")?et:et.parents(".tree:eq(0)");if(cnt.size()==0||!tree_component.inst[cnt.attr("id")]){if(tmp.scroll_time)clearTimeout(tmp.scroll_time);if(tmp.drag_help.find("IMG").size()==0){tmp.drag_help.find("li:eq(0)").append("