65c59fc1979e756191e53614b918fd3274217151.svn-base 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. /**
  7. * @class Ext.menu.BaseItem
  8. * @extends Ext.Component The base class for all items that render into menus.
  9. * BaseItem provides default rendering, activated state management and
  10. * base configuration options shared by all menu components.
  11. * @constructor Creates a new BaseItem
  12. * @param {Object}
  13. * config Configuration options
  14. */
  15. Ext.menu.BaseItem = function(config) {
  16. Ext.menu.BaseItem.superclass.constructor.call(this, config);
  17. this.addEvents(
  18. /**
  19. * @event click Fires when this item is clicked
  20. * @param {Ext.menu.BaseItem}
  21. * this
  22. * @param {Ext.EventObject}
  23. * e
  24. */
  25. 'click',
  26. /**
  27. * @event activate Fires when this item is activated
  28. * @param {Ext.menu.BaseItem}
  29. * this
  30. */
  31. 'activate',
  32. /**
  33. * @event deactivate Fires when this item is deactivated
  34. * @param {Ext.menu.BaseItem}
  35. * this
  36. */
  37. 'deactivate');
  38. if (this.handler) {
  39. this.on("click", this.handler, this.scope);
  40. }
  41. };
  42. Ext.extend(Ext.menu.BaseItem, Ext.Component, {
  43. /**
  44. * @cfg {Function} handler A function that will handle the click event of
  45. * this menu item (defaults to undefined)
  46. */
  47. /**
  48. * @cfg {Object} scope The scope in which the handler function will be
  49. * called.
  50. */
  51. /**
  52. * @cfg {Boolean} canActivate True if this item can be visually activated
  53. * (defaults to false)
  54. */
  55. canActivate : false,
  56. /**
  57. * @cfg {String} activeClass The CSS class to use when the item becomes
  58. * activated (defaults to "x-menu-item-active")
  59. */
  60. activeClass : "x-menu-item-active",
  61. /**
  62. * @cfg {Boolean} hideOnClick True to hide the containing menu after this
  63. * item is clicked (defaults to true)
  64. */
  65. hideOnClick : true,
  66. /**
  67. * @cfg {Number} hideDelay Length of time in milliseconds to wait before
  68. * hiding after a click (defaults to 100)
  69. */
  70. hideDelay : 100,
  71. // private
  72. ctype : "Ext.menu.BaseItem",
  73. // private
  74. actionMode : "container",
  75. // private
  76. render : function(container, parentMenu) {
  77. this.parentMenu = parentMenu;
  78. Ext.menu.BaseItem.superclass.render.call(this, container);
  79. this.container.menuItemId = this.id;
  80. },
  81. // private
  82. onRender : function(container, position) {
  83. this.el = Ext.get(this.el);
  84. container.dom.appendChild(this.el.dom);
  85. },
  86. /**
  87. * Sets the function that will handle click events for this item (equivalent
  88. * to passing in the {@link #handler} config property). If an existing
  89. * handler is already registered, it will be unregistered for you.
  90. *
  91. * @param {Function}
  92. * handler The function that should be called on click
  93. * @param {Object}
  94. * scope The scope that should be passed to the handler
  95. */
  96. setHandler : function(handler, scope) {
  97. if (this.handler) {
  98. this.un("click", this.handler, this.scope);
  99. }
  100. this.on("click", this.handler = handler, this.scope = scope);
  101. },
  102. // private
  103. onClick : function(e) {
  104. if (!this.disabled && this.fireEvent("click", this, e) !== false
  105. && this.parentMenu.fireEvent("itemclick", this, e) !== false) {
  106. this.handleClick(e);
  107. } else {
  108. e.stopEvent();
  109. }
  110. },
  111. // private
  112. activate : function() {
  113. if (this.disabled) {
  114. return false;
  115. }
  116. var li = this.container;
  117. li.addClass(this.activeClass);
  118. this.region = li.getRegion().adjust(2, 2, -2, -2);
  119. this.fireEvent("activate", this);
  120. return true;
  121. },
  122. // private
  123. deactivate : function() {
  124. this.container.removeClass(this.activeClass);
  125. this.fireEvent("deactivate", this);
  126. },
  127. // private
  128. shouldDeactivate : function(e) {
  129. return !this.region || !this.region.contains(e.getPoint());
  130. },
  131. // private
  132. handleClick : function(e) {
  133. if (this.hideOnClick) {
  134. this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
  135. }
  136. },
  137. // private
  138. expandMenu : function(autoActivate) {
  139. // do nothing
  140. },
  141. // private
  142. hideMenu : function() {
  143. // do nothing
  144. }
  145. });