📄 spmenu.js
字号:
//------------------------------------------------------//
// Solution Partner's ASP.NET Hierarchical Menu Control //
// Copyright (c) 2002-2005 //
// Jon Henning - Solution Partner's Inc //
// jhenning@solpart.com - http://www.solpart.com //
// Compatible Menu Version: <Min: 1400> //
// <Max: 1.7.2.0> //
// <Script Version: 1720> //
//------------------------------------------------------//
var m_oSolpartMenu;
if (m_oSolpartMenu == null)
m_oSolpartMenu = new Array(); //stores all menu objects (SolpartMenu) in array
var m_spm_sBrowser;
var m_spm_sVersion;
function spm_initMyMenu(oXML, oCtl) //Creates SolpartMenu object and calls generate method
{
m_oSolpartMenu[oCtl.id] = new SolpartMenu(oCtl);
m_oSolpartMenu[oCtl.id].GenerateMenuHTML(oXML);
}
//------- Constructor -------//
function SolpartMenu(o)
{
__db(o.id + ' - constructor');
// var me = this; //allow attached events to reference this
//--- Data Properties ---//
this.systemImagesPath=spm_getAttr(o, 'SysImgPath', '');
this.iconImagesPath=spm_getAttr(o, 'IconImgPath', this.systemImagesPath);
this.xml = spm_getAttr(o, 'XML', '');
this.xmlFileName = spm_getAttr(o, 'XMLFileName', '');
//--- Appearance Properties ---//
this.fontStyle=spm_getAttr(o, 'FontStyle', 'font-family: arial;');
this.backColor=spm_getAttr(o, 'BackColor');
this.foreColor=spm_getAttr(o, 'ForeColor');
this.iconBackColor=spm_getAttr(o, 'IconBackColor');
this.hlColor=spm_getAttr(o, 'HlColor', '');
this.shColor=spm_getAttr(o, 'ShColor', '');
this.selColor=spm_getAttr(o, 'SelColor');
this.selForeColor=spm_getAttr(o, 'SelForeColor');
this.selBorderColor=spm_getAttr(o, 'SelBorderColor');
this.menuAlignment = spm_getAttr(o, 'MenuAlignment', 'Left');
this.display=spm_getAttr(o, 'Display', 'horizontal');
this.MBLeftHTML=spm_getAttr(o, 'MBLHTML', '');
this.MBRightHTML=spm_getAttr(o, 'MBRHTML', '');
this.rootArrow = spm_getAttr(o, 'RootArrow', '0');
this.rootArrowImage = spm_getAttr(o, 'RootArrowImage', '');
this.arrowImage = spm_getAttr(o, 'ArrowImage', '');
this.backImage=spm_getAttr(o, 'BackImage', '');
this.supportsTransitions = spm_getAttr(o, 'SupportsTrans', '0');
//--- Transition Properteis ---//
//this.menuEffectsStyle=spm_getAttr(o, 'MenuEffectsStyle', '');
this.menuTransitionLength=spm_getAttr(o, 'MenuTransitionLength', .3);
this.menuTransition=spm_getAttr(o, 'MenuTransition', 'None');
this.menuTransitionStyle=spm_getAttr(o, 'MenuTransitionStyle', '');
this.SolpartMenuTransitionObject = new SolpartMenuTransitionObject();
//--- Behavior Properteis ---//
this.moveable = spm_getAttr(o, 'Moveable', '0');
this.moDisplay=spm_getAttr(o, 'MODisplay', 'HighLight');
this.moExpand=spm_getAttr(o, 'MOExpand', "-1");
this.moutDelay=spm_getAttr(o, 'MOutDelay', "0");
this.minDelay=spm_getAttr(o, 'MInDelay', "0");
this.minDelayType=null;
this.minDelayTimer=null;
this.minDelayObj=null;
if (spm_browserType() == 'safari') //safari has issues with mouseoutdelay...
this.moutDelay = 5000;
this.target=spm_getAttr(o, 'target', "");
this.moScroll=spm_getAttr(o, 'MOScroll', "-1");
//--- Sizing Properties ---//
this.menuBarHeight=spm_fixUnit(spm_getAttr(o, 'MenuBarHeight', '0'));
this.menuItemHeight=spm_fixUnit(spm_getAttr(o, 'MenuItemHeight', '0'));
this.iconWidth=spm_fixUnit(spm_getAttr(o, 'IconWidth', '0'));
this.borderWidth=spm_getAttr(o, 'BorderWidth', '1');
//--- CSS Properties ---//
this.cssMenuContainer=spm_getAttr(o, 'CSSMenuContainer', '');
this.cssMenuBar=spm_getAttr(o, 'CSSMenuBar', '');
this.cssMenuItem=spm_getAttr(o, 'CSSMenuItem', '');
this.cssMenuIcon=spm_getAttr(o, 'CSSMenuIcon', '');
this.cssSubMenu=spm_getAttr(o, 'CSSSubMenu', '');
this.cssMenuBreak=spm_getAttr(o, 'CSSMenuBreak', '');
this.cssMenuItemSel=spm_getAttr(o, 'CSSMenuItemSel', '');
this.cssMenuArrow=spm_getAttr(o, 'CSSMenuArrow', '');
this.cssMenuRootArrow=spm_getAttr(o, 'CSSRootMenuArw', '');
this.cssMenuScrollItem=spm_getAttr(o, 'CSSScrollItem', '');
//for right to left (rtl) menus
this.direction = spm_getCurrentStyle(document.body, 'direction');
this.useIFrames=(spm_getAttr(o, 'useIFrames', '1') != '0' && spm_supportsIFrameTrick());
this.delaySubmenuLoad=(spm_getAttr(o, 'delaySubmenuLoad', '0') != '0' && spm_needsSubMenuDelay());
//---- methods ---//
//this.GenerateMenuHTML=__GenerateMenuHTML;
//----- private ----//
this._m_sNSpace = o.id; //stores namespace for menu
this._m_sOuterTables = ''; //stores HTML for sub menus
this._m_oDOM; //stores XML DOM object
this._m_oMenu = o; //stores container
this._m_oMenuMove; //stores control that is used for moving menu
this._m_oTblMenuBar; //stores menu container
this._m_aOpenMenuID = new Array(); //stores list of menus that are currently displayed
this._m_bMoving=false; //flag to determine menu is being dragged
this._m_dHideTimer = null; //used to time when mouse out occured to auto hide menu based on mouseoutdelay
this._m_oScrollingMenu = null; //used in scrolling menu on mouse over
__db(this._m_oMenu.id + ' - constructor end');
}
//--- Destroys interrnal object references ---//
SolpartMenu.prototype.destroy = function ()
{
this.systemImagesPath = null;
this.iconImagesPath = null;
this.xml = null;
this.xmlFileName = null;
//--- Appearance Properties ---//
this.fontStyle = null;
this.backColor = null;
this.foreColor = null;
this.iconBackColor = null;
this.hlColor = null;
this.shColor = null;
this.selColor = null;
this.selForeColor = null;
this.selBorderColor = null;
this.menuAlignment = null;
this.display = null;
this.rootArrow = null;
this.rootArrowImage = null;
this.arrowImage = null;
this.backImage = null;
//--- Transition Properteis ---//
//this.menuEffectsStyle = null;
this.menuTransitionLength = null;
this.menuTransition = null;
this.SolpartMenuTransitionObject = null;
//--- Behavior Properteis ---//
this.moveable = null;
this.moDisplay = null;
this.moExpand = null;
this.moutDelay = null;
//--- Sizing Properties ---//
this.menuBarHeight = null;
this.menuItemHeight = null;
this.iconWidth = null;
this.borderWidth = null;
//--- CSS Properties ---//
this.cssMenuContainer = null;
this.cssMenuBar = null;
this.cssMenuItem = null;
this.cssMenuIcon = null;
this.cssSubMenu = null;
this.cssMenuBreak = null;
this.cssMenuItemSel = null;
this.cssMenuArrow = null;
this.cssMenuRootArrow = null;
//---- methods ---//
//----- private ----//
m_oSolpartMenu[this._m_sNSpace] = null;
this._m_sNSpace = null; //stores namespace for menu
this._m_sOuterTables = null; //stores HTML for sub menus
this._m_oDOM = null; //stores XML DOM object
this._m_oMenu = null; //stores container
this._m_oMenuMove = null; //stores control that is used for moving menu
this._m_oTblMenuBar = null; //stores menu container
this._m_aOpenMenuID = null; //stores list of menus that are currently displayed
this._m_bMoving = null; //flag to determine menu is being dragged
this._m_dHideTimer = null; //used to time when mouse out occured to auto hide menu based on mouseoutdelay
this._m_oScrollingMenu = null; //used in scrolling menu on mouse over
}
//--- xml document loaded (non-dataisland) ---//
SolpartMenu.prototype.onXMLLoad = function ()
{
this.GenerateMenuHTML(this._m_oDOM);
}
//--- Generates menu HTML through passed in XML DOM ---//
SolpartMenu.prototype.GenerateMenuHTML = function (oXML)
{
__db(this._m_oMenu.id + ' - GenerateMenuHTML');
//'Generates the main menu bar
var sHTML = '';
this._m_sOuterTables = '';
if (oXML == null)
{
if (this._m_oDOM == null)
{
oXML = spm_createDOMDoc();
this._m_oDOM = oXML;
if (this.xml.length)
oXML.loadXML(this.xml);
if (this.xmlFileName.length)
{
oXML.onload = eval('onxmlload' + this._m_sNSpace);
oXML.load(this.xmlFileName);
return; //async load
}
}
}
else
this._m_oDOM = oXML;
if (this.display == "vertical")
{
sHTML += '<table ID="tbl' + this._m_sNSpace + 'MenuBar" CELLPADDING=\'0\' CELLSPACING=\'0\' BORDER="0" CLASS="' + spm_fixCSSForMac(this.getIntCSSName('spmbctr') + this.cssMenuContainer) + '" HEIGHT="100%" STYLE="vertical-align: middle;">\n'; //removed position: relative; for IE and display: block; for Opera
sHTML += MyIIf(this.MBLeftHTML.length, '<tr>\n <td>' + this.MBLeftHTML + '</td>\n</tr>\n', '');
sHTML += MyIIf(Number(this.moveable), '<tr>\n <td ID="td' + this._m_sNSpace + 'MenuMove" height=\'3px\' style=\'cursor: move; ' + spm_getMenuBorderStyle(this) + '\'>' + spm_getSpacer(this) + '</td>\n</tr>\n', '');
sHTML += this.GetMenuItems(this._m_oDOM.documentElement);
sHTML += ' <tr><td HEIGHT="100%">' + spm_getSpacer(this) + '</td>\n' ;
sHTML += ' </tr>\n';
sHTML += MyIIf(this.MBRightHTML.length, '<tr>\n <td>' + this.MBRightHTML + '</td>\n</tr>\n', '');
sHTML += '</table>\n';
}
else
{
sHTML += '<table ID="tbl' + this._m_sNSpace + 'MenuBar" CELLPADDING=\'0\' CELLSPACING=\'0\' BORDER="0" CLASS="' + spm_fixCSSForMac(this.getIntCSSName('spmbctr') + this.cssMenuContainer) + '" WIDTH="100%" STYLE="vertical-align: middle; ">\n'; //removed position: relative; for IE and display: block; for Opera
sHTML += ' <tr>\n';
sHTML += MyIIf(this.MBLeftHTML.length, '<td>' + this.MBLeftHTML + '</td>\n', '');
sHTML += MyIIf(Number(this.moveable), ' <td ID="td' + this._m_sNSpace + 'MenuMove" width=\'3px\' style=\'cursor: move; ' + spm_getMenuBorderStyle(this) + '\'>' + spm_getSpacer(this) + '</td>\n', '');
sHTML += spm_getMenuSpacingImage('left', this);
sHTML += this.GetMenuItems(this._m_oDOM.documentElement);
sHTML += spm_getMenuSpacingImage('right', this);
sHTML += MyIIf(this.MBRightHTML.length, '<td>' + this.MBRightHTML + '</td>\n', '');
sHTML += ' </tr>\n';
sHTML += '</table>\n';
}
this._m_oMenu.innerHTML = sHTML;
this.GenerateSubMenus();
this._m_oMenuMove = spm_getById('td' + this._m_sNSpace + 'MenuMove');
spm_getTags("BODY")[0].onclick = spm_appendFunction(spm_getTags("BODY")[0].onclick, 'm_oSolpartMenu["' + this._m_sNSpace + '"].bodyclick();'); //document.body.onclick = this.bodyclick;
this._m_oTblMenuBar = spm_getById('tbl' + this._m_sNSpace + 'MenuBar');
this.fireEvent('onMenuComplete');
__db(this._m_oMenu.id + ' - GenerateMenuHTML end');
}
SolpartMenu.prototype.GenerateSubMenus = function (oXML)
{
if (this._m_sOuterTables.length > 0)
{
var oDiv = spm_getById(this._m_sNSpace + '_divOuterTables');
if (oDiv == null)
{
alert('It appears that your menu dll is out of sync with your script file.');
return;
}
if (this.delaySubmenuLoad != '0' && document.readyState != 'complete')
return;
oDiv.innerHTML = this._m_sOuterTables;
}
this._m_sOuterTables = '';
}
function spm_getMenuBarEvents(sCtl)
{
return 'onmouseover="m_oSolpartMenu[\'' + sCtl + '\'].onMBMO(this);" onmouseout="m_oSolpartMenu[\'' + sCtl + '\'].onMBMOUT(this);" onclick="m_oSolpartMenu[\'' + sCtl + '\'].onMBC(this, event);" onmousedown="m_oSolpartMenu[\'' + sCtl + '\'].onMBMD(this);" onmouseup="m_oSolpartMenu[\'' + sCtl + '\'].onMBMU(this);"';
}
function spm_getMenuItemEvents(sCtl)
{
return 'onmouseover="m_oSolpartMenu[\'' + sCtl + '\'].onMBIMO(this);" onmouseout="m_oSolpartMenu[\'' + sCtl + '\'].onMBIMOUT(this);" onclick="m_oSolpartMenu[\'' + sCtl + '\'].onMBIC(this, event);"';
}
//--- Returns HTML for menu items (recursive function) ---//
SolpartMenu.prototype.GetMenuItems = function (oParent)
{
var oNode;
var sHTML = '';
var sID;
var sParentID;
var sClickAction;
for (var i = 0; i < oParent.childNodes.length; i++)
{
oNode = oParent.childNodes[i];
if (oNode.nodeType != 3 && oNode.nodeType != 8) //exclude nodeType of Text (Netscape/Mozilla) issue!
{
//'determine if root level item and set parent id accordingly
if (oNode.parentNode.nodeName != "menuitem")
sParentID = "-1";
else
sParentID = oNode.parentNode.getAttribute("id");
if (oNode.nodeName == "menuitem")
sID = oNode.getAttribute("id");
else
sID = "";
__db(sID + ' getmenuitems');
sClickAction = spm_getMenuClickAction(oNode, this);
if (sParentID == "-1") //'if top level menu item
{
if (this.display == "vertical")
sHTML += "<tr>\n"; //'if vertical display then add rows for each top menuitem
if (oNode.nodeName == 'menubreak')
{
if (this.display == "vertical")
sHTML += "<tr>\n"; //'if vertical display then add rows for each top menuitem
var sBreakHTML = spm_getAttr(oNode, 'lefthtml', '') + spm_getAttr(oNode, 'righthtml', '');
if (sBreakHTML.length > 0)
sHTML += ' <td class="' + spm_fixCSSForMac(this.getIntCSSName('spmbrk') + this.cssMenuBreak) + '">' + sBreakHTML + '</td>\n';
else
sHTML += ' <td class="' + spm_fixCSSForMac(this.getIntCSSName('spmbrk') + this.cssMenuBreak) + '">' + spm_getMenuImage('spacer.gif', this, true, ' ') + '</td>\n';
if (this.display == "vertical")
sHTML += "</tr>\n";
}
else
{
sHTML += '<td>\n<table width="100%" CELLPADDING="0" CELLSPACING="0" border="0">\n<tr id="td' + this._m_sNSpace + sID + '" ' + spm_getMenuBarEvents(this._m_sNSpace) + ' class="' + spm_fixCSSForMac(this.getIntCSSName('spmbar spmitm') + this.cssMenuBar + ' ' + this.cssMenuItem + ' ' + spm_getMenuItemCSS(oNode)) + '" savecss="' + spm_getMenuItemCSS(oNode) + '" saveselcss="' + spm_getMenuItemSelCSS(oNode) + '" menuclick="' + sClickAction + '" style="' + spm_getMenuItemStyle('item', oNode) + '">\n';
var sAlign = this.display=='vertical' ? 'align="' + this.menuAlignment + '"' : '';
sHTML += '<td unselectable="on" NOWRAP="NOWRAP" ' + sAlign + ' TITLE="' + spm_getAttr(oNode, 'tooltip', '') + '">' + spm_getImage(oNode, this) + spm_getItemHTML(oNode, 'left', ' ') + spm_getAttr(oNode, 'title', '') + spm_getItemHTML(oNode, 'right') + MyIIf(Number(this.rootArrow) && spm_nodeHasChildren(oNode), '</td>\n<td align="right" class="' + spm_fixCSSForMac(this.getIntCSSName('spmrarw') + this.cssMenuRootArrow) + '">' + spm_getArrow(this.rootArrowImage, this) + "", ' ') + '\n</td>\n</tr>\n</table>\n</td>\n';
}
if (this.display == "vertical")
sHTML += "</tr>\n";
}
else //'submenu - not top level menu item
{
switch(oNode.nodeName)
{
case "menuitem":
{
sHTML += ' <tr ID="tr' + this._m_sNSpace + sID + '" ' + spm_getMenuItemEvents(this._m_sNSpace) + ' parentID="' + sParentID + '" class="' + spm_fixCSSForMac(this.getIntCSSName('spmitm') + this.cssMenuItem + ' ' + spm_getMenuItemCSS(oNode)) + '" savecss="' + spm_getMenuItemCSS(oNode) + '" saveselcss="' + spm_getMenuItemSelCSS(oNode) + '" menuclick="' + sClickAction + '" style="' + spm_getMenuItemStyle('item', oNode) + '">\n';
sHTML += ' <td unselectable="on" id="icon' + this._m_sNSpace + sID + '" class="' + spm_fixCSSForMac(this.getIntCSSName('spmicn') + this.cssMenuIcon) + '" style="' + spm_getMenuItemStyle('image', oNode) + '; ' + spm_getMenuItemStyle('item', oNode) + '">' + spm_getImage(oNode, this) + '</td>\n';
sHTML += ' <td unselectable="on" id="td' + this._m_sNSpace + sID + '" class="' + spm_fixCSSForMac(this.getIntCSSName('spmitm') + this.cssMenuItem + ' ' + spm_getMenuItemCSS(oNode)) + '" savecss="' + spm_getMenuItemCSS(oNode) + '" NOWRAP="NOWRAP" TITLE="' + spm_getAttr(oNode, 'tooltip', '') + '" style="' + spm_getMenuItemStyle('item', oNode) + '">' + spm_getItemHTML(oNode, 'left', '') + spm_getAttr(oNode, 'title', '') + spm_getItemHTML(oNode, 'right', '') + '</td>\n';
sHTML += ' <td unselectable="on" id="arrow' + this._m_sNSpace + sID + '" width="15px" CLASS="' + spm_fixCSSForMac(this.getIntCSSName('spmarw') + this.cssMenuArrow) + '" style="' + spm_getMenuItemStyle('item', oNode) + '">' + MyIIf(spm_nodeHasChildren(oNode), spm_getArrow(this.arrowImage, this), spm_getSpacer(this)) + '</td>\n';
sHTML += ' </tr>\n';
break;
}
case "menubreak":
{
var sBreakHTML = spm_getAttr(oNode, 'lefthtml', '') + spm_getAttr(oNode, 'righthtml', '');
if (sBreakHTML.length > 0)
sHTML += ' <tr><td colspan="3" class="' + spm_fixCSSForMac(this.getIntCSSName('spmbrk') + this.cssMenuBreak) + '">' + sBreakHTML + '</td>\n</tr>\n';
else
sHTML += ' <tr>\n<td style="height: 1px" class="' + spm_fixCSSForMac(this.getIntCSSName('spmicn') + this.cssMenuIcon) + '">' + spm_getMenuImage('spacer.gif', this, true, ' ') + '</td>\n<td colspan="2" class="' + spm_fixCSSForMac(this.getIntCSSName('spmbrk') + this.cssMenuBreak) + '">' + spm_getMenuImage('spacer.gif', this, true, ' ') + '</td>\n</tr>\n';
break;
}
}
}
//'Generate sub menu - note: we are recursively calling ourself
//'netscape renders tables with display: block as having cellpadding!!! therefore using div outside table - LAME!
if (oNode.childNodes.length > 0)
{
var sTag = 'DIV';
var sStyle = '';
if (spm_isMac('ie'))
{
sTag = 'P';
sStyle = 'margin-top:0px; margin-left:0px;'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -