Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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