diff options
author | Andrew Dolgov <[email protected]> | 2011-11-08 20:40:44 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2011-11-08 20:40:44 +0400 |
commit | 81bea17aefb26859f825b9293c7c99192874806e (patch) | |
tree | fb244408ca271affa2899adb634788802c9a89d8 /lib/dijit/_base/typematic.js | |
parent | 870a70e109ac9e80a88047044530de53d0404ec7 (diff) |
upgrade Dojo to 1.6.1
Diffstat (limited to 'lib/dijit/_base/typematic.js')
-rw-r--r-- | lib/dijit/_base/typematic.js | 262 |
1 files changed, 183 insertions, 79 deletions
diff --git a/lib/dijit/_base/typematic.js b/lib/dijit/_base/typematic.js index 460e9db1a..f424b71d5 100644 --- a/lib/dijit/_base/typematic.js +++ b/lib/dijit/_base/typematic.js @@ -1,87 +1,191 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ -if(!dojo._hasResource["dijit._base.typematic"]){ -dojo._hasResource["dijit._base.typematic"]=true; +if(!dojo._hasResource["dijit._base.typematic"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dijit._base.typematic"] = true; dojo.provide("dijit._base.typematic"); -dijit.typematic={_fireEventAndReload:function(){ -this._timer=null; -this._callback(++this._count,this._node,this._evt); -this._currentTimeout=Math.max(this._currentTimeout<0?this._initialDelay:(this._subsequentDelay>1?this._subsequentDelay:Math.round(this._currentTimeout*this._subsequentDelay)),this._minDelay); -this._timer=setTimeout(dojo.hitch(this,"_fireEventAndReload"),this._currentTimeout); -},trigger:function(_1,_2,_3,_4,_5,_6,_7,_8){ -if(_5!=this._obj){ -this.stop(); -this._initialDelay=_7||500; -this._subsequentDelay=_6||0.9; -this._minDelay=_8||10; -this._obj=_5; -this._evt=_1; -this._node=_3; -this._currentTimeout=-1; -this._count=-1; -this._callback=dojo.hitch(_2,_4); -this._fireEventAndReload(); -this._evt=dojo.mixin({faux:true},_1); -} -},stop:function(){ -if(this._timer){ -clearTimeout(this._timer); -this._timer=null; -} -if(this._obj){ -this._callback(-1,this._node,this._evt); -this._obj=null; -} -},addKeyListener:function(_9,_a,_b,_c,_d,_e,_f){ -if(_a.keyCode){ -_a.charOrCode=_a.keyCode; -dojo.deprecated("keyCode attribute parameter for dijit.typematic.addKeyListener is deprecated. Use charOrCode instead.","","2.0"); -}else{ -if(_a.charCode){ -_a.charOrCode=String.fromCharCode(_a.charCode); -dojo.deprecated("charCode attribute parameter for dijit.typematic.addKeyListener is deprecated. Use charOrCode instead.","","2.0"); -} -} -return [dojo.connect(_9,"onkeypress",this,function(evt){ -if(evt.charOrCode==_a.charOrCode&&(_a.ctrlKey===undefined||_a.ctrlKey==evt.ctrlKey)&&(_a.altKey===undefined||_a.altKey==evt.altKey)&&(_a.metaKey===undefined||_a.metaKey==(evt.metaKey||false))&&(_a.shiftKey===undefined||_a.shiftKey==evt.shiftKey)){ -dojo.stopEvent(evt); -dijit.typematic.trigger(evt,_b,_9,_c,_a,_d,_e,_f); -}else{ -if(dijit.typematic._obj==_a){ -dijit.typematic.stop(); -} -} -}),dojo.connect(_9,"onkeyup",this,function(evt){ -if(dijit.typematic._obj==_a){ -dijit.typematic.stop(); -} -})]; -},addMouseListener:function(_10,_11,_12,_13,_14,_15){ -var dc=dojo.connect; -return [dc(_10,"mousedown",this,function(evt){ -dojo.stopEvent(evt); -dijit.typematic.trigger(evt,_11,_10,_12,_10,_13,_14,_15); -}),dc(_10,"mouseup",this,function(evt){ -dojo.stopEvent(evt); -dijit.typematic.stop(); -}),dc(_10,"mouseout",this,function(evt){ -dojo.stopEvent(evt); -dijit.typematic.stop(); -}),dc(_10,"mousemove",this,function(evt){ -evt.preventDefault(); -}),dc(_10,"dblclick",this,function(evt){ -dojo.stopEvent(evt); -if(dojo.isIE){ -dijit.typematic.trigger(evt,_11,_10,_12,_10,_13,_14,_15); -setTimeout(dojo.hitch(this,dijit.typematic.stop),50); -} -})]; -},addListener:function(_16,_17,_18,_19,_1a,_1b,_1c,_1d){ -return this.addKeyListener(_17,_18,_19,_1a,_1b,_1c,_1d).concat(this.addMouseListener(_16,_19,_1a,_1b,_1c,_1d)); -}}; + + +dijit.typematic = { + // summary: + // These functions are used to repetitively call a user specified callback + // method when a specific key or mouse click over a specific DOM node is + // held down for a specific amount of time. + // Only 1 such event is allowed to occur on the browser page at 1 time. + + _fireEventAndReload: function(){ + this._timer = null; + this._callback(++this._count, this._node, this._evt); + + // Schedule next event, timer is at most minDelay (default 10ms) to avoid + // browser overload (particularly avoiding starving DOH robot so it never gets to send a mouseup) + this._currentTimeout = Math.max( + this._currentTimeout < 0 ? this._initialDelay : + (this._subsequentDelay > 1 ? this._subsequentDelay : Math.round(this._currentTimeout * this._subsequentDelay)), + this._minDelay); + this._timer = setTimeout(dojo.hitch(this, "_fireEventAndReload"), this._currentTimeout); + }, + + trigger: function(/*Event*/ evt, /*Object*/ _this, /*DOMNode*/ node, /*Function*/ callback, /*Object*/ obj, /*Number*/ subsequentDelay, /*Number*/ initialDelay, /*Number?*/ minDelay){ + // summary: + // Start a timed, repeating callback sequence. + // If already started, the function call is ignored. + // This method is not normally called by the user but can be + // when the normal listener code is insufficient. + // evt: + // key or mouse event object to pass to the user callback + // _this: + // pointer to the user's widget space. + // node: + // the DOM node object to pass the the callback function + // callback: + // function to call until the sequence is stopped called with 3 parameters: + // count: + // integer representing number of repeated calls (0..n) with -1 indicating the iteration has stopped + // node: + // the DOM node object passed in + // evt: + // key or mouse event object + // obj: + // user space object used to uniquely identify each typematic sequence + // subsequentDelay (optional): + // if > 1, the number of milliseconds until the 3->n events occur + // or else the fractional time multiplier for the next event's delay, default=0.9 + // initialDelay (optional): + // the number of milliseconds until the 2nd event occurs, default=500ms + // minDelay (optional): + // the maximum delay in milliseconds for event to fire, default=10ms + if(obj != this._obj){ + this.stop(); + this._initialDelay = initialDelay || 500; + this._subsequentDelay = subsequentDelay || 0.90; + this._minDelay = minDelay || 10; + this._obj = obj; + this._evt = evt; + this._node = node; + this._currentTimeout = -1; + this._count = -1; + this._callback = dojo.hitch(_this, callback); + this._fireEventAndReload(); + this._evt = dojo.mixin({faux: true}, evt); + } + }, + + stop: function(){ + // summary: + // Stop an ongoing timed, repeating callback sequence. + if(this._timer){ + clearTimeout(this._timer); + this._timer = null; + } + if(this._obj){ + this._callback(-1, this._node, this._evt); + this._obj = null; + } + }, + + addKeyListener: function(/*DOMNode*/ node, /*Object*/ keyObject, /*Object*/ _this, /*Function*/ callback, /*Number*/ subsequentDelay, /*Number*/ initialDelay, /*Number?*/ minDelay){ + // summary: + // Start listening for a specific typematic key. + // See also the trigger method for other parameters. + // keyObject: + // an object defining the key to listen for: + // charOrCode: + // the printable character (string) or keyCode (number) to listen for. + // keyCode: + // (deprecated - use charOrCode) the keyCode (number) to listen for (implies charCode = 0). + // charCode: + // (deprecated - use charOrCode) the charCode (number) to listen for. + // ctrlKey: + // desired ctrl key state to initiate the callback sequence: + // - pressed (true) + // - released (false) + // - either (unspecified) + // altKey: + // same as ctrlKey but for the alt key + // shiftKey: + // same as ctrlKey but for the shift key + // returns: + // an array of dojo.connect handles + if(keyObject.keyCode){ + keyObject.charOrCode = keyObject.keyCode; + dojo.deprecated("keyCode attribute parameter for dijit.typematic.addKeyListener is deprecated. Use charOrCode instead.", "", "2.0"); + }else if(keyObject.charCode){ + keyObject.charOrCode = String.fromCharCode(keyObject.charCode); + dojo.deprecated("charCode attribute parameter for dijit.typematic.addKeyListener is deprecated. Use charOrCode instead.", "", "2.0"); + } + return [ + dojo.connect(node, "onkeypress", this, function(evt){ + if(evt.charOrCode == keyObject.charOrCode && + (keyObject.ctrlKey === undefined || keyObject.ctrlKey == evt.ctrlKey) && + (keyObject.altKey === undefined || keyObject.altKey == evt.altKey) && + (keyObject.metaKey === undefined || keyObject.metaKey == (evt.metaKey || false)) && // IE doesn't even set metaKey + (keyObject.shiftKey === undefined || keyObject.shiftKey == evt.shiftKey)){ + dojo.stopEvent(evt); + dijit.typematic.trigger(evt, _this, node, callback, keyObject, subsequentDelay, initialDelay, minDelay); + }else if(dijit.typematic._obj == keyObject){ + dijit.typematic.stop(); + } + }), + dojo.connect(node, "onkeyup", this, function(evt){ + if(dijit.typematic._obj == keyObject){ + dijit.typematic.stop(); + } + }) + ]; + }, + + addMouseListener: function(/*DOMNode*/ node, /*Object*/ _this, /*Function*/ callback, /*Number*/ subsequentDelay, /*Number*/ initialDelay, /*Number?*/ minDelay){ + // summary: + // Start listening for a typematic mouse click. + // See the trigger method for other parameters. + // returns: + // an array of dojo.connect handles + var dc = dojo.connect; + return [ + dc(node, "mousedown", this, function(evt){ + dojo.stopEvent(evt); + dijit.typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay, minDelay); + }), + dc(node, "mouseup", this, function(evt){ + dojo.stopEvent(evt); + dijit.typematic.stop(); + }), + dc(node, "mouseout", this, function(evt){ + dojo.stopEvent(evt); + dijit.typematic.stop(); + }), + dc(node, "mousemove", this, function(evt){ + evt.preventDefault(); + }), + dc(node, "dblclick", this, function(evt){ + dojo.stopEvent(evt); + if(dojo.isIE){ + dijit.typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay, minDelay); + setTimeout(dojo.hitch(this, dijit.typematic.stop), 50); + } + }) + ]; + }, + + addListener: function(/*Node*/ mouseNode, /*Node*/ keyNode, /*Object*/ keyObject, /*Object*/ _this, /*Function*/ callback, /*Number*/ subsequentDelay, /*Number*/ initialDelay, /*Number?*/ minDelay){ + // summary: + // Start listening for a specific typematic key and mouseclick. + // This is a thin wrapper to addKeyListener and addMouseListener. + // See the addMouseListener and addKeyListener methods for other parameters. + // mouseNode: + // the DOM node object to listen on for mouse events. + // keyNode: + // the DOM node object to listen on for key events. + // returns: + // an array of dojo.connect handles + return this.addKeyListener(keyNode, keyObject, _this, callback, subsequentDelay, initialDelay, minDelay).concat( + this.addMouseListener(mouseNode, _this, callback, subsequentDelay, initialDelay, minDelay)); + } +}; + } |