Menu2.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:17k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2. Copyright (c) 2004-2006, The Dojo Foundation
  3. All Rights Reserved.
  4. Licensed under the Academic Free License version 2.1 or above OR the
  5. modified BSD license. For more information on Dojo licensing, see:
  6. http://dojotoolkit.org/community/licensing.shtml
  7. */
  8. dojo.provide("dojo.widget.Menu2");
  9. dojo.require("dojo.widget.PopupContainer");
  10. dojo.declare("dojo.widget.MenuBase", null, function () {
  11. this.eventNames = {open:""};
  12. }, {isContainer:true, isMenu:true, eventNaming:"default", templateCssString:"n.dojoPopupMenu2 {ntposition: absolute;ntborder: 1px solid #7298d0;ntbackground:#85aeec url(images/soriaMenuBg.gif) repeat-x bottom left !important;ntpadding: 1px;ntmargin-top: 1px;ntmargin-bottom: 1px;n}nn.dojoMenuItem2{ntwhite-space: nowrap;ntfont: menu;ntmargin: 0;n}nn.dojoMenuItem2Hover {ntbackground-color: #D2E4FD;ntcursor:pointer;ntcursor:hand;n}nn.dojoMenuItem2Icon {ntposition: relative;ntbackground-position: center center;ntbackground-repeat: no-repeat;ntwidth: 16px;ntheight: 16px;ntpadding-right: 3px;n}nn.dojoMenuItem2Label {ntposition: relative;ntvertical-align: middle;n}nn/* main label text */n.dojoMenuItem2Label {ntposition: relative;ntvertical-align: middle;n}nn.dojoMenuItem2Accel {ntposition: relative;ntvertical-align: middle;ntpadding-left: 3px;n}nn.dojoMenuItem2Disabled .dojoMenuItem2Label,n.dojoMenuItem2Disabled .dojoMenuItem2Accel {ntcolor: #607a9e;n}nn.dojoMenuItem2Submenu {ntposition: relative;ntbackground-position: center center;ntbackground-repeat: no-repeat;ntbackground-image: url(images/submenu_off.gif);ntwidth: 5px;ntheight: 9px;ntpadding-left: 3px;n}n.dojoMenuItem2Hover .dojoMenuItem2Submenu {ntbackground-image: url(images/submenu_on.gif);n}nn.dojoMenuItem2Disabled .dojoMenuItem2Submenu {ntbackground-image: url(images/submenu_disabled.gif);n}nn.dojoMenuSeparator2 {ntfont-size: 1px;ntmargin: 0;n}nn.dojoMenuSeparator2Top {ntheight: 50%;ntborder-bottom: 1px solid #7a98c4;ntmargin: 0px 2px;ntfont-size: 1px;n}nn.dojoMenuSeparator2Bottom {ntheight: 50%;ntborder-top: 1px solid #c9deff;ntmargin: 0px 2px;ntfont-size: 1px;n}nn.dojoMenuBar2 {ntbackground:#85aeec url(images/soriaBarBg.gif) repeat-x top left;nt/*border-bottom:1px solid #6b9fec;*/ntpadding: 1px;n}nn.dojoMenuBar2 .dojoMenuItem2 {ntwhite-space: nowrap;ntfont: menu;ntmargin: 0;ntposition: relative;ntvertical-align: middle;ntz-index: 1;ntpadding: 3px 8px;ntdisplay: inline;/* needed in khtml to display correctly */ntdisplay: -moz-inline-box;/* needed in firefox */ntcursor:pointer;ntcursor:hand;n}nn.dojoMenuBar2 .dojoMenuItem2Hover {ntbackground-color:#d2e4fd;n}nn.dojoMenuBar2 .dojoMenuItem2Disabled span {ntcolor: #4f6582;n}n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Menu2.css"), submenuDelay:500, initialize:function (args, frag) {
  13. if (this.eventNaming == "default") {
  14. for (var eventName in this.eventNames) {
  15. this.eventNames[eventName] = this.widgetId + "/" + eventName;
  16. }
  17. }
  18. }, _moveToNext:function (evt) {
  19. this._highlightOption(1);
  20. return true;
  21. }, _moveToPrevious:function (evt) {
  22. this._highlightOption(-1);
  23. return true;
  24. }, _moveToParentMenu:function (evt) {
  25. if (this._highlighted_option && this.parentMenu) {
  26. if (evt._menu2UpKeyProcessed) {
  27. return true;
  28. } else {
  29. this._highlighted_option.onUnhover();
  30. this.closeSubmenu();
  31. evt._menu2UpKeyProcessed = true;
  32. }
  33. }
  34. return false;
  35. }, _moveToChildMenu:function (evt) {
  36. if (this._highlighted_option && this._highlighted_option.submenuId) {
  37. this._highlighted_option._onClick(true);
  38. return true;
  39. }
  40. return false;
  41. }, _selectCurrentItem:function (evt) {
  42. if (this._highlighted_option) {
  43. this._highlighted_option._onClick();
  44. return true;
  45. }
  46. return false;
  47. }, processKey:function (evt) {
  48. if (evt.ctrlKey || evt.altKey || !evt.key) {
  49. return false;
  50. }
  51. var rval = false;
  52. switch (evt.key) {
  53.   case evt.KEY_DOWN_ARROW:
  54. rval = this._moveToNext(evt);
  55. break;
  56.   case evt.KEY_UP_ARROW:
  57. rval = this._moveToPrevious(evt);
  58. break;
  59.   case evt.KEY_RIGHT_ARROW:
  60. rval = this._moveToChildMenu(evt);
  61. break;
  62.   case evt.KEY_LEFT_ARROW:
  63. rval = this._moveToParentMenu(evt);
  64. break;
  65.   case " ":
  66.   case evt.KEY_ENTER:
  67. if (rval = this._selectCurrentItem(evt)) {
  68. break;
  69. }
  70.   case evt.KEY_ESCAPE:
  71.   case evt.KEY_TAB:
  72. this.close(true);
  73. rval = true;
  74. break;
  75. }
  76. return rval;
  77. }, _findValidItem:function (dir, curItem) {
  78. if (curItem) {
  79. curItem = dir > 0 ? curItem.getNextSibling() : curItem.getPreviousSibling();
  80. }
  81. for (var i = 0; i < this.children.length; ++i) {
  82. if (!curItem) {
  83. curItem = dir > 0 ? this.children[0] : this.children[this.children.length - 1];
  84. }
  85. if (curItem.onHover && curItem.isShowing()) {
  86. return curItem;
  87. }
  88. curItem = dir > 0 ? curItem.getNextSibling() : curItem.getPreviousSibling();
  89. }
  90. }, _highlightOption:function (dir) {
  91. var item;
  92. if ((!this._highlighted_option)) {
  93. item = this._findValidItem(dir);
  94. } else {
  95. item = this._findValidItem(dir, this._highlighted_option);
  96. }
  97. if (item) {
  98. if (this._highlighted_option) {
  99. this._highlighted_option.onUnhover();
  100. }
  101. item.onHover();
  102. dojo.html.scrollIntoView(item.domNode);
  103. try {
  104. var node = dojo.html.getElementsByClass("dojoMenuItem2Label", item.domNode)[0];
  105. node.focus();
  106. }
  107. catch (e) {
  108. }
  109. }
  110. }, onItemClick:function (item) {
  111. }, closeSubmenu:function (force) {
  112. if (this.currentSubmenu == null) {
  113. return;
  114. }
  115. this.currentSubmenu.close(force);
  116. this.currentSubmenu = null;
  117. this.currentSubmenuTrigger.is_open = false;
  118. this.currentSubmenuTrigger._closedSubmenu(force);
  119. this.currentSubmenuTrigger = null;
  120. }});
  121. dojo.widget.defineWidget("dojo.widget.PopupMenu2", [dojo.widget.HtmlWidget, dojo.widget.PopupContainerBase, dojo.widget.MenuBase], function () {
  122. this.targetNodeIds = [];
  123. }, {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 () {
  124. if (this.contextMenuForWindow) {
  125. var doc = dojo.body();
  126. this.bindDomNode(doc);
  127. } else {
  128. if (this.targetNodeIds.length > 0) {
  129. dojo.lang.forEach(this.targetNodeIds, this.bindDomNode, this);
  130. }
  131. }
  132. this._subscribeSubitemsOnOpen();
  133. }, _subscribeSubitemsOnOpen:function () {
  134. var subItems = this.getChildrenOfType(dojo.widget.MenuItem2);
  135. for (var i = 0; i < subItems.length; i++) {
  136. dojo.event.topic.subscribe(this.eventNames.open, subItems[i], "menuOpen");
  137. }
  138. }, getTopOpenEvent:function () {
  139. var menu = this;
  140. while (menu.parentMenu) {
  141. menu = menu.parentMenu;
  142. }
  143. return menu.openEvent;
  144. }, bindDomNode:function (node) {
  145. node = dojo.byId(node);
  146. var win = dojo.html.getElementWindow(node);
  147. if (dojo.html.isTag(node, "iframe") == "iframe") {
  148. win = dojo.html.iframeContentWindow(node);
  149. node = dojo.withGlobal(win, dojo.body);
  150. }
  151. dojo.widget.Menu2.OperaAndKonqFixer.fixNode(node);
  152. dojo.event.kwConnect({srcObj:node, srcFunc:"oncontextmenu", targetObj:this, targetFunc:"onOpen", once:true});
  153. if (dojo.render.html.moz && win.document.designMode.toLowerCase() == "on") {
  154. dojo.event.browser.addListener(node, "contextmenu", dojo.lang.hitch(this, "onOpen"));
  155. }
  156. dojo.widget.PopupManager.registerWin(win);
  157. }, unBindDomNode:function (nodeName) {
  158. var node = dojo.byId(nodeName);
  159. dojo.event.kwDisconnect({srcObj:node, srcFunc:"oncontextmenu", targetObj:this, targetFunc:"onOpen", once:true});
  160. dojo.widget.Menu2.OperaAndKonqFixer.cleanNode(node);
  161. }, _openAsSubmenu:function (parent, explodeSrc, orient) {
  162. if (this.isShowingNow) {
  163. return;
  164. }
  165. this.parentMenu = parent;
  166. this.open(explodeSrc, parent, explodeSrc, orient);
  167. }, close:function (force) {
  168. if (this.animationInProgress) {
  169. dojo.widget.PopupContainerBase.prototype.close.call(this, force);
  170. return;
  171. }
  172. if (this._highlighted_option) {
  173. this._highlighted_option.onUnhover();
  174. }
  175. dojo.widget.PopupContainerBase.prototype.close.call(this, force);
  176. this.parentMenu = null;
  177. }, closeAll:function (force) {
  178. if (this.parentMenu) {
  179. this.parentMenu.closeAll(force);
  180. } else {
  181. this.close(force);
  182. }
  183. }, _openSubmenu:function (submenu, from_item) {
  184. submenu._openAsSubmenu(this, from_item.arrow, {"TR":"TL", "TL":"TR"});
  185. this.currentSubmenu = submenu;
  186. this.currentSubmenuTrigger = from_item;
  187. this.currentSubmenuTrigger.is_open = true;
  188. }, focus:function () {
  189. if (this.currentSubmenuTrigger) {
  190. if (this.currentSubmenuTrigger.caption) {
  191. try {
  192. this.currentSubmenuTrigger.caption.focus();
  193. }
  194. catch (e) {
  195. }
  196. } else {
  197. try {
  198. this.currentSubmenuTrigger.domNode.focus();
  199. }
  200. catch (e) {
  201. }
  202. }
  203. }
  204. }, onOpen:function (e) {
  205. this.openEvent = e;
  206. if (e["target"]) {
  207. this.openedForWindow = dojo.html.getElementWindow(e.target);
  208. } else {
  209. this.openedForWindow = null;
  210. }
  211. var x = e.pageX, y = e.pageY;
  212. var win = dojo.html.getElementWindow(e.target);
  213. var iframe = win._frameElement || win.frameElement;
  214. if (iframe) {
  215. var cood = dojo.html.abs(iframe, true);
  216. x += cood.x - dojo.withGlobal(win, dojo.html.getScroll).left;
  217. y += cood.y - dojo.withGlobal(win, dojo.html.getScroll).top;
  218. }
  219. this.open(x, y, null, [x, y]);
  220. dojo.event.browser.stopEvent(e);
  221. }});
  222. dojo.widget.defineWidget("dojo.widget.MenuItem2", dojo.widget.HtmlWidget, function () {
  223. this.eventNames = {engage:""};
  224. }, {templateString:"<tr class="dojoMenuItem2" dojoAttachEvent="onMouseOver: onHover; onMouseOut: onUnhover; onClick: _onClick; onKey:onKey;">" + "<td><div class="${this.iconClass}" style="${this.iconStyle}"></div></td>" + "<td tabIndex="-1" class="dojoMenuItem2Label" dojoAttachPoint="caption">${this.caption}</td>" + "<td class="dojoMenuItem2Accel">${this.accelKey}</td>" + "<td><div class="dojoMenuItem2Submenu" style="display:${this.arrowDisplay};" dojoAttachPoint="arrow"></div></td>" + "</tr>", is_hovering:false, hover_timer:null, is_open:false, topPosition:0, caption:"Untitled", accelKey:"", iconSrc:"", disabledClass:"dojoMenuItem2Disabled", iconClass:"dojoMenuItem2Icon", submenuId:"", eventNaming:"default", highlightClass:"dojoMenuItem2Hover", postMixInProperties:function () {
  225. this.iconStyle = "";
  226. if (this.iconSrc) {
  227. if ((this.iconSrc.toLowerCase().substring(this.iconSrc.length - 4) == ".png") && (dojo.render.html.ie55 || dojo.render.html.ie60)) {
  228. this.iconStyle = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.iconSrc + "', sizingMethod='image')";
  229. } else {
  230. this.iconStyle = "background-image: url(" + this.iconSrc + ")";
  231. }
  232. }
  233. this.arrowDisplay = this.submenuId ? "block" : "none";
  234. dojo.widget.MenuItem2.superclass.postMixInProperties.apply(this, arguments);
  235. }, fillInTemplate:function () {
  236. dojo.html.disableSelection(this.domNode);
  237. if (this.disabled) {
  238. this.setDisabled(true);
  239. }
  240. if (this.eventNaming == "default") {
  241. for (var eventName in this.eventNames) {
  242. this.eventNames[eventName] = this.widgetId + "/" + eventName;
  243. }
  244. }
  245. }, onHover:function () {
  246. this.onUnhover();
  247. if (this.is_hovering) {
  248. return;
  249. }
  250. if (this.is_open) {
  251. return;
  252. }
  253. if (this.parent._highlighted_option) {
  254. this.parent._highlighted_option.onUnhover();
  255. }
  256. this.parent.closeSubmenu();
  257. this.parent._highlighted_option = this;
  258. dojo.widget.PopupManager.setFocusedMenu(this.parent);
  259. this._highlightItem();
  260. if (this.is_hovering) {
  261. this._stopSubmenuTimer();
  262. }
  263. this.is_hovering = true;
  264. this._startSubmenuTimer();
  265. }, onUnhover:function () {
  266. if (!this.is_open) {
  267. this._unhighlightItem();
  268. }
  269. this.is_hovering = false;
  270. this.parent._highlighted_option = null;
  271. if (this.parent.parentMenu) {
  272. dojo.widget.PopupManager.setFocusedMenu(this.parent.parentMenu);
  273. }
  274. this._stopSubmenuTimer();
  275. }, _onClick:function (focus) {
  276. var displayingSubMenu = false;
  277. if (this.disabled) {
  278. return false;
  279. }
  280. if (this.submenuId) {
  281. if (!this.is_open) {
  282. this._stopSubmenuTimer();
  283. this._openSubmenu();
  284. }
  285. displayingSubMenu = true;
  286. } else {
  287. this.onUnhover();
  288. this.parent.closeAll(true);
  289. }
  290. this.onClick();
  291. dojo.event.topic.publish(this.eventNames.engage, this);
  292. if (displayingSubMenu && focus) {
  293. dojo.widget.getWidgetById(this.submenuId)._highlightOption(1);
  294. }
  295. return;
  296. }, onClick:function () {
  297. this.parent.onItemClick(this);
  298. }, _highlightItem:function () {
  299. dojo.html.addClass(this.domNode, this.highlightClass);
  300. }, _unhighlightItem:function () {
  301. dojo.html.removeClass(this.domNode, this.highlightClass);
  302. }, _startSubmenuTimer:function () {
  303. this._stopSubmenuTimer();
  304. if (this.disabled) {
  305. return;
  306. }
  307. var self = this;
  308. var closure = function () {
  309. return function () {
  310. self._openSubmenu();
  311. };
  312. }();
  313. this.hover_timer = dojo.lang.setTimeout(closure, this.parent.submenuDelay);
  314. }, _stopSubmenuTimer:function () {
  315. if (this.hover_timer) {
  316. dojo.lang.clearTimeout(this.hover_timer);
  317. this.hover_timer = null;
  318. }
  319. }, _openSubmenu:function () {
  320. if (this.disabled) {
  321. return;
  322. }
  323. this.parent.closeSubmenu();
  324. var submenu = dojo.widget.getWidgetById(this.submenuId);
  325. if (submenu) {
  326. this.parent._openSubmenu(submenu, this);
  327. }
  328. }, _closedSubmenu:function () {
  329. this.onUnhover();
  330. }, setDisabled:function (value) {
  331. this.disabled = value;
  332. if (this.disabled) {
  333. dojo.html.addClass(this.domNode, this.disabledClass);
  334. } else {
  335. dojo.html.removeClass(this.domNode, this.disabledClass);
  336. }
  337. }, enable:function () {
  338. this.setDisabled(false);
  339. }, disable:function () {
  340. this.setDisabled(true);
  341. }, menuOpen:function (message) {
  342. }});
  343. dojo.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 () {
  344. dojo.html.disableSelection(this.domNode);
  345. }});
  346. dojo.widget.defineWidget("dojo.widget.MenuBar2", [dojo.widget.HtmlWidget, dojo.widget.MenuBase], {menuOverlap:2, templateString:"<div class="dojoMenuBar2" dojoAttachPoint="containerNode" tabIndex="0"></div>", close:function (force) {
  347. if (this._highlighted_option) {
  348. this._highlighted_option.onUnhover();
  349. }
  350. this.closeSubmenu(force);
  351. }, closeAll:function (force) {
  352. this.close(force);
  353. }, processKey:function (evt) {
  354. if (evt.ctrlKey || evt.altKey) {
  355. return false;
  356. }
  357. var rval = false;
  358. switch (evt.key) {
  359.   case evt.KEY_DOWN_ARROW:
  360. rval = this._moveToChildMenu(evt);
  361. break;
  362.   case evt.KEY_UP_ARROW:
  363. rval = this._moveToParentMenu(evt);
  364. break;
  365.   case evt.KEY_RIGHT_ARROW:
  366. rval = this._moveToNext(evt);
  367. break;
  368.   case evt.KEY_LEFT_ARROW:
  369. rval = this._moveToPrevious(evt);
  370. break;
  371.   default:
  372. rval = dojo.widget.MenuBar2.superclass.processKey.apply(this, arguments);
  373. break;
  374. }
  375. return rval;
  376. }, postCreate:function () {
  377. dojo.widget.MenuBar2.superclass.postCreate.apply(this, arguments);
  378. this.isShowingNow = true;
  379. }, _openSubmenu:function (submenu, from_item) {
  380. submenu._openAsSubmenu(this, from_item.domNode, {"BL":"TL", "TL":"BL"});
  381. this.currentSubmenu = submenu;
  382. this.currentSubmenuTrigger = from_item;
  383. this.currentSubmenuTrigger.is_open = true;
  384. }});
  385. dojo.widget.defineWidget("dojo.widget.MenuBarItem2", dojo.widget.MenuItem2, {templateString:"<span class="dojoMenuItem2" dojoAttachEvent="onMouseOver: onHover; onMouseOut: onUnhover; onClick: _onClick;">${this.caption}</span>"});
  386. dojo.widget.Menu2.OperaAndKonqFixer = new function () {
  387. var implement = true;
  388. var delfunc = false;
  389. if (!dojo.lang.isFunction(dojo.doc().oncontextmenu)) {
  390. dojo.doc().oncontextmenu = function () {
  391. implement = false;
  392. delfunc = true;
  393. };
  394. }
  395. if (dojo.doc().createEvent) {
  396. try {
  397. var e = dojo.doc().createEvent("MouseEvents");
  398. e.initMouseEvent("contextmenu", 1, 1, dojo.global(), 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, null);
  399. dojo.doc().dispatchEvent(e);
  400. }
  401. catch (e) {
  402. }
  403. } else {
  404. implement = false;
  405. }
  406. if (delfunc) {
  407. delete dojo.doc().oncontextmenu;
  408. }
  409. this.fixNode = function (node) {
  410. if (implement) {
  411. if (!dojo.lang.isFunction(node.oncontextmenu)) {
  412. node.oncontextmenu = function (e) {
  413. };
  414. }
  415. if (dojo.render.html.opera) {
  416. node._menufixer_opera = function (e) {
  417. if (e.ctrlKey) {
  418. this.oncontextmenu(e);
  419. }
  420. };
  421. dojo.event.connect(node, "onclick", node, "_menufixer_opera");
  422. } else {
  423. node._menufixer_konq = function (e) {
  424. if (e.button == 2) {
  425. e.preventDefault();
  426. this.oncontextmenu(e);
  427. }
  428. };
  429. dojo.event.connect(node, "onmousedown", node, "_menufixer_konq");
  430. }
  431. }
  432. };
  433. this.cleanNode = function (node) {
  434. if (implement) {
  435. if (node._menufixer_opera) {
  436. dojo.event.disconnect(node, "onclick", node, "_menufixer_opera");
  437. delete node._menufixer_opera;
  438. } else {
  439. if (node._menufixer_konq) {
  440. dojo.event.disconnect(node, "onmousedown", node, "_menufixer_konq");
  441. delete node._menufixer_konq;
  442. }
  443. }
  444. if (node.oncontextmenu) {
  445. delete node.oncontextmenu;
  446. }
  447. }
  448. };
  449. };