📄 menu4.js
字号:
// 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; tr = up.rows[0]; if ( scrollContainer.scrollTop == 0 ) { if ( tr.className == "hover" || tr.className == "disabled-hover" ) tr.className = "disabled-hover"; else tr.className = "disabled"; } else { if ( tr.className == "disabled-hover" || tr.className == "hover" ) tr.className = "hover"; else tr.className = ""; } tr = down.rows[0]; if ( scrollContainer.scrollHeight - scrollContainer.clientHeight <= scrollContainer.scrollTop ) { if ( tr.className == "hover" || tr.className == "disabled-hover" ) tr.className = "disabled-hover"; else tr.className = "disabled"; } else { if ( tr.className == "disabled-hover" || tr.className == "hover" ) tr.className = "hover"; else tr.className = ""; }};Menu.prototype.closeAllMenus = function () { if ( this.parentMenu ) this.parentMenu.closeAllMenus(); else this.close();};Menu.prototype.close = function () { this.closeAllSubs(); window.clearTimeout( this._showTimer ); window.clearTimeout( this._closeTimer ); if ( this.popup ) this.popup.hide(); var pm = this.parentMenu; if ( pm && pm.shownSubMenu == this ) pm.shownSubMenu = null; this.setSelectedIndex( -1 ); this._checkCloseState();};Menu.prototype.closeAllSubs = function ( oNotThisSub) { // go through items and check for sub menus var items = this.items; var l = items.length; for (var i = 0; i < l; i++) { if ( items[i].subMenu != null && items[i].subMenu != oNotThisSub ) items[i].subMenu.close(); }};Menu.prototype.getSelectedIndex = function () { return this.selectedIndex;};Menu.prototype.setSelectedIndex = function ( nIndex ) { if ( this.selectedIndex == nIndex ) return; if ( nIndex >= this.items.length ) nIndex = -1; var mi; // deselect old if ( this.selectedIndex != -1 ) { mi = this.items[ this.selectedIndex ]; mi.setSelected( false ); } this.selectedIndex = nIndex; mi = this.items[ this.selectedIndex ]; if ( mi != null ) mi.setSelected( true );};Menu.prototype.goToNextMenuItem = function () { var i = 0; var items = this.items; var length = items.length; var index = this.getSelectedIndex(); var tmp; do { if ( index == -1 || index >= length ) index = 0; else index++; i++; tmp = items[index] } while ( !( tmp != null && tmp instanceof MenuItem && !(tmp instanceof MenuSeparator) || i >= length ) ) if ( tmp != null ) this.setSelectedIndex( index );};Menu.prototype.goToPreviousMenuItem = function () { var i = 0; var items = this.items; var length = items.length; var index = this.getSelectedIndex(); var tmp; do { if ( index == -1 || index >= length ) index = length - 1; else index--; i++; tmp = items[index] } while ( !( tmp != null && tmp instanceof MenuItem && !(tmp instanceof MenuSeparator) || i >= length ) ) if ( tmp != null ) this.setSelectedIndex( index );};Menu.prototype.goToNextMenu = function () { var index = this.getSelectedIndex(); var mi = this.items[ index ]; if ( mi && mi.subMenu && !mi.disabled ) { mi.subMenu.setSelectedIndex( 0 ); mi.showSubMenu( false ); } else { // go up to root and select next var mb = this.getMenuBar(); if ( mb != null ) mb.goToNextMenuItem(); }};Menu.prototype.goToPreviousMenu = function () { if ( this.parentMenuItem && this.parentMenuItem instanceof MenuButton ) { this.parentMenu.goToPreviousMenuItem(); } else if ( this.parentMenuItem ) { this.close(); }};Menu.prototype.getMenuBar = function () { if ( this.parentMenu == null ) return null; return this.parentMenu.getMenuBar();};Menu.prototype.makeEventListeners = function () { if ( this.eventListeners != null ) return; this.eventListeners = { onscroll: new Function( "eventListeners.menu.onscroll(\"" + this.id + "\")" ), onmouseover: new Function( "eventListeners.menu.onmouseover(\"" + this.id + "\")" ), onmouseout: new Function( "eventListeners.menu.onmouseout(\"" + this.id + "\")" ), onmouseup: new Function( "eventListeners.menu.onmouseup(\"" + this.id + "\")" ), onmousewheel: new Function( "eventListeners.menu.onmousewheel(\"" + this.id + "\")" ), onreadystatechange: new Function( "eventListeners.menu.onreadystatechange(\"" + this.id + "\")" ), onkeydown: new Function( "eventListeners.menu.onkeydown(\"" + this.id + "\")" ), oncontextmenu: new Function( "eventListeners.menu.oncontextmenu(\"" + this.id + "\")" ), onunload: new Function( "eventListeners.menu.onunload(\"" + this.id + "\")" ) };};Menu.prototype.detachEvents = function () { if ( this.eventListeners == null ) return; var d = this.getDocument(); var w = d.parentWindow; var scrollContainer = d.getElementById("scroll-container"); scrollContainer.detachEvent( "onscroll", this.eventListeners.onscroll ); d.detachEvent( "onmouseover", this.eventListeners.onmouseover ); d.detachEvent( "onmouseout", this.eventListeners.onmouseout ); d.detachEvent( "onmouseup", this.eventListeners.onmouseup ); d.detachEvent( "onmousewheel", this.eventListeners.onmousewheel ); if (this.cssText == null) { var linkEl = d.getElementsByTagName("LINK")[0]; linkEl.detachEvent( "onreadystatechange", this.eventListeners.onreadystatechange ); } d.detachEvent( "onkeydown", this.eventListeners.onkeydown ); d.detachEvent( "oncontextmenu", this.eventListeners.oncontextmenu ); // prevent IE to keep menu open when navigating away window.detachEvent( "onunload", this.eventListeners.onunload );}Menu.prototype.hookupMenu = function ( d ) { this.detachEvents(); this.makeEventListeners(); var oThis = this; var d = this.getDocument(); var w = d.parentWindow; var scrollContainer = d.getElementById("scroll-container"); // listen to the onscroll scrollContainer.attachEvent( "onscroll", this.eventListeners.onscroll ); d.attachEvent( "onmouseover", this.eventListeners.onmouseover ); d.attachEvent( "onmouseout", this.eventListeners.onmouseout ); d.attachEvent( "onmouseup", this.eventListeners.onmouseup ); d.attachEvent( "onmousewheel", this.eventListeners.onmousewheel ); // if css file is not loaded we need to wait for it to load. // Once loaded fix the size if (this.cssText == null) { var linkEl = d.getElementsByTagName("LINK")[0]; if ( linkEl.readyState != "complete") { linkEl.attachEvent( "onreadystatechange", this.eventListeners.onreadystatechange ); } } d.attachEvent( "onkeydown", this.eventListeners.onkeydown ); d.attachEvent( "oncontextmenu", this.eventListeners.oncontextmenu ); // prevent IE to keep menu open when navigating away window.attachEvent( "onunload", this.eventListeners.onunload ); var all = d.all; var l = all.length; for ( var i = 0; i < l; i++ ) all[i].unselectable = "on";};Menu.prototype.handleKeyEvent = function ( oEvent ) { if ( this.shownSubMenu ) // sub menu handles key event return; var nKeyCode = oEvent.keyCode; switch ( nKeyCode ) { case 40: // down this.goToNextMenuItem(); break; case 38: // up this.goToPreviousMenuItem(); break; case 39: // right this.goToNextMenu(); break; case 37: // left this.goToPreviousMenu(); break; case 13: // enter var mi = this.items[ this.getSelectedIndex() ]; if ( mi ) mi.dispatchAction(); break; case 27: // esc this.close(); // should close menu and go to parent menu item break; case Menu.keyboardAccelKey: case Menu.keyboardAccelKey2: this.closeAllMenus(); break; default: // find any mnemonic that matches var c = String.fromCharCode( nKeyCode ).toLowerCase(); var items = this.items; var l = items.length; for ( var i = 0; i < l; i++ ) { if ( items[i].mnemonic == c ) { items[i].dispatchAction(); break; } } } // cancel default action oEvent.returnValue = false; oEvent.keyCode = 0;};// poll close state and when closed call _oncloseMenu.prototype._startClosePoll = function () { var oThis = this; window.clearInterval( this._onCloseInterval ); this._onCloseInterval = window.setInterval( "eventListeners.menu.oncloseinterval(\"" + this.id + "\")", 100 );};Menu.prototype._checkCloseState = function () { var closed = this.popup == null || !this.popup.isOpen; if ( closed && this._closed != closed ) { this._closed = closed; this._closedAt = new Date().valueOf(); window.clearInterval( this._onCloseInterval ); if ( typeof this._onclose == "function" ) { var e = this.getDocument().parentWindow.event; if ( e != null && e.keyCode == 27 ) this._closeReason = "escape"; else this._closeReason = "unknown"; this._onclose(); } if ( typeof this.onclose == "function" ) this.onclose(); }};Menu.prototype._isCssFileLoaded = function () { if (this.cssText != null) return true; var d = this.getMeasureDocument(); var l = d.getElementsByTagName("LINK")[0]; return l.readyState == "complete";};Menu.prototype.destroy = function () { var l = this.items.length; for ( var i = l -1; i >= 0; i-- ) this.items[i].destroy(); this.detachEvents(); this.items = []; this.parentMenu = null; this.parentMenuItem = null; this.shownSubMenu = null; this._cachedSizes = null; this.eventListeners = null; if ( this.popup != null ) { var d = this.popup.document; d.open("text/plain", "replace"); d.write(""); d.close(); this.popup = null; } if ( Menu._measureMenu == this ) { Menu._measureMenu = null; var d = Menu._measureFrame.contentWindow.document; d.open("text/plain", "replace"); d.write(""); d.close(); Menu._measureFrame.parentNode.removeChild(Menu._measureFrame); Menu._measureFrame = null; } menuCache.remove( this );};////////////////////////////////////////////////////////////////////////////////////// MenuItem//function MenuItem( sLabelText, fAction, sIconSrc, oSubMenu ) { // public this.icon = sIconSrc || ""; this.text = sLabelText; this.action = fAction; this.subMenu = oSubMenu; this.parentMenu = null; // private this._selected = false; this._useInsets = true; // should insets be taken into account when showing sub menu this.id = menuCache.getId(); menuCache[ this.id ] = this;}MenuItem.prototype.subMenuDirection = "horizontal";MenuItem.prototype.disabled = false;MenuItem.prototype.mnemonic = null;MenuItem.prototype.shortcut = null;MenuItem.prototype.toolTip = "";MenuItem.prototype.target = null;MenuItem.prototype.visible = true;MenuItem.prototype.toHtml = function () { var cssClass = this.getCssClass(); var toolTip = this.getToolTip(); return "<tr" + (cssClass != "" ? " class=\"" + cssClass + "\"" : "") + (toolTip != "" ? " title=\"" + toolTip + "\"" : "") + (!this.visible ? " style=\"display: none\"" : "") + ">" + this.getIconCellHtml() + this.getTextCellHtml() + this.getShortcutCellHtml() + this.getSubMenuArrowCellHtml() + "</tr>";};MenuItem.prototype.getTextHtml = function () { var s = this.text; if ( !s || !this.mnemonic ) return s; // replace character with <u> character </u> // /^(((<([^>]|MNEMONIC)+>)|[^MNEMONIC])*)(MNEMONIC)/i var re = new RegExp( "^(((<([^>]|" + this.mnemonic + ")+>)|[^<" + this.mnemonic + "])*)(" + this.mnemonic + ")", "i" ); re.exec( s ); if ( RegExp.index != -1 && RegExp.$5 != "" ) return RegExp.$1 + "<u>" + RegExp.$5 + "</u>" + RegExp.rightContext; else return s;};MenuItem.prototype.getIconHtml = function () { return this.icon != "" ? "<img src=\"" + this.icon + "\">" : "<span> </span>";};MenuItem.prototype.getTextCellHtml = function () { return "<td class=\"label-cell\" nowrap=\"nowrap\">" + this.makeDisabledContainer( this.getTextHtml() ) + "</td>";};MenuItem.prototype.getIconCellHtml = function () { return "<td class=\"" + (this.icon != "" ? "icon-cell" : "empty-icon-cell") + "\">" + this.makeDisabledContainer( this.getIconHtml() ) + "</td>";};MenuItem.prototype.getCssClass = function () { if ( this.disabled && this._selected ) return "disabled-hover"; else if ( this.disabled ) return "disabled"; else if ( this._selected ) return "hover"; return "";};MenuItem.prototype.getToolTip = function () { return this.toolTip;};MenuItem.prototype.getShortcutHtml = function () { if ( this.shortcut == null ) return " "; return this.shortcut;};MenuItem.prototype.getShortcutCellHtml = function () { return "<td class=\"shortcut-cell\" nowrap=\"nowrap\">" + this.makeDisabledContainer( this.getShortcutHtml() ) + "</td>";};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -