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.

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