Button2.html 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  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-button-Button'>/**
  19. </span> * @docauthor Robert Dougan &lt;rob@sencha.com&gt;
  20. *
  21. * Create simple buttons with this component. Customisations include {@link #iconAlign aligned}
  22. * {@link #iconCls icons}, {@link #cfg-menu dropdown menus}, {@link #tooltip tooltips}
  23. * and {@link #scale sizing options}. Specify a {@link #handler handler} to run code when
  24. * a user clicks the button, or use {@link #listeners listeners} for other events such as
  25. * {@link #mouseover mouseover}. Example usage:
  26. *
  27. * @example
  28. * Ext.create('Ext.Button', {
  29. * text: 'Click me',
  30. * renderTo: Ext.getBody(),
  31. * handler: function() {
  32. * alert('You clicked the button!');
  33. * }
  34. * });
  35. *
  36. * The {@link #handler} configuration can also be updated dynamically using the {@link #setHandler}
  37. * method. Example usage:
  38. *
  39. * @example
  40. * Ext.create('Ext.Button', {
  41. * text : 'Dynamic Handler Button',
  42. * renderTo: Ext.getBody(),
  43. * handler : function() {
  44. * // this button will spit out a different number every time you click it.
  45. * // so firstly we must check if that number is already set:
  46. * if (this.clickCount) {
  47. * // looks like the property is already set, so lets just add 1 to that number and alert the user
  48. * this.clickCount++;
  49. * alert('You have clicked the button &quot;' + this.clickCount + '&quot; times.\n\nTry clicking it again..');
  50. * } else {
  51. * // if the clickCount property is not set, we will set it and alert the user
  52. * this.clickCount = 1;
  53. * alert('You just clicked the button for the first time!\n\nTry pressing it again..');
  54. * }
  55. * }
  56. * });
  57. *
  58. * A button within a container:
  59. *
  60. * @example
  61. * Ext.create('Ext.Container', {
  62. * renderTo: Ext.getBody(),
  63. * items : [
  64. * {
  65. * xtype: 'button',
  66. * text : 'My Button'
  67. * }
  68. * ]
  69. * });
  70. *
  71. * A useful option of Button is the {@link #scale} configuration. This configuration has three different options:
  72. *
  73. * - `'small'`
  74. * - `'medium'`
  75. * - `'large'`
  76. *
  77. * Example usage:
  78. *
  79. * @example
  80. * Ext.create('Ext.Button', {
  81. * renderTo: document.body,
  82. * text : 'Click me',
  83. * scale : 'large'
  84. * });
  85. *
  86. * Buttons can also be toggled. To enable this, you simple set the {@link #enableToggle} property to `true`.
  87. * Example usage:
  88. *
  89. * @example
  90. * Ext.create('Ext.Button', {
  91. * renderTo: Ext.getBody(),
  92. * text: 'Click Me',
  93. * enableToggle: true
  94. * });
  95. *
  96. * You can assign a menu to a button by using the {@link #cfg-menu} configuration. This standard configuration
  97. * can either be a reference to a {@link Ext.menu.Menu menu} object, a {@link Ext.menu.Menu menu} id or a
  98. * {@link Ext.menu.Menu menu} config blob. When assigning a menu to a button, an arrow is automatically
  99. * added to the button. You can change the alignment of the arrow using the {@link #arrowAlign} configuration
  100. * on button. Example usage:
  101. *
  102. * @example
  103. * Ext.create('Ext.Button', {
  104. * text : 'Menu button',
  105. * renderTo : Ext.getBody(),
  106. * arrowAlign: 'bottom',
  107. * menu : [
  108. * {text: 'Item 1'},
  109. * {text: 'Item 2'},
  110. * {text: 'Item 3'},
  111. * {text: 'Item 4'}
  112. * ]
  113. * });
  114. *
  115. * Using listeners, you can easily listen to events fired by any component, using the {@link #listeners}
  116. * configuration or using the {@link #addListener} method. Button has a variety of different listeners:
  117. *
  118. * - `click`
  119. * - `toggle`
  120. * - `mouseover`
  121. * - `mouseout`
  122. * - `mouseshow`
  123. * - `menuhide`
  124. * - `menutriggerover`
  125. * - `menutriggerout`
  126. *
  127. * Example usage:
  128. *
  129. * @example
  130. * Ext.create('Ext.Button', {
  131. * text : 'Button',
  132. * renderTo : Ext.getBody(),
  133. * listeners: {
  134. * click: function() {
  135. * // this == the button, as we are in the local scope
  136. * this.setText('I was clicked!');
  137. * },
  138. * mouseover: function() {
  139. * // set a new config which says we moused over, if not already set
  140. * if (!this.mousedOver) {
  141. * this.mousedOver = true;
  142. * alert('You moused over a button!\n\nI wont do this again.');
  143. * }
  144. * }
  145. * }
  146. * });
  147. */
  148. Ext.define('Ext.button.Button', {
  149. /* Begin Definitions */
  150. alias: 'widget.button',
  151. extend: 'Ext.Component',
  152. requires: [
  153. 'Ext.menu.Manager',
  154. 'Ext.util.ClickRepeater',
  155. 'Ext.layout.component.Button',
  156. 'Ext.util.TextMetrics',
  157. 'Ext.util.KeyMap'
  158. ],
  159. alternateClassName: 'Ext.Button',
  160. /* End Definitions */
  161. /*
  162. * @property {Boolean} isAction
  163. * `true` in this class to identify an object as an instantiated Button, or subclass thereof.
  164. */
  165. isButton: true,
  166. componentLayout: 'button',
  167. <span id='Ext-button-Button-property-hidden'> /**
  168. </span> * @property {Boolean} hidden
  169. * True if this button is hidden.
  170. * @readonly
  171. */
  172. hidden: false,
  173. <span id='Ext-button-Button-property-disabled'> /**
  174. </span> * @property {Boolean} disabled
  175. * True if this button is disabled.
  176. * @readonly
  177. */
  178. disabled: false,
  179. <span id='Ext-button-Button-property-pressed'> /**
  180. </span> * @property {Boolean} pressed
  181. * True if this button is pressed (only if enableToggle = true).
  182. * @readonly
  183. */
  184. pressed: false,
  185. <span id='Ext-button-Button-cfg-text'> /**
  186. </span> * @cfg {String} text
  187. * The button text to be used as innerHTML (html tags are accepted).
  188. */
  189. <span id='Ext-button-Button-cfg-icon'> /**
  190. </span> * @cfg {String} icon
  191. * The path to an image to display in the button.
  192. */
  193. <span id='Ext-button-Button-cfg-handler'> /**
  194. </span> * @cfg {Function} handler
  195. * A function called when the button is clicked (can be used instead of click event).
  196. * @cfg {Ext.button.Button} handler.button This button.
  197. * @cfg {Ext.EventObject} handler.e The click event.
  198. */
  199. <span id='Ext-button-Button-cfg-minWidth'> /**
  200. </span> * @cfg {Number} minWidth
  201. * The minimum width for this button (used to give a set of buttons a common width).
  202. * See also {@link Ext.panel.Panel}.{@link Ext.panel.Panel#minButtonWidth minButtonWidth}.
  203. */
  204. <span id='Ext-button-Button-cfg-tooltip'> /**
  205. </span> * @cfg {String/Object} tooltip
  206. * The tooltip for the button - can be a string to be used as innerHTML (html tags are accepted) or
  207. * QuickTips config object.
  208. */
  209. <span id='Ext-button-Button-cfg-hidden'> /**
  210. </span> * @cfg {Boolean} [hidden=false]
  211. * True to start hidden.
  212. */
  213. <span id='Ext-button-Button-cfg-disabled'> /**
  214. </span> * @cfg {Boolean} [disabled=false]
  215. * True to start disabled.
  216. */
  217. <span id='Ext-button-Button-cfg-pressed'> /**
  218. </span> * @cfg {Boolean} [pressed=false]
  219. * True to start pressed (only if enableToggle = true)
  220. */
  221. <span id='Ext-button-Button-cfg-toggleGroup'> /**
  222. </span> * @cfg {String} toggleGroup
  223. * The group this toggle button is a member of (only 1 per group can be pressed). If a toggleGroup
  224. * is specified, the {@link #enableToggle} configuration will automatically be set to true.
  225. */
  226. <span id='Ext-button-Button-cfg-repeat'> /**
  227. </span> * @cfg {Boolean/Object} [repeat=false]
  228. * True to repeat fire the click event while the mouse is down. This can also be a
  229. * {@link Ext.util.ClickRepeater ClickRepeater} config object.
  230. */
  231. <span id='Ext-button-Button-cfg-tabIndex'> /**
  232. </span> * @cfg {Number} tabIndex
  233. * Set a DOM tabIndex for this button.
  234. */
  235. <span id='Ext-button-Button-cfg-allowDepress'> /**
  236. </span> * @cfg {Boolean} [allowDepress=true]
  237. * False to not allow a pressed Button to be depressed. Only valid when {@link #enableToggle} is true.
  238. */
  239. <span id='Ext-button-Button-cfg-enableToggle'> /**
  240. </span> * @cfg {Boolean} [enableToggle=false]
  241. * True to enable pressed/not pressed toggling. If a {@link #toggleGroup} is specified, this
  242. * option will be set to true.
  243. */
  244. enableToggle: false,
  245. <span id='Ext-button-Button-cfg-toggleHandler'> /**
  246. </span> * @cfg {Function} toggleHandler
  247. * Function called when a Button with {@link #enableToggle} set to true is clicked.
  248. * @cfg {Ext.button.Button} toggleHandler.button This button.
  249. * @cfg {Boolean} toggleHandler.state The next state of the Button, true means pressed.
  250. */
  251. <span id='Ext-button-Button-cfg-menu'> /**
  252. </span> * @cfg {Ext.menu.Menu/String/Object} menu
  253. * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob.
  254. */
  255. <span id='Ext-button-Button-cfg-menuAlign'> /**
  256. </span> * @cfg {String} menuAlign
  257. * The position to align the menu to (see {@link Ext.Element#alignTo} for more details).
  258. */
  259. menuAlign: 'tl-bl?',
  260. <span id='Ext-button-Button-cfg-textAlign'> /**
  261. </span> * @cfg {String} textAlign
  262. * The text alignment for this button (center, left, right).
  263. */
  264. textAlign: 'center',
  265. <span id='Ext-button-Button-cfg-overflowText'> /**
  266. </span> * @cfg {String} overflowText
  267. * If used in a {@link Ext.toolbar.Toolbar Toolbar}, the text to be used if this item is shown in the overflow menu.
  268. * See also {@link Ext.toolbar.Item}.`{@link Ext.toolbar.Item#overflowText overflowText}`.
  269. */
  270. <span id='Ext-button-Button-cfg-iconCls'> /**
  271. </span> * @cfg {String} iconCls
  272. * A css class which sets a background image to be used as the icon for this button.
  273. */
  274. <span id='Ext-button-Button-cfg-type'> /**
  275. </span> * @cfg {String} type
  276. * The type of `&lt;input&gt;` to create: submit, reset or button.
  277. */
  278. type: 'button',
  279. <span id='Ext-button-Button-cfg-clickEvent'> /**
  280. </span> * @cfg {String} clickEvent
  281. * The DOM event that will fire the handler of the button. This can be any valid event name (dblclick, contextmenu).
  282. */
  283. clickEvent: 'click',
  284. <span id='Ext-button-Button-cfg-preventDefault'> /**
  285. </span> * @cfg {Boolean} preventDefault
  286. * True to prevent the default action when the {@link #clickEvent} is processed.
  287. */
  288. preventDefault: true,
  289. <span id='Ext-button-Button-cfg-handleMouseEvents'> /**
  290. </span> * @cfg {Boolean} handleMouseEvents
  291. * False to disable visual cues on mouseover, mouseout and mousedown.
  292. */
  293. handleMouseEvents: true,
  294. <span id='Ext-button-Button-cfg-tooltipType'> /**
  295. </span> * @cfg {String} tooltipType
  296. * The type of tooltip to use. Either 'qtip' for QuickTips or 'title' for title attribute.
  297. */
  298. tooltipType: 'qtip',
  299. <span id='Ext-button-Button-cfg-baseCls'> /**
  300. </span> * @cfg {String} [baseCls='x-btn']
  301. * The base CSS class to add to all buttons.
  302. */
  303. baseCls: Ext.baseCSSPrefix + 'btn',
  304. <span id='Ext-button-Button-cfg-pressedCls'> /**
  305. </span> * @cfg {String} pressedCls
  306. * The CSS class to add to a button when it is in the pressed state.
  307. */
  308. pressedCls: 'pressed',
  309. <span id='Ext-button-Button-cfg-overCls'> /**
  310. </span> * @cfg {String} overCls
  311. * The CSS class to add to a button when it is in the over (hovered) state.
  312. */
  313. overCls: 'over',
  314. <span id='Ext-button-Button-cfg-focusCls'> /**
  315. </span> * @cfg {String} focusCls
  316. * The CSS class to add to a button when it is in the focussed state.
  317. */
  318. focusCls: 'focus',
  319. <span id='Ext-button-Button-cfg-menuActiveCls'> /**
  320. </span> * @cfg {String} menuActiveCls
  321. * The CSS class to add to a button when it's menu is active.
  322. */
  323. menuActiveCls: 'menu-active',
  324. <span id='Ext-button-Button-cfg-href'> /**
  325. </span> * @cfg {String} href
  326. * The URL to open when the button is clicked. Specifying this config causes the Button to be
  327. * rendered with an anchor (An `&lt;a&gt;` element) as its active element, referencing the specified URL.
  328. *
  329. * This is better than specifying a click handler of
  330. *
  331. * function() { window.location = &quot;http://www.sencha.com&quot; }
  332. *
  333. * because the UI will provide meaningful hints to the user as to what to expect upon clicking
  334. * the button, and will also allow the user to open in a new tab or window, bookmark or drag the URL, or directly save
  335. * the URL stream to disk.
  336. *
  337. * See also the {@link #hrefTarget} config.
  338. */
  339. <span id='Ext-button-Button-cfg-hrefTarget'> /**
  340. </span> * @cfg {String} [hrefTarget=&quot;_blank&quot;]
  341. * The target attribute to use for the underlying anchor. Only used if the {@link #href}
  342. * property is specified.
  343. */
  344. hrefTarget: '_blank',
  345. border: true,
  346. <span id='Ext-button-Button-cfg-baseParams'> /**
  347. </span> * @cfg {Object} baseParams
  348. * An object literal of parameters to pass to the url when the {@link #href} property is specified.
  349. */
  350. <span id='Ext-button-Button-cfg-params'> /**
  351. </span> * @cfg {Object} params
  352. * An object literal of parameters to pass to the url when the {@link #href} property is specified. Any params
  353. * override {@link #baseParams}. New params can be set using the {@link #setParams} method.
  354. */
  355. childEls: [
  356. 'btnEl', 'btnWrap', 'btnInnerEl', 'btnIconEl'
  357. ],
  358. renderTpl: [
  359. '&lt;em id=&quot;{id}-btnWrap&quot;&lt;tpl if=&quot;splitCls&quot;&gt; class=&quot;{splitCls}&quot;&lt;/tpl&gt;&gt;',
  360. '&lt;tpl if=&quot;href&quot;&gt;',
  361. '&lt;a id=&quot;{id}-btnEl&quot; href=&quot;{href}&quot; class=&quot;{btnCls}&quot; target=&quot;{hrefTarget}&quot;',
  362. '&lt;tpl if=&quot;tabIndex&quot;&gt; tabIndex=&quot;{tabIndex}&quot;&lt;/tpl&gt;',
  363. '&lt;tpl if=&quot;disabled&quot;&gt; disabled=&quot;disabled&quot;&lt;/tpl&gt;',
  364. ' role=&quot;link&quot;&gt;',
  365. '&lt;span id=&quot;{id}-btnInnerEl&quot; class=&quot;{baseCls}-inner&quot;&gt;',
  366. '{text}',
  367. '&lt;/span&gt;',
  368. '&lt;span id=&quot;{id}-btnIconEl&quot; class=&quot;{baseCls}-icon {iconCls}&quot;&lt;tpl if=&quot;iconUrl&quot;&gt; style=&quot;background-image:url({iconUrl})&quot;&lt;/tpl&gt;&gt;&lt;/span&gt;',
  369. '&lt;/a&gt;',
  370. '&lt;tpl else&gt;',
  371. '&lt;button id=&quot;{id}-btnEl&quot; type=&quot;{type}&quot; class=&quot;{btnCls}&quot; hidefocus=&quot;true&quot;',
  372. // the autocomplete=&quot;off&quot; is required to prevent Firefox from remembering
  373. // the button's disabled state between page reloads.
  374. '&lt;tpl if=&quot;tabIndex&quot;&gt; tabIndex=&quot;{tabIndex}&quot;&lt;/tpl&gt;',
  375. '&lt;tpl if=&quot;disabled&quot;&gt; disabled=&quot;disabled&quot;&lt;/tpl&gt;',
  376. ' role=&quot;button&quot; autocomplete=&quot;off&quot;&gt;',
  377. '&lt;span id=&quot;{id}-btnInnerEl&quot; class=&quot;{baseCls}-inner&quot; style=&quot;{innerSpanStyle}&quot;&gt;',
  378. '{text}',
  379. '&lt;/span&gt;',
  380. '&lt;span id=&quot;{id}-btnIconEl&quot; class=&quot;{baseCls}-icon {iconCls}&quot;&lt;tpl if=&quot;iconUrl&quot;&gt; style=&quot;background-image:url({iconUrl})&quot;&lt;/tpl&gt;&gt;&lt;/span&gt;',
  381. '&lt;/button&gt;',
  382. '&lt;/tpl&gt;',
  383. '&lt;/em&gt;',
  384. '&lt;tpl if=&quot;closable&quot;&gt;',
  385. '&lt;a id=&quot;{id}-closeEl&quot; href=&quot;#&quot; class=&quot;{baseCls}-close-btn&quot; title=&quot;{closeText}&quot;&gt;&lt;/a&gt;',
  386. '&lt;/tpl&gt;'
  387. ],
  388. <span id='Ext-button-Button-cfg-scale'> /**
  389. </span> * @cfg {String} scale
  390. * The size of the Button. Three values are allowed:
  391. *
  392. * - 'small' - Results in the button element being 16px high.
  393. * - 'medium' - Results in the button element being 24px high.
  394. * - 'large' - Results in the button element being 32px high.
  395. */
  396. scale: 'small',
  397. <span id='Ext-button-Button-property-allowedScales'> /**
  398. </span> * @private
  399. * An array of allowed scales.
  400. */
  401. allowedScales: ['small', 'medium', 'large'],
  402. <span id='Ext-button-Button-cfg-scope'> /**
  403. </span> * @cfg {Object} scope
  404. * The scope (**this** reference) in which the `{@link #handler}` and `{@link #toggleHandler}` is executed.
  405. * Defaults to this Button.
  406. */
  407. <span id='Ext-button-Button-cfg-iconAlign'> /**
  408. </span> * @cfg {String} iconAlign
  409. * The side of the Button box to render the icon. Four values are allowed:
  410. *
  411. * - 'top'
  412. * - 'right'
  413. * - 'bottom'
  414. * - 'left'
  415. */
  416. iconAlign: 'left',
  417. <span id='Ext-button-Button-cfg-arrowAlign'> /**
  418. </span> * @cfg {String} arrowAlign
  419. * The side of the Button box to render the arrow if the button has an associated {@link #cfg-menu}. Two
  420. * values are allowed:
  421. *
  422. * - 'right'
  423. * - 'bottom'
  424. */
  425. arrowAlign: 'right',
  426. <span id='Ext-button-Button-cfg-arrowCls'> /**
  427. </span> * @cfg {String} arrowCls
  428. * The className used for the inner arrow element if the button has a menu.
  429. */
  430. arrowCls: 'arrow',
  431. <span id='Ext-button-Button-property-template'> /**
  432. </span> * @property {Ext.Template} template
  433. * A {@link Ext.Template Template} used to create the Button's DOM structure.
  434. *
  435. * Instances, or subclasses which need a different DOM structure may provide a different template layout in
  436. * conjunction with an implementation of {@link #getTemplateArgs}.
  437. */
  438. <span id='Ext-button-Button-cfg-cls'> /**
  439. </span> * @cfg {String} cls
  440. * A CSS class string to apply to the button's main element.
  441. */
  442. <span id='Ext-button-Button-property-menu'> /**
  443. </span> * @property {Ext.menu.Menu} menu
  444. * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #cfg-menu} config
  445. * option.
  446. */
  447. maskOnDisable: false,
  448. <span id='Ext-button-Button-property-persistentPadding'> /**
  449. </span> * @private
  450. * @property persistentPadding
  451. * The padding spuriously added to a &amp;lt;button&gt; element which must be accounted for in the margins of the innerEl.
  452. * This is calculated at first render time by creating a hidden button and measuring its insides.
  453. */
  454. persistentPadding: undefined,
  455. shrinkWrap: 3,
  456. frame: true,
  457. // inherit docs
  458. initComponent: function() {
  459. var me = this;
  460. me.callParent(arguments);
  461. me.addEvents(
  462. <span id='Ext-button-Button-event-click'> /**
  463. </span> * @event click
  464. * Fires when this button is clicked, before the configured {@link #handler} is invoked. Execution of the
  465. * {@link #handler} may be vetoed by returning &lt;code&gt;false&lt;/code&gt; to this event.
  466. * @param {Ext.button.Button} this
  467. * @param {Event} e The click event
  468. */
  469. 'click',
  470. <span id='Ext-button-Button-event-toggle'> /**
  471. </span> * @event toggle
  472. * Fires when the 'pressed' state of this button changes (only if enableToggle = true)
  473. * @param {Ext.button.Button} this
  474. * @param {Boolean} pressed
  475. */
  476. 'toggle',
  477. <span id='Ext-button-Button-event-mouseover'> /**
  478. </span> * @event mouseover
  479. * Fires when the mouse hovers over the button
  480. * @param {Ext.button.Button} this
  481. * @param {Event} e The event object
  482. */
  483. 'mouseover',
  484. <span id='Ext-button-Button-event-mouseout'> /**
  485. </span> * @event mouseout
  486. * Fires when the mouse exits the button
  487. * @param {Ext.button.Button} this
  488. * @param {Event} e The event object
  489. */
  490. 'mouseout',
  491. <span id='Ext-button-Button-event-menushow'> /**
  492. </span> * @event menushow
  493. * If this button has a menu, this event fires when it is shown
  494. * @param {Ext.button.Button} this
  495. * @param {Ext.menu.Menu} menu
  496. */
  497. 'menushow',
  498. <span id='Ext-button-Button-event-menuhide'> /**
  499. </span> * @event menuhide
  500. * If this button has a menu, this event fires when it is hidden
  501. * @param {Ext.button.Button} this
  502. * @param {Ext.menu.Menu} menu
  503. */
  504. 'menuhide',
  505. <span id='Ext-button-Button-event-menutriggerover'> /**
  506. </span> * @event menutriggerover
  507. * If this button has a menu, this event fires when the mouse enters the menu triggering element
  508. * @param {Ext.button.Button} this
  509. * @param {Ext.menu.Menu} menu
  510. * @param {Event} e
  511. */
  512. 'menutriggerover',
  513. <span id='Ext-button-Button-event-menutriggerout'> /**
  514. </span> * @event menutriggerout
  515. * If this button has a menu, this event fires when the mouse leaves the menu triggering element
  516. * @param {Ext.button.Button} this
  517. * @param {Ext.menu.Menu} menu
  518. * @param {Event} e
  519. */
  520. 'menutriggerout'
  521. );
  522. if (me.menu) {
  523. // Flag that we'll have a splitCls
  524. me.split = true;
  525. // retrieve menu by id or instantiate instance if needed
  526. me.menu = Ext.menu.Manager.get(me.menu);
  527. me.menu.ownerButton = me;
  528. }
  529. // Accept url as a synonym for href
  530. if (me.url) {
  531. me.href = me.url;
  532. }
  533. // preventDefault defaults to false for links
  534. if (me.href &amp;&amp; !me.hasOwnProperty('preventDefault')) {
  535. me.preventDefault = false;
  536. }
  537. if (Ext.isString(me.toggleGroup) &amp;&amp; me.toggleGroup !== '') {
  538. me.enableToggle = true;
  539. }
  540. if (me.html &amp;&amp; !me.text) {
  541. me.text = me.html;
  542. delete me.html;
  543. }
  544. },
  545. // inherit docs
  546. getActionEl: function() {
  547. return this.btnEl;
  548. },
  549. // inherit docs
  550. getFocusEl: function() {
  551. return this.useElForFocus ? this.el : this.btnEl;
  552. },
  553. // Buttons add the focus class to the *outermost element*, not the focusEl!
  554. onFocus: function(e) {
  555. var me = this;
  556. // Set this flag, so that when AbstractComponent's onFocus gets the focusEl to add the focusCls
  557. // to, it will get the encapsulating element - that's what the CSS rules for Button need right now
  558. me.useElForFocus = true;
  559. me.callParent(arguments);
  560. me.useElForFocus = false;
  561. },
  562. // See comments in onFocus
  563. onBlur : function(e) {
  564. this.useElForFocus = true;
  565. this.callParent(arguments);
  566. this.useElForFocus = false;
  567. },
  568. // See comments in onFocus
  569. onDisable: function(){
  570. this.useElForFocus = true;
  571. this.callParent(arguments);
  572. this.useElForFocus = false;
  573. },
  574. // private
  575. setComponentCls: function() {
  576. var me = this,
  577. cls = me.getComponentCls();
  578. if (!Ext.isEmpty(me.oldCls)) {
  579. me.removeClsWithUI(me.oldCls);
  580. me.removeClsWithUI(me.pressedCls);
  581. }
  582. me.oldCls = cls;
  583. me.addClsWithUI(cls);
  584. },
  585. getComponentCls: function() {
  586. var me = this,
  587. cls = [];
  588. // Check whether the button has an icon or not, and if it has an icon, what is the alignment
  589. if (me.iconCls || me.icon) {
  590. if (me.text) {
  591. cls.push('icon-text-' + me.iconAlign);
  592. } else {
  593. cls.push('icon');
  594. }
  595. } else if (me.text) {
  596. cls.push('noicon');
  597. }
  598. if (me.pressed) {
  599. cls.push(me.pressedCls);
  600. }
  601. return cls;
  602. },
  603. beforeRender: function () {
  604. var me = this;
  605. me.callParent();
  606. // Add all needed classes to the protoElement.
  607. me.oldCls = me.getComponentCls();
  608. me.addClsWithUI(me.oldCls);
  609. // Apply the renderData to the template args
  610. Ext.applyIf(me.renderData, me.getTemplateArgs());
  611. if (me.scale) {
  612. me.setScale(me.scale);
  613. }
  614. },
  615. // private
  616. onRender: function() {
  617. var me = this,
  618. addOnclick,
  619. btn,
  620. btnListeners;
  621. me.doc = Ext.getDoc();
  622. me.callParent(arguments);
  623. // If it is a split button + has a toolip for the arrow
  624. if (me.split &amp;&amp; me.arrowTooltip) {
  625. me.arrowEl.dom.setAttribute(me.getTipAttr(), me.arrowTooltip);
  626. }
  627. // Set btn as a local variable for easy access
  628. btn = me.el;
  629. if (me.tooltip) {
  630. me.setTooltip(me.tooltip, true);
  631. }
  632. // Add the mouse events to the button
  633. if (me.handleMouseEvents) {
  634. btnListeners = {
  635. scope: me,
  636. mouseover: me.onMouseOver,
  637. mouseout: me.onMouseOut,
  638. mousedown: me.onMouseDown
  639. };
  640. if (me.split) {
  641. btnListeners.mousemove = me.onMouseMove;
  642. }
  643. } else {
  644. btnListeners = {
  645. scope: me
  646. };
  647. }
  648. // Check if the button has a menu
  649. if (me.menu) {
  650. me.mon(me.menu, {
  651. scope: me,
  652. show: me.onMenuShow,
  653. hide: me.onMenuHide
  654. });
  655. me.keyMap = new Ext.util.KeyMap({
  656. target: me.el,
  657. key: Ext.EventObject.DOWN,
  658. handler: me.onDownKey,
  659. scope: me
  660. });
  661. }
  662. // Check if it is a repeat button
  663. if (me.repeat) {
  664. me.mon(new Ext.util.ClickRepeater(btn, Ext.isObject(me.repeat) ? me.repeat: {}), 'click', me.onRepeatClick, me);
  665. } else {
  666. // If the activation event already has a handler, make a note to add the handler later
  667. if (btnListeners[me.clickEvent]) {
  668. addOnclick = true;
  669. } else {
  670. btnListeners[me.clickEvent] = me.onClick;
  671. }
  672. }
  673. // Add whatever button listeners we need
  674. me.mon(btn, btnListeners);
  675. // If the listeners object had an entry for our clickEvent, add a listener now
  676. if (addOnclick) {
  677. me.mon(btn, me.clickEvent, me.onClick, me);
  678. }
  679. // Register the button in the toggle manager
  680. Ext.ButtonToggleManager.register(me);
  681. },
  682. <span id='Ext-button-Button-method-getTemplateArgs'> /**
  683. </span> * This method returns an object which provides substitution parameters for the {@link #renderTpl XTemplate} used to
  684. * create this Button's DOM structure.
  685. *
  686. * Instances or subclasses which use a different Template to create a different DOM structure may need to provide
  687. * their own implementation of this method.
  688. *
  689. * @return {Object} Substitution data for a Template. The default implementation which provides data for the default
  690. * {@link #template} returns an Object containing the following properties:
  691. * @return {String} return.type The `&lt;button&gt;`'s {@link #type}
  692. * @return {String} return.splitCls A CSS class to determine the presence and position of an arrow icon.
  693. * (`'x-btn-arrow'` or `'x-btn-arrow-bottom'` or `''`)
  694. * @return {String} return.cls A CSS class name applied to the Button's main `&lt;tbody&gt;` element which determines the
  695. * button's scale and icon alignment.
  696. * @return {String} return.text The {@link #text} to display ion the Button.
  697. * @return {Number} return.tabIndex The tab index within the input flow.
  698. */
  699. getTemplateArgs: function() {
  700. var me = this,
  701. persistentPadding = me.getPersistentPadding(),
  702. innerSpanStyle = '';
  703. // Create negative margin offsets to counteract persistent button padding if needed
  704. if (Math.max.apply(Math, persistentPadding) &gt; 0) {
  705. innerSpanStyle = 'margin:' + Ext.Array.map(persistentPadding, function(pad) {
  706. return -pad + 'px';
  707. }).join(' ');
  708. }
  709. return {
  710. href : me.getHref(),
  711. disabled : me.disabled,
  712. hrefTarget: me.hrefTarget,
  713. type : me.type,
  714. btnCls : me.getBtnCls(),
  715. splitCls : me.getSplitCls(),
  716. iconUrl : me.icon,
  717. iconCls : me.iconCls,
  718. text : me.text || '&amp;#160;',
  719. tabIndex : me.tabIndex,
  720. innerSpanStyle: innerSpanStyle
  721. };
  722. },
  723. <span id='Ext-button-Button-method-getHref'> /**
  724. </span> * @private
  725. * If there is a configured href for this Button, returns the href with parameters appended.
  726. * @returns The href string with parameters appended.
  727. */
  728. getHref: function() {
  729. var me = this,
  730. params = Ext.apply({}, me.baseParams);
  731. // write baseParams first, then write any params
  732. params = Ext.apply(params, me.params);
  733. return me.href ? Ext.urlAppend(me.href, Ext.Object.toQueryString(params)) : false;
  734. },
  735. <span id='Ext-button-Button-method-setParams'> /**
  736. </span> * Sets the href of the link dynamically according to the params passed, and any {@link #baseParams} configured.
  737. *
  738. * **Only valid if the Button was originally configured with a {@link #href}**
  739. *
  740. * @param {Object} params Parameters to use in the href URL.
  741. */
  742. setParams: function(params) {
  743. this.params = params;
  744. this.btnEl.dom.href = this.getHref();
  745. },
  746. getSplitCls: function() {
  747. var me = this;
  748. return me.split ? (me.baseCls + '-' + me.arrowCls) + ' ' + (me.baseCls + '-' + me.arrowCls + '-' + me.arrowAlign) : '';
  749. },
  750. getBtnCls: function() {
  751. return this.textAlign ? this.baseCls + '-' + this.textAlign : '';
  752. },
  753. <span id='Ext-button-Button-method-setIconCls'> /**
  754. </span> * Sets the CSS class that provides a background image to use as the button's icon. This method also changes the
  755. * value of the {@link #iconCls} config internally.
  756. * @param {String} cls The CSS class providing the icon image
  757. * @return {Ext.button.Button} this
  758. */
  759. setIconCls: function(cls) {
  760. var me = this,
  761. btnIconEl = me.btnIconEl,
  762. oldCls = me.iconCls;
  763. me.iconCls = cls;
  764. if (btnIconEl) {
  765. // Remove the previous iconCls from the button
  766. btnIconEl.removeCls(oldCls);
  767. btnIconEl.addCls(cls || '');
  768. me.setComponentCls();
  769. if (me.didIconStateChange(oldCls, cls)) {
  770. me.updateLayout();
  771. }
  772. }
  773. return me;
  774. },
  775. <span id='Ext-button-Button-method-setTooltip'> /**
  776. </span> * Sets the tooltip for this Button.
  777. *
  778. * @param {String/Object} tooltip This may be:
  779. *
  780. * - **String** : A string to be used as innerHTML (html tags are accepted) to show in a tooltip
  781. * - **Object** : A configuration object for {@link Ext.tip.QuickTipManager#register}.
  782. *
  783. * @return {Ext.button.Button} this
  784. */
  785. setTooltip: function(tooltip, initial) {
  786. var me = this;
  787. if (me.rendered) {
  788. if (!initial) {
  789. me.clearTip();
  790. }
  791. if (Ext.isObject(tooltip)) {
  792. Ext.tip.QuickTipManager.register(Ext.apply({
  793. target: me.btnEl.id
  794. },
  795. tooltip));
  796. me.tooltip = tooltip;
  797. } else {
  798. me.btnEl.dom.setAttribute(me.getTipAttr(), tooltip);
  799. }
  800. } else {
  801. me.tooltip = tooltip;
  802. }
  803. return me;
  804. },
  805. <span id='Ext-button-Button-method-setTextAlign'> /**
  806. </span> * Sets the text alignment for this button.
  807. * @param {String} align The new alignment of the button text. See {@link #textAlign}.
  808. */
  809. setTextAlign: function(align) {
  810. var me = this,
  811. btnEl = me.btnEl;
  812. if (btnEl) {
  813. btnEl.removeCls(me.baseCls + '-' + me.textAlign);
  814. btnEl.addCls(me.baseCls + '-' + align);
  815. }
  816. me.textAlign = align;
  817. return me;
  818. },
  819. getTipAttr: function(){
  820. return this.tooltipType == 'qtip' ? 'data-qtip' : 'title';
  821. },
  822. // private
  823. getRefItems: function(deep){
  824. var menu = this.menu,
  825. items;
  826. if (menu) {
  827. items = menu.getRefItems(deep);
  828. items.unshift(menu);
  829. }
  830. return items || [];
  831. },
  832. // private
  833. clearTip: function() {
  834. if (Ext.isObject(this.tooltip)) {
  835. Ext.tip.QuickTipManager.unregister(this.btnEl);
  836. }
  837. },
  838. // private
  839. beforeDestroy: function() {
  840. var me = this;
  841. if (me.rendered) {
  842. me.clearTip();
  843. }
  844. if (me.menu &amp;&amp; me.destroyMenu !== false) {
  845. Ext.destroy(me.menu);
  846. }
  847. Ext.destroy(me.btnInnerEl, me.repeater);
  848. me.callParent();
  849. },
  850. // private
  851. onDestroy: function() {
  852. var me = this;
  853. if (me.rendered) {
  854. me.doc.un('mouseover', me.monitorMouseOver, me);
  855. me.doc.un('mouseup', me.onMouseUp, me);
  856. delete me.doc;
  857. Ext.ButtonToggleManager.unregister(me);
  858. Ext.destroy(me.keyMap);
  859. delete me.keyMap;
  860. }
  861. me.callParent();
  862. },
  863. <span id='Ext-button-Button-method-setHandler'> /**
  864. </span> * Assigns this Button's click handler
  865. * @param {Function} handler The function to call when the button is clicked
  866. * @param {Object} [scope] The scope (`this` reference) in which the handler function is executed.
  867. * Defaults to this Button.
  868. * @return {Ext.button.Button} this
  869. */
  870. setHandler: function(handler, scope) {
  871. this.handler = handler;
  872. this.scope = scope;
  873. return this;
  874. },
  875. <span id='Ext-button-Button-method-setText'> /**
  876. </span> * Sets this Button's text
  877. * @param {String} text The button text
  878. * @return {Ext.button.Button} this
  879. */
  880. setText: function(text) {
  881. var me = this;
  882. me.text = text;
  883. if (me.rendered) {
  884. me.btnInnerEl.update(text || '&amp;#160;');
  885. me.setComponentCls();
  886. if (Ext.isStrict &amp;&amp; Ext.isIE8) {
  887. // weird repaint issue causes it to not resize
  888. me.el.repaint();
  889. }
  890. me.updateLayout();
  891. }
  892. return me;
  893. },
  894. <span id='Ext-button-Button-method-setIcon'> /**
  895. </span> * Sets the background image (inline style) of the button. This method also changes the value of the {@link #icon}
  896. * config internally.
  897. * @param {String} icon The path to an image to display in the button
  898. * @return {Ext.button.Button} this
  899. */
  900. setIcon: function(icon) {
  901. var me = this,
  902. btnIconEl = me.btnIconEl,
  903. oldIcon = me.icon;
  904. me.icon = icon;
  905. if (btnIconEl) {
  906. btnIconEl.setStyle('background-image', icon ? 'url(' + icon + ')': '');
  907. me.setComponentCls();
  908. if (me.didIconStateChange(oldIcon, icon)) {
  909. me.updateLayout();
  910. }
  911. }
  912. return me;
  913. },
  914. <span id='Ext-button-Button-method-didIconStateChange'> /**
  915. </span> * Checks if the icon/iconCls changed from being empty to having a value, or having a value to being empty.
  916. * @private
  917. * @param {String} old The old icon/iconCls
  918. * @param {String} current The current icon/iconCls
  919. * @return {Boolean} True if the icon state changed
  920. */
  921. didIconStateChange: function(old, current) {
  922. var currentEmpty = Ext.isEmpty(current);
  923. return Ext.isEmpty(old) ? !currentEmpty : currentEmpty;
  924. },
  925. <span id='Ext-button-Button-method-getText'> /**
  926. </span> * Gets the text for this Button
  927. * @return {String} The button text
  928. */
  929. getText: function() {
  930. return this.text;
  931. },
  932. <span id='Ext-button-Button-method-toggle'> /**
  933. </span> * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
  934. * @param {Boolean} [state] Force a particular state
  935. * @param {Boolean} [suppressEvent=false] True to stop events being fired when calling this method.
  936. * @return {Ext.button.Button} this
  937. */
  938. toggle: function(state, suppressEvent) {
  939. var me = this;
  940. state = state === undefined ? !me.pressed: !!state;
  941. if (state !== me.pressed) {
  942. if (me.rendered) {
  943. me[state ? 'addClsWithUI': 'removeClsWithUI'](me.pressedCls);
  944. }
  945. me.pressed = state;
  946. if (!suppressEvent) {
  947. me.fireEvent('toggle', me, state);
  948. Ext.callback(me.toggleHandler, me.scope || me, [me, state]);
  949. }
  950. }
  951. return me;
  952. },
  953. maybeShowMenu: function(){
  954. var me = this;
  955. if (me.menu &amp;&amp; !me.hasVisibleMenu() &amp;&amp; !me.ignoreNextClick) {
  956. me.showMenu();
  957. }
  958. },
  959. <span id='Ext-button-Button-method-showMenu'> /**
  960. </span> * Shows this button's menu (if it has one)
  961. */
  962. showMenu: function() {
  963. var me = this;
  964. if (me.rendered &amp;&amp; me.menu) {
  965. if (me.tooltip &amp;&amp; me.getTipAttr() != 'title') {
  966. Ext.tip.QuickTipManager.getQuickTip().cancelShow(me.btnEl);
  967. }
  968. if (me.menu.isVisible()) {
  969. me.menu.hide();
  970. }
  971. me.menu.showBy(me.el, me.menuAlign, ((!Ext.isStrict &amp;&amp; Ext.isIE) || Ext.isIE6) ? [-2, -2] : undefined);
  972. }
  973. return me;
  974. },
  975. <span id='Ext-button-Button-method-hideMenu'> /**
  976. </span> * Hides this button's menu (if it has one)
  977. */
  978. hideMenu: function() {
  979. if (this.hasVisibleMenu()) {
  980. this.menu.hide();
  981. }
  982. return this;
  983. },
  984. <span id='Ext-button-Button-method-hasVisibleMenu'> /**
  985. </span> * Returns true if the button has a menu and it is visible
  986. * @return {Boolean}
  987. */
  988. hasVisibleMenu: function() {
  989. var menu = this.menu;
  990. return menu &amp;&amp; menu.rendered &amp;&amp; menu.isVisible();
  991. },
  992. // private
  993. onRepeatClick: function(repeat, e) {
  994. this.onClick(e);
  995. },
  996. // private
  997. onClick: function(e) {
  998. var me = this;
  999. if (me.preventDefault || (me.disabled &amp;&amp; me.getHref()) &amp;&amp; e) {
  1000. e.preventDefault();
  1001. }
  1002. if (e.button !== 0) {
  1003. return;
  1004. }
  1005. if (!me.disabled) {
  1006. me.doToggle();
  1007. me.maybeShowMenu();
  1008. me.fireHandler(e);
  1009. }
  1010. },
  1011. fireHandler: function(e){
  1012. var me = this,
  1013. handler = me.handler;
  1014. if (me.fireEvent('click', me, e) !== false) {
  1015. if (handler) {
  1016. handler.call(me.scope || me, me, e);
  1017. }
  1018. me.blur();
  1019. }
  1020. },
  1021. doToggle: function(){
  1022. var me = this;
  1023. if (me.enableToggle &amp;&amp; (me.allowDepress !== false || !me.pressed)) {
  1024. me.toggle();
  1025. }
  1026. },
  1027. <span id='Ext-button-Button-method-onMouseOver'> /**
  1028. </span> * @private mouseover handler called when a mouseover event occurs anywhere within the encapsulating element.
  1029. * The targets are interrogated to see what is being entered from where.
  1030. * @param e
  1031. */
  1032. onMouseOver: function(e) {
  1033. var me = this;
  1034. if (!me.disabled &amp;&amp; !e.within(me.el, true, true)) {
  1035. me.onMouseEnter(e);
  1036. }
  1037. },
  1038. <span id='Ext-button-Button-method-onMouseOut'> /**
  1039. </span> * @private
  1040. * mouseout handler called when a mouseout event occurs anywhere within the encapsulating element -
  1041. * or the mouse leaves the encapsulating element.
  1042. * The targets are interrogated to see what is being exited to where.
  1043. * @param e
  1044. */
  1045. onMouseOut: function(e) {
  1046. var me = this;
  1047. if (!e.within(me.el, true, true)) {
  1048. if (me.overMenuTrigger) {
  1049. me.onMenuTriggerOut(e);
  1050. }
  1051. me.onMouseLeave(e);
  1052. }
  1053. },
  1054. <span id='Ext-button-Button-method-onMouseMove'> /**
  1055. </span> * @private
  1056. * mousemove handler called when the mouse moves anywhere within the encapsulating element.
  1057. * The position is checked to determine if the mouse is entering or leaving the trigger area. Using
  1058. * mousemove to check this is more resource intensive than we'd like, but it is necessary because
  1059. * the trigger area does not line up exactly with sub-elements so we don't always get mouseover/out
  1060. * events when needed. In the future we should consider making the trigger a separate element that
  1061. * is absolutely positioned and sized over the trigger area.
  1062. */
  1063. onMouseMove: function(e) {
  1064. var me = this,
  1065. el = me.el,
  1066. over = me.overMenuTrigger,
  1067. overlap, btnSize;
  1068. if (me.split) {
  1069. if (me.arrowAlign === 'right') {
  1070. overlap = e.getX() - el.getX();
  1071. btnSize = el.getWidth();
  1072. } else {
  1073. overlap = e.getY() - el.getY();
  1074. btnSize = el.getHeight();
  1075. }
  1076. if (overlap &gt; (btnSize - me.getTriggerSize())) {
  1077. if (!over) {
  1078. me.onMenuTriggerOver(e);
  1079. }
  1080. } else {
  1081. if (over) {
  1082. me.onMenuTriggerOut(e);
  1083. }
  1084. }
  1085. }
  1086. },
  1087. <span id='Ext-button-Button-method-getTriggerSize'> /**
  1088. </span> * @private
  1089. * Measures the size of the trigger area for menu and split buttons. Will be a width for
  1090. * a right-aligned trigger and a height for a bottom-aligned trigger. Cached after first measurement.
  1091. */
  1092. getTriggerSize: function() {
  1093. var me = this,
  1094. size = me.triggerSize,
  1095. side, sideFirstLetter, undef;
  1096. if (size === undef) {
  1097. side = me.arrowAlign;
  1098. sideFirstLetter = side.charAt(0);
  1099. size = me.triggerSize = me.el.getFrameWidth(sideFirstLetter) + me.btnWrap.getFrameWidth(sideFirstLetter) + me.frameSize[side];
  1100. }
  1101. return size;
  1102. },
  1103. <span id='Ext-button-Button-method-onMouseEnter'> /**
  1104. </span> * @private
  1105. * virtual mouseenter handler called when it is detected that the mouseout event
  1106. * signified the mouse entering the encapsulating element.
  1107. * @param e
  1108. */
  1109. onMouseEnter: function(e) {
  1110. var me = this;
  1111. me.addClsWithUI(me.overCls);
  1112. me.fireEvent('mouseover', me, e);
  1113. },
  1114. <span id='Ext-button-Button-method-onMouseLeave'> /**
  1115. </span> * @private
  1116. * virtual mouseleave handler called when it is detected that the mouseover event
  1117. * signified the mouse entering the encapsulating element.
  1118. * @param e
  1119. */
  1120. onMouseLeave: function(e) {
  1121. var me = this;
  1122. me.removeClsWithUI(me.overCls);
  1123. me.fireEvent('mouseout', me, e);
  1124. },
  1125. <span id='Ext-button-Button-method-onMenuTriggerOver'> /**
  1126. </span> * @private
  1127. * virtual mouseenter handler called when it is detected that the mouseover event
  1128. * signified the mouse entering the arrow area of the button - the `&lt;em&gt;`.
  1129. * @param e
  1130. */
  1131. onMenuTriggerOver: function(e) {
  1132. var me = this;
  1133. me.overMenuTrigger = true;
  1134. me.fireEvent('menutriggerover', me, me.menu, e);
  1135. },
  1136. <span id='Ext-button-Button-method-onMenuTriggerOut'> /**
  1137. </span> * @private
  1138. * virtual mouseleave handler called when it is detected that the mouseout event
  1139. * signified the mouse leaving the arrow area of the button - the `&lt;em&gt;`.
  1140. * @param e
  1141. */
  1142. onMenuTriggerOut: function(e) {
  1143. var me = this;
  1144. delete me.overMenuTrigger;
  1145. me.fireEvent('menutriggerout', me, me.menu, e);
  1146. },
  1147. // inherit docs
  1148. enable : function(silent) {
  1149. var me = this;
  1150. me.callParent(arguments);
  1151. if (me.btnEl) {
  1152. me.btnEl.dom.disabled = false;
  1153. }
  1154. me.removeClsWithUI('disabled');
  1155. return me;
  1156. },
  1157. // inherit docs
  1158. disable : function(silent) {
  1159. var me = this;
  1160. me.callParent(arguments);
  1161. if (me.btnEl) {
  1162. me.btnEl.dom.disabled = true;
  1163. }
  1164. me.addClsWithUI('disabled');
  1165. me.removeClsWithUI(me.overCls);
  1166. // IE renders disabled text by layering gray text on top of white text, offset by 1 pixel. Normally this is fine
  1167. // but in some circumstances (such as using formBind) it gets confused and renders them side by side instead.
  1168. if (me.btnInnerEl &amp;&amp; (Ext.isIE6 || Ext.isIE7)) {
  1169. me.btnInnerEl.repaint();
  1170. }
  1171. return me;
  1172. },
  1173. <span id='Ext-button-Button-method-setScale'> /**
  1174. </span> * Method to change the scale of the button. See {@link #scale} for allowed configurations.
  1175. * @param {String} scale The scale to change to.
  1176. */
  1177. setScale: function(scale) {
  1178. var me = this,
  1179. ui = me.ui.replace('-' + me.scale, '');
  1180. //check if it is an allowed scale
  1181. if (!Ext.Array.contains(me.allowedScales, scale)) {
  1182. throw('#setScale: scale must be an allowed scale (' + me.allowedScales.join(', ') + ')');
  1183. }
  1184. me.scale = scale;
  1185. me.setUI(ui);
  1186. },
  1187. // inherit docs
  1188. setUI: function(ui) {
  1189. var me = this;
  1190. //we need to append the scale to the UI, if not already done
  1191. if (me.scale &amp;&amp; !ui.match(me.scale)) {
  1192. ui = ui + '-' + me.scale;
  1193. }
  1194. me.callParent([ui]);
  1195. // Set all the state classNames, as they need to include the UI
  1196. // me.disabledCls += ' ' + me.baseCls + '-' + me.ui + '-disabled';
  1197. },
  1198. // private
  1199. onMouseDown: function(e) {
  1200. var me = this;
  1201. if (!me.disabled &amp;&amp; e.button === 0) {
  1202. me.addClsWithUI(me.pressedCls);
  1203. me.doc.on('mouseup', me.onMouseUp, me);
  1204. }
  1205. },
  1206. // private
  1207. onMouseUp: function(e) {
  1208. var me = this;
  1209. if (e.button === 0) {
  1210. if (!me.pressed) {
  1211. me.removeClsWithUI(me.pressedCls);
  1212. }
  1213. me.doc.un('mouseup', me.onMouseUp, me);
  1214. }
  1215. },
  1216. // private
  1217. onMenuShow: function(e) {
  1218. var me = this;
  1219. me.ignoreNextClick = 0;
  1220. me.addClsWithUI(me.menuActiveCls);
  1221. me.fireEvent('menushow', me, me.menu);
  1222. },
  1223. // private
  1224. onMenuHide: function(e) {
  1225. var me = this;
  1226. me.removeClsWithUI(me.menuActiveCls);
  1227. me.ignoreNextClick = Ext.defer(me.restoreClick, 250, me);
  1228. me.fireEvent('menuhide', me, me.menu);
  1229. },
  1230. // private
  1231. restoreClick: function() {
  1232. this.ignoreNextClick = 0;
  1233. },
  1234. // private
  1235. onDownKey: function() {
  1236. var me = this;
  1237. if (!me.disabled) {
  1238. if (me.menu) {
  1239. me.showMenu();
  1240. }
  1241. }
  1242. },
  1243. <span id='Ext-button-Button-method-getPersistentPadding'> /**
  1244. </span> * @private
  1245. * Some browsers (notably Safari and older Chromes on Windows) add extra &quot;padding&quot; inside the button
  1246. * element that cannot be removed. This method returns the size of that padding with a one-time detection.
  1247. * @return {Number[]} [top, right, bottom, left]
  1248. */
  1249. getPersistentPadding: function() {
  1250. var me = this,
  1251. reset = Ext.scopeResetCSS,
  1252. padding = me.persistentPadding,
  1253. btn, leftTop, btnEl, btnInnerEl, wrap;
  1254. // Create auto-size button offscreen and measure its insides
  1255. // Short-circuit IE as it sometimes gives false positive for padding
  1256. if (!padding) {
  1257. padding = me.self.prototype.persistentPadding = [0, 0, 0, 0];
  1258. if (!Ext.isIE) {
  1259. btn = new Ext.button.Button({
  1260. text: 'test',
  1261. style: 'position:absolute;top:-999px;'
  1262. });
  1263. btn.el = Ext.DomHelper.append(Ext.resetElement, btn.getRenderTree(), true);
  1264. btn.applyChildEls(btn.el);
  1265. btnEl = btn.btnEl;
  1266. btnInnerEl = btn.btnInnerEl;
  1267. btnEl.setSize(null, null); //clear any hard dimensions on the button el to see what it does naturally
  1268. leftTop = btnInnerEl.getOffsetsTo(btnEl);
  1269. padding[0] = leftTop[1];
  1270. padding[1] = btnEl.getWidth() - btnInnerEl.getWidth() - leftTop[0];
  1271. padding[2] = btnEl.getHeight() - btnInnerEl.getHeight() - leftTop[1];
  1272. padding[3] = leftTop[0];
  1273. btn.destroy();
  1274. btn.el.remove();
  1275. }
  1276. }
  1277. return padding;
  1278. }
  1279. }, function() {
  1280. var groups = {},
  1281. toggleGroup = function(btn, state) {
  1282. if (state) {
  1283. var g = groups[btn.toggleGroup],
  1284. length = g.length,
  1285. i;
  1286. for (i = 0; i &lt; length; i++) {
  1287. if (g[i] !== btn) {
  1288. g[i].toggle(false);
  1289. }
  1290. }
  1291. }
  1292. };
  1293. // Private utility class used by Button
  1294. Ext.ButtonToggleManager = {
  1295. register: function(btn) {
  1296. if (!btn.toggleGroup) {
  1297. return;
  1298. }
  1299. var group = groups[btn.toggleGroup];
  1300. if (!group) {
  1301. group = groups[btn.toggleGroup] = [];
  1302. }
  1303. group.push(btn);
  1304. btn.on('toggle', toggleGroup);
  1305. },
  1306. unregister: function(btn) {
  1307. if (!btn.toggleGroup) {
  1308. return;
  1309. }
  1310. var group = groups[btn.toggleGroup];
  1311. if (group) {
  1312. Ext.Array.remove(group, btn);
  1313. btn.un('toggle', toggleGroup);
  1314. }
  1315. },
  1316. // Gets the pressed button in the passed group or null
  1317. // @param {String} group
  1318. // @return {Ext.button.Button}
  1319. getPressed: function(group) {
  1320. var g = groups[group],
  1321. i = 0,
  1322. len;
  1323. if (g) {
  1324. for (len = g.length; i &lt; len; i++) {
  1325. if (g[i].pressed === true) {
  1326. return g[i];
  1327. }
  1328. }
  1329. }
  1330. return null;
  1331. }
  1332. };
  1333. });
  1334. </pre>
  1335. </body>
  1336. </html>