4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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> * This class is used to display small visual icons in the header of a panel. There are a set of
20 * 25 icons that can be specified by using the {@link #type} config. The {@link #handler} config
21 * can be used to provide a function that will respond to any click events. In general, this class
22 * will not be instantiated directly, rather it will be created by specifying the {@link Ext.panel.Panel#tools}
23 * configuration on the Panel itself.
26 * Ext.create('Ext.panel.Panel', {
29 * renderTo: document.body,
33 * handler: function(){
40 * handler: function(){
45 * handler: function(event, target, owner, tool){
47 * owner.child('#refresh').show();
52 Ext.define('Ext.panel.Tool', {
53 extend: 'Ext.Component',
54 requires: ['Ext.tip.QuickTipManager'],
57 baseCls: Ext.baseCSSPrefix + 'tool',
58 disabledCls: Ext.baseCSSPrefix + 'tool-disabled',
59 toolPressedCls: Ext.baseCSSPrefix + 'tool-pressed',
60 toolOverCls: Ext.baseCSSPrefix + 'tool-over',
62 renderTpl: ['<img id="{id}-toolEl" src="{blank}" class="{baseCls}-{type}" role="presentation"/>'],
64 <span id='Ext-panel-Tool-cfg-handler'> /**
65 </span> * @cfg {Function} handler
66 * A function to execute when the tool is clicked. Arguments passed are:
68 * - **event** : Ext.EventObject - The click event.
69 * - **toolEl** : Ext.Element - The tool Element.
70 * - **owner** : Ext.panel.Header - The host panel header.
71 * - **tool** : Ext.panel.Tool - The tool object
74 <span id='Ext-panel-Tool-cfg-scope'> /**
75 </span> * @cfg {Object} scope
76 * The scope to execute the {@link #handler} function. Defaults to the tool.
79 <span id='Ext-panel-Tool-cfg-type'> /**
80 </span> * @cfg {String} type
81 * The type of tool to render. The following types are available:
83 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-close"></span> close
84 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-minimize"></span> minimize
85 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-maximize"></span> maximize
86 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-restore"></span> restore
87 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-toggle"></span> toggle
88 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-gear"></span> gear
89 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-prev"></span> prev
90 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-next"></span> next
91 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-pin"></span> pin
92 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-unpin"></span> unpin
93 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-right"></span> right
94 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-left"></span> left
95 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-down"></span> down
96 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-up"></span> up
97 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-refresh"></span> refresh
98 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-plus"></span> plus
99 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-minus"></span> minus
100 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-search"></span> search
101 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-save"></span> save
102 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-help"></span> help
103 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-print"></span> print
104 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-expand"></span> expand
105 * - <span class="x-tool"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tool-collapse"></span> collapse
108 <span id='Ext-panel-Tool-cfg-tooltip'> /**
109 </span> * @cfg {String/Object} tooltip
110 * The tooltip for the tool - can be a string to be used as innerHTML (html tags are accepted) or QuickTips config
114 <span id='Ext-panel-Tool-cfg-tooltipType'> /**
115 </span> * @cfg {String} tooltipType
116 * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
120 <span id='Ext-panel-Tool-cfg-stopEvent'> /**
121 </span> * @cfg {Boolean} stopEvent
122 * Specify as false to allow click event to propagate.
126 initComponent: function() {
129 <span id='Ext-panel-Tool-event-click'> /**
130 </span> * @event click
131 * Fires when the tool is clicked
132 * @param {Ext.panel.Tool} this
133 * @param {Ext.EventObject} e The event object
167 if (me.id && Ext.Array.indexOf(types, me.id) > -1 && Ext.global.console) {
168 Ext.global.console.warn('When specifying a tool you should use the type option, the id can conflict now that tool is a Component');
172 me.type = me.type || me.id;
174 Ext.applyIf(me.renderData, {
176 blank: Ext.BLANK_IMAGE_URL,
180 me.addChildEls('toolEl');
182 // alias qtip, should use tooltip since it's what we have in the docs
183 me.tooltip = me.tooltip || me.qtip;
188 afterRender: function() {
192 me.callParent(arguments);
194 if (Ext.isObject(me.tooltip)) {
195 Ext.tip.QuickTipManager.register(Ext.apply({
200 attr = me.tooltipType == 'qtip' ? 'data-qtip' : 'title';
201 me.toolEl.dom.setAttribute(attr, me.tooltip);
207 mousedown: me.onMouseDown,
208 mouseover: me.onMouseOver,
209 mouseout: me.onMouseOut,
214 <span id='Ext-panel-Tool-method-setType'> /**
215 </span> * Sets the type of the tool. Allows the icon to be changed.
216 * @param {String} type The new type. See the {@link #type} config.
217 * @return {Ext.panel.Tool} this
219 setType: function(type) {
224 me.toolEl.dom.className = me.baseCls + '-' + type;
229 <span id='Ext-panel-Tool-method-bindTo'> /**
230 </span> * Binds this tool to a component.
232 * @param {Ext.Component} component The component
234 bindTo: function(component) {
235 this.owner = component;
238 <span id='Ext-panel-Tool-method-onClick'> /**
239 </span> * Called when the tool element is clicked
241 * @param {Ext.EventObject} e
242 * @param {HTMLElement} target The target element
244 onClick: function(e, target) {
251 owner = me.owner || me.ownerCt;
253 //remove the pressed + over class
254 me.el.removeCls(me.toolPressedCls);
255 me.el.removeCls(me.toolOverCls);
257 if (me.stopEvent !== false) {
261 Ext.callback(me.handler, me.scope || me, [e, target, owner, me]);
262 me.fireEvent('click', me, e);
267 onDestroy: function(){
268 if (Ext.isObject(this.tooltip)) {
269 Ext.tip.QuickTipManager.unregister(this.id);
274 <span id='Ext-panel-Tool-method-onMouseDown'> /**
275 </span> * Called when the user presses their mouse button down on a tool
276 * Adds the press class ({@link #toolPressedCls})
279 onMouseDown: function() {
284 this.el.addCls(this.toolPressedCls);
287 <span id='Ext-panel-Tool-method-onMouseOver'> /**
288 </span> * Called when the user rolls over a tool
289 * Adds the over class ({@link #toolOverCls})
292 onMouseOver: function() {
296 this.el.addCls(this.toolOverCls);
299 <span id='Ext-panel-Tool-method-onMouseOut'> /**
300 </span> * Called when the user rolls out from a tool.
301 * Removes the over class ({@link #toolOverCls})
304 onMouseOut: function() {
305 this.el.removeCls(this.toolOverCls);