4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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'>/**
19 </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 Ext.define('Ext.util.ClickRepeater', {
30 extend: 'Ext.util.Observable',
32 <span id='Ext-util-ClickRepeater-method-constructor'> /**
33 </span> * Creates new ClickRepeater.
34 * @param {String/HTMLElement/Ext.Element} el The element or its ID to listen on
35 * @param {Object} config (optional) Config object.
37 constructor : function(el, config){
38 this.el = Ext.get(el);
39 this.el.unselectable();
41 Ext.apply(this, config);
44 <span id='Ext-util-ClickRepeater-event-mousedown'> /**
45 </span> * @event mousedown
46 * Fires when the mouse button is depressed.
47 * @param {Ext.util.ClickRepeater} this
48 * @param {Ext.EventObject} e
50 "mousedown",
51 <span id='Ext-util-ClickRepeater-event-click'> /**
52 </span> * @event click
53 * Fires on a specified interval during the time the element is pressed.
54 * @param {Ext.util.ClickRepeater} this
55 * @param {Ext.EventObject} e
58 <span id='Ext-util-ClickRepeater-event-mouseup'> /**
59 </span> * @event mouseup
60 * Fires when the mouse key is released.
61 * @param {Ext.util.ClickRepeater} this
62 * @param {Ext.EventObject} e
72 // allow inline handler
74 this.on("click", this.handler, this.scope || this);
80 <span id='Ext-util-ClickRepeater-cfg-el'> /**
81 </span> * @cfg {String/HTMLElement/Ext.Element} el The element to act as a button.
84 <span id='Ext-util-ClickRepeater-cfg-pressedCls'> /**
85 </span> * @cfg {String} pressedCls A CSS class name to be applied to the element while pressed.
88 <span id='Ext-util-ClickRepeater-cfg-accelerate'> /**
89 </span> * @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
90 * "interval" and "delay" are ignored.
93 <span id='Ext-util-ClickRepeater-cfg-interval'> /**
94 </span> * @cfg {Number} interval The interval between firings of the "click" event. Default 20 ms.
98 <span id='Ext-util-ClickRepeater-cfg-delay'> /**
99 </span> * @cfg {Number} delay The initial delay before the repeating event begins firing.
100 * Similar to an autorepeat key delay.
104 <span id='Ext-util-ClickRepeater-cfg-preventDefault'> /**
105 </span> * @cfg {Boolean} preventDefault True to prevent the default click event
107 preventDefault : true,
108 <span id='Ext-util-ClickRepeater-cfg-stopDefault'> /**
109 </span> * @cfg {Boolean} stopDefault True to stop the default click event
115 <span id='Ext-util-ClickRepeater-method-enable'> /**
116 </span> * Enables the repeater and allows events to fire.
120 this.el.on('mousedown', this.handleMouseDown, this);
122 this.el.on('dblclick', this.handleDblClick, this);
124 if(this.preventDefault || this.stopDefault){
125 this.el.on('click', this.eventOptions, this);
128 this.disabled = false;
131 <span id='Ext-util-ClickRepeater-method-disable'> /**
132 </span> * Disables the repeater and stops events from firing.
134 disable: function(/* private */ force){
135 if(force || !this.disabled){
136 clearTimeout(this.timer);
138 this.el.removeCls(this.pressedCls);
140 Ext.getDoc().un('mouseup', this.handleMouseUp, this);
141 this.el.removeAllListeners();
143 this.disabled = true;
146 <span id='Ext-util-ClickRepeater-method-setDisabled'> /**
147 </span> * Convenience function for setting disabled/enabled by boolean.
148 * @param {Boolean} disabled
150 setDisabled: function(disabled){
151 this[disabled ? 'disable' : 'enable']();
154 eventOptions: function(e){
155 if(this.preventDefault){
158 if(this.stopDefault){
164 destroy : function() {
166 Ext.destroy(this.el);
167 this.clearListeners();
170 handleDblClick : function(e){
171 clearTimeout(this.timer);
174 this.fireEvent("mousedown", this, e);
175 this.fireEvent("click", this, e);
179 handleMouseDown : function(e){
180 clearTimeout(this.timer);
183 this.el.addCls(this.pressedCls);
185 this.mousedownTime = new Date();
187 Ext.getDoc().on("mouseup", this.handleMouseUp, this);
188 this.el.on("mouseout", this.handleMouseOut, this);
190 this.fireEvent("mousedown", this, e);
191 this.fireEvent("click", this, e);
193 // Do not honor delay or interval if acceleration wanted.
194 if (this.accelerate) {
198 // Re-wrap the event object in a non-shared object, so it doesn't lose its context if
199 // the global shared EventObject gets a new Event put into it before the timer fires.
200 e = new Ext.EventObjectImpl(e);
202 this.timer = Ext.defer(this.click, this.delay || this.interval, this, [e]);
207 this.fireEvent("click", this, e);
208 this.timer = Ext.defer(this.click, this.accelerate ?
209 this.easeOutExpo(Ext.Date.getElapsed(this.mousedownTime),
213 this.interval, this, [e]);
216 easeOutExpo : function (t, b, c, d) {
217 return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
221 handleMouseOut : function(){
222 clearTimeout(this.timer);
224 this.el.removeCls(this.pressedCls);
226 this.el.on("mouseover", this.handleMouseReturn, this);
230 handleMouseReturn : function(){
231 this.el.un("mouseover", this.handleMouseReturn, this);
233 this.el.addCls(this.pressedCls);
239 handleMouseUp : function(e){
240 clearTimeout(this.timer);
241 this.el.un("mouseover", this.handleMouseReturn, this);
242 this.el.un("mouseout", this.handleMouseOut, this);
243 Ext.getDoc().un("mouseup", this.handleMouseUp, this);
245 this.el.removeCls(this.pressedCls);
247 this.fireEvent("mouseup", this, e);