Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

850 lines
27 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.Button"></div>/**
  16. * @class Ext.Button
  17. * @extends Ext.BoxComponent
  18. * Simple Button class
  19. * @cfg {String} text The button text to be used as innerHTML (html tags are accepted)
  20. * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
  21. * CSS property of the button by default, so if you want a mixed icon/text button, set cls:'x-btn-text-icon')
  22. * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event).
  23. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  24. * <li><code>b</code> : Button<div class="sub-desc">This Button.</div></li>
  25. * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>
  26. * </ul></div>
  27. * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width).
  28. * See also {@link Ext.Panel}.<tt>{@link Ext.Panel#minButtonWidth minButtonWidth}</tt>.
  29. * @cfg {String/Object} tooltip The tooltip for the button - can be a string to be used as innerHTML (html tags are accepted) or QuickTips config object
  30. * @cfg {Boolean} hidden True to start hidden (defaults to false)
  31. * @cfg {Boolean} disabled True to start disabled (defaults to false)
  32. * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
  33. * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed)
  34. * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
  35. * a {@link Ext.util.ClickRepeater ClickRepeater} config object (defaults to false).
  36. * @constructor
  37. * Create a new button
  38. * @param {Object} config The config object
  39. * @xtype button
  40. */
  41. Ext.Button = Ext.extend(Ext.BoxComponent, {
  42. /**
  43. * Read-only. True if this button is hidden
  44. * @type Boolean
  45. */
  46. hidden : false,
  47. /**
  48. * Read-only. True if this button is disabled
  49. * @type Boolean
  50. */
  51. disabled : false,
  52. /**
  53. * Read-only. True if this button is pressed (only if enableToggle = true)
  54. * @type Boolean
  55. */
  56. pressed : false,
  57. /**
  58. * @cfg {Number} tabIndex Set a DOM tabIndex for this button (defaults to undefined)
  59. */
  60. /**
  61. * @cfg {Boolean} allowDepress
  62. * False to not allow a pressed Button to be depressed (defaults to undefined). Only valid when {@link #enableToggle} is true.
  63. */
  64. /**
  65. * @cfg {Boolean} enableToggle
  66. * True to enable pressed/not pressed toggling (defaults to false)
  67. */
  68. enableToggle : false,
  69. /**
  70. * @cfg {Function} toggleHandler
  71. * Function called when a Button with {@link #enableToggle} set to true is clicked. Two arguments are passed:<ul class="mdetail-params">
  72. * <li><b>button</b> : Ext.Button<div class="sub-desc">this Button object</div></li>
  73. * <li><b>state</b> : Boolean<div class="sub-desc">The next state of the Button, true means pressed.</div></li>
  74. * </ul>
  75. */
  76. /**
  77. * @cfg {Mixed} menu
  78. * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
  79. */
  80. /**
  81. * @cfg {String} menuAlign
  82. * The position to align the menu to (see {@link Ext.Element#alignTo} for more details, defaults to 'tl-bl?').
  83. */
  84. menuAlign : 'tl-bl?',
  85. /**
  86. * @cfg {String} overflowText If used in a {@link Ext.Toolbar Toolbar}, the
  87. * text to be used if this item is shown in the overflow menu. See also
  88. * {@link Ext.Toolbar.Item}.<code>{@link Ext.Toolbar.Item#overflowText overflowText}</code>.
  89. */
  90. /**
  91. * @cfg {String} iconCls
  92. * A css class which sets a background image to be used as the icon for this button
  93. */
  94. /**
  95. * @cfg {String} type
  96. * submit, reset or button - defaults to 'button'
  97. */
  98. type : 'button',
  99. // private
  100. menuClassTarget : 'tr:nth(2)',
  101. /**
  102. * @cfg {String} clickEvent
  103. * The DOM event that will fire the handler of the button. This can be any valid event name (dblclick, contextmenu).
  104. * Defaults to <tt>'click'</tt>.
  105. */
  106. clickEvent : 'click',
  107. /**
  108. * @cfg {Boolean} handleMouseEvents
  109. * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
  110. */
  111. handleMouseEvents : true,
  112. /**
  113. * @cfg {String} tooltipType
  114. * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
  115. */
  116. tooltipType : 'qtip',
  117. /**
  118. * @cfg {String} buttonSelector
  119. * <p>(Optional) A {@link Ext.DomQuery DomQuery} selector which is used to extract the active, clickable element from the
  120. * DOM structure created.</p>
  121. * <p>When a custom {@link #template} is used, you must ensure that this selector results in the selection of
  122. * a focussable element.</p>
  123. * <p>Defaults to <b><tt>'button:first-child'</tt></b>.</p>
  124. */
  125. buttonSelector : 'button:first-child',
  126. /**
  127. * @cfg {String} scale
  128. * <p>(Optional) The size of the Button. Three values are allowed:</p>
  129. * <ul class="mdetail-params">
  130. * <li>'small'<div class="sub-desc">Results in the button element being 16px high.</div></li>
  131. * <li>'medium'<div class="sub-desc">Results in the button element being 24px high.</div></li>
  132. * <li>'large'<div class="sub-desc">Results in the button element being 32px high.</div></li>
  133. * </ul>
  134. * <p>Defaults to <b><tt>'small'</tt></b>.</p>
  135. */
  136. scale : 'small',
  137. /**
  138. * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
  139. * <code>{@link #handler}</code> and <code>{@link #toggleHandler}</code> is
  140. * executed. Defaults to this Button.
  141. */
  142. /**
  143. * @cfg {String} iconAlign
  144. * <p>(Optional) The side of the Button box to render the icon. Four values are allowed:</p>
  145. * <ul class="mdetail-params">
  146. * <li>'top'<div class="sub-desc"></div></li>
  147. * <li>'right'<div class="sub-desc"></div></li>
  148. * <li>'bottom'<div class="sub-desc"></div></li>
  149. * <li>'left'<div class="sub-desc"></div></li>
  150. * </ul>
  151. * <p>Defaults to <b><tt>'left'</tt></b>.</p>
  152. */
  153. iconAlign : 'left',
  154. /**
  155. * @cfg {String} arrowAlign
  156. * <p>(Optional) The side of the Button box to render the arrow if the button has an associated {@link #menu}.
  157. * Two values are allowed:</p>
  158. * <ul class="mdetail-params">
  159. * <li>'right'<div class="sub-desc"></div></li>
  160. * <li>'bottom'<div class="sub-desc"></div></li>
  161. * </ul>
  162. * <p>Defaults to <b><tt>'right'</tt></b>.</p>
  163. */
  164. arrowAlign : 'right',
  165. /**
  166. * @cfg {Ext.Template} template (Optional)
  167. * <p>A {@link Ext.Template Template} used to create the Button's DOM structure.</p>
  168. * Instances, or subclasses which need a different DOM structure may provide a different
  169. * template layout in conjunction with an implementation of {@link #getTemplateArgs}.
  170. * @type Ext.Template
  171. * @property template
  172. */
  173. /**
  174. * @cfg {String} cls
  175. * A CSS class string to apply to the button's main element.
  176. */
  177. /**
  178. * @property menu
  179. * @type Menu
  180. * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option.
  181. */
  182. /**
  183. * @cfg {Boolean} autoWidth
  184. * By default, if a width is not specified the button will attempt to stretch horizontally to fit its content.
  185. * If the button is being managed by a width sizing layout (hbox, fit, anchor), set this to false to prevent
  186. * the button from doing this automatic sizing.
  187. * Defaults to <tt>undefined</tt>.
  188. */
  189. initComponent : function(){
  190. if(this.menu){
  191. this.menu = Ext.menu.MenuMgr.get(this.menu);
  192. this.menu.ownerCt = this;
  193. }
  194. Ext.Button.superclass.initComponent.call(this);
  195. this.addEvents(
  196. /**
  197. * @event click
  198. * Fires when this button is clicked
  199. * @param {Button} this
  200. * @param {EventObject} e The click event
  201. */
  202. 'click',
  203. /**
  204. * @event toggle
  205. * Fires when the 'pressed' state of this button changes (only if enableToggle = true)
  206. * @param {Button} this
  207. * @param {Boolean} pressed
  208. */
  209. 'toggle',
  210. /**
  211. * @event mouseover
  212. * Fires when the mouse hovers over the button
  213. * @param {Button} this
  214. * @param {Event} e The event object
  215. */
  216. 'mouseover',
  217. /**
  218. * @event mouseout
  219. * Fires when the mouse exits the button
  220. * @param {Button} this
  221. * @param {Event} e The event object
  222. */
  223. 'mouseout',
  224. /**
  225. * @event menushow
  226. * If this button has a menu, this event fires when it is shown
  227. * @param {Button} this
  228. * @param {Menu} menu
  229. */
  230. 'menushow',
  231. /**
  232. * @event menuhide
  233. * If this button has a menu, this event fires when it is hidden
  234. * @param {Button} this
  235. * @param {Menu} menu
  236. */
  237. 'menuhide',
  238. /**
  239. * @event menutriggerover
  240. * If this button has a menu, this event fires when the mouse enters the menu triggering element
  241. * @param {Button} this
  242. * @param {Menu} menu
  243. * @param {EventObject} e
  244. */
  245. 'menutriggerover',
  246. /**
  247. * @event menutriggerout
  248. * If this button has a menu, this event fires when the mouse leaves the menu triggering element
  249. * @param {Button} this
  250. * @param {Menu} menu
  251. * @param {EventObject} e
  252. */
  253. 'menutriggerout'
  254. );
  255. if (this.menu){
  256. this.menu.ownerCt = undefined;
  257. }
  258. if(Ext.isString(this.toggleGroup)){
  259. this.enableToggle = true;
  260. }
  261. },
  262. /**
  263. * <p>This method returns an Array which provides substitution parameters for the {@link #template Template} used
  264. * to create this Button's DOM structure.</p>
  265. * <p>Instances or subclasses which use a different Template to create a different DOM structure may need to provide their
  266. * own implementation of this method.</p>
  267. * <p>The default implementation which provides data for the default {@link #template} returns an Array containing the
  268. * following items:</p><div class="mdetail-params"><ul>
  269. * <li>The &lt;button&gt;'s {@link #type}</li>
  270. * <li>A CSS class name applied to the Button's main &lt;tbody&gt; element which determines the button's scale and icon alignment.</li>
  271. * <li>A CSS class to determine the presence and position of an arrow icon. (<code>'x-btn-arrow'</code> or <code>'x-btn-arrow-bottom'</code> or <code>''</code>)</li>
  272. * <li>The {@link #cls} CSS class name applied to the button's wrapping &lt;table&gt; element.</li>
  273. * <li>The Component id which is applied to the button's wrapping &lt;table&gt; element.</li>
  274. * </ul></div>
  275. * @return {Array} Substitution data for a Template.
  276. */
  277. getTemplateArgs : function(){
  278. return [this.type, 'x-btn-' + this.scale + ' x-btn-icon-' + this.scale + '-' + this.iconAlign, this.getMenuClass(), this.cls, this.id];
  279. },
  280. // private
  281. setButtonClass : function(){
  282. if(this.useSetClass){
  283. if(!Ext.isEmpty(this.oldCls)){
  284. this.el.removeClass([this.oldCls, 'x-btn-pressed']);
  285. }
  286. this.oldCls = (this.iconCls || this.icon) ? (this.text ? 'x-btn-text-icon' : 'x-btn-icon') : 'x-btn-noicon';
  287. this.el.addClass([this.oldCls, this.pressed ? 'x-btn-pressed' : null]);
  288. }
  289. },
  290. // protected
  291. getMenuClass : function(){
  292. return this.menu ? (this.arrowAlign != 'bottom' ? 'x-btn-arrow' : 'x-btn-arrow-bottom') : '';
  293. },
  294. // private
  295. onRender : function(ct, position){
  296. if(!this.template){
  297. if(!Ext.Button.buttonTemplate){
  298. // hideous table template
  299. Ext.Button.buttonTemplate = new Ext.Template(
  300. '<table id="{4}" cellspacing="0" class="x-btn {3}"><tbody class="{1}">',
  301. '<tr><td class="x-btn-tl"><i>&#160;</i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i>&#160;</i></td></tr>',
  302. '<tr><td class="x-btn-ml"><i>&#160;</i></td><td class="x-btn-mc"><em class="{2}" unselectable="on"><button type="{0}"></button></em></td><td class="x-btn-mr"><i>&#160;</i></td></tr>',
  303. '<tr><td class="x-btn-bl"><i>&#160;</i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i>&#160;</i></td></tr>',
  304. '</tbody></table>');
  305. Ext.Button.buttonTemplate.compile();
  306. }
  307. this.template = Ext.Button.buttonTemplate;
  308. }
  309. var btn, targs = this.getTemplateArgs();
  310. if(position){
  311. btn = this.template.insertBefore(position, targs, true);
  312. }else{
  313. btn = this.template.append(ct, targs, true);
  314. }
  315. /**
  316. * An {@link Ext.Element Element} encapsulating the Button's clickable element. By default,
  317. * this references a <tt>&lt;button&gt;</tt> element. Read only.
  318. * @type Ext.Element
  319. * @property btnEl
  320. */
  321. this.btnEl = btn.child(this.buttonSelector);
  322. this.mon(this.btnEl, {
  323. scope: this,
  324. focus: this.onFocus,
  325. blur: this.onBlur
  326. });
  327. this.initButtonEl(btn, this.btnEl);
  328. Ext.ButtonToggleMgr.register(this);
  329. },
  330. // private
  331. initButtonEl : function(btn, btnEl){
  332. this.el = btn;
  333. this.setIcon(this.icon);
  334. this.setText(this.text);
  335. this.setIconClass(this.iconCls);
  336. if(Ext.isDefined(this.tabIndex)){
  337. btnEl.dom.tabIndex = this.tabIndex;
  338. }
  339. if(this.tooltip){
  340. this.setTooltip(this.tooltip, true);
  341. }
  342. if(this.handleMouseEvents){
  343. this.mon(btn, {
  344. scope: this,
  345. mouseover: this.onMouseOver,
  346. mousedown: this.onMouseDown
  347. });
  348. // new functionality for monitoring on the document level
  349. //this.mon(btn, 'mouseout', this.onMouseOut, this);
  350. }
  351. if(this.menu){
  352. this.mon(this.menu, {
  353. scope: this,
  354. show: this.onMenuShow,
  355. hide: this.onMenuHide
  356. });
  357. }
  358. if(this.repeat){
  359. var repeater = new Ext.util.ClickRepeater(btn, Ext.isObject(this.repeat) ? this.repeat : {});
  360. this.mon(repeater, 'click', this.onRepeatClick, this);
  361. }else{
  362. this.mon(btn, this.clickEvent, this.onClick, this);
  363. }
  364. },
  365. // private
  366. afterRender : function(){
  367. Ext.Button.superclass.afterRender.call(this);
  368. this.useSetClass = true;
  369. this.setButtonClass();
  370. this.doc = Ext.getDoc();
  371. this.doAutoWidth();
  372. },
  373. /**
  374. * Sets the CSS class that provides a background image to use as the button's icon. This method also changes
  375. * the value of the {@link iconCls} config internally.
  376. * @param {String} cls The CSS class providing the icon image
  377. * @return {Ext.Button} this
  378. */
  379. setIconClass : function(cls){
  380. this.iconCls = cls;
  381. if(this.el){
  382. this.btnEl.dom.className = '';
  383. this.btnEl.addClass(['x-btn-text', cls || '']);
  384. this.setButtonClass();
  385. }
  386. return this;
  387. },
  388. /**
  389. * Sets the tooltip for this Button.
  390. * @param {String/Object} tooltip. This may be:<div class="mdesc-details"><ul>
  391. * <li><b>String</b> : A string to be used as innerHTML (html tags are accepted) to show in a tooltip</li>
  392. * <li><b>Object</b> : A configuration object for {@link Ext.QuickTips#register}.</li>
  393. * </ul></div>
  394. * @return {Ext.Button} this
  395. */
  396. setTooltip : function(tooltip, /* private */ initial){
  397. if(this.rendered){
  398. if(!initial){
  399. this.clearTip();
  400. }
  401. if(Ext.isObject(tooltip)){
  402. Ext.QuickTips.register(Ext.apply({
  403. target: this.btnEl.id
  404. }, tooltip));
  405. this.tooltip = tooltip;
  406. }else{
  407. this.btnEl.dom[this.tooltipType] = tooltip;
  408. }
  409. }else{
  410. this.tooltip = tooltip;
  411. }
  412. return this;
  413. },
  414. // private
  415. clearTip : function(){
  416. if(Ext.isObject(this.tooltip)){
  417. Ext.QuickTips.unregister(this.btnEl);
  418. }
  419. },
  420. // private
  421. beforeDestroy : function(){
  422. if(this.rendered){
  423. this.clearTip();
  424. }
  425. if(this.menu && this.destroyMenu !== false) {
  426. Ext.destroy(this.btnEl, this.menu);
  427. }
  428. Ext.destroy(this.repeater);
  429. },
  430. // private
  431. onDestroy : function(){
  432. if(this.rendered){
  433. this.doc.un('mouseover', this.monitorMouseOver, this);
  434. this.doc.un('mouseup', this.onMouseUp, this);
  435. delete this.doc;
  436. delete this.btnEl;
  437. Ext.ButtonToggleMgr.unregister(this);
  438. }
  439. Ext.Button.superclass.onDestroy.call(this);
  440. },
  441. // private
  442. doAutoWidth : function(){
  443. if(this.autoWidth !== false && this.el && this.text && this.width === undefined){
  444. this.el.setWidth('auto');
  445. if(Ext.isIE7 && Ext.isStrict){
  446. var ib = this.btnEl;
  447. if(ib && ib.getWidth() > 20){
  448. ib.clip();
  449. ib.setWidth(Ext.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
  450. }
  451. }
  452. if(this.minWidth){
  453. if(this.el.getWidth() < this.minWidth){
  454. this.el.setWidth(this.minWidth);
  455. }
  456. }
  457. }
  458. },
  459. /**
  460. * Assigns this Button's click handler
  461. * @param {Function} handler The function to call when the button is clicked
  462. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
  463. * Defaults to this Button.
  464. * @return {Ext.Button} this
  465. */
  466. setHandler : function(handler, scope){
  467. this.handler = handler;
  468. this.scope = scope;
  469. return this;
  470. },
  471. /**
  472. * Sets this Button's text
  473. * @param {String} text The button text
  474. * @return {Ext.Button} this
  475. */
  476. setText : function(text){
  477. this.text = text;
  478. if(this.el){
  479. this.btnEl.update(text || '&#160;');
  480. this.setButtonClass();
  481. }
  482. this.doAutoWidth();
  483. return this;
  484. },
  485. /**
  486. * Sets the background image (inline style) of the button. This method also changes
  487. * the value of the {@link icon} config internally.
  488. * @param {String} icon The path to an image to display in the button
  489. * @return {Ext.Button} this
  490. */
  491. setIcon : function(icon){
  492. this.icon = icon;
  493. if(this.el){
  494. this.btnEl.setStyle('background-image', icon ? 'url(' + icon + ')' : '');
  495. this.setButtonClass();
  496. }
  497. return this;
  498. },
  499. /**
  500. * Gets the text for this Button
  501. * @return {String} The button text
  502. */
  503. getText : function(){
  504. return this.text;
  505. },
  506. /**
  507. * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
  508. * @param {Boolean} state (optional) Force a particular state
  509. * @param {Boolean} supressEvent (optional) True to stop events being fired when calling this method.
  510. * @return {Ext.Button} this
  511. */
  512. toggle : function(state, suppressEvent){
  513. state = state === undefined ? !this.pressed : !!state;
  514. if(state != this.pressed){
  515. if(this.rendered){
  516. this.el[state ? 'addClass' : 'removeClass']('x-btn-pressed');
  517. }
  518. this.pressed = state;
  519. if(!suppressEvent){
  520. this.fireEvent('toggle', this, state);
  521. if(this.toggleHandler){
  522. this.toggleHandler.call(this.scope || this, this, state);
  523. }
  524. }
  525. }
  526. return this;
  527. },
  528. // private
  529. onDisable : function(){
  530. this.onDisableChange(true);
  531. },
  532. // private
  533. onEnable : function(){
  534. this.onDisableChange(false);
  535. },
  536. onDisableChange : function(disabled){
  537. if(this.el){
  538. if(!Ext.isIE6 || !this.text){
  539. this.el[disabled ? 'addClass' : 'removeClass'](this.disabledClass);
  540. }
  541. this.el.dom.disabled = disabled;
  542. }
  543. this.disabled = disabled;
  544. },
  545. /**
  546. * Show this button's menu (if it has one)
  547. */
  548. showMenu : function(){
  549. if(this.rendered && this.menu){
  550. if(this.tooltip){
  551. Ext.QuickTips.getQuickTip().cancelShow(this.btnEl);
  552. }
  553. if(this.menu.isVisible()){
  554. this.menu.hide();
  555. }
  556. this.menu.ownerCt = this;
  557. this.menu.show(this.el, this.menuAlign);
  558. }
  559. return this;
  560. },
  561. /**
  562. * Hide this button's menu (if it has one)
  563. */
  564. hideMenu : function(){
  565. if(this.hasVisibleMenu()){
  566. this.menu.hide();
  567. }
  568. return this;
  569. },
  570. /**
  571. * Returns true if the button has a menu and it is visible
  572. * @return {Boolean}
  573. */
  574. hasVisibleMenu : function(){
  575. return this.menu && this.menu.ownerCt == this && this.menu.isVisible();
  576. },
  577. // private
  578. onRepeatClick : function(repeat, e){
  579. this.onClick(e);
  580. },
  581. // private
  582. onClick : function(e){
  583. if(e){
  584. e.preventDefault();
  585. }
  586. if(e.button !== 0){
  587. return;
  588. }
  589. if(!this.disabled){
  590. this.doToggle();
  591. if(this.menu && !this.hasVisibleMenu() && !this.ignoreNextClick){
  592. this.showMenu();
  593. }
  594. this.fireEvent('click', this, e);
  595. if(this.handler){
  596. //this.el.removeClass('x-btn-over');
  597. this.handler.call(this.scope || this, this, e);
  598. }
  599. }
  600. },
  601. // private
  602. doToggle: function(){
  603. if (this.enableToggle && (this.allowDepress !== false || !this.pressed)) {
  604. this.toggle();
  605. }
  606. },
  607. // private
  608. isMenuTriggerOver : function(e, internal){
  609. return this.menu && !internal;
  610. },
  611. // private
  612. isMenuTriggerOut : function(e, internal){
  613. return this.menu && !internal;
  614. },
  615. // private
  616. onMouseOver : function(e){
  617. if(!this.disabled){
  618. var internal = e.within(this.el, true);
  619. if(!internal){
  620. this.el.addClass('x-btn-over');
  621. if(!this.monitoringMouseOver){
  622. this.doc.on('mouseover', this.monitorMouseOver, this);
  623. this.monitoringMouseOver = true;
  624. }
  625. this.fireEvent('mouseover', this, e);
  626. }
  627. if(this.isMenuTriggerOver(e, internal)){
  628. this.fireEvent('menutriggerover', this, this.menu, e);
  629. }
  630. }
  631. },
  632. // private
  633. monitorMouseOver : function(e){
  634. if(e.target != this.el.dom && !e.within(this.el)){
  635. if(this.monitoringMouseOver){
  636. this.doc.un('mouseover', this.monitorMouseOver, this);
  637. this.monitoringMouseOver = false;
  638. }
  639. this.onMouseOut(e);
  640. }
  641. },
  642. // private
  643. onMouseOut : function(e){
  644. var internal = e.within(this.el) && e.target != this.el.dom;
  645. this.el.removeClass('x-btn-over');
  646. this.fireEvent('mouseout', this, e);
  647. if(this.isMenuTriggerOut(e, internal)){
  648. this.fireEvent('menutriggerout', this, this.menu, e);
  649. }
  650. },
  651. focus : function() {
  652. this.btnEl.focus();
  653. },
  654. blur : function() {
  655. this.btnEl.blur();
  656. },
  657. // private
  658. onFocus : function(e){
  659. if(!this.disabled){
  660. this.el.addClass('x-btn-focus');
  661. }
  662. },
  663. // private
  664. onBlur : function(e){
  665. this.el.removeClass('x-btn-focus');
  666. },
  667. // private
  668. getClickEl : function(e, isUp){
  669. return this.el;
  670. },
  671. // private
  672. onMouseDown : function(e){
  673. if(!this.disabled && e.button === 0){
  674. this.getClickEl(e).addClass('x-btn-click');
  675. this.doc.on('mouseup', this.onMouseUp, this);
  676. }
  677. },
  678. // private
  679. onMouseUp : function(e){
  680. if(e.button === 0){
  681. this.getClickEl(e, true).removeClass('x-btn-click');
  682. this.doc.un('mouseup', this.onMouseUp, this);
  683. }
  684. },
  685. // private
  686. onMenuShow : function(e){
  687. if(this.menu.ownerCt == this){
  688. this.menu.ownerCt = this;
  689. this.ignoreNextClick = 0;
  690. this.el.addClass('x-btn-menu-active');
  691. this.fireEvent('menushow', this, this.menu);
  692. }
  693. },
  694. // private
  695. onMenuHide : function(e){
  696. if(this.menu.ownerCt == this){
  697. this.el.removeClass('x-btn-menu-active');
  698. this.ignoreNextClick = this.restoreClick.defer(250, this);
  699. this.fireEvent('menuhide', this, this.menu);
  700. delete this.menu.ownerCt;
  701. }
  702. },
  703. // private
  704. restoreClick : function(){
  705. this.ignoreNextClick = 0;
  706. }
  707. /**
  708. * @cfg {String} autoEl @hide
  709. */
  710. /**
  711. * @cfg {String/Object} html @hide
  712. */
  713. /**
  714. * @cfg {String} contentEl @hide
  715. */
  716. /**
  717. * @cfg {Mixed} data @hide
  718. */
  719. /**
  720. * @cfg {Mixed} tpl @hide
  721. */
  722. /**
  723. * @cfg {String} tplWriteMode @hide
  724. */
  725. });
  726. Ext.reg('button', Ext.Button);
  727. // Private utility class used by Button
  728. Ext.ButtonToggleMgr = function(){
  729. var groups = {};
  730. function toggleGroup(btn, state){
  731. if(state){
  732. var g = groups[btn.toggleGroup];
  733. for(var i = 0, l = g.length; i < l; i++){
  734. if(g[i] != btn){
  735. g[i].toggle(false);
  736. }
  737. }
  738. }
  739. }
  740. return {
  741. register : function(btn){
  742. if(!btn.toggleGroup){
  743. return;
  744. }
  745. var g = groups[btn.toggleGroup];
  746. if(!g){
  747. g = groups[btn.toggleGroup] = [];
  748. }
  749. g.push(btn);
  750. btn.on('toggle', toggleGroup);
  751. },
  752. unregister : function(btn){
  753. if(!btn.toggleGroup){
  754. return;
  755. }
  756. var g = groups[btn.toggleGroup];
  757. if(g){
  758. g.remove(btn);
  759. btn.un('toggle', toggleGroup);
  760. }
  761. },
  762. /**
  763. * Gets the pressed button in the passed group or null
  764. * @param {String} group
  765. * @return Button
  766. */
  767. getPressed : function(group){
  768. var g = groups[group];
  769. if(g){
  770. for(var i = 0, len = g.length; i < len; i++){
  771. if(g[i].pressed === true){
  772. return g[i];
  773. }
  774. }
  775. }
  776. return null;
  777. }
  778. };
  779. }();
  780. </pre>
  781. </body>
  782. </html>