root / trunk / web / dojo / dojox / drawing / manager / keys.js @ 11
History | View | Annotate | Download (3.14 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.drawing.manager.keys"]){ |
||
9 | dojo._hasResource["dojox.drawing.manager.keys"]=true; |
||
10 | dojo.provide("dojox.drawing.manager.keys");
|
||
11 | (function(){
|
||
12 | var _1=false; |
||
13 | var _2=true; |
||
14 | var _3="abcdefghijklmnopqrstuvwxyz"; |
||
15 | dojox.drawing.manager.keys={arrowIncrement:1,arrowShiftIncrement:10,shift:false,ctrl:false,alt:false,cmmd:false,meta:false,onDelete:function(_4){ |
||
16 | },onEsc:function(_5){ |
||
17 | },onEnter:function(_6){ |
||
18 | },onArrow:function(_7){ |
||
19 | },onKeyDown:function(_8){ |
||
20 | },onKeyUp:function(_9){ |
||
21 | },listeners:[],register:function(_a){ |
||
22 | var _b=dojox.drawing.util.uid("listener"); |
||
23 | this.listeners.push({handle:_b,scope:_a.scope||window,callback:_a.callback,keyCode:_a.keyCode}); |
||
24 | },_getLetter:function(_c){ |
||
25 | if(!_c.meta&&_c.keyCode>=65&&_c.keyCode<=90){ |
||
26 | return _3.charAt(_c.keyCode-65); |
||
27 | } |
||
28 | return null; |
||
29 | },_mixin:function(_d){ |
||
30 | _d.meta=this.meta;
|
||
31 | _d.shift=this.shift;
|
||
32 | _d.alt=this.alt;
|
||
33 | _d.cmmd=this.cmmd;
|
||
34 | _d.letter=this._getLetter(_d);
|
||
35 | return _d;
|
||
36 | },editMode:function(_e){ |
||
37 | _1=_e; |
||
38 | },enable:function(_f){ |
||
39 | _2=_f; |
||
40 | },scanForFields:function(){ |
||
41 | if(this._fieldCons){ |
||
42 | dojo.forEach(this._fieldCons,dojo.disconnect,dojo);
|
||
43 | } |
||
44 | this._fieldCons=[];
|
||
45 | dojo.query("input").forEach(function(n){ |
||
46 | var a=dojo.connect(n,"focus",this,function(evt){ |
||
47 | this.enable(false); |
||
48 | }); |
||
49 | var b=dojo.connect(n,"blur",this,function(evt){ |
||
50 | this.enable(true); |
||
51 | }); |
||
52 | this._fieldCons.push(a);
|
||
53 | this._fieldCons.push(b);
|
||
54 | },this);
|
||
55 | },init:function(){ |
||
56 | setTimeout(dojo.hitch(this,"scanForFields"),500); |
||
57 | dojo.connect(document,"blur",this,function(evt){ |
||
58 | this.meta=this.shift=this.ctrl=this.cmmd=this.alt=false; |
||
59 | }); |
||
60 | dojo.connect(document,"keydown",this,function(evt){ |
||
61 | if(!_2){
|
||
62 | return;
|
||
63 | } |
||
64 | if(evt.keyCode==16){ |
||
65 | this.shift=true; |
||
66 | } |
||
67 | if(evt.keyCode==17){ |
||
68 | this.ctrl=true; |
||
69 | } |
||
70 | if(evt.keyCode==18){ |
||
71 | this.alt=true; |
||
72 | } |
||
73 | if(evt.keyCode==224){ |
||
74 | this.cmmd=true; |
||
75 | } |
||
76 | this.meta=this.shift||this.ctrl||this.cmmd||this.alt; |
||
77 | if(!_1){
|
||
78 | this.onKeyDown(this._mixin(evt)); |
||
79 | if(evt.keyCode==8||evt.keyCode==46){ |
||
80 | dojo.stopEvent(evt); |
||
81 | } |
||
82 | } |
||
83 | }); |
||
84 | dojo.connect(document,"keyup",this,function(evt){ |
||
85 | if(!_2){
|
||
86 | return;
|
||
87 | } |
||
88 | var _10=false; |
||
89 | if(evt.keyCode==16){ |
||
90 | this.shift=false; |
||
91 | } |
||
92 | if(evt.keyCode==17){ |
||
93 | this.ctrl=false; |
||
94 | } |
||
95 | if(evt.keyCode==18){ |
||
96 | this.alt=false; |
||
97 | } |
||
98 | if(evt.keyCode==224){ |
||
99 | this.cmmd=false; |
||
100 | } |
||
101 | this.meta=this.shift||this.ctrl||this.cmmd||this.alt; |
||
102 | !_1&&this.onKeyUp(this._mixin(evt)); |
||
103 | if(evt.keyCode==13){ |
||
104 | console.warn("KEY ENTER");
|
||
105 | this.onEnter(evt);
|
||
106 | _10=true;
|
||
107 | } |
||
108 | if(evt.keyCode==27){ |
||
109 | this.onEsc(evt);
|
||
110 | _10=true;
|
||
111 | } |
||
112 | if(evt.keyCode==8||evt.keyCode==46){ |
||
113 | this.onDelete(evt);
|
||
114 | _10=true;
|
||
115 | } |
||
116 | if(_10&&!_1){
|
||
117 | dojo.stopEvent(evt); |
||
118 | } |
||
119 | }); |
||
120 | dojo.connect(document,"keypress",this,function(evt){ |
||
121 | if(!_2){
|
||
122 | return;
|
||
123 | } |
||
124 | var inc=this.shift?this.arrowIncrement*this.arrowShiftIncrement:this.arrowIncrement; |
||
125 | var x=0,y=0; |
||
126 | if(evt.keyCode==32&&!_1){ |
||
127 | dojo.stopEvent(evt); |
||
128 | } |
||
129 | if(evt.keyCode==37){ |
||
130 | x=-inc; |
||
131 | } |
||
132 | if(evt.keyCode==38){ |
||
133 | y=-inc; |
||
134 | } |
||
135 | if(evt.keyCode==39){ |
||
136 | x=inc; |
||
137 | } |
||
138 | if(evt.keyCode==40){ |
||
139 | y=inc; |
||
140 | } |
||
141 | if(x||y){
|
||
142 | evt.x=x; |
||
143 | evt.y=y; |
||
144 | evt.shift=this.shift;
|
||
145 | this.onArrow(evt);
|
||
146 | if(!_1){
|
||
147 | dojo.stopEvent(evt); |
||
148 | } |
||
149 | } |
||
150 | }); |
||
151 | }}; |
||
152 | dojo.addOnLoad(dojox.drawing.manager.keys,"init");
|
||
153 | })(); |
||
154 | } |