]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/_base/typematic.js
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dijit._base.typematic"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
._hasResource
["dijit._base.typematic"] = true;
10 dojo
.provide("dijit._base.typematic");
15 // These functions are used to repetitively call a user specified callback
16 // method when a specific key or mouse click over a specific DOM node is
17 // held down for a specific amount of time.
18 // Only 1 such event is allowed to occur on the browser page at 1 time.
20 _fireEventAndReload: function(){
22 this._callback(++this._count
, this._node
, this._evt
);
24 // Schedule next event, timer is at most minDelay (default 10ms) to avoid
25 // browser overload (particularly avoiding starving DOH robot so it never gets to send a mouseup)
26 this._currentTimeout
= Math
.max(
27 this._currentTimeout
< 0 ? this._initialDelay
:
28 (this._subsequentDelay
> 1 ? this._subsequentDelay
: Math
.round(this._currentTimeout
* this._subsequentDelay
)),
30 this._timer
= setTimeout(dojo
.hitch(this, "_fireEventAndReload"), this._currentTimeout
);
33 trigger: function(/*Event*/ evt
, /*Object*/ _this
, /*DOMNode*/ node
, /*Function*/ callback
, /*Object*/ obj
, /*Number*/ subsequentDelay
, /*Number*/ initialDelay
, /*Number?*/ minDelay
){
35 // Start a timed, repeating callback sequence.
36 // If already started, the function call is ignored.
37 // This method is not normally called by the user but can be
38 // when the normal listener code is insufficient.
40 // key or mouse event object to pass to the user callback
42 // pointer to the user's widget space.
44 // the DOM node object to pass the the callback function
46 // function to call until the sequence is stopped called with 3 parameters:
48 // integer representing number of repeated calls (0..n) with -1 indicating the iteration has stopped
50 // the DOM node object passed in
52 // key or mouse event object
54 // user space object used to uniquely identify each typematic sequence
55 // subsequentDelay (optional):
56 // if > 1, the number of milliseconds until the 3->n events occur
57 // or else the fractional time multiplier for the next event's delay, default=0.9
58 // initialDelay (optional):
59 // the number of milliseconds until the 2nd event occurs, default=500ms
60 // minDelay (optional):
61 // the maximum delay in milliseconds for event to fire, default=10ms
64 this._initialDelay
= initialDelay
|| 500;
65 this._subsequentDelay
= subsequentDelay
|| 0.90;
66 this._minDelay
= minDelay
|| 10;
70 this._currentTimeout
= -1;
72 this._callback
= dojo
.hitch(_this
, callback
);
73 this._fireEventAndReload();
74 this._evt
= dojo
.mixin({faux
: true}, evt
);
80 // Stop an ongoing timed, repeating callback sequence.
82 clearTimeout(this._timer
);
86 this._callback(-1, this._node
, this._evt
);
91 addKeyListener: function(/*DOMNode*/ node
, /*Object*/ keyObject
, /*Object*/ _this
, /*Function*/ callback
, /*Number*/ subsequentDelay
, /*Number*/ initialDelay
, /*Number?*/ minDelay
){
93 // Start listening for a specific typematic key.
94 // See also the trigger method for other parameters.
96 // an object defining the key to listen for:
98 // the printable character (string) or keyCode (number) to listen for.
100 // (deprecated - use charOrCode) the keyCode (number) to listen for (implies charCode = 0).
102 // (deprecated - use charOrCode) the charCode (number) to listen for.
104 // desired ctrl key state to initiate the callback sequence:
106 // - released (false)
107 // - either (unspecified)
109 // same as ctrlKey but for the alt key
111 // same as ctrlKey but for the shift key
113 // an array of dojo.connect handles
114 if(keyObject
.keyCode
){
115 keyObject
.charOrCode
= keyObject
.keyCode
;
116 dojo
.deprecated("keyCode attribute parameter for dijit.typematic.addKeyListener is deprecated. Use charOrCode instead.", "", "2.0");
117 }else if(keyObject
.charCode
){
118 keyObject
.charOrCode
= String
.fromCharCode(keyObject
.charCode
);
119 dojo
.deprecated("charCode attribute parameter for dijit.typematic.addKeyListener is deprecated. Use charOrCode instead.", "", "2.0");
122 dojo
.connect(node
, "onkeypress", this, function(evt
){
123 if(evt
.charOrCode
== keyObject
.charOrCode
&&
124 (keyObject
.ctrlKey
=== undefined || keyObject
.ctrlKey
== evt
.ctrlKey
) &&
125 (keyObject
.altKey
=== undefined || keyObject
.altKey
== evt
.altKey
) &&
126 (keyObject
.metaKey
=== undefined || keyObject
.metaKey
== (evt
.metaKey
|| false)) && // IE doesn't even set metaKey
127 (keyObject
.shiftKey
=== undefined || keyObject
.shiftKey
== evt
.shiftKey
)){
129 dijit
.typematic
.trigger(evt
, _this
, node
, callback
, keyObject
, subsequentDelay
, initialDelay
, minDelay
);
130 }else if(dijit
.typematic
._obj
== keyObject
){
131 dijit
.typematic
.stop();
134 dojo
.connect(node
, "onkeyup", this, function(evt
){
135 if(dijit
.typematic
._obj
== keyObject
){
136 dijit
.typematic
.stop();
142 addMouseListener: function(/*DOMNode*/ node
, /*Object*/ _this
, /*Function*/ callback
, /*Number*/ subsequentDelay
, /*Number*/ initialDelay
, /*Number?*/ minDelay
){
144 // Start listening for a typematic mouse click.
145 // See the trigger method for other parameters.
147 // an array of dojo.connect handles
148 var dc
= dojo
.connect
;
150 dc(node
, "mousedown", this, function(evt
){
152 dijit
.typematic
.trigger(evt
, _this
, node
, callback
, node
, subsequentDelay
, initialDelay
, minDelay
);
154 dc(node
, "mouseup", this, function(evt
){
156 dijit
.typematic
.stop();
158 dc(node
, "mouseout", this, function(evt
){
160 dijit
.typematic
.stop();
162 dc(node
, "mousemove", this, function(evt
){
163 evt
.preventDefault();
165 dc(node
, "dblclick", this, function(evt
){
168 dijit
.typematic
.trigger(evt
, _this
, node
, callback
, node
, subsequentDelay
, initialDelay
, minDelay
);
169 setTimeout(dojo
.hitch(this, dijit
.typematic
.stop
), 50);
175 addListener: function(/*Node*/ mouseNode
, /*Node*/ keyNode
, /*Object*/ keyObject
, /*Object*/ _this
, /*Function*/ callback
, /*Number*/ subsequentDelay
, /*Number*/ initialDelay
, /*Number?*/ minDelay
){
177 // Start listening for a specific typematic key and mouseclick.
178 // This is a thin wrapper to addKeyListener and addMouseListener.
179 // See the addMouseListener and addKeyListener methods for other parameters.
181 // the DOM node object to listen on for mouse events.
183 // the DOM node object to listen on for key events.
185 // an array of dojo.connect handles
186 return this.addKeyListener(keyNode
, keyObject
, _this
, callback
, subsequentDelay
, initialDelay
, minDelay
).concat(
187 this.addMouseListener(mouseNode
, _this
, callback
, subsequentDelay
, initialDelay
, minDelay
));