1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-util.ClickRepeater-method-constructor'><span id='Ext-util.ClickRepeater'>/**
2 </span></span> * @class Ext.util.ClickRepeater
3 * @extends Ext.util.Observable
5 * A wrapper class which can be applied to any element. Fires a "click" event while the
6 * mouse is pressed. The interval between firings may be specified in the config but
7 * defaults to 20 milliseconds.
9 * Optionally, a CSS class may be applied to the element during the time it is pressed.
12 * @param {Mixed} el The element to listen on
13 * @param {Object} config
16 Ext.define('Ext.util.ClickRepeater', {
17 extend: 'Ext.util.Observable',
19 constructor : function(el, config){
20 this.el = Ext.get(el);
21 this.el.unselectable();
23 Ext.apply(this, config);
26 <span id='Ext-util.ClickRepeater-event-mousedown'> /**
27 </span> * @event mousedown
28 * Fires when the mouse button is depressed.
29 * @param {Ext.util.ClickRepeater} this
30 * @param {Ext.EventObject} e
32 "mousedown",
33 <span id='Ext-util.ClickRepeater-event-click'> /**
34 </span> * @event click
35 * Fires on a specified interval during the time the element is pressed.
36 * @param {Ext.util.ClickRepeater} this
37 * @param {Ext.EventObject} e
40 <span id='Ext-util.ClickRepeater-event-mouseup'> /**
41 </span> * @event mouseup
42 * Fires when the mouse key is released.
43 * @param {Ext.util.ClickRepeater} this
44 * @param {Ext.EventObject} e
54 // allow inline handler
56 this.on("click", this.handler, this.scope || this);
62 <span id='Ext-util.ClickRepeater-cfg-el'> /**
63 </span> * @cfg {Mixed} el The element to act as a button.
66 <span id='Ext-util.ClickRepeater-cfg-pressedCls'> /**
67 </span> * @cfg {String} pressedCls A CSS class name to be applied to the element while pressed.
70 <span id='Ext-util.ClickRepeater-cfg-accelerate'> /**
71 </span> * @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
72 * "interval" and "delay" are ignored.
75 <span id='Ext-util.ClickRepeater-cfg-interval'> /**
76 </span> * @cfg {Number} interval The interval between firings of the "click" event. Default 20 ms.
80 <span id='Ext-util.ClickRepeater-cfg-delay'> /**
81 </span> * @cfg {Number} delay The initial delay before the repeating event begins firing.
82 * Similar to an autorepeat key delay.
86 <span id='Ext-util.ClickRepeater-cfg-preventDefault'> /**
87 </span> * @cfg {Boolean} preventDefault True to prevent the default click event
89 preventDefault : true,
90 <span id='Ext-util.ClickRepeater-cfg-stopDefault'> /**
91 </span> * @cfg {Boolean} stopDefault True to stop the default click event
97 <span id='Ext-util.ClickRepeater-method-enable'> /**
98 </span> * Enables the repeater and allows events to fire.
102 this.el.on('mousedown', this.handleMouseDown, this);
104 this.el.on('dblclick', this.handleDblClick, this);
106 if(this.preventDefault || this.stopDefault){
107 this.el.on('click', this.eventOptions, this);
110 this.disabled = false;
113 <span id='Ext-util.ClickRepeater-method-disable'> /**
114 </span> * Disables the repeater and stops events from firing.
116 disable: function(/* private */ force){
117 if(force || !this.disabled){
118 clearTimeout(this.timer);
120 this.el.removeCls(this.pressedCls);
122 Ext.getDoc().un('mouseup', this.handleMouseUp, this);
123 this.el.removeAllListeners();
125 this.disabled = true;
128 <span id='Ext-util.ClickRepeater-method-setDisabled'> /**
129 </span> * Convenience function for setting disabled/enabled by boolean.
130 * @param {Boolean} disabled
132 setDisabled: function(disabled){
133 this[disabled ? 'disable' : 'enable']();
136 eventOptions: function(e){
137 if(this.preventDefault){
140 if(this.stopDefault){
146 destroy : function() {
148 Ext.destroy(this.el);
149 this.clearListeners();
152 handleDblClick : function(e){
153 clearTimeout(this.timer);
156 this.fireEvent("mousedown", this, e);
157 this.fireEvent("click", this, e);
161 handleMouseDown : function(e){
162 clearTimeout(this.timer);
165 this.el.addCls(this.pressedCls);
167 this.mousedownTime = new Date();
169 Ext.getDoc().on("mouseup", this.handleMouseUp, this);
170 this.el.on("mouseout", this.handleMouseOut, this);
172 this.fireEvent("mousedown", this, e);
173 this.fireEvent("click", this, e);
175 // Do not honor delay or interval if acceleration wanted.
176 if (this.accelerate) {
180 // Re-wrap the event object in a non-shared object, so it doesn't lose its context if
181 // the global shared EventObject gets a new Event put into it before the timer fires.
182 e = new Ext.EventObjectImpl(e);
184 this.timer = Ext.defer(this.click, this.delay || this.interval, this, [e]);
189 this.fireEvent("click", this, e);
190 this.timer = Ext.defer(this.click, this.accelerate ?
191 this.easeOutExpo(Ext.Date.getElapsed(this.mousedownTime),
195 this.interval, this, [e]);
198 easeOutExpo : function (t, b, c, d) {
199 return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
203 handleMouseOut : function(){
204 clearTimeout(this.timer);
206 this.el.removeCls(this.pressedCls);
208 this.el.on("mouseover", this.handleMouseReturn, this);
212 handleMouseReturn : function(){
213 this.el.un("mouseover", this.handleMouseReturn, this);
215 this.el.addCls(this.pressedCls);
221 handleMouseUp : function(e){
222 clearTimeout(this.timer);
223 this.el.un("mouseover", this.handleMouseReturn, this);
224 this.el.un("mouseout", this.handleMouseOut, this);
225 Ext.getDoc().un("mouseup", this.handleMouseUp, this);
227 this.el.removeCls(this.pressedCls);
229 this.fireEvent("mouseup", this, e);
232 </pre></pre></body></html>