📄 treeview.htc
字号:
//
// return: true if something interesting happened (expanded, collapsed), false otherwise
//
function doNodePlusMinusClick(el)
{
if (g_bInteractive == false)
return false;
// The element, which is in a content node outside of the document, is outside the event hierarchy.
// Fire the event ourselves, rather than relying on bubbling.
event.cancelBubble = true;
g_nodeClicked = el;
if (el.getAttribute("expanded") == false && el.getAttribute("_bound") == null && el.getAttribute("TreeNodeSrc") != null)
{
el._isExpanding = true;
private_databind(el);
return true;
}
else
return finishNodePlusMinusClick(el);
}
function finishNodePlusMinusClick(el)
{
// See if we're a leaf (no children) or a branch (children)
var exp = getNodeAttribute(el, "expandable");
if (exp == null && el.getAttribute("TreeNodeSrc") != null)
exp = "checkOnce";
if (el.children.tags("treenode").length > 0 || exp == "always" || (exp == "checkOnce" && el.getAttribute("checkedExpandable") != true))
{
//
// We're a branch. Update ourselves.
//
var expanded = !el.getAttribute("expanded");
el.setAttribute("expanded", expanded, 0);
if (exp == "checkOnce")
el.checkedExpandable = true;
var evt = createEventObject();
evt.treeNodeIndex = getNodeIndex(el);
var eventToFire = changeJunctionImage(el);
// update our children
updateTree(el);
doVisualRefresh();
// show status node if we're posting back for databinding
if (expanded == true && el.children.tags("treenode").length == 0 && element.getAttribute("onfirequeuedevents") != null)
addStatusNode(el, L_strRetrievingNodes_Text);
eventToFire.fire(evt);
return true;
}
return false;
}
//
// changeJunctionImage()
//
// Changes the +/- junction image to match current Expanded state.
//
// el: treenode element containing junction image to change
//
function changeJunctionImage(el)
{
// find the icons we need to change
var icon1 = el.subtree.all("junction",0);
if (el.getAttribute("expanded") == true)
{
// Expanding the node
if (icon1 != null)
icon1.src = icon1.src.replace(/plus/, "minus");
if (selectedNodeIndex != getNodeIndex(el) || getNodeAttribute(el, "selectedimageurl") == null)
changeIcon(el, "ExpandedImageUrl");
return _tvevtExpand;
}
else
{
// Collapsing the node
if (icon1 != null)
icon1.src = icon1.src.replace(/minus/, "plus");
if (selectedNodeIndex != getNodeIndex(el))
changeIcon(el, "ImageUrl");
return _tvevtCollapse;
}
}
//
// DefaultNodeOnClick()
//
// A default onclick handler for treenode elements to cancel the event bubble.
// This is needed for the server control, otherwise the event will bubble up the
// tree until it hits a node with an onclick handler. In the case of a server
// control, odds are good that the onclick handler will cause a server postback,
// thereby preventing the tree from getting its onclick. So we need to cancel
// the bubble, allowing the onclick event we fire on the tree to get through.
//
function DefaultNodeOnClick()
{
event.cancelBubble = true;
}
function getClickedNodeIndex()
{
if (g_nodeClicked != null)
return getNodeIndex(g_nodeClicked);
else
return null;
}
function getNodeLevel(node)
{
var level = 0;
while (node.parentElement.tagName.toLowerCase() == "treenode")
{
node = node.parentElement;
level++;
}
return level;
}
//
// getNodeIndex()
//
// Walks up the tree, generating an index string of the form a.b.c[...].z (ex: 1.0.5.12) where
// each number represents a 0-based index into a set of children. Each set of these values
// creates a unique index to a node. In the following tree:
// A
// / | \
// B C D
// / \ / \
// E F G H
// node F is 0.0.1, node G is 0.2.0, and H is 0.2.1.
//
function getNodeIndex(node)
{
var strIndex = "";
if (node != null)
{
if (node.getAttribute("sibIndex") == null)
{
if (node.parentElement == null)
{
// There is no parent, this node is in the ether
return null;
}
// generate a sibling index
var col = node.parentElement.children.tags("treenode");
var i = 0;
while (col[i] != node)
i++;
node.sibIndex = i;
}
strIndex = node.sibIndex.toString();
while (node.parentElement && node.parentElement.tagName.toLowerCase() == "treenode")
{
node = node.parentElement;
if (node.getAttribute("sibIndex") == null)
return null;
strIndex = node.sibIndex + "." + strIndex;
}
}
return strIndex;
}
//
// getNodeFromIndex()
//
// The flipside of getNodeIndex, this function returns a node given a dot-delimited index
//
function getNodeFromIndex(strIndex)
{
if (strIndex != null && strIndex != undefined && strIndex.length != 0)
{
// convert index string into array of strings
var a = strIndex.split(".");
var i = 0;
var node = contentNode;
while (i < a.length)
{
var coll = node.children.tags("treenode");
if (coll == null || coll.length < (a[i] - 0) + 1)
{
return null;
}
node = coll.item(a[i++] - 0);
}
return node;
}
else
{
return null;
}
}
//
// getNextVisibleNode()
//
function getNextVisibleNode(node)
{
var next = node;
if (node.getAttribute("expanded") == true)
{
// get first child treenode
next = node.children[0];
while (next != null && next != undefined && next.nodeName.toLowerCase() != "treenode")
next = next.nextSibling;
if (next)
return next;
}
// get first sibling treenode
next = node.nextSibling;
while (next != null && next != undefined && next.nodeName.toLowerCase() != "treenode")
next = next.nextSibling;
if (next != null)
return next;
// get first sibling of first ancestor that has one
next = node.parentElement;
while ((next.nextSibling == null || next.nextSibling == undefined) && next.nodeName.toLowerCase() == "treenode")
{
next = next.parentElement;
}
if (next.nextSibling != null && next.nextSibling != undefined && next.nextSibling.nodeName.toLowerCase() == "treenode")
return next.nextSibling;
else
return null;
}
//
// getPreviousVisibleNode()
//
function getPreviousVisibleNode(node)
{
var prev = node;
// check for a previous sibling
prev = node.previousSibling;
while (prev != null && prev != undefined && prev.nodeName.toLowerCase() != "treenode")
prev = prev.previousSibling;
if (prev)
{
// Found a previous sibling. If that sibling is expanded, we need to drop down to its last child
if (prev.getAttribute("expanded") == true)
{
// get last child
var lastChild = prev;
while (lastChild != node && lastChild != null)
{
prev = lastChild;
lastChild = getNextVisibleNode(prev);
}
}
return prev;
}
// get parent
if (node.parentElement.nodeName.toLowerCase() == "treenode")
return node.parentElement;
else
return null;
}
//
// setHiddenHelperValue()
//
function setHiddenHelperValue()
{
var id = element.HelperID;
if (id == null)
return;
var helper = window.document.all(id);
if (helper == null)
return;
var parentTop = -1;
var parentLeft = -1;
var parent = element.offsetParent;
if (parent != null)
{
parentTop = parent.scrollTop;
parentLeft = parent.scrollLeft;
}
helper.value = (g_bFocus ? "1" : "0") + "|" + HoverNodeIndex + "|" + element.scrollTop + "|" + element.scrollLeft + "|" + parentTop + "|" + parentLeft + "|" + g_strQueuedEvents;
}
//
// scrollTree()
//
function scrollTree(tnode)
{
var node = tnode.subtree.all.item("_tntext", 0);
var top = node.offsetTop - element.scrollTop;
if (top < 0)
{
element.scrollTop += top;
}
else
{
var bottom = top + node.offsetHeight;
var elemHeight = element.clientHeight;
if (bottom > elemHeight)
{
element.scrollTop += bottom - elemHeight;
}
}
var rc = node.getBoundingClientRect();
var elRc = element.getBoundingClientRect();
// scroll window if we're focused
if (g_bFocus)
{
if (elRc.top + rc.top < element.document.body.clientTop)
node.scrollIntoView(true);
else if (elRc.top + rc.bottom > element.document.body.clientHeight)
node.scrollIntoView(false);
}
}
//
// getInheritedType()
//
// Returns the node's inheritedType, if defined, or finds it and returns it if undefined.
// A node's inheritedType is the first of:
// * parent's childType
// * parent's type's childType
// * parent's inheritedType's childType
// * parent's inheritedType
//
function getInheritedType(el)
{
if (el.inheritedType === undefined || g_bInTypesBoundEvent)
{
var parentNode = el.parentElement;
/*
while (parentNode.tagName.toLowerCase() != "treenode" && parentNode.tagName.toLowerCase() != "treeview")
parentNode = parentNode.parentElement;
*/
// parent's childType
el.inheritedType = parentNode.getAttribute("childType");
var tagname = parentNode.tagName.toLowerCase();
if (el.inheritedType == null && tagname != "treeview")
{
// parent's type's or inheritedType's childType
var _parenttype = getNodeTypeObject(parentNode);
if (_parenttype != null)
{
el.inheritedType = _parenttype.getAttribute("childType");
}
// parent's inheritedType
if (el.inheritedType == null && tagname == "treenode")
{
el.inheritedType = getInheritedType(parentNode);
}
}
// grab from the treeview
if (el.inheritedType == null)
el.inheritedType = element.getAttribute("childType");
}
return el.inheritedType;
}
//
// getNodeTypeObject()
//
// Returns the node type object for the given node, if defined. If undefined, searches
// for and stores the node type object, then returns it. Returns null if no type is defined
// for this node.
//
// This function assumes that a node's type or inheritedType attribute holds the name of its type
//
function getNodeTypeObject(el)
{
if (el.nodetypeIndex == undefined || g_bInTypesBoundEvent)
{
var theType = el.getAttribute("type");
if (theType == null)
theType = getInheritedType(el);
if (theType == null)
return null;
theType = theType.toLowerCase();
var i = 0;
var len = element.nodeTypes.length;
while (i < len)
{
if (element.nodeTypes[i].getAttribute("type") == theType)
{
el.nodetypeIndex = i;
break;
}
i++;
}
}
return element.nodeTypes[el.nodetypeIndex];
}
//
// replaceJunctionNode()
//
// Replace the junction node of the given node by generating a new one
//
// node: treenode on which to perform replacement
//
function replaceJunctionNode(node)
{
if (node.subtree == null)
return;
var oldNode = node.subtree.all("junction", 0);
if (oldNode == null)
return;
var cJunction = calcJunction(node);
var exp = node.getAttribute("Expandable");
if (exp == null && node.getAttribute("TreeNodeSrc") != null)
exp = "checkOnce";
var bChildNodes = node.children.tags("treenode").length > 0;
var junctionNode = generateJunctionNode(node,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -