• R/O
  • SSH

micro-keyboard: Commit

keyboard event helper and constants library


Commit MetaInfo

Revision68c69e01f2eb6e58788df6576a6ba3387368d1db (tree)
Time2017-04-14 11:51:18
Authorfrostbane <frostbane@prog...>
Commiterfrostbane

Log Message

change array access to function

Change Summary

Incremental Difference

diff -r cd09b411a091 -r 68c69e01f2eb src/microkeyboard.js
--- a/src/microkeyboard.js Fri Apr 14 00:04:49 2017 +0900
+++ b/src/microkeyboard.js Fri Apr 14 11:51:18 2017 +0900
@@ -62,8 +62,6 @@
6262 module
6363 */
6464
65-
66-
6765 (function(global, factory){
6866 "use strict";
6967
@@ -76,85 +74,6 @@
7674 }(this, (function(){
7775 "use strict";
7876
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-
15877 var kb = {};
15978
16079 var KeyCodes = [];
@@ -257,13 +176,9 @@
257176 KeyCodes[221] = "]";
258177 KeyCodes[222] = "'";
259178
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+ };
267182
268183 kb.Backspace = 8;
269184 kb.Tab = 9;
@@ -367,12 +282,14 @@
367282 kb.ClosingBrace = 221;
368283 kb.SingleQuote = 222;
369284
285+ var functype = typeof function(){};
286+
370287 if (Object.hasOwnProperty("freeze") && typeof Object.freeze === functype)
371288 Object.freeze(kb);
372289 else if (Object.hasOwnProperty("preventExtensions") && typeof Object.preventExtensions === functype)
373290 Object.preventExtensions(kb);
374291 else
375- console.warn("Unable to freeze object, Keyboard will be mutable.");
292+ console.warn("Unable to freeze object, Keyboard enumeration will be mutable.");
376293
377294 return kb;
378295
Show on old repository browser