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

📄 ig_webmenu.js

📁 研究怎样通过手写代码来完成自动生成代码
💻 JS
📖 第 1 页 / 共 5 页
字号:
/* 
Infragistics Hierarchical Menu Script 
Control Version 5.1.20051.37
Copyright (c) 2001-2004 Infragistics, Inc. All Rights Reserved.
Comments:
Functions marked public are for use by developers and are documented and supported.
Functions marked private are for the internal use of the UltraWebMenu component and are not 
documented for use by developers and are not supported for use by developers
*/

var ig_currentMenu;
var ig_menuPopup = null;
var ig_menuObject = null;
var igmenu_initialized = false;

var statcount = 0;
// public - Obtains a menu Item object using its id
function igmenu_getItemById(itemId) {
	var oItem = igmenu_itemarray[itemId];
	if(oItem)
		return oItem;	
	var item=igmenu_getElementById(itemId);
	if(!item)
		return null;
	oItem = new igmenu_initItem(item);
	igmenu_itemarray[itemId] = oItem;
	return oItem;
}

// public - Obtains a menu object using its id
function igmenu_getMenuById(menuId) {
	return igmenu_array[menuId];
}

// public - returns the menu object for the Item Id
function igmenu_getMenuByItemId(itemId) {
	var mn = igmenu_getMenuNameByItemId(itemId);  
	return igmenu_array[mn];
}

// public - returns the Menu Name (mn) from an itemId
function igmenu_getMenuNameByItemId(itemId) {
   var menuName = itemId;
   var strArray = menuName.split("_");
   menuName = strArray[0];
   return menuName;
}

// public - Retrieves an element by its tag name in a browser independant way
function igmenu_getElementById(id) {
	return ig_csom.getElementById(id);
}

// Warning: Private functions for internal component usage only
// The functions in this section are not intended for general use and are not supported
// or documented.

// private - Performed on page initialization
function igmenu_initialize() {
	ig_csom.addEventListener(document, "mousedown", igmenu_mouseDown, true);
	ig_csom.addEventListener(document, "mouseup", igmenu_mouseUp, true);
	ig_csom.addEventListener(document.body, "focus",igmenu_PurgeQueue,true);
	ig_currentMenu = null;
	ig_menuPopup = null;

}

var igmenu_array=[];
var igmenu_itemarray=[];
var igmenu_dropDowns;

// private - initializes the menu object on the client
function igmenu_initMenu(menuId) {
	
   if(!igmenu_initialized) {
	  igmenu_initialize();
	  igmenu_intialized = true;
   }

   var menuElement = igmenu_getElementById(menuId+"_MainM");
   var menu = new igmenu_menu(menuElement,eval("igmenu_"+menuId+"_Menu"));
   igmenu_array[menuId] = menu;
   menu.fireEvent(menu.Events.InitializeMenu,"(\""+menuId+"\");");
   
   if(!ig_csom.IsIE  || ig_csom.IsMac)
		menu.HideDropDowns = false;
		
   if(!ig_csom.IsIE55Plus && menu.HideDropDowns==true && igmenu_dropDowns==null) {
		igmenu_dropDowns = document.all.tags("SELECT");
   }
   /* Now adjust the menu so that the first element is tab able*/
   var tIndex = menu.getTabIndex();
   if (tIndex && tIndex>0)
   {
		var oItem = menu.getZerothMember();
		if (oItem) AdjustTabIndex(null,oItem,false);
   }
   /* END Now adjust the menu so that the first element is tab able*/   
   menu.MenuLoaded=true;
   return menu;
}

