]>
git.proxmox.com Git - sencha-touch.git/blob - src/src/util/TapRepeater.js
2 * A wrapper class which can be applied to any element. Fires a "tap" event while
3 * touching the device. The interval between firings may be specified in the config but
4 * defaults to 20 milliseconds.
6 Ext
.define('Ext.util.TapRepeater', {
7 requires
: ['Ext.DateExtras'],
10 observable
: 'Ext.mixin.Observable'
15 * Fires when the touch is started.
16 * @param {Ext.util.TapRepeater} this
17 * @param {Ext.event.Event} e
22 * Fires on a specified interval during the time the element is pressed.
23 * @param {Ext.util.TapRepeater} this
24 * @param {Ext.event.Event} e
29 * Fires when the touch is ended.
30 * @param {Ext.util.TapRepeater} this
31 * @param {Ext.event.Event} e
46 * Creates new TapRepeater.
47 * @param {Object} config
49 constructor: function(config
) {
52 for (var configName
in config
) {
53 if (me
.self
.prototype.config
&& !(configName
in me
.self
.prototype.config
)) {
54 me
[configName
] = config
[configName
];
55 Ext
.Logger
.warn('Applied config as instance property: "' + configName
+ '"', me
);
59 me
.initConfig(config
);
62 updateEl: function(newEl
, oldEl
) {
64 touchstart
: 'onTouchStart',
65 touchend
: 'onTouchEnd',
76 eventOptions: function(e
) {
77 if (this.getPreventDefault()) {
80 if (this.getStopDefault()) {
87 this.clearListeners();
92 onTouchStart: function(e
) {
94 pressCls
= me
.getPressCls();
95 clearTimeout(me
.getTimer());
97 me
.getEl().addCls(pressCls
);
99 me
.tapStartTime
= new Date();
101 me
.fireEvent('touchstart', me
, e
);
102 me
.fireEvent('tap', me
, e
);
104 // Do not honor delay or interval if acceleration wanted.
105 if (me
.getAccelerate()) {
108 me
.setTimer(Ext
.defer(me
.tap
, me
.getDelay() || me
.getInterval(), me
, [e
]));
114 me
.fireEvent('tap', me
, e
);
115 me
.setTimer(Ext
.defer(me
.tap
, me
.getAccelerate() ? me
.easeOutExpo(Ext
.Date
.getElapsed(me
.tapStartTime
),
118 12000) : me
.getInterval(), me
, [e
]));
121 // Easing calculation
123 easeOutExpo: function(t
, b
, c
, d
) {
124 return (t
== d
) ? b
+ c
: c
* ( - Math
.pow(2, -10 * t
/ d
) + 1) + b
;
128 onTouchEnd: function(e
) {
130 clearTimeout(me
.getTimer());
131 me
.getEl().removeCls(me
.getPressCls());
132 me
.fireEvent('touchend', me
, e
);