Tool.html 13 KB

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