Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 1e3cc27

Browse files
committed
ENH: Refs #223. Optimized the indentation related codes.
1 parent 1483130 commit 1e3cc27

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

core/public/js/layout/jquery.treeTable.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
childPrefix: "child-of-",
4646
clickableNodeNames: true,
4747
expandable: true,
48-
indent: 19,
48+
indent: 7,
4949
initialState: "collapsed",
5050
treeColumn: 0
5151
};
@@ -203,22 +203,13 @@
203203
// 3: +node+ should not be inserted as a child of +node+ itself.
204204

205205
if($.inArray(node[0].id, ancestorNames) == -1 && (!parent || (destination.id != parent[0].id)) && destination.id != node[0].id) {
206-
206+
indent(node, ancestorsOf(node).length * options.indent * -1); // Remove indentation
207+
207208
if(parent) {node.removeClass(options.childPrefix + parent[0].id);}
208209

209210
node.addClass(options.childPrefix + destination.id);
210211
move(node, destination); // Recursively move nodes to new location
211-
// adjust node's padding'
212-
var cell = $($(destination).children("td")[options.treeColumn]);
213-
var padding = getPaddingLeft(cell) + options.indent;
214-
node.children("td:first")[options.treeColumn].style.paddingLeft = (padding-12) + "px";
215-
// adust node's children's padding'
216-
var childPaddingLeft = padding - 12 + options.indent;
217-
var arrayCell=childrenOf(node);
218-
if(arrayCell==null)return;
219-
arrayCell.each(function(){
220-
$(this).children("td:first")[options.treeColumn].style.paddingLeft = (childPaddingLeft-12) + "px";
221-
});
212+
indent(node, ancestorsOf(node).length * options.indent);
222213
}
223214

224215
return this;
@@ -268,14 +259,14 @@
268259
}
269260

270261
function indent(node, value) {
271-
var cell = $(node.children("td:first")[options.treeColumn]);
262+
var cell = $(node.children("td")[options.treeColumn]);
272263
cell[0].style.paddingLeft = getPaddingLeft(cell) + value + "px";
273264

274265
childrenOf(node).each(function() {
275266
indent($(this), value);
276267
});
277268
};
278-
269+
279270
function initEvent()
280271
{
281272
// Make visible that a row is clicked
@@ -440,11 +431,11 @@
440431
arrayCell.each(function() {
441432
if(first)
442433
{
443-
$(this).children("td:first")[options.treeColumn].style.paddingLeft = (padding-12) + "px";
434+
$(this).children("td:first")[options.treeColumn].style.paddingLeft = padding + "px";
444435
}
445436
else
446437
{
447-
$(this).children("td:first")[options.treeColumn].style.paddingLeft = (padding-12) + "px";
438+
$(this).children("td:first")[options.treeColumn].style.paddingLeft = padding + "px";
448439
}
449440
if(node.hasClass('expanded'))
450441
{
@@ -491,11 +482,11 @@
491482
var padding = getPaddingLeft(cell) + options.indent;
492483

493484
childNodes.each(function() {
494-
$(this).children("td:first")[options.treeColumn].style.paddingLeft = (padding-12) + "px";
485+
$(this).children("td:first")[options.treeColumn].style.paddingLeft = padding + "px";
495486
});
496487

497488
if(options.expandable) {
498-
cell.prepend('<span style="margin-left: -' + options.indent + 'px; padding-left: ' + options.indent + 'px" class="expander"></span>');
489+
cell.prepend('<span style="margin-left: -' + (options.indent+12) + 'px; padding-left: ' + (options.indent+12) + 'px" class="expander"></span>');
499490
$(cell[0].firstChild).click(function() {node.toggleBranch();});
500491

501492
if(options.clickableNodeNames) {

0 commit comments

Comments
 (0)