📄 jscooktree.js
字号:
else if (hasChild)
{
lvl = ctGetPropertyLevel (level, nodeProperties.folderLeft);
str += '<span class="JSCookTreeFolderClosed">' + nodeProperties.folderLeft[lvl][0] + '</span>' +
'<span class="JSCookTreeFolderOpen">' + nodeProperties.folderLeft[lvl][1] + '</span>';
}
else
{
lvl = ctGetPropertyLevel (level, nodeProperties.itemLeft);
str += nodeProperties.itemLeft[lvl];
}
str += '</td>';
str += '<td class="' + classStr + 'Text"' + actionStr + '>';
str += '<a';
if (item[2] != null)
{
str += ' href="' + item[2] + '"';
if (item[3])
str += ' target="' + item[3] + '"';
}
if (item[4] != null)
str += ' title="' + item[4] + '"';
else
str += ' title="' + item[1] + '"';
str += '>' + item[1] + '</a></td>';
str += '<td class="' + classStr + 'Right"' + actionStr + '>';
if (hasChild)
{
lvl = ctGetPropertyLevel (level, nodeProperties.folderRight);
str += '<span class="JSCookTreeFolderClosed">' + nodeProperties.folderRight[lvl][0] + '</span>' +
'<span class="JSCookTreeFolderOpen">' + nodeProperties.folderRight[lvl][1] + '</span>';
}
else
{
lvl = ctGetPropertyLevel (level, nodeProperties.itemRight);
str += nodeProperties.itemRight[lvl];
}
str += '</td>'
str += '</tr></table>';
if (hasChild)
{
childIndent = indent;
lvl = ctGetPropertyLevel (level, nodeProperties.spacer);
childIndent += nodeProperties.spacer[lvl][connectSelect];
str += ctDrawSub (item, false, idSub, treeIndex, level + 1, nodeProperties, prefix, childIndent);
}
}
str += '</div>';
return str;
}
//////////////////////////////////////////////////////////////////////
//
// Mouse Event Handling Functions
//
//////////////////////////////////////////////////////////////////////
//
// action should be taken for mouse moving in to the menu item
//
function ctItemMouseOver (item)
{
var treeItem = _ctItemList[item.ctIndex];
var isDefaultItem = ctIsDefaultItem (treeItem);
if (isDefaultItem)
{
var className = ctGetDefaultClassName (item);
if (item.className == className)
item.className = className + 'Hover';
}
}
//
// action should be taken for mouse moving out of the menu item
//
function ctItemMouseOut (item)
{
if (ctIsDefaultItem (_ctItemList[item.ctIndex]))
{
var className = ctGetDefaultClassName (item);
if (item.className == (className + 'Hover') ||
item.className == (className + 'Active'))
{
var tree = _ctTreeList[item.ctTreeIndex];
var currentItem = (tree.hideType <= 1) ? tree.currentItem : _ctCurrentItem;
if (item == currentItem)
item.className = className + 'Selected';
else
item.className = className;
}
}
}
//
// action should be taken for mouse button down at a menu item
//
function ctItemMouseDown (item)
{
//document.write('<textarea name="view">'+item+'</textarea>');
if (ctIsDefaultItem (_ctItemList[item.ctIndex]))
{
var className = ctGetDefaultClassName (item);
if (item.className == (className + 'Hover'))
item.className = className + 'Active';
}
}
//
// action should be taken for mouse button up at a menu item
//
function ctItemMouseUp (item)
{
if (item.ctIdSub)
{
// toggle the submenu
var subMenu = ctGetObject (item.ctIdSub);
if (subMenu.style.display == 'block')
{
ctCloseFolder (item);
}
else
{
ctOpenFolder (item);
}
}
ctSetSelectedItem (item);
}
//
// set the item as the selected item
//
function ctSetSelectedItem (item)
{
var tree = _ctTreeList[item.ctTreeIndex];
var hideType = tree.hideType;
var otherItem;
if (hideType <= 1)
otherItem = tree.currentItem;
else
otherItem = _ctCurrentItem;
if (otherItem != item)
{
ctLabelMenu (item);
// set otherItem to normal
if (otherItem)
{
if (ctIsDefaultItem (_ctItemList[otherItem.ctIndex]))
{
var className = ctGetDefaultClassName (otherItem);
if (otherItem.className == (className + 'Selected'))
otherItem.className = className;
}
// hide otherItem if required
if (hideType > 0 && otherItem)
ctHideMenu (otherItem, item);
}
// finally, set this item as selected
if (hideType <= 1)
tree.currentItem = item;
else
_ctCurrentItem = item;
if (ctIsDefaultItem (_ctItemList[item.ctIndex]))
{
var className = ctGetDefaultClassName (item);
item.className = className + 'Selected';
}
}
}
//////////////////////////////////////////////////////////////////////
//
// Mouse Event Support Utility Functions
//
//////////////////////////////////////////////////////////////////////
//
// check if an item is in open form
//
function ctIsFolderOpen (item)
{
if (item.id == 'JSCookTreeFolderOpen')
return true;
return false;
}
//
// change an item into the open form
//
function ctOpenFolder (item)
{
if (ctIsFolderOpen (item))
return;
if (item.ctIdSub)
{
var subMenu = ctGetObject (item.ctIdSub);
subMenu.style.display = 'block';
item.id = 'JSCookTreeFolderOpen';
}
}
//
// change an item into the closed form
//
function ctCloseFolder (item)
{
if (!ctIsFolderOpen (item))
return;
// hide the downstream menus
if (item.ctIdSub)
{
var subMenu = ctGetObject (item.ctIdSub);
var i;
for (i = 0; i < subMenu.ctSubMenu.length; ++i)
ctCloseFolder (subMenu.ctSubMenu[i].ctParent);
var expandLevel = _ctTreeList[item.ctTreeIndex].expandLevel;
if (item.ctLevel < expandLevel)
return;
subMenu.style.display = 'none';
item.id = 'JSCookTreeFolderClosed';
}
}
//
// setup an menu item
//
function ctSetupItem (item, index, treeIndex, level, idSub)
{
if (!item.ctIndex)
{
item.ctIndex = index;
item.ctTreeIndex = treeIndex;
item.ctLevel = level;
item.ctIdSub = idSub;
}
var thisMenu = ctGetThisMenu (item);
ctSetupMenu (thisMenu, item, null, null);
if (idSub)
{
var subMenu = ctGetObject (idSub);
ctSetupMenu (subMenu, null, thisMenu, item);
}
}
//
// setup the relationship between a node and its sub menu
//
function ctSetupMenu (thisMenu, thisItem, parentMenu, parentItem)
{
if (!thisMenu.ctSubMenu)
thisMenu.ctSubMenu = new Array ();
if (parentItem)
{
if (!thisMenu.ctParent)
{
// establish the tree w/ back edge
thisMenu.ctParent = parentItem;
thisMenu.ctLevel = parentItem.ctLevel + 1;
//parentMenu.ctSubMenu.push (thisMenu);
parentMenu.ctSubMenu[parentMenu.ctSubMenu.length] = thisMenu;
}
}
if (thisItem)
{
if (!thisItem.ctMenu)
{
thisItem.ctMenu = thisMenu;
thisMenu.ctLevel = thisItem.ctLevel;
if (!thisMenu.ctItems)
thisMenu.ctItems = new Array ();
//thisMenu.ctItems.push (thisItem);
thisMenu.ctItems[thisMenu.ctItems.length] = thisItem;
}
}
}
//
// label the path from the menu root to the item
//
function ctLabelMenu (item)
{
var thisMenu = ctGetThisMenu (item);
while (thisMenu && thisMenu.ctLevel != 0)
{
thisMenu.ctCurrentItem = item;
thisMenu = ctGetThisMenu (thisMenu.ctParent);
}
}
//
// hide an item up to the parent menu of activeItem
//
function ctHideMenu (item, activeItem)
{
var subMenu;
while (item)
{
if (item.ctIdSub &&
(subMenu = ctGetObject (item.ctIdSub)).ctLevel &&
(subMenu.ctCurrentItem != activeItem))
{
ctCloseFolder (item);
}
item = ctGetThisMenu (item).ctParent;
}
}
//
// returns the menu div where this obj (menu item) is in
//
function ctGetThisMenu (item)
{
var str = _ctTreeList[item.ctTreeIndex].prefix;
if (item.ctLevel == 0)
str += 'TreeLevel0';
else
{
var themeLevel = _ctTreeList[item.ctTreeIndex].nodeProperties.themeLevel;
var lvl = (item.ctLevel < themeLevel) ? item.ctLevel : themeLevel;
str += 'TreeLevel' + lvl;
}
while (item)
{
if (item.className == str)
return item;
item = item.parentNode;
}
return null;
}
//
// return true if there is next item
//
// used to determine connectors
//
function ctHasNextItem (index, tree)
{
if (index < (tree.length - 2) ||
(index == (tree.length - 2) && tree[index + 1]))
return true;
else
return false;
}
function ctGetDefaultClassName (item)
{
var tree = _ctTreeList[item.ctTreeIndex];
return tree.prefix + 'Row';
}
//
// return true if this item is handled using default handlers
//
function ctIsDefaultItem (item)
{
if (item[0] == _ctNoAction)
return false;
return true;
}
//
// returns the object baring the id
//
function ctGetObject (id)
{
if (document.all)
return document.all[id];
return document.getElementById (id);
}
//
// debug function, ignore :)
//
function ctGetProperties (obj)
{
var msg = obj + ':\n';
var i;
for (i in obj)
msg += i + ' = ' + obj[i] + '; ';
return msg;
}
/* JSCookTree v2.01 1. change Array.push (obj) call to Array[length] = obj.
Suggestion from Dick van der Kaaden <dick@netrex.nl> to
make the script compatible with IE 5.0
2. added ctGetSelectedItem (treeIndex) function due to demand
*/
/* JSCookTree v2.0 1. added controls over tree branches opening/closing
2. added the ability to mark a specific tree item
3. added an extra description field to make the tree
format the same as JSCookMenu
4. more control over themes. allow multiple trees
w/ different themes co-exist in the same page
5. tooltips.
*/
/* JSCookTree v1.01. made more tolerant to extra commas */
/* JSCookTree v1.0. (c) Copyright 2002 by Heng Yuan */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -