ClickRepeater-min.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.util.ClickRepeater = function(B, A) {
  7. this.el = Ext.get(B);
  8. this.el.unselectable();
  9. Ext.apply(this, A);
  10. this.addEvents("mousedown", "click", "mouseup");
  11. this.el.on("mousedown", this.handleMouseDown, this);
  12. if (this.preventDefault || this.stopDefault) {
  13. this.el.on("click", function(C) {
  14. if (this.preventDefault) {
  15. C.preventDefault()
  16. }
  17. if (this.stopDefault) {
  18. C.stopEvent()
  19. }
  20. }, this)
  21. }
  22. if (this.handler) {
  23. this.on("click", this.handler, this.scope || this)
  24. }
  25. Ext.util.ClickRepeater.superclass.constructor.call(this)
  26. };
  27. Ext.extend(Ext.util.ClickRepeater, Ext.util.Observable, {
  28. interval : 20,
  29. delay : 250,
  30. preventDefault : true,
  31. stopDefault : false,
  32. timer : 0,
  33. handleMouseDown : function() {
  34. clearTimeout(this.timer);
  35. this.el.blur();
  36. if (this.pressClass) {
  37. this.el.addClass(this.pressClass)
  38. }
  39. this.mousedownTime = allGetServerTime();
  40. Ext.getDoc().on("mouseup", this.handleMouseUp, this);
  41. this.el.on("mouseout", this.handleMouseOut, this);
  42. this.fireEvent("mousedown", this);
  43. this.fireEvent("click", this);
  44. if (this.accelerate) {
  45. this.delay = 400
  46. }
  47. this.timer = this.click
  48. .defer(this.delay || this.interval, this)
  49. },
  50. click : function() {
  51. this.fireEvent("click", this);
  52. this.timer = this.click
  53. .defer( this.accelerate ? this.easeOutExpo(
  54. this.mousedownTime.getElapsed(), 400,
  55. -390, 12000) : this.interval, this)
  56. },
  57. easeOutExpo : function(B, A, D, C) {
  58. return (B == C) ? A + D : D * (-Math.pow(2, -10 * B / C) + 1)
  59. + A
  60. },
  61. handleMouseOut : function() {
  62. clearTimeout(this.timer);
  63. if (this.pressClass) {
  64. this.el.removeClass(this.pressClass)
  65. }
  66. this.el.on("mouseover", this.handleMouseReturn, this)
  67. },
  68. handleMouseReturn : function() {
  69. this.el.un("mouseover", this.handleMouseReturn);
  70. if (this.pressClass) {
  71. this.el.addClass(this.pressClass)
  72. }
  73. this.click()
  74. },
  75. handleMouseUp : function() {
  76. clearTimeout(this.timer);
  77. this.el.un("mouseover", this.handleMouseReturn);
  78. this.el.un("mouseout", this.handleMouseOut);
  79. Ext.getDoc().un("mouseup", this.handleMouseUp);
  80. this.el.removeClass(this.pressClass);
  81. this.fireEvent("mouseup", this)
  82. }
  83. });