📄 zpmenu-core.js
字号:
menu.style.visibility = 'inherit'; if (menu.__zp_dropshadow) { menu.__zp_dropshadow.style.visibility = 'inherit'; } } for (var ii = 0; ii < tree.animations.length; ii++) { tree.animations[ii](menu, menu.__zp_anim_counter); if (menu.__zp_dropshadow && tree.animations[ii] != Zapatec.Menu.animations.fade) { tree.animations[ii](menu.__zp_dropshadow, menu.__zp_anim_counter); } } // Iterate if (!(show && menu.__zp_anim_counter == 100)) { // Prevent infinite loop menu.__zp_anim_counter += tree.config.animSpeed * (show ? 1 : -1); if (menu.__zp_anim_counter > 100) { // Correction to show menu properly menu.__zp_anim_counter = 100; menu.__zp_anim_timer = setTimeout(function() { tree.treeSetDisplay(menu, show); }, 50); } else if (menu.__zp_anim_counter <= 0) { // Hide menu menu.__zp_anim_counter = 0; menu.style.visibility = 'hidden'; menu.style.left = '-9999px'; menu.style.top = '-9999px'; if (menu.__zp_dropshadow) { menu.__zp_dropshadow.style.visibility = 'hidden'; menu.__zp_dropshadow.style.left = '-9999px'; menu.__zp_dropshadow.style.top = '-9999px'; } } else { // Next iteration menu.__zp_anim_timer = setTimeout(function() { tree.treeSetDisplay(menu, show); }, 50); } }};/** * Attached to mouseover event of top menu items. * @private */Zapatec.Menu.prototype.mouseOver = function(sId) { // Get item var oEl = document.getElementById(sId); if (oEl) { // Get tree var oTree = oEl.__zp_tree || oEl.firstChild.__zp_tree; if (oTree) { oTree = Zapatec.Menu.all[oTree]; if (oTree) { oTree.itemMouseHandler(oEl.__zp_item, Zapatec.Menu.MOUSEOVER); } } }};/** * Global event handler that gets called when a menu item is moused over. * @private */Zapatec.Menu.onItemMouseOver = function() { // Loop up the DOM, dispatch event to correct source item. var item = this, tree = null; while (item && item != document.body) { var t_id = item.__zp_tree || item.firstChild.__zp_tree; if (t_id) tree = Zapatec.Menu.all[t_id]; var itemClassName = item.className; if (/zpMenu-item/.test(itemClassName) && !/zpMenu-item-hr/.test(itemClassName)) { tree.itemMouseHandler(item.__zp_item, Zapatec.Menu.MOUSEOVER); } item = tree && item.__zp_treeid ? tree.items[item.__zp_item] : item.parentNode; } return true; // To make tooltips work in Opera};/** * Attached to mouseout event of top menu items. * @private */Zapatec.Menu.prototype.mouseOut = function(sId) { // Get item var oEl = document.getElementById(sId); if (oEl) { // Get tree var oTree = oEl.__zp_tree || oEl.firstChild.__zp_tree; if (oTree) { oTree = Zapatec.Menu.all[oTree]; if (oTree) { oTree.itemMouseHandler(oEl.__zp_item, Zapatec.Menu.MOUSEOUT); } } }};/** * Global event handler that gets called when a menu item is moused out. * @private */Zapatec.Menu.onItemMouseOut = function() { var item = this, tree = null; while (item && item != document.body) { var t_id = item.__zp_tree || item.firstChild.__zp_tree; if (t_id) tree = Zapatec.Menu.all[t_id]; var itemClassName = item.className; if ( /zpMenu-item/.test(itemClassName) && !/zpMenu-item-hr/.test(itemClassName) && // Top item was not unselected with Esc button !(/zpMenu-level-1/.test(itemClassName) && !/zpMenu-item-selected/.test(itemClassName)) ) { tree.itemMouseHandler(item.__zp_item, Zapatec.Menu.MOUSEOUT); } item = tree && item.__zp_treeid ? tree.items[item.__zp_item] : item.parentNode; } return false;};/** * Global event handler that gets called when a menu item is clicked, to make * the whole item clickable. * @private */Zapatec.Menu.onItemClick = function(ev) { var item = this; if (!/zpMenuDisabled/.test(item.className)) { while (item && item != document.body) { if (item.nodeName && item.nodeName.toLowerCase() == 'a') { return true; } if (/zpMenu-item/.test(item.className)) { var objMenu = Zapatec.Menu.all[item.__zp_tree]; if (!objMenu.config.preventDoubleCall){ objMenu.called = false; } if (!objMenu.called) { // Show-on-click mode if (objMenu.config.onClick && item.__zp_subtree && (/zpMenu-top/.test(objMenu.trees[item.__zp_parent].className))) { objMenu.itemMouseHandler(item.__zp_item, Zapatec.Menu.CLICK); return Zapatec.Utils.stopEvent(ev); } // Otherwise navigate the page var itemLink = item.getElementsByTagName('a'); var itemInput = item.getElementsByTagName('input'); var itemSelect = item.getElementsByTagName('select'); if (itemLink && itemLink.item(0) && itemLink.item(0).getAttribute('href') && itemLink.item(0).getAttribute('href') != '#' && itemLink.item(0).getAttribute('href') != window.document.location.href + '#' && itemLink.item(0).getAttribute('href') != 'javascript:void(0)') { var href = itemLink.item(0).getAttribute('href'); var target = itemLink.item(0).getAttribute('target'); if (objMenu.config.rememberPath || objMenu.config.pathCookie != '__zp_item') { // Save path in cookies Zapatec.Utils.writeCookie(objMenu.config.pathCookie, item.__zp_item); } try { ev || (ev = window.event); if (target) { window.open(href, target); } else if (ev && ev.shiftKey) { window.open(href, "_blank"); } else { window.location.href = href; // may raise exception in Mozilla } } catch(e) {}; if (objMenu.config.triggerEvent) { objMenu.hideMenu(); } else { // Collapse all submenus objMenu.collapseAll(); // Unselect top item while (Zapatec.Menu.selectedItemsStack.length) { var oTopItem = Zapatec.Menu.selectedItemsStack.pop(); oTopItem.onmouseout(); } } } else if (itemInput && itemInput.item(0)) { var inp = itemInput.item(0); var type = inp.getAttribute('type'); if (type == 'checkbox') { if (inp.checked) { inp.checked = false; } else { inp.checked = true; } } else if (type == 'radio') { inp.checked = true; } } else if (itemSelect && itemSelect.item(0)) { return true; // Pass through } else if (item.__zp_subtree) { objMenu.itemMouseHandler(item.__zp_item, Zapatec.Menu.CLICK); } else if (objMenu.config.triggerEvent) { objMenu.hideMenu(); } if (objMenu.config.preventDoubleCall){ objMenu.called = true; } return Zapatec.Utils.stopEvent(ev); } } item = item.parentNode; } } return false;};/** * Called from the mouse over/out event handlers to process the mouse event and * correctly manage timers. * * @private * @param {string} item_id Item ID * @param {number} type 0 = mouseout, 1 = mouseover, 2 = click */Zapatec.Menu.prototype.itemMouseHandler = function(item_id, type) { if (type) { // Mouseover or click // Put this menu on top this.putOnTop(); } else { // Mouseout // Restore zIndex this.restoreZIndex(); } var item = this.items[item_id]; if (!item) return; var menu = this._getTree(item.__zp_parent); // If slide animation and Opera, skip mouseover and mouseout events while // animating subtree because current item may receive fake mouseout even when // mouse pointer is over it and loose cursor. Other solution is needed because // submenu may stay expanded due to missing real mouseout event. if (type < 2 && window.opera && this.config.slide) { var objSubtree = this._getTree(item.__zp_subtree); if (objSubtree && objSubtree.__zp_anim_counter && objSubtree.__zp_anim_counter < 100) { return; } } // Record an item as lit/shown, and dim/hide any previously lit items. if (menu && menu.__zp_activeitem != item_id) { if (menu.__zp_activeitem) { var lastItem = this.items[menu.__zp_activeitem]; clearTimeout(lastItem.__zp_dimtimer); clearTimeout(lastItem.__zp_mousetimer); var objMenu = this; setTimeout(function() { Zapatec.Menu.unselectItem(lastItem); // Threading bugfix for some menus remaining visible. if (lastItem.__zp_state) objMenu.toggleItem(lastItem.__zp_item, false); Zapatec.Menu.selectItem(item); }, 0); } else { setTimeout(function() { Zapatec.Menu.selectItem(item); }, 0); } menu.__zp_activeitem = item_id; } // Set a timer to dim this item when the whole menu hides. clearTimeout(item.__zp_dimtimer); if (type == Zapatec.Menu.MOUSEOUT) { item.__zp_dimtimer = setTimeout(function() { Zapatec.Menu.unselectItem(item); if (menu.__zp_activeitem == item_id) menu.__zp_activeitem = ''; }, this.config.hideDelay); } // Stop any pending show/hide action. clearTimeout(item.__zp_mousetimer); // Check if this is a click on a first-level menu item. if (this.config.onClick && !this.clickDone) { if (/zpMenu-top/.test(this.trees[item.__zp_parent].className) && (type == Zapatec.Menu.MOUSEOVER)) return; // Set the flag that enables further onmouseover activity. if (type == Zapatec.Menu.CLICK) this.clickDone = true; } // Setup show/hide timers. if (!item.__zp_state && type) { item.__zp_mousetimer = setTimeout('Zapatec.Menu.all["' + item.__zp_tree + '"].itemShow("' + item.__zp_item + '")', (this.config.showDelay || 1)); } else if (item.__zp_state && !type) { item.__zp_mousetimer = setTimeout('Zapatec.Menu.all["' + item.__zp_tree + '"].itemHide("' + item.__zp_item + '")', (this.config.hideDelay || 1)); }};/** * Called from the itemMouseHandler() after a timeout; positions and shows * a designated item's branch of the menu. * * @private * @param {string} item_id Item ID to show */Zapatec.Menu.prototype.itemShow = function(item_id) { var item = this.items[item_id]; if (/zpMenuDisabled/.test(item.className)) { return; } var subMenu = this._getTree(item.__zp_subtree); if (!subMenu) { return; } var parMenu = this._getTree(item.__zp_parent); // Setting visible here works around MSIE bug where // offsetWidth/Height are initially zero. if (!subMenu.offsetHeight) { subMenu.style.visibility = 'visible'; } // In Opera z-index is not inherited by default if (subMenu.style.zIndex === '') { subMenu.style.zIndex = 'inherit'; } var subMenuBorderLeft, subMenuBorderTop; if (typeof subMenu.clientLeft != 'undefined') { // IE & Opera subMenuBorderLeft = subMenu.clientLeft; subMenuBorderTop = subMenu.clientTop; } else { // Mozilla subMenuBorderLeft = (subMenu.offsetWidth - subMenu.clientWidth) / 2; subMenuBorderTop = (subMenu.offsetHeight - subMenu.clientHeight) / 2; } var fc = subMenu.firstChild; var subMenuMarginLeft = fc.offsetLeft; var subMenuMarginTop = fc.offsetTop; // Acquire browser dimensions var scrollX = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft || 0; var scrollY = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop || 0; var objWindowSize = Zapatec.Utils.getWindowSize(); var winW = objWindowSize.width; var winH = objWindowSize.height; // Adjust sub-menu width and height if (!subMenu.style.width || !subMenu.style.height) { var maxHeight = winH - 7; if (subMenu.offsetHeight > maxHeight) { // Need scrolling // iSubMenuOffsetHeight is needed because IE 5.0 delays with offsetHeight // calculation after element is changed var iSubMenuOffsetHeight = subMenu.offsetHeight; fc.__zp_first = fc.firstChild; fc.__zp_last = fc.lastChild; var objUp = Zapatec.Utils.createElement("div"); objUp.__zp_tree = fc.firstChild.__zp_tree; objUp.className = 'zpMenuScrollUpInactive'; objUp.__zp_mouseover = false; objUp.__zp_timer = null; // Up arrow handler var funcMoveUp = function() { var objContainer = objUp.parentNode; var iContainerHeight = objContainer.parentNode.clientHeight; var objUpArrow = objContainer.firstChild; var objDownArrow = objContainer.lastChild; // Check if we can move up if (objContainer.__zp_first.previousSibling != objUpArrow) { // Show first item if (objContainer.__zp_first.style.height) { // Partly hidden objContainer.__zp_first.style.height = ''; objContainer.__zp_first.style.overflow = ''; } else { // Completely hidden objContainer.__zp_first = objContainer.__zp_first.previousSibling; objContainer.__zp_first.style.display = 'bl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -