📄 treeview.js
字号:
//////////////////////////////////////////////
/// Booksir.WebControl.TreeView (2005) ///
////////////////////////////////////////////
var TreeView_KeyboardHooked = false;
var TreeView_DragAndDropHooked = false;
var TreeView_Active = null;
var TreeView_DragActive = null;
/////////////////////////////
/// TreeNode ///
////////////////////////////
function TreeNode()
{
this.Parent = null;
this.TreeView = null;
this.Nodes = new Array();
this.ID = null;
this.SignImage = null;
this.SignImageExpanded = null;
this.Image = 0;
this.ImageExpanded = 0;
this.Action = null;
this.Index = 0;
this.Text = null;
this.Value = null;
this.Category = null;
this.NodeCss = null;
this.NodeCssOver = null;
this.NodeCssSelect = null;
this.ContextMenuName = null;
this.Enabled = true;
this.Expanded = false;
this.Checked = false;
this.Selected = false;
}
TreeNode.prototype.Next = function()
{
var nodeCollection = (this.Parent != null) ? this.Parent.Nodes : this.TreeView.Nodes;
return (this.Index >= nodeCollection.length) ? null : nodeCollection[this.Index + 1];
}
TreeNode.prototype.Prev = function()
{
var nodeCollection = (this.Parent != null) ? this.Parent.Nodes : this.TreeView.Nodes;
return (this.Index <= 0) ? null : nodeCollection[this.Index - 1];
}
TreeNode.prototype.NextVisible = function()
{
if (this.Expanded)
return this.Nodes[0];
if (this.Next() != null)
return this.Next();
var currentNode = this;
while (currentNode.Parent != null)
{
if (currentNode.Parent.Next() != null);
return currentNode.Parent.Next();
currentNode = currentNode.Parent;
}
return null;
}
TreeNode.prototype.PrevVisible = function()
{
if (this.Prev() != null)
return this.Prev();
if (this.Parent != null)
return this.Parent;
return null;
}
TreeNode.prototype.Toggle = function()
{
if (!this.Nodes.length)
return;
if (!this.TreeView.FireEvent(this.TreeView.BeforeClientToggle, this))
return;
(this.Expanded) ? this.Collapse() : this.Expand();
if (!this.TreeView.FireEvent(this.TreeView.AfterClientToggle, this));
}
TreeNode.prototype.CollapseNonParentNodes = function()
{
for (i=0;i<this.TreeView.AllNodes.length;i++)
{
if (!this.IsParent(this.TreeView.AllNodes[i]))
{
this.TreeView.AllNodes[i].CollapseNoEffect();
}
}
}
TreeNode.prototype.Expand = function()
{
if (this.TreeView.SingleExpandPath)
this.CollapseNonParentNodes();
var childGroup = document.getElementById("G" + this.ID);
childGroup.style.overflow = "hidden";
childGroup.style.height = "1px";
childGroup.style.display = "block";
childGroup.firstChild.style.position = "relative";
rtvNodeExpand(childGroup.id);
this.ImageOn();
this.SignOn();
this.Expanded = true;
this.TreeView.UpdateExpandedState();
}
TreeNode.prototype.CollapseNoEffect = function()
{
if (this.Nodes.length > 0)
{
var childGroup = document.getElementById("G" + this.ID);
childGroup.style.display = "none";
this.ImageOff();
this.SignOff();
this.Expanded = false;
this.TreeView.UpdateExpandedState();
}
}
TreeNode.prototype.Collapse = function()
{
if (this.Nodes.length > 0)
{
var childGroup = document.getElementById("G" + this.ID);
childGroup.style.overflow = "hidden";
childGroup.style.display = "block";
childGroup.firstChild.style.position = "relative"
rtvNodeCollapse(childGroup.id);
this.ImageOff();
this.SignOff();
this.Expanded = false;
this.TreeView.UpdateExpandedState();
}
}
TreeNode.prototype.Highlight = function(e)
{
if (!this.Enabled)
return;
if (!this.TreeView.FireEvent(this.TreeView.BeforeClientHighlight, this))
return;
if (this.TreeView.MultipleSelect && e.ctrlKey)
{
if (this.Selected)
{
this.TextElement().className = this.NodeCss;
this.Selected = false;
this.TreeView.UpdateSelectedState();
this.TreeView.FireEvent(this.TreeView.AfterClientHighlight, this);
return;
}
}
else
{
this.TreeView.UnSelectAllNodes();
}
this.TextElement().className = this.NodeCssSelect;
this.TreeView.SelectNode(this);
this.TreeView.FireEvent(this.TreeView.AfterClientHighlight, this);
}
TreeNode.prototype.ExecuteAction = function()
{
if (!this.TreeView.FireEvent(this.TreeView.BeforeClientClick, this))
return;
if (this.Action != null)
{
if (this.Action.substr(0,12) == "__doPostBack" && this.TreeView.CausesValidation)
{
if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate())
{
eval(this.Action);
}
}
else
{
eval(this.Action);
}
}
}
TreeNode.prototype.Select = function(e)
{
if (!this.Enabled) return;
this.Highlight(e);
this.TreeView.LastHighlighted = this;
if (!this.TreeView.CancelAction)
this.ExecuteAction();
}
TreeNode.prototype.UnSelect = function()
{
this.TextElement().className = this.NodeCss;
this.Selected = false;
}
TreeNode.prototype.Disable = function()
{
this.TextElement().className = "TreeNodeDisabled";
this.Enabled = false;
}
TreeNode.prototype.Hover = function()
{
if (!this.Enabled) return;
this.TreeView.LastHighlighted = this;
if (!this.Selected)
this.TextElement().className = this.NodeCssOver;
}
TreeNode.prototype.UnHover = function()
{
if (!this.Enabled) return;
this.TreeView.LastHighlighted = null;
if (!this.Selected)
this.TextElement().className = this.NodeCss;
}
TreeNode.prototype.CheckBoxClick = function(e)
{
if (!this.TreeView.FireEvent(this.TreeView.BeforeClientCheck, this))
return;
this.Checked = !this.Checked;
this.TreeView.UpdateCheckedState();
this.TreeView.FireEvent(this.TreeView.AfterClientCheck, this);
}
TreeNode.prototype.Check = function()
{
if (this.CheckElement() != null)
{
this.CheckElement().checked = true;
this.Checked = true;
this.TreeView.UpdateCheckedState();
}
}
TreeNode.prototype.UnCheck = function()
{
if (this.CheckElement() != null)
{
this.CheckElement().checked = false;
this.Checked = false;
this.TreeView.UpdateCheckedState();
}
}
TreeNode.prototype.IsSet = function(a)
{
return (a != null && a != "");
}
TreeNode.prototype.ImageOn = function()
{
var imageElement = document.getElementById(this.ID + "i");
if (this.ImageExpanded != 0)
imageElement.src = this.ImageExpanded;
}
TreeNode.prototype.ImageOff = function()
{
var imageElement = document.getElementById(this.ID + "i");
if (this.Image != 0)
imageElement.src = this.Image;
}
TreeNode.prototype.SignOn = function()
{
var signElement = document.getElementById(this.ID + "c");
if (this.IsSet(this.SignImageExpanded))
signElement.src = this.SignImageExpanded;
}
TreeNode.prototype.SignOff = function()
{
var signElement = document.getElementById(this.ID + "c");
if (this.IsSet(this.SignImage))
signElement.src = this.SignImage;
}
TreeNode.prototype.TextElement = function()
{
return document.getElementById(this.ID).getElementsByTagName("span")[0];
}
TreeNode.prototype.CheckElement = function()
{
return document.getElementById(this.ID).getElementsByTagName("input")[0];
}
TreeNode.prototype.IsParent = function(node)
{
var parent = this.Parent
while (parent != null)
{
if (node == parent)
return true;
parent = parent.Parent;
}
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// TreeView Defs
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TreeView(uniqueId, id, firstNodeId, _nodeCss, _nodeCssOver, _nodeCssSelect, _multipleSelect, _ie, _serverId, _dragAndDrop)
{
this.ID = _serverId;
this.UniqueId = uniqueId;
this.Container = id;
this.Nodes = new Array();
this.AllNodes = new Array();
this.NodeCss = _nodeCss;
this.NodeCssOver = _nodeCssOver;
this.NodeCssSelect = _nodeCssSelect;
this.MultipleSelect = _multipleSelect;
this.IE = _ie;
this.SelectedNode = null;
this.DragAndDrop = _dragAndDrop;
this.DragMode = false;
this.DragSource = null;
this.DragClone = null;
this.LastHighlighted = null;
this.MouseInside = false;
this.HtmlElementID = "";
// Client-side events
this.BeforeClientClick = null;
this.BeforeClientHighlight = null;
this.AfterClientHighlight = null;
this.BeforeClientDrop = null;
this.BeforeClientToggle = null;
this.AfterClientToggle = null;
this.BeforeClientContextClick = null;
this.AfterClientContextClick = null;
this.BeforeClientCheck = null;
this.AfterClientCheck = null;
this.AfterClientMove = null;
this.CausesValidation = true;
this.ContextMenuVisible = false;
this.ContextMenuName = null;
this.SingleExpandPath = false;
var ImageList = new Array();
this.PreloadImages(ImageList);
this.LoadTree(ImageList);
var images = document.getElementById(this.Container).getElementsByTagName("IMG");
var i;
for (i=0; i<images.length; i++)
{
var index = images[i].getAttribute("r");
if (index != null && index != "")
images[i].src = ImageList[index].src;
(document.all) ? images[i].align = "absmiddle" : images[i].valign = "absmiddle";
}
if (!TreeView_KeyboardHooked)
{
TreeView_KeyboardHooked = true;
if (this.IE)
document.attachEvent('onkeydown', this.KeyDown);
else
document.addEventListener('keydown', this.KeyDown, false);
}
if (!TreeView_DragAndDropHooked)
{
TreeView_DragAndDropHooked = true;
if (this.IE)
{
if (this.DragAndDrop)
document.attachEvent('onmousemove', rtvMouseMove);
document.attachEvent('onmouseup', rtvMouseUp);
}
else
{
if (this.DragAndDrop)
document.addEventListener('mousemove', rtvMouseMove, false);
document.addEventListener('mouseup', rtvMouseUp, false);
}
}
}
TreeView.prototype.PreloadImages = function(images)
{
var imageData = eval(this.ID + "ImageData");
var i;
for (i=0; i<imageData.length; i++)
{
var image = new Image();
image.src = imageData[i];
images[i] = image;
}
}
TreeView.prototype.FindNode = function(node)
{
var i;
for (i=0;i<this.AllNodes.length;i++)
{
if (this.AllNodes[i].ID == node)
return this.AllNodes[i];
}
return null;
}
TreeView.prototype.FindNodeByText = function(text)
{
var i;
for (i=0;i<this.AllNodes.length;i++)
{
if (this.AllNodes[i].Text == text)
return this.AllNodes[i];
}
return null;
}
TreeView.prototype.FindNodeByValue = function(value)
{
var i;
for (i=0;i<this.AllNodes.length;i++)
{
if (this.AllNodes[i].Value == value)
return this.AllNodes[i];
}
return null;
}
TreeView.prototype.LoadTree = function(imageList)
{
var cd = eval(this.ID + "ClientData");
var i;
var parent = null;
for (i=0; i<cd.length; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -