source: trunk/web/addons/job_monarch/lib/extjs/source/util/ClickRepeater.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 4.7 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9/**
10 @class Ext.util.ClickRepeater
11 @extends Ext.util.Observable
12
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.
16
17 Optionally, a CSS class may be applied to the element during the time it is pressed.
18
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
28
29 @history
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
33
34 @constructor
35 @param {Mixed} el The element to listen on
36 @param {Object} config
37 */
38Ext.util.ClickRepeater = function(el, config)
39{
40    this.el = Ext.get(el);
41    this.el.unselectable();
42
43    Ext.apply(this, config);
44
45    this.addEvents(
46    /**
47     * @event mousedown
48     * Fires when the mouse button is depressed.
49     * @param {Ext.util.ClickRepeater} this
50     */
51        "mousedown",
52    /**
53     * @event click
54     * Fires on a specified interval during the time the element is pressed.
55     * @param {Ext.util.ClickRepeater} this
56     */
57        "click",
58    /**
59     * @event mouseup
60     * Fires when the mouse key is released.
61     * @param {Ext.util.ClickRepeater} this
62     */
63        "mouseup"
64    );
65
66    this.el.on("mousedown", this.handleMouseDown, this);
67    if(this.preventDefault || this.stopDefault){
68        this.el.on("click", function(e){
69            if(this.preventDefault){
70                e.preventDefault();
71            }
72            if(this.stopDefault){
73                e.stopEvent();
74            }
75        }, this);
76    }
77
78    // allow inline handler
79    if(this.handler){
80        this.on("click", this.handler,  this.scope || this);
81    }
82
83    Ext.util.ClickRepeater.superclass.constructor.call(this);
84};
85
86Ext.extend(Ext.util.ClickRepeater, Ext.util.Observable, {
87    interval : 20,
88    delay: 250,
89    preventDefault : true,
90    stopDefault : false,
91    timer : 0,
92
93    // private
94    destroy : function() {
95        Ext.destroy(this.el);
96        this.purgeListeners();
97    },
98   
99    // private
100    handleMouseDown : function(){
101        clearTimeout(this.timer);
102        this.el.blur();
103        if(this.pressClass){
104            this.el.addClass(this.pressClass);
105        }
106        this.mousedownTime = new Date();
107
108        Ext.getDoc().on("mouseup", this.handleMouseUp, this);
109        this.el.on("mouseout", this.handleMouseOut, this);
110
111        this.fireEvent("mousedown", this);
112        this.fireEvent("click", this);
113
114//      Do not honor delay or interval if acceleration wanted.
115        if (this.accelerate) {
116            this.delay = 400;
117            }
118        this.timer = this.click.defer(this.delay || this.interval, this);
119    },
120
121    // private
122    click : function(){
123        this.fireEvent("click", this);
124        this.timer = this.click.defer(this.accelerate ?
125            this.easeOutExpo(this.mousedownTime.getElapsed(),
126                400,
127                -390,
128                12000) :
129            this.interval, this);
130    },
131
132    easeOutExpo : function (t, b, c, d) {
133        return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
134    },
135
136    // private
137    handleMouseOut : function(){
138        clearTimeout(this.timer);
139        if(this.pressClass){
140            this.el.removeClass(this.pressClass);
141        }
142        this.el.on("mouseover", this.handleMouseReturn, this);
143    },
144
145    // private
146    handleMouseReturn : function(){
147        this.el.un("mouseover", this.handleMouseReturn, this);
148        if(this.pressClass){
149            this.el.addClass(this.pressClass);
150        }
151        this.click();
152    },
153
154    // private
155    handleMouseUp : function(){
156        clearTimeout(this.timer);
157        this.el.un("mouseover", this.handleMouseReturn, this);
158        this.el.un("mouseout", this.handleMouseOut, this);
159        Ext.getDoc().un("mouseup", this.handleMouseUp, this);
160        this.el.removeClass(this.pressClass);
161        this.fireEvent("mouseup", this);
162    }
163});
Note: See TracBrowser for help on using the repository browser.