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.

139 lines
5.3 KiB

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