diff options
author | Teddy Wing | 2015-05-23 16:21:38 -0400 |
---|---|---|
committer | Teddy Wing | 2015-05-23 16:21:38 -0400 |
commit | 3a09e4dd09a6af3b228fcda68aa0709626b5ee51 (patch) | |
tree | a434d76ccae2a55cfe4f4c0215a99017de4bba33 /lib/mousetrap/plugins/record/tests/jelly.js | |
parent | 6183a0bb3caf4805ed4242a4ac104b9890db3601 (diff) | |
download | Peniquitous-3a09e4dd09a6af3b228fcda68aa0709626b5ee51.tar.bz2 |
Set up Bower. Install Mousetrap.
* Create limited bower.json file
* Create .bowerrc that tells Bower to use the `lib` directory
* Install Mousetrap for key events
Diffstat (limited to 'lib/mousetrap/plugins/record/tests/jelly.js')
-rw-r--r-- | lib/mousetrap/plugins/record/tests/jelly.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/mousetrap/plugins/record/tests/jelly.js b/lib/mousetrap/plugins/record/tests/jelly.js new file mode 100644 index 0000000..57ff01a --- /dev/null +++ b/lib/mousetrap/plugins/record/tests/jelly.js @@ -0,0 +1,53 @@ +/** + * Peanut butter goes great with jelly. + * + * @author Dan Tao <daniel.tao@gmail.com> + */ +var Jelly = (function() { + var recordButton = $("button.test-record"), + recordResult = $("div.test-record-result"); + + function _formatSequenceAsHtml(sequence) { + var combos = [], + i; + + for (i = 0; i < sequence.length; ++i) { + combos.push('<span>' + _formatKeysAsHtml(sequence[i].split('+')) + '</span>'); + } + + return combos.join(' '); + } + + function _formatKeysAsHtml(keys) { + var htmlKeys = [], + i; + + for (i = 0; i < keys.length; ++i) { + htmlKeys.push('<kbd>' + keys[i] + '</kbd>'); + } + + return htmlKeys.join('+'); + } + + function _prepareRecordTest() { + recordButton.prop('disabled', true); + recordButton.text('Recording'); + + Mousetrap.record(function(sequence) { + recordResult.html(_formatSequenceAsHtml(sequence)); + recordButton.prop('disabled', false); + recordButton.text('Record'); + }); + + // take focus away from the button so that Mousetrap will actually + // capture keystrokes + recordButton.blur(); + } + + return { + spread: function() { + recordButton.click(_prepareRecordTest); + } + }; + +})(); |