📄 xmenu.js
字号:
/********************************
*
* xmenu v1.3
* CopyRight: stinger 2005/9
*
*********************************/
function getObject(id)
{
if (typeof(id)!="string" || id=="") return(null);
if (document.all) return(document.all(id));
if (document.getElementById) return(document.getElementById(id));
try
{
return(eval(id));
}
catch(E)
{
return(null);
}
}
function _xmenu(OName)
{
this.name = OName;
this.Queue = new Array();
this.SeqId = 0;
this.CImage = "/images/xmenu0.gif";
this.OImage = "/images/xmenu1.gif";
this.CFolder = "/images/folder0.gif";
this.OFolder = "/images/folder1.gif";
this.IName = "image";
this.Dest = OName;
}
//SeqId, Follow, Name, URL, Target, Extend
_xmenu.prototype.Add = function()
{
this.Queue[this.SeqId++] = arguments;
}
_xmenu.prototype.Update = function()
{
for (var i=0; i<this.SeqId; i++)
{
if (this.Queue[i][0]==arguments[0])
{
this.Queue[i] = arguments;
break;
}
}
}
_xmenu.prototype.Remove = function(Seq)
{
var Queue = new Array();
var k = 0;
for (var i=0; i<this.SeqId; i++)
{
if (this.Queue[i][0]!=Seq) Queue[k++] = this.Queue[i];
}
this.Queue = Queue;
this.SeqId = Queue.length;
}
_xmenu.prototype.hasChild = function(Seq)
{
for (var i=0; i<this.SeqId; i++)
{
if (this.Queue[i][1]==Seq) return(true);
}
return(false);
}
_xmenu.prototype.Query = function(Seq)
{
for (var i=0; i<this.SeqId; i++)
{
if (this.Queue[i].length==6 && this.Queue[i][5]==Seq) return(this.Queue[i]);
}
return(null);
}
_xmenu.prototype.toHTML = function(Seq, Depth)
{
var html = "";
for (var i=0; i<this.SeqId; i++)
{
if (this.Queue[i][1]==Seq)
{
var MyId = this.name + this.Queue[i][0];
html += '<div id="' + MyId + '" style="';
//style
html += 'position:relative;left:' + (Depth*10) + 'px;'
if (Seq) html += 'display:none;';
//html += 'cursor:hand"';
html += '"';
//onclick
//html += ' onclick="' + this.name + '.expand(\'' + MyId + '\');"';
html += '>'
//images
html += '<img id="' + this.IName + this.Queue[i][0] + '" src="'
if (this.hasChild(this.Queue[i][0]))
{
html += this.CImage;
}
else
{
html += this.OImage;
}
html += '" border="0" style="cursor:hand"';
html += ' onclick="' + this.name + '.expand(\'' + MyId + '\');" />';
//innerText
html += ' '
if (this.Queue[i][3]==null)
{
html += '<a href="#"';
}
else
{
html += '<a href="' + this.Queue[i][3] + '"';
html += ' target="' + (this.Queue[i][4]==null?this.Dest:this.Queue[i][4]) + '"';
}
html += ' style="cursor:hand"';
html += ' onclick="' + this.name + '.expand(\'' + MyId + '\');">';
html += this.Queue[i][2];
html += '</a>';
html += this.toHTML(this.Queue[i][0], Depth+1);
html += '</div>';
}
}
return(html);
}
_xmenu.prototype.expand = function(id)
{
var Obj = getObject(id);
var Seq = Obj.id.substring(this.name.length);
var fd = false;
var fi = false;
Seq = parseInt(Seq);
if (this.hasChild(Seq))
{
for (var i=0; i<this.SeqId; i++)
{
if (this.Queue[i][1]==Seq)
{
var MyId = this.name + this.Queue[i][0];
var MyObj = getObject(MyId);
if (MyObj!=null)
{
if (fd==false)
{
fd = true;
fi = (MyObj.style.display=='none')?true:false;
}
MyObj.style.display = fi?'block':'none';
}
//if (fi==false && this.hasChild(this.Queue[i][0])) this.expand(MyId);
}
}
getObject(this.IName + Seq).src = (fi==true)?this.OImage:this.CImage;
}
}
_xmenu.prototype.expandx = function(Seq)
{
var MyId;
var MyObj;
for (var i=0; i<this.SeqId; i++)
{
if (this.Queue[i][0]==Seq)
{
if (this.hasChild(Seq))
{
for (k=0; k<this.SeqId; k++)
{
if (this.Queue[k][1]==Seq)
{
MyId = this.name + this.Queue[k][0];
MyObj = getObject(MyId);
if (MyObj!=null) MyObj.style.display = 'block';
}
}
}
MyId = this.IName + this.Queue[i][0];
MyObj = getObject(MyId);
if (MyObj) MyObj.src = this.OImage;
if (this.Queue[i][1]!=0) this.expandx(this.Queue[i][1]);
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -