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

📄 menu4.js

📁 java版源代码,里面包含很多源代码,大家可以看看.
💻 JS
📖 第 1 页 / 共 4 页
字号:
var _MenuImagesDir = _imgDir+"menu/";var menuCache = {	_count:		0,	_idPrefix:	"-menu-cache-",	getId:	function () {		return this._idPrefix + this._count++;	},	remove:	function ( o ) {		delete this[ o.id ];	}};////////////////////////////////////////////////////////////////////////////////////// Menu//function Menu() {	this.items = [];	this.parentMenu = null;	this.parentMenuItem = null;	this.popup = null;	this.shownSubMenu = null;	this._aboutToShowSubMenu = false;	this.selectedIndex = -1;	this._drawn = false;	this._scrollingMode = false;	this._showTimer = null;	this._closeTimer = null;	this._onCloseInterval = null;	this._closed = true;	this._closedAt = 0;	this._cachedSizes = {};	this._measureInvalid = true;	this.id = menuCache.getId();	menuCache[ this.id ] = this;}Menu.prototype.cssFile = _MenuImagesDir+"menu.css";Menu.prototype.cssText = null;Menu.prototype.mouseHoverDisabled = true;Menu.prototype.showTimeout = 250;Menu.prototype.closeTimeout = 250;Menu.keyboardAccelKey = 27;				// the keyCode for the key tp activateMenu.keyboardAccelKey2 = 121;			// the menubarMenu.keyboardAccelProperty = "ctrlKey";	// when this property is true default										// actions will be canceled on a menu// Use -1 to disable keyboard invoke of the menubar// Use "" to allow all normal keyboard commands inside the menusMenu.prototype.add = function ( mi, beforeMi ) {	if ( beforeMi != null ) {		var items = this.items;		var l = items.length;		var i = 0;		for ( ; i < l; i++ ) {			if ( items[i] == beforeMi )				break;		}		this.items = items.slice( 0, i ).concat( mi ).concat( items.slice( i, l ) );		// update itemIndex		for (var j = i; j < l + 1; j++)			this.items[j].itemIndex = j;	}	else {		this.items.push( mi );		mi.itemIndex = this.items.length - 1;	}	mi.parentMenu = this;	if ( mi.subMenu ) {		mi.subMenu.parentMenu = this;		mi.subMenu.parentMenuItem = mi;	}	return mi;};Menu.prototype.remove = function ( mi ) {	var res = [];	var items = this.items;	var l = items.length;	for (var i = 0; i < l; i++) {		if ( items[i] != mi ) {			res.push( items[i] );			items[i].itemIndex = res.length - 1;		}	}	this.items = res;	mi.parentMenu = null;	return mi;};Menu.prototype.toHtml = function () {	var items = this.items;	var l = items.length	var itemsHtml = new Array( l );	for (var i = 0; i < l; i++)		itemsHtml[i] = items[i].toHtml();	return  "<html><head>" +			(this.cssText == null ?				"<link id=\"_CSS0\" type=\"text/css\" rel=\"StyleSheet\" href=\"" + this.cssFile + "\" />" :				"<style type=\"text/css\">" + this.cssText + "</style>") +			"</head><body class=\"menu-body\">" +			"<div class=\"outer-border\"><div class=\"inner-border\">" +			"<table id=\"scroll-up-item\" cellspacing=\"0\" style=\"display: none\">" +			"<tr class=\"disabled\"><td>" +			"<span class=\"disabled-container\"><span class=\"disabled-container\">" +			"5" +			"</span></span>" + "</td></tr></table>" +			"<div id=\"scroll-container\">" +			"<table cellspacing=\"0\">" +			itemsHtml.join( "" ) +			"</table>" +			"</div>" +			"<table id=\"scroll-down-item\" cellspacing=\"0\" style=\"display: none\">" +			"<tr><td>" +			"<span class=\"disabled-container\"><span class=\"disabled-container\">" +			"6" +			"</span></span>" +			"</td></tr></table>" +			"</div></div>" +			"</body></html>";};Menu.prototype.createPopup = function () {	var w;	var pm = this.parentMenu;	if ( pm == null )		w = window;	else		w = pm.getDocument().parentWindow;	this.popup = w.createPopup();};Menu.prototype.getMeasureDocument = function () {	if ( this.isShown() && this._drawn )		return this.getDocument();	var mf = Menu._measureFrame;	if ( mf == null ) {		// should be top document		mf = Menu._measureFrame = document.createElement("IFRAME");		var mfs = mf.style;		mfs.position = "absolute";		mfs.visibility = "hidden";		mfs.left = "-100px";		mfs.top = "-100px";		mfs.width = "10px";		mfs.height = "10px";		mf.frameBorder = 0;		document.body.appendChild( mf );	}	var d = mf.contentWindow.document	if ( Menu._measureMenu == this && !this._measureInvalid )		return d;	d.open( "text/html", "replace" );	d.write( this.toHtml() );	d.close();	Menu._measureMenu = this;	this._measureInvalid = false;	return d;};Menu.prototype.getDocument = function () {	if ( this.popup )		return this.popup.document;	else		return null;};Menu.prototype.getPopup = function () {	if ( this.popup == null )		this.createPopup();	return this.popup;};Menu.prototype.invalidate = function () {	if ( this._drawn ) {		// do some memory cleanup		if ( this._scrollUpButton )			this._scrollUpButton.destroy();		if ( this._scrollDownButton )			this._scrollDownButton.destroy();		var items = this.items;		var l = items.length;		var mi;		for ( var i = 0; i < l; i++ ) {			mi = items[i];			mi._htmlElement_menuItem = null;			mi._htmlElement = null;		}		this.detachEvents();	}	this._drawn = false;	this.resetSizeCache();	this._measureInvalid = true;};Menu.prototype.redrawMenu = function () {	this.invalidate();	this.drawMenu();};Menu.prototype.drawMenu = function () {	if ( this._drawn ) return;	this.getPopup();	var d = this.getDocument();	d.open( "text/html", "replace" );	d.write( this.toHtml() );	d.close();	this._drawn = true;	// set up scroll buttons	var up = d.getElementById( "scroll-up-item" );	var down = d.getElementById( "scroll-down-item" );	var scrollContainer = d.getElementById( "scroll-container" );	new ScrollButton( up, scrollContainer, 8 );	new ScrollButton( down, scrollContainer, 2 );	// bind menu items to the table rows	var rows = scrollContainer.firstChild.tBodies[0].rows;	var items = this.items;	var l = rows.length;	var mi;	for ( var i = 0; i < l; i++ ) {		mi = items[i];		rows[i]._menuItem = mi;		mi._htmlElement = rows[i];	}	// hook up mouse	this.hookupMenu( d );};Menu.prototype.show = function ( left, top, w, h ) {	var pm = this.parentMenu;	if ( pm )		pm.closeAllSubs( this );	var wasShown = this.isShown();	if ( typeof this.onbeforeshow == "function" && !wasShown){		this.onbeforeshow();	}	this.drawMenu();	/*	if(this.cssFile!=_imgDir+"menu/menu.css"){		var a = this.popup.document.getElementById("_CSS0");		a.href=_imgDir+"menu/menu.css";		this.cssFile=_imgDir+"menu/menu.css";	}		this.updateSizeCache(true);	*/	if ( left == null ) left = 0;	if ( top == null ) top = 0;	w = w || Math.min( window.screen.width, this.getPreferredWidth() );	h = h || Math.min( window.screen.height, this.getPreferredHeight() );			this.popup.show( left, top, w, h );	// work around a bug that sometimes occured with large pages when	// opening the first menu	if ( this.getPreferredWidth() == 0 ) {		this.invalidate();		this.show( left, top, w, h );		return;	}	this.fixScrollButtons();	this.fixScrollEnabledState();	// clear selected item	if ( this.selectedIndex != -1 ) {		if ( this.items[ this.selectedIndex ] )			this.items[ this.selectedIndex ].setSelected( false );	}	if ( pm ) {		pm.shownSubMenu = this;		pm._aboutToShowSubMenu = false;	}	window.clearTimeout( this._showTimer );	window.clearTimeout( this._closeTimer );	this._closed = false;	this._startClosePoll();	if ( typeof this.onshow == "function" && !wasShown && this.isShown() )		this.onshow();};Menu.prototype.isShown = function () {	this._checkCloseState();	return this.popup != null && this.popup.isOpen;};Menu.prototype.fixSize = function () {	var w = Math.min( window.screen.width, this.getPreferredWidth() );	var h = Math.min( window.screen.height, this.getPreferredHeight() );	var l = Math.max( 0, this.getLeft() );	var t = Math.max( 0, this.getTop() );	this.popup.show( l, t, w, h );};Menu.prototype.getWidth = function () {	var d = this.getDocument();	if ( d != null )		return d.body.offsetWidth;	else		return 0;};Menu.prototype.getHeight = function () {	var d = this.getDocument();	if ( d != null )		return d.body.offsetHeight;	else		return 0;};Menu.prototype.getPreferredWidth = function () {	this.updateSizeCache();	return this._cachedSizes.preferredWidth;};Menu.prototype.getPreferredHeight = function () {	this.updateSizeCache();	return this._cachedSizes.preferredHeight;};Menu.prototype.getLeft = function () {	var d = this.getDocument();	if ( d != null )		return d.parentWindow.screenLeft;	else		return 0;};Menu.prototype.getTop = function () {	var d = this.getDocument();	if ( d != null )		return d.parentWindow.screenTop;	else		return 0;};// Depreciated. Use show insteadMenu.prototype.setLeft = function ( l ) {	throw new Error("Depreciated. Use show instead");	//var t = this.getTop();	//this.setLocation( l, t );};// Depreciated. Use show insteadMenu.prototype.setTop = function ( t ) {	throw new Error("Depreciated. Use show instead");	//var l = this.getLeft();	//this.setLocation( l, t );};// Depreciated. Use show insteadMenu.prototype.setLocation = function ( l, t ) {	throw new Error("Depreciated. Use show instead");	//var w = this.getWidth();	//var h = this.getHeight();	//this.popup.show( l, t, w, h );};// Depreciated. Use show insteadMenu.prototype.setRect = function ( l, t, w, h ) {	throw new Error("Depreciated. Use show instead");	//this.popup.show( l, t, w, h );};Menu.prototype.getInsetLeft = function () {	this.updateSizeCache();	return this._cachedSizes.insetLeft;};Menu.prototype.getInsetRight = function () {	this.updateSizeCache();	return this._cachedSizes.insetRight;};Menu.prototype.getInsetTop = function () {	this.updateSizeCache();	return this._cachedSizes.insetTop;};Menu.prototype.getInsetBottom = function () {	this.updateSizeCache();	return this._cachedSizes.insetBottom;};Menu.prototype.areSizesCached = function () {	var cs = this._cachedSizes;	return this._drawn &&		"preferredWidth" in cs &&		"preferredHeight" in cs &&		"insetLeft" in cs &&		"insetRight" in cs &&		"insetTop" in cs &&		"insetBottom" in cs;};// depreciatedMenu.prototype.cacheSizes = function ( bForce ) {	return updateSizeCache( bForce );};Menu.prototype.resetSizeCache = function () {	this._cachedSizes = {};};Menu.prototype.updateSizeCache = function ( bForce ) {		if ( this.areSizesCached() && !bForce){			return;	}		var d = this.getMeasureDocument();	var body = d.body;		var cs = this._cachedSizes = {};	// reset	var scrollContainer = d.getElementById( "scroll-container" );	// preferred width	cs.preferredWidth = d.body.scrollWidth;	// preferred height	scrollContainer.style.overflow = "visible";	cs.preferredHeight = body.firstChild.offsetHeight; //body.scrollHeight;	scrollContainer.style.overflow = "hidden";	// inset left	cs.insetLeft = posLib.getLeft( scrollContainer );	// inset right	cs.insetRight = body.scrollWidth - posLib.getLeft( scrollContainer ) -					scrollContainer.offsetWidth;	// inset top	var up = d.getElementById( "scroll-up-item" );	if ( up.currentStyle.display == "none" )		cs.insetTop = posLib.getTop( scrollContainer );	else		cs.insetTop = posLib.getTop( up );	// inset bottom	var down = d.getElementById( "scroll-down-item" );	if ( down.currentStyle.display == "none" ) {		cs.insetBottom = body.scrollHeight - posLib.getTop( scrollContainer ) -						scrollContainer.offsetHeight;	}	else {		cs.insetBottom = body.scrollHeight - posLib.getTop( down ) -						down.offsetHeight;	}	};Menu.prototype.fixScrollButtons = function () {	var d = this.getDocument();	var up = d.getElementById( "scroll-up-item" );	var down = d.getElementById( "scroll-down-item" );	var scrollContainer = d.getElementById( "scroll-container" );	var scs = scrollContainer.style;	if ( scrollContainer.scrollHeight > this.getHeight() ) {		up.style.display = "";		down.style.display = "";		scs.height = "";		scs.overflow = "visible";		scs.height = Math.max( 0, this.getHeight() -			( d.body.scrollHeight - scrollContainer.offsetHeight ) ) + "px";		scs.overflow = "hidden";		this._scrollingMode = true;	}	else {		up.style.display = "none";		down.style.display = "none";		scs.overflow = "visible";		scs.height = "";		this._scrollingMode = false;	}};Menu.prototype.fixScrollEnabledState = function () {	var d = this.getDocument();	var up = d.getElementById( "scroll-up-item" );	var down = d.getElementById( "scroll-down-item" );	var scrollContainer = d.getElementById( "scroll-container" );	var tr;

⌨️ 快捷键说明

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