Tool.js
10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/**
* This class is used to display small visual icons in the header of a panel. There are a set of
* 25 icons that can be specified by using the {@link #type} config. The {@link #handler} config
* can be used to provide a function that will respond to any click events. In general, this class
* will not be instantiated directly, rather it will be created by specifying the {@link Ext.panel.Panel#tools}
* configuration on the Panel itself.
*
* @example
* Ext.create('Ext.panel.Panel', {
* width: 200,
* height: 200,
* renderTo: document.body,
* title: 'A Panel',
* tools: [{
* type: 'help',
* handler: function(){
* // show help here
* }
* }, {
* itemId: 'refresh',
* type: 'refresh',
* hidden: true,
* handler: function(){
* // do refresh
* }
* }, {
* type: 'search',
* handler: function(event, target, owner, tool){
* // do search
* owner.child('#refresh').show();
* }
* }]
* });
*/
Ext.define('Ext.panel.Tool', {
extend: 'Ext.Component',
requires: ['Ext.tip.QuickTipManager'],
alias: 'widget.tool',
baseCls: Ext.baseCSSPrefix + 'tool',
disabledCls: Ext.baseCSSPrefix + 'tool-disabled',
/**
* @cfg
* @private
*/
toolPressedCls: Ext.baseCSSPrefix + 'tool-pressed',
/**
* @cfg
* @private
*/
toolOverCls: Ext.baseCSSPrefix + 'tool-over',
ariaRole: 'button',
childEls: [
'toolEl'
],
renderTpl: [
'<img id="{id}-toolEl" src="{blank}" class="{baseCls}-{type}" role="presentation"/>'
],
/**
* @cfg {Function} handler
* A function to execute when the tool is clicked. Arguments passed are:
*
* - **event** : Ext.EventObject - The click event.
* - **toolEl** : Ext.Element - The tool Element.
* - **owner** : Ext.panel.Header - The host panel header.
* - **tool** : Ext.panel.Tool - The tool object
*/
/**
* @cfg {Object} scope
* The scope to execute the {@link #handler} function. Defaults to the tool.
*/
/**
* @cfg {String} type
* The type of tool to render. The following types are available:
*
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-close"></span> close
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-minimize"></span> minimize
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-maximize"></span> maximize
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-restore"></span> restore
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-toggle"></span> toggle
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-gear"></span> gear
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-prev"></span> prev
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-next"></span> next
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-pin"></span> pin
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-unpin"></span> unpin
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-right"></span> right
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-left"></span> left
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-down"></span> down
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-up"></span> up
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-refresh"></span> refresh
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-plus"></span> plus
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-minus"></span> minus
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-search"></span> search
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-save"></span> save
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-help"></span> help
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-print"></span> print
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-expand"></span> expand
* - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-collapse"></span> collapse
*/
/**
* @cfg {String/Object} tooltip
* The tooltip for the tool - can be a string to be used as innerHTML (html tags are accepted) or QuickTips config
* object
*/
/**
* @cfg {String} tooltipType
* The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
*/
tooltipType: 'qtip',
/**
* @cfg {Boolean} stopEvent
* Specify as false to allow click event to propagate.
*/
stopEvent: true,
height: 15,
width: 15,
//<debug>
_toolTypes: {
close:1,
collapse:1,
down:1,
expand:1,
gear:1,
help:1,
left:1,
maximize:1,
minimize:1,
minus:1,
//move:1,
next:1,
pin:1,
plus:1,
prev:1,
print:1,
refresh:1,
//resize:1,
restore:1,
right:1,
save:1,
search:1,
toggle:1,
unpin:1,
up:1
},
//</debug>
initComponent: function() {
var me = this;
me.addEvents(
/**
* @event click
* Fires when the tool is clicked
* @param {Ext.panel.Tool} this
* @param {Ext.EventObject} e The event object
*/
'click'
);
//<debug>
if (me.id && me._toolTypes[me.id] && Ext.global.console) {
Ext.global.console.warn('When specifying a tool you should use the type option, the id can conflict now that tool is a Component');
}
//</debug>
me.type = me.type || me.id;
Ext.applyIf(me.renderData, {
baseCls: me.baseCls,
blank: Ext.BLANK_IMAGE_URL,
type: me.type
});
// alias qtip, should use tooltip since it's what we have in the docs
me.tooltip = me.tooltip || me.qtip;
me.callParent();
me.on({
element: 'toolEl',
click: me.onClick,
mousedown: me.onMouseDown,
mouseover: me.onMouseOver,
mouseout: me.onMouseOut,
scope: me
});
},
// inherit docs
afterRender: function() {
var me = this,
attr;
me.callParent(arguments);
if (me.tooltip) {
if (Ext.isObject(me.tooltip)) {
Ext.tip.QuickTipManager.register(Ext.apply({
target: me.id
}, me.tooltip));
}
else {
attr = me.tooltipType == 'qtip' ? 'data-qtip' : 'title';
me.toolEl.dom.setAttribute(attr, me.tooltip);
}
}
},
getFocusEl: function() {
return this.el;
},
/**
* Sets the type of the tool. Allows the icon to be changed.
* @param {String} type The new type. See the {@link #type} config.
* @return {Ext.panel.Tool} this
*/
setType: function(type) {
var me = this;
me.type = type;
if (me.rendered) {
me.toolEl.dom.className = me.baseCls + '-' + type;
}
return me;
},
/**
* Binds this tool to a component.
* @private
* @param {Ext.Component} component The component
*/
bindTo: function(component) {
this.owner = component;
},
/**
* Called when the tool element is clicked
* @private
* @param {Ext.EventObject} e
* @param {HTMLElement} target The target element
*/
onClick: function(e, target) {
var me = this,
owner;
if (me.disabled) {
return false;
}
owner = me.owner || me.ownerCt;
//remove the pressed + over class
me.el.removeCls(me.toolPressedCls);
me.el.removeCls(me.toolOverCls);
if (me.stopEvent !== false) {
e.stopEvent();
}
Ext.callback(me.handler, me.scope || me, [e, target, owner, me]);
me.fireEvent('click', me, e);
return true;
},
// inherit docs
onDestroy: function(){
if (Ext.isObject(this.tooltip)) {
Ext.tip.QuickTipManager.unregister(this.id);
}
this.callParent();
},
/**
* Called when the user presses their mouse button down on a tool
* Adds the press class ({@link #toolPressedCls})
* @private
*/
onMouseDown: function() {
if (this.disabled) {
return false;
}
this.el.addCls(this.toolPressedCls);
},
/**
* Called when the user rolls over a tool
* Adds the over class ({@link #toolOverCls})
* @private
*/
onMouseOver: function() {
if (this.disabled) {
return false;
}
this.el.addCls(this.toolOverCls);
},
/**
* Called when the user rolls out from a tool.
* Removes the over class ({@link #toolOverCls})
* @private
*/
onMouseOut: function() {
this.el.removeCls(this.toolOverCls);
}
});