Board Logo

Toggling nodes and following link
TomCrawford - 11/17/2005 at 10:00 AM

I searched the forum for something relevant but couldn't find anything. I basically wanted to toggle a node when it was selected and also follow the html link for that node, even if the node was deselected (after toggling). I came up with the following, **I want to know if there is a better way that Tigra recommend**:

var TREE_ITEMS = [
['node1','index.html',{'myid':'4'},
['node2','index.html',{'myid':'14'}]],
['node3','index.html',{'myid':'14'}]
];

// styles deleted to save space but you'd need different styles for selected and normal
var TREE_TPL = {
'target' : '_self',
'onItemSelect' : 'id_selected'
};

function id_selected(o_item) {
var id = o_item.a_config[2]['myid'];

if ( o_item.n_state & 4 ) {
id = 0;
o_item.select(true); // Deselects node

// Can do something with the id here, I just set a cookie

document.location = o_item.a_config[1];
return false;
}

// I also set a cookie here

return true;
}


rock - 11/17/2005 at 10:50 AM

Try the following code:

Code:

/*
This function modifies tree behavior so nodes will open on single click and then follow the link assigned
Function should be called AS onItemSelect handler of the tree
*/

function onItemSelectHandler (o_item) {
// if node then toggle
if (o_item.a_config[3]) {
o_item.o_root.toggle(o_item.n_id);
}
// proceed to default handler
return true;
}


You could also call the handler on deselect event. Note if only single item could be selected, deselect event will be called automatically.


TomCrawford - 11/17/2005 at 12:50 PM

Taken from the Tree Menu Pro help doc:

toggle(n_id) : Toggles the open/close state of item having in a_index array index n_id. No value returned.

I don't want to change the open/close state; I wanted to change the selected state. Your solution doesn't deselect the node when it's selected.

Calling select(b_deselect) on the o_item results in too many recursions.

T


rock - 11/21/2005 at 12:38 PM

Please refer to our Customer Care System and submit there a ticket with required functionlity described in details


APSeabrook - 11/25/2005 at 02:10 AM

This is not an elegant solution but it seems to work.

/*
This function has been modified to display a frames page at the same time as expanding the menu.
*/

function onItemSelectHandler2 (o_item) {
// if node with no link then toggle
if (o_item.a_config[3] && !o_item.a_config[1]) {
o_item.o_root.toggle(o_item.n_id);
// cancel default action
window.parent.TARGET_FRAME_NAME.location='Your_Page.html';
return false;

}
// proceed to default handler
return true;

}


Any comments?


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/