4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
15 * @class Roo.util.ClickRepeater
16 * @extends Roo.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 10 milliseconds.
22 * Optionally, a CSS class may be applied to the element during the time it is pressed.
24 * @cfg {String/HTMLElement/Element} el The element to act as a button.
25 * @cfg {Number} delay The initial delay before the repeating event begins firing.
26 * Similar to an autorepeat key delay.
27 * @cfg {Number} interval The interval between firings of the "click" event. Default 10 ms.
28 * @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
29 * @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
30 * "interval" and "delay" are ignored. "immediate" is honored.
31 * @cfg {Boolean} preventDefault True to prevent the default click event
32 * @cfg {Boolean} stopDefault True to stop the default click event
35 * 2007-02-02 jvs Original code contributed by Nige "Animal" White
36 * 2007-02-02 jvs Renamed to ClickRepeater
37 * 2007-02-03 jvs Modifications for FF Mac and Safari
40 * @param {String/HTMLElement/Element} el The element to listen on
41 * @param {Object} config
43 Roo.util.ClickRepeater = function(el, config)
45 this.el = Roo.get(el);
46 this.el.unselectable();
48 Roo.apply(this, config);
53 * Fires when the mouse button is depressed.
54 * @param {Roo.util.ClickRepeater} this
59 * Fires on a specified interval during the time the element is pressed.
60 * @param {Roo.util.ClickRepeater} this
65 * Fires when the mouse key is released.
66 * @param {Roo.util.ClickRepeater} this
71 this.el.on("mousedown", this.handleMouseDown, this);
72 if(this.preventDefault || this.stopDefault){
73 this.el.on("click", function(e){
74 if(this.preventDefault){
83 // allow inline handler
85 this.on("click", this.handler, this.scope || this);
88 Roo.util.ClickRepeater.superclass.constructor.call(this);
91 Roo.extend(Roo.util.ClickRepeater, Roo.util.Observable, {
94 preventDefault : true,
99 handleMouseDown : function(){
100 clearTimeout(this.timer);
103 this.el.addClass(this.pressClass);
105 this.mousedownTime = new Date();
107 Roo.get(document).on("mouseup", this.handleMouseUp, this);
108 this.el.on("mouseout", this.handleMouseOut, this);
110 this.fireEvent("mousedown", this);
111 this.fireEvent("click", this);
113 this.timer = this.click.defer(this.delay || this.interval, this);
118 this.fireEvent("click", this);
119 this.timer = this.click.defer(this.getInterval(), this);
123 getInterval: function(){
124 if(!this.accelerate){
125 return this.interval;
127 var pressTime = this.mousedownTime.getElapsed();
130 }else if(pressTime < 1700){
132 }else if(pressTime < 2600){
134 }else if(pressTime < 3500){
136 }else if(pressTime < 4400){
138 }else if(pressTime < 5300){
140 }else if(pressTime < 6200){
148 handleMouseOut : function(){
149 clearTimeout(this.timer);
151 this.el.removeClass(this.pressClass);
153 this.el.on("mouseover", this.handleMouseReturn, this);
157 handleMouseReturn : function(){
158 this.el.un("mouseover", this.handleMouseReturn);
160 this.el.addClass(this.pressClass);
166 handleMouseUp : function(){
167 clearTimeout(this.timer);
168 this.el.un("mouseover", this.handleMouseReturn);
169 this.el.un("mouseout", this.handleMouseOut);
170 Roo.get(document).un("mouseup", this.handleMouseUp);
171 this.el.removeClass(this.pressClass);
172 this.fireEvent("mouseup", this);