📄 menu2.js
字号:
// String // CSS class for menu item when it's hovered over highlightClass: 'dojoMenuItem2Hover', postMixInProperties: function(){ this.iconStyle=""; if (this.iconSrc){ if ((this.iconSrc.toLowerCase().substring(this.iconSrc.length-4) == ".png") && (dojo.render.html.ie55 || dojo.render.html.ie60)){ this.iconStyle="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.iconSrc+"', sizingMethod='image')"; }else{ this.iconStyle="background-image: url("+this.iconSrc+")"; } } this.arrowDisplay = this.submenuId ? 'block' : 'none'; dojo.widget.MenuItem2.superclass.postMixInProperties.apply(this, arguments); }, fillInTemplate: function(){ dojo.html.disableSelection(this.domNode); if (this.disabled){ this.setDisabled(true); } if (this.eventNaming == "default") { for (var eventName in this.eventNames) { this.eventNames[eventName] = this.widgetId+"/"+eventName; } } }, onHover: function(){ // summary: callback when mouse is moved onto menu item //this is to prevent some annoying behavior when both mouse and keyboard are used this.onUnhover(); if (this.is_hovering){ return; } if (this.is_open){ return; } if(this.parent._highlighted_option){ this.parent._highlighted_option.onUnhover(); } this.parent.closeSubpopup(); this.parent._highlighted_option = this; dojo.widget.PopupManager.setFocusedMenu(this.parent); this._highlightItem(); if (this.is_hovering){ this._stopSubmenuTimer(); } this.is_hovering = true; this._startSubmenuTimer(); }, onUnhover: function(){ // summary: callback when mouse is moved off of menu item if(!this.is_open){ this._unhighlightItem(); } this.is_hovering = false; this.parent._highlighted_option = null; if(this.parent.parentPopup){ dojo.widget.PopupManager.setFocusedMenu(this.parent.parentPopup); } this._stopSubmenuTimer(); }, _onClick: function(focus){ // summary: internal function for clicks var displayingSubMenu = false; if (this.disabled){ return false; } if (this.submenuId){ if (!this.is_open){ this._stopSubmenuTimer(); this._openSubmenu(); } displayingSubMenu = true; }else{ // for some browsers the onMouseOut doesn't get called (?), so call it manually this.onUnhover(); //only onUnhover when no submenu is available this.parent.closeAll(true); } // user defined handler for click this.onClick(); dojo.event.topic.publish(this.eventNames.engage, this); if(displayingSubMenu && focus){ dojo.widget.getWidgetById(this.submenuId)._highlightOption(1); } return; }, onClick: function() { // summary // User defined function to handle clicks // this default function call the parent // menu's onItemClick this.parent.onItemClick(this); }, _highlightItem: function(){ dojo.html.addClass(this.domNode, this.highlightClass); }, _unhighlightItem: function(){ dojo.html.removeClass(this.domNode, this.highlightClass); }, _startSubmenuTimer: function(){ this._stopSubmenuTimer(); if (this.disabled){ return; } var self = this; var closure = function(){ return function(){ self._openSubmenu(); } }(); this.hover_timer = dojo.lang.setTimeout(closure, this.parent.submenuDelay); }, _stopSubmenuTimer: function(){ if (this.hover_timer){ dojo.lang.clearTimeout(this.hover_timer); this.hover_timer = null; } }, _openSubmenu: function(){ if (this.disabled){ return; } // first close any other open submenu this.parent.closeSubpopup(); var submenu = dojo.widget.getWidgetById(this.submenuId); if (submenu){ this.parent._openSubmenu(submenu, this); } }, _closedSubmenu: function(){ this.onUnhover(); }, setDisabled: function(/*Boolean*/ value){ // summary: enable or disable this menu item this.disabled = value; if (this.disabled){ dojo.html.addClass(this.domNode, 'dojoMenuItem2Disabled'); }else{ dojo.html.removeClass(this.domNode, 'dojoMenuItem2Disabled'); } }, enable: function(){ // summary: enable this menu item so user can click it this.setDisabled(false); }, disable: function(){ // summary: disable this menu item so user can't click it this.setDisabled(true); }, menuOpen: function(message) { // summary: callback when menu is opened // TODO: I don't see anyone calling this menu item }});// summary// A line between two menu itemsdojo.widget.defineWidget( "dojo.widget.MenuSeparator2", dojo.widget.HtmlWidget,{ templateString: '<tr class="dojoMenuSeparator2"><td colspan=4>' +'<div class="dojoMenuSeparator2Top"></div>' +'<div class="dojoMenuSeparator2Bottom"></div>' +'</td></tr>', postCreate: function(){ dojo.html.disableSelection(this.domNode); }});// summary// A menu bar, listing menu choices horizontally, like the "File" menu in most desktop applicationsdojo.widget.defineWidget( "dojo.widget.MenuBar2", dojo.widget.PopupMenu2,{ menuOverlap: 2, templateString: '<div class="dojoMenuBar2" tabIndex="0"><table class="dojoMenuBar2Client"><tr dojoAttachPoint="containerNode"></tr></table></div>', close: function(force){ if(this._highlighted_option){ this._highlighted_option.onUnhover(); } this.closeSubpopup(force); }, processKey: function(/*Event*/ evt){ if(evt.ctrlKey || evt.altKey){ return false; } if (!dojo.html.hasClass(evt.target,"dojoMenuBar2")) { return false; } var rval = false; switch(evt.key){ case evt.KEY_DOWN_ARROW: rval = this._moveToChildMenu(evt); break; case evt.KEY_UP_ARROW: rval = this._moveToParentMenu(evt); break; case evt.KEY_RIGHT_ARROW: rval = this._moveToNext(evt); break; case evt.KEY_LEFT_ARROW: rval = this._moveToPrevious(evt); break; default: rval = dojo.widget.MenuBar2.superclass.processKey.apply(this, arguments); break; } return rval; }, postCreate: function(){ dojo.widget.MenuBar2.superclass.postCreate.apply(this, arguments); dojo.widget.PopupManager.opened(this); this.isShowingNow = true; }, /* * override PopupMenu2 to open the submenu below us rather than to our right */ _openSubmenu: function(submenu, from_item){ var fromPos = dojo.html.getAbsolutePosition(from_item.domNode, true); var ourPos = dojo.html.getAbsolutePosition(this.domNode, true); var our_h = dojo.html.getBorderBox(this.domNode).height; var x = fromPos.x; var y = ourPos.y + our_h - this.menuOverlap; submenu.open(x, y, this, from_item.domNode); this.currentSubmenuTrigger = from_item; this.currentSubmenuTrigger.is_open = true; }});// summary// Item in a Menu2Bardojo.widget.defineWidget( "dojo.widget.MenuBarItem2", dojo.widget.MenuItem2,{ templateString: '<td class="dojoMenuBarItem2" dojoAttachEvent="onMouseOver: onHover; onMouseOut: onUnhover; onClick: _onClick;">' +'<span>${this.caption}</span>' +'</td>', highlightClass: 'dojoMenuBarItem2Hover', setDisabled: function(value){ this.disabled = value; if (this.disabled){ dojo.html.addClass(this.domNode, 'dojoMenuBarItem2Disabled'); }else{ dojo.html.removeClass(this.domNode, 'dojoMenuBarItem2Disabled'); } }});// ************************** make contextmenu work in konqueror and opera *********************dojo.widget.Menu2.OperaAndKonqFixer = new function(){ var implement = true; var delfunc = false; /** dom event check * * make a event and dispatch it and se if it calls function below, * if it indeed is supported and we dont need to implement our own */ // gets called if we have support for oncontextmenu if (!dojo.lang.isFunction(dojo.doc().oncontextmenu)){ dojo.doc().oncontextmenu = function(){ implement = false; delfunc = true; } } if (dojo.doc().createEvent){ // moz, safari has contextmenu event, need to do livecheck on this env. try { var e = dojo.doc().createEvent("MouseEvents"); e.initMouseEvent("contextmenu", 1, 1, dojo.global(), 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, null); dojo.doc().dispatchEvent(e); } catch (e) {/* assume not supported */} } else { // IE no need to implement custom contextmenu implement = false; } // clear this one if it wasn't there before if (delfunc){ delete dojo.doc().oncontextmenu; } /***** end dom event check *****/ /** * this fixes a dom node by attaching a custom oncontextmenu function that gets called when apropriate * @param node a dom node * * no returns */ this.fixNode = function(node){ if (implement){ // attach stub oncontextmenu function if (!dojo.lang.isFunction(node.oncontextmenu)){ node.oncontextmenu = function(e){/*stub*/} } // attach control function for oncontextmenu if (dojo.render.html.opera){ // opera // listen to ctrl-click events node._menufixer_opera = function(e){ if (e.ctrlKey){ this.oncontextmenu(e); } }; dojo.event.connect(node, "onclick", node, "_menufixer_opera"); } else { // konqueror // rightclick, listen to mousedown events node._menufixer_konq = function(e){ if (e.button==2 ){ e.preventDefault(); // need to prevent browsers menu this.oncontextmenu(e); } }; dojo.event.connect(node, "onmousedown", node, "_menufixer_konq"); } } } /** * this cleans up a fixed node, prevent memoryleak? * @param node node to clean * * no returns */ this.cleanNode = function(node){ if (implement){ // checks needed if we gets a non fixed node if (node._menufixer_opera){ dojo.event.disconnect(node, "onclick", node, "_menufixer_opera"); delete node._menufixer_opera; } else if(node._menufixer_konq){ dojo.event.disconnect(node, "onmousedown", node, "_menufixer_konq"); delete node._menufixer_konq; } if (node.oncontextmenu){ delete node.oncontextmenu; } } }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -