4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-panel-Tool'>/**
19 </span> * @class Ext.panel.Tool
20 * @extends Ext.Component
22 This class is used to display small visual icons in the header of a panel. There are a set of
23 25 icons that can be specified by using the {@link #type} config. The {@link #handler} config
24 can be used to provide a function that will respond to any click events. In general, this class
25 will not be instantiated directly, rather it will be created by specifying the {@link Ext.panel.Panel#tools}
26 configuration on the Panel itself.
30 Ext.create('Ext.panel.Panel', {
33 renderTo: document.body,
49 handler: function(event, target, owner, tool){
51 owner.child('#refresh').show();
58 Ext.define('Ext.panel.Tool', {
59 extend: 'Ext.Component',
60 requires: ['Ext.tip.QuickTipManager'],
63 baseCls: Ext.baseCSSPrefix + 'tool',
64 disabledCls: Ext.baseCSSPrefix + 'tool-disabled',
65 toolPressedCls: Ext.baseCSSPrefix + 'tool-pressed',
66 toolOverCls: Ext.baseCSSPrefix + 'tool-over',
68 renderTpl: ['<img src="{blank}" class="{baseCls}-{type}" role="presentation"/>'],
70 <span id='Ext-panel-Tool-cfg-handler'> /**
71 </span> * @cfg {Function} handler
72 * A function to execute when the tool is clicked.
73 * Arguments passed are:
75 * <li><b>event</b> : Ext.EventObject<div class="sub-desc">The click event.</div></li>
76 * <li><b>toolEl</b> : Ext.core.Element<div class="sub-desc">The tool Element.</div></li>
77 * <li><b>panel</b> : Ext.panel.Panel<div class="sub-desc">The host Panel</div></li>
78 * <li><b>tool</b> : Ext.panel.Tool<div class="sub-desc">The tool object</div></li>
82 <span id='Ext-panel-Tool-cfg-scope'> /**
83 </span> * @cfg {Object} scope
84 * The scope to execute the {@link #handler} function. Defaults to the tool.
87 <span id='Ext-panel-Tool-cfg-type'> /**
88 </span> * @cfg {String} type
89 * The type of tool to render. The following types are available:
91 * <li>close</li>
92 * <li>collapse</li>
93 * <li>down</li>
94 * <li>expand</li>
95 * <li>gear</li>
96 * <li>help</li>
97 * <li>left</li>
98 * <li>maximize</li>
99 * <li>minimize</li>
100 * <li>minus</li>
101 * <li>move</li>
102 * <li>next</li>
103 * <li>pin</li>
104 * <li>plus</li>
105 * <li>prev</li>
106 * <li>print</li>
107 * <li>refresh</li>
108 * <li>resize</li>
109 * <li>restore</li>
110 * <li>right</li>
111 * <li>save</li>
112 * <li>search</li>
113 * <li>toggle</li>
114 * <li>unpin</li>
115 * <li>up</li>
119 <span id='Ext-panel-Tool-cfg-tooltip'> /**
120 </span> * @cfg {String/Object} tooltip
121 * The tooltip for the tool - can be a string to be used as innerHTML (html tags are accepted) or QuickTips config object
124 <span id='Ext-panel-Tool-cfg-stopEvent'> /**
125 </span> * @cfg {Boolean} stopEvent
126 * Defaults to true. Specify as false to allow click event to propagate.
130 initComponent: function() {
133 <span id='Ext-panel-Tool-event-click'> /**
134 </span> * @event click
135 * Fires when the tool is clicked
136 * @param {Ext.panel.Tool} this
137 * @param {Ext.EventObject} e The event object
171 if (me.id && Ext.Array.indexOf(types, me.id) > -1 && Ext.global.console) {
172 Ext.global.console.warn('When specifying a tool you should use the type option, the id can conflict now that tool is a Component');
176 me.type = me.type || me.id;
178 Ext.applyIf(me.renderData, {
180 blank: Ext.BLANK_IMAGE_URL,
183 me.renderSelectors.toolEl = '.' + me.baseCls + '-' + me.type;
188 afterRender: function() {
190 me.callParent(arguments);
192 if (Ext.isObject(me.qtip)) {
193 Ext.tip.QuickTipManager.register(Ext.apply({
198 me.toolEl.dom.qtip = me.qtip;
204 mousedown: me.onMouseDown,
205 mouseover: me.onMouseOver,
206 mouseout: me.onMouseOut,
211 <span id='Ext-panel-Tool-method-setType'> /**
212 </span> * Set the type of the tool. Allows the icon to be changed.
213 * @param {String} type The new type. See the {@link #type} config.
214 * @return {Ext.panel.Tool} this
216 setType: function(type) {
221 me.toolEl.dom.className = me.baseCls + '-' + type;
226 <span id='Ext-panel-Tool-method-bindTo'> /**
227 </span> * Binds this tool to a component.
229 * @param {Ext.Component} component The component
231 bindTo: function(component) {
232 this.owner = component;
235 <span id='Ext-panel-Tool-method-onClick'> /**
236 </span> * Fired when the tool element is clicked
238 * @param {Ext.EventObject} e
239 * @param {HTMLElement} target The target element
241 onClick: function(e, target) {
248 owner = me.owner || me.ownerCt;
250 //remove the pressed + over class
251 me.el.removeCls(me.toolPressedCls);
252 me.el.removeCls(me.toolOverCls);
254 if (me.stopEvent !== false) {
258 Ext.callback(me.handler, me.scope || me, [e, target, owner, me]);
259 me.fireEvent('click', me, e);
264 onDestroy: function(){
265 if (Ext.isObject(this.tooltip)) {
266 Ext.tip.QuickTipManager.unregister(this.id);
271 <span id='Ext-panel-Tool-method-onMouseDown'> /**
272 </span> * Called then the user pressing their mouse button down on a tool
273 * Adds the press class ({@link #toolPressedCls})
276 onMouseDown: function() {
281 this.el.addCls(this.toolPressedCls);
284 <span id='Ext-panel-Tool-method-onMouseOver'> /**
285 </span> * Called when the user rolls over a tool
286 * Adds the over class ({@link #toolOverCls})
289 onMouseOver: function() {
293 this.el.addCls(this.toolOverCls);
296 <span id='Ext-panel-Tool-method-onMouseOut'> /**
297 </span> * Called when the user rolls out from a tool.
298 * Removes the over class ({@link #toolOverCls})
301 onMouseOut: function() {
302 this.el.removeCls(this.toolOverCls);