3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.util.ClickRepeater"></div>/**
15 @class Ext.util.ClickRepeater
16 @extends Ext.util.Observable
18 A wrapper class which can be applied to any element. Fires a "click" event while the
19 mouse is pressed. The interval between firings may be specified in the config but
20 defaults to 20 milliseconds.
22 Optionally, a CSS class may be applied to the element during the time it is pressed.
24 @cfg {Mixed} el The element to act as a button.
25 @cfg {Number} delay The initial delay before the repeating event begins firing.
26 Similar to an autorepeat key delay.
27 @cfg {Number} interval The interval between firings of the "click" event. Default 20 ms.
28 @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
29 @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
30 "interval" and "delay" are ignored.
31 @cfg {Boolean} preventDefault True to prevent the default click event
32 @cfg {Boolean} stopDefault True to stop the default click event
35 2007-02-02 jvs Original code contributed by Nige "Animal" White
36 2007-02-02 jvs Renamed to ClickRepeater
37 2007-02-03 jvs Modifications for FF Mac and Safari
40 @param {Mixed} el The element to listen on
41 @param {Object} config
43 Ext.util.ClickRepeater = function(el, config)
45 this.el = Ext.get(el);
46 this.el.unselectable();
48 Ext.apply(this, config);
53 * Fires when the mouse button is depressed.
54 * @param {Ext.util.ClickRepeater} this
59 * Fires on a specified interval during the time the element is pressed.
60 * @param {Ext.util.ClickRepeater} this
65 * Fires when the mouse key is released.
66 * @param {Ext.util.ClickRepeater} this
76 // allow inline handler
78 this.on("click", this.handler, this.scope || this);
81 Ext.util.ClickRepeater.superclass.constructor.call(this);
84 Ext.extend(Ext.util.ClickRepeater, Ext.util.Observable, {
87 preventDefault : true,
92 * Enables the repeater and allows events to fire.
96 this.el.on('mousedown', this.handleMouseDown, this);
97 if(this.preventDefault || this.stopDefault){
98 this.el.on('click', this.eventOptions, this);
101 this.disabled = false;
105 * Disables the repeater and stops events from firing.
107 disable: function(/* private */ force){
108 if(force || !this.disabled){
109 clearTimeout(this.timer);
111 this.el.removeClass(this.pressClass);
113 Ext.getDoc().un('mouseup', this.handleMouseUp, this);
114 this.el.removeAllListeners();
116 this.disabled = true;
120 * Convenience function for setting disabled/enabled by boolean.
121 * @param {Boolean} disabled
123 setDisabled: function(disabled){
124 this[disabled ? 'disable' : 'enable']();
127 eventOptions: function(e){
128 if(this.preventDefault){
131 if(this.stopDefault){
137 destroy : function() {
139 Ext.destroy(this.el);
140 this.purgeListeners();
144 handleMouseDown : function(){
145 clearTimeout(this.timer);
148 this.el.addClass(this.pressClass);
150 this.mousedownTime = new Date();
152 Ext.getDoc().on("mouseup", this.handleMouseUp, this);
153 this.el.on("mouseout", this.handleMouseOut, this);
155 this.fireEvent("mousedown", this);
156 this.fireEvent("click", this);
158 // Do not honor delay or interval if acceleration wanted.
159 if (this.accelerate) {
162 this.timer = this.click.defer(this.delay || this.interval, this);
167 this.fireEvent("click", this);
168 this.timer = this.click.defer(this.accelerate ?
169 this.easeOutExpo(this.mousedownTime.getElapsed(),
173 this.interval, this);
176 easeOutExpo : function (t, b, c, d) {
177 return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
181 handleMouseOut : function(){
182 clearTimeout(this.timer);
184 this.el.removeClass(this.pressClass);
186 this.el.on("mouseover", this.handleMouseReturn, this);
190 handleMouseReturn : function(){
191 this.el.un("mouseover", this.handleMouseReturn, this);
193 this.el.addClass(this.pressClass);
199 handleMouseUp : function(){
200 clearTimeout(this.timer);
201 this.el.un("mouseover", this.handleMouseReturn, this);
202 this.el.un("mouseout", this.handleMouseOut, this);
203 Ext.getDoc().un("mouseup", this.handleMouseUp, this);
204 this.el.removeClass(this.pressClass);
205 this.fireEvent("mouseup", this);