3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.util.ClickRepeater"></div>/**
16 @class Ext.util.ClickRepeater
17 @extends Ext.util.Observable
19 A wrapper class which can be applied to any element. Fires a "click" event while the
20 mouse is pressed. The interval between firings may be specified in the config but
21 defaults to 20 milliseconds.
23 Optionally, a CSS class may be applied to the element during the time it is pressed.
25 @cfg {Mixed} el The element to act as a button.
26 @cfg {Number} delay The initial delay before the repeating event begins firing.
27 Similar to an autorepeat key delay.
28 @cfg {Number} interval The interval between firings of the "click" event. Default 20 ms.
29 @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
30 @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
31 "interval" and "delay" are ignored.
32 @cfg {Boolean} preventDefault True to prevent the default click event
33 @cfg {Boolean} stopDefault True to stop the default click event
36 2007-02-02 jvs Original code contributed by Nige "Animal" White
37 2007-02-02 jvs Renamed to ClickRepeater
38 2007-02-03 jvs Modifications for FF Mac and Safari
41 @param {Mixed} el The element to listen on
42 @param {Object} config
44 Ext.util.ClickRepeater = Ext.extend(Ext.util.Observable, {
46 constructor : function(el, config){
47 this.el = Ext.get(el);
48 this.el.unselectable();
50 Ext.apply(this, config);
55 * Fires when the mouse button is depressed.
56 * @param {Ext.util.ClickRepeater} this
57 * @param {Ext.EventObject} e
62 * Fires on a specified interval during the time the element is pressed.
63 * @param {Ext.util.ClickRepeater} this
64 * @param {Ext.EventObject} e
69 * Fires when the mouse key is released.
70 * @param {Ext.util.ClickRepeater} this
71 * @param {Ext.EventObject} e
81 // allow inline handler
83 this.on("click", this.handler, this.scope || this);
86 Ext.util.ClickRepeater.superclass.constructor.call(this);
91 preventDefault : true,
96 * Enables the repeater and allows events to fire.
100 this.el.on('mousedown', this.handleMouseDown, this);
102 this.el.on('dblclick', this.handleDblClick, this);
104 if(this.preventDefault || this.stopDefault){
105 this.el.on('click', this.eventOptions, this);
108 this.disabled = false;
112 * Disables the repeater and stops events from firing.
114 disable: function(/* private */ force){
115 if(force || !this.disabled){
116 clearTimeout(this.timer);
118 this.el.removeClass(this.pressClass);
120 Ext.getDoc().un('mouseup', this.handleMouseUp, this);
121 this.el.removeAllListeners();
123 this.disabled = true;
127 * Convenience function for setting disabled/enabled by boolean.
128 * @param {Boolean} disabled
130 setDisabled: function(disabled){
131 this[disabled ? 'disable' : 'enable']();
134 eventOptions: function(e){
135 if(this.preventDefault){
138 if(this.stopDefault){
144 destroy : function() {
146 Ext.destroy(this.el);
147 this.purgeListeners();
150 handleDblClick : function(e){
151 clearTimeout(this.timer);
154 this.fireEvent("mousedown", this, e);
155 this.fireEvent("click", this, e);
159 handleMouseDown : function(e){
160 clearTimeout(this.timer);
163 this.el.addClass(this.pressClass);
165 this.mousedownTime = new Date();
167 Ext.getDoc().on("mouseup", this.handleMouseUp, this);
168 this.el.on("mouseout", this.handleMouseOut, this);
170 this.fireEvent("mousedown", this, e);
171 this.fireEvent("click", this, e);
173 // Do not honor delay or interval if acceleration wanted.
174 if (this.accelerate) {
177 this.timer = this.click.defer(this.delay || this.interval, this, [e]);
182 this.fireEvent("click", this, e);
183 this.timer = this.click.defer(this.accelerate ?
184 this.easeOutExpo(this.mousedownTime.getElapsed(),
188 this.interval, this, [e]);
191 easeOutExpo : function (t, b, c, d) {
192 return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
196 handleMouseOut : function(){
197 clearTimeout(this.timer);
199 this.el.removeClass(this.pressClass);
201 this.el.on("mouseover", this.handleMouseReturn, this);
205 handleMouseReturn : function(){
206 this.el.un("mouseover", this.handleMouseReturn, this);
208 this.el.addClass(this.pressClass);
214 handleMouseUp : function(e){
215 clearTimeout(this.timer);
216 this.el.un("mouseover", this.handleMouseReturn, this);
217 this.el.un("mouseout", this.handleMouseOut, this);
218 Ext.getDoc().un("mouseup", this.handleMouseUp, this);
219 this.el.removeClass(this.pressClass);
220 this.fireEvent("mouseup", this, e);