| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/connect", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/on", |
| 6 |
"dojo/sniff", |
| 7 |
"./main" |
| 8 |
], function(array, connect, lang, on, has, dijit){ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
var typematic = (dijit.typematic = { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
_fireEventAndReload: function(){ |
| 21 |
this._timer = null; |
| 22 |
this._callback(++this._count, this._node, this._evt); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
this._currentTimeout = Math.max( |
| 27 |
this._currentTimeout < 0 ? this._initialDelay : |
| 28 |
(this._subsequentDelay > 1 ? this._subsequentDelay : Math.round(this._currentTimeout * this._subsequentDelay)), |
| 29 |
this._minDelay); |
| 30 |
this._timer = setTimeout(lang.hitch(this, "_fireEventAndReload"), this._currentTimeout); |
| 31 |
}, |
| 32 |
|
| 33 |
trigger: function( evt, _this, node, callback, obj, subsequentDelay, initialDelay, minDelay){ |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
if(obj != this._obj){ |
| 63 |
this.stop(); |
| 64 |
this._initialDelay = initialDelay || 500; |
| 65 |
this._subsequentDelay = subsequentDelay || 0.90; |
| 66 |
this._minDelay = minDelay || 10; |
| 67 |
this._obj = obj; |
| 68 |
this._node = node; |
| 69 |
this._currentTimeout = -1; |
| 70 |
this._count = -1; |
| 71 |
this._callback = lang.hitch(_this, callback); |
| 72 |
this._evt = { faux: true }; |
| 73 |
for(var attr in evt){ |
| 74 |
if(attr != "layerX" && attr != "layerY"){ |
| 75 |
var v = evt[attr]; |
| 76 |
if(typeof v != "function" && typeof v != "undefined"){ |
| 77 |
this._evt[attr] = v |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
this._fireEventAndReload(); |
| 82 |
} |
| 83 |
}, |
| 84 |
|
| 85 |
stop: function(){ |
| 86 |
|
| 87 |
|
| 88 |
if(this._timer){ |
| 89 |
clearTimeout(this._timer); |
| 90 |
this._timer = null; |
| 91 |
} |
| 92 |
if(this._obj){ |
| 93 |
this._callback(-1, this._node, this._evt); |
| 94 |
this._obj = null; |
| 95 |
} |
| 96 |
}, |
| 97 |
|
| 98 |
addKeyListener: function( node, keyObject, _this, callback, subsequentDelay, initialDelay, minDelay){ |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
var type = "keyCode" in keyObject ? "keydown" : "charCode" in keyObject ? "keypress" : connect._keypress, |
| 120 |
attr = "keyCode" in keyObject ? "keyCode" : "charCode" in keyObject ? "charCode" : "charOrCode"; |
| 121 |
|
| 122 |
var handles = [ |
| 123 |
on(node, type, lang.hitch(this, function(evt){ |
| 124 |
if(evt[attr] == keyObject[attr] && |
| 125 |
(keyObject.ctrlKey === undefined || keyObject.ctrlKey == evt.ctrlKey) && |
| 126 |
(keyObject.altKey === undefined || keyObject.altKey == evt.altKey) && |
| 127 |
(keyObject.metaKey === undefined || keyObject.metaKey == (evt.metaKey || false)) && |
| 128 |
(keyObject.shiftKey === undefined || keyObject.shiftKey == evt.shiftKey)){ |
| 129 |
evt.stopPropagation(); |
| 130 |
evt.preventDefault(); |
| 131 |
typematic.trigger(evt, _this, node, callback, keyObject, subsequentDelay, initialDelay, minDelay); |
| 132 |
}else if(typematic._obj == keyObject){ |
| 133 |
typematic.stop(); |
| 134 |
} |
| 135 |
})), |
| 136 |
on(node, "keyup", lang.hitch(this, function(){ |
| 137 |
if(typematic._obj == keyObject){ |
| 138 |
typematic.stop(); |
| 139 |
} |
| 140 |
})) |
| 141 |
]; |
| 142 |
return { remove: function(){ |
| 143 |
array.forEach(handles, function(h){ |
| 144 |
h.remove(); |
| 145 |
}); |
| 146 |
} }; |
| 147 |
}, |
| 148 |
|
| 149 |
addMouseListener: function( node, _this, callback, subsequentDelay, initialDelay, minDelay){ |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
var handles = [ |
| 156 |
on(node, "mousedown", lang.hitch(this, function(evt){ |
| 157 |
evt.preventDefault(); |
| 158 |
typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay, minDelay); |
| 159 |
})), |
| 160 |
on(node, "mouseup", lang.hitch(this, function(evt){ |
| 161 |
if(this._obj){ |
| 162 |
evt.preventDefault(); |
| 163 |
} |
| 164 |
typematic.stop(); |
| 165 |
})), |
| 166 |
on(node, "mouseout", lang.hitch(this, function(evt){ |
| 167 |
if(this._obj){ |
| 168 |
evt.preventDefault(); |
| 169 |
} |
| 170 |
typematic.stop(); |
| 171 |
})), |
| 172 |
on(node, "dblclick", lang.hitch(this, function(evt){ |
| 173 |
evt.preventDefault(); |
| 174 |
if(has("ie") < 9){ |
| 175 |
typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay, minDelay); |
| 176 |
setTimeout(lang.hitch(this, typematic.stop), 50); |
| 177 |
} |
| 178 |
})) |
| 179 |
]; |
| 180 |
return { remove: function(){ |
| 181 |
array.forEach(handles, function(h){ |
| 182 |
h.remove(); |
| 183 |
}); |
| 184 |
} }; |
| 185 |
}, |
| 186 |
|
| 187 |
addListener: function( mouseNode, keyNode, keyObject, _this, callback, subsequentDelay, initialDelay, minDelay){ |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
var handles = [ |
| 199 |
this.addKeyListener(keyNode, keyObject, _this, callback, subsequentDelay, initialDelay, minDelay), |
| 200 |
this.addMouseListener(mouseNode, _this, callback, subsequentDelay, initialDelay, minDelay) |
| 201 |
]; |
| 202 |
return { remove: function(){ |
| 203 |
array.forEach(handles, function(h){ |
| 204 |
h.remove(); |
| 205 |
}); |
| 206 |
} }; |
| 207 |
} |
| 208 |
}); |
| 209 |
|
| 210 |
return typematic; |
| 211 |
}); |