ClickRepeater_wev8.js
4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
@class Ext.util.ClickRepeater
@extends Ext.util.Observable
A wrapper class which can be applied to any element. Fires a "click" event while the
mouse is pressed. The interval between firings may be specified in the config but
defaults to 20 milliseconds.
Optionally, a CSS class may be applied to the element during the time it is pressed.
@cfg {Mixed} el The element to act as a button.
@cfg {Number} delay The initial delay before the repeating event begins firing.
Similar to an autorepeat key delay.
@cfg {Number} interval The interval between firings of the "click" event. Default 20 ms.
@cfg {String} pressClass A CSS class name to be applied to the element while pressed.
@cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
"interval" and "delay" are ignored.
@cfg {Boolean} preventDefault True to prevent the default click event
@cfg {Boolean} stopDefault True to stop the default click event
@history
2007-02-02 jvs Original code contributed by Nige "Animal" White
2007-02-02 jvs Renamed to ClickRepeater
2007-02-03 jvs Modifications for FF Mac and Safari
@constructor
@param {Mixed} el The element to listen on
@param {Object} config
*/
Ext.util.ClickRepeater = function(el, config)
{
this.el = Ext.get(el);
this.el.unselectable();
Ext.apply(this, config);
this.addEvents(
/**
* @event mousedown
* Fires when the mouse button is depressed.
* @param {Ext.util.ClickRepeater} this
*/
"mousedown",
/**
* @event click
* Fires on a specified interval during the time the element is pressed.
* @param {Ext.util.ClickRepeater} this
*/
"click",
/**
* @event mouseup
* Fires when the mouse key is released.
* @param {Ext.util.ClickRepeater} this
*/
"mouseup"
);
this.el.on("mousedown", this.handleMouseDown, this);
if(this.preventDefault || this.stopDefault){
this.el.on("click", function(e){
if(this.preventDefault){
e.preventDefault();
}
if(this.stopDefault){
e.stopEvent();
}
}, this);
}
// allow inline handler
if(this.handler){
this.on("click", this.handler, this.scope || this);
}
Ext.util.ClickRepeater.superclass.constructor.call(this);
};
Ext.extend(Ext.util.ClickRepeater, Ext.util.Observable, {
interval : 20,
delay: 250,
preventDefault : true,
stopDefault : false,
timer : 0,
// private
handleMouseDown : function(){
clearTimeout(this.timer);
this.el.blur();
if(this.pressClass){
this.el.addClass(this.pressClass);
}
this.mousedownTime = new Date();
Ext.getDoc().on("mouseup", this.handleMouseUp, this);
this.el.on("mouseout", this.handleMouseOut, this);
this.fireEvent("mousedown", this);
this.fireEvent("click", this);
// Do not honor delay or interval if acceleration wanted.
if (this.accelerate) {
this.delay = 400;
}
this.timer = this.click.defer(this.delay || this.interval, this);
},
// private
click : function(){
this.fireEvent("click", this);
this.timer = this.click.defer(this.accelerate ?
this.easeOutExpo(this.mousedownTime.getElapsed(),
400,
-390,
12000) :
this.interval, this);
},
easeOutExpo : function (t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
// private
handleMouseOut : function(){
clearTimeout(this.timer);
if(this.pressClass){
this.el.removeClass(this.pressClass);
}
this.el.on("mouseover", this.handleMouseReturn, this);
},
// private
handleMouseReturn : function(){
this.el.un("mouseover", this.handleMouseReturn);
if(this.pressClass){
this.el.addClass(this.pressClass);
}
this.click();
},
// private
handleMouseUp : function(){
clearTimeout(this.timer);
this.el.un("mouseover", this.handleMouseReturn);
this.el.un("mouseout", this.handleMouseOut);
Ext.getDoc().un("mouseup", this.handleMouseUp);
this.el.removeClass(this.pressClass);
this.fireEvent("mouseup", this);
}
});