keyboard event helper and constants library
Revision | 28d0fba316a3ff8e4c643fbabb4871ee8c6c56ec (tree) |
---|---|
Time | 2017-04-14 11:51:35 |
Author | frostbane <frostbane@prog...> |
Commiter | frostbane |
Merge with feature/api_change
@@ -0,0 +1,1 @@ | ||
1 | +792c1b270b62f24d797815b4317449fb189f42ad v0.0.2 |
@@ -62,8 +62,6 @@ | ||
62 | 62 | module |
63 | 63 | */ |
64 | 64 | |
65 | - | |
66 | - | |
67 | 65 | (function(global, factory){ |
68 | 66 | "use strict"; |
69 | 67 |
@@ -76,85 +74,6 @@ | ||
76 | 74 | }(this, (function(){ |
77 | 75 | "use strict"; |
78 | 76 | |
79 | - var functype = typeof function(){}; | |
80 | - | |
81 | - // var Enum = function(){ | |
82 | - // var offset = 0, | |
83 | - // index = 0, | |
84 | - // stringtype = typeof "string", | |
85 | - // functype = typeof function(){}, | |
86 | - // idRe = new RegExp(/^[$A-Z_][0-9A-Z_$]*$/i), | |
87 | - // numRe = new RegExp(/^[0-9]*$/i), | |
88 | - // trimRe = new RegExp(/^\s+|\s+$/g), | |
89 | - // eobj = { __proto__ :this, }, | |
90 | - // setVal = function(obj, val, opts){ | |
91 | - // try { | |
92 | - // Object.defineProperty(obj, val, opts); | |
93 | - // } catch(ex) { | |
94 | - // obj[val] = opts.value; | |
95 | - // } | |
96 | - // }; | |
97 | - // | |
98 | - // for (var i = 0; i < arguments.length; i++) { | |
99 | - // var val = arguments[i]; | |
100 | - // | |
101 | - // if (typeof val !== stringtype) | |
102 | - // throw "invalid enumeration type, '" + typeof val + "'"; | |
103 | - // | |
104 | - // if (val.replace(trimRe, '') === "") | |
105 | - // throw "blank enumeration"; | |
106 | - // | |
107 | - // if (val.indexOf("=") === 0) | |
108 | - // throw "blank enumeration, '" + val + "'"; | |
109 | - // | |
110 | - // if (val.indexOf("=") > 0) { | |
111 | - // var parts = val.split("="); | |
112 | - // | |
113 | - // if (parts.length !== 2) | |
114 | - // throw "multiple assignments, '" + val + "'"; | |
115 | - // | |
116 | - // var assignment = parts[1].replace(trimRe, ''); | |
117 | - // | |
118 | - // if (assignment !== "") { | |
119 | - // if (!numRe.test(assignment)) | |
120 | - // throw "invalid assignment, '" + val + "'"; | |
121 | - // | |
122 | - // offset = parseInt(assignment); | |
123 | - // | |
124 | - // if (isNaN(offset)) | |
125 | - // throw "invalid assignment, '" + val + "'"; | |
126 | - // | |
127 | - // index = 0; | |
128 | - // } | |
129 | - // | |
130 | - // val = parts[0]; | |
131 | - // } | |
132 | - // | |
133 | - // val = val.replace(trimRe, ''); | |
134 | - // | |
135 | - // if (!idRe.test(val)) | |
136 | - // throw "invalid enumeration, '" + val + "'"; | |
137 | - // | |
138 | - // if (eobj.hasOwnProperty(val)) | |
139 | - // throw "duplicate enumeration, '" + val + "'"; | |
140 | - // | |
141 | - // setVal(eobj, val, { | |
142 | - // value :offset + index++, | |
143 | - // writable :false, | |
144 | - // configurable :false, | |
145 | - // enumerable :true, | |
146 | - // }); | |
147 | - // | |
148 | - // } | |
149 | - // | |
150 | - // if (Object.hasOwnProperty("freeze") && typeof Object.freeze === functype) | |
151 | - // Object.freeze(eobj); | |
152 | - // else if (Object.hasOwnProperty("preventExtensions") && typeof Object.preventExtensions === functype) | |
153 | - // Object.preventExtensions(eobj); | |
154 | - // | |
155 | - // return eobj; | |
156 | - // }; | |
157 | - | |
158 | 77 | var kb = {}; |
159 | 78 | |
160 | 79 | var KeyCodes = []; |
@@ -257,13 +176,9 @@ | ||
257 | 176 | KeyCodes[221] = "]"; |
258 | 177 | KeyCodes[222] = "'"; |
259 | 178 | |
260 | - if (Object.hasOwnProperty("freeze") && typeof Object.freeze === functype) | |
261 | - Object.freeze(KeyCodes); | |
262 | - else if (Object.hasOwnProperty("preventExtensions") && typeof Object.preventExtensions === functype) | |
263 | - Object.preventExtensions(KeyCodes); | |
264 | - | |
265 | - kb.keyCodes = KeyCodes; | |
266 | - | |
179 | + kb.keyCodes = function(n){ | |
180 | + return KeyCodes[n]; | |
181 | + }; | |
267 | 182 | |
268 | 183 | kb.Backspace = 8; |
269 | 184 | kb.Tab = 9; |
@@ -367,12 +282,14 @@ | ||
367 | 282 | kb.ClosingBrace = 221; |
368 | 283 | kb.SingleQuote = 222; |
369 | 284 | |
285 | + var functype = typeof function(){}; | |
286 | + | |
370 | 287 | if (Object.hasOwnProperty("freeze") && typeof Object.freeze === functype) |
371 | 288 | Object.freeze(kb); |
372 | 289 | else if (Object.hasOwnProperty("preventExtensions") && typeof Object.preventExtensions === functype) |
373 | 290 | Object.preventExtensions(kb); |
374 | 291 | else |
375 | - console.warn("Unable to freeze object, Keyboard will be mutable."); | |
292 | + console.warn("Unable to freeze object, Keyboard enumeration will be mutable."); | |
376 | 293 | |
377 | 294 | return kb; |
378 | 295 |