📄 menu4.js
字号:
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 _onclose
Menu.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>";
};
MenuItem.prototype.getSubMenuArrowHtml = function () {
if ( this.subMenu == null )
return " ";
return 4; // right arrow using the marlett (or webdings) font
};
MenuItem.prototype.getSubMenuArrowCellHtml = function () {
return "<td class=\"arrow-cell\">" +
this.makeDisabledContainer(
this.getSubMenuArrowHtml()
) +
"</td>";
};
MenuItem.prototype.makeDisabledContainer = function ( s ) {
if ( this.disabled )
return "<span class=\"disabled-container\"><span class=\"disabled-container\">" +
s + "</span></span>";
return s;
};
MenuItem.prototype.dispatchAction = function () {
if ( this.disabled )
return;
this.setSelected( true );
if ( this.subMenu ) {
if ( !this.subMenu.isShown() )
this.showSubMenu( false );
return;
}
if ( typeof this.action == "function" ) {
this.setSelected( false );
this.parentMenu.closeAllMenus();
this.action();
}
else if ( typeof this.action == "string" ) { // href
this.setSelected( false );
this.parentMenu.closeAllMenus();
if ( this.target != null )
window.open( this.action, this.target );
else
document.location.href = this.action;
}
};
MenuItem.prototype.setSelected = function ( bSelected ) {
if ( this._selected == bSelected ) return;
this._selected = Boolean( bSelected );
var tr = this._htmlElement;
if ( tr )
tr.className = this.getCssClass();
if ( !this._selected )
this.closeSubMenu( true );
var pm = this.parentMenu;
if ( bSelected ) {
pm.setSelectedIndex( this.itemIndex );
this.scrollIntoView();
// select item in parent menu as well
if ( pm.parentMenuItem )
pm.parentMenuItem.setSelected( true );
}
else
pm.setSelectedIndex( -1 );
if ( this._selected ) {
// clear timers for parent menu
window.clearTimeout( pm._closeTimer );
}
};
MenuItem.prototype.getSelected = function () {
return this.itemIndex == this.parentMenu.selectedIndex;
};
MenuItem.prototype.showSubMenu = function ( bDelayed ) {
var sm = this.subMenu;
var pm = this.parentMenu;
if ( sm && !this.disabled ) {
pm._aboutToShowSubMenu = true;
window.clearTimeout( sm._showTimer );
window.clearTimeout( sm._closeTimer );
var showTimeout = bDelayed ? sm.showTimeout : 0;
var oThis = this;
sm._showTimer = window.setTimeout(
"eventListeners.menuItem.onshowtimer(\"" + this.id + "\")",
showTimeout );
}
};
MenuItem.prototype.closeSubMenu = function ( bDelay ) {
var sm = this.subMenu;
if ( sm ) {
window.clearTimeout( sm._showTimer );
window.clearTimeout( sm._closeTimer );
if ( sm.popup ) {
if ( !bDelay )
sm.close();
else {
var oThis = this;
sm._closeTimer = window.setTimeout(
"eventListeners.menuItem.onclosetimer(\"" + this.id + "\")",
sm.closeTimeout );
}
}
}
};
MenuItem.prototype.scrollIntoView = function () {
if ( this.parentMenu._scrollingMode ) {
var d = this.parentMenu.getDocument();
var sc = d.getElementById( "scroll-container" );
var scrollTop = sc.scrollTop;
var clientHeight = sc.clientHeight;
var offsetTop = this._htmlElement.offsetTop;
var offsetHeight = this._htmlElement.offsetHeight;
if ( offsetTop < scrollTop )
sc.scrollTop = offsetTop;
else if ( offsetTop + offsetHeight > scrollTop + clientHeight )
sc.scrollTop = offsetTop + offsetHeight - clientHeight;
}
};
MenuItem.prototype.positionSubMenu = function () {
var dir = this.subMenuDirection;
var el = this._htmlElement;
var useInsets = this._useInsets;
var sm = this.subMenu;
var oThis = this;
if ( !sm._isCssFileLoaded() ) {
window.setTimeout(
"eventListeners.menuItem.onpositionsubmenutimer(\"" + this.id + "\")",
1 );
return;
}
// find parent item rectangle
var rect = {
left: posLib.getScreenLeft( el ),
top: posLib.getScreenTop( el ),
width: el.offsetWidth,
height: el.offsetHeight
};
var menuRect = {
left: sm.getLeft(),
top: sm.getTop(),
width: sm.getPreferredWidth(),
height: sm.getPreferredHeight(),
insetLeft: useInsets ? sm.getInsetLeft() : 0,
insetRight: useInsets ? sm.getInsetRight() : 0,
insetTop: useInsets ? sm.getInsetTop() : 0,
insetBottom: useInsets ? sm.getInsetBottom() : 0
};
// work around for buggy graphics drivers that screw up the screen.left
var screenWidth = screen.width;
var screenHeight = screen.height;
while ( rect.left > screenWidth )
screenWidth += screen.width;
while ( rect.top > screenHeight )
screenHeight += screen.height;
var left, top, width = menuRect.width, height = menuRect.height;
if ( dir == "vertical" ) {
if ( rect.left + menuRect.width - menuRect.insetLeft <= screenWidth )
left = rect.left - menuRect.insetLeft;
else if ( screenWidth >= menuRect.width )
left = screenWidth - menuRect.width;
else
left = 0;
if ( rect.top + rect.height + menuRect.height - menuRect.insetTop <= screenHeight )
top = rect.top + rect.height - menuRect.insetTop;
else if ( rect.top - menuRect.height + menuRect.insetBottom >= 0 )
top = rect.top - menuRect.height + menuRect.insetBottom;
else { // use largest and resize
var sizeAbove = rect.top + menuRect.insetBottom;
var sizeBelow = screenHeight - rect.top - rect.height + menuRect.insetTop;
if ( sizeBelow >= sizeAbove ) {
top = rect.top + rect.height - menuRect.insetTop;
height = sizeBelow;
}
else {
top = 0;
height = sizeAbove;
}
}
}
else {
if ( rect.top + menuRect.height - menuRect.insetTop <= screenHeight )
top = rect.top - menuRect.insetTop;
else if ( rect.top + rect.height - menuRect.height + menuRect.insetBottom >= 0)
top = rect.top + rect.height - menuRect.height + menuRect.insetBottom;
else if ( screenHeight >= menuRect.height )
top = screenHeight - menuRect.height;
else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -