![]() |
![]() |
|
|
|
|
Sweet! Thanks a bunchness.
I didn't know you where a js coder. Better not give me your phone number. LOLI was looking at the wrong function. ![]() I changed Code:
this.root.id + 1 Code:
this.root.id + 2 Thanks again. Jump ![]() ![]() |
||
|
__________________
Currently working hard to break the server... >> Help support JSR through our Amazon store |
||
|
|
||
| Sponsored Links |
|
|
|
|
|
|
Quote:
Quote:
|
|||
|
|
||
|
|
|
You know.. that + 2 thing just doesn't sit well with me. Mostly because it won't work if you tried to put commodities down on the bottom, for example. That only works because commodities is the first category. It would also stop working if you added more siblings to "Ingredients" down in the equipment list. I'm finishing up a little rewrite as we speak because otherwise I wouldn't be able to sleep tonight :P Basically I wrote a function to figure out the level of the current node (as an integer) and then the if statement can check that value to decide whether or not to close other branches. That way your solrain_core.js (or whatever other file is using dtree.js) can set the level to go down to as a configuration option.
|
||
|
|
||
|
|
|
Ok got it. First thing to do is paste this in as a new function. I put it right above the dTree.prototype.o function declaration just cause it was near where I was working that way. The new function returns the tree level of the node id you give it. Mmmmmm recursion. The Solrain Core node is level 0, then commodities/capacitors/etc are level 1, and so on.
Code:
dTree.prototype.getNodeLevel = function(id) {
if(this.aNodes[id].pid > -1) {
return 1 + this.getNodeLevel(this.aNodes[id].pid);
} else {
return 0;
}
};
Code:
// Toggle Open or close
dTree.prototype.o = function(id) {
var cn = this.aNodes[id];
this.nodeStatus(!cn._io, id, cn._ls);
cn._io = !cn._io;
if (this.config.closeSameLevel) {
if (this.getNodeLevel(id) <= this.config.maxCollapseLevel) {
this.closeLevel(cn);
}
}
if (this.config.useCookies) this.updateCookie();
};
Code:
// Tree object
function dTree(objName) {
this.config = {
target : null,
folderLinks : true,
useSelection : true,
useCookies : true,
useLines : true,
useIcons : true,
useStatusText : false,
closeSameLevel : false,
inOrder : false,
maxCollapseLevel :3
}
Code:
d = new dTree('d');
d.config.closeSameLevel=true;
d.config.folderLinks=false;
d.config.inOrder=true;
d.config.maxCollapseLevel=3;
blahblah adding nodes.
If you already have all of those created and don't feel like messing with that whole thing then just replace the this.config.maxCollapseLevel in the if statement under the o function with an integer. 3 in this case. After all of that stuff the tree will collapse all sibling nodes whenever you click on a node if the node you clicked on is level 3 or lower. Whew. I'll be able to sleep. |
||
|
|
||
|
|
|
Quote:
Now I need to get to work on better tree graphics that fit Jumpgate better. *looks around for fluid.* ![]() |
||
|
|
||
|
|
|
Sorta nitpicky... but you might want to change one little thing. I'm not even sure if the tree would work properly if for some reason the nodes you added didn't get set up with the first node you add being id = 0 with pid = -1. If for some reason your first node was id=1 with pid=0 or some other weird thing, the getNodeLevel function would stop working correctly. Just change the -1 in the if statement to this.root.id
Code:
dTree.prototype.getNodeLevel = function(id) {
if(this.aNodes[id].pid > this.root.id) {
return 1 + this.getNodeLevel(this.aNodes[id].pid);
} else {
return 0;
}
};
![]() Of course we still have to assume that no matter where the id starts it always gets greater as you add nodes. You couldn't have a node with an id less than the root's pid. Just gonna have to assume that. The line must be drawn somewhere. |
||
|
|
||