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.

227 lines
8.4 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-util-ClickRepeater-method-constructor'><span id='Ext-util-ClickRepeater-cfg-stopDefault'><span id='Ext-util-ClickRepeater-cfg-accelerate'><span id='Ext-util-ClickRepeater-cfg-pressClass'><span id='Ext-util-ClickRepeater-cfg-interval'><span id='Ext-util-ClickRepeater-cfg-delay'><span id='Ext-util-ClickRepeater-cfg-el'><span id='Ext-util-ClickRepeater'>/**
  19. </span></span></span></span></span></span></span></span> @class Ext.util.ClickRepeater
  20. @extends Ext.util.Observable
  21. A wrapper class which can be applied to any element. Fires a &quot;click&quot; event while the
  22. mouse is pressed. The interval between firings may be specified in the config but
  23. defaults to 20 milliseconds.
  24. Optionally, a CSS class may be applied to the element during the time it is pressed.
  25. @cfg {Mixed} el The element to act as a button.
  26. @cfg {Number} delay The initial delay before the repeating event begins firing.
  27. Similar to an autorepeat key delay.
  28. @cfg {Number} interval The interval between firings of the &quot;click&quot; event. Default 20 ms.
  29. @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
  30. @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
  31. &quot;interval&quot; and &quot;delay&quot; are ignored.
  32. @cfg {Boolean} preventDefault True to prevent the default click event
  33. @cfg {Boolean} stopDefault True to stop the default click event
  34. @history
  35. 2007-02-02 jvs Original code contributed by Nige &quot;Animal&quot; White
  36. 2007-02-02 jvs Renamed to ClickRepeater
  37. 2007-02-03 jvs Modifications for FF Mac and Safari
  38. @constructor
  39. @param {Mixed} el The element to listen on
  40. @param {Object} config
  41. */
  42. Ext.util.ClickRepeater = Ext.extend(Ext.util.Observable, {
  43. constructor : function(el, config){
  44. this.el = Ext.get(el);
  45. this.el.unselectable();
  46. Ext.apply(this, config);
  47. this.addEvents(
  48. <span id='Ext-util-ClickRepeater-event-mousedown'> /**
  49. </span> * @event mousedown
  50. * Fires when the mouse button is depressed.
  51. * @param {Ext.util.ClickRepeater} this
  52. * @param {Ext.EventObject} e
  53. */
  54. &quot;mousedown&quot;,
  55. <span id='Ext-util-ClickRepeater-event-click'> /**
  56. </span> * @event click
  57. * Fires on a specified interval during the time the element is pressed.
  58. * @param {Ext.util.ClickRepeater} this
  59. * @param {Ext.EventObject} e
  60. */
  61. &quot;click&quot;,
  62. <span id='Ext-util-ClickRepeater-event-mouseup'> /**
  63. </span> * @event mouseup
  64. * Fires when the mouse key is released.
  65. * @param {Ext.util.ClickRepeater} this
  66. * @param {Ext.EventObject} e
  67. */
  68. &quot;mouseup&quot;
  69. );
  70. if(!this.disabled){
  71. this.disabled = true;
  72. this.enable();
  73. }
  74. // allow inline handler
  75. if(this.handler){
  76. this.on(&quot;click&quot;, this.handler, this.scope || this);
  77. }
  78. Ext.util.ClickRepeater.superclass.constructor.call(this);
  79. },
  80. <span id='Ext-util-ClickRepeater-property-interval'> interval : 20,
  81. </span><span id='Ext-util-ClickRepeater-property-delay'> delay: 250,
  82. </span><span id='Ext-util-ClickRepeater-property-preventDefault'> preventDefault : true,
  83. </span><span id='Ext-util-ClickRepeater-property-stopDefault'> stopDefault : false,
  84. </span><span id='Ext-util-ClickRepeater-property-timer'> timer : 0,
  85. </span>
  86. <span id='Ext-util-ClickRepeater-method-enable'> /**
  87. </span> * Enables the repeater and allows events to fire.
  88. */
  89. enable: function(){
  90. if(this.disabled){
  91. this.el.on('mousedown', this.handleMouseDown, this);
  92. if (Ext.isIE){
  93. this.el.on('dblclick', this.handleDblClick, this);
  94. }
  95. if(this.preventDefault || this.stopDefault){
  96. this.el.on('click', this.eventOptions, this);
  97. }
  98. }
  99. this.disabled = false;
  100. },
  101. <span id='Ext-util-ClickRepeater-method-disable'> /**
  102. </span> * Disables the repeater and stops events from firing.
  103. */
  104. disable: function(/* private */ force){
  105. if(force || !this.disabled){
  106. clearTimeout(this.timer);
  107. if(this.pressClass){
  108. this.el.removeClass(this.pressClass);
  109. }
  110. Ext.getDoc().un('mouseup', this.handleMouseUp, this);
  111. this.el.removeAllListeners();
  112. }
  113. this.disabled = true;
  114. },
  115. <span id='Ext-util-ClickRepeater-method-setDisabled'> /**
  116. </span> * Convenience function for setting disabled/enabled by boolean.
  117. * @param {Boolean} disabled
  118. */
  119. setDisabled: function(disabled){
  120. this[disabled ? 'disable' : 'enable']();
  121. },
  122. <span id='Ext-util-ClickRepeater-method-eventOptions'> eventOptions: function(e){
  123. </span> if(this.preventDefault){
  124. e.preventDefault();
  125. }
  126. if(this.stopDefault){
  127. e.stopEvent();
  128. }
  129. },
  130. <span id='Ext-util-ClickRepeater-method-destroy'> // private
  131. </span> destroy : function() {
  132. this.disable(true);
  133. Ext.destroy(this.el);
  134. this.purgeListeners();
  135. },
  136. <span id='Ext-util-ClickRepeater-method-handleDblClick'> handleDblClick : function(e){
  137. </span> clearTimeout(this.timer);
  138. this.el.blur();
  139. this.fireEvent(&quot;mousedown&quot;, this, e);
  140. this.fireEvent(&quot;click&quot;, this, e);
  141. },
  142. <span id='Ext-util-ClickRepeater-method-handleMouseDown'> // private
  143. </span> handleMouseDown : function(e){
  144. clearTimeout(this.timer);
  145. this.el.blur();
  146. if(this.pressClass){
  147. this.el.addClass(this.pressClass);
  148. }
  149. this.mousedownTime = new Date();
  150. Ext.getDoc().on(&quot;mouseup&quot;, this.handleMouseUp, this);
  151. this.el.on(&quot;mouseout&quot;, this.handleMouseOut, this);
  152. this.fireEvent(&quot;mousedown&quot;, this, e);
  153. this.fireEvent(&quot;click&quot;, this, e);
  154. // Do not honor delay or interval if acceleration wanted.
  155. if (this.accelerate) {
  156. this.delay = 400;
  157. }
  158. this.timer = this.click.defer(this.delay || this.interval, this, [e]);
  159. },
  160. <span id='Ext-util-ClickRepeater-method-click'> // private
  161. </span> click : function(e){
  162. this.fireEvent(&quot;click&quot;, this, e);
  163. this.timer = this.click.defer(this.accelerate ?
  164. this.easeOutExpo(this.mousedownTime.getElapsed(),
  165. 400,
  166. -390,
  167. 12000) :
  168. this.interval, this, [e]);
  169. },
  170. <span id='Ext-util-ClickRepeater-method-easeOutExpo'> easeOutExpo : function (t, b, c, d) {
  171. </span> return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
  172. },
  173. <span id='Ext-util-ClickRepeater-method-handleMouseOut'> // private
  174. </span> handleMouseOut : function(){
  175. clearTimeout(this.timer);
  176. if(this.pressClass){
  177. this.el.removeClass(this.pressClass);
  178. }
  179. this.el.on(&quot;mouseover&quot;, this.handleMouseReturn, this);
  180. },
  181. <span id='Ext-util-ClickRepeater-method-handleMouseReturn'> // private
  182. </span> handleMouseReturn : function(){
  183. this.el.un(&quot;mouseover&quot;, this.handleMouseReturn, this);
  184. if(this.pressClass){
  185. this.el.addClass(this.pressClass);
  186. }
  187. this.click();
  188. },
  189. <span id='Ext-util-ClickRepeater-method-handleMouseUp'> // private
  190. </span> handleMouseUp : function(e){
  191. clearTimeout(this.timer);
  192. this.el.un(&quot;mouseover&quot;, this.handleMouseReturn, this);
  193. this.el.un(&quot;mouseout&quot;, this.handleMouseOut, this);
  194. Ext.getDoc().un(&quot;mouseup&quot;, this.handleMouseUp, this);
  195. this.el.removeClass(this.pressClass);
  196. this.fireEvent(&quot;mouseup&quot;, this, e);
  197. }
  198. });</pre>
  199. </body>
  200. </html>