Web Interface For Lite Argus Control modules
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.

135 lines
4.4 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.SplitButton"></div>/**
  16. * @class Ext.SplitButton
  17. * @extends Ext.Button
  18. * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
  19. * click event of the button. Typically this would be used to display a dropdown menu that provides additional
  20. * options to the primary button action, but any custom handler can provide the arrowclick implementation. Example usage:
  21. * <pre><code>
  22. // display a dropdown menu:
  23. new Ext.SplitButton({
  24. renderTo: 'button-ct', // the container id
  25. text: 'Options',
  26. handler: optionsHandler, // handle a click on the button itself
  27. menu: new Ext.menu.Menu({
  28. items: [
  29. // these items will render as dropdown menu items when the arrow is clicked:
  30. {text: 'Item 1', handler: item1Handler},
  31. {text: 'Item 2', handler: item2Handler}
  32. ]
  33. })
  34. });
  35. // Instead of showing a menu, you provide any type of custom
  36. // functionality you want when the dropdown arrow is clicked:
  37. new Ext.SplitButton({
  38. renderTo: 'button-ct',
  39. text: 'Options',
  40. handler: optionsHandler,
  41. arrowHandler: myCustomHandler
  42. });
  43. </code></pre>
  44. * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
  45. * @cfg {String} arrowTooltip The title attribute of the arrow
  46. * @constructor
  47. * Create a new menu button
  48. * @param {Object} config The config object
  49. * @xtype splitbutton
  50. */
  51. Ext.SplitButton = Ext.extend(Ext.Button, {
  52. // private
  53. arrowSelector : 'em',
  54. split: true,
  55. // private
  56. initComponent : function(){
  57. Ext.SplitButton.superclass.initComponent.call(this);
  58. /**
  59. * @event arrowclick
  60. * Fires when this button's arrow is clicked
  61. * @param {MenuButton} this
  62. * @param {EventObject} e The click event
  63. */
  64. this.addEvents("arrowclick");
  65. },
  66. // private
  67. onRender : function(){
  68. Ext.SplitButton.superclass.onRender.apply(this, arguments);
  69. if(this.arrowTooltip){
  70. this.el.child(this.arrowSelector).dom[this.tooltipType] = this.arrowTooltip;
  71. }
  72. },
  73. /**
  74. * Sets this button's arrow click handler.
  75. * @param {Function} handler The function to call when the arrow is clicked
  76. * @param {Object} scope (optional) Scope for the function passed above
  77. */
  78. setArrowHandler : function(handler, scope){
  79. this.arrowHandler = handler;
  80. this.scope = scope;
  81. },
  82. getMenuClass : function(){
  83. return 'x-btn-split' + (this.arrowAlign == 'bottom' ? '-bottom' : '');
  84. },
  85. isClickOnArrow : function(e){
  86. if (this.arrowAlign != 'bottom') {
  87. var visBtn = this.el.child('em.x-btn-split');
  88. var right = visBtn.getRegion().right - visBtn.getPadding('r');
  89. return e.getPageX() > right;
  90. } else {
  91. return e.getPageY() > this.btnEl.getRegion().bottom;
  92. }
  93. },
  94. // private
  95. onClick : function(e, t){
  96. e.preventDefault();
  97. if(!this.disabled){
  98. if(this.isClickOnArrow(e)){
  99. if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){
  100. this.showMenu();
  101. }
  102. this.fireEvent("arrowclick", this, e);
  103. if(this.arrowHandler){
  104. this.arrowHandler.call(this.scope || this, this, e);
  105. }
  106. }else{
  107. this.doToggle();
  108. this.fireEvent("click", this, e);
  109. if(this.handler){
  110. this.handler.call(this.scope || this, this, e);
  111. }
  112. }
  113. }
  114. },
  115. // private
  116. isMenuTriggerOver : function(e){
  117. return this.menu && e.target.tagName == this.arrowSelector;
  118. },
  119. // private
  120. isMenuTriggerOut : function(e, internal){
  121. return this.menu && e.target.tagName != this.arrowSelector;
  122. }
  123. });
  124. Ext.reg('splitbutton', Ext.SplitButton);</pre>
  125. </body>
  126. </html>