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();
59 Ext.define('Ext.panel.Tool', {
60 extend: 'Ext.Component',
61 requires: ['Ext.tip.QuickTipManager'],
64 baseCls: Ext.baseCSSPrefix + 'tool',
65 disabledCls: Ext.baseCSSPrefix + 'tool-disabled',
66 toolPressedCls: Ext.baseCSSPrefix + 'tool-pressed',
67 toolOverCls: Ext.baseCSSPrefix + 'tool-over',
69 renderTpl: ['<img src="{blank}" class="{baseCls}-{type}" role="presentation"/>'],
71 <span id='Ext-panel-Tool-cfg-handler'> /**
72 </span> * @cfg {Function} handler
73 * A function to execute when the tool is clicked.
74 * Arguments passed are:
76 * <li><b>event</b> : Ext.EventObject<div class="sub-desc">The click event.</div></li>
77 * <li><b>toolEl</b> : Ext.core.Element<div class="sub-desc">The tool Element.</div></li>
78 * <li><b>panel</b> : Ext.panel.Panel<div class="sub-desc">The host Panel</div></li>
79 * <li><b>tool</b> : Ext.panel.Tool<div class="sub-desc">The tool object</div></li>
83 <span id='Ext-panel-Tool-cfg-scope'> /**
84 </span> * @cfg {Object} scope
85 * The scope to execute the {@link #handler} function. Defaults to the tool.
88 <span id='Ext-panel-Tool-cfg-type'> /**
89 </span> * @cfg {String} type
90 * The type of tool to render. The following types are available:
92 * <li>close</li>
93 * <li>collapse</li>
94 * <li>down</li>
95 * <li>expand</li>
96 * <li>gear</li>
97 * <li>help</li>
98 * <li>left</li>
99 * <li>maximize</li>
100 * <li>minimize</li>
101 * <li>minus</li>
102 * <li>move</li>
103 * <li>next</li>
104 * <li>pin</li>
105 * <li>plus</li>
106 * <li>prev</li>
107 * <li>print</li>
108 * <li>refresh</li>
109 * <li>resize</li>
110 * <li>restore</li>
111 * <li>right</li>
112 * <li>save</li>
113 * <li>search</li>
114 * <li>toggle</li>
115 * <li>unpin</li>
116 * <li>up</li>
120 <span id='Ext-panel-Tool-cfg-tooltip'> /**
121 </span> * @cfg {String/Object} tooltip
122 * The tooltip for the tool - can be a string to be used as innerHTML (html tags are accepted) or QuickTips config object
125 <span id='Ext-panel-Tool-cfg-stopEvent'> /**
126 </span> * @cfg {Boolean} stopEvent
127 * Defaults to true. Specify as false to allow click event to propagate.
131 initComponent: function() {
134 <span id='Ext-panel-Tool-event-click'> /**
135 </span> * @event click
136 * Fires when the tool is clicked
137 * @param {Ext.panel.Tool} this
138 * @param {Ext.EventObject} e The event object
172 if (me.id && Ext.Array.indexOf(types, me.id) > -1 && Ext.global.console) {
173 Ext.global.console.warn('When specifying a tool you should use the type option, the id can conflict now that tool is a Component');
177 me.type = me.type || me.id;
179 Ext.applyIf(me.renderData, {
181 blank: Ext.BLANK_IMAGE_URL,
184 me.renderSelectors.toolEl = '.' + me.baseCls + '-' + me.type;
189 afterRender: function() {
191 me.callParent(arguments);
193 if (Ext.isObject(me.qtip)) {
194 Ext.tip.QuickTipManager.register(Ext.apply({
199 me.toolEl.dom.qtip = me.qtip;
205 mousedown: me.onMouseDown,
206 mouseover: me.onMouseOver,
207 mouseout: me.onMouseOut,
212 <span id='Ext-panel-Tool-method-setType'> /**
213 </span> * Set the type of the tool. Allows the icon to be changed.
214 * @param {String} type The new type. See the {@link #type} config.
215 * @return {Ext.panel.Tool} this
217 setType: function(type) {
222 me.toolEl.dom.className = me.baseCls + '-' + type;
227 <span id='Ext-panel-Tool-method-bindTo'> /**
228 </span> * Binds this tool to a component.
230 * @param {Ext.Component} component The component
232 bindTo: function(component) {
233 this.owner = component;
236 <span id='Ext-panel-Tool-method-onClick'> /**
237 </span> * Fired when the tool element is clicked
239 * @param {Ext.EventObject} e
240 * @param {HTMLElement} target The target element
242 onClick: function(e, target) {
249 owner = me.owner || me.ownerCt;
251 //remove the pressed + over class
252 me.el.removeCls(me.toolPressedCls);
253 me.el.removeCls(me.toolOverCls);
255 if (me.stopEvent !== false) {
259 Ext.callback(me.handler, me.scope || me, [e, target, owner, me]);
260 me.fireEvent('click', me, e);
265 onDestroy: function(){
266 if (Ext.isObject(this.tooltip)) {
267 Ext.tip.QuickTipManager.unregister(this.id);
272 <span id='Ext-panel-Tool-method-onMouseDown'> /**
273 </span> * Called then the user pressing their mouse button down on a tool
274 * Adds the press class ({@link #toolPressedCls})
277 onMouseDown: function() {
282 this.el.addCls(this.toolPressedCls);
285 <span id='Ext-panel-Tool-method-onMouseOver'> /**
286 </span> * Called when the user rolls over a tool
287 * Adds the over class ({@link #toolOverCls})
290 onMouseOver: function() {
294 this.el.addCls(this.toolOverCls);
297 <span id='Ext-panel-Tool-method-onMouseOut'> /**
298 </span> * Called when the user rolls out from a tool.
299 * Removes the over class ({@link #toolOverCls})
302 onMouseOut: function() {
303 this.el.removeCls(this.toolOverCls);