PageRenderTime 31ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/ext-4.1.0_b3/docs/source/Manager4.html

https://bitbucket.org/srogerf/javascript
HTML | 238 lines | 208 code | 30 blank | 0 comment | 0 complexity | 441b8b4941e74883f539c3e5cd69ed70 MD5 | raw file
  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-Manager'>/**
  19. </span> * Provides a common registry of all menus on a page.
  20. * @singleton
  21. */
  22. Ext.define('Ext.menu.Manager', {
  23. singleton: true,
  24. requires: [
  25. 'Ext.util.MixedCollection',
  26. 'Ext.util.KeyMap'
  27. ],
  28. alternateClassName: 'Ext.menu.MenuMgr',
  29. uses: ['Ext.menu.Menu'],
  30. menus: {},
  31. groups: {},
  32. attached: false,
  33. lastShow: new Date(),
  34. init: function() {
  35. var me = this;
  36. me.active = new Ext.util.MixedCollection();
  37. Ext.getDoc().addKeyListener(27, function() {
  38. if (me.active.length &gt; 0) {
  39. me.hideAll();
  40. }
  41. }, me);
  42. },
  43. <span id='Ext-menu-Manager-method-hideAll'> /**
  44. </span> * Hides all menus that are currently visible
  45. * @return {Boolean} success True if any active menus were hidden.
  46. */
  47. hideAll: function() {
  48. var active = this.active,
  49. clone, menus, m, mLen;
  50. if (active &amp;&amp; active.length &gt; 0) {
  51. clone = active.clone();
  52. menus = clone.items;
  53. mLen = menus.length;
  54. for (m = 0; m &lt; mLen; m++) {
  55. menus[m].hide();
  56. }
  57. return true;
  58. }
  59. return false;
  60. },
  61. onHide: function(m) {
  62. var me = this,
  63. active = me.active;
  64. active.remove(m);
  65. if (active.length &lt; 1) {
  66. Ext.getDoc().un('mousedown', me.onMouseDown, me);
  67. me.attached = false;
  68. }
  69. },
  70. onShow: function(m) {
  71. var me = this,
  72. active = me.active,
  73. last = active.last(),
  74. attached = me.attached,
  75. menuEl = m.getEl(),
  76. zIndex;
  77. me.lastShow = new Date();
  78. active.add(m);
  79. if (!attached) {
  80. Ext.getDoc().on('mousedown', me.onMouseDown, me, {
  81. // On IE we have issues with the menu stealing focus at certain points
  82. // during the head, so give it a short buffer
  83. buffer: Ext.isIE ? 10 : undefined
  84. });
  85. me.attached = true;
  86. }
  87. m.toFront();
  88. },
  89. onBeforeHide: function(m) {
  90. if (m.activeChild) {
  91. m.activeChild.hide();
  92. }
  93. if (m.autoHideTimer) {
  94. clearTimeout(m.autoHideTimer);
  95. delete m.autoHideTimer;
  96. }
  97. },
  98. onBeforeShow: function(m) {
  99. var active = this.active,
  100. parentMenu = m.parentMenu;
  101. active.remove(m);
  102. if (!parentMenu &amp;&amp; !m.allowOtherMenus) {
  103. this.hideAll();
  104. }
  105. else if (parentMenu &amp;&amp; parentMenu.activeChild &amp;&amp; m != parentMenu.activeChild) {
  106. parentMenu.activeChild.hide();
  107. }
  108. },
  109. // private
  110. onMouseDown: function(e) {
  111. var me = this,
  112. active = me.active,
  113. lastShow = me.lastShow;
  114. if (Ext.Date.getElapsed(lastShow) &gt; 50 &amp;&amp; active.length &gt; 0 &amp;&amp; !e.getTarget('.' + Ext.baseCSSPrefix + 'menu')) {
  115. me.hideAll();
  116. }
  117. },
  118. // private
  119. register: function(menu) {
  120. var me = this;
  121. if (!me.active) {
  122. me.init();
  123. }
  124. if (menu.floating) {
  125. me.menus[menu.id] = menu;
  126. menu.on({
  127. beforehide: me.onBeforeHide,
  128. hide: me.onHide,
  129. beforeshow: me.onBeforeShow,
  130. show: me.onShow,
  131. scope: me
  132. });
  133. }
  134. },
  135. <span id='Ext-menu-Manager-method-get'> /**
  136. </span> * Returns a {@link Ext.menu.Menu} object
  137. * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
  138. * be used to generate and return a new Menu this.
  139. * @return {Ext.menu.Menu} The specified menu, or null if none are found
  140. */
  141. get: function(menu) {
  142. var menus = this.menus;
  143. if (typeof menu == 'string') { // menu id
  144. if (!menus) { // not initialized, no menus to return
  145. return null;
  146. }
  147. return menus[menu];
  148. } else if (menu.isMenu) { // menu instance
  149. return menu;
  150. } else if (Ext.isArray(menu)) { // array of menu items
  151. return new Ext.menu.Menu({items:menu});
  152. } else { // otherwise, must be a config
  153. return Ext.ComponentManager.create(menu, 'menu');
  154. }
  155. },
  156. // private
  157. unregister: function(menu) {
  158. var me = this,
  159. menus = me.menus,
  160. active = me.active;
  161. delete menus[menu.id];
  162. active.remove(menu);
  163. menu.un({
  164. beforehide: me.onBeforeHide,
  165. hide: me.onHide,
  166. beforeshow: me.onBeforeShow,
  167. show: me.onShow,
  168. scope: me
  169. });
  170. },
  171. // private
  172. registerCheckable: function(menuItem) {
  173. var groups = this.groups,
  174. groupId = menuItem.group;
  175. if (groupId) {
  176. if (!groups[groupId]) {
  177. groups[groupId] = [];
  178. }
  179. groups[groupId].push(menuItem);
  180. }
  181. },
  182. // private
  183. unregisterCheckable: function(menuItem) {
  184. var groups = this.groups,
  185. groupId = menuItem.group;
  186. if (groupId) {
  187. Ext.Array.remove(groups[groupId], menuItem);
  188. }
  189. },
  190. onCheckChange: function(menuItem, state) {
  191. var groups = this.groups,
  192. groupId = menuItem.group,
  193. i = 0,
  194. group, ln, curr;
  195. if (groupId &amp;&amp; state) {
  196. group = groups[groupId];
  197. ln = group.length;
  198. for (; i &lt; ln; i++) {
  199. curr = group[i];
  200. if (curr != menuItem) {
  201. curr.setChecked(false);
  202. }
  203. }
  204. }
  205. }
  206. });</pre>
  207. </body>
  208. </html>