1 |
85ad3d82
|
Assos Assos
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
(function($) {
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
var options;
|
14 |
|
|
var defaultPaddingLeft;
|
15 |
|
|
|
16 |
|
|
$.fn.treeTable = function(opts) {
|
17 |
|
|
options = $.extend({}, $.fn.treeTable.defaults, opts);
|
18 |
|
|
|
19 |
|
|
return this.each(function() {
|
20 |
|
|
$(this).addClass("treeTable").find("tbody tr").each(function() {
|
21 |
|
|
|
22 |
|
|
if(!options.expandable || $(this)[0].className.search(options.childPrefix) == -1) {
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
if (isNaN(defaultPaddingLeft)) {
|
27 |
|
|
defaultPaddingLeft = parseInt($($(this).children("td")[options.treeColumn]).css('padding-left'), 10);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
initialize($(this));
|
31 |
|
|
} else if(options.initialState == "collapsed") {
|
32 |
|
|
this.style.display = "none";
|
33 |
|
|
}
|
34 |
|
|
});
|
35 |
|
|
});
|
36 |
|
|
};
|
37 |
|
|
|
38 |
|
|
$.fn.treeTable.defaults = {
|
39 |
|
|
childPrefix: "child-of-",
|
40 |
|
|
clickableNodeNames: false,
|
41 |
|
|
expandable: true,
|
42 |
|
|
indent: 19,
|
43 |
|
|
initialState: "collapsed",
|
44 |
|
|
treeColumn: 0
|
45 |
|
|
};
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
$.fn.collapse = function() {
|
49 |
|
|
$(this).addClass("collapsed");
|
50 |
|
|
|
51 |
|
|
childrenOf($(this)).each(function() {
|
52 |
|
|
if(!$(this).hasClass("collapsed")) {
|
53 |
|
|
$(this).collapse();
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
this.style.display = "none";
|
57 |
|
|
});
|
58 |
|
|
|
59 |
|
|
return this;
|
60 |
|
|
};
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
$.fn.expand = function() {
|
64 |
|
|
$(this).removeClass("collapsed").addClass("expanded");
|
65 |
|
|
|
66 |
|
|
childrenOf($(this)).each(function() {
|
67 |
|
|
initialize($(this));
|
68 |
|
|
|
69 |
|
|
if($(this).is(".expanded.parent")) {
|
70 |
|
|
$(this).expand();
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
$(this).show();
|
75 |
|
|
});
|
76 |
|
|
|
77 |
|
|
return this;
|
78 |
|
|
};
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
$.fn.reveal = function() {
|
82 |
|
|
$(ancestorsOf($(this)).reverse()).each(function() {
|
83 |
|
|
initialize($(this));
|
84 |
|
|
$(this).expand().show();
|
85 |
|
|
});
|
86 |
|
|
|
87 |
|
|
return this;
|
88 |
|
|
};
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
$.fn.appendBranchTo = function(destination) {
|
92 |
|
|
var node = $(this);
|
93 |
|
|
var parent = parentOf(node);
|
94 |
|
|
|
95 |
|
|
var ancestorNames = $.map(ancestorsOf($(destination)), function(a) { return a.id; });
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
if($.inArray(node[0].id, ancestorNames) == -1 && (!parent || (destination.id != parent[0].id)) && destination.id != node[0].id) {
|
105 |
|
|
indent(node, ancestorsOf(node).length * options.indent * -1);
|
106 |
|
|
|
107 |
|
|
if(parent) { node.removeClass(options.childPrefix + parent[0].id); }
|
108 |
|
|
|
109 |
|
|
node.addClass(options.childPrefix + destination.id);
|
110 |
|
|
move(node, destination);
|
111 |
|
|
indent(node, ancestorsOf(node).length * options.indent);
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
return this;
|
115 |
|
|
};
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
$.fn.reverse = function() {
|
119 |
|
|
return this.pushStack(this.get().reverse(), arguments);
|
120 |
|
|
};
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
$.fn.toggleBranch = function() {
|
124 |
|
|
if($(this).hasClass("collapsed")) {
|
125 |
|
|
$(this).expand();
|
126 |
|
|
} else {
|
127 |
|
|
$(this).removeClass("expanded").collapse();
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
return this;
|
131 |
|
|
};
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
function ancestorsOf(node) {
|
136 |
|
|
var ancestors = [];
|
137 |
|
|
while(node = parentOf(node)) {
|
138 |
|
|
ancestors[ancestors.length] = node[0];
|
139 |
|
|
}
|
140 |
|
|
return ancestors;
|
141 |
|
|
};
|
142 |
|
|
|
143 |
|
|
function childrenOf(node) {
|
144 |
|
|
return $(node).siblings("tr." + options.childPrefix + node[0].id);
|
145 |
|
|
};
|
146 |
|
|
|
147 |
|
|
function getPaddingLeft(node) {
|
148 |
|
|
var paddingLeft = parseInt(node[0].style.paddingLeft, 10);
|
149 |
|
|
return (isNaN(paddingLeft)) ? defaultPaddingLeft : paddingLeft;
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
function indent(node, value) {
|
153 |
|
|
var cell = $(node.children("td")[options.treeColumn]);
|
154 |
|
|
cell[0].style.paddingLeft = getPaddingLeft(cell) + value + "px";
|
155 |
|
|
|
156 |
|
|
childrenOf(node).each(function() {
|
157 |
|
|
indent($(this), value);
|
158 |
|
|
});
|
159 |
|
|
};
|
160 |
|
|
|
161 |
|
|
function initialize(node) {
|
162 |
|
|
if(!node.hasClass("initialized")) {
|
163 |
|
|
node.addClass("initialized");
|
164 |
|
|
|
165 |
|
|
var childNodes = childrenOf(node);
|
166 |
|
|
|
167 |
|
|
if(!node.hasClass("parent") && childNodes.length > 0) {
|
168 |
|
|
node.addClass("parent");
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
if(node.hasClass("parent")) {
|
172 |
|
|
var cell = $(node.children("td")[options.treeColumn]);
|
173 |
|
|
var padding = getPaddingLeft(cell) + options.indent;
|
174 |
|
|
|
175 |
|
|
childNodes.each(function() {
|
176 |
|
|
$(this).children("td")[options.treeColumn].style.paddingLeft = padding + "px";
|
177 |
|
|
});
|
178 |
|
|
|
179 |
|
|
if(options.expandable) {
|
180 |
|
|
cell.prepend('<span style="margin-left: -' + options.indent + 'px; padding-left: ' + options.indent + 'px" class="expander"></span>');
|
181 |
|
|
$(cell[0].firstChild).click(function() { node.toggleBranch(); });
|
182 |
|
|
|
183 |
|
|
if(options.clickableNodeNames) {
|
184 |
|
|
cell[0].style.cursor = "pointer";
|
185 |
|
|
$(cell).click(function(e) {
|
186 |
|
|
|
187 |
|
|
if (e.target.className != 'expander') {
|
188 |
|
|
node.toggleBranch();
|
189 |
|
|
}
|
190 |
|
|
});
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
if(!(node.hasClass("expanded") || node.hasClass("collapsed"))) {
|
195 |
|
|
node.addClass(options.initialState);
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
if(node.hasClass("expanded")) {
|
199 |
|
|
node.expand();
|
200 |
|
|
}
|
201 |
|
|
}
|
202 |
|
|
}
|
203 |
|
|
}
|
204 |
|
|
};
|
205 |
|
|
|
206 |
|
|
function move(node, destination) {
|
207 |
|
|
node.insertAfter(destination);
|
208 |
|
|
childrenOf(node).reverse().each(function() { move($(this), node[0]); });
|
209 |
|
|
};
|
210 |
|
|
|
211 |
|
|
function parentOf(node) {
|
212 |
|
|
var classNames = node[0].className.split(' ');
|
213 |
|
|
|
214 |
|
|
for(key in classNames) {
|
215 |
|
|
if(classNames[key].match(options.childPrefix)) {
|
216 |
|
|
return $(node).siblings("#" + classNames[key].substring(options.childPrefix.length));
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
};
|
220 |
|
|
})(jQuery); |