⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu_click.js

📁 找了很久才找到到源代码
💻 JS
📖 第 1 页 / 共 2 页
字号:
<%@page buffer="none" session="false" import="java.util.*, org.opencms.jsp.*" %><%

// initialize action element to access API
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);

// determine JS version to build from requested URI
boolean isMouseOver = cms.getRequestContext().getUri().endsWith("over.js");

%>//********************************************************
// Do not remove this notice.
//
// Copyright 2000-2004 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//********************************************************
// Modified by Andreas Zahner (a.zahner@alkacon.com)
//********************************************************

//----------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------

function Browser() {

	var ua, s, i;

	this.isIE    = false;  // Internet Explorer
	this.isOP    = false;  // Opera
	this.isNS    = false;  // Netscape
	this.version = null;

	ua = navigator.userAgent;

	s = "Opera";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isOP = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	// Treat any other "Gecko" browser as Netscape 6.1.

	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		return;
	}

	s = "MSIE";
	if ((i = ua.indexOf(s))) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
}

var browser = new Browser();

//----------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------

var activeButton = null;

<% 
	if (! isMouseOver) {
%>
// Capture mouse clicks on the page so any active button can be deactivated.

if (browser.isIE)
	document.onmousedown = pageMousedown;
else
	document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {

	var el;

	// If there is no active button, exit.

	if (activeButton == null)
		return;

	// Find the element that was clicked on.

	if (browser.isIE)
		el = window.event.srcElement;
	else
		el = (event.target.tagName ? event.target : event.target.parentNode);

	// If the active button was clicked on, exit.

	if (el == activeButton)
		return;

	// If the element is not part of a menu, reset and clear the active
	// button.

	if (getContainerWith(el, "DIV", "menu") == null) {
		resetButton(activeButton);
		activeButton = null;
	}
}
<%
	}
%>

function buttonClick(event, menuId) {

	var button;
	try {
		// Get the target button element.
	
		if (browser.isIE)
			button = window.event.srcElement;
		else
			button = event.currentTarget;
	
		// Blur focus from the link to remove that annoying outline.
	
		button.blur();
	
		// Associate the named menu to this button if not already done.
		// Additionally, initialize menu display.
	
		if (button.menu == null) {
			button.menu = document.getElementById(menuId);
			if (button.menu.isInitialized == null)
				menuInit(button.menu);
		}
	
	<%
		if (isMouseOver) {
	%>
		// [MODIFIED] Added for activate/deactivate on mouseover.
	
		// Set mouseout event handler for the button, if not already done.
	
		if (button.onmouseout == null)
			button.onmouseout = buttonOrMenuMouseout;
	
		// Exit if this button is the currently active one.
	
		if (button == activeButton)
			return false;
	
		// [END MODIFIED]
	<%
		}
	%>
	
		// Reset the currently active button, if any.
	
		if (activeButton != null) {
			resetButton(activeButton);}
	
		// Activate this button, unless it was the currently active one.
	
		if (button != activeButton) {
			depressButton(button);
			activeButton = button;
		}
		else {<%
		if (! isMouseOver) {
	%>
			// AZ: open link when pressing top menu button again
			if (activeButton.tagName == "IMG" || activeButton.tagName == "img") {
				document.location.href = activeButton.parentNode.href;
			} else {
				document.location.href = activeButton.href;
			}
			// /AZ
	<% 
		} 
	%>
			activeButton = null;	
		}
	} catch (e) {}
	
	return false;
}

function buttonMouseover(event, menuId) {

	var button;
<%
	if (isMouseOver) {
%>
	// [MODIFIED] Added for activate/deactivate on mouseover.

	// Activates this button's menu if no other is currently active.

	if (activeButton == null) {
		buttonClick(event, menuId);
		return;
	}

	// [END MODIFIED]
<%
	}
%>

	// Find the target button element.

	if (browser.isIE)
		button = window.event.srcElement;
	else
		button = event.currentTarget;

	// If any other button menu is active, make this one active instead.

	if (activeButton != null && activeButton != button)
		buttonClick(event, menuId);
}

function depressButton(button) {

	var x, y;

	// Update the button's style class to make it look like it's depressed.

	button.className += " menuButtonActive";
	
<%
	if (isMouseOver) {
%>

	// [MODIFIED] Added for activate/deactivate on mouseover.

	// Set mouseout event handler for the button, if not already done.

	if (button.onmouseout == null)
		button.onmouseout = buttonOrMenuMouseout;
	if (button.menu.onmouseout == null)
		button.menu.onmouseout = buttonOrMenuMouseout;

	// [END MODIFIED]
<%
	}
%>

	// Position the associated drop down menu under the button and show it.

	x = getPageOffsetLeft(button);
	y = getPageOffsetTop(button) + button.offsetHeight;

	// For IE, adjust position.

	if (browser.isIE) {
		x += button.offsetParent.clientLeft;
		y += button.offsetParent.clientTop;
	}
	
	// AZ: corrected IE position error and NS position error on non image menubar links
	var childNodeName = "";
	try {
		if (browser.isNS) {
			// check if there is an image child node in Mozilla based browsers
			childNodeName = button.childNodes[0].tagName;
		}
	} catch (e) {}
		if (browser.isIE) {
		y += 1;
	}
	// /AZ
	
	button.menu.style.left = x + "px";
	button.menu.style.top  = y + "px";
	
	if (browser.isNS) {
		// AZ: workaround to avoid display issues in NS based browsers (disabled)
		//tempMenu = button.menu;
		//setTimeout("showMainMenu();", 0);
	} else {
		//button.menu.style.visibility = "visible";
	}
	button.menu.style.visibility = "visible";
	
	// For IE; size, position and show the menu's IFRAME as well.

	if (button.menu.iframeEl != null) {
		button.menu.iframeEl.style.left = button.menu.style.left;
		button.menu.iframeEl.style.top  = button.menu.style.top;
		button.menu.iframeEl.style.width  = button.menu.offsetWidth + "px";
		button.menu.iframeEl.style.height = button.menu.offsetHeight + "px";
		button.menu.iframeEl.style.display = "";
	}
}

function resetButton(button) {

	// Restore the button's style class.

	removeClassName(button, "menuButtonActive");

	// Hide the button's menu, first closing any sub menus.

	if (button.menu != null) {
		closeSubMenu(button.menu);
		button.menu.style.visibility = "hidden";

		// For IE, hide menu's IFRAME as well.

		if (button.menu.iframeEl != null)
			button.menu.iframeEl.style.display = "none";
	}
}

//----------------------------------------------
// Code to handle the menus and sub menus.
//----------------------------------------------

function menuMouseover(event) {

	var menu;

	// Find the target menu element.

	if (browser.isIE)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -