Skip to content

Commit

Permalink
Add sessionStorage to persist input type across pages ref #72
Browse files Browse the repository at this point in the history
  • Loading branch information
ten1seven committed May 15, 2018
1 parent 44a0c65 commit 74449af
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,16 @@ whatInput.unRegisterOnChange(myFunction)

## Compatibility

What Input works in all modern browsers. For compatibility with IE8, polyfills are required for:
What Input works in all modern browsers.

* addEventListener
* IndexOf
## Changelog

Add your own, or grab the bundle included here.
### v5.1.0

```html
<!--[if lte IE 8]>
<script src="lte-IE8.js"></script>
<![endif]-->
```

## Changelog
* **Added:** Session variable stores last used input and intent so subsiquent page loads don't have to wait for interactions to set the correct input and intent state.
* **Removed:** IE8 support.

### v5.0.6
### v5.0.7

* **Fixed:** `unRegisterOnChange` failed to unregister items at index 0.

Expand Down
29 changes: 28 additions & 1 deletion 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 v5.0.7
* @version v5.1.0
* @link https://github.com/ten1seven/what-input
* @license MIT
*/
Expand Down Expand Up @@ -108,6 +108,18 @@ return /******/ (function(modules) { // webpackBootstrap
// last used input intent
var currentIntent = currentInput;

// check for sessionStorage support
// then check for session variables and use if available
if (window.sessionStorage) {
if (window.sessionStorage.getItem('what-input')) {
currentInput = window.sessionStorage.getItem('what-input');
}

if (window.sessionStorage.getItem('what-intent')) {
currentIntent = window.sessionStorage.getItem('what-intent');
}
}

// event buffer timer
var eventTimer = null;

Expand Down Expand Up @@ -237,6 +249,11 @@ return /******/ (function(modules) { // webpackBootstrap

if (currentInput !== value && shouldUpdate) {
currentInput = value;

if (window.sessionStorage) {
window.sessionStorage.setItem('what-input', currentInput);
}

doUpdate('input');
}

Expand All @@ -247,6 +264,11 @@ return /******/ (function(modules) { // webpackBootstrap

if (notFormInput) {
currentIntent = value;

if (window.sessionStorage) {
window.sessionStorage.setItem('what-intent', currentIntent);
}

doUpdate('intent');
}
}
Expand Down Expand Up @@ -275,6 +297,11 @@ return /******/ (function(modules) { // webpackBootstrap

if (currentIntent !== value) {
currentIntent = value;

if (window.sessionStorage) {
window.sessionStorage.setItem('what-intent', currentIntent);
}

doUpdate('intent');
}
}
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.

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": "5.0.7",
"version": "5.1.0",
"description":
"A global utility for tracking the current input method (mouse, keyboard or touch).",
"main": "dist/what-input.js",
Expand Down
27 changes: 27 additions & 0 deletions src/scripts/what-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ module.exports = (() => {
// last used input intent
let currentIntent = currentInput

// check for sessionStorage support
// then check for session variables and use if available
if (window.sessionStorage) {
if (window.sessionStorage.getItem('what-input')) {
currentInput = window.sessionStorage.getItem('what-input')
}

if (window.sessionStorage.getItem('what-intent')) {
currentIntent = window.sessionStorage.getItem('what-intent')
}
}

// event buffer timer
let eventTimer = null

Expand Down Expand Up @@ -178,6 +190,11 @@ module.exports = (() => {

if (currentInput !== value && shouldUpdate) {
currentInput = value

if (window.sessionStorage) {
window.sessionStorage.setItem('what-input', currentInput)
}

doUpdate('input')
}

Expand All @@ -191,6 +208,11 @@ module.exports = (() => {

if (notFormInput) {
currentIntent = value

if (window.sessionStorage) {
window.sessionStorage.setItem('what-intent', currentIntent)
}

doUpdate('intent')
}
}
Expand Down Expand Up @@ -222,6 +244,11 @@ module.exports = (() => {

if (currentIntent !== value) {
currentIntent = value

if (window.sessionStorage) {
window.sessionStorage.setItem('what-intent', currentIntent)
}

doUpdate('intent')
}
}
Expand Down

0 comments on commit 74449af

Please sign in to comment.