You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
6.4 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-menu-MenuMgr'>/**
  19. </span> * @class Ext.menu.MenuMgr
  20. * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
  21. * @singleton
  22. */
  23. Ext.menu.MenuMgr = function(){
  24. var menus,
  25. active,
  26. map,
  27. groups = {},
  28. attached = false,
  29. lastShow = new Date();
  30. // private - called when first menu is created
  31. function init(){
  32. menus = {};
  33. active = new Ext.util.MixedCollection();
  34. map = Ext.getDoc().addKeyListener(27, hideAll);
  35. map.disable();
  36. }
  37. // private
  38. function hideAll(){
  39. if(active &amp;&amp; active.length &gt; 0){
  40. var c = active.clone();
  41. c.each(function(m){
  42. m.hide();
  43. });
  44. return true;
  45. }
  46. return false;
  47. }
  48. // private
  49. function onHide(m){
  50. active.remove(m);
  51. if(active.length &lt; 1){
  52. map.disable();
  53. Ext.getDoc().un(&quot;mousedown&quot;, onMouseDown);
  54. attached = false;
  55. }
  56. }
  57. // private
  58. function onShow(m){
  59. var last = active.last();
  60. lastShow = new Date();
  61. active.add(m);
  62. if(!attached){
  63. map.enable();
  64. Ext.getDoc().on(&quot;mousedown&quot;, onMouseDown);
  65. attached = true;
  66. }
  67. if(m.parentMenu){
  68. m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle(&quot;z-index&quot;), 10) + 3);
  69. m.parentMenu.activeChild = m;
  70. }else if(last &amp;&amp; !last.isDestroyed &amp;&amp; last.isVisible()){
  71. m.getEl().setZIndex(parseInt(last.getEl().getStyle(&quot;z-index&quot;), 10) + 3);
  72. }
  73. }
  74. // private
  75. function onBeforeHide(m){
  76. if(m.activeChild){
  77. m.activeChild.hide();
  78. }
  79. if(m.autoHideTimer){
  80. clearTimeout(m.autoHideTimer);
  81. delete m.autoHideTimer;
  82. }
  83. }
  84. // private
  85. function onBeforeShow(m){
  86. var pm = m.parentMenu;
  87. if(!pm &amp;&amp; !m.allowOtherMenus){
  88. hideAll();
  89. }else if(pm &amp;&amp; pm.activeChild){
  90. pm.activeChild.hide();
  91. }
  92. }
  93. // private
  94. function onMouseDown(e){
  95. if(lastShow.getElapsed() &gt; 50 &amp;&amp; active.length &gt; 0 &amp;&amp; !e.getTarget(&quot;.x-menu&quot;)){
  96. hideAll();
  97. }
  98. }
  99. return {
  100. <span id='Ext-menu-MenuMgr-method-hideAll'> /**
  101. </span> * Hides all menus that are currently visible
  102. * @return {Boolean} success True if any active menus were hidden.
  103. */
  104. hideAll : function(){
  105. return hideAll();
  106. },
  107. // private
  108. register : function(menu){
  109. if(!menus){
  110. init();
  111. }
  112. menus[menu.id] = menu;
  113. menu.on({
  114. beforehide: onBeforeHide,
  115. hide: onHide,
  116. beforeshow: onBeforeShow,
  117. show: onShow
  118. });
  119. },
  120. <span id='Ext-menu-MenuMgr-method-get'> /**
  121. </span> * Returns a {@link Ext.menu.Menu} object
  122. * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
  123. * be used to generate and return a new Menu instance.
  124. * @return {Ext.menu.Menu} The specified menu, or null if none are found
  125. */
  126. get : function(menu){
  127. if(typeof menu == &quot;string&quot;){ // menu id
  128. if(!menus){ // not initialized, no menus to return
  129. return null;
  130. }
  131. return menus[menu];
  132. }else if(menu.events){ // menu instance
  133. return menu;
  134. }else if(typeof menu.length == 'number'){ // array of menu items?
  135. return new Ext.menu.Menu({items:menu});
  136. }else{ // otherwise, must be a config
  137. return Ext.create(menu, 'menu');
  138. }
  139. },
  140. // private
  141. unregister : function(menu){
  142. delete menus[menu.id];
  143. menu.un(&quot;beforehide&quot;, onBeforeHide);
  144. menu.un(&quot;hide&quot;, onHide);
  145. menu.un(&quot;beforeshow&quot;, onBeforeShow);
  146. menu.un(&quot;show&quot;, onShow);
  147. },
  148. // private
  149. registerCheckable : function(menuItem){
  150. var g = menuItem.group;
  151. if(g){
  152. if(!groups[g]){
  153. groups[g] = [];
  154. }
  155. groups[g].push(menuItem);
  156. }
  157. },
  158. // private
  159. unregisterCheckable : function(menuItem){
  160. var g = menuItem.group;
  161. if(g){
  162. groups[g].remove(menuItem);
  163. }
  164. },
  165. // private
  166. onCheckChange: function(item, state){
  167. if(item.group &amp;&amp; state){
  168. var group = groups[item.group],
  169. i = 0,
  170. len = group.length,
  171. current;
  172. for(; i &lt; len; i++){
  173. current = group[i];
  174. if(current != item){
  175. current.setChecked(false);
  176. }
  177. }
  178. }
  179. },
  180. getCheckedItem : function(groupId){
  181. var g = groups[groupId];
  182. if(g){
  183. for(var i = 0, l = g.length; i &lt; l; i++){
  184. if(g[i].checked){
  185. return g[i];
  186. }
  187. }
  188. }
  189. return null;
  190. },
  191. setCheckedItem : function(groupId, itemId){
  192. var g = groups[groupId];
  193. if(g){
  194. for(var i = 0, l = g.length; i &lt; l; i++){
  195. if(g[i].id == itemId){
  196. g[i].setChecked(true);
  197. }
  198. }
  199. }
  200. return null;
  201. }
  202. };
  203. }();
  204. </pre>
  205. </body>
  206. </html>