📄 jscookmenu.js
字号:
items[items.length] = _cmSplit;
continue;
}
var item = new Array ();
var currentItem = currentDomItem.firstChild;
for (; currentItem; currentItem = currentItem.nextSibling)
{
// scan for span tag
if (!currentItem.tagName || currentItem.tagName.toLowerCase () != 'span')
continue;
if (!currentItem.firstChild)
item[0] = null;
else
item[0] = currentItem.innerHTML;
break;
}
if (!currentItem)
continue;
for (; currentItem; currentItem = currentItem.nextSibling)
{
// scan for span tag
if (!currentItem.tagName || currentItem.tagName.toLowerCase () != 'a')
continue;
item[1] = currentItem.innerHTML;
item[2] = currentItem.href;
item[3] = currentItem.target;
item[4] = currentItem.title;
if (item[4] == '')
item[4] = null;
break;
}
for (; currentItem; currentItem = currentItem.nextSibling)
{
// scan for span tag
if (!currentItem.tagName || currentItem.tagName.toLowerCase () != 'ul')
continue;
var subMenuItems = cmDrawFromTextSubMenu (currentItem);
for (i = 0; i < subMenuItems.length; ++i)
item[i + 5] = subMenuItems[i];
break;
}
items[items.length] = item;
}
return items;
}
//////////////////////////////////////////////////////////////////////
//
// Mouse Event Handling Functions
//
//////////////////////////////////////////////////////////////////////
//
// action should be taken for mouse moving in to the menu item
//
// Here we just do things concerning this menu item, w/o opening sub menus.
//
function cmItemMouseOver (obj, prefix, isMain, idSub, index)
{
clearTimeout (_cmTimeOut);
if (!obj.cmPrefix)
{
obj.cmPrefix = prefix;
obj.cmIsMain = isMain;
}
var thisMenu = cmGetThisMenu (obj, prefix);
// insert obj into cmItems if cmItems doesn't have obj
if (!thisMenu.cmItems)
thisMenu.cmItems = new Array ();
var i;
for (i = 0; i < thisMenu.cmItems.length; ++i)
{
if (thisMenu.cmItems[i] == obj)
break;
}
if (i == thisMenu.cmItems.length)
{
//thisMenu.cmItems.push (obj);
thisMenu.cmItems[i] = obj;
}
// hide the previous submenu that is not this branch
if (_cmCurrentItem)
{
// occationally, we get this case when user
// move the mouse slowly to the border
if (_cmCurrentItem == obj || _cmCurrentItem == thisMenu)
{
var item = _cmItemList[index];
cmSetStatus (item);
return;
}
var thatPrefix = _cmCurrentItem.cmPrefix;
var thatMenu = cmGetThisMenu (_cmCurrentItem, thatPrefix);
if (thatMenu != thisMenu.cmParentMenu)
{
if (_cmCurrentItem.cmIsMain)
_cmCurrentItem.className = thatPrefix + 'MainItem';
else
_cmCurrentItem.className = thatPrefix + 'MenuItem';
if (thatMenu.id != idSub)
cmHideMenu (thatMenu, thisMenu, thatPrefix);
}
}
// okay, set the current menu to this obj
_cmCurrentItem = obj;
// just in case, reset all items in this menu to MenuItem
cmResetMenu (thisMenu, prefix);
var item = _cmItemList[index];
var isDefaultItem = cmIsDefaultItem (item);
if (isDefaultItem)
{
if (isMain)
obj.className = prefix + 'MainItemHover';
else
obj.className = prefix + 'MenuItemHover';
}
cmSetStatus (item);
}
//
// action should be taken for mouse moving in to the menu item
//
// This function also opens sub menu
//
function cmItemMouseOverOpenSub (obj, prefix, isMain, idSub, orient, index)
{
cmItemMouseOver (obj, prefix, isMain, idSub, index);
if (idSub)
{
var subMenu = cmGetObject (idSub);
cmShowSubMenu (obj, prefix, subMenu, orient);
}
}
//
// action should be taken for mouse moving out of the menu item
//
function cmItemMouseOut (obj, delayTime)
{
if (!delayTime)
delayTime = _cmNodeProperties.delay;
_cmTimeOut = window.setTimeout ('cmHideMenuTime ()', delayTime);
window.defaultStatus = '';
}
//
// action should be taken for mouse button down at a menu item
//
function cmItemMouseDown (obj, index)
{
if (cmIsDefaultItem (_cmItemList[index]))
{
if (obj.cmIsMain)
obj.className = obj.cmPrefix + 'MainItemActive';
else
obj.className = obj.cmPrefix + 'MenuItemActive';
}
}
//
// action should be taken for mouse button down at a menu item
// this is one also opens submenu if needed
//
function cmItemMouseDownOpenSub (obj, index, prefix, orient, idSub)
{
cmItemMouseDown (obj, index);
if (idSub)
{
var subMenu = cmGetObject (idSub);
cmShowSubMenu (obj, prefix, subMenu, orient);
}
}
//
// action should be taken for mouse button up at a menu item
//
function cmItemMouseUp (obj, index)
{
var item = _cmItemList[index];
var link = null, target = '_self';
if (item.length > 2)
link = item[2];
if (item.length > 3 && item[3])
target = item[3];
if (link != null)
{
window.open (link, target);
}
var prefix = obj.cmPrefix;
var thisMenu = cmGetThisMenu (obj, prefix);
var hasChild = (item.length > 5);
if (!hasChild)
{
if (cmIsDefaultItem (item))
{
if (obj.cmIsMain)
obj.className = prefix + 'MainItem';
else
obj.className = prefix + 'MenuItem';
}
cmHideMenu (thisMenu, null, prefix);
}
else
{
if (cmIsDefaultItem (item))
{
if (obj.cmIsMain)
obj.className = prefix + 'MainItemHover';
else
obj.className = prefix + 'MenuItemHover';
}
}
}
//////////////////////////////////////////////////////////////////////
//
// Mouse Event Support Utility Functions
//
//////////////////////////////////////////////////////////////////////
//
// move submenu to the appropriate location
//
// @param obj the menu item that opens up the subMenu
// subMenu the sub menu to be shown
// orient the orientation of the subMenu
//
function cmMoveSubMenu (obj, subMenu, orient)
{
var mode = String (orient);
var p = subMenu.offsetParent;
var subMenuWidth = cmGetWidth (subMenu);
var horiz = cmGetHorizontalAlign (obj, mode, p, subMenuWidth);
if (mode.charAt (0) == 'h')
{
if (mode.charAt (1) == 'b')
subMenu.style.top = (cmGetYAt (obj, p) + cmGetHeight (obj)) + 'px';
else
subMenu.style.top = (cmGetYAt (obj, p) - cmGetHeight (subMenu)) + 'px';
if (horiz == 'r')
subMenu.style.left = (cmGetXAt (obj, p)) + 'px';
else
subMenu.style.left = (cmGetXAt (obj, p) + cmGetWidth (obj) - subMenuWidth) + 'px';
}
else
{
if (horiz == 'r')
subMenu.style.left = (cmGetXAt (obj, p) + cmGetWidth (obj)) + 'px';
else
subMenu.style.left = (cmGetXAt (obj, p) - subMenuWidth) + 'px';
if (mode.charAt (1) == 'b')
subMenu.style.top = (cmGetYAt (obj, p)) + 'px';
else
subMenu.style.top = (cmGetYAt (obj, p) + cmGetHeight (obj) - cmGetHeight (subMenu)) + 'px';
}
}
//
// automatically re-adjust the menu position based on available screen size.
//
function cmGetHorizontalAlign (obj, mode, p, subMenuWidth)
{
var horiz = mode.charAt (2);
if (!(document.body))
return horiz;
var body = document.body;
var browserLeft;
var browserRight;
if (window.innerWidth)
{
// DOM window attributes
browserLeft = window.pageXOffset;
browserRight = window.innerWidth + browserLeft;
}
else if (body.clientWidth)
{
// IE attributes
browserLeft = body.clientLeft;
browserRight = body.clientWidth + browserLeft;
}
else
return horiz;
if (mode.charAt (0) == 'h')
{
if (horiz == 'r' && (cmGetXAt (obj) + subMenuWidth) > browserRight)
horiz = 'l';
if (horiz == 'l' && (cmGetXAt (obj) + cmGetWidth (obj) - subMenuWidth) < browserLeft)
horiz = 'r';
return horiz;
}
else
{
if (horiz == 'r' && (cmGetXAt (obj, p) + cmGetWidth (obj) + subMenuWidth) > browserRight)
horiz = 'l';
if (horiz == 'l' && (cmGetXAt (obj, p) - subMenuWidth) < browserLeft)
horiz = 'r';
return horiz;
}
}
//
// show the subMenu w/ specified orientation
// also move it to the correct coordinates
//
// @param obj the menu item that opens up the subMenu
// subMenu the sub menu to be shown
// orient the orientation of the subMenu
//
function cmShowSubMenu (obj, prefix, subMenu, orient)
{
if (!subMenu.cmParentMenu)
{
// establish the tree w/ back edge
var thisMenu = cmGetThisMenu (obj, prefix);
subMenu.cmParentMenu = thisMenu;
if (!thisMenu.cmSubMenu)
thisMenu.cmSubMenu = new Array ();
//thisMenu.cmSubMenu.push (subMenu);
thisMenu.cmSubMenu[thisMenu.cmSubMenu.length] = subMenu;
}
// position the sub menu
cmMoveSubMenu (obj, subMenu, orient);
subMenu.style.visibility = 'visible';
//
// On IE, controls such as SELECT, OBJECT, IFRAME (before 5.5)
// are window based controls. So, if the sub menu and these
// controls overlap, sub menu would be hidden behind them. Thus
// one needs to turn the visibility of these controls off when the
// sub menu is showing, and turn their visibility back on
// when the sub menu is hiding.
//
if (document.all) // it is IE
{
/* part of Felix Zaslavskiy's fix on hiding controls
not really sure if this part is necessary, but shouldn't
hurt. */
if (!subMenu.cmOverlap)
subMenu.cmOverlap = new Array ();
/*@cc_on @*/
/*@if (@_jscript_version >= 5.5)
@else @*/
cmHideControl ("IFRAME", subMenu);
/*@end @*/
cmHideControl ("SELECT", subMenu);
cmHideControl ("OBJECT", subMenu);
}
}
//
// reset all the menu items to class MenuItem in thisMenu
//
function cmResetMenu (thisMenu, prefix)
{
if (thisMenu.cmItems)
{
var i;
var str;
var items = thisMenu.cmItems;
for (i = 0; i < items.length; ++i)
{
if (items[i].cmIsMain)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -