2 Copyright (c) 2004-2010, 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["dojo._base.event"]){
9 dojo._hasResource["dojo._base.event"]=true;
10 dojo.provide("dojo._base.event");
11 dojo.require("dojo._base.connect");
13 var _1=(dojo._event_listener={add:function(_2,_3,fp){
17 _3=_1._normalizeEventName(_3);
18 fp=_1._fixCallback(_3,fp);
20 if(!dojo.isIE&&(_3=="mouseenter"||_3=="mouseleave")){
22 _3=(_3=="mouseenter")?"mouseover":"mouseout";
24 if(!dojo.isDescendant(e.relatedTarget,_2)){
25 return _5.call(this,e);
29 _2.addEventListener(_3,fp,false);
31 },remove:function(_6,_7,_8){
33 _7=_1._normalizeEventName(_7);
34 if(!dojo.isIE&&(_7=="mouseenter"||_7=="mouseleave")){
35 _7=(_7=="mouseenter")?"mouseover":"mouseout";
37 _6.removeEventListener(_7,_8,false);
39 },_normalizeEventName:function(_9){
40 return _9.slice(0,2)=="on"?_9.slice(2):_9;
41 },_fixCallback:function(_a,fp){
42 return _a!="keypress"?fp:function(e){
43 return fp.call(this,_1._fixEvent(e,this));
45 },_fixEvent:function(_b,_c){
52 },_setKeyChar:function(_d){
53 _d.keyChar=_d.charCode?String.fromCharCode(_d.charCode):"";
54 _d.charOrCode=_d.keyChar||_d.keyCode;
55 },_punctMap:{106:42,111:47,186:59,187:43,188:44,189:45,190:46,191:47,192:96,219:91,220:92,221:93,222:39}});
56 dojo.fixEvent=function(_e,_f){
57 return _1._fixEvent(_e,_f);
59 dojo.stopEvent=function(evt){
61 evt.stopPropagation();
63 var _10=dojo._listener;
64 dojo._connect=function(obj,_11,_12,_13,_14){
65 var _15=obj&&(obj.nodeType||obj.attachEvent||obj.addEventListener);
66 var lid=_15?(_14?2:1):0,l=[dojo._listener,_1,_10][lid];
67 var h=l.add(obj,_11,dojo.hitch(_12,_13));
68 return [obj,_11,h,lid];
70 dojo._disconnect=function(obj,_16,_17,_18){
71 ([dojo._listener,_1,_10][_18]).remove(obj,_16,_17);
73 dojo.keys={BACKSPACE:8,TAB:9,CLEAR:12,ENTER:13,SHIFT:16,CTRL:17,ALT:18,META:dojo.isSafari?91:224,PAUSE:19,CAPS_LOCK:20,ESCAPE:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT_ARROW:37,UP_ARROW:38,RIGHT_ARROW:39,DOWN_ARROW:40,INSERT:45,DELETE:46,HELP:47,LEFT_WINDOW:91,RIGHT_WINDOW:92,SELECT:93,NUMPAD_0:96,NUMPAD_1:97,NUMPAD_2:98,NUMPAD_3:99,NUMPAD_4:100,NUMPAD_5:101,NUMPAD_6:102,NUMPAD_7:103,NUMPAD_8:104,NUMPAD_9:105,NUMPAD_MULTIPLY:106,NUMPAD_PLUS:107,NUMPAD_ENTER:108,NUMPAD_MINUS:109,NUMPAD_PERIOD:110,NUMPAD_DIVIDE:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,F13:124,F14:125,F15:126,NUM_LOCK:144,SCROLL_LOCK:145,copyKey:dojo.isMac&&!dojo.isAIR?(dojo.isSafari?91:224):17};
74 var _19=dojo.isMac?"metaKey":"ctrlKey";
75 dojo.isCopyKey=function(e){
79 dojo.mouseButtons={LEFT:1,MIDDLE:4,RIGHT:2,isButton:function(e,_1a){
83 },isMiddle:function(e){
85 },isRight:function(e){
89 dojo.mouseButtons={LEFT:0,MIDDLE:1,RIGHT:2,isButton:function(e,_1b){
93 },isMiddle:function(e){
95 },isRight:function(e){
100 var _1c=function(e,_1d){
102 return (e.keyCode=_1d);
108 var iel=dojo._listener;
109 var _1e=(dojo._ieListenersName="_"+dojo._scopeName+"_listeners");
110 if(!dojo.config._allow_leaks){
111 _10=iel=dojo._ie_listener={handlers:[],add:function(_1f,_20,_21){
112 _1f=_1f||dojo.global;
115 var d=dojo._getIeDispatcher();
116 d.target=f&&(ieh.push(f)-1);
120 return f[_1e].push(ieh.push(_21)-1);
121 },remove:function(_22,_23,_24){
122 var f=(_22||dojo.global)[_23],l=f&&f[_1e];
128 var ieh=iel.handlers;
130 dojo.mixin(_1,{add:function(_25,_26,fp){
134 _26=_1._normalizeEventName(_26);
135 if(_26=="onkeypress"){
136 var kd=_25.onkeydown;
137 if(!kd||!kd[_1e]||!kd._stealthKeydownHandle){
138 var h=_1.add(_25,"onkeydown",_1._stealthKeyDown);
140 kd._stealthKeydownHandle=h;
141 kd._stealthKeydownRefs=1;
143 kd._stealthKeydownRefs++;
146 return iel.add(_25,_26,_1._fixCallback(fp));
147 },remove:function(_27,_28,_29){
148 _28=_1._normalizeEventName(_28);
149 iel.remove(_27,_28,_29);
150 if(_28=="onkeypress"){
151 var kd=_27.onkeydown;
152 if(--kd._stealthKeydownRefs<=0){
153 iel.remove(_27,"onkeydown",kd._stealthKeydownHandle);
154 delete kd._stealthKeydownHandle;
157 },_normalizeEventName:function(_2a){
158 return _2a.slice(0,2)!="on"?"on"+_2a:_2a;
160 },_fixEvent:function(evt,_2b){
162 var w=_2b&&(_2b.ownerDocument||_2b.document||_2b).parentWindow||window;
168 evt.target=evt.srcElement;
169 evt.currentTarget=(_2b||evt.srcElement);
170 evt.layerX=evt.offsetX;
171 evt.layerY=evt.offsetY;
172 var se=evt.srcElement,doc=(se&&se.ownerDocument)||document;
173 var _2c=((dojo.isIE<6)||(doc["compatMode"]=="BackCompat"))?doc.body:doc.documentElement;
174 var _2d=dojo._getIeDocumentElementOffset();
175 evt.pageX=evt.clientX+dojo._fixIeBiDiScrollLeft(_2c.scrollLeft||0)-_2d.x;
176 evt.pageY=evt.clientY+(_2c.scrollTop||0)-_2d.y;
177 if(evt.type=="mouseover"){
178 evt.relatedTarget=evt.fromElement;
180 if(evt.type=="mouseout"){
181 evt.relatedTarget=evt.toElement;
183 evt.stopPropagation=_1._stopPropagation;
184 evt.preventDefault=_1._preventDefault;
185 return _1._fixKeys(evt);
186 },_fixKeys:function(evt){
189 var c=("charCode" in evt?evt.charCode:evt.keyCode);
207 },_stealthKeyDown:function(evt){
208 var kp=evt.currentTarget.onkeypress;
213 var _2e=k!=13&&k!=32&&k!=27&&(k<48||k>90)&&(k<96||k>111)&&(k<186||k>192)&&(k<219||k>222);
214 if(_2e||evt.ctrlKey){
223 if((!evt.shiftKey)&&(c>=65&&c<=90)){
226 c=_1._punctMap[c]||c;
231 var _2f=_1._synthesizeEvent(evt,{type:"keypress",faux:true,charCode:c});
232 kp.call(evt.currentTarget,_2f);
233 evt.cancelBubble=_2f.cancelBubble;
234 evt.returnValue=_2f.returnValue;
235 _1c(evt,_2f.keyCode);
237 },_stopPropagation:function(){
238 this.cancelBubble=true;
239 },_preventDefault:function(){
240 this.bubbledKeyCode=this.keyCode;
244 this.returnValue=false;
246 dojo.stopEvent=function(evt){
247 evt=evt||window.event;
248 _1._stopPropagation.call(evt);
249 _1._preventDefault.call(evt);
252 _1._synthesizeEvent=function(evt,_30){
253 var _31=dojo.mixin({},evt,_30);
255 _31.preventDefault=function(){
256 evt.preventDefault();
258 _31.stopPropagation=function(){
259 evt.stopPropagation();
264 dojo.mixin(_1,{_fixEvent:function(evt,_32){
271 c=c<41&&!evt.shiftKey?0:c;
272 if(evt.ctrlKey&&!evt.shiftKey&&c>=65&&c<=90){
275 return _1._synthesizeEvent(evt,{charCode:c});
282 _1._remove=_1.remove;
283 dojo.mixin(_1,{add:function(_33,_34,fp){
287 var _35=_1._add(_33,_34,fp);
288 if(_1._normalizeEventName(_34)=="keypress"){
289 _35._stealthKeyDownHandle=_1._add(_33,"keydown",function(evt){
291 var _36=k!=13&&k!=32&&(k<48||k>90)&&(k<96||k>111)&&(k<186||k>192)&&(k<219||k>222);
292 if(_36||evt.ctrlKey){
301 if(!evt.shiftKey&&c>=65&&c<=90){
304 c=_1._punctMap[c]||c;
309 var _37=_1._synthesizeEvent(evt,{type:"keypress",faux:true,charCode:c});
310 fp.call(evt.currentTarget,_37);
315 },remove:function(_38,_39,_3a){
317 if(_3a._stealthKeyDownHandle){
318 _1._remove(_38,"keydown",_3a._stealthKeyDownHandle);
320 _1._remove(_38,_39,_3a);
322 },_fixEvent:function(evt,_3b){
330 return _1._synthesizeEvent(evt,{charCode:c,faux:true});
337 dojo._ieDispatcher=function(_3c,_3d){
338 var ap=Array.prototype,h=dojo._ie_listener.handlers,c=_3c.callee,ls=c[dojo._ieListenersName],t=h[c.target];
339 var r=t&&t.apply(_3d,_3c);
340 var lls=[].concat(ls);
349 dojo._getIeDispatcher=function(){
350 return new Function(dojo._scopeName+"._ieDispatcher(arguments, this)");
352 dojo._event_listener._fixCallback=function(fp){
353 var f=dojo._event_listener._fixEvent;
355 return fp.call(this,f(e,this));