1 rio.KeyMap = Class.create({ 2 initialize: function(map, isMac) { 3 this.map = map; 4 this.isMac = isMac; 5 }, 6 7 handle: function(e) { 8 this.map.each(function(m) { 9 var map = m.map || (this.isMac ? m.mac : m.win); 10 11 if (Object.isString(map.key)) { 12 map.key = rio.KeyMap.specialKeys()[map.key] || rio.KeyMap.charCode(map.key); 13 } 14 15 var effectiveKeyCode = (e.keyCode >= 96 && e.keyCode <= 105) ? e.keyCode - 48 : e.keyCode; 16 if (map.key == effectiveKeyCode) { 17 if (map.ctrl == undefined || map.ctrl == e.ctrlKey) { 18 if (map.alt == undefined || map.alt == e.altKey) { 19 if (map.shift == undefined || map.shift == e.shiftKey) { 20 if (map.meta == undefined || map.meta == e.metaKey) { 21 (m.handler || Prototype.emptyFunction)(e); 22 23 if (m.stop) { 24 e.stop(); 25 } 26 } 27 } 28 } 29 } 30 } 31 }.bind(this)); 32 } 33 }); 34 35 Object.extend(rio.KeyMap, { 36 build: function(map) { 37 return new rio.KeyMap(map, rio.boot.isMac); 38 }, 39 charCode: function(c) { 40 return "0123456789_______abcdefghijklmnopqrstuvwxyz".indexOf(c) + 48; 41 }, 42 specialKeys: function() { 43 return { 44 "left": Event.KEY_LEFT, 45 "right": Event.KEY_RIGHT, 46 "up": Event.KEY_UP, 47 "down": Event.KEY_DOWN, 48 "tab": Event.KEY_TAB, 49 "enter": Event.KEY_RETURN, 50 "home": Event.KEY_HOME, 51 "end": Event.KEY_END, 52 "backspace": Event.KEY_BACKSPACE, 53 "delete": Event.KEY_DELETE, 54 "space": 32, 55 "esc": Event.KEY_ESC, 56 ",": 188 57 }; 58 }, 59 toString: function() { return "KeyMap"; } 60 }); 61