diff options
author | Solly Ross <sross@redhat.com> | 2014-05-20 19:16:01 -0400 |
---|---|---|
committer | Solly Ross <sross@redhat.com> | 2014-09-15 16:46:02 -0400 |
commit | 31f169e86fe7b8065c5e1406ed2885549920e822 (patch) | |
tree | 3d9b01234598af0ee0e75d81f68ddfea5367da6f | |
parent | d6e281baf66b6aa59e54ea0e1c775b46f9698af2 (diff) | |
download | novnc-31f169e86fe7b8065c5e1406ed2885549920e822.tar.gz |
Cleanup: Keyboard code
File: keyboard.js
Tests Added: False (already present)
Changes:
- Fixed JSHint Errors
- Moved functions outside loops
- Added proper include directives to tests
-rw-r--r-- | include/keyboard.js | 29 | ||||
-rw-r--r-- | tests/test.helper.js | 4 | ||||
-rw-r--r-- | tests/test.keyboard.js | 5 |
3 files changed, 25 insertions, 13 deletions
diff --git a/include/keyboard.js b/include/keyboard.js index c89411c..6044321 100644 --- a/include/keyboard.js +++ b/include/keyboard.js @@ -15,7 +15,7 @@ var kbdUtil = (function() { var sub = substitutions[cp]; return sub ? sub : cp; - }; + } function isMac() { return navigator && !!(/mac/i).exec(navigator.platform); @@ -387,17 +387,22 @@ function VerifyCharModifier(next) { if (timer) { return; } + + var delayProcess = function () { + clearTimeout(timer); + timer = null; + process(); + }; + while (queue.length !== 0) { var cur = queue[0]; queue = queue.splice(1); switch (cur.type) { case 'stall': // insert a delay before processing available events. - timer = setTimeout(function() { - clearTimeout(timer); - timer = null; - process(); - }, 5); + /* jshint loopfunc: true */ + timer = setTimeout(delayProcess, 5); + /* jshint loopfunc: false */ return; case 'keydown': // is the next element a keypress? Then we should merge the two @@ -489,23 +494,25 @@ function TrackKeyState(next) { var item = state.splice(idx, 1)[0]; // for each keysym tracked by this key entry, clone the current event and override the keysym + var clone = (function(){ + function Clone(){} + return function (obj) { Clone.prototype=obj; return new Clone(); }; + }()); for (var key in item.keysyms) { - var clone = (function(){ - function Clone(){} - return function (obj) { Clone.prototype=obj; return new Clone(); }; - }()); var out = clone(evt); out.keysym = item.keysyms[key]; next(out); } break; case 'releaseall': + /* jshint shadow: true */ for (var i = 0; i < state.length; ++i) { for (var key in state[i].keysyms) { var keysym = state[i].keysyms[key]; next({keyId: 0, keysym: keysym, type: 'keyup'}); } } + /* jshint shadow: false */ state = []; } }; @@ -527,8 +534,10 @@ function EscapeModifiers(next) { // send the character event next(evt); // redo modifiers + /* jshint shadow: true */ for (var i = 0; i < evt.escape.length; ++i) { next({type: 'keydown', keyId: 0, keysym: keysyms.lookup(evt.escape[i])}); } + /* jshint shadow: false */ }; } diff --git a/tests/test.helper.js b/tests/test.helper.js index d9e8e14..98009d2 100644 --- a/tests/test.helper.js +++ b/tests/test.helper.js @@ -1,4 +1,6 @@ -var assert = chai.assert; +// requires local modules: keysym, keysymdef, keyboard + +var assert = chai.assert; var expect = chai.expect; describe('Helpers', function() { diff --git a/tests/test.keyboard.js b/tests/test.keyboard.js index 80d1fee..2ac65af 100644 --- a/tests/test.keyboard.js +++ b/tests/test.keyboard.js @@ -1,7 +1,8 @@ +// requires local modules: input, keyboard, keysymdef var assert = chai.assert; var expect = chai.expect; - +/* jshint newcap: false, expr: true */ describe('Key Event Pipeline Stages', function() { "use strict"; describe('Decode Keyboard Events', function() { @@ -50,7 +51,7 @@ describe('Key Event Pipeline Stages', function() { KeyEventDecoder(kbdUtil.ModifierSync(), function(evt) { expect(evt).to.be.deep.equal({keyId: 0x41, type: 'keydown'}); done(); - }).keydown({keyCode: 0x41}) + }).keydown({keyCode: 0x41}); }); it('should forward keyup events with the right type', function(done) { KeyEventDecoder(kbdUtil.ModifierSync(), function(evt) { |