4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-util-ClickRepeater-method-constructor'><span id='Ext-util-ClickRepeater'>/**
19 </span></span> * @class Ext.util.ClickRepeater
20 * @extends Ext.util.Observable
22 * A wrapper class which can be applied to any element. Fires a "click" event while the
23 * mouse is pressed. The interval between firings may be specified in the config but
24 * defaults to 20 milliseconds.
26 * Optionally, a CSS class may be applied to the element during the time it is pressed.
29 * @param {Mixed} el The element to listen on
30 * @param {Object} config
33 Ext.define('Ext.util.ClickRepeater', {
34 extend: 'Ext.util.Observable',
36 constructor : function(el, config){
37 this.el = Ext.get(el);
38 this.el.unselectable();
40 Ext.apply(this, config);
43 <span id='Ext-util-ClickRepeater-event-mousedown'> /**
44 </span> * @event mousedown
45 * Fires when the mouse button is depressed.
46 * @param {Ext.util.ClickRepeater} this
47 * @param {Ext.EventObject} e
49 "mousedown",
50 <span id='Ext-util-ClickRepeater-event-click'> /**
51 </span> * @event click
52 * Fires on a specified interval during the time the element is pressed.
53 * @param {Ext.util.ClickRepeater} this
54 * @param {Ext.EventObject} e
57 <span id='Ext-util-ClickRepeater-event-mouseup'> /**
58 </span> * @event mouseup
59 * Fires when the mouse key is released.
60 * @param {Ext.util.ClickRepeater} this
61 * @param {Ext.EventObject} e
71 // allow inline handler
73 this.on("click", this.handler, this.scope || this);
79 <span id='Ext-util-ClickRepeater-cfg-el'> /**
80 </span> * @cfg {Mixed} el The element to act as a button.
83 <span id='Ext-util-ClickRepeater-cfg-pressedCls'> /**
84 </span> * @cfg {String} pressedCls A CSS class name to be applied to the element while pressed.
87 <span id='Ext-util-ClickRepeater-cfg-accelerate'> /**
88 </span> * @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
89 * "interval" and "delay" are ignored.
92 <span id='Ext-util-ClickRepeater-cfg-interval'> /**
93 </span> * @cfg {Number} interval The interval between firings of the "click" event. Default 20 ms.
97 <span id='Ext-util-ClickRepeater-cfg-delay'> /**
98 </span> * @cfg {Number} delay The initial delay before the repeating event begins firing.
99 * Similar to an autorepeat key delay.
103 <span id='Ext-util-ClickRepeater-cfg-preventDefault'> /**
104 </span> * @cfg {Boolean} preventDefault True to prevent the default click event
106 preventDefault : true,
107 <span id='Ext-util-ClickRepeater-cfg-stopDefault'> /**
108 </span> * @cfg {Boolean} stopDefault True to stop the default click event
114 <span id='Ext-util-ClickRepeater-method-enable'> /**
115 </span> * Enables the repeater and allows events to fire.
119 this.el.on('mousedown', this.handleMouseDown, this);
121 this.el.on('dblclick', this.handleDblClick, this);
123 if(this.preventDefault || this.stopDefault){
124 this.el.on('click', this.eventOptions, this);
127 this.disabled = false;
130 <span id='Ext-util-ClickRepeater-method-disable'> /**
131 </span> * Disables the repeater and stops events from firing.
133 disable: function(/* private */ force){
134 if(force || !this.disabled){
135 clearTimeout(this.timer);
137 this.el.removeCls(this.pressedCls);
139 Ext.getDoc().un('mouseup', this.handleMouseUp, this);
140 this.el.removeAllListeners();
142 this.disabled = true;
145 <span id='Ext-util-ClickRepeater-method-setDisabled'> /**
146 </span> * Convenience function for setting disabled/enabled by boolean.
147 * @param {Boolean} disabled
149 setDisabled: function(disabled){
150 this[disabled ? 'disable' : 'enable']();
153 eventOptions: function(e){
154 if(this.preventDefault){
157 if(this.stopDefault){
163 destroy : function() {
165 Ext.destroy(this.el);
166 this.clearListeners();
169 handleDblClick : function(e){
170 clearTimeout(this.timer);
173 this.fireEvent("mousedown", this, e);
174 this.fireEvent("click", this, e);
178 handleMouseDown : function(e){
179 clearTimeout(this.timer);
182 this.el.addCls(this.pressedCls);
184 this.mousedownTime = new Date();
186 Ext.getDoc().on("mouseup", this.handleMouseUp, this);
187 this.el.on("mouseout", this.handleMouseOut, this);
189 this.fireEvent("mousedown", this, e);
190 this.fireEvent("click", this, e);
192 // Do not honor delay or interval if acceleration wanted.
193 if (this.accelerate) {
197 // Re-wrap the event object in a non-shared object, so it doesn't lose its context if
198 // the global shared EventObject gets a new Event put into it before the timer fires.
199 e = new Ext.EventObjectImpl(e);
201 this.timer = Ext.defer(this.click, this.delay || this.interval, this, [e]);
206 this.fireEvent("click", this, e);
207 this.timer = Ext.defer(this.click, this.accelerate ?
208 this.easeOutExpo(Ext.Date.getElapsed(this.mousedownTime),
212 this.interval, this, [e]);
215 easeOutExpo : function (t, b, c, d) {
216 return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
220 handleMouseOut : function(){
221 clearTimeout(this.timer);
223 this.el.removeCls(this.pressedCls);
225 this.el.on("mouseover", this.handleMouseReturn, this);
229 handleMouseReturn : function(){
230 this.el.un("mouseover", this.handleMouseReturn, this);
232 this.el.addCls(this.pressedCls);
238 handleMouseUp : function(e){
239 clearTimeout(this.timer);
240 this.el.un("mouseover", this.handleMouseReturn, this);
241 this.el.un("mouseout", this.handleMouseOut, this);
242 Ext.getDoc().un("mouseup", this.handleMouseUp, this);
244 this.el.removeCls(this.pressedCls);
246 this.fireEvent("mouseup", this, e);