annotate inkscape/firefox/content/tree_component.js @ 1327:ab281ec3eeec

Add a layers group for components The children of the layers group of a components is layers of the component. All layers are children of a layers group instead of a component group.
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 30 Jan 2011 23:04:06 +0800
parents 4350aa369149
children
rev   line source
352
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1 /*
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
2 * jsTree 0.9.6
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
3 * http://jstree.com/
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
4 *
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
5 * Copyright (c) 2008 Ivan Bozhanov (vakata.com)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
6 *
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
7 * Dual licensed under the MIT and GPL licenses:
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
8 * http://www.opensource.org/licenses/mit-license.php
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
9 * http://www.gnu.org/licenses/gpl.html
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
10 *
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
11 * Date: 2009-02-24
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
12 *
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
13 */
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
14
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
15 (function($) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
16 // jQuery plugin
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
17 $.fn.tree = function (opts) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
18 return this.each(function() {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
19 var conf = $.extend({},opts);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
20 if(tree_component.inst && tree_component.inst[$(this).attr('id')]) tree_component.inst[$(this).attr('id')].destroy();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
21 if(conf !== false) new tree_component().init(this, conf);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
22 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
23 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
24 $.tree_create = function() {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
25 return new tree_component();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
26 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
27 $.tree_focused = function() {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
28 return tree_component.inst[tree_component.focused];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
29 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
30 // core
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
31 function tree_component () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
32 // instance manager
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
33 if(typeof tree_component.inst == "undefined") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
34 tree_component.cntr = 0;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
35 tree_component.inst = {};
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
36
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
37 // DRAG'N'DROP STUFF
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
38 tree_component.drag_drop = {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
39 isdown : false, // Is there a drag
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
40 drag_node : false, // The actual node
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
41 drag_help : false, // The helper
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
42 origin_tree : false,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
43 marker : false,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
44
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
45 move_type : false, // before, after or inside
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
46 ref_node : false, // reference node
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
47 appended : false, // is helper appended
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
48
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
49 foreign : false, // Is the dragged node a foreign one
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
50 droppable : [], // Array of classes that can be dropped onto the tree
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
51
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
52 open_time : false, // Timeout for opening nodes
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
53 scroll_time : false // Timeout for scrolling
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
54 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
55 // listening for clicks on foreign nodes
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
56 tree_component.mousedown = function(event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
57 var tmp = $(event.target);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
58 if(tree_component.drag_drop.droppable.length && tmp.is("." + tree_component.drag_drop.droppable.join(", .")) ) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
59 tree_component.drag_drop.drag_help = $("<li id='dragged' class='dragged foreign " + event.target.className + "'><a href='#'>" + tmp.text() + "</a></li>");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
60 tree_component.drag_drop.drag_node = tree_component.drag_drop.drag_help;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
61 tree_component.drag_drop.isdown = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
62 tree_component.drag_drop.foreign = tmp;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
63 tmp.blur();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
64 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
65 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
66 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
67 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
68 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
69 return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
70 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
71 tree_component.mouseup = function(event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
72 var tmp = tree_component.drag_drop;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
73 if(tmp.open_time) clearTimeout(tmp.open_time);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
74 if(tmp.scroll_time) clearTimeout(tmp.scroll_time);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
75 if(tmp.foreign === false && tmp.drag_node && tmp.drag_node.size()) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
76 tmp.drag_help.remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
77 if(tmp.move_type) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
78 var tree1 = tree_component.inst[tmp.ref_node.parents(".tree:eq(0)").attr("id")];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
79 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) ) );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
80 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
81 tmp.move_type = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
82 tmp.ref_node = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
83 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
84 if(tmp.drag_node && tmp.foreign !== false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
85 tmp.drag_help.remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
86 if(tmp.move_type) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
87 var tree1 = tree_component.inst[tmp.ref_node.parents(".tree:eq(0)").attr("id")];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
88 if(tree1) tree1.settings.callback.ondrop.call(null, tmp.foreign.get(0), tree1.get_node(tmp.ref_node).get(0), tmp.move_type, tree1);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
89 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
90 tmp.foreign = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
91 tmp.move_type = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
92 tmp.ref_node = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
93 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
94 // RESET EVERYTHING
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
95 tree_component.drag_drop.marker.hide();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
96 tmp.drag_help = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
97 tmp.drag_node = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
98 tmp.isdown = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
99 tmp.appended = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
100 if(tmp.origin_tree) tmp.origin_tree.container.find("li.dragged").removeClass("dragged");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
101 tmp.origin_tree = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
102 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
103 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
104 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
105 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
106 tree_component.mousemove = function(event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
107 var tmp = tree_component.drag_drop;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
108
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
109 if(tmp.isdown) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
110 if(tmp.open_time) clearTimeout(tmp.open_time);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
111 if(!tmp.appended) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
112 if(tmp.foreign !== false) tmp.origin_tree = $.tree_focused();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
113 tmp.origin_tree.container.children("ul:eq(0)").append(tmp.drag_help);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
114 var temp = $(tmp.drag_help).offsetParent();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
115 if(temp.is("html")) temp = $("body");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
116 tmp.po = temp.offset();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
117 tmp.w = tmp.drag_help.width();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
118
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
119 tmp.appended = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
120 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
121 tmp.drag_help.css({ "left" : (event.pageX - tmp.po.left - (tmp.origin_tree.settings.ui.rtl ? tmp.w : -5 ) ), "top" : (event.pageY - tmp.po.top + ($.browser.opera ? tmp.origin_tree.container.scrollTop() : 0) + 15) });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
122
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
123 if(event.target.tagName == "IMG" && event.target.id == "marker") return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
124
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
125 var cnt = $(event.target).parents(".tree:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
126
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
127 // if not moving over a tree
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
128 if(cnt.size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
129 if(tmp.scroll_time) clearTimeout(tmp.scroll_time);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
130 if(tmp.drag_help.children("IMG").size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
131 tmp.drag_help.append("<img style='position:absolute; " + (tmp.origin_tree.settings.ui.rtl ? "right" : "left" ) + ":4px; top:0px; background:white; padding:2px;' src='" + tmp.origin_tree.settings.ui.theme_path + "remove.png' />");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
132 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
133 tmp.move_type = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
134 tmp.ref_node = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
135 tree_component.drag_drop.marker.hide();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
136 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
137 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
138
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
139 var tree2 = tree_component.inst[cnt.attr("id")];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
140 tree2.off_height();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
141
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
142 // if moving over another tree and multitree is false
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
143 if( tmp.foreign === false && tmp.origin_tree.container.get(0) != tree2.container.get(0) && (!tmp.origin_tree.settings.rules.multitree || !tree2.settings.rules.multitree) ) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
144 if(tmp.drag_help.children("IMG").size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
145 tmp.drag_help.append("<img style='position:absolute; " + (tmp.origin_tree.settings.ui.rtl ? "right" : "left" ) + ":4px; top:0px; background:white; padding:2px;' src='" + tmp.origin_tree.settings.ui.theme_path + "remove.png' />");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
146 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
147 tmp.move_type = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
148 tmp.ref_node = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
149 tree_component.drag_drop.marker.hide();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
150 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
151 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
152
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
153 if(tmp.scroll_time) clearTimeout(tmp.scroll_time);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
154 tmp.scroll_time = setTimeout( function() { tree2.scrollCheck(event.pageX,event.pageY); }, 50);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
155
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
156 var mov = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
157 var st = cnt.scrollTop();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
158
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
159 var et = $(event.target);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
160 if(event.target.tagName == "A" ) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
161 // just in case if hover is over the draggable
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
162 if(et.is("#dragged")) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
163 if(tree2.get_node(event.target).hasClass("closed")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
164 tmp.open_time = setTimeout( function () { tree2.open_branch(et); }, 500);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
165 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
166
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
167 var goTo = {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
168 x : (et.offset().left - 1),
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
169 y : (event.pageY - tree2.offset.top)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
170 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
171 if(cnt.hasClass("rtl")) goTo.x += et.width() - 8;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
172 var arr = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
173 if( (goTo.y + st)%tree2.li_height < tree2.li_height/3 + 1 ) arr = ["before","inside","after"];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
174 else if((goTo.y + st)%tree2.li_height > tree2.li_height*2/3 - 1 ) arr = ["after","inside","before"];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
175 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
176 if((goTo.y + st)%tree2.li_height < tree2.li_height/2) arr = ["inside","before","after"];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
177 else arr = ["inside","after","before"];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
178 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
179 var ok = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
180 $.each(arr, function(i, val) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
181 if(tree2.checkMove(tmp.origin_tree.container.find("li.dragged"), et, val)) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
182 mov = val;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
183 ok = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
184 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
185 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
186 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
187 if(ok) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
188 switch(mov) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
189 case "before":
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
190 goTo.y = event.pageY - (goTo.y + st)%tree2.li_height - 2 ;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
191 if(cnt.hasClass("rtl")) { tree_component.drag_drop.marker.attr("src", tree2.settings.ui.theme_path + "marker_rtl.gif").width(40); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
192 else { tree_component.drag_drop.marker.attr("src", tree2.settings.ui.theme_path + "marker.gif").width(40); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
193 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
194 case "after":
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
195 goTo.y = event.pageY - (goTo.y + st)%tree2.li_height + tree2.li_height - 2 ;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
196 if(cnt.hasClass("rtl")) { tree_component.drag_drop.marker.attr("src", tree2.settings.ui.theme_path + "marker_rtl.gif").width(40); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
197 else { tree_component.drag_drop.marker.attr("src", tree2.settings.ui.theme_path + "marker.gif").width(40); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
198 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
199 case "inside":
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
200 goTo.x -= 2;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
201 if(cnt.hasClass("rtl")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
202 goTo.x += 36;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
203 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
204 goTo.y = event.pageY - (goTo.y + st)%tree2.li_height + Math.floor(tree2.li_height/2) - 2 ;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
205 tree_component.drag_drop.marker.attr("src", tree2.settings.ui.theme_path + "default/plus.gif").width(11);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
206 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
207 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
208 tmp.move_type = mov;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
209 tmp.ref_node = $(event.target);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
210 tmp.drag_help.children("IMG").remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
211 tree_component.drag_drop.marker.css({ "left" : goTo.x , "top" : goTo.y }).show();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
212 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
213 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
214 if(event.target.tagName != "A" || !ok) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
215 if(tmp.drag_help.children("IMG").size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
216 tmp.drag_help.append("<img style='position:absolute; " + (tmp.origin_tree.settings.ui.rtl ? "right" : "left" ) + ":4px; top:0px; background:white; padding:2px;' src='" + tmp.origin_tree.settings.ui.theme_path + "remove.png' />");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
217 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
218 tmp.move_type = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
219 tmp.ref_node = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
220 tree_component.drag_drop.marker.hide();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
221 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
222 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
223 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
224 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
225 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
226 return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
227 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
228 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
229 return {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
230 cntr : ++tree_component.cntr,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
231 settings : {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
232 data : {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
233 type : "predefined", // ENUM [json, xml_flat, xml_nested, predefined]
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
234 method : "GET", // HOW TO REQUEST FILES
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
235 async : false, // BOOL - async loading onopen
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
236 async_data : function (NODE) { return { id : $(NODE).attr("id") || 0 } }, // PARAMETERS PASSED TO SERVER
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
237 url : false, // FALSE or STRING - url to document to be used (async or not)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
238 json : false // FALSE or OBJECT if type is JSON and async is false - the tree dump as json
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
239 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
240 selected : false, // FALSE or STRING or ARRAY
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
241 opened : [], // ARRAY OF INITIALLY OPENED NODES
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
242 languages : [], // ARRAY of string values (which will be used as CSS classes - so they must be valid)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
243 path : false, // FALSE or STRING (if false - will be autodetected)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
244 cookies : false, // FALSE or OBJECT (prefix, open, selected, opts - from jqCookie - expires, path, domain, secure)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
245 ui : {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
246 dots : true, // BOOL - dots or no dots
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
247 rtl : false, // BOOL - is the tree right-to-left
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
248 animation : 0, // INT - duration of open/close animations in miliseconds
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
249 hover_mode : true, // SHOULD get_* functions chage focus or change hovered item
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
250 scroll_spd : 4,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
251 theme_path : false, // Path to themes
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
252 theme_name : "default",// Name of theme
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
253 context : [
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
254 {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
255 id : "create",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
256 label : "Create",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
257 icon : "create.png",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
258 visible : function (NODE, TREE_OBJ) { if(NODE.length != 1) return false; return TREE_OBJ.check("creatable", NODE); },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
259 action : function (NODE, TREE_OBJ) { TREE_OBJ.create(false, TREE_OBJ.selected); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
260 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
261 "separator",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
262 {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
263 id : "rename",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
264 label : "Rename",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
265 icon : "rename.png",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
266 visible : function (NODE, TREE_OBJ) { if(NODE.length != 1) return false; return TREE_OBJ.check("renameable", NODE); },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
267 action : function (NODE, TREE_OBJ) { TREE_OBJ.rename(); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
268 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
269 {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
270 id : "delete",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
271 label : "Delete",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
272 icon : "remove.png",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
273 visible : function (NODE, TREE_OBJ) { var ok = true; $.each(NODE, function () { if(TREE_OBJ.check("deletable", this) == false) ok = false; return false; }); return ok; },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
274 action : function (NODE, TREE_OBJ) { $.each(NODE, function () { TREE_OBJ.remove(this); }); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
275 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
276 ]
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
277 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
278 rules : {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
279 multiple : false, // FALSE | CTRL | ON - multiple selection off/ with or without holding Ctrl
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
280 metadata : false, // FALSE or STRING - attribute name (use metadata plugin)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
281 type_attr : "rel", // STRING attribute name (where is the type stored if no metadata)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
282 multitree : false, // BOOL - is drag n drop between trees allowed
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
283 createat : "bottom", // STRING (top or bottom) new nodes get inserted at top or bottom
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
284 use_inline : false, // CHECK FOR INLINE RULES - REQUIRES METADATA
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
285 clickable : "all", // which node types can the user select | default - all
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
286 renameable : "all", // which node types can the user select | default - all
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
287 deletable : "all", // which node types can the user delete | default - all
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
288 creatable : "all", // which node types can the user create in | default - all
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
289 draggable : "none", // which node types can the user move | default - none | "all"
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
290 dragrules : "all", // what move operations between nodes are allowed | default - none | "all"
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
291 drag_copy : false, // FALSE | CTRL | ON - drag to copy off/ with or without holding Ctrl
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
292 droppable : []
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
293 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
294 lang : {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
295 new_node : "New folder",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
296 loading : "Loading ..."
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
297 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
298 callback : { // various callbacks to attach custom logic to
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
299 // before focus - should return true | false
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
300 beforechange: function(NODE,TREE_OBJ) { return true },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
301 beforeopen : function(NODE,TREE_OBJ) { return true },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
302 beforeclose : function(NODE,TREE_OBJ) { return true },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
303 // before move - should return true | false
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
304 beforemove : function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
305 // before create - should return true | false
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
306 beforecreate: function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
307 // before rename - should return true | false
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
308 beforerename: function(NODE,LANG,TREE_OBJ) { return true },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
309 // before delete - should return true | false
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
310 beforedelete: function(NODE,TREE_OBJ) { return true },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
311
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
312 onselect : function(NODE,TREE_OBJ) { }, // node selected
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
313 ondeselect : function(NODE,TREE_OBJ) { }, // node deselected
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
314 onchange : function(NODE,TREE_OBJ) { }, // focus changed
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
315 onrename : function(NODE,LANG,TREE_OBJ) { }, // node renamed ISNEW - TRUE|FALSE, current language
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
316 onmove : function(NODE,REF_NODE,TYPE,TREE_OBJ) { }, // move completed (TYPE is BELOW|ABOVE|INSIDE)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
317 oncopy : function(NODE,REF_NODE,TYPE,TREE_OBJ) { }, // copy completed (TYPE is BELOW|ABOVE|INSIDE)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
318 oncreate : function(NODE,REF_NODE,TYPE,TREE_OBJ) { }, // node created, parent node (TYPE is createat)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
319 ondelete : function(NODE, TREE_OBJ) { }, // node deleted
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
320 onopen : function(NODE, TREE_OBJ) { }, // node opened
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
321 onopen_all : function(NODE, TREE_OBJ) { }, // all nodes opened
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
322 onclose : function(NODE, TREE_OBJ) { }, // node closed
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
323 error : function(TEXT, TREE_OBJ) { }, // error occured
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
324 // double click on node - defaults to open/close & select
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
325 ondblclk : function(NODE, TREE_OBJ) { TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE); },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
326 // right click - to prevent use: EV.preventDefault(); EV.stopPropagation(); return false
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
327 onrgtclk : function(NODE, TREE_OBJ, EV) { },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
328 onload : function(TREE_OBJ) { },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
329 onfocus : function(TREE_OBJ) { },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
330 ondrop : function(NODE,REF_NODE,TYPE,TREE_OBJ) {}
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
331 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
332 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
333 // INITIALIZATION
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
334 init : function(elem, opts) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
335 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
336 this.container = $(elem);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
337 if(this.container.size == 0) { alert("Invalid container node!"); return }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
338
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
339 tree_component.inst[this.cntr] = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
340 if(!this.container.attr("id")) this.container.attr("id","jstree_" + this.cntr);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
341 tree_component.inst[this.container.attr("id")] = tree_component.inst[this.cntr];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
342 tree_component.focused = this.cntr;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
343
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
344 // MERGE OPTIONS WITH DEFAULTS
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
345 if(opts && opts.cookies) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
346 this.settings.cookies = $.extend({},this.settings.cookies,opts.cookies);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
347 delete opts.cookies;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
348 if(!this.settings.cookies.opts) this.settings.cookies.opts = {};
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
349 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
350 if(opts && opts.callback) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
351 this.settings.callback = $.extend({},this.settings.callback,opts.callback);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
352 delete opts.callback;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
353 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
354 if(opts && opts.data) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
355 this.settings.data = $.extend({},this.settings.data,opts.data);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
356 delete opts.data;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
357 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
358 if(opts && opts.ui) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
359 this.settings.ui = $.extend({},this.settings.ui,opts.ui);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
360 delete opts.ui;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
361 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
362 if(opts && opts.rules) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
363 this.settings.rules = $.extend({},this.settings.rules,opts.rules);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
364 delete opts.rules;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
365 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
366 if(opts && opts.lang) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
367 this.settings.lang = $.extend({},this.settings.lang,opts.lang);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
368 delete opts.lang;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
369 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
370 this.settings = $.extend({},this.settings,opts);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
371
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
372 // PATH TO IMAGES AND XSL
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
373 if(this.settings.path == false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
374 this.path = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
375 $("script").each( function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
376 if(this.src.toString().match(/tree_component.*?js$/)) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
377 _this.path = this.src.toString().replace(/tree_component.*?js$/, "");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
378 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
379 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
380 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
381 else this.path = this.settings.path;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
382
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
383 // DEAL WITH LANGUAGE VERSIONS
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
384 this.current_lang = this.settings.languages && this.settings.languages.length ? this.settings.languages[0] : false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
385 if(this.settings.languages && this.settings.languages.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
386 this.sn = get_sheet_num("tree_component.css");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
387 var st = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
388 var id = this.container.attr("id") ? "#" + this.container.attr("id") : ".tree";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
389 for(var ln = 0; ln < this.settings.languages.length; ln++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
390 st = add_css(id + " ." + this.settings.languages[ln], this.sn);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
391 if(st !== false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
392 if(this.settings.languages[ln] == this.current_lang) st.style.display = "inline";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
393 else st.style.display = "none";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
394 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
395 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
396 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
397
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
398 // DROPPABLES
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
399 if(this.settings.rules.droppable.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
400 for(var i in this.settings.rules.droppable) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
401 tree_component.drag_drop.droppable.push(this.settings.rules.droppable[i]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
402 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
403 tree_component.drag_drop.droppable = $.unique(tree_component.drag_drop.droppable);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
404 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
405
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
406 // THEMES
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
407 if(this.settings.ui.theme_path === false) this.settings.ui.theme_path = this.path + "themes/";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
408 this.theme = this.settings.ui.theme_path;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
409 if(_this.settings.ui.theme_name) this.theme += _this.settings.ui.theme_name + "/";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
410 add_sheet(_this.settings.ui.theme_path + "default/style.css");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
411 if(this.settings.ui.theme_name && this.settings.ui.theme_name != "default") add_sheet(_this.theme + "style.css");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
412
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
413 this.container.addClass("tree");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
414 if(this.settings.ui.rtl) this.container.addClass("rtl");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
415 if(this.settings.rules.multiple) this.selected_arr = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
416 this.offset = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
417
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
418 if(this.settings.ui.dots == false) this.container.addClass("no_dots");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
419
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
420 // CONTEXT MENU
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
421 this.context_menu();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
422
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
423 this.hovered = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
424 this.locked = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
425
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
426 // CREATE DUMMY FOR MOVING
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
427 if(this.settings.rules.draggable != "none" && tree_component.drag_drop.marker === false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
428 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
429 tree_component.drag_drop.marker = $("<img>")
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
430 .attr({
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
431 id : "marker",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
432 src : _this.settings.ui.theme_path + "marker.gif"
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
433 })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
434 .css({
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
435 height : "5px",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
436 width : "40px",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
437 display : "block",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
438 position : "absolute",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
439 left : "30px",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
440 top : "30px",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
441 zIndex : "1000"
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
442 }).hide().appendTo("body");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
443 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
444 this.refresh();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
445 this.attachEvents();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
446 this.focus();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
447 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
448 off_height : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
449 if(this.offset === false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
450 this.container.css({ position : "relative" });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
451 this.offset = this.container.offset();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
452 var tmp = 0;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
453 tmp = parseInt($.curCSS(this.container.get(0), "paddingTop", true),10);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
454 if(tmp) this.offset.top += tmp;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
455 tmp = parseInt($.curCSS(this.container.get(0), "borderTopWidth", true),10);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
456 if(tmp) this.offset.top += tmp;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
457 this.container.css({ position : "" });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
458 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
459 if(!this.li_height) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
460 var tmp = this.container.find("ul li.closed, ul li.leaf").eq(0);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
461 this.li_height = tmp.height();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
462 if(tmp.children("ul:eq(0)").size()) this.li_height -= tmp.children("ul:eq(0)").height();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
463 if(!this.li_height) this.li_height = 18;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
464 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
465 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
466 context_menu : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
467 this.context = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
468 if(this.settings.ui.context != false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
469 var str = '<div class="context">';
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
470 for(var i in this.settings.ui.context) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
471 if(this.settings.ui.context[i] == "separator") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
472 str += "<span class='separator'>&nbsp;</span>";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
473 continue;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
474 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
475 var icn = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
476 if(this.settings.ui.context[i].icon) icn = 'background-image:url(\'' + ( this.settings.ui.context[i].icon.indexOf("/") == -1 ? this.theme + this.settings.ui.context[i].icon : this.settings.ui.context[i].icon ) + '\');';
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
477 str += '<a rel="' + this.settings.ui.context[i].id + '" href="#" style="' + icn + '">' + this.settings.ui.context[i].label + '</a>';
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
478 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
479 str += '</div>';
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
480 this.context = $(str);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
481 this.context.hide();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
482 this.context.append = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
483 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
484 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
485 // REPAINT TREE
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
486 refresh : function (obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
487 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
488 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
489
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
490 // SAVE OPENED
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
491 this.opened = Array();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
492 if(this.settings.cookies && $.cookie(this.settings.cookies.prefix + '_open')) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
493 var str = $.cookie(this.settings.cookies.prefix + '_open');
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
494 var tmp = str.split(",");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
495 $.each(tmp, function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
496 _this.opened.push("#" + this.replace(/^#/,""));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
497 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
498 this.settings.opened = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
499 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
500 else if(this.settings.opened != false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
501 $.each(this.settings.opened, function (i, item) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
502 _this.opened.push("#" + this.replace(/^#/,""));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
503 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
504 this.settings.opened = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
505 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
506 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
507 this.container.find("li.open").each(function (i) { _this.opened.push("#" + this.id); });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
508 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
509
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
510 // SAVE SELECTED
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
511 if(this.selected) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
512 this.settings.selected = Array();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
513 if(this.selected_arr) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
514 $.each(this.selected_arr, function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
515 if(this.attr("id")) _this.settings.selected.push("#" + this.attr("id"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
516 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
517 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
518 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
519 if(this.selected.attr("id")) this.settings.selected.push("#" + this.selected.attr("id"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
520 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
521 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
522 else if(this.settings.cookies && $.cookie(this.settings.cookies.prefix + '_selected')) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
523 this.settings.selected = Array();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
524 var str = $.cookie(this.settings.cookies.prefix + '_selected');
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
525 var tmp = str.split(",");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
526 $.each(tmp, function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
527 _this.settings.selected.push("#" + this.replace(/^#/,""));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
528 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
529 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
530 else if(this.settings.selected !== false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
531 var tmp = Array();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
532 if((typeof this.settings.selected).toLowerCase() == "object") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
533 $.each(this.settings.selected, function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
534 if(this.replace(/^#/,"").length > 0) tmp.push("#" + this.replace(/^#/,""));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
535 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
536 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
537 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
538 if(this.settings.selected.replace(/^#/,"").length > 0) tmp.push("#" + this.settings.selected.replace(/^#/,""));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
539 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
540 this.settings.selected = tmp;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
541 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
542
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
543 if(obj && this.settings.data.async) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
544 this.opened = Array();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
545 obj = this.get_node(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
546 obj.find("li.open").each(function (i) { _this.opened.push("#" + this.id); });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
547 this.close_branch(obj, true);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
548 obj.children("ul:eq(0)").html("");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
549 return this.open_branch(obj, true, function () { _this.reselect.apply(_this); });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
550 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
551
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
552 var cls = "tree-default";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
553 if(this.settings.ui.theme_name != "default") cls += " tree-" + _this.settings.ui.theme_name;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
554
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
555 if(this.settings.data.type == "xml_flat" || this.settings.data.type == "xml_nested") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
556 this.scrtop = this.container.get(0).scrollTop;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
557 var xsl = (this.settings.data.type == "xml_flat") ? "flat.xsl" : "nested.xsl";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
558 this.container.getTransform(this.path + xsl, this.settings.data.url, { params : { theme_name : cls, theme_path : _this.theme }, meth : _this.settings.data.method, dat : _this.settings.data.async_data.apply(_this,[obj]) ,callback: function () { _this.context_menu.apply(_this); _this.reselect.apply(_this); } });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
559 return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
560 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
561 else if(this.settings.data.type == "json") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
562 if(this.settings.data.json) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
563 var str = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
564 if(this.settings.data.json.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
565 for(var i = 0; i < this.settings.data.json.length; i++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
566 str += this.parseJSON(this.settings.data.json[i]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
567 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
568 } else str = this.parseJSON(this.settings.data.json);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
569 this.container.html("<ul class='" + cls + "'>" + str + "</ul>");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
570 this.container.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
571 this.container.find("li").not(".open").not(".closed").addClass("leaf");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
572 this.context_menu();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
573 this.reselect();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
574 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
575 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
576 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
577 $.ajax({
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
578 type : this.settings.data.method,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
579 url : this.settings.data.url,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
580 data : this.settings.data.async_data(false),
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
581 dataType : "json",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
582 success : function (data) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
583 var str = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
584 if(data.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
585 for(var i = 0; i < data.length; i++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
586 str += _this.parseJSON(data[i]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
587 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
588 } else str = _this.parseJSON(data);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
589 _this.container.html("<ul class='" + cls + "'>" + str + "</ul>");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
590 _this.container.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
591 _this.container.find("li").not(".open").not(".closed").addClass("leaf");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
592 _this.context_menu.apply(_this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
593 _this.reselect.apply(_this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
594 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
595 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
596 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
597 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
598 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
599 this.container.children("ul:eq(0)").attr("class", cls);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
600 this.container.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
601 this.container.find("li").not(".open").not(".closed").addClass("leaf");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
602 this.reselect();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
603 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
604 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
605 // CONVERT JSON TO HTML
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
606 parseJSON : function (data) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
607 if(!data || !data.data) return "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
608 var str = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
609 str += "<li ";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
610 var cls = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
611 if(data.attributes) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
612 for(var i in data.attributes) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
613 if(i == "class") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
614 str += " class='" + data.attributes[i] + " ";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
615 if(data.state == "closed" || data.state == "open") str += " " + data.state + " ";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
616 str += "' ";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
617 cls = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
618 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
619 else str += " " + i + "='" + data.attributes[i] + "' ";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
620 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
621 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
622 if(!cls && (data.state == "closed" || data.state == "open")) str += " class='" + data.state + "' ";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
623 str += ">";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
624 if(this.settings.languages.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
625 for(var i = 0; i < this.settings.languages.length; i++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
626 var attr = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
627 attr["href"] = "#";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
628 attr["style"] = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
629 attr["class"] = this.settings.languages[i];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
630 if(data.data[this.settings.languages[i]] && (typeof data.data[this.settings.languages[i]].attributes).toLowerCase() != "undefined") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
631 for(var j in data.data[this.settings.languages[i]].attributes) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
632 if(j == "style" || j == "class") attr[j] += " " + data.data[this.settings.languages[i]].attributes[j];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
633 else attr[j] = data.data[this.settings.languages[i]].attributes[j];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
634 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
635 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
636 if(data.data[this.settings.languages[i]] && data.data[this.settings.languages[i]].icon) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
637 var icn = data.data[this.settings.languages[i]].icon.indexOf("/") == -1 ? this.theme + data.data[this.settings.languages[i]].icon : data.data[this.settings.languages[i]].icon;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
638 attr["style"] += " ; background-image:url('" + icn + "'); ";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
639 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
640 str += "<a";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
641 for(var j in attr) str += ' ' + j + '="' + attr[j] + '" ';
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
642 str += ">" + ( (typeof data.data[this.settings.languages[i]].title).toLowerCase() != "undefined" ? data.data[this.settings.languages[i]].title : data.data[this.settings.languages[i]] ) + "</a>";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
643 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
644 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
645 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
646 var attr = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
647 attr["href"] = "#";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
648 attr["style"] = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
649 attr["class"] = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
650 if((typeof data.data.attributes).toLowerCase() != "undefined") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
651 for(var i in data.data.attributes) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
652 if(i == "style" || i == "class") attr[i] += " " + data.data.attributes[i];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
653 else attr[i] = data.data.attributes[i];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
654 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
655 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
656 if(data.data.icon) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
657 var icn = data.data.icon.indexOf("/") == -1 ? this.theme + data.data.icon : data.data.icon;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
658 attr["style"] += " ; background-image:url('" + icn + "');";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
659 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
660 str += "<a";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
661 for(var i in attr) str += ' ' + i + '="' + attr[i] + '" ';
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
662 str += ">" + ( (typeof data.data.title).toLowerCase() != "undefined" ? data.data.title : data.data ) + "</a>";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
663 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
664 if(data.children && data.children.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
665 str += '<ul>';
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
666 for(var i = 0; i < data.children.length; i++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
667 str += this.parseJSON(data.children[i]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
668 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
669 str += '</ul>';
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
670 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
671 str += "</li>";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
672 return str;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
673 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
674 // getJSON from HTML
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
675 getJSON : function (nod, outer_attrib, inner_attrib, force) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
676 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
677 if(!nod || $(nod).size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
678 nod = this.container.children("ul").children("li");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
679 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
680 else nod = $(nod);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
681
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
682 if(nod.size() > 1) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
683 var arr = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
684 nod.each(function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
685 arr.push(_this.getJSON(this, outer_attrib, inner_attrib));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
686 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
687 return arr;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
688 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
689
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
690 if(!outer_attrib) outer_attrib = [ "id", "rel", "class" ];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
691 if(!inner_attrib) inner_attrib = [ ];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
692 var obj = { attributes : {}, data : false };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
693 for(var i in outer_attrib) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
694 obj.attributes[outer_attrib[i]] = nod.attr(outer_attrib[i]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
695 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
696 if(this.settings.languages.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
697 obj.data = {};
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
698 for(var i in this.settings.languages) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
699 var a = nod.children("a." + this.settings.languages[i]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
700 if(force || inner_attrib.length || a.get(0).style.backgroundImage.toString().length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
701 obj.data[this.settings.languages[i]] = {};
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
702 obj.data[this.settings.languages[i]].title = a.text();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
703 if(a.get(0).style.backgroundImage.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
704 obj.data[this.settings.languages[i]].icon = a.get(0).style.backgroundImage.replace("url(","").replace(")","");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
705 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
706 if(inner_attrib.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
707 obj.data[this.settings.languages[i]].attributes = {};
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
708 for(var j in inner_attrib) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
709 obj.data[this.settings.languages[i]].attributes[inner_attrib[j]] = a.attr(inner_attrib[j]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
710 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
711 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
712 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
713 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
714 obj.data[this.settings.languages[i]] = a.text();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
715 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
716 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
717 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
718 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
719 var a = nod.children("a");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
720 if(force || inner_attrib.length || a.get(0).style.backgroundImage.toString().length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
721 obj.data = {};
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
722 obj.data.title = a.text();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
723 if(a.get(0).style.backgroundImage.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
724 obj.data.icon = a.get(0).style.backgroundImage.replace("url(","").replace(")","");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
725 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
726 if(inner_attrib.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
727 obj.data.attributes = {};
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
728 for(var j in inner_attrib) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
729 obj.data.attributes[inner_attrib[j]] = a.attr(inner_attrib[j]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
730 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
731 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
732 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
733 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
734 obj.data = a.text();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
735 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
736 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
737
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
738 if(nod.children("ul").size() > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
739 obj.children = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
740 nod.children("ul").children("li").each(function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
741 obj.children.push(_this.getJSON(this, outer_attrib, inner_attrib));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
742 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
743 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
744 return obj;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
745 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
746 focus : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
747 if(this.locked) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
748 if(tree_component.focused != this.cntr) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
749 tree_component.focused = this.cntr;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
750 this.settings.callback.onfocus.call(null, this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
751 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
752 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
753 show_context : function (obj, x, y) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
754 var tmp = this.context.show().offsetParent();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
755 if(tmp.is("html")) tmp = $("body");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
756 tmp = tmp.offset();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
757 this.context.css({ "left" : (x - tmp.left - (this.settings.ui.rtl ? $(this.context).width() : -5 ) ), "top" : (y - tmp.top + ($.browser.opera ? this.container.scrollTop() : 0) + 15) });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
758 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
759 hide_context : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
760 this.context.hide();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
761 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
762 // ALL EVENTS
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
763 attachEvents : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
764 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
765
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
766 this.container
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
767 .bind("mousedown", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
768 if(tree_component.drag_drop.isdown) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
769 tree_component.drag_drop.move_type = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
770 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
771 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
772 event.stopImmediatePropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
773 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
774 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
775 })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
776 .bind("mouseup", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
777 setTimeout( function() { _this.focus.apply(_this); }, 5);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
778 })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
779 .bind("click", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
780 //event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
781 return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
782 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
783 $("#" + this.container.attr("id") + " li")
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
784 .live("click", function(event) { // WHEN CLICK IS ON THE ARROW
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
785 if(event.target.tagName != "LI") return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
786 _this.toggle_branch.apply(_this, [event.target]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
787 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
788 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
789 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
790 $("#" + this.container.attr("id") + " li a")
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
791 .live("click", function (event) { // WHEN CLICK IS ON THE TEXT OR ICON
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
792 if(event.which && event.which == 3) return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
793 if(_this.locked) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
794 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
795 event.target.blur();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
796 return _this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
797 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
798 _this.select_branch.apply(_this, [event.target, event.ctrlKey || _this.settings.rules.multiple == "on"]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
799 if(_this.inp) { _this.inp.blur(); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
800 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
801 event.target.blur();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
802 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
803 })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
804 .live("dblclick", function (event) { // WHEN DOUBLECLICK ON TEXT OR ICON
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
805 if(_this.locked) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
806 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
807 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
808 event.target.blur();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
809 return _this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
810 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
811 _this.settings.callback.ondblclk.call(null, _this.get_node(event.target).get(0), _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
812 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
813 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
814 event.target.blur();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
815 })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
816 .live("contextmenu", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
817 if(_this.locked) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
818 event.target.blur();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
819 return _this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
820 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
821 var val = _this.settings.callback.onrgtclk.call(null, _this.get_node(event.target).get(0), _this, event);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
822 if(_this.context) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
823 if(_this.context.append == false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
824 _this.container.find("ul:eq(0)").append(_this.context);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
825 _this.context.append = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
826 for(var i in _this.settings.ui.context) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
827 if(_this.settings.ui.context[i] == "separator") continue;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
828 (function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
829 var func = _this.settings.ui.context[i].action;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
830 _this.context.children("[rel=" + _this.settings.ui.context[i].id +"]")
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
831 .bind("click", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
832 if(!$(this).hasClass("disabled")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
833 func.call(null, _this.selected_arr || _this.selected, _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
834 _this.hide_context();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
835 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
836 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
837 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
838 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
839 })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
840 .bind("mouseup", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
841 this.blur();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
842 if($(this).hasClass("disabled")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
843 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
844 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
845 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
846 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
847 })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
848 .bind("mousedown", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
849 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
850 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
851 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
852 })();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
853 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
854 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
855 var obj = _this.get_node(event.target);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
856 if(_this.inp) { _this.inp.blur(); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
857 if(obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
858 if(!obj.children("a:eq(0)").hasClass("clicked")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
859 _this.select_branch.apply(_this, [event.target, event.ctrlKey || _this.settings.rules.multiple == "on"]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
860 event.target.blur();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
861 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
862 _this.context.children("a").removeClass("disabled").show();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
863 var go = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
864 for(var i in _this.settings.ui.context) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
865 if(_this.settings.ui.context[i] == "separator") continue;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
866 var state = _this.settings.ui.context[i].visible.call(null, _this.selected_arr || _this.selected, _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
867 if(state === false) _this.context.children("[rel=" + _this.settings.ui.context[i].id +"]").addClass("disabled");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
868 if(state === -1) _this.context.children("[rel=" + _this.settings.ui.context[i].id +"]").hide();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
869 else go = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
870 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
871 if(go == true) _this.show_context(obj, event.pageX, event.pageY);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
872 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
873 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
874 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
875 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
876 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
877 return val;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
878 })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
879 .live("mouseover", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
880 if(_this.locked) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
881 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
882 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
883 return _this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
884 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
885 if(_this.settings.ui.hover_mode && _this.hovered !== false && event.target.tagName == "A") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
886 _this.hovered.children("a").removeClass("hover");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
887 _this.hovered = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
888 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
889 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
890
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
891 // ATTACH DRAG & DROP ONLY IF NEEDED
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
892 if(this.settings.rules.draggable != "none") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
893 $("#" + this.container.attr("id") + " li a")
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
894 .live("mousedown", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
895 _this.focus.apply(_this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
896 if(_this.locked) return _this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
897 // SELECT LIST ITEM NODE
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
898 var obj = _this.get_node(event.target);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
899 // IF ITEM IS DRAGGABLE
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
900 if(_this.settings.rules.multiple != false && _this.selected_arr.length > 1 && obj.children("a:eq(0)").hasClass("clicked")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
901 var counter = 0;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
902 for(var i in _this.selected_arr) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
903 if(_this.check("draggable", _this.selected_arr[i])) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
904 _this.selected_arr[i].addClass("dragged");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
905 tree_component.drag_drop.origin_tree = _this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
906 counter ++;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
907 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
908 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
909 if(counter > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
910 if(_this.check("draggable", obj)) tree_component.drag_drop.drag_node = obj;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
911 else tree_component.drag_drop.drag_node = _this.container.find("li.dragged:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
912 tree_component.drag_drop.isdown = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
913 tree_component.drag_drop.drag_help = $(tree_component.drag_drop.drag_node.get(0).cloneNode(true));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
914 tree_component.drag_drop.drag_help.attr("id","dragged");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
915 tree_component.drag_drop.drag_help.children("a").html("Multiple selection").end().children("ul").remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
916 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
917 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
918 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
919 if(_this.check("draggable", obj)) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
920 tree_component.drag_drop.drag_node = obj;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
921 tree_component.drag_drop.drag_help = $(obj.get(0).cloneNode(true));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
922 tree_component.drag_drop.drag_help.attr("id","dragged");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
923 tree_component.drag_drop.isdown = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
924 tree_component.drag_drop.foreign = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
925 tree_component.drag_drop.origin_tree = _this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
926 obj.addClass("dragged");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
927 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
928 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
929 obj.blur();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
930 event.preventDefault();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
931 event.stopPropagation();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
932 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
933 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
934 $(document)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
935 .bind("mousedown", tree_component.mousedown)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
936 .bind("mouseup", tree_component.mouseup)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
937 .bind("mousemove", tree_component.mousemove);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
938 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
939 // ENDIF OF DRAG & DROP FUNCTIONS
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
940 if(_this.context) $(document).bind("mousedown", function() { _this.hide_context(); });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
941 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
942 checkMove : function (NODES, REF_NODE, TYPE) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
943 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
944 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
945
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
946 // OVER SELF OR CHILDREN
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
947 if(REF_NODE.parents("li.dragged").size() > 0 || REF_NODE.is(".dragged")) return this.error("MOVE: NODE OVER SELF");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
948 // CHECK AGAINST DRAG_RULES
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
949 if(NODES.size() == 1) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
950 var NODE = NODES.eq(0);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
951 if(tree_component.drag_drop.foreign) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
952 if(this.settings.rules.droppable.length == 0) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
953 if(!NODE.is("." + this.settings.rules.droppable.join(", ."))) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
954 var ok = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
955 for(var i in this.settings.rules.droppable) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
956 if(NODE.is("." + this.settings.rules.droppable[i])) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
957 if(this.settings.rules.metadata) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
958 $.metadata.setType("attr", this.settings.rules.metadata);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
959 NODE.attr(this.settings.rules.metadata, "type: '" + this.settings.rules.droppable[i] + "'");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
960 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
961 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
962 NODE.attr(this.settings.rules.type_attr, this.settings.rules.droppable[i]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
963 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
964 ok = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
965 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
966 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
967 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
968 if(!ok) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
969 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
970 if(!this.check("dragrules", [NODE, TYPE, REF_NODE.parents("li:eq(0)")])) return this.error("MOVE: AGAINST DRAG RULES");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
971 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
972 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
973 var ok = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
974 NODES.each(function (i) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
975 if(ok == false) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
976 if(i > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
977 var ref = NODES.eq( (i - 1) );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
978 var mv = "after";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
979 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
980 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
981 var ref = REF_NODE;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
982 var mv = TYPE;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
983 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
984 if(!_this.check.apply(_this,["dragrules", [$(this), mv, ref]])) ok = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
985 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
986 if(ok == false) return this.error("MOVE: AGAINST DRAG RULES");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
987 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
988 // CHECK AGAINST METADATA
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
989 if(this.settings.rules.use_inline && this.settings.rules.metadata) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
990 var nd = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
991 if(TYPE == "inside") nd = REF_NODE.parents("li:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
992 else nd = REF_NODE.parents("li:eq(1)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
993 if(nd.size()) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
994 // VALID CHILDREN CHECK
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
995 if(typeof nd.metadata()["valid_children"] != "undefined") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
996 var tmp = nd.metadata()["valid_children"];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
997 var ok = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
998 NODES.each(function (i) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
999 if(ok == false) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1000 if($.inArray(_this.get_type(this), tmp) == -1) ok = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1001 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1002 if(ok == false) return this.error("MOVE: NOT A VALID CHILD");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1003 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1004 // CHECK IF PARENT HAS FREE SLOTS FOR CHILDREN
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1005 if(typeof nd.metadata()["max_children"] != "undefined") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1006 if((nd.children("ul:eq(0)").children("li").not(".dragged").size() + NODES.size()) > nd.metadata().max_children) return this.error("MOVE: MAX CHILDREN REACHED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1007 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1008 // CHECK FOR MAXDEPTH UP THE CHAIN
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1009 var incr = 0;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1010 NODES.each(function (i) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1011 var i = 1;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1012 var t = $(this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1013 while(i < 100) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1014 t = t.children("ul:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1015 if(t.size() == 0) break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1016 i ++
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1017 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1018 incr = Math.max(i,incr);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1019 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1020 var ok = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1021 nd.parents("li").each(function(i) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1022 if(ok == false) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1023 if($(this).metadata().max_depth) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1024 if( (i + incr) >= $(this).metadata().max_depth) ok = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1025 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1026 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1027 if(ok == false) return this.error("MOVE: MAX_DEPTH REACHED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1028 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1029 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1030 return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1031 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1032 // USED AFTER REFRESH
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1033 reselect : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1034 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1035 // REOPEN BRANCHES
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1036 if(this.opened && this.opened.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1037 var opn = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1038 for(var j = 0; j < this.opened.length; j++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1039 if(this.settings.data.async) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1040 if(this.get_node(this.opened[j]).size() > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1041 opn = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1042 var tmp = this.opened[j];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1043 delete this.opened[j];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1044 this.open_branch(tmp, true, function () { _this.reselect.apply(_this); } )
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1045 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1046 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1047 else this.open_branch(this.opened[j], true);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1048 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1049 if(this.settings.data.async && opn) return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1050 delete this.opened;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1051 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1052 // REPOSITION SCROLL
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1053 if(this.scrtop) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1054 this.container.scrollTop(_this.scrtop);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1055 delete this.scrtop;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1056 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1057 // RESELECT PREVIOUSLY SELECTED
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1058 if(this.settings.selected !== false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1059 $.each(this.settings.selected, function (i) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1060 _this.select_branch($(_this.settings.selected[i]), (_this.settings.rules.multiple !== false && i > 0) );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1061 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1062 this.settings.selected = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1063 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1064 this.settings.callback.onload.call(null, _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1065 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1066 // GET THE EXTENDED LI ELEMENT
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1067 get_node : function (obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1068 var obj = $(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1069 return obj.is("li") ? obj : obj.parents("li:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1070 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1071 // GET THE TYPE OF THE NODE
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1072 get_type : function (obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1073 obj = !obj ? this.selected : this.get_node(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1074 if(!obj) return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1075 if(this.settings.rules.metadata) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1076 $.metadata.setType("attr", this.settings.rules.metadata);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1077 var tmp = obj.metadata().type;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1078 if(tmp) return tmp;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1079 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1080 return obj.attr(this.settings.rules.type_attr);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1081 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1082 // SCROLL CONTAINER WHILE DRAGGING
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1083 scrollCheck : function (x,y) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1084 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1085 var cnt = _this.container;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1086 var off = _this.offset;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1087
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1088 var st = cnt.scrollTop();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1089 var sl = cnt.scrollLeft();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1090 // DETECT HORIZONTAL SCROLL
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1091 var h_cor = (cnt.get(0).scrollWidth > cnt.width()) ? 40 : 20;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1092
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1093 if(y - off.top < 20) cnt.scrollTop(Math.max( (st - _this.settings.ui.scroll_spd) ,0)); // NEAR TOP
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1094 if(cnt.height() - (y - off.top) < h_cor) cnt.scrollTop(st + _this.settings.ui.scroll_spd); // NEAR BOTTOM
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1095 if(x - off.left < 20) cnt.scrollLeft(Math.max( (sl - _this.settings.ui.scroll_spd),0)); // NEAR LEFT
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1096 if(cnt.width() - (x - off.left) < 40) cnt.scrollLeft(sl + _this.settings.ui.scroll_spd); // NEAR RIGHT
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1097
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1098 if(cnt.scrollLeft() != sl || cnt.scrollTop() != st) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1099 _this.moveType = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1100 _this.moveRef = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1101 tree_component.drag_drop.marker.hide();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1102 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1103 tree_component.drag_drop.scroll_time = setTimeout( function() { _this.scrollCheck(x,y); }, 50);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1104 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1105 check : function (rule, nodes) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1106 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1107 // CHECK LOCAL RULES IF METADATA
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1108 if(rule != "dragrules" && this.settings.rules.use_inline && this.settings.rules.metadata) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1109 $.metadata.setType("attr", this.settings.rules.metadata);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1110 if(typeof this.get_node(nodes).metadata()[rule] != "undefined") return this.get_node(nodes).metadata()[rule];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1111 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1112 if(!this.settings.rules[rule]) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1113 if(this.settings.rules[rule] == "none") return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1114 if(this.settings.rules[rule] == "all") return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1115 if(rule == "dragrules") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1116 var nds = new Array();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1117 nds[0] = this.get_type(nodes[0]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1118 nds[1] = nodes[1];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1119 nds[2] = this.get_type(nodes[2]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1120 for(var i = 0; i < this.settings.rules.dragrules.length; i++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1121 var r = this.settings.rules.dragrules[i];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1122 var n = (r.indexOf("!") === 0) ? false : true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1123 if(!n) r = r.replace("!","");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1124 var tmp = r.split(" ");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1125 for(var j = 0; j < 3; j++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1126 if(tmp[j] == nds[j] || tmp[j] == "*") tmp[j] = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1127 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1128 if(tmp[0] === true && tmp[1] === true && tmp[2] === true) return n;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1129 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1130 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1131 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1132 else
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1133 return ($.inArray(this.get_type(nodes),this.settings.rules[rule]) != -1) ? true : false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1134 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1135 hover_branch : function (obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1136 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1137 if(this.settings.ui.hover_mode == false) return this.select_branch(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1138 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1139 var obj = _this.get_node(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1140 if(!obj.size()) return this.error("HOVER: NOT A VALID NODE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1141 // CHECK AGAINST RULES FOR SELECTABLE NODES
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1142 if(!_this.check("clickable", obj)) return this.error("SELECT: NODE NOT SELECTABLE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1143 if(this.hovered) this.hovered.children("A").removeClass("hover");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1144
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1145 // SAVE NEWLY SELECTED
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1146 this.hovered = obj;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1147
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1148 // FOCUS NEW NODE AND OPEN ALL PARENT NODES IF CLOSED
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1149 this.hovered.children("a").removeClass("hover").addClass("hover");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1150
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1151 // SCROLL SELECTED NODE INTO VIEW
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1152 var off_t = this.hovered.offset().top;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1153 var beg_t = this.container.offset().top;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1154 var end_t = beg_t + this.container.height();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1155 var h_cor = (this.container.get(0).scrollWidth > this.container.width()) ? 40 : 20;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1156 if(off_t + 5 < beg_t) this.container.scrollTop(this.container.scrollTop() - (beg_t - off_t + 5) );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1157 if(off_t + h_cor > end_t) this.container.scrollTop(this.container.scrollTop() + (off_t + h_cor - end_t) );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1158 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1159 select_branch : function (obj, multiple) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1160 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1161 if(!obj && this.hovered !== false) obj = this.hovered;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1162 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1163 obj = _this.get_node(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1164 if(!obj.size()) return this.error("SELECT: NOT A VALID NODE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1165 obj.children("a").removeClass("hover");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1166 // CHECK AGAINST RULES FOR SELECTABLE NODES
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1167 if(!_this.check("clickable", obj)) return this.error("SELECT: NODE NOT SELECTABLE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1168 if(_this.settings.callback.beforechange.call(null,obj.get(0),_this) === false) return this.error("SELECT: STOPPED BY USER");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1169 // IF multiple AND obj IS ALREADY SELECTED - DESELECT IT
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1170 if(this.settings.rules.multiple != false && multiple && obj.children("a.clicked").size() > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1171 return this.deselect_branch(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1172 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1173 if(this.settings.rules.multiple != false && multiple) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1174 this.selected_arr.push(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1175 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1176 if(this.settings.rules.multiple != false && !multiple) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1177 for(var i in this.selected_arr) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1178 this.selected_arr[i].children("A").removeClass("clicked");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1179 this.settings.callback.ondeselect.call(null, this.selected_arr[i].get(0), _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1180 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1181 this.selected_arr = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1182 this.selected_arr.push(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1183 if(this.selected && this.selected.children("A").hasClass("clicked")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1184 this.selected.children("A").removeClass("clicked");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1185 this.settings.callback.ondeselect.call(null, this.selected.get(0), _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1186 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1187 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1188 if(!this.settings.rules.multiple) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1189 if(this.selected) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1190 this.selected.children("A").removeClass("clicked");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1191 this.settings.callback.ondeselect.call(null, this.selected.get(0), _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1192 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1193 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1194 // SAVE NEWLY SELECTED
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1195 this.selected = obj;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1196 if(this.settings.ui.hover_mode && this.hovered !== false) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1197 this.hovered.children("A").removeClass("hover");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1198 this.hovered = obj;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1199 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1200
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1201 // FOCUS NEW NODE AND OPEN ALL PARENT NODES IF CLOSED
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1202 this.selected.children("a").removeClass("clicked").addClass("clicked").end().parents("li.closed").each( function () { _this.open_branch(this, true); });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1203
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1204 // SCROLL SELECTED NODE INTO VIEW
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1205 var off_t = this.selected.offset().top;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1206 var beg_t = this.container.offset().top;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1207 var end_t = beg_t + this.container.height();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1208 var h_cor = (this.container.get(0).scrollWidth > this.container.width()) ? 40 : 20;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1209 if(off_t + 5 < beg_t) this.container.scrollTop(this.container.scrollTop() - (beg_t - off_t + 5) );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1210 if(off_t + h_cor > end_t) this.container.scrollTop(this.container.scrollTop() + (off_t + h_cor - end_t) );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1211
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1212 this.set_cookie("selected");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1213 this.settings.callback.onselect.call(null, this.selected.get(0), _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1214 this.settings.callback.onchange.call(null, this.selected.get(0), _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1215 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1216 deselect_branch : function (obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1217 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1218 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1219 var obj = this.get_node(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1220 obj.children("a").removeClass("clicked");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1221 this.settings.callback.ondeselect.call(null, obj.get(0), _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1222 if(this.settings.rules.multiple != false && this.selected_arr.length > 1) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1223 this.selected_arr = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1224 this.container.find("a.clicked").filter(":first-child").parent().each(function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1225 _this.selected_arr.push($(this));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1226 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1227 if(obj.get(0) == this.selected.get(0)) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1228 this.selected = this.selected_arr[0];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1229 this.set_cookie("selected");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1230 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1231 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1232 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1233 if(this.settings.rules.multiple != false) this.selected_arr = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1234 this.selected = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1235 this.set_cookie("selected");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1236 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1237 if(this.selected) this.settings.callback.onchange.call(null, this.selected.get(0), _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1238 else this.settings.callback.onchange.call(null, false, _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1239 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1240 toggle_branch : function (obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1241 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1242 var obj = this.get_node(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1243 if(obj.hasClass("closed")) return this.open_branch(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1244 if(obj.hasClass("open")) return this.close_branch(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1245 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1246 open_branch : function (obj, disable_animation, callback) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1247 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1248 var obj = this.get_node(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1249 if(!obj.size()) return this.error("OPEN: NO SUCH NODE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1250 if(obj.hasClass("leaf")) return this.error("OPEN: OPENING LEAF NODE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1251
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1252 if(this.settings.data.async && obj.find("li").size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1253 if(this.settings.callback.beforeopen.call(null,obj.get(0),this) === false) return this.error("OPEN: STOPPED BY USER");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1254 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1255 obj.children("ul:eq(0)").remove().end().append("<ul><li class='last'><a class='loading' href='#'>" + (_this.settings.lang.loading || "Loading ...") + "</a></li></ul>");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1256 obj.removeClass("closed").addClass("open");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1257 if(this.settings.data.type == "xml_flat" || this.settings.data.type == "xml_nested") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1258 var xsl = (this.settings.data.type == "xml_flat") ? "flat.xsl" : "nested.xsl";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1259 obj.children("ul:eq(0)").getTransform(this.path + xsl, this.settings.data.url, { params : { theme_path : _this.theme }, meth : this.settings.data.method, dat : this.settings.data.async_data(obj), repl : true, callback: function (str, json) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1260 if(str.length < 15) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1261 obj.removeClass("closed").removeClass("open").addClass("leaf").children("ul").remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1262 if(callback) callback.call();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1263 return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1264 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1265 _this.open_branch.apply(_this, [obj]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1266 if(callback) callback.call();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1267 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1268 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1269 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1270 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1271 $.ajax({
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1272 type : this.settings.data.method,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1273 url : this.settings.data.url,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1274 data : this.settings.data.async_data(obj),
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1275 dataType : "json",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1276 success : function (data, textStatus) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1277 if(!data || data.length == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1278 obj.removeClass("closed").removeClass("open").addClass("leaf").children("ul").remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1279 if(callback) callback.call();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1280 return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1281 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1282 var str = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1283 if(data.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1284 for(var i = 0; i < data.length; i++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1285 str += _this.parseJSON(data[i]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1286 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1287 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1288 else str = _this.parseJSON(data);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1289 if(str.length > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1290 obj.children("ul:eq(0)").replaceWith("<ul>" + str + "</ul>");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1291 obj.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1292 obj.find("li").not(".open").not(".closed").addClass("leaf");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1293 _this.open_branch.apply(_this, [obj]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1294 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1295 else obj.removeClass("closed").removeClass("open").addClass("leaf").children("ul").remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1296 if(callback) callback.call();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1297 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1298 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1299 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1300 return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1301 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1302 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1303 if(!this.settings.data.async) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1304 if(this.settings.callback.beforeopen.call(null,obj.get(0),this) === false) return this.error("OPEN: STOPPED BY USER");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1305 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1306 if(parseInt(this.settings.ui.animation) > 0 && !disable_animation ) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1307 obj.children("ul:eq(0)").css("display","none");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1308 obj.removeClass("closed").addClass("open");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1309 obj.children("ul:eq(0)").slideDown(parseInt(this.settings.ui.animation), function() {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1310 $(this).css("display","");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1311 if(callback) callback.call();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1312 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1313 } else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1314 obj.removeClass("closed").addClass("open");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1315 if(callback) callback.call();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1316 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1317 this.set_cookie("open");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1318 this.settings.callback.onopen.call(null, obj.get(0), this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1319 return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1320 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1321 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1322 close_branch : function (obj, disable_animation) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1323 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1324 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1325 var obj = this.get_node(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1326 if(!obj.size()) return this.error("CLOSE: NO SUCH NODE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1327 if(_this.settings.callback.beforeclose.call(null,obj.get(0),_this) === false) return this.error("CLOSE: STOPPED BY USER");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1328 if(parseInt(this.settings.ui.animation) > 0 && !disable_animation && obj.children("ul:eq(0)").size() == 1) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1329 obj.children("ul:eq(0)").slideUp(parseInt(this.settings.ui.animation), function() {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1330 obj.removeClass("open").addClass("closed");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1331 _this.set_cookie("open");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1332 $(this).css("display","");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1333 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1334 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1335 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1336 obj.removeClass("open").addClass("closed");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1337 this.set_cookie("open");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1338 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1339 if(this.selected && obj.children("ul:eq(0)").find("a.clicked").size() > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1340 obj.find("li:has(a.clicked)").each(function() {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1341 _this.deselect_branch(this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1342 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1343 if(obj.children("a.clicked").size() == 0) this.select_branch(obj, (this.settings.rules.multiple != false && this.selected_arr.length > 0) );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1344 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1345 this.settings.callback.onclose.call(null, obj.get(0), this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1346 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1347 open_all : function (obj, callback) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1348 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1349 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1350 obj = obj ? $(obj) : this.container;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1351
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1352 var s = obj.find("li.closed").size();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1353 if(!callback) this.cl_count = 0;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1354 else this.cl_count --;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1355 if(s > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1356 this.cl_count += s;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1357 obj.find("li.closed").each( function () { var __this = this; _this.open_branch.apply(_this, [this, true, function() { _this.open_all.apply(_this, [__this, true]); } ]); });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1358 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1359 else if(this.cl_count == 0) this.settings.callback.onopen_all.call(null,this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1360 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1361 close_all : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1362 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1363 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1364 this.container.find("li.open").each( function () { _this.close_branch(this, true); });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1365 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1366 show_lang : function (i) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1367 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1368 if(this.settings.languages[i] == this.current_lang) return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1369 var st = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1370 var id = this.container.attr("id") ? "#" + this.container.attr("id") : ".tree";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1371 st = get_css(id + " ." + this.current_lang, this.sn);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1372 if(st !== false) st.style.display = "none";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1373 st = get_css(id + " ." + this.settings.languages[i], this.sn);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1374 if(st !== false) st.style.display = "block";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1375 this.current_lang = this.settings.languages[i];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1376 return true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1377 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1378 cycle_lang : function() {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1379 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1380 var i = $.inArray(this.current_lang, this.settings.languages);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1381 i ++;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1382 if(i > this.settings.languages.length - 1) i = 0;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1383 this.show_lang(i);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1384 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1385 create : function (type, obj, data, icon, id, position) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1386 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1387 // NOTHING SELECTED
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1388 obj = obj ? this.get_node(obj) : this.selected;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1389 if(!obj || !obj.size()) return this.error("CREATE: NO NODE SELECTED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1390 if(!this.check("creatable", obj)) return this.error("CREATE: CANNOT CREATE IN NODE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1391
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1392 var t = type || this.get_type(obj) || "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1393 if(this.settings.rules.use_inline && this.settings.rules.metadata) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1394 $.metadata.setType("attr", this.settings.rules.metadata);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1395 if(typeof obj.metadata()["valid_children"] != "undefined") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1396 if($.inArray(t, obj.metadata()["valid_children"]) == -1) return this.error("CREATE: NODE NOT A VALID CHILD");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1397 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1398 if(typeof obj.metadata()["max_children"] != "undefined") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1399 if( (obj.children("ul:eq(0)").children("li").size() + 1) > obj.metadata().max_children) return this.error("CREATE: MAX_CHILDREN REACHED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1400 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1401 var ok = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1402 obj.parents("li").each(function(i) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1403 if($(this).metadata().max_depth) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1404 if( (i + 1) >= $(this).metadata().max_depth) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1405 ok = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1406 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1407 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1408 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1409 if(!ok) return this.error("CREATE: MAX_DEPTH REACHED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1410 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1411 if(obj.hasClass("closed")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1412 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1413 return this.open_branch(obj, true, function () { _this.create.apply(_this, [type, obj, data, icon, id]); } );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1414 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1415
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1416 if(id) $li = $("<li id='" + id + "' />");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1417 else $li = $("<li />");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1418 // NEW NODE IS OF PASSED TYPE OR PARENT'S TYPE
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1419 if(this.settings.rules.metadata) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1420 $.metadata.setType("attr", this.settings.rules.metadata);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1421 $li.attr(this.settings.rules.metadata, "type: '" + t + "'");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1422 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1423 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1424 $li.attr(this.settings.rules.type_attr, t)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1425 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1426
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1427 var icn = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1428 if((typeof icon).toLowerCase() == "string") {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1429 icn = icon;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1430 icn = icn.indexOf("/") == -1 ? this.theme + icn : icn;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1431 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1432 if(this.settings.languages.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1433 for(var i = 0; i < this.settings.languages.length; i++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1434 if((typeof data).toLowerCase() == "string") val = data;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1435 else if(data && data[i]) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1436 val = data[i];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1437 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1438 else if(this.settings.lang.new_node) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1439 if((typeof this.settings.lang.new_node).toLowerCase() != "string" && this.settings.lang.new_node[i])
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1440 val = this.settings.lang.new_node[i];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1441 else
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1442 val = this.settings.lang.new_node;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1443 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1444 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1445 val = "New folder";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1446 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1447 if((typeof icon).toLowerCase() != "string" && icon && icon[i]) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1448 icn = icon[i];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1449 icn = icn.indexOf("/") == -1 ? this.theme + icn : icn;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1450 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1451 $li.append("<a href='#'" + ( icn.length ? " style='background-image:url(\"" + icn + "\");' " : " ") + "class='" + this.settings.languages[i] + "'>" + val + "</a>");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1452 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1453 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1454 else { $li.append("<a href='#'" + ( icn.length ? " style='background-image:url(\"" + icn + "\");' " : " ") + ">" + (data || this.settings.lang.new_node || "New folder") + "</a>"); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1455 $li.addClass("leaf");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1456 if(this.settings.rules.createat == "top" || obj.children("ul").size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1457 this.moved($li,obj.children("a:eq(0)"),"inside", true);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1458 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1459 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1460 this.moved($li,obj.children("ul:eq(0)").children("li:last").children("a:eq(0)"),"after",true);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1461 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1462 this.select_branch($li.children("a:eq(0)"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1463 if(!data) this.rename();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1464 return $li;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1465 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1466 rename : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1467 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1468 if(this.selected) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1469 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1470 if(!this.check("renameable", this.selected)) return this.error("RENAME: NODE NOT RENAMABLE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1471 if(!this.settings.callback.beforerename.call(null,this.selected.get(0), _this.current_lang, _this)) return this.error("RENAME: STOPPED BY USER");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1472 var obj = this.selected;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1473 if(this.current_lang) obj = obj.find("a." + this.current_lang).get(0);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1474 else obj = obj.find("a:first").get(0);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1475 last_value = obj.innerHTML;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1476 _this.inp = $("<input type='text' />");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1477 _this.inp
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1478 .val(last_value)
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1479 .bind("mousedown", function (event) { event.stopPropagation(); })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1480 .bind("mouseup", function (event) { event.stopPropagation(); })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1481 .bind("click", function (event) { event.stopPropagation(); })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1482 .bind("keyup", function (event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1483 var key = event.keyCode || event.which;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1484 if(key == 27) { this.value = last_value; this.blur(); return }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1485 if(key == 13) { this.blur(); return }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1486 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1487 _this.inp.blur(function(event) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1488 if(this.value == "") this.value == last_value;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1489 $(obj).html( $(obj).parent().find("input").eq(0).attr("value") ).get(0).style.display = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1490 $(obj).prevAll("span").remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1491 if(this.value != last_value) _this.settings.callback.onrename.call(null, _this.get_node(obj).get(0), _this.current_lang, _this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1492 _this.inp = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1493 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1494 var spn = $("<span />").addClass(obj.className).append(_this.inp);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1495 spn.attr("style", $(obj).attr("style"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1496 obj.style.display = "none";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1497 $(obj).parent().prepend(spn);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1498 _this.inp.get(0).focus();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1499 _this.inp.get(0).select();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1500 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1501 else return this.error("RENAME: NO NODE SELECTED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1502 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1503 // REMOVE NODES
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1504 remove : function(obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1505 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1506 if(obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1507 obj = this.get_node(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1508 if(obj.size()) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1509 if(!this.check("deletable", obj)) return this.error("DELETE: NODE NOT DELETABLE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1510 if(!this.settings.callback.beforedelete.call(null,obj.get(0), _this)) return this.error("DELETE: STOPPED BY USER");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1511 $parent = obj.parent();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1512 obj = obj.remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1513 $parent.children("li:last").addClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1514 if($parent.children("li").size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1515 $li = $parent.parents("li:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1516 $li.removeClass("open").removeClass("closed").addClass("leaf").children("ul").remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1517 this.set_cookie("open");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1518 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1519 this.settings.callback.ondelete.call(null, obj, this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1520 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1521 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1522 else if(this.selected) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1523 if(!this.check("deletable", this.selected)) return this.error("DELETE: NODE NOT DELETABLE");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1524 if(!this.settings.callback.beforedelete.call(null,this.selected.get(0), _this)) return this.error("DELETE: STOPPED BY USER");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1525 $parent = this.selected.parent();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1526 var obj = this.selected;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1527 if(this.settings.rules.multiple == false || this.selected_arr.length == 1) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1528 var stop = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1529 var tmp = (this.selected.prev("li:eq(0)").size()) ? this.selected.prev("li:eq(0)") : this.selected.parents("li:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1530 // this.get_prev(true);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1531 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1532 obj = obj.remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1533 $parent.children("li:last").addClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1534 if($parent.children("li").size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1535 $li = $parent.parents("li:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1536 $li.removeClass("open").removeClass("closed").addClass("leaf").children("ul").remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1537 this.set_cookie("open");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1538 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1539 //this.selected = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1540 this.settings.callback.ondelete.call(null, obj, this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1541 if(stop && tmp) this.select_branch(tmp);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1542 if(this.settings.rules.multiple != false && !stop) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1543 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1544 this.selected_arr = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1545 this.container.find("a.clicked").filter(":first-child").parent().each(function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1546 _this.selected_arr.push($(this));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1547 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1548 if(this.selected_arr.length > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1549 this.selected = this.selected_arr[0];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1550 this.remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1551 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1552 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1553 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1554 else return this.error("DELETE: NO NODE SELECTED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1555 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1556 // FOR EXPLORER-LIKE KEYBOARD SHORTCUTS
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1557 get_next : function(force) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1558 var obj = this.hovered || this.selected;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1559 if(obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1560 if(obj.hasClass("open")) return force ? this.select_branch(obj.find("li:eq(0)")) : this.hover_branch(obj.find("li:eq(0)"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1561 else if($(obj).nextAll("li").size() > 0) return force ? this.select_branch(obj.nextAll("li:eq(0)")) : this.hover_branch(obj.nextAll("li:eq(0)"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1562 else return force ? this.select_branch(obj.parents("li").next("li").eq(0)) : this.hover_branch(obj.parents("li").next("li").eq(0));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1563 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1564 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1565 get_prev : function(force) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1566 var obj = this.hovered || this.selected;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1567 if(obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1568 if(obj.prev("li").size()) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1569 var obj = obj.prev("li").eq(0);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1570 while(obj.hasClass("open")) obj = obj.children("ul:eq(0)").children("li:last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1571 return force ? this.select_branch(obj) : this.hover_branch(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1572 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1573 else { return force ? this.select_branch(obj.parents("li:eq(0)")) : this.hover_branch(obj.parents("li:eq(0)")); }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1574 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1575 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1576 get_left : function(force, rtl) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1577 if(this.settings.ui.rtl && !rtl) return this.get_right(force, true);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1578 var obj = this.hovered || this.selected;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1579 if(obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1580 if(obj.hasClass("open")) this.close_branch(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1581 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1582 return force ? this.select_branch(obj.parents("li:eq(0)")) : this.hover_branch(obj.parents("li:eq(0)"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1583 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1584 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1585 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1586 get_right : function(force, rtl) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1587 if(this.settings.ui.rtl && !rtl) return this.get_left(force, true);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1588 var obj = this.hovered || this.selected;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1589 if(obj) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1590 if(obj.hasClass("closed")) this.open_branch(obj);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1591 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1592 return force ? this.select_branch(obj.find("li:eq(0)")) : this.hover_branch(obj.find("li:eq(0)"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1593 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1594 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1595 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1596 toggleDots : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1597 this.container.toggleClass("no_dots");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1598 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1599 set_cookie : function (type) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1600 if(this.settings.cookies === false) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1601 if(this.settings.cookies[type] === false) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1602 switch(type) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1603 case "selected":
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1604 if(this.settings.rules.multiple != false && this.selected_arr.length > 1) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1605 var val = Array();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1606 $.each(this.selected_arr, function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1607 val.push(this.attr("id"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1608 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1609 val = val.join(",");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1610 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1611 else var val = this.selected ? this.selected.attr("id") : false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1612 $.cookie(this.settings.cookies.prefix + '_selected',val,this.settings.cookies.opts);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1613 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1614 case "open":
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1615 var str = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1616 this.container.find("li.open").each(function (i) { str += this.id + ","; });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1617 $.cookie(this.settings.cookies.prefix + '_open',str.replace(/,$/ig,""),this.settings.cookies.opts);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1618 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1619 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1620 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1621 moved : function (what, where, how, is_new, is_copy) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1622 var what = $(what);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1623 var $parent = $(what).parents("ul:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1624 var $where = $(where);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1625 // IF MULTIPLE
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1626 if(what.size() > 1) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1627 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1628 var tmp = this.moved(what.eq(0),where,how, false, is_copy);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1629 what.each(function (i) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1630 if(i == 0) return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1631 tmp = _this.moved(this, tmp.children("a:eq(0)"), "after", false, is_copy);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1632 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1633 return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1634 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1635 if(is_copy) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1636 _what = what.clone();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1637 _what.each(function (i) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1638 this.id = this.id + "_copy";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1639 $(this).find("li").each(function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1640 this.id = this.id + "_copy";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1641 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1642 $(this).removeClass("dragged").find("a.clicked").removeClass("clicked").end().find("li.dragged").removeClass("dragged");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1643 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1644 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1645 else _what = what;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1646 if(is_new) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1647 if(!this.settings.callback.beforecreate.call(null,this.get_node(what).get(0), this.get_node(where).get(0),how,this)) return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1648 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1649 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1650 if(!this.settings.callback.beforemove.call(null,this.get_node(what).get(0), this.get_node(where).get(0),how,this)) return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1651 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1652
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1653 if(!is_new) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1654 var tmp = what.parents(".tree:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1655 // if different trees
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1656 if(tmp.get(0) != this.container.get(0)) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1657 tmp = tree_component.inst[tmp.attr("id")];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1658 // if there are languages - otherwise - no cleanup needed
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1659 if(tmp.settings.languages.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1660 var res = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1661 // if new tree has no languages - use current visible
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1662 if(this.settings.languages.length == 0) res.push("." + tmp.current_lang);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1663 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1664 for(var i in this.settings.languages) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1665 for(var j in tmp.settings.languages) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1666 if(this.settings.languages[i] == tmp.settings.languages[j]) res.push("." + this.settings.languages[i]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1667 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1668 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1669 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1670 if(res.length == 0) return this.error("MOVE: NO COMMON LANGUAGES");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1671 what.find("a").not(res.join(",")).remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1672 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1673 what.find("a.clicked").removeClass("clicked");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1674 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1675 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1676 what = _what;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1677
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1678 // ADD NODE TO NEW PLACE
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1679 switch(how) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1680 case "before":
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1681 $where.parents("ul:eq(0)").children("li.last").removeClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1682 $where.parent().before(what.removeClass("last"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1683 $where.parents("ul:eq(0)").children("li:last").addClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1684 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1685 case "after":
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1686 $where.parents("ul:eq(0)").children("li.last").removeClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1687 $where.parent().after(what.removeClass("last"));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1688 $where.parents("ul:eq(0)").children("li:last").addClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1689 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1690 case "inside":
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1691 if(this.settings.data.async) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1692 var obj = this.get_node($where);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1693 if(obj.hasClass("closed")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1694 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1695 return this.open_branch(obj, true, function () { _this.moved.apply(_this, [what, where, how, is_new, is_copy]); })
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1696 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1697 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1698 if($where.parent().children("ul:first").size()) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1699 if(this.settings.rules.createat == "top") $where.parent().children("ul:first").prepend(what.removeClass("last")).children("li:last").addClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1700 else $where.parent().children("ul:first").children(".last").removeClass("last").end().append(what.removeClass("last")).children("li:last").addClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1701 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1702 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1703 what.addClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1704 $where.parent().append("<ul/>").removeClass("leaf").addClass("closed");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1705 $where.parent().children("ul:first").prepend(what);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1706 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1707 if(!this.settings.data.async) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1708 this.open_branch($where);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1709 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1710 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1711 default:
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1712 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1713 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1714 // CLEANUP OLD PARENT
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1715 if($parent.find("li").size() == 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1716 var $li = $parent.parent();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1717 $li.removeClass("open").removeClass("closed").addClass("leaf").children("ul").remove();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1718 $li.parents("ul:eq(0)").children("li.last").removeClass("last").end().children("li:last").addClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1719 this.set_cookie("open");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1720 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1721 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1722 $parent.children("li.last").removeClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1723 $parent.children("li:last").addClass("last");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1724 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1725 if(is_new && how != "inside") where = this.get_node(where).parents("li:eq(0)");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1726 if(is_copy) this.settings.callback.oncopy.call(null, this.get_node(what).get(0), this.get_node(where).get(0), how, this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1727 else if(is_new) this.settings.callback.oncreate.call(null, this.get_node(what).get(0), this.get_node(where).get(0), this.settings.rules.createat, this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1728 else this.settings.callback.onmove.call(null, this.get_node(what).get(0), this.get_node(where).get(0), how, this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1729 return what;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1730 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1731 error : function (code) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1732 this.settings.callback.error.call(null,code,this);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1733 return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1734 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1735 lock : function (state) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1736 this.locked = state;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1737 if(this.locked) this.container.addClass("locked");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1738 else this.container.removeClass("locked");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1739 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1740 cut : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1741 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1742 if(!this.selected) return this.error("CUT: NO NODE SELECTED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1743 this.copy_nodes = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1744 this.cut_nodes = this.container.find("a.clicked").filter(":first-child").parent();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1745 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1746 copy : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1747 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1748 if(!this.selected) return this.error("COPY: NO NODE SELECTED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1749 this.copy_nodes = this.container.find("a.clicked").filter(":first-child").parent();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1750 this.cut_nodes = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1751 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1752 paste : function () {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1753 if(this.locked) return this.error("LOCKED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1754 if(!this.selected) return this.error("PASTE: NO NODE SELECTED");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1755 if(!this.copy_nodes && !this.cut_nodes) return this.error("PASTE: NOTHING TO DO");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1756 if(this.copy_nodes && this.copy_nodes.size()) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1757 if(!this.checkMove(this.copy_nodes, this.selected.children("a:eq(0)"), "inside")) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1758 this.moved(this.copy_nodes, this.selected.children("a:eq(0)"), "inside", false, true);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1759 this.copy_nodes = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1760 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1761 if(this.cut_nodes && this.cut_nodes.size()) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1762 if(!this.checkMove(this.cut_nodes, this.selected.children("a:eq(0)"), "inside")) return false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1763 this.moved(this.cut_nodes, this.selected.children("a:eq(0)"), "inside");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1764 this.cut_nodes = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1765 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1766 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1767 search : function(str) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1768 var _this = this;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1769 if(!str || (this.srch && str != this.srch) ) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1770 this.srch = "";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1771 this.srch_opn = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1772 this.container.find("a.search").removeClass("search");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1773 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1774 this.srch = str;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1775 if(!str) return;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1776 if(this.settings.data.async) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1777 if(!this.srch_opn) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1778 var dd = $.extend( { "search" : str } , this.settings.data.async_data(false) );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1779 $.ajax({
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1780 type : this.settings.data.method,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1781 url : this.settings.data.url,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1782 data : dd,
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1783 dataType : "text",
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1784 success : function (data) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1785 _this.srch_opn = $.unique(data.split(","));
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1786 _this.search.apply(_this,[str]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1787 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1788 });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1789 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1790 else if(this.srch_opn.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1791 if(this.srch_opn && this.srch_opn.length) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1792 var opn = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1793 for(var j = 0; j < this.srch_opn.length; j++) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1794 if(this.get_node("#" + this.srch_opn[j]).size() > 0) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1795 opn = true;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1796 var tmp = "#" + this.srch_opn[j];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1797 delete this.srch_opn[j];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1798 this.open_branch(tmp, true, function () { _this.search.apply(_this,[str]); } );
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1799 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1800 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1801 if(!opn) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1802 this.srch_opn = [];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1803 _this.search.apply(_this,[str]);
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1804 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1805 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1806 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1807 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1808 var selector = "a";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1809 // IF LANGUAGE VERSIONS
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1810 if(this.settings.languages.length) selector += "." + this.current_lang;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1811 this.container.find(selector + ":contains('" + str + "')").addClass("search");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1812 this.srch_opn = false;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1813 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1814 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1815 else {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1816 var selector = "a";
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1817 // IF LANGUAGE VERSIONS
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1818 if(this.settings.languages.length) selector += "." + this.current_lang;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1819 this.container.find(selector + ":contains('" + str + "')").addClass("search").parents("li.closed").each( function () { _this.open_branch(this, true); });
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1820 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1821 },
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1822
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1823 destroy : function() {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1824 this.container.unbind().find("li").die().find("a").die();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1825 this.container.removeClass("tree").children("ul").removeClass("tree-" + this.settings.ui.theme_name).find("li").removeClass("leaf").removeClass("open").removeClass("closed").removeClass("last").children("a").removeClass("clicked");
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1826
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1827 if(this.cntr == tree_component.focused) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1828 for(var i in tree_component.inst) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1829 if(i != this.cntr && i != this.container.attr("id")) {
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1830 tree_component.inst[i].focus();
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1831 break;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1832 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1833 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1834 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1835 delete tree_component.inst[this.cntr];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1836 delete tree_component.inst[this.container.attr("id")];
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1837 tree_component.cntr --;
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1838 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1839 }
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1840 };
4350aa369149 Use jQuery UI components.
wycc
parents:
diff changeset
1841 })(jQuery);