From 730ecfedc6a974381868433d6fc1a80a25c07216 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Tue, 11 Aug 2015 03:03:52 -0600 Subject: [PATCH 1/2] use else if to check for additional key codes --- dist/bespoke-keys.js | 5 ++--- dist/bespoke-keys.min.js | 4 ++-- lib/bespoke-keys.js | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/dist/bespoke-keys.js b/dist/bespoke-keys.js index dfd1bdf..087c4c3 100644 --- a/dist/bespoke-keys.js +++ b/dist/bespoke-keys.js @@ -1,5 +1,5 @@ /*! - * bespoke-keys v1.0.0 + * bespoke-keys v1.1.0 * * Copyright 2015, Mark Dalgleish * This content is released under the MIT license @@ -17,8 +17,7 @@ module.exports = function(options) { (isHorizontal && e.which == 39) || // RIGHT (!isHorizontal && e.which == 40) // DOWN ) { deck.next(); } - - if (e.which == 33 || // PAGE UP + else if (e.which == 33 || // PAGE UP (e.which == 32 && e.shiftKey) || // SPACE + SHIFT (isHorizontal && e.which == 37) || // LEFT (!isHorizontal && e.which == 38) // UP diff --git a/dist/bespoke-keys.min.js b/dist/bespoke-keys.min.js index 6b8ae6e..aa7a0da 100644 --- a/dist/bespoke-keys.min.js +++ b/dist/bespoke-keys.min.js @@ -1,2 +1,2 @@ -/*! bespoke-keys v1.0.0 © 2015 Mark Dalgleish, MIT License */ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self);var i=n;i=i.bespoke||(i.bespoke={}),i=i.plugins||(i.plugins={}),i.keys=e()}}(function(){return function e(n,i,t){function r(f,u){if(!i[f]){if(!n[f]){var c="function"==typeof require&&require;if(!u&&c)return c(f,!0);if(o)return o(f,!0);throw new Error("Cannot find module '"+f+"'")}var d=i[f]={exports:{}};n[f][0].call(d.exports,function(e){var i=n[f][1][e];return r(i?i:e)},d,d.exports,e,n,i,t)}return i[f].exports}for(var o="function"==typeof require&&require,f=0;f Date: Thu, 13 Aug 2015 19:35:07 -0600 Subject: [PATCH 2/2] fix tests; verify events don't trigger in input when using bespoke-forms --- package.json | 1 + test/spec/bespoke-keysSpec.js | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index f50128d..25b497b 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "devDependencies": { "bespoke": "^1.0.0-beta", + "bespoke-forms": "^1.0.0", "browserify": "^4.1.5", "function-bind": "^0.1.0", "gulp": "^3.5.1", diff --git a/test/spec/bespoke-keysSpec.js b/test/spec/bespoke-keysSpec.js index 0043614..c9f2bf2 100755 --- a/test/spec/bespoke-keysSpec.js +++ b/test/spec/bespoke-keysSpec.js @@ -1,24 +1,27 @@ describe("bespoke-keys", function() { Function.prototype.bind = Function.prototype.bind || require('function-bind'); - require('simulant/simulant'); - var bespoke = require('bespoke'), - keys = require('../../lib-instrumented/bespoke-keys.js'); + var simulant = require('simulant'), + bespoke = require('bespoke'), + keys = require('../../lib-instrumented/bespoke-keys.js'), + forms = require('bespoke-forms'); var deck, - + inputBox = null, createDeck = function(optionValue) { var parent = document.createElement('article'); - parent.innerHTML = '
'; + parent.innerHTML = '
'; + inputBox = parent.querySelector('input'); deck = bespoke.from(parent, [ - keys(optionValue) + keys(optionValue), + forms(optionValue) ]); }, - pressKey = function(which, isShift) { - simulant.fire(document, 'keydown', { which: which, shiftKey: !!isShift }); + pressKey = function(which, isShift, element) { + simulant.fire((element || document), 'keydown', { which: which, shiftKey: !!isShift }); }; describe("horizontal deck", function() { @@ -46,6 +49,11 @@ describe("bespoke-keys", function() { expect(deck.slide()).toBe(1); }); + it("should not go to the next slide when pressing the space bar in an input field", function() { + pressKey(32, false, inputBox); + expect(deck.slide()).toBe(0); + }); + }); describe("previous slide", function() {