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");
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.
12 _fireEventAndReload: function(){
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);
19 trigger: function(/*Event*/ evt, /* Object */ _this, /*DOMNode*/ node, /* Function */ callback, /* Object */ obj, /* Number */ subsequentDelay, /* Number */ initialDelay){
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.
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
39 this._initialDelay = initialDelay || 500;
40 this._subsequentDelay = subsequentDelay || 0.90;
44 this._currentTimeout = -1;
46 this._callback = dojo.hitch(_this, callback);
47 this._fireEventAndReload();
53 // Stop an ongoing timed, repeating callback sequence.
55 clearTimeout(this._timer);
59 this._callback(-1, this._node, this._evt);
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:
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
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)){
83 dijit.typematic.trigger(keyObject, _this, node, callback, keyObject, subsequentDelay, initialDelay);
84 }else if(dijit.typematic._obj == keyObject){
85 dijit.typematic.stop();
88 dojo.connect(node, "onkeyup", this, function(evt){
89 if(dijit.typematic._obj == keyObject){
90 dijit.typematic.stop();
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;
102 dc(node, "mousedown", this, function(evt){
104 dijit.typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay);
106 dc(node, "mouseup", this, function(evt){
108 dijit.typematic.stop();
110 dc(node, "mouseout", this, function(evt){
112 dijit.typematic.stop();
114 dc(node, "mousemove", this, function(evt){
117 dc(node, "dblclick", this, function(evt){
120 dijit.typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay);
121 setTimeout(dojo.hitch(this, dijit.typematic.stop), 50);
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));