新版本susymenu树形菜单,请大家指教、分享
/* Susy Menu Class, version 2.0.0
* 2007 shaoyu su
*
* Susy-Menu Class is freely distributable .
*
*
*--------------------------------------------------------------------------*/
var CONTEXT_PATH='';
var NS = (navigator.appName=="Netscape")?true:false;
var EXCEPTION_INFO = {EvalError:'eval()use error',
RangeError:'num overflow',
ReferenceError:'illegal or no can identify num',
SyntaxError:'syntax parse error',
TypeError:'operate num type error',
URIError:'URI use error'
};
String.prototype.trim = function(){
return this.replace(/(^[\\s]*)|([\\s]*$)/g, "");
}
var menuItems = new Array();
Object.extend = function(destination, source) {
for (property in source) {
destination[property] = source[property];
}
return destination;
}
function Parameter(){
this.option = {
menuType:'0',
expandHeadImgUrl:'js/expandHead.gif',
expandBodyImgUrl:'',
expandFootImgUrl:'',
mergeHeadImgUrl:'js/mergeHead.gif',
mergeBodyImgUrl:'',
mergeFootImgUrl:'',
status:'merge',
headWidth:20,
bodyWidth:100,
footWidth:0,
height:20,
mLeft:15,
mTop:3,
fontFamily:'宋体',
fontSize:'12',
fontWeight:'normal',
fontStyle:'normal',
textAlign:'left',
color:'transparent',
gap:'2',
conBackImg:''
};
}
Parameter.prototype.setParameter=function(option){
this.option = Object.extend(this.option,option || {});
}
var lineN = 60;
Parameter.prototype.show=function(mainDivId,menus){
var mainDiv = null;
lineN = 62;
try{
if( mainDivId && mainDivId != '')mainDiv = document.getElementById(mainDivId);
if(mainDiv != null){
var midDiv = document.createElement('div');
midDiv.style.position="absolute";
midDiv.style.left=mainDiv.offsetLeft;
midDiv.style.top=mainDiv.offsetTop;
lineN = 70;
var itemWidth = parseInt(this.option.headWidth)+parseInt(this.option.bodyWidth)+parseInt(this.option.footWidth);
if(menus){
if(1 == parseInt(this.option.menuType)){
midDiv.style.width=menus.length * (itemWidth + parseInt(this.option.mLeft) + parseInt(this.option.gap)) + parseInt(this.option.mLeft);
midDiv.style.border="1px solid green";
}
lineN = 77;
var openedMenuStr = getCookie("OpenedMenu");
for(var i=0;i0){
if(menuItems[this.index].option.status=='merge')
menuItems[this.index].changeSelfImg('expand');
}
if('1'==menuItems[this.index].option.menuType){
menuItems[this.index].startExpandTimer();
}
this.status = 'over';
}
}
};
this.midA.onmouseout=function(){
if(menuItems && menuItems[this.index]){
if(!this.status || this.status!='out'){
if(menuItems[this.index].children && menuItems[this.index].children.length>0){
menuItems[this.index].changeSelfImg(menuItems[this.index].option.status);
}
if('1'==menuItems[this.index].option.menuType){
menuItems[this.index].startMergeTimer();
}
this.status = 'out';
}
}
};
this.menuDiv.onmouseover=function(){
if('1'!=menuItems[this.index].option.menuType)return;
if(menuItems[this.index].timer){
window.clearTimeout(menuItems[this.index].timer);
menuItems[this.index].timer=null;
}
menuItems[this.index].mouseOver=true;
//if(menuItems[this.index].superior)menuItems[this.index].superior.startExpandTimer();
}
this.menuDiv.onmouseout=function(){
if('1'!=menuItems[this.index].option.menuType)return;
menuItems[this.index].startMergeTimer();
}
if(NS)
this.headImg.setAttribute('style','float:left');
else
this.headImg.style.styleFloat='left';
this.headImg.style.width = this.option.headWidth;
this.headImg.style.height = this.option.height;
this.headImg.style.backgroundColor=this.option.color;
this.headImg.style.backgroundRepeat='no-repeat';
this.headImg.style.backgroundPosition='0 50%';
if(NS)
this.bodyDiv.setAttribute('style','float:left');
else
this.bodyDiv.style.styleFloat='left';
this.bodyDiv.style.width = this.option.bodyWidth;
this.bodyDiv.style.height = this.option.height;
this.bodyDiv.style.backgroundColor=this.option.color;
this.bodyDiv.style.fontFamily=this.option.fontFamily;
this.bodyDiv.style.fontWeight=this.option.fontWeight;
this.bodyDiv.style.fontSize=this.option.fontSize;
this.bodyDiv.style.fontStyle=this.option.fontStyle;
this.bodyDiv.style.textAlign=this.option.textAlign;
this.bodyDiv.style.lineHeight = this.bodyDiv.style.height;
this.bodyDiv.style.backgroundRepeat='no-repeat';
this.bodyDiv.style.backgroundPosition='0 50%';
if(NS)
this.footImg.setAttribute('style','float:left');
else
this.footImg.style.styleFloat='left';
this.footImg.style.width = this.option.footWidth;
this.footImg.style.height = this.option.height;
this.footImg.style.backgroundColor=this.option.color;
this.headImg.style.backgroundRepeat='no-repeat';
this.headImg.style.backgroundPosition='0 50%';
this.bodyDiv.innerHTML=this.title;
this.midA.appendChild(this.headImg);
this.midA.appendChild(this.bodyDiv);
this.midA.appendChild(this.footImg);
this.midDiv.appendChild(this.midA);
this.menuDiv.appendChild(this.midDiv);
this.menuDiv.appendChild(this.container);
this.changeSelfImg('merge');
if('1' == this.option.menuType && this.superior){
this.container.style.left =0;
this.container.style.left = parseInt(this.container.style.left) + parseInt(this.midDiv.style.width) + parseInt(this.menuDiv.style.marginLeft) + parseInt(this.option.gap);
}
//this.container.style.top = parseInt(superiorDiv.style.top) + parseInt(this.menuDiv.style.marginTop);
//alert(this.container.style.top);
if(this.children){
for(var i=0;i0)sT = parseInt(this.children[i-1].container.style.top);
else if(!this.superior)sT = sT + parseInt(this.option.mTop);
this.children[i].container.style.top = sT + parseInt(this.option.mTop) + parseInt(this.option.height);
}
this.children[i].init(this.container,this);
}
}
superiorDiv.appendChild(this.menuDiv);
}
}
Menu.prototype.changeStatus=function(source){
if(source && ''!=source)this.option.status=source;
if(this.option.status=='merge'){
this.expand();
} else {
this.merge();
if('1' == this.option.menuType && this.children){
for(var i=0;i
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
新版本菜单中的一种类型,另一种形式在下面运行代码中展示。