3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.util.ClickRepeater"></div>/**
10 @class Ext.util.ClickRepeater
11 @extends Ext.util.Observable
13 A wrapper class which can be applied to any element. Fires a "click" event while the
14 mouse is pressed. The interval between firings may be specified in the config but
15 defaults to 20 milliseconds.
17 Optionally, a CSS class may be applied to the element during the time it is pressed.
19 @cfg {Mixed} el The element to act as a button.
20 @cfg {Number} delay The initial delay before the repeating event begins firing.
21 Similar to an autorepeat key delay.
22 @cfg {Number} interval The interval between firings of the "click" event. Default 20 ms.
23 @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
24 @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
25 "interval" and "delay" are ignored.
26 @cfg {Boolean} preventDefault True to prevent the default click event
27 @cfg {Boolean} stopDefault True to stop the default click event
30 2007-02-02 jvs Original code contributed by Nige "Animal" White
31 2007-02-02 jvs Renamed to ClickRepeater
32 2007-02-03 jvs Modifications for FF Mac and Safari
35 @param {Mixed} el The element to listen on
36 @param {Object} config
38 Ext.util.ClickRepeater = function(el, config)
40 this.el = Ext.get(el);
41 this.el.unselectable();
43 Ext.apply(this, config);
48 * Fires when the mouse button is depressed.
49 * @param {Ext.util.ClickRepeater} this
54 * Fires on a specified interval during the time the element is pressed.
55 * @param {Ext.util.ClickRepeater} this
60 * Fires when the mouse key is released.
61 * @param {Ext.util.ClickRepeater} this
71 // allow inline handler
73 this.on("click", this.handler, this.scope || this);
76 Ext.util.ClickRepeater.superclass.constructor.call(this);
79 Ext.extend(Ext.util.ClickRepeater, Ext.util.Observable, {
82 preventDefault : true,
87 * Enables the repeater and allows events to fire.
91 this.el.on('mousedown', this.handleMouseDown, this);
92 if(this.preventDefault || this.stopDefault){
93 this.el.on('click', this.eventOptions, this);
96 this.disabled = false;
100 * Disables the repeater and stops events from firing.
102 disable: function(/* private */ force){
103 if(force || !this.disabled){
104 clearTimeout(this.timer);
106 this.el.removeClass(this.pressClass);
108 Ext.getDoc().un('mouseup', this.handleMouseUp, this);
109 this.el.removeAllListeners();
111 this.disabled = true;
115 * Convenience function for setting disabled/enabled by boolean.
116 * @param {Boolean} disabled
118 setDisabled: function(disabled){
119 this[disabled ? 'disable' : 'enable']();
122 eventOptions: function(e){
123 if(this.preventDefault){
126 if(this.stopDefault){
132 destroy : function() {
134 Ext.destroy(this.el);
135 this.purgeListeners();
139 handleMouseDown : function(){
140 clearTimeout(this.timer);
143 this.el.addClass(this.pressClass);
145 this.mousedownTime = new Date();
147 Ext.getDoc().on("mouseup", this.handleMouseUp, this);
148 this.el.on("mouseout", this.handleMouseOut, this);
150 this.fireEvent("mousedown", this);
151 this.fireEvent("click", this);
153 // Do not honor delay or interval if acceleration wanted.
154 if (this.accelerate) {
157 this.timer = this.click.defer(this.delay || this.interval, this);
162 this.fireEvent("click", this);
163 this.timer = this.click.defer(this.accelerate ?
164 this.easeOutExpo(this.mousedownTime.getElapsed(),
168 this.interval, this);
171 easeOutExpo : function (t, b, c, d) {
172 return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
176 handleMouseOut : function(){
177 clearTimeout(this.timer);
179 this.el.removeClass(this.pressClass);
181 this.el.on("mouseover", this.handleMouseReturn, this);
185 handleMouseReturn : function(){
186 this.el.un("mouseover", this.handleMouseReturn, this);
188 this.el.addClass(this.pressClass);
194 handleMouseUp : function(){
195 clearTimeout(this.timer);
196 this.el.un("mouseover", this.handleMouseReturn, this);
197 this.el.un("mouseout", this.handleMouseOut, this);
198 Ext.getDoc().un("mouseup", this.handleMouseUp, this);
199 this.el.removeClass(this.pressClass);
200 this.fireEvent("mouseup", this);