menu2.js

来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 456 行 · 第 1/2 页

JS
456
字号
/*
	Copyright (c) 2004-2006, The Dojo Foundation
	All Rights Reserved.

	Licensed under the Academic Free License version 2.1 or above OR the
	modified BSD license. For more information on Dojo licensing, see:

		http://dojotoolkit.org/community/licensing.shtml
*/



dojo.provide("dojo.widget.Menu2");
dojo.require("dojo.widget.PopupContainer");
dojo.declare("dojo.widget.MenuBase", null, function () {
	this.eventNames = {open:""};
}, {isContainer:true, isMenu:true, eventNaming:"default", templateCssString:"\n.dojoPopupMenu2 {\n\tposition: absolute;\n\tborder: 1px solid #7298d0;\n\tbackground:#85aeec url(images/soriaMenuBg.gif) repeat-x bottom left !important;\n\tpadding: 1px;\n\tmargin-top: 1px;\n\tmargin-bottom: 1px;\n}\n\n.dojoMenuItem2{\n\twhite-space: nowrap;\n\tfont: menu;\n\tmargin: 0;\n}\n\n.dojoMenuItem2Hover {\n\tbackground-color: #D2E4FD;\n\tcursor:pointer;\n\tcursor:hand;\n}\n\n.dojoMenuItem2Icon {\n\tposition: relative;\n\tbackground-position: center center;\n\tbackground-repeat: no-repeat;\n\twidth: 16px;\n\theight: 16px;\n\tpadding-right: 3px;\n}\n\n.dojoMenuItem2Label {\n\tposition: relative;\n\tvertical-align: middle;\n}\n\n/* main label text */\n.dojoMenuItem2Label {\n\tposition: relative;\n\tvertical-align: middle;\n}\n\n.dojoMenuItem2Accel {\n\tposition: relative;\n\tvertical-align: middle;\n\tpadding-left: 3px;\n}\n\n.dojoMenuItem2Disabled .dojoMenuItem2Label,\n.dojoMenuItem2Disabled .dojoMenuItem2Accel {\n\tcolor: #607a9e;\n}\n\n.dojoMenuItem2Submenu {\n\tposition: relative;\n\tbackground-position: center center;\n\tbackground-repeat: no-repeat;\n\tbackground-image: url(images/submenu_off.gif);\n\twidth: 5px;\n\theight: 9px;\n\tpadding-left: 3px;\n}\n.dojoMenuItem2Hover .dojoMenuItem2Submenu {\n\tbackground-image: url(images/submenu_on.gif);\n}\n\n.dojoMenuItem2Disabled .dojoMenuItem2Submenu {\n\tbackground-image: url(images/submenu_disabled.gif);\n}\n\n.dojoMenuSeparator2 {\n\tfont-size: 1px;\n\tmargin: 0;\n}\n\n.dojoMenuSeparator2Top {\n\theight: 50%;\n\tborder-bottom: 1px solid #7a98c4;\n\tmargin: 0px 2px;\n\tfont-size: 1px;\n}\n\n.dojoMenuSeparator2Bottom {\n\theight: 50%;\n\tborder-top: 1px solid #c9deff;\n\tmargin: 0px 2px;\n\tfont-size: 1px;\n}\n\n.dojoMenuBar2 {\n\tbackground:#85aeec url(images/soriaBarBg.gif) repeat-x top left;\n\t/*border-bottom:1px solid #6b9fec;*/\n\tpadding: 1px;\n}\n\n.dojoMenuBar2 .dojoMenuItem2 {\n\twhite-space: nowrap;\n\tfont: menu;\n\tmargin: 0;\n\tposition: relative;\n\tvertical-align: middle;\n\tz-index: 1;\n\tpadding: 3px 8px;\n\tdisplay: inline;/* needed in khtml to display correctly */\n\tdisplay: -moz-inline-box;/* needed in firefox */\n\tcursor:pointer;\n\tcursor:hand;\n}\n\n.dojoMenuBar2 .dojoMenuItem2Hover {\n\tbackground-color:#d2e4fd;\n}\n\n.dojoMenuBar2 .dojoMenuItem2Disabled span {\n\tcolor: #4f6582;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Menu2.css"), submenuDelay:500, initialize:function (args, frag) {
	if (this.eventNaming == "default") {
		for (var eventName in this.eventNames) {
			this.eventNames[eventName] = this.widgetId + "/" + eventName;
		}
	}
}, _moveToNext:function (evt) {
	this._highlightOption(1);
	return true;
}, _moveToPrevious:function (evt) {
	this._highlightOption(-1);
	return true;
}, _moveToParentMenu:function (evt) {
	if (this._highlighted_option && this.parentMenu) {
		if (evt._menu2UpKeyProcessed) {
			return true;
		} else {
			this._highlighted_option.onUnhover();
			this.closeSubmenu();
			evt._menu2UpKeyProcessed = true;
		}
	}
	return false;
}, _moveToChildMenu:function (evt) {
	if (this._highlighted_option && this._highlighted_option.submenuId) {
		this._highlighted_option._onClick(true);
		return true;
	}
	return false;
}, _selectCurrentItem:function (evt) {
	if (this._highlighted_option) {
		this._highlighted_option._onClick();
		return true;
	}
	return false;
}, processKey:function (evt) {
	if (evt.ctrlKey || evt.altKey || !evt.key) {
		return false;
	}
	var rval = false;
	switch (evt.key) {
	  case evt.KEY_DOWN_ARROW:
		rval = this._moveToNext(evt);
		break;
	  case evt.KEY_UP_ARROW:
		rval = this._moveToPrevious(evt);
		break;
	  case evt.KEY_RIGHT_ARROW:
		rval = this._moveToChildMenu(evt);
		break;
	  case evt.KEY_LEFT_ARROW:
		rval = this._moveToParentMenu(evt);
		break;
	  case " ":
	  case evt.KEY_ENTER:
		if (rval = this._selectCurrentItem(evt)) {
			break;
		}
	  case evt.KEY_ESCAPE:
	  case evt.KEY_TAB:
		this.close(true);
		rval = true;
		break;
	}
	return rval;
}, _findValidItem:function (dir, curItem) {
	if (curItem) {
		curItem = dir > 0 ? curItem.getNextSibling() : curItem.getPreviousSibling();
	}
	for (var i = 0; i < this.children.length; ++i) {
		if (!curItem) {
			curItem = dir > 0 ? this.children[0] : this.children[this.children.length - 1];
		}
		if (curItem.onHover && curItem.isShowing()) {
			return curItem;
		}
		curItem = dir > 0 ? curItem.getNextSibling() : curItem.getPreviousSibling();
	}
}, _highlightOption:function (dir) {
	var item;
	if ((!this._highlighted_option)) {
		item = this._findValidItem(dir);
	} else {
		item = this._findValidItem(dir, this._highlighted_option);
	}
	if (item) {
		if (this._highlighted_option) {
			this._highlighted_option.onUnhover();
		}
		item.onHover();
		dojo.html.scrollIntoView(item.domNode);
		try {
			var node = dojo.html.getElementsByClass("dojoMenuItem2Label", item.domNode)[0];
			node.focus();
		}
		catch (e) {
		}
	}
}, onItemClick:function (item) {
}, closeSubmenu:function (force) {
	if (this.currentSubmenu == null) {
		return;
	}
	this.currentSubmenu.close(force);
	this.currentSubmenu = null;
	this.currentSubmenuTrigger.is_open = false;
	this.currentSubmenuTrigger._closedSubmenu(force);
	this.currentSubmenuTrigger = null;
}});
dojo.widget.defineWidget("dojo.widget.PopupMenu2", [dojo.widget.HtmlWidget, dojo.widget.PopupContainerBase, dojo.widget.MenuBase], function () {
	this.targetNodeIds = [];
}, {templateString:"<table class=\"dojoPopupMenu2\" border=0 cellspacing=0 cellpadding=0 style=\"display: none; position: absolute;\">" + "<tbody dojoAttachPoint=\"containerNode\"></tbody>" + "</table>", submenuOverlap:5, contextMenuForWindow:false, parentMenu:null, postCreate:function () {
	if (this.contextMenuForWindow) {
		var doc = dojo.body();
		this.bindDomNode(doc);
	} else {
		if (this.targetNodeIds.length > 0) {
			dojo.lang.forEach(this.targetNodeIds, this.bindDomNode, this);
		}
	}
	this._subscribeSubitemsOnOpen();
}, _subscribeSubitemsOnOpen:function () {
	var subItems = this.getChildrenOfType(dojo.widget.MenuItem2);
	for (var i = 0; i < subItems.length; i++) {
		dojo.event.topic.subscribe(this.eventNames.open, subItems[i], "menuOpen");
	}
}, getTopOpenEvent:function () {
	var menu = this;
	while (menu.parentMenu) {
		menu = menu.parentMenu;
	}
	return menu.openEvent;
}, bindDomNode:function (node) {
	node = dojo.byId(node);
	var win = dojo.html.getElementWindow(node);
	if (dojo.html.isTag(node, "iframe") == "iframe") {
		win = dojo.html.iframeContentWindow(node);
		node = dojo.withGlobal(win, dojo.body);
	}
	dojo.widget.Menu2.OperaAndKonqFixer.fixNode(node);
	dojo.event.kwConnect({srcObj:node, srcFunc:"oncontextmenu", targetObj:this, targetFunc:"onOpen", once:true});
	if (dojo.render.html.moz && win.document.designMode.toLowerCase() == "on") {
		dojo.event.browser.addListener(node, "contextmenu", dojo.lang.hitch(this, "onOpen"));
	}
	dojo.widget.PopupManager.registerWin(win);
}, unBindDomNode:function (nodeName) {
	var node = dojo.byId(nodeName);
	dojo.event.kwDisconnect({srcObj:node, srcFunc:"oncontextmenu", targetObj:this, targetFunc:"onOpen", once:true});
	dojo.widget.Menu2.OperaAndKonqFixer.cleanNode(node);
}, _openAsSubmenu:function (parent, explodeSrc, orient) {
	if (this.isShowingNow) {
		return;
	}
	this.parentMenu = parent;
	this.open(explodeSrc, parent, explodeSrc, orient);
}, close:function (force) {
	if (this.animationInProgress) {
		dojo.widget.PopupContainerBase.prototype.close.call(this, force);
		return;
	}
	if (this._highlighted_option) {
		this._highlighted_option.onUnhover();
	}
	dojo.widget.PopupContainerBase.prototype.close.call(this, force);
	this.parentMenu = null;
}, closeAll:function (force) {
	if (this.parentMenu) {
		this.parentMenu.closeAll(force);
	} else {
		this.close(force);
	}
}, _openSubmenu:function (submenu, from_item) {
	submenu._openAsSubmenu(this, from_item.arrow, {"TR":"TL", "TL":"TR"});
	this.currentSubmenu = submenu;
	this.currentSubmenuTrigger = from_item;
	this.currentSubmenuTrigger.is_open = true;
}, focus:function () {
	if (this.currentSubmenuTrigger) {
		if (this.currentSubmenuTrigger.caption) {
			try {
				this.currentSubmenuTrigger.caption.focus();
			}
			catch (e) {
			}
		} else {
			try {
				this.currentSubmenuTrigger.domNode.focus();
			}
			catch (e) {
			}
		}
	}
}, onOpen:function (e) {
	this.openEvent = e;
	if (e["target"]) {
		this.openedForWindow = dojo.html.getElementWindow(e.target);
	} else {
		this.openedForWindow = null;
	}
	var x = e.pageX, y = e.pageY;
	var win = dojo.html.getElementWindow(e.target);
	var iframe = win._frameElement || win.frameElement;
	if (iframe) {
		var cood = dojo.html.abs(iframe, true);
		x += cood.x - dojo.withGlobal(win, dojo.html.getScroll).left;
		y += cood.y - dojo.withGlobal(win, dojo.html.getScroll).top;
	}
	this.open(x, y, null, [x, y]);
	dojo.event.browser.stopEvent(e);
}});
dojo.widget.defineWidget("dojo.widget.MenuItem2", dojo.widget.HtmlWidget, function () {
	this.eventNames = {engage:""};

⌨️ 快捷键说明

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