2 * Toolbar button with menu that appears when hovered over.
4 Ext.define('Docs.view.HoverMenuButton', {
5 extend: 'Ext.toolbar.TextItem',
6 alias: 'widget.hovermenubutton',
7 componentCls: "hover-menu-button",
13 * @cfg {Ext.data.Store} store
14 * Store with menu items (required).
18 * @cfg {Object} menuCfg
19 * Additional config options for {@link Docs.view.HoverMenu}
24 * @cfg {Boolean} showCount
25 * True to show small number in button indicating the number of items in menu.
31 // Global list of all menus.
32 // So we can hide all other menus while showing a specific one.
36 initComponent: function() {
40 * Fired when button clicked.
45 * Fired when close link in menu clicked.
46 * @param {String} name Name of the class and or member that was closed.
47 * For example "Ext.Ajax" or "Ext.Ajax-method-request".
52 // Append links count to button text, update it when store filtered
54 this.initialText = this.text;
55 this.text += ' <sup>' + this.store.getCount() + '</sup>';
56 this.store.on("datachanged", function() {
57 this.setText(this.initialText + ' <sup>' + this.store.getCount() + '</sup>');
61 this.menu = Ext.create('Docs.view.HoverMenu', Ext.apply({
65 this.callParent(arguments);
68 onRender: function() {
69 this.callParent(arguments);
75 this.fireEvent("click");
77 mouseover: function() {
79 Ext.Array.forEach(Docs.view.HoverMenuButton.menus, function(menu) {
80 if (menu !== this.menu) {
84 // stop pending menuhide process
85 clearTimeout(this.hideTimeout);
87 // position menu right below button and show it
88 var p = this.getEl().getXY();
89 this.menu.getEl().setStyle({
94 mouseout: this.deferHideMenu,
98 this.menu.getEl().on({
99 mouseover: function() {
100 clearTimeout(this.hideTimeout);
102 mouseout: this.deferHideMenu,
108 onDestroy: function() {
111 // remove from global menu list
112 Ext.Array.remove(Docs.view.HoverMenuButton.menus, this.menu);
114 this.callParent(arguments);
117 renderMenu: function() {
118 this.menu.getEl().setVisibilityMode(Ext.core.Element.DISPLAY);
121 this.menu.getEl().addListener('click', function(e) {
122 if (e.getTarget(".close")) {
123 this.fireEvent("closeclick", e.getTarget().rel);
130 Docs.view.HoverMenuButton.menus.push(this.menu);
133 deferHideMenu: function() {
134 this.hideTimeout = Ext.Function.defer(function() {
140 * Returns the store used by menu.
141 * @return {Ext.data.Store}
143 getStore: function() {