Skip to content

Commit

Permalink
Merge pull request #64 from ten1seven/jf/tab-key-inputs
Browse files Browse the repository at this point in the history
Replicates functionality resolved in #50
  • Loading branch information
ten1seven authored Jun 13, 2017
2 parents dab188a + f15c0f6 commit 018f5d2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

__A global utility for tracking the current input method (mouse, keyboard or touch).__

## What Input is now v4.1.6
## What Input is now v4.2.0

What Input adds data attributes to the `<html>` tag based on the type of input being used. It also exposes a simple API that can be used for scripting interactions.

### June 13, 2017

* Updated: Typing _in_ form inputs does not change input type, but tabbing between inputs _does_ initiate a switch from `mouse` to `keyboard`.

### June 12, 2017

* Added: passive event listener for `wheel` event.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "what-input",
"version": "4.1.6",
"version": "4.2.0",
"homepage": "https://github.com/ten1seven/what-input",
"repository": {
"url": "https://github.com/ten1seven/what-input.git",
Expand Down
9 changes: 7 additions & 2 deletions dist/what-input.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* what-input - A global utility for tracking the current input method (mouse, keyboard or touch).
* @version v4.1.6
* @version v4.2.0
* @link https://github.com/ten1seven/what-input
* @license MIT
*/
Expand Down Expand Up @@ -90,6 +90,10 @@ return /******/ (function(modules) { // webpackBootstrap
93 // Windows menu / right Apple cmd
];

// list of keys for which we change intent even for form inputs
var changeIntentMap = [9 // tab
];

// mapping of events to input types
var inputMap = {
keydown: 'keyboard',
Expand Down Expand Up @@ -194,8 +198,9 @@ return /******/ (function(modules) { // webpackBootstrap
if (currentInput !== value || currentIntent !== value) {
var activeElem = document.activeElement;
var activeInput = false;
var notFormInput = activeElem && activeElem.nodeName && formInputs.indexOf(activeElem.nodeName.toLowerCase()) === -1;

if (activeElem && activeElem.nodeName && formInputs.indexOf(activeElem.nodeName.toLowerCase()) === -1) {
if (notFormInput || changeIntentMap.indexOf(eventKey) !== -1) {
activeInput = true;
}

Expand Down
4 changes: 2 additions & 2 deletions dist/what-input.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions docs/scripts/what-input.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* what-input - A global utility for tracking the current input method (mouse, keyboard or touch).
* @version v4.1.6
* @version v4.2.0
* @link https://github.com/ten1seven/what-input
* @license MIT
*/
Expand Down Expand Up @@ -90,6 +90,10 @@ return /******/ (function(modules) { // webpackBootstrap
93 // Windows menu / right Apple cmd
];

// list of keys for which we change intent even for form inputs
var changeIntentMap = [9 // tab
];

// mapping of events to input types
var inputMap = {
keydown: 'keyboard',
Expand Down Expand Up @@ -194,8 +198,9 @@ return /******/ (function(modules) { // webpackBootstrap
if (currentInput !== value || currentIntent !== value) {
var activeElem = document.activeElement;
var activeInput = false;
var notFormInput = activeElem && activeElem.nodeName && formInputs.indexOf(activeElem.nodeName.toLowerCase()) === -1;

if (activeElem && activeElem.nodeName && formInputs.indexOf(activeElem.nodeName.toLowerCase()) === -1) {
if (notFormInput || changeIntentMap.indexOf(eventKey) !== -1) {
activeInput = true;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "what-input",
"version": "4.1.6",
"version": "4.2.0",
"description": "A global utility for tracking the current input method (mouse, keyboard or touch).",
"main": "dist/what-input.js",
"repository": {
Expand Down
11 changes: 8 additions & 3 deletions src/what-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module.exports = (() => {
93 // Windows menu / right Apple cmd
]

// list of keys for which we change intent even for form inputs
const changeIntentMap = [
9 // tab
]

// mapping of events to input types
const inputMap = {
keydown: 'keyboard',
Expand Down Expand Up @@ -135,12 +140,12 @@ module.exports = (() => {
if (currentInput !== value || currentIntent !== value) {
let activeElem = document.activeElement
let activeInput = false

if (
let notFormInput =
activeElem &&
activeElem.nodeName &&
formInputs.indexOf(activeElem.nodeName.toLowerCase()) === -1
) {

if (notFormInput || changeIntentMap.indexOf(eventKey) !== -1) {
activeInput = true
}

Expand Down

0 comments on commit 018f5d2

Please sign in to comment.