]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/_base/typematic.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dijit / _base / typematic.js
1 if(!dojo._hasResource["dijit._base.typematic"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit._base.typematic"] = true;
3 dojo.provide("dijit._base.typematic");
4
5 dijit.typematic = {
6         // summary:
7         //      These functions are used to repetitively call a user specified callback
8         //      method when a specific key or mouse click over a specific DOM node is
9         //      held down for a specific amount of time.
10         //      Only 1 such event is allowed to occur on the browser page at 1 time.
11
12         _fireEventAndReload: function(){
13                 this._timer = null;
14                 this._callback(++this._count, this._node, this._evt);
15                 this._currentTimeout = (this._currentTimeout < 0) ? this._initialDelay : ((this._subsequentDelay > 1) ? this._subsequentDelay : Math.round(this._currentTimeout * this._subsequentDelay));
16                 this._timer = setTimeout(dojo.hitch(this, "_fireEventAndReload"), this._currentTimeout);
17         },
18
19         trigger: function(/*Event*/ evt, /* Object */ _this, /*DOMNode*/ node, /* Function */ callback, /* Object */ obj, /* Number */ subsequentDelay, /* Number */ initialDelay){
20                 // summary:
21                 //      Start a timed, repeating callback sequence.
22                 //      If already started, the function call is ignored.
23                 //      This method is not normally called by the user but can be
24                 //      when the normal listener code is insufficient.
25                 //      Parameters:
26                 //      evt: key or mouse event object to pass to the user callback
27                 //      _this: pointer to the user's widget space.
28                 //      node: the DOM node object to pass the the callback function
29                 //      callback: function to call until the sequence is stopped called with 3 parameters:
30                 //              count: integer representing number of repeated calls (0..n) with -1 indicating the iteration has stopped
31                 //              node: the DOM node object passed in
32                 //              evt: key or mouse event object
33                 //      obj: user space object used to uniquely identify each typematic sequence
34                 //      subsequentDelay: if > 1, the number of milliseconds until the 3->n events occur
35                 //              or else the fractional time multiplier for the next event's delay, default=0.9
36                 //      initialDelay: the number of milliseconds until the 2nd event occurs, default=500ms
37                 if(obj != this._obj){
38                         this.stop();
39                         this._initialDelay = initialDelay || 500;
40                         this._subsequentDelay = subsequentDelay || 0.90;
41                         this._obj = obj;
42                         this._evt = evt;
43                         this._node = node;
44                         this._currentTimeout = -1;
45                         this._count = -1;
46                         this._callback = dojo.hitch(_this, callback);
47                         this._fireEventAndReload();
48                 }
49         },
50
51         stop: function(){
52                 // summary:
53                 //        Stop an ongoing timed, repeating callback sequence.
54                 if(this._timer){
55                         clearTimeout(this._timer);
56                         this._timer = null;
57                 }
58                 if(this._obj){
59                         this._callback(-1, this._node, this._evt);
60                         this._obj = null;
61                 }
62         },
63
64         addKeyListener: function(/*DOMNode*/ node, /*Object*/ keyObject, /*Object*/ _this, /*Function*/ callback, /*Number*/ subsequentDelay, /*Number*/ initialDelay){
65                 // summary: Start listening for a specific typematic key.
66                 //      keyObject: an object defining the key to listen for.
67                 //              key: (mandatory) the keyCode (number) or character (string) to listen for.
68                 //              ctrlKey: desired ctrl key state to initiate the calback sequence:
69                 //                      pressed (true)
70                 //                      released (false)
71                 //                      either (unspecified)
72                 //              altKey: same as ctrlKey but for the alt key
73                 //              shiftKey: same as ctrlKey but for the shift key
74                 //      See the trigger method for other parameters.
75                 //      Returns an array of dojo.connect handles
76                 return [
77                         dojo.connect(node, "onkeypress", this, function(evt){
78                                 if(evt.keyCode == keyObject.keyCode && (!keyObject.charCode || keyObject.charCode == evt.charCode) &&
79                                 (keyObject.ctrlKey === undefined || keyObject.ctrlKey == evt.ctrlKey) &&
80                                 (keyObject.altKey === undefined || keyObject.altKey == evt.ctrlKey) &&
81                                 (keyObject.shiftKey === undefined || keyObject.shiftKey == evt.ctrlKey)){
82                                         dojo.stopEvent(evt);
83                                         dijit.typematic.trigger(keyObject, _this, node, callback, keyObject, subsequentDelay, initialDelay);
84                                 }else if(dijit.typematic._obj == keyObject){
85                                         dijit.typematic.stop();
86                                 }
87                         }),
88                         dojo.connect(node, "onkeyup", this, function(evt){
89                                 if(dijit.typematic._obj == keyObject){
90                                         dijit.typematic.stop();
91                                 }
92                         })
93                 ];
94         },
95
96         addMouseListener: function(/*DOMNode*/ node, /*Object*/ _this, /*Function*/ callback, /*Number*/ subsequentDelay, /*Number*/ initialDelay){
97                 // summary: Start listening for a typematic mouse click.
98                 //      See the trigger method for other parameters.
99                 //      Returns an array of dojo.connect handles
100                 var dc = dojo.connect;
101                 return [
102                         dc(node, "mousedown", this, function(evt){
103                                 dojo.stopEvent(evt);
104                                 dijit.typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay);
105                         }),
106                         dc(node, "mouseup", this, function(evt){
107                                 dojo.stopEvent(evt);
108                                 dijit.typematic.stop();
109                         }),
110                         dc(node, "mouseout", this, function(evt){
111                                 dojo.stopEvent(evt);
112                                 dijit.typematic.stop();
113                         }),
114                         dc(node, "mousemove", this, function(evt){
115                                 dojo.stopEvent(evt);
116                         }),
117                         dc(node, "dblclick", this, function(evt){
118                                 dojo.stopEvent(evt);
119                                 if(dojo.isIE){
120                                         dijit.typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay);
121                                         setTimeout(dojo.hitch(this, dijit.typematic.stop), 50);
122                                 }
123                         })
124                 ];
125         },
126
127         addListener: function(/*Node*/ mouseNode, /*Node*/ keyNode, /*Object*/ keyObject, /*Object*/ _this, /*Function*/ callback, /*Number*/ subsequentDelay, /*Number*/ initialDelay){
128                 // summary: Start listening for a specific typematic key and mouseclick.
129                 //      This is a thin wrapper to addKeyListener and addMouseListener.
130                 //      mouseNode: the DOM node object to listen on for mouse events.
131                 //      keyNode: the DOM node object to listen on for key events.
132                 //      See the addMouseListener and addKeyListener methods for other parameters.
133                 //      Returns an array of dojo.connect handles
134                 return this.addKeyListener(keyNode, keyObject, _this, callback, subsequentDelay, initialDelay).concat(
135                         this.addMouseListener(mouseNode, _this, callback, subsequentDelay, initialDelay));
136         }
137 };
138
139 }