// This global array holds all the tree nodes var nodes_array = new Array() // This global variable holds the currently displayed document var current_document = -1 // Pre-load the images var temp_image = new Image(22, 16) temp_image.src = "open.gif" var temp_image = new Image(22, 16) temp_image.src = "closed.gif" var temp_image = new Image(18, 13) temp_image.src = "plus.gif" var temp_image = new Image(18, 13) temp_image.src = "minus.gif" var temp_image = new Image(22, 16) temp_image.src = "open_page.gif" var temp_image = new Image(22, 16) temp_image.src = "closed_page.gif" // This function creates a node in the tree with the following arguments: // level - The level within the tree hierarchy (0 = top) // index - The node's index within the global nodes_array // text - The text displayed in the tree for this node // state - Folder: "open" (expanded) or "closed" (collapsed) // Document: "open" (displayed) or "closed" (hidden) // url - For a document, the address it will display when clicked function node_data (level, index, text, state, url) { this.level = level this.index = index this.text = text this.state = state this.url = url } // This function creates a node in the tree; the // arguments are used by the node_data() function function create_node(level, text, state, url) { // Create a new node array var new_node = new Array() // Put it in the global nodes_array var nodes_index = nodes_array.length nodes_array[nodes_index] = new_node // The first item in the array is the node_data object new_node[0] = new node_data(level, nodes_index, text, state, url) // Return the array return new_node } // This function adds a child to an existing parent node function add_child(parent_node, child_node) { // We're adding an item to the parent's array, so the array's // current length represents the next index of that array var next_index = parent_node.length // Add the child node to the parent's array parent_node[next_index] = child_node // Return the child return child_node } function write_menu() { // Clear the frame and write the basic opening tags frames["tree_frame"].document.clear() frames["tree_frame"].document.writeln('') frames["tree_frame"].document.writeln('
') frames["tree_frame"].document.writeln('') // Create a table for each node frames["tree_frame"].document.writeln('
')
frames["tree_frame"].document.writeln('')
if (main_node[0].state == "closed") {
frames["tree_frame"].document.writeln('![]() ![]() ![]() ![]() | ')
frames["tree_frame"].document.writeln(main_node[0].text)
frames["tree_frame"].document.writeln('<\/td>')
frames["tree_frame"].document.writeln('<\/tr>')
frames["tree_frame"].document.writeln("<\/table>")
// If the main node state is "open", write the child nodes
if (main_node[0].state == "open") {
write_children(main_node)
}
// Finish up
frames["tree_frame"].document.writeln('<\/body>')
frames["tree_frame"].document.writeln('<\/html>')
frames["tree_frame"].document.close()
}
// This function writes all the child node for whatever
// parent node is specified as the argument. Note that
// this function is called recursively whenever any
// child node has children of its own.
function write_children(parent_node) {
var child_node
var indent_width
// Run through all of the parent's child nodes
// parent_node[0] refers to the parent node itself, so start at 1
for (var counter = 1; counter < parent_node.length; counter++) {
// Store the child node
child_node = parent_node[counter]
// First check to see if this is a folder or a document
var its_a_folder = true
if (child_node.length == 1) {
its_a_folder = false
}
// Create a table for the child node
frames["tree_frame"].document.writeln('
|