// private - constructor for the menu scroll object
function igmenu_scroller(subMenuElement) {
	this.subMenu = subMenuElement;
	this.fullHeight = this.subMenu.offsetHeight;
	this.active = false;
	this.ms = igmenu_getMenuByItemId(this.subMenu.id);
	
	// private - implements the showing and hiding of submenus
	this.addScroll = function() {
		this.scrollDiv = this.subMenu.firstChild
		this.table = this.scrollDiv.firstChild;
		this.topDiv = window.document.createElement("DIV");
		this.topDiv.topDiv = true;
		this.bottomDiv = window.document.createElement("DIV");
		this.bottomDiv.bottomDiv = true;
		
		this.topDiv.style.cssText = "padding-left:46%;";
		this.bottomDiv.style.cssText = "padding-left:46%;";
		
		// add image elements to top and bottom divs
		var img = window.document.createElement("IMG");
		img.src = this.ms.ScrollImageTopDisabled;
		this.topDiv.appendChild(img);
		img = window.document.createElement("IMG");
		img.src = this.ms.ScrollImageBottom;
		this.bottomDiv.appendChild(img);
		
		// top and bottom divs to the document object
		this.subMenu.insertBefore(this.topDiv, this.subMenu.firstChild);
		this.subMenu.appendChild(this.bottomDiv);
		
		if(!ig_csom.isEmpty(this.ms.DefaultItemClass)) {
			this.topDiv.className = this.ms.DefaultItemClass;
			this.bottomDiv.className = this.ms.DefaultItemClass;
		}
		// Add mouse event listeners to top and bottom divs
		ig_csom.addEventListener(this.topDiv, "mouseover", igmenu_onScrollMouseOver, true);
		ig_csom.addEventListener(this.bottomDiv, "mouseover", igmenu_onScrollMouseOver, true);
		ig_csom.addEventListener(this.topDiv, "mouseout", igmenu_onScrollMouseOut, true);
		ig_csom.addEventListener(this.bottomDiv, "mouseout", igmenu_onScrollMouseOut, true);
	}
	this.setScrollHeight = function(scrollHeight) {
		if(scrollHeight >= 0)
			this.scrollDiv.style.height=scrollHeight;
	}
	this.getScrollHeight = function() {
		return this.scrollDiv.style.height;
	}
	this.show = function() {
		if(this.topDiv.innerHTML.indexOf(this.ms.ScrollImageTopDisabled) == -1)
			this.topDiv.innerHTML = "<img src='" + this.ms.ScrollImageTopDisabled + "'>"
		if(this.bottomDiv.innerHTML.indexOf(this.ms.ScrollImageBottom) == -1)
			this.bottomDiv.innerHTML = "<img src='" + this.ms.ScrollImageBottom + "'>"

		this.scrollDiv.scrollTop = 0;
		this.scrollDiv.style.overflow="hidden";
		this.topDiv.style.display="";
		this.topDiv.style.visibility="visible";
		this.bottomDiv.style.display="";
		this.bottomDiv.style.visibility="visible";
		this.active = true;
	}
	this.hide = function() {
		this.topDiv.style.display="none";
		this.topDiv.style.visibility="hidden";
		this.bottomDiv.style.display="none";
		this.bottomDiv.style.visibility="hidden";
		this.subMenu.style.height = this.fullHeight;
		this.scrollDiv.style.overflow="";
		this.active = false;
	}	
	this.addScroll();
}
// private - constructor for the menu object
function igmenu_menu(menuElement,menuProps) {
	this.MenuId = menuElement.id;
	this.MenuElement = menuElement;
	this.Id = menuElement.id;
	this.Element = menuElement;
	this.UniqueId=menuProps[0];
	this.MenuTarget=menuProps[1];
	this.WebMenuStyle=menuProps[2];
	this.HoverClass=menuProps[4];
	this.TopSelectedClass=menuProps[5];
	this.ExpandEffects = new igmenu_expandEffects(menuProps[8], menuProps[9], menuProps[10], menuProps[11], menuProps[12], menuProps[13], menuProps[14]);
	this.CheckedImage=menuProps[15];
	this.UncheckedImage=menuProps[16];
	this.DisabledClass=menuProps[17];
	this.DefaultItemClass=menuProps[18];
	this.ScrollImageTop=menuProps[19];
	this.ScrollImageTopDisabled=menuProps[20];
	this.ScrollImageBottom=menuProps[21];
	this.ScrollImageBottomDisabled=menuProps[22];
	this.LeftHandDisplay=menuProps[23];
	this.CurrentLeftHandDisplay=this.LeftHandDisplay
	this.HideDropDowns=menuProps[24];
	this.TargetUrl=menuProps[25];
	this.TargetFrame=menuProps[26];
	this.getItems = function ()	{
		var itemAr=new Array();
		var itemCount=0;
		var uniqueId = this.getClientUniqueId();
		var item=igmenu_getItemById(uniqueId+"_1");
		if(item == null) {
			for(var i = 2; i < 15; i++) {
				//item = igmenu_getItemById(uniqueId+"_"+i.toString());
				item = igmenu_getItemById(uniqueId+i.toString());				
				if(item != null)
					break;
			}
		}
		while(item)	{
			itemAr[itemCount++]=igmenu_getItemById(item.Id);
			item=item.getNextSibling();
		}
		return itemAr;
	}

	// private
	this.getClientUniqueId = function() {
		var u = this.UniqueId.replace(/:/gi, "");
		u = u.replace(/_/gi, "");
		return u;
	}
	var uniqueId = this.getClientUniqueId();
	this.Events=new igmenu_events(eval("igmenu_"+uniqueId+"_Events"));
	this.MenuLoaded=false;
	this.NeedPostBack=false;
	this.CancelPostBack=false;
	this.TopHoverStarted=false;

	this.ItemQueue = new Array();
	
	// private - Fires an event to client-side script and then to the server if necessary
	this.fireEvent = function (eventObj,eventString)
	{
		var result=false;
		if(eventObj[0]!="")
			result=eval(eventObj[0]+eventString);
		if(this.MenuLoaded && result!=true && eventObj[1]==1 && !this.CancelPostBack)
			this.NeedPostBack=true;
		this.CancelPostBack=false;
		return result;
	}

	// private - displays top level submenus for horizontal positioning
	this.displayHorizontalSubMenu = function (parentItem, MenuId) {
		var subMenu = igmenu_getElementById(MenuId);
		subMenu.parentMenu = igmenu_getSubMenu(parentItem);
		igmenu_treeCreate(this, subMenu);
		this.displaySubMenu(subMenu, parentItem, false);
	}
	
	// private - displays top level submenus for vertical positioning
	this.displayVerticalSubMenu = function (parentItem, MenuId) {
		var subMenu = igmenu_getElementById(MenuId);
		subMenu.parentMenu = igmenu_getSubMenu(parentItem);
		igmenu_treeCreate(this, subMenu);
		this.hoverItem(parentItem);
		this.displaySubMenu(subMenu, parentItem, true);
	}
	
	// private - displays sub menus beneath top-level submenus.
	this.displaySubSubMenu = function (parentItem, MenuId) {
		var subMenu = igmenu_getElementById(MenuId);
		subMenu.parentMenu = igmenu_getSubMenu(parentItem);
		this.clearDescendants(subMenu.parentMenu, true);
		this.displaySubMenu(subMenu, parentItem, true);
		igmenu_menuTreeAdd(subMenu);
	}
	
	/* added for keyboard navigation */
	this.getZerothMember = function()
	{			
		var oItem = null;
		if (this)
		{			
			var oItems = this.getItems();
			for (var iCount=0; oItems&&iCount<oItems.length ;iCount++)
			{
				oItem = oItems[iCount];
				if (oItem.getEnabled()) break;
				else oItem=null;
			}
		}
		return oItem;		
	}

	/* end added for keyboard navigation */
	
	// private - implements the showing and hiding of submenus
	this.displaySubMenu = function(subMenu, parentItem, vertical) {
		var type		= this.ExpandEffects.Type;
		var duration	= this.ExpandEffects.Duration/1000;;
		var opacity		= this.ExpandEffects.Opacity;
		var shadowWidth = this.ExpandEffects.ShadowWidth;
		var shadowColor = this.ExpandEffects.ShadowColor;
		if(subMenu.style.visibility != "hidden")
			return;
			
		if(ig_csom.IsIE55Plus && this.HideDropDowns) {	
			if(subMenu.transPanel==null) {	
				subMenu.transPanel=ig_csom.createTransparentPanel();
			}
		}
		igmenu_callDisplayMenu(true, subMenu.id);
		var mn=igmenu_getMenuNameByItemId(subMenu.id);
		if(this.fireEvent(this.Events.SubMenuDisplay,"(\""+mn+"\",\""+subMenu.id+"\", true)"))
			return;


		if(ig_csom.IsMac || (subMenu.style.filter == null)) {
			subMenu.style.visibility='visible';
			subMenu.style.display="";
		}
		else
		if(type != 'NotSet') {
			subMenu.style.filter = "progid:DXImageTransform.Microsoft."+type+"(duration="+duration+");"
			if(shadowWidth > 0)
				subMenu.style.filter += " progid:DXImageTransform.Microsoft.Shadow(Direction=135, Strength="+shadowWidth+",color="+shadowColor+");"
			if(opacity < 100)
				subMenu.style.filter += " progid:DXImageTransform.Microsoft.Alpha(Opacity="+opacity+");"
			try{
			if(subMenu.filters[0] != null)
	        	subMenu.filters[0].apply();
	       	}catch(ex){}
			subMenu.style.visibility='visible'
			subMenu.style.display="";
			try{
			if(subMenu.filters[0] != null)
				subMenu.filters[0].play();
	       	}catch(ex){}
		}
		else {
			subMenu.runtimeStyle.filter = "";
			try{
			if(shadowWidth > 0)
				subMenu.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.Shadow(Direction=135, Strength="+shadowWidth+",color="+shadowColor+");"
			if(opacity < 100)
				subMenu.runtimeStyle.filter += " progid:DXImageTransform.Microsoft.Alpha(Opacity="+opacity+");"
	       	}catch(ex){}
			subMenu.style.visibility='visible';
			subMenu.style.display="";
		}
				
		if(subMenu.style.width == "") {
			subMenu.style.width = subMenu.offsetWidth + 15;
			if(ig_csom.IsNetscape6 || ig_csom.IsMac) {
				if(subMenu.childNodes.length == 1) {
					subMenu.childNodes[0].style.width = subMenu.style.width;
					subMenu.childNodes[0].childNodes[0].style.width = subMenu.style.width;
			   	}
				else {
					subMenu.childNodes[1].style.width = subMenu.style.width;
					subMenu.childNodes[1].childNodes[0].style.width = subMenu.style.width;
			   	}
			}
			else {
				if(ig_csom.IsIE55Plus) {
					if(subMenu.firstChild != null) {
						subMenu.firstChild.style.width = subMenu.style.width;
						if(subMenu.firstChild.firstChild != null)
							subMenu.firstChild.firstChild.style.width = subMenu.style.width;
					}
				}
			}
		}
		
		// set submenu position	
		var pageWidth	= document.body.clientWidth;		
		var menuWidth	= (ig_csom.IsNetscape6)?subMenu.offsetWidth:subMenu.clientWidth;		
		var pageHeight	= document.body.clientHeight;
		var menuHeight	= subMenu.offsetHeight;
		var scrollTop	= document.body.scrollTop;
		var scrollLeft	= document.body.scrollLeft;
		var menuX		= 0;
		var menuY		= 0;
		
		if(parentItem == null) { // popup menu
			menuX = subMenu.offsetLeft;	
			menuY = subMenu.offsetTop;	
		}
		else 
		if(vertical) { // display next to vertical menu
			menuY = igmenu_getTopPos(parentItem);	
			if(subMenu.parentMenu.scroller != null && subMenu.parentMenu.scroller.active) {
				menuY = menuY - subMenu.parentMenu.scroller.scrollDiv.scrollTop;
			}
			if(this.CurrentLeftHandDisplay==false)
				menuX = igmenu_getLeftPos(parentItem) + parentItem.offsetWidth - 4; 	
			else
				menuX = igmenu_getLeftPos(parentItem) - menuWidth; 	
			
			var switched = this.CurrentLeftHandDisplay != this.LeftHandDisplay; 
			// Check which way to align the menu
			if(this.CurrentLeftHandDisplay==false && !switched) { // align right
				if((menuX + menuWidth) > pageWidth + scrollLeft) {
						this.CurrentLeftHandDisplay=true; // change to left
					menuX = igmenu_getLeftPos(parentItem) - menuWidth; 
				}
			}
			else
			if(this.CurrentLeftHandDisplay==true && !switched) { // aligned left
				if((menuX < 0)) { //- menuWidth) < 0) {
					this.CurrentLeftHandDisplay=false; // change to right
					menuX = igmenu_getLeftPos(parentItem) + parentItem.offsetWidth; 
				}
			}
		}
		else { // display under horizontal menu
			menuX = igmenu_getLeftPos(parentItem); 
			menuY = igmenu_getTopPos(parentItem) + parentItem.offsetHeight+1;	
		}
		
		if(ig_csom.IsIE  && !ig_csom.IsMac) {
			var scrollHeight;
			if(!subMenu.scroller)
				scrollHeight = subMenu.firstChild.firstChild.scrollHeight;
			else
				scrollHeight = subMenu.scroller.table.scrollHeight;
			if(scrollHeight > pageHeight - 4) {
				if(!subMenu.scroller) {
	 				subMenu.scroller = new igmenu_scroller(subMenu);
				}
				subMenu.scroller.show();
				var divsHeight = subMenu.scroller.topDiv.offsetHeight + subMenu.scroller.bottomDiv.offsetHeight + 8;
				subMenu.scroller.setScrollHeight(pageHeight - divsHeight);
				menuHeight = subMenu.offsetHeight;
			}

⌨️ 快捷键说明

